Prechádzať zdrojové kódy

Remove option to export images as binary
Clean up some TODO tags

noalak 8 rokov pred
rodič
commit
e8fcba5cb0

+ 0 - 3
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.GLTFExporter.AbstractMesh.cs

@@ -31,9 +31,6 @@ namespace Max2Babylon
 
             // Transform
             gltfNode.translation = babylonAbstractMesh.position;
-            // TODO - Choose between this method and the extra root node
-            // Switch from left to right handed coordinate system
-            //gltfNode.translation[0] *= -1;
             if (babylonAbstractMesh.rotationQuaternion != null)
             {
                 gltfNode.rotation = babylonAbstractMesh.rotationQuaternion;

+ 4 - 7
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.GLTFExporter.Camera.cs

@@ -5,7 +5,6 @@ namespace Max2Babylon
 {
     partial class BabylonExporter
     {
-        // TODO - Test if ok with a gltf viewer working with custom camera (babylon loader/sandbox doesn't load them)
         private GLTFCamera ExportCamera(BabylonCamera babylonCamera, GLTF gltf, GLTFNode gltfParentNode)
         {
             RaiseMessage("GLTFExporter.Camera | Export camera named: " + babylonCamera.name, 1);
@@ -37,8 +36,6 @@ namespace Max2Babylon
 
             // Transform
             gltfNode.translation = babylonCamera.position;
-            // Switch from left to right handed coordinate system
-            //gltfNode.translation[0] *= -1;
             if (babylonCamera.rotationQuaternion != null)
             {
                 gltfNode.rotation = babylonCamera.rotationQuaternion;
@@ -85,8 +82,8 @@ namespace Max2Babylon
             {
                 case (BabylonCamera.CameraMode.ORTHOGRAPHIC_CAMERA):
                     var gltfCameraOrthographic = new GLTFCameraOrthographic();
-                    gltfCameraOrthographic.xmag = 1; // TODO - How to retreive value from babylon? xmag:The floating-point horizontal magnification of the view
-                    gltfCameraOrthographic.ymag = 1; // TODO - How to retreive value from babylon? ymag:The floating-point vertical magnification of the view
+                    gltfCameraOrthographic.xmag = 1; // Do not bother about it - still mandatory
+                    gltfCameraOrthographic.ymag = 1; // Do not bother about it - still mandatory
                     gltfCameraOrthographic.zfar = babylonCamera.maxZ;
                     gltfCameraOrthographic.znear = babylonCamera.minZ;
 
@@ -95,8 +92,8 @@ namespace Max2Babylon
                     break;
                 case (BabylonCamera.CameraMode.PERSPECTIVE_CAMERA):
                     var gltfCameraPerspective = new GLTFCameraPerspective();
-                    gltfCameraPerspective.aspectRatio = null; // 0.8f; // TODO - How to retreive value from babylon? The aspect ratio in babylon is computed based on the engine rather than set on a camera (aspectRatio = _gl.drawingBufferWidth / _gl.drawingBufferHeight)
-                    gltfCameraPerspective.yfov = babylonCamera.fov; // WARNING - Babylon camera fov mode is assumed to be vertical (FOVMODE_VERTICAL_FIXED)
+                    gltfCameraPerspective.aspectRatio = null; // Do not bother about it - use default glTF value
+                    gltfCameraPerspective.yfov = babylonCamera.fov; // Babylon camera fov mode is assumed to be vertical (FOVMODE_VERTICAL_FIXED)
                     gltfCameraPerspective.zfar = babylonCamera.maxZ;
                     gltfCameraPerspective.znear = babylonCamera.minZ;
 

+ 0 - 2
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.GLTFExporter.Light.cs

@@ -36,8 +36,6 @@ namespace Max2Babylon
 
             // Transform
             gltfNode.translation = babylonLight.position;
-            // Switch from left to right handed coordinate system
-            //gltfNode.translation[0] *= -1;
             // No rotation defined for babylon light. Use identity instead.
             gltfNode.rotation = new float[4] { 0, 0, 0, 1 };
             // No scaling defined for babylon light. Use identity instead.

+ 23 - 34
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.GLTFExporter.cs

@@ -17,7 +17,7 @@ namespace Max2Babylon
 
         private List<BabylonNode> babylonNodes;
 
-        public void ExportGltf(BabylonScene babylonScene, string outputFile, bool generateBinary, bool exportGltfImagesAsBinary)
+        public void ExportGltf(BabylonScene babylonScene, string outputFile, bool generateBinary)
         {
             RaiseMessage("GLTFExporter | Export outputFile=" + outputFile + " generateBinary=" + generateBinary);
             RaiseMessage("GLTFExporter | Exportation started", Color.Blue);
@@ -73,10 +73,8 @@ namespace Max2Babylon
                 ReportProgressChanged((int)progression);
                 CheckCancelled();
             });
-
-            // TODO - Choose between this method and the reverse of X axis
+            
             // Switch from left to right handed coordinate system
-            RaiseMessage("GLTFExporter | Exporting root node");
             var tmpNodesList = new List<int>(scene.NodesList);
             var rootNode = new BabylonMesh
             {
@@ -85,7 +83,7 @@ namespace Max2Babylon
                 scaling = new float[] { 1, 1, -1 },
                 idGroupInstance = -1
             };
-            scene.NodesList.Clear();
+            scene.NodesList.Clear(); // Only root node is listed in node list
             GLTFNode gltfRootNode = ExportAbstractMesh(rootNode, gltf, null);
             gltfRootNode.ChildrenList.AddRange(tmpNodesList);
 
@@ -97,11 +95,6 @@ namespace Max2Babylon
                 CheckCancelled();
             };
             RaiseMessage(string.Format("GLTFExporter | Nb materials exported: {0}", gltf.MaterialsList.Count), Color.Gray, 1);
-            
-            if (exportGltfImagesAsBinary)
-            {
-                SwitchImagesFromUriToBinary(gltf);
-            }
 
             // Cast lists to arrays
             gltf.Prepare();
@@ -145,27 +138,17 @@ namespace Max2Babylon
                 {
                     gltfBuffer.uri = null;
                 }
-                // Switch images to binary if not already done
-                // TODO - make it optional
-                if (!exportGltfImagesAsBinary)
+                // Switch images to binary
+                var imageBufferViews = SwitchImagesFromUriToBinary(gltf);
+                imageBufferViews.ForEach(imageBufferView =>
                 {
-                    var imageBufferViews = SwitchImagesFromUriToBinary(gltf);
-                    imageBufferViews.ForEach(imageBufferView =>
-                    {
-                        imageBufferView.Buffer.bytesList.AddRange(imageBufferView.bytesList);
-                    });
-                }
+                    imageBufferView.Buffer.bytesList.AddRange(imageBufferView.bytesList);
+                });
                 gltf.Prepare();
                 // Serialize gltf data to JSON string then convert it to bytes
                 byte[] chunkDataJson = Encoding.ASCII.GetBytes(gltfToJson(gltf));
                 // JSON chunk must be padded with trailing Space chars (0x20) to satisfy alignment requirements 
-                var nbSpaceToAdd = chunkDataJson.Length % 4 == 0 ? 0 : (4 - chunkDataJson.Length % 4);
-                var chunkDataJsonList = new List<byte>(chunkDataJson);
-                for (int i = 0; i < nbSpaceToAdd; i++)
-                {
-                    chunkDataJsonList.Add(0x20);
-                }
-                chunkDataJson = chunkDataJsonList.ToArray();
+                chunkDataJson = padChunk(chunkDataJson, 4, 0x20);
                 UInt32 chunkLengthJson = (UInt32)chunkDataJson.Length;
                 length += chunkLengthJson + 8; // 8 = JSON chunk header length
                 
@@ -352,14 +335,8 @@ namespace Max2Babylon
                         image.Save(m, imageFormat);
                         byte[] imageBytes = m.ToArray();
 
-                        // JSON chunk must be padded with trailing Space chars (0x20) to satisfy alignment requirements 
-                        var nbSpaceToAdd = imageBytes.Length % 4 == 0 ? 0 : (4 - imageBytes.Length % 4);
-                        var imageBytesList = new List<byte>(imageBytes);
-                        for (int i = 0; i < nbSpaceToAdd; i++)
-                        {
-                            imageBytesList.Add(0x00);
-                        }
-                        imageBytes = imageBytesList.ToArray();
+                        // Chunk must be padded with trailing zeros (0x00) to satisfy alignment requirements
+                        imageBytes = padChunk(imageBytes, 4, 0x00);
 
                         // BufferView - Image
                         var buffer = gltf.buffer;
@@ -387,5 +364,17 @@ namespace Max2Babylon
             }
             return imageBufferViews;
         }
+
+        private byte[] padChunk(byte[] chunk, int padding, byte trailingChar)
+        {
+            var chunkModuloPadding = chunk.Length % padding;
+            var nbCharacterToAdd = chunkModuloPadding == 0 ? 0 : (padding - chunkModuloPadding);
+            var chunkList = new List<byte>(chunk);
+            for (int i = 0; i < nbCharacterToAdd; i++)
+            {
+                chunkList.Add(trailingChar);
+            }
+            return chunkList.ToArray();
+        }
     }
 }

+ 2 - 2
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.cs

@@ -77,7 +77,7 @@ namespace Max2Babylon
             }
         }
 
-        public async Task ExportAsync(string outputFile, bool generateManifest, bool onlySelected, bool generateBinary, bool exportGltf, bool exportGltfImagesAsBinary, Form callerForm)
+        public async Task ExportAsync(string outputFile, bool generateManifest, bool onlySelected, bool generateBinary, bool exportGltf, Form callerForm)
         {
             var gameConversionManger = Loader.Global.ConversionManager;
             gameConversionManger.CoordSystem = Autodesk.Max.IGameConversionManager.CoordSystem.D3d;
@@ -298,7 +298,7 @@ namespace Max2Babylon
             // Export glTF
             if (exportGltf)
             {
-                ExportGltf(babylonScene, outputFile, generateBinary, exportGltfImagesAsBinary);
+                ExportGltf(babylonScene, outputFile, generateBinary);
             }
 
             watch.Stop();

+ 0 - 15
Exporters/3ds Max/Max2Babylon/Forms/ExporterForm.Designer.cs

@@ -48,7 +48,6 @@
             this.butExportAndRun = new System.Windows.Forms.Button();
             this.butClose = new System.Windows.Forms.Button();
             this.chkGltf = new System.Windows.Forms.CheckBox();
-            this.chkGltfImagesAsBinary = new System.Windows.Forms.CheckBox();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
             this.groupBox1.SuspendLayout();
             this.SuspendLayout();
@@ -181,7 +180,6 @@
             // 
             this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
-            this.groupBox1.Controls.Add(this.chkGltfImagesAsBinary);
             this.groupBox1.Controls.Add(this.chkBinary);
             this.groupBox1.Controls.Add(this.chkOnlySelected);
             this.groupBox1.Controls.Add(this.chkAutoSave);
@@ -279,18 +277,6 @@
             this.chkGltf.UseVisualStyleBackColor = true;
             this.chkGltf.CheckedChanged += new System.EventHandler(this.chkGltf_CheckedChanged);
             // 
-            // chkGltfImageAsBinary
-            // 
-            this.chkGltfImagesAsBinary.AutoSize = true;
-            this.chkGltfImagesAsBinary.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.chkGltfImagesAsBinary.Location = new System.Drawing.Point(166, 127);
-            this.chkGltfImagesAsBinary.Name = "chkGltfImagesAsBinary";
-            this.chkGltfImagesAsBinary.Size = new System.Drawing.Size(158, 17);
-            this.chkGltfImagesAsBinary.TabIndex = 18;
-            this.chkGltfImagesAsBinary.Text = "Export glTF images as binary";
-            this.chkGltfImagesAsBinary.UseVisualStyleBackColor = true;
-            this.chkGltfImagesAsBinary.CheckedChanged += new System.EventHandler(this.checkGltfImagesAsBinary_CheckedChanged);
-            // 
             // ExporterForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -344,6 +330,5 @@
         private System.Windows.Forms.Button butClose;
         private System.Windows.Forms.CheckBox chkBinary;
         private System.Windows.Forms.CheckBox chkGltf;
-        private System.Windows.Forms.CheckBox chkGltfImagesAsBinary;
     }
 }

+ 1 - 8
Exporters/3ds Max/Max2Babylon/Forms/ExporterForm.cs

@@ -33,7 +33,6 @@ namespace Max2Babylon
             Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
             Tools.PrepareCheckBox(chkBinary, Loader.Core.RootNode, "babylonjs_binary");
             Tools.PrepareCheckBox(chkGltf, Loader.Core.RootNode, "babylonjs_exportGltf");
-            Tools.PrepareCheckBox(chkGltfImagesAsBinary, Loader.Core.RootNode, "babylonjs_exportGltfImagesAsBinary");
         }
 
         private void butBrowse_Click(object sender, EventArgs e)
@@ -58,7 +57,6 @@ namespace Max2Babylon
             Tools.UpdateCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
             Tools.UpdateCheckBox(chkBinary, Loader.Core.RootNode, "babylonjs_binary");
             Tools.UpdateCheckBox(chkGltf, Loader.Core.RootNode, "babylonjs_exportGltf");
-            Tools.UpdateCheckBox(chkGltfImagesAsBinary, Loader.Core.RootNode, "babylonjs_exportGltfImagesAsBinary");
 
             Loader.Core.RootNode.SetLocalData(txtFilename.Text);
 
@@ -125,7 +123,7 @@ namespace Max2Babylon
                 exporter.AutoSave3dsMaxFile = chkAutoSave.Checked;
                 exporter.ExportHiddenObjects = chkHidden.Checked;
                 exporter.CopyTexturesToOutput = chkCopyTextures.Checked;
-                await exporter.ExportAsync(txtFilename.Text, chkManifest.Checked, chkOnlySelected.Checked, chkBinary.Checked, chkGltf.Checked, chkGltfImagesAsBinary.Checked, this);
+                await exporter.ExportAsync(txtFilename.Text, chkManifest.Checked, chkOnlySelected.Checked, chkBinary.Checked, chkGltf.Checked, this);
             }
             catch (OperationCanceledException)
             {
@@ -234,10 +232,5 @@ namespace Max2Babylon
         {
 
         }
-
-        private void checkGltfImagesAsBinary_CheckedChanged(object sender, EventArgs e)
-        {
-
-        }
     }
 }