Selaa lähdekoodia

Fixed normals and lights.
Should check cast shadows

Simon Ferquel 10 vuotta sitten
vanhempi
commit
f8c14f5cc9

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

@@ -48,35 +48,31 @@ namespace Max2Babylon
 
             var directionScale = -1;
 
-            switch (gameLight.LightType)
+            switch (lightState.Type)
             {
-                case Autodesk.Max.IGameLight.LightType.Omni:
+                case LightType.OmniLgt:
                     babylonLight.type = 0;
                     break;
-                case Autodesk.Max.IGameLight.LightType.Fspot:
-                case Autodesk.Max.IGameLight.LightType.Tspot:
+                case LightType.SpotLgt:
                     babylonLight.type = 2;
-
-                    float fallOff = 0;
-                    gameLight.LightFallOff.GetPropertyValue(ref fallOff, 0, true);
-                    babylonLight.angle = (float)(fallOff * Math.PI / 180.0f);
+                    babylonLight.angle = (float)(maxLight.GetFallsize(0, Tools.Forever) * Math.PI / 180.0f);
                     babylonLight.exponent = 1;
                     break;
-                case Autodesk.Max.IGameLight.LightType.Dir:
-                case Autodesk.Max.IGameLight.LightType.Tdir:
+                case LightType.DirectLgt:
                     babylonLight.type = 1;
                     break;
-                case Autodesk.Max.IGameLight.LightType.Unknown:
+                case LightType.AmbientLgt:
                     babylonLight.type = 3;
                     babylonLight.groundColor = new float[] { 0, 0, 0 };
                     directionScale = 1;
                     break;
             }
 
-            // Shadows
-            if (gameLight.CastShadows)
+
+            // Shadows 
+            if (maxLight.ShadowMethod == 1)
             {
-                if (babylonLight.type == 1)
+                if (lightState.Type == LightType.DirectLgt)
                 {
                     ExportShadowGenerator(lightNode.MaxNode, babylonScene);
                 }
@@ -86,6 +82,7 @@ namespace Max2Babylon
                 }
             }
 
+
             // Position
             var wm = lightNode.GetObjectTM(0);
             var position = wm.Translation;
@@ -98,13 +95,14 @@ namespace Max2Babylon
                 var targetWm = target.GetObjectTM(0);
                 var targetPosition = targetWm.Translation;
 
-                var direction = targetPosition.Subtract(position);
+                var direction = targetPosition.Subtract(position).Normalize;
                 babylonLight.direction = new float[] { direction.X, direction.Y, direction.Z };
             }
             else
             {
-                var dir = wm.GetRow(3);
-                babylonLight.direction = new float[] { position.X - dir.X, position.Y - dir.Y, position.Z - dir.Z };
+                var vDir = Loader.Global.Point3.Create(0, -1, 0);
+                vDir = wm.ExtractMatrix3().VectorTransform(vDir).Normalize;
+                babylonLight.direction = new float[] { vDir.X, vDir.Y, vDir.Z };
             }
 
 

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

@@ -28,8 +28,6 @@ namespace Max2Babylon
             }
 
             var gameMesh = meshNode.IGameObject.AsGameMesh();
-            gameMesh.SetCreateOptimizedNormalList();
-            gameMesh.SetUseWeightedNormals();
             bool initialized = gameMesh.InitializeData; //needed, the property is in fact a method initializing the exporter that has wrongly been auto 
             // translated into a property because it has no parameters
 
@@ -75,13 +73,13 @@ namespace Max2Babylon
                 var meshRotation = localTM.Rotation;
                 var meshScale = localTM.Scaling;
                 babylonMesh.position = new float[] { meshTrans.X, meshTrans.Y, meshTrans.Z };
-                float rotx = 0, roty = 0, rotz = 0;
-                unsafe
-                {
-                    meshRotation.GetEuler(new IntPtr(&rotx), new IntPtr(&roty), new IntPtr(&rotz));
-                }
-                babylonMesh.rotation = new float[] { rotx, roty, rotz };
-                //babylonMesh.rotationQuaternion = new float[] { meshRotation.X, meshRotation.Y, meshRotation.Z, meshRotation.W };
+                //float rotx = 0, roty = 0, rotz = 0;
+                //unsafe
+                //{
+                //    meshRotation.GetEuler(new IntPtr(&rotx), new IntPtr(&roty), new IntPtr(&rotz));
+                //}
+                //babylonMesh.rotation = new float[] { rotx, roty, rotz };
+                babylonMesh.rotationQuaternion = new float[] { meshRotation.X, meshRotation.Y, meshRotation.Z, -meshRotation.W };
                 babylonMesh.scaling = new float[] { meshScale.X, meshScale.Y, meshScale.Z };
             }
             //// Pivot // something to do with GameMesh ?
@@ -268,7 +266,7 @@ namespace Max2Babylon
 
                 // Buffers
                 babylonMesh.positions = vertices.SelectMany(v => new float[] { v.Position.X, v.Position.Y, v.Position.Z }).ToArray();
-                babylonMesh.normals = vertices.SelectMany(v => new float[] { -v.Normal.X, -v.Normal.Y, -v.Normal.Z }).ToArray();
+                babylonMesh.normals = vertices.SelectMany(v => new float[] { v.Normal.X, v.Normal.Y, v.Normal.Z }).ToArray();
                 if (hasUV)
                 {
                     babylonMesh.uvs = vertices.SelectMany(v => new float[] { v.UV.X, 1-v.UV.Y }).ToArray();