Skip to content

Imported Model is rotated by 90 degrees #849

Closed

Description

@ruzannakamalyan

Hi,

I'm using the latest version of Assimp and Assimp.Net 3.0 release.
After Importing I'm getting the model rotated by 90 degrees.

Any suggestions on what I'm missing?

Activity

  1. kimkulling commented on Apr 5, 2016

    @kimkulling
    Member

    Have you used the transformation matrix of the root node?

  2. ruzannakamalyan commented on Apr 5, 2016

    @ruzannakamalyan
    Author

    Hi Kim, thanks for your prompt answer. I'll post the processing function. The first call is for model.RootNode, where the model is the imported model.

    public GameObject processNodes(Assimp.Node rootNode) {
            GameObject unityRoot  = new GameObject( rootNode.Name );
                     if ( rootNode.HasChildren ) {
                foreach ( Assimp.Node childNode in rootNode.Children ) {
                    GameObject unityChild = processNodes( childNode );
                    unityChild.transform.parent = unityRoot .transform;
                }
            }
            Assimp.Vector3D position, scaling;
            Assimp.Quaternion rotation;
            rootNode.Transform.Decompose( out scaling, out rotation, out position );
            unityRoot.transform.localPosition = new Vector3( position.X, position.Y, position.Z );
            unityRoot.transform.localRotation = new UnityEngine.Quaternion( rotation.X, rotation.Y, rotation.Z, rotation.W );
            unityRoot.transform.localScale = new Vector3( scaling.X, scaling.Y, scaling.Z );
    } 
    
  3. kimkulling commented on Apr 6, 2016

    @kimkulling
    Member

    Hm, which loader are you using. Maybe there is something wrong. Your code looks fine for me.

  4. ruzannakamalyan commented on Apr 6, 2016

    @ruzannakamalyan
    Author

    I'm trying to load an fbx model with Assimp in Unity. And I'm sorry, there was a little mistake in my first question, I have edited it. Actually I'm using Assimp.Net version 3.0, because with the latest release of it or the code from the master branch an exception is thrown at the file importing step.

    AssimpImporter importer = new AssimpImporter();
    MeshVertexLimitConfig m = new MeshVertexLimitConfig (meshVertexLimit);
    importer.SetConfig (m);
    Scene model = importer.ImportFile(path + '/' + modelName,
                PostProcessSteps.SplitLargeMeshes |
                PostProcessSteps.OptimizeGraph |
                PostProcessSteps.OptimizeMeshes |
                PostProcessSteps.Triangulate |
                PostProcessSteps.SortByPrimitiveType |
                PostProcessPreset.TargetRealTimeMaximumQuality
            );
    
    
  5. ruzannakamalyan commented on Apr 8, 2016

    @ruzannakamalyan
    Author

    Hi @kimkulling ,

    I have found some points about the issue. My exported model has Z-up axis, instead of Y-up axis (unlike assimp), that's why the model is rotated. Is there a way I can get that info from the model (how the axises are set up in the model)?
    Thanks.

  6. smalcom commented on Aug 1, 2016

    @smalcom
    Contributor

    Up-axis usually taken from file format specification. Or from description of a camera if scene is contain it.
    Also you must pay attention to your graphics library. For example - OpenGL by default has Y-up axis.

  7. BBlayne commented on Oct 17, 2016

    @BBlayne

    Hey I have a similar issue but annoyingly everything LOOKS fine when imported, but the Armature itself when I peek at the code is rotated by 90 degrees, this means when I try to get the world space coordinates of the bones, all non-root bones have the Y and Z columns flipped and with the wrong sign.

  8. ne0ndrag0n commented on Dec 31, 2016

    @ne0ndrag0n

    I think Assimp may be applying the wrong transform to mRootNode. Isn't a scene-level, root node transform supposed to be identity? Here's my debug output for scene->mRootNode->mTransform for a Z_UP COLLADA file containing two sibling boxes at the scene level:

    (1.000000, 0.000000, 0.000000, 0.000000)
    (0.000000, 0.000000, -1.000000, 0.000000) 
    (0.000000, 1.000000, 0.000000, 0.000000) 
    (0.000000, 0.000000, 0.000000, 1.000000)
    

    Inside the COLLADA file, the only transform matricies specified are on the boxes themselves, not on the scene node, so I expected this to be an identity mat4. If I manually do scene->mRootNode->mTransformation = aiMatrix4x4(); before processing the tree, everything works as intended. If this isn't supposed to be an identity matrix, what is it?

    I can send the COLLADA file if it assists in reproducing the (possible) issue.

  9. BBlayne commented on Dec 31, 2016

    @BBlayne

    @ne0ndrag0n I think its because whatever program you used uses different coordinates; its similar I think to my problem above; for me, blender is Z up and Y forward; but when imported it's rotated 90 degrees if I don't have "Experimental apply transforms" enabled.

    Similarly I get problems with the Blender bone orientations; depending on their bone roll ASSIMP doesn't import them in properly.

  10. kimkulling commented on Apr 18, 2017

    @kimkulling
    Member

    Any chance to get the Collada model? And sorry for my late response!

    Kim

  11. catdsnny commented on Mar 24, 2018

    @catdsnny

    Had the same issue when loading a model into opengl based C++ engine. Flipping Y and Z coordinates on load solved the problem for me.

  12. Alexees commented on Mar 29, 2018

    @Alexees

    @ruzannakamalyan @kimkulling I just came across the same issue. A model (fbx) that is correctly rotated when dragging into Unity's project folder structure is rotated 90 degree around the x axis relative to its coordinate system when imported through TriLib. When I do the following in the AssetLoader.cs (703) its correct, but since it depends on the model I can't do that:

    unityVertices[v] = AssimpInterop.aiMesh_GetVertex(mesh, v);
    unityVertices[v] = Matrix4x4.Rotate(Quaternion.Euler(-90, 0, 0)) * unityVertices[v];
    

    Since this is an AssimpInterop call (native) I don't even know how to fix that.
    Did you guys have a solution for this, implemented or recommended or anything?

  13. JrIndie commented on Jun 18, 2018

    @JrIndie

    I also am currently facing this issue. Is there any solution? Other than manually fixing matrix while parsing? I am using aiProcess_MakeLeftHanded, since I am using DirectX. however, its still rotated sideways. You would have to flip the y, and z axis, but internally it might be calculating using wrong rotation.

    I am using blender exporting to collada.

  14. added
    Bug
    on Dec 8, 2018
  15. kimkulling commented on Dec 8, 2018

    @kimkulling
    Member

    I was pretty sure that this one should be fixed already. But unfortunately it seems to be still there.

  16. 20 remaining items

  17. jpincho commented on Jul 7, 2021

    @jpincho

    Apparently, FBX allows some arbitrary orientations of the default axis, blender also supports it, but when loading it through assimp, those orientations are not reflected by default. You have to read them from the metadata.
    I think assimp should do this automatically. It's just checking if that data is present, and if so, assign it to the root node.
    It may be format specific, but that's why we're using assimp, to abstract from that.

  18. seyitcemyilmaz commented on Nov 30, 2022

    @seyitcemyilmaz

    I'm currently using this snippet of code to fix that orientation, and it works perfectly for me.

    	if (Scene->mMetaData)
    	{
    		int32_t UpAxis = 1, UpAxisSign = 1, FrontAxis = 2, FrontAxisSign = 1, CoordAxis = 0, CoordAxisSign = 1;
    		double UnitScaleFactor = 1.0;
    		for (unsigned MetadataIndex = 0; MetadataIndex < Scene->mMetaData->mNumProperties; ++MetadataIndex)
    		{
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxis") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, UpAxis);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxisSign") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, UpAxisSign);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxis") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, FrontAxis);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxisSign") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, FrontAxisSign);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxis") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, CoordAxis);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxisSign") == 0)
    			{
    				Scene->mMetaData->Get<int32_t>(MetadataIndex, CoordAxisSign);
    			}
    			if (strcmp(Scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UnitScaleFactor") == 0)
    			{
    				Scene->mMetaData->Get<double>(MetadataIndex, UnitScaleFactor);
    			}
    		}
    
    		aiVector3D upVec, forwardVec, rightVec;
    
    		upVec[UpAxis] = UpAxisSign * (float)UnitScaleFactor;
    		forwardVec[FrontAxis] = FrontAxisSign * (float)UnitScaleFactor;
    		rightVec[CoordAxis] = CoordAxisSign * (float)UnitScaleFactor;
    
    		aiMatrix4x4 mat(rightVec.x, rightVec.y, rightVec.z, 0.0f,
    			upVec.x, upVec.y, upVec.z, 0.0f,
    			forwardVec.x, forwardVec.y, forwardVec.z, 0.0f,
    			0.0f, 0.0f, 0.0f, 1.0f);
    		Scene->mRootNode->mTransformation = mat;
    	}
    

    Then obviously reading the value from mTransformation :)

    It solved my wrong rotationed bone problem. Thank you very much.

  19. Danil0v3s commented on Aug 12, 2023

    @Danil0v3s

    Found this thread yesterday and since I'm using the AssimpNet wrapper and was having the same problem I thought maybe I could fix this in blender since I'm not really keen to change any cpp then do all the other steps to make it load properly in Unity.

    Here's the gist https://gist.github.com/Danil0v3s/4c923d51d148d61a3b4feaf34b77a644

    What it does is use the official valve plugin to load the SMD, then I apply the rotation, save it to a new folder and reload the entire project as a new file. That way the process won't eventually fill up and get extremely slow

  20. JulianKnodt commented on Sep 18, 2023

    @JulianKnodt
    Contributor

    I think the issue is also because assimp does not respect the root node transformation of the scene hierarchy. I've been messing around with it and it seems that it will swap axes, and while it can output correctly to GLB if the root node transform rotates it, with FBX modifying the root node transform does not seem to have any effect regardless of what the transform is

  21. netpenthe commented on Sep 28, 2023

    @netpenthe

    +1, would be great to fix

  22. kimkulling commented on Mar 13, 2024

    @kimkulling
    Member

    After a looong period of time I found the issue again: #5494

    Feedback would be hightly appreciated.

  23. livinamuk commented on Mar 18, 2024

    @livinamuk

    This is huge. Thank you.

  24. added
    FBX
    Orientation
    Explanation
    on Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExplanationFBXOrientationPostprocessing

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions