Просмотр исходного кода

Added DeltaKosh's command line flag /rl, and used flag to control whether
or not the Right->Left coordinate transformation took place.

professorf 11 лет назад
Родитель
Сommit
8535d7d858

+ 5 - 2
Exporters/XNA - OBJ/BabylonExport.Core/Entities/StandardMaterial.cs

@@ -69,8 +69,11 @@ namespace BabylonExport.Core
 
             babylonMaterial.diffuseTexture = new BabylonTexture();
             babylonMaterial.diffuseTexture.name = Path.GetFileName(DiffuseTexture);
-            if (babylonMaterial.diffuseTexture.name.ToLower().EndsWith(".png"))  // Only PNGs have transparency, otherwise .JPG
-                babylonMaterial.diffuseTexture.hasAlpha = true; 
+
+            if (babylonMaterial.diffuseTexture.name.ToLower().EndsWith(".png"))
+            {
+                babylonMaterial.diffuseTexture.hasAlpha = true;
+            }
 
             scene.AddTexture(DiffuseTexture);
         }

+ 1 - 1
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/IExporter.cs

@@ -8,6 +8,6 @@ namespace BabylonExport.Core
 
         string SupportedExtensions { get; }
 
-        void GenerateBabylonFile(string file, string outputFile, bool skinned);
+        void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft);
     }
 }

+ 1 - 1
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/MXB/NovaExporter.cs

@@ -39,7 +39,7 @@ namespace BabylonExport.Core.Exporters
             }
         }
 
-        public void GenerateBabylonFile(string file, string outputFile, bool skinned)
+        public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft)
         {
             try
             {

+ 1 - 1
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/OBJ/ObjExporter.cs

@@ -35,7 +35,7 @@ namespace BabylonExport.Core.Exporters
             }
         }
 
-        public void GenerateBabylonFile(string file, string outputFile, bool skinned)
+        public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft)
         {
             var text = File.ReadAllText(file);
 

+ 29 - 24
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/ThroughXNA/XNAExporter.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Linq;
 using System.Runtime.Serialization.Json;
 using System.Windows.Forms;
+using BabylonExport.Core.Exporters.FBX;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
 using SkinnedModel;
@@ -25,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);
@@ -53,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
             {
@@ -78,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();
@@ -115,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);
             }
@@ -175,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;
@@ -185,17 +186,18 @@ namespace BabylonExport.Core.Exporters.XNA
                 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 Needed for Right-Left Coordinate System
+
+                if (rightToLeft)
                 {
-                    ushort ti;
-                    ti = indices[ib];
-                    indices[ib] = indices[ib + 2];
-                    indices[ib + 2] = ti;
+                    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);
@@ -204,19 +206,21 @@ namespace BabylonExport.Core.Exporters.XNA
                     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;
-                        // Negate Position.Z & Normal.Z -- Needed for Right-Left Coordinate System
-                        vertices[index].Position.Z = -vertices[index].Position.Z;
-                        vertices[index].Normal.Z = -vertices[index].Normal.Z;
+                        if (rightToLeft)
+                        {
+                            vertices[index].Position.Z = -vertices[index].Position.Z;
+                            vertices[index].Normal.Z = -vertices[index].Normal.Z;
+                        }
                     }
-                    // Prefix MeshName to MeshParts -- MeshName#MeshPartIndex
+
                     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 < 32) return; // Error: Not a PositionNormalTextured mesh!
+                    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);
@@ -224,12 +228,13 @@ namespace BabylonExport.Core.Exporters.XNA
                     for (int index = 0; index < vertices.Length; index++)
                     {
                         vertices[index].TextureCoordinates.Y = 1.0f - vertices[index].TextureCoordinates.Y;
-                        // Negate Position.Z & Normal.Z -- Needed for Right-Left Coordinate System
-                        vertices[index].Position.Z = -vertices[index].Position.Z;
-                        vertices[index].Normal.Z = -vertices[index].Normal.Z;
+                        if (rightToLeft)
+                        {
+                            vertices[index].Position.Z = -vertices[index].Position.Z;
+                            vertices[index].Normal.Z = -vertices[index].Normal.Z;
+                        }
                     }
 
-                    // Prefix MeshName to MeshParts -- MeshName#MeshPartIndex
                     mesh.AddPart(modelMesh.Name + "#" + indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
                     mesh.CreateBabylonMesh(scene, proxyID, skeleton);
                 }
@@ -241,7 +246,7 @@ namespace BabylonExport.Core.Exporters.XNA
         void ParseEffect(Effect effect, BabylonScene scene)
         {
             var material = new StandardMaterial(effect.GetHashCode().ToString());
-            
+
             exportedMaterials.Add(material);
 
             var basicEffect = effect as BasicEffect;

+ 6 - 2
Exporters/XNA - OBJ/BabylonExport/Program.cs

@@ -43,6 +43,7 @@ namespace BabylonExport
                     // Parsing arguments
                     string input = "";
                     bool skinned = false;
+                    bool rightToLeft = false;
                     foreach (var arg in args)
                     {
                         var order = arg.Substring(0, 3);
@@ -58,6 +59,9 @@ namespace BabylonExport
                             case "/sk":
                                 skinned = true;
                                 break;
+                            case "/rl":
+                                rightToLeft = true;
+                                break;
                             default:
                                 DisplayUsage();
                                 return;
@@ -104,7 +108,7 @@ namespace BabylonExport
                                 Console.WriteLine("Generation of " + outputName + " started");
                                 Console.WriteLine();
                                 Console.ResetColor();
-                                importer.GenerateBabylonFile(input, outputName, skinned);
+                                importer.GenerateBabylonFile(input, outputName, skinned, rightToLeft);
                                 Console.ForegroundColor = ConsoleColor.Green;
                                 Console.WriteLine();
                                 Console.WriteLine();
@@ -163,7 +167,7 @@ namespace BabylonExport
 
         static void DisplayUsage()
         {
-            Console.WriteLine("Babylon Import usage: BabylonImport.exe /i:\"source file\" /o:\"output folder\" [/sk]");
+            Console.WriteLine("Babylon Import usage: BabylonImport.exe /i:\"source file\" /o:\"output folder\" [/sk] [/rl]");
         }
     }
 }