Reputation: 5615
I have a simple .blend level which looks like it's flipped when importing with Assimp:
Blender uses Z as its Up vector, my engine uses Y. There are no export/save options in Blender that allows me to set that in .blend
Afaik Assimp should handle this for me. Here's how I'm loading the model, converting it to a runtime format for my engine:
// vertices, normals and uvs
{
u32 VertexCount = SrcMesh->mNumVertices;
u32 ByteCount = VertexCount * sizeof(f32) * 3;
DstMesh->VerticesCount = VertexCount;
DstMesh->Vertices = new vec[VertexCount];
memcpy(DstMesh->Vertices, SrcMesh->mVertices, ByteCount);
FAIL_IF_NOT(SrcMesh->mNormals, "Model doesn't have normals");
DstMesh->Normals = new vec[VertexCount];
memcpy(DstMesh->Normals, SrcMesh->mNormals, ByteCount);
FAIL_IF_NOT(SrcMesh->mTextureCoords[0], "Model doesn't have UVs");
DstMesh->UVs = new vec[VertexCount];
memcpy(DstMesh->UVs, SrcMesh->mTextureCoords[0], ByteCount);
}
// faces
{
DstMesh->FacesCount = SrcMesh->mNumFaces;
DstMesh->Faces = new mesh_face[DstMesh->FacesCount];
For(i32, F, DstMesh->FacesCount)
{
aiFace *SrcFace = &SrcMesh->mFaces[F];
mesh_face *DstFace = &DstMesh->Faces[F];
FAIL_IF_NOT(SrcFace->mNumIndices == 3, "Model is not triangulated. Face index %d has %d indices", F, SrcFace->mNumIndices);
memcpy(DstFace->Indices, SrcFace->mIndices, 3 * sizeof(u32));
}
}
Note I also tried finding the node that mesh's belong to, and transforming the vertices/normals by that node's final transform (by final I mean I recurse all the node's parents and apply their transforms and finally the node's local transform) -- But that didn't do anything because the mesh has no parent.
My questions are:
Here's the referenced model: https://www.dropbox.com/s/hwsyfyqip5pqhrh/StusRoom.blend?dl=0
Thanks for any help!
Upvotes: 1
Views: 783
Reputation: 16
I figured out that Blender expect .glb files to be in XZ-Y axis order, so perhaps this is true for .blend files as well.
Regarding the AssImp - I was dealing with this issue myself on my work, and I figured out that the problem is the AssImp - check the link: https://github.com/assimp/assimp/issues/849 (as you can see this is still open, even though it's over 5 years old now)
I believe you need to figure out some workaround to somehow manually rotate the file, since assimp will rotate it for you.
Hope it helps! Best regards
Upvotes: 0