浏览代码

3dsmax exporter can now generate binary babylon files

David Catuhe 10 年之前
父节点
当前提交
335223146d

二进制
Exporters/3ds Max/Max2Babylon-0.12.0.zip


二进制
Exporters/3ds Max/Max2Babylon-0.13.0.zip


+ 4 - 0
Exporters/3ds Max/Max2Babylon/2015/Max2Babylon2015.csproj

@@ -46,6 +46,10 @@
       <HintPath>Refs\2015\Autodesk.Max.dll</HintPath>
       <Private>False</Private>
     </Reference>
+    <Reference Include="BabylonFileConverter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Refs\BabylonFileConverter.dll</HintPath>
+    </Reference>
     <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>

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

@@ -17,7 +17,7 @@ namespace Max2Babylon
             return new BabylonAnimationKey
             {
                 frame = key.Time / Ticks,
-                values = new []{key.Val}
+                values = new[] { key.Val }
             };
         }
 
@@ -78,7 +78,7 @@ namespace Max2Babylon
 
                     return new BabylonAnimationKey
                     {
-                        frame = key.Time/Ticks,
+                        frame = key.Time / Ticks,
                         values = key.Val.ToArraySwitched()
                     };
                 }))
@@ -94,7 +94,7 @@ namespace Max2Babylon
 
                     return new BabylonAnimationKey
                     {
-                        frame = key.Time/Ticks,
+                        frame = key.Time / Ticks,
                         values = key.Val.S.ToArraySwitched()
                     };
                 });
@@ -187,11 +187,11 @@ namespace Max2Babylon
 
         static void RemoveLinearAnimationKeys(List<BabylonAnimationKey> keys)
         {
-            for(int ixFirst = keys.Count-3; ixFirst >=0; --ixFirst)
+            for (int ixFirst = keys.Count - 3; ixFirst >= 0; --ixFirst)
             {
                 while (keys.Count - ixFirst >= 3)
                 {
-                    if(!RemoveAnimationKey(keys, ixFirst))
+                    if (!RemoveAnimationKey(keys, ixFirst))
                     {
                         break;
                     }
@@ -204,7 +204,7 @@ namespace Max2Babylon
             double weight2 = (double)(frame1 - frame0) / (double)(frame2 - frame0);
             double weight0 = 1 - weight2;
             float[] result = new float[value0.Length];
-            for(int i = 0; i < result.Length; ++i)
+            for (int i = 0; i < result.Length; ++i)
             {
                 result[i] = (float)(value0[i] * weight0 + value2[i] * weight2);
             }
@@ -218,7 +218,7 @@ namespace Max2Babylon
             var last = keys[ixFirst + 2];
 
             // first pass, frame equality
-            if(first.values.IsEqualTo(last.values) && first.values.IsEqualTo(middle.values))
+            if (first.values.IsEqualTo(last.values) && first.values.IsEqualTo(middle.values))
             {
                 keys.RemoveAt(ixFirst + 1);
                 return true;
@@ -232,7 +232,7 @@ namespace Max2Babylon
                 return true;
             }
             return false;
-            
+
         }
 
         private static void ExportAnimation(string property, List<BabylonAnimation> animations, Func<int, float[]> extractValueFunc, BabylonAnimation.DataType dataType)
@@ -246,13 +246,13 @@ namespace Max2Babylon
             {
                 var current = extractValueFunc(key);
 
-                
-                    keys.Add(new BabylonAnimationKey()
-                    {
-                        frame = key / Ticks,
-                        values = current
-                    });
-                
+
+                keys.Add(new BabylonAnimationKey()
+                {
+                    frame = key / Ticks,
+                    values = current
+                });
+
 
                 previous = current;
             }
@@ -294,6 +294,6 @@ namespace Max2Babylon
                     animations.Add(babylonAnimation);
                 }
             }
-        }        
+        }
     }
 }

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

@@ -22,8 +22,6 @@ namespace Max2Babylon
         public event Action<string, Color, int, bool> OnMessage;
         public event Action<string, int> OnError;
 
-        string maxSceneFileName;
-
         readonly List<string> alreadyExportedTextures = new List<string>();
 
         public bool AutoSave3dsMaxFile { get; set; }
@@ -32,7 +30,9 @@ namespace Max2Babylon
 
         public bool CopyTexturesToOutput { get; set; }
 
-        private bool exportQuaternionsInsteadOfEulers;
+        public string MaxSceneFileName { get; set; }
+
+        public bool ExportQuaternionsInsteadOfEulers { get; set; }
 
         void ReportProgressChanged(int progress)
         {
@@ -80,7 +80,7 @@ namespace Max2Babylon
             }
         }
 
-        public async Task ExportAsync(string outputFile, bool generateManifest, bool onlySelected, Form callerForm)
+        public async Task ExportAsync(string outputFile, bool generateManifest, bool onlySelected, bool generateBinary, Form callerForm)
         {
             var gameConversionManger = Loader.Global.ConversionManager;
             gameConversionManger.CoordSystem = Autodesk.Max.IGameConversionManager.CoordSystem.D3d;
@@ -89,7 +89,7 @@ namespace Max2Babylon
             gameScene.InitialiseIGame(onlySelected);
             gameScene.SetStaticFrame(0);
 
-            maxSceneFileName = gameScene.SceneFileName;
+            MaxSceneFileName = gameScene.SceneFileName;
 
             IsCancelled = false;
             RaiseMessage("Exportation started", Color.Blue);
@@ -127,7 +127,7 @@ namespace Max2Babylon
             babylonScene.ambientColor = Loader.Core.GetAmbient(0, Tools.Forever).ToArray();
 
             babylonScene.gravity = rawScene.GetVector3Property("babylonjs_gravity");
-            exportQuaternionsInsteadOfEulers = rawScene.GetBoolProperty("babylonjs_exportquaternions", 1);
+            ExportQuaternionsInsteadOfEulers = rawScene.GetBoolProperty("babylonjs_exportquaternions", 1);
 
             // Cameras
             BabylonCamera mainCamera = null;
@@ -277,6 +277,15 @@ namespace Max2Babylon
                 }
             });
 
+            // Binary
+            if (generateBinary)
+            {
+                RaiseMessage("Generating binary files");
+                BabylonFileConverter.BinaryConverter.Convert(outputFile, Path.GetDirectoryName(outputFile) + "\\Binary",
+                    message => RaiseMessage(message, 1),
+                    error => RaiseError(error, 1));
+            }
+
             ReportProgressChanged(100);
             watch.Stop();
             RaiseMessage(string.Format("Exportation done in {0:0.00}s", watch.ElapsedMilliseconds / 1000.0), Color.Blue);

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

@@ -47,6 +47,7 @@
             this.chkHidden = new System.Windows.Forms.CheckBox();
             this.butExportAndRun = new System.Windows.Forms.Button();
             this.butClose = new System.Windows.Forms.Button();
+            this.chkBinary = new System.Windows.Forms.CheckBox();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
             this.groupBox1.SuspendLayout();
             this.SuspendLayout();
@@ -179,6 +180,7 @@
             // 
             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.chkBinary);
             this.groupBox1.Controls.Add(this.chkOnlySelected);
             this.groupBox1.Controls.Add(this.chkAutoSave);
             this.groupBox1.Controls.Add(this.chkHidden);
@@ -198,7 +200,7 @@
             // 
             this.chkOnlySelected.AutoSize = true;
             this.chkOnlySelected.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.chkOnlySelected.Location = new System.Drawing.Point(362, 81);
+            this.chkOnlySelected.Location = new System.Drawing.Point(320, 81);
             this.chkOnlySelected.Name = "chkOnlySelected";
             this.chkOnlySelected.Size = new System.Drawing.Size(118, 17);
             this.chkOnlySelected.TabIndex = 15;
@@ -209,7 +211,7 @@
             // 
             this.chkAutoSave.AutoSize = true;
             this.chkAutoSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.chkAutoSave.Location = new System.Drawing.Point(196, 104);
+            this.chkAutoSave.Location = new System.Drawing.Point(166, 104);
             this.chkAutoSave.Name = "chkAutoSave";
             this.chkAutoSave.Size = new System.Drawing.Size(130, 17);
             this.chkAutoSave.TabIndex = 14;
@@ -220,7 +222,7 @@
             // 
             this.chkHidden.AutoSize = true;
             this.chkHidden.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.chkHidden.Location = new System.Drawing.Point(196, 81);
+            this.chkHidden.Location = new System.Drawing.Point(166, 81);
             this.chkHidden.Name = "chkHidden";
             this.chkHidden.Size = new System.Drawing.Size(125, 17);
             this.chkHidden.TabIndex = 13;
@@ -252,6 +254,17 @@
             this.butClose.UseVisualStyleBackColor = true;
             this.butClose.Click += new System.EventHandler(this.butClose_Click);
             // 
+            // chkBinary
+            // 
+            this.chkBinary.AutoSize = true;
+            this.chkBinary.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.chkBinary.Location = new System.Drawing.Point(320, 104);
+            this.chkBinary.Name = "chkBinary";
+            this.chkBinary.Size = new System.Drawing.Size(156, 17);
+            this.chkBinary.TabIndex = 16;
+            this.chkBinary.Text = "Also generate binary version";
+            this.chkBinary.UseVisualStyleBackColor = true;
+            // 
             // ExporterForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -302,5 +315,6 @@
         private System.Windows.Forms.Button butExportAndRun;
         private System.Windows.Forms.CheckBox chkOnlySelected;
         private System.Windows.Forms.Button butClose;
+        private System.Windows.Forms.CheckBox chkBinary;
     }
 }

+ 4 - 2
Exporters/3ds Max/Max2Babylon/Forms/ExporterForm.cs

@@ -30,7 +30,8 @@ namespace Max2Babylon
             Tools.PrepareCheckBox(chkCopyTextures, Loader.Core.RootNode, "babylonjs_copytextures", 1);
             Tools.PrepareCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
             Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 1);
-            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");   
+            Tools.PrepareCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
+            Tools.PrepareCheckBox(chkBinary, Loader.Core.RootNode, "babylonjs_binary"); 
         }
 
         private void butBrowse_Click(object sender, EventArgs e)
@@ -53,6 +54,7 @@ namespace Max2Babylon
             Tools.UpdateCheckBox(chkHidden, Loader.Core.RootNode, "babylonjs_exporthidden");
             Tools.UpdateCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave");
             Tools.UpdateCheckBox(chkOnlySelected, Loader.Core.RootNode, "babylonjs_onlySelected");
+            Tools.UpdateCheckBox(chkBinary, Loader.Core.RootNode, "babylonjs_binary");
 
             Loader.Core.RootNode.SetLocalData(txtFilename.Text);
 
@@ -119,7 +121,7 @@ namespace Max2Babylon
                 exporter.AutoSave3dsMaxFile = chkAutoSave.Checked;
                 exporter.ExportHiddenObjects = chkHidden.Checked;
                 exporter.CopyTexturesToOutput = chkCopyTextures.Checked;
-                await exporter.ExportAsync(txtFilename.Text, chkManifest.Checked, chkOnlySelected.Checked, this);
+                await exporter.ExportAsync(txtFilename.Text, chkManifest.Checked, chkOnlySelected.Checked, chkBinary.Checked, this);
             }
             catch (OperationCanceledException)
             {

+ 4 - 6
Exporters/3ds Max/Max2Babylon/Forms/ObjectPropertiesForm.cs

@@ -37,12 +37,10 @@ namespace Max2Babylon
             {
                 var node = Loader.Core.GetSelNode(index);
 
-                //if (node.ObjectRef != null && node.ObjectRef.Eval(0).Obj.SuperClassID == SClass_ID.Geomobject)
-                //{
-
-                // handle "virtual objects" // todo : differentiate them and remove mesh specific settings (keep only animation settings)
-                objects.Add(node);
-                //}
+                if (node.ObjectRef != null && node.ObjectRef.Eval(0).Obj.SuperClassID == SClass_ID.Geomobject)
+                {
+                    objects.Add(node);
+                }
             }
 
             Tools.PrepareCheckBox(chkNoExport, objects, "babylonjs_noexport");

+ 4 - 0
Exporters/3ds Max/Max2Babylon/Max2Babylon.csproj

@@ -46,6 +46,9 @@
       <HintPath>Refs\Autodesk.Max.dll</HintPath>
       <Private>False</Private>
     </Reference>
+    <Reference Include="BabylonFileConverter">
+      <HintPath>Refs\BabylonFileConverter.dll</HintPath>
+    </Reference>
     <Reference Include="Newtonsoft.Json">
       <HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
@@ -132,6 +135,7 @@
   </ItemGroup>
   <ItemGroup>
     <Content Include="Refs\Autodesk.Max.dll" />
+    <Content Include="Refs\BabylonFileConverter.dll" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Forms\LightPropertiesForm.resx">

二进制
Exporters/3ds Max/Max2Babylon/Refs/BabylonFileConverter.dll


+ 1 - 0
Exporters/3ds Max/Max2Babylon/Tools/Tools.cs

@@ -26,6 +26,7 @@ namespace Max2Babylon
         {
             return Assembly.Load("Autodesk.Max.Wrappers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
         }
+
         public static IIGameCamera AsGameCamera(this IIGameObject obj)
         {
             var type = GetWrappersAssembly().GetType("Autodesk.Max.Wrappers.IGameCamera");

+ 1 - 2
Exporters/3ds Max/Max2Babylon/packages.config

@@ -1,5 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="Newtonsoft.Json" version="6.0.6" targetFramework="net45" />
-  <package id="SharpDX" version="2.6.3" targetFramework="net45" />
+  <package id="Newtonsoft.Json" version="6.0.7" targetFramework="net45" />
 </packages>