|
@@ -26,7 +26,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
|
|
|
private int texturesCount = 0;
|
|
|
|
|
|
- public void GenerateBabylonFile(string file, string outputFile, bool skinned)
|
|
|
+ public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft)
|
|
|
{
|
|
|
if (OnImportProgressChanged != null)
|
|
|
OnImportProgressChanged(0);
|
|
@@ -54,7 +54,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
if (string.IsNullOrEmpty(buildError))
|
|
|
{
|
|
|
var model = contentManager.Load<Model>("Model");
|
|
|
- ParseModel(model, scene);
|
|
|
+ ParseModel(model, scene, rightToLeft);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -79,7 +79,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
OnImportProgressChanged(100);
|
|
|
}
|
|
|
|
|
|
- void ParseModel(Model model, BabylonScene scene)
|
|
|
+ void ParseModel(Model model, BabylonScene scene, bool rightToLeft)
|
|
|
{
|
|
|
var effects = model.Meshes.SelectMany(m => m.Effects).ToList();
|
|
|
var meshes = model.Meshes.ToList();
|
|
@@ -116,7 +116,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
|
|
|
foreach (var mesh in meshes)
|
|
|
{
|
|
|
- ParseMesh(mesh, scene, currentSkeleton);
|
|
|
+ ParseMesh(mesh, scene, currentSkeleton, rightToLeft);
|
|
|
if (OnImportProgressChanged != null)
|
|
|
OnImportProgressChanged(((progress++) * 100) / total);
|
|
|
}
|
|
@@ -176,7 +176,7 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
skeleton.bones = bones.ToArray();
|
|
|
}
|
|
|
|
|
|
- void ParseMesh(ModelMesh modelMesh, BabylonScene scene, BabylonSkeleton skeleton)
|
|
|
+ void ParseMesh(ModelMesh modelMesh, BabylonScene scene, BabylonSkeleton skeleton, bool rightToLeft)
|
|
|
{
|
|
|
var proxyID = ProxyMesh.CreateBabylonMesh(modelMesh.Name, scene);
|
|
|
int indexName = 0;
|
|
@@ -188,6 +188,16 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
var indices = new ushort[part.PrimitiveCount * 3];
|
|
|
part.IndexBuffer.GetData(part.StartIndex * 2, indices, 0, indices.Length);
|
|
|
|
|
|
+ if (rightToLeft)
|
|
|
+ {
|
|
|
+ for (int ib = 0; ib < indices.Length; ib += 3) // reverse winding of triangles
|
|
|
+ {
|
|
|
+ ushort 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);
|
|
@@ -198,13 +208,19 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
for (int index = 0; index < vertices.Length; index++)
|
|
|
{
|
|
|
vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y;
|
|
|
+ if (rightToLeft)
|
|
|
+ {
|
|
|
+ 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.AddPart(modelMesh.Name+"#"+indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
|
|
|
mesh.CreateBabylonMesh(scene, proxyID, skeleton);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ if (part.VertexBuffer.VertexDeclaration.VertexStride < PositionNormalTextured.Stride) return; // Error: Not a PositionNormalTextured mesh!
|
|
|
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);
|
|
@@ -212,9 +228,14 @@ namespace BabylonExport.Core.Exporters.XNA
|
|
|
for (int index = 0; index < vertices.Length; index++)
|
|
|
{
|
|
|
vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y;
|
|
|
+ if (rightToLeft)
|
|
|
+ {
|
|
|
+ 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.AddPart(modelMesh.Name + "#" + indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
|
|
|
mesh.CreateBabylonMesh(scene, proxyID, skeleton);
|
|
|
}
|
|
|
|