Browse Source

Small foxes to 3dsmax exporter

David Catuhe 11 năm trước cách đây
mục cha
commit
c115b3eca3

BIN
Exporters/3ds Max/Max2Babylon-0.7.5.zip


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

@@ -137,6 +137,11 @@ namespace Max2Babylon
                 keys.Add(generateFunc(index, keyControl));
             }
 
+            if (keys.Count == 0)
+            {
+                return false;
+            }
+
             var end = Loader.Core.AnimRange.End;
             if (keys[keys.Count - 1].frame != end / Ticks)
             {

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

@@ -7,6 +7,23 @@ namespace Max2Babylon
 {
     partial class BabylonExporter
     {
+        void ExportDefaultLight(BabylonScene babylonScene)
+        {
+            var babylonLight = new BabylonLight();
+            babylonLight.name = "Default light";
+            babylonLight.id = Guid.NewGuid().ToString();
+            babylonLight.type = 3;
+            babylonLight.groundColor = new float[] { 0, 0, 0 };
+            babylonLight.direction = new[] { 0, 1.0f, 0 };
+
+            babylonLight.intensity = 1;
+
+            babylonLight.diffuse = new[] { 1.0f, 1.0f, 1.0f };
+            babylonLight.specular = new[] { 1.0f, 1.0f, 1.0f }; 
+
+            babylonScene.LightsList.Add(babylonLight);
+        }
+
         private void ExportLight(IINode lightNode, BabylonScene babylonScene)
         {
             if (lightNode.GetBoolProperty("babylonjs_noexport"))

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

@@ -73,18 +73,18 @@ namespace Max2Babylon
                 babylonMaterial.wireframe = stdMat.Wire;
 
                 // Textures
-                babylonMaterial.ambientTexture = ExportTexture(stdMat, 0, babylonScene);    // Ambient
-                babylonMaterial.diffuseTexture = ExportTexture(stdMat, 1, babylonScene);    // Diffuse
-                babylonMaterial.specularTexture = ExportTexture(stdMat, 2, babylonScene);   // Specular
-                babylonMaterial.emissiveTexture = ExportTexture(stdMat, 5, babylonScene);   // Emissive
-                babylonMaterial.opacityTexture = ExportTexture(stdMat, 6, babylonScene);    // Opacity
-                babylonMaterial.bumpTexture = ExportTexture(stdMat, 8, babylonScene);       // Bump
-                babylonMaterial.reflectionTexture = ExportTexture(stdMat, 9, babylonScene, true); // Reflection
+                babylonMaterial.ambientTexture = ExportTexture(stdMat, 0, babylonScene);                // Ambient
+                babylonMaterial.diffuseTexture = ExportTexture(stdMat, 1, babylonScene);                // Diffuse
+                babylonMaterial.specularTexture = ExportTexture(stdMat, 2, babylonScene);               // Specular
+                babylonMaterial.emissiveTexture = ExportTexture(stdMat, 5, babylonScene);               // Emissive
+                babylonMaterial.opacityTexture = ExportTexture(stdMat, 6, babylonScene, false, true);   // Opacity
+                babylonMaterial.bumpTexture = ExportTexture(stdMat, 8, babylonScene);                   // Bump
+                babylonMaterial.reflectionTexture = ExportTexture(stdMat, 9, babylonScene, true);       // Reflection
 
                 // Constraints
                 if (babylonMaterial.diffuseTexture != null)
                 {
-                    babylonMaterial.emissive = new [] { 1.0f, 1.0f, 1.0f };
+                    babylonMaterial.diffuse = new [] { 1.0f, 1.0f, 1.0f };
                 }
 
                 if (babylonMaterial.emissiveTexture != null)

+ 1 - 0
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.ShadowGenerator.cs

@@ -16,6 +16,7 @@ namespace Max2Babylon
             babylonShadowGenerator.lightId = lightNode.GetGuid().ToString();
 
             babylonShadowGenerator.mapSize = maxLight.GetMapSize(0, Tools.Forever);
+            babylonShadowGenerator.usePoissonSampling = maxLight.AbsMapBias == 1;
 
             var list = new List<string>();
 

+ 18 - 8
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Texture.cs

@@ -20,7 +20,7 @@ namespace Max2Babylon
                 var data = File.ReadAllBytes(filepath);
                 var intArray = new int[data.Length / 4];
 
-                Buffer.BlockCopy(data, 0, intArray, 0, data.Length);
+                Buffer.BlockCopy(data, 0, intArray, 0, intArray.Length * 4);
 
 
                 int width = intArray[4];
@@ -30,15 +30,15 @@ namespace Max2Babylon
                 if ((width >> (mipmapsCount -1)) > 1)
                 {
                     var expected = 1;
-                    var currentWidth = width;
+                    var currentSize = Math.Max(width, height);
 
-                    while (currentWidth > 1)
+                    while (currentSize > 1)
                     {
-                        currentWidth = currentWidth >> 1;
+                        currentSize = currentSize >> 1;
                         expected++;
                     }
 
-                    RaiseWarning(string.Format("Mipmaps chain is not complete: {0} maps instead of {1} (based on texture width: {2})", mipmapsCount, expected, width), 2);
+                    RaiseWarning(string.Format("Mipmaps chain is not complete: {0} maps instead of {1} (based on texture max size: {2})", mipmapsCount, expected, width), 2);
                     RaiseWarning(string.Format("You must generate a complete mipmaps chain for .dds)"), 2);
                     RaiseWarning(string.Format("Mipmaps will be disabled for this texture. If you want automatic texture generation you cannot use a .dds)"), 2);
                 }
@@ -53,7 +53,7 @@ namespace Max2Babylon
             }
         }
 
-        private BabylonTexture ExportTexture(IStdMat2 stdMat, int index, BabylonScene babylonScene, Boolean allowCube = false)
+        private BabylonTexture ExportTexture(IStdMat2 stdMat, int index, BabylonScene babylonScene, bool allowCube = false, bool forceAlpha = false)
         {
             if (!stdMat.MapEnabled(index))
             {
@@ -69,8 +69,18 @@ namespace Max2Babylon
                 return null;
             }
 
-            babylonTexture.hasAlpha = (texture.AlphaSource != 3);
-            babylonTexture.getAlphaFromRGB = (texture.AlphaSource == 2);
+            if (forceAlpha)
+            {
+                babylonTexture.hasAlpha = true;
+                babylonTexture.getAlphaFromRGB = (texture.AlphaSource == 2) || (texture.AlphaSource == 3);                
+            }
+            else
+            {
+                babylonTexture.hasAlpha = (texture.AlphaSource != 3);
+                babylonTexture.getAlphaFromRGB = (texture.AlphaSource == 2);
+            }
+
+
             babylonTexture.level = stdMat.GetTexmapAmt(index, 0);
 
             var uvGen = texture.UVGen;

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

@@ -208,6 +208,8 @@ namespace Max2Babylon
             if (babylonScene.LightsList.Count == 0)
             {
                 RaiseWarning("No light defined", 1);
+                RaiseWarning("A default hemispheric light was added for your convenience", 1);
+                ExportDefaultLight(babylonScene);
             }
             else
             {

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

@@ -29,9 +29,7 @@ namespace Max2Babylon
             Tools.PrepareCheckBox(chkManifest, Loader.Core.RootNode, "babylonjs_generatemanifest");
             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);
-
-            butExportAndRun.Enabled = WebServer.IsSupported;
+            Tools.PrepareCheckBox(chkAutoSave, Loader.Core.RootNode, "babylonjs_autosave", 1);            
         }
 
         private void butBrowse_Click(object sender, EventArgs e)
@@ -70,7 +68,7 @@ namespace Max2Babylon
             {
                 try
                 {
-                    currentNode = CreateTreeNode(rank, warning, Color.Orange);
+                    currentNode = CreateTreeNode(rank, warning, Color.DarkOrange);
                     currentNode.EnsureVisible();
                 }
                 catch
@@ -110,6 +108,7 @@ namespace Max2Babylon
             };
 
             butExport.Enabled = false;
+            butExportAndRun.Enabled = false;
             butCancel.Enabled = true;
 
             bool success = true;
@@ -136,6 +135,7 @@ namespace Max2Babylon
 
             butCancel.Enabled = false;
             butExport.Enabled = true;
+            butExportAndRun.Enabled = WebServer.IsSupported;
 
             BringToFront();
 
@@ -186,6 +186,7 @@ namespace Max2Babylon
         private void txtFilename_TextChanged(object sender, EventArgs e)
         {
             butExport.Enabled = !string.IsNullOrEmpty(txtFilename.Text.Trim());
+            butExportAndRun.Enabled = butExport.Enabled && WebServer.IsSupported;
         }
 
         private void butCancel_Click(object sender, EventArgs e)

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

@@ -222,9 +222,9 @@ namespace Max2Babylon
         {
             foreach (var x in node.Nodes())
             {
+                yield return x;
                 foreach (var y in x.NodeTree())
                     yield return y;
-                yield return x;
             }
         }
 

+ 24 - 13
Exporters/3ds Max/Max2Babylon/Tools/WebServer.cs

@@ -3,6 +3,7 @@ using System.IO;
 using System.Net;
 using System.Text;
 using System.Threading.Tasks;
+using System.Web;
 
 namespace Max2Babylon
 {
@@ -20,37 +21,47 @@ namespace Max2Babylon
     <script type='text/javascript' src='http://www.babylonjs.com/cannon.js'></script>
     <script type='text/javascript' src='http://www.babylonjs.com/babylon.js'></script>
     <style type='text/css'>
-        html,
-        body,
-        div,
-        canvas {
+        html, body, div, canvas {
             width: 100%;
             height: 100%;
             padding: 0;
             margin: 0;
             overflow: hidden;
         }
+
+        #waitLabel {
+            position: absolute;
+            width: 100%;
+            height: 100%;
+            font-size: 40px;
+            text-align: center;
+            top: 50%;
+            margin-top: -20px;
+            font-family: Arial;
+            font-weight: bold;
+        }
     </style>
 </head>
 
 <body>
     <canvas id='canvas'></canvas>
+    <div id='waitLabel'>loading....please wait</div>
     <script type='text/javascript'>
         var canvas = document.getElementById('canvas');
         var engine = new BABYLON.Engine(canvas, true);
 
         BABYLON.SceneLoader.Load('', '###SCENE###', engine, function (newScene) {
-            newScene.executeWhenReady(function () {
-                newScene.activeCamera.attachControl(canvas);
+            newScene.activeCamera.attachControl(canvas);
 
-                engine.runRenderLoop(function() {
-                    newScene.render();
-                });
+            engine.runRenderLoop(function() {
+                newScene.render();
+            });
 
-                window.addEventListener('resize', function () {
-                    engine.resize();
-                });
+            window.addEventListener('resize', function () {
+                engine.resize();
             });
+
+            document.getElementById('waitLabel').style.display = 'none';
         });
     </script>
 </body>
@@ -108,7 +119,7 @@ namespace Max2Babylon
                     {
                         try
                         {
-                            var buffer = File.ReadAllBytes(Path.Combine(SceneFolder, url.PathAndQuery.Substring(1)));
+                            var buffer = File.ReadAllBytes(Path.Combine(SceneFolder, HttpUtility.UrlDecode(url.PathAndQuery.Substring(1))));
                             WriteResponse(context, buffer);
                         }
                         catch