ProfessorF Posted December 15, 2013 Share Posted December 15, 2013 I noticed that my Maya model: Was coming out backwards in Babylon: I eventually figured out that it was because Maya is a right-handed coordinate system & Babylon.js is left-handed. I think it's most efficient to code the transformation in the BabylonExporter, so I did the following: 1. Change the winding of the triangles (otherwise faces become invisible)2. Invert Z position3. Invert Z normal The relevant code in BabylonExport.Core > Exporters > ThroughXNA > XNAExporter.cs void ParseMesh(ModelMesh modelMesh, BabylonScene scene, BabylonSkeleton skeleton) { var proxyID = ProxyMesh.CreateBabylonMesh(modelMesh.Name, scene); int indexName = 0; foreach (var part in modelMesh.MeshParts) { var material = exportedMaterials.First(m => m.Name == part.Effect.GetHashCode().ToString()); var indices = new ushort[part.PrimitiveCount * 3]; part.IndexBuffer.GetData(part.StartIndex * 2, indices, 0, indices.Length); for (int ib = 0; ib < indices.Length; ib += 3) // reverse winding of triangles { ushort ti; ti = indices[ib]; indices[ib] = indices[ib + 2]; indices[ib + 2] = ti; } if (part.VertexBuffer.VertexDeclaration.VertexStride >= PositionNormalTexturedWeights.Stride) { var mesh = new Mesh<PositionNormalTexturedWeights>(material); var vertices = new PositionNormalTexturedWeights[part.NumVertices]; part.VertexBuffer.GetData(part.VertexOffset * part.VertexBuffer.VertexDeclaration.VertexStride, vertices, 0, vertices.Length, part.VertexBuffer.VertexDeclaration.VertexStride); for (int index = 0; index < vertices.Length; index++) { vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y; vertices[index].Position.Z = -vertices[index].Position.Z; vertices[index].Normal.Z = -vertices[index].Normal.Z; } mesh.AddPart(indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList()); mesh.CreateBabylonMesh(scene, proxyID, skeleton); } else { if (part.VertexBuffer.VertexDeclaration.VertexStride < 32) return; var mesh = new Mesh<PositionNormalTextured>(material); var vertices = new PositionNormalTextured[part.NumVertices]; part.VertexBuffer.GetData(part.VertexOffset * part.VertexBuffer.VertexDeclaration.VertexStride, vertices, 0, vertices.Length, part.VertexBuffer.VertexDeclaration.VertexStride); for (int index = 0; index < vertices.Length; index++) { vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y; vertices[index].Position.Z = -vertices[index].Position.Z; vertices[index].Normal.Z = -vertices[index].Normal.Z; } mesh.AddPart(indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList()); mesh.CreateBabylonMesh(scene, proxyID, skeleton); } indexName++; } } This fixed the problem: DeltaKosh, should this be a permanent fix, or maybe can you add a flag to the command-line (/rightleft ?) , to invoke the green code? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 16, 2013 Share Posted December 16, 2013 Hello Prof, it can't be a permanent fix because the FBX can be left handed (my dude.fbx is left handed for instance) but I can easily add the switch Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 16, 2013 Share Posted December 16, 2013 I added a "/rl" to the new version You can try it here: http://www.babylonjs.com/prof.zip Quote Link to comment Share on other sites More sharing options...
ProfessorF Posted December 16, 2013 Author Share Posted December 16, 2013 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.