Prechádzať zdrojové kódy

Merge with core repository

Simon Ferquel 10 rokov pred
rodič
commit
ccb9ad0c9f

+ 4 - 4
Babylon/Mesh/babylon.abstractMesh.ts

@@ -361,7 +361,7 @@
                 var cameraGlobalPosition = new BABYLON.Vector3(cameraWorldMatrix.m[12], cameraWorldMatrix.m[13], cameraWorldMatrix.m[14]);
 
                 BABYLON.Matrix.TranslationToRef(this.position.x + cameraGlobalPosition.x, this.position.y + cameraGlobalPosition.y,
-                                                this.position.z + cameraGlobalPosition.z, this._localTranslation);
+                    this.position.z + cameraGlobalPosition.z, this._localTranslation);
             } else {
                 BABYLON.Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._localTranslation);
             }
@@ -518,7 +518,7 @@
         }
 
         // Physics
-        public setPhysicsState(impostor?: any, options?: PhysicsBodyCreationOptions): void {
+        public setPhysicsState(impostor?: any, options?: PhysicsBodyCreationOptions): any {
             var physicsEngine = this.getScene().getPhysicsEngine();
 
             if (!physicsEngine) {
@@ -548,7 +548,7 @@
             this._physicRestitution = options.restitution;
 
 
-            physicsEngine._registerMesh(this, impostor, options);
+            return physicsEngine._registerMesh(this, impostor, options);
         }
 
         public getPhysicsImpostor(): number {
@@ -870,4 +870,4 @@
             }
         }
     }
-}
+}

+ 1 - 1
Babylon/Particles/babylon.particleSystem.ts

@@ -333,7 +333,7 @@
                 this._appendParticleVertex(offset++, particle, 0, 1);
             }
             var engine = this._scene.getEngine();
-            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices, this.particles.length * this._vertexStrideSize);
+            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices);
         }
 
         public render(): number {

+ 2 - 7
Babylon/Rendering/babylon.renderingGroup.ts

@@ -10,10 +10,9 @@
             this._scene = scene;
         }
 
-        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents: () => void) => void,
-            beforeTransparents): boolean {
+        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void): boolean {
             if (customRenderFunction) {
-                customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes, beforeTransparents);
+                customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes);
                 return true;
             }
 
@@ -40,10 +39,6 @@
             }
             engine.setAlphaTesting(false);
 
-            if (beforeTransparents) {
-                beforeTransparents();
-            }
-
             // Transparent
             if (this._transparentSubMeshes.length) {
                 // Sorting

+ 3 - 8
Babylon/Rendering/babylon.renderingManager.ts

@@ -60,7 +60,7 @@
             this._depthBufferAlreadyCleaned = true;
         }
 
-        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents: () => void) => void,
+        public render(customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>) => void,
             activeMeshes: AbstractMesh[], renderParticles: boolean, renderSprites: boolean): void {
             for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthBufferAlreadyCleaned = false;
@@ -68,16 +68,11 @@
 
                 if (renderingGroup) {
                     this._clearDepthBuffer();
-                    if (!renderingGroup.render(customRenderFunction, () => {
-                        if (renderSprites) {
-                            this._renderSprites(index);
-                        }
-                    })) {
+                    if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
-                    } else if (renderSprites) {
-                        this._renderSprites(index);
                     }
                 }
+                this._renderSprites(index);
                 if (renderParticles) {
                     this._renderParticles(index, activeMeshes);
                 }

+ 1 - 1
Babylon/Sprites/babylon.spriteManager.ts

@@ -120,7 +120,7 @@
                 this._appendSpriteVertex(offset++, sprite, 1, 1, rowSize);
                 this._appendSpriteVertex(offset++, sprite, 0, 1, rowSize);
             }
-            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices, max * this._vertexStrideSize);
+            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices);
 
             // Render
             var effect = this._effectBase;

+ 39 - 9
Babylon/babylon.engine.js

@@ -364,16 +364,17 @@
             // Public members
             this.isFullscreen = false;
             this.isPointerLock = false;
-            this.forceWireframe = false;
             this.cullBackFaces = true;
             this.renderEvenInBackground = true;
             this.scenes = new Array();
             this._windowIsBackground = false;
             this._runningLoop = false;
             this._loadingDivBackgroundColor = "black";
+            this._drawCalls = 0;
             // States
             this._depthCullingState = new _DepthCullingState();
             this._alphaState = new _AlphaState();
+            this._alphaMode = Engine.ALPHA_DISABLE;
             // Cache
             this._loadedTexturesCache = new Array();
             this._activeTexturesCache = new Array();
@@ -471,6 +472,10 @@
             document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
             document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
             document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
+
+            this._audioEngine = new BABYLON.AudioEngine();
+
+            BABYLON.Tools.Log("Babylon.js engine (v" + Engine.Version + ") launched");
         }
         Object.defineProperty(Engine, "ALPHA_DISABLE", {
             get: function () {
@@ -536,6 +541,10 @@
             configurable: true
         });
 
+        Engine.prototype.getAudioEngine = function () {
+            return this._audioEngine;
+        };
+
         Engine.prototype.getAspectRatio = function (camera) {
             var viewport = camera.viewport;
             return (this.getRenderWidth() * viewport.width) / (this.getRenderHeight() * viewport.height);
@@ -582,7 +591,19 @@
             return this._caps;
         };
 
+        Object.defineProperty(Engine.prototype, "drawCalls", {
+            get: function () {
+                return this._drawCalls;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
         // Methods
+        Engine.prototype.resetDrawCalls = function () {
+            this._drawCalls = 0;
+        };
+
         Engine.prototype.setDepthFunctionToGreater = function () {
             this._depthCullingState.depthFunc = this._gl.GREATER;
         };
@@ -728,7 +749,7 @@
         };
 
         Engine.prototype.flushFramebuffer = function () {
-            this._gl.flush();
+            //   this._gl.flush();
         };
 
         Engine.prototype.restoreDefaultFramebuffer = function () {
@@ -764,19 +785,19 @@
             return vbo;
         };
 
-        Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, length) {
+        Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, offset) {
             this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer);
 
-            //if (length && length != vertices.length) {
-            //    this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(vertices, 0, length));
-            //} else {
+            if (offset === undefined) {
+                offset = 0;
+            }
+
             if (vertices instanceof Float32Array) {
-                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, vertices);
+                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, vertices);
             } else {
-                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(vertices));
+                this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, new Float32Array(vertices));
             }
 
-            //  }
             this._resetVertexBufferBinding();
         };
 
@@ -930,6 +951,8 @@
             }
 
             this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2);
+
+            this._drawCalls++;
         };
 
         Engine.prototype.drawPointClouds = function (verticesStart, verticesCount, instancesCount) {
@@ -942,6 +965,7 @@
             }
 
             this._gl.drawArrays(this._gl.POINTS, verticesStart, verticesCount);
+            this._drawCalls++;
         };
 
         // Shaders
@@ -1183,6 +1207,12 @@
                     this._alphaState.alphaBlend = true;
                     break;
             }
+
+            this._alphaMode = mode;
+        };
+
+        Engine.prototype.getAlphaMode = function () {
+            return this._alphaMode;
         };
 
         Engine.prototype.setAlphaTesting = function (enable) {

+ 129 - 24
Babylon/babylon.scene.js

@@ -8,9 +8,13 @@
             this.clearColor = new BABYLON.Color3(0.2, 0.2, 0.3);
             this.ambientColor = new BABYLON.Color3(0, 0, 0);
             this.forceWireframe = false;
+            this.forcePointsCloud = false;
+            this.forceShowBoundingBoxes = false;
+            this.animationsEnabled = true;
             this.cameraToUseForPointers = null;
             // Fog
-            this.fogMode = BABYLON.Scene.FOGMODE_NONE;
+            this.fogEnabled = true;
+            this.fogMode = Scene.FOGMODE_NONE;
             this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
             this.fogDensity = 0.1;
             this.fogStart = 0;
@@ -40,6 +44,7 @@
             // Layers
             this.layers = new Array();
             // Skeletons
+            this.skeletonsEnabled = true;
             this.skeletons = new Array();
             // Lens flares
             this.lensFlaresEnabled = true;
@@ -59,6 +64,7 @@
             // Procedural textures
             this.proceduralTexturesEnabled = true;
             this._proceduralTextures = new Array();
+            this.soundTracks = new Array();
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;
@@ -75,11 +81,13 @@
             this._onReadyCallbacks = new Array();
             this._pendingData = [];
             this._onBeforeRenderCallbacks = new Array();
+            this._onAfterRenderCallbacks = new Array();
             this._activeMeshes = new BABYLON.SmartArray(256);
             this._processedMaterials = new BABYLON.SmartArray(256);
             this._renderTargets = new BABYLON.SmartArray(256);
             this._activeParticleSystems = new BABYLON.SmartArray(256);
             this._activeSkeletons = new BABYLON.SmartArray(32);
+            this._activeBones = 0;
             this._activeAnimatables = new Array();
             this._transformMatrix = BABYLON.Matrix.Zero();
             this._scaledPosition = BABYLON.Vector3.Zero();
@@ -98,10 +106,21 @@
             this._outlineRenderer = new BABYLON.OutlineRenderer(this);
 
             this.attachControl();
+
+            this._debugLayer = new BABYLON.DebugLayer(this);
+            this.mainSoundTrack = new BABYLON.SoundTrack(this, { mainTrack: true });
         }
-        Object.defineProperty(Scene.prototype, "meshUnderPointer", {
+        Object.defineProperty(Scene.prototype, "debugLayer", {
             // Properties
             get: function () {
+                return this._debugLayer;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+        Object.defineProperty(Scene.prototype, "meshUnderPointer", {
+            get: function () {
                 return this._meshUnderPointer;
             },
             enumerable: true,
@@ -124,6 +143,10 @@
             configurable: true
         });
 
+        Scene.prototype.getCachedMaterial = function () {
+            return this._cachedMaterial;
+        };
+
         Scene.prototype.getBoundingBoxRenderer = function () {
             return this._boundingBoxRenderer;
         };
@@ -148,6 +171,10 @@
             return this._activeParticles;
         };
 
+        Scene.prototype.getActiveBones = function () {
+            return this._activeBones;
+        };
+
         // Stats
         Scene.prototype.getLastFrameDuration = function () {
             return this._lastFrameDuration;
@@ -317,6 +344,10 @@
             return true;
         };
 
+        Scene.prototype.resetCachedMaterial = function () {
+            this._cachedMaterial = null;
+        };
+
         Scene.prototype.registerBeforeRender = function (func) {
             this._onBeforeRenderCallbacks.push(func);
         };
@@ -329,6 +360,18 @@
             }
         };
 
+        Scene.prototype.registerAfterRender = function (func) {
+            this._onAfterRenderCallbacks.push(func);
+        };
+
+        Scene.prototype.unregisterAfterRender = function (func) {
+            var index = this._onAfterRenderCallbacks.indexOf(func);
+
+            if (index > -1) {
+                this._onAfterRenderCallbacks.splice(index, 1);
+            }
+        };
+
         Scene.prototype._addPendingData = function (data) {
             this._pendingData.push(data);
         };
@@ -432,6 +475,10 @@
         };
 
         Scene.prototype._animate = function () {
+            if (!this.animationsEnabled) {
+                return;
+            }
+
             if (!this._animationStartDate) {
                 this._animationStartDate = BABYLON.Tools.Now;
             }
@@ -662,7 +709,7 @@
         };
 
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
-            if (mesh.subMeshes.length == 1 || subMesh.isInFrustum(this._frustumPlanes)) {
+            if (mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
                 var material = subMesh.getMaterial();
 
                 if (mesh.showSubMeshesBoundingBox) {
@@ -680,7 +727,7 @@
                     }
 
                     // Dispatch
-                    this._activeVertices += subMesh.verticesCount;
+                    this._activeVertices += subMesh.indexCount;
                     this._renderingManager.dispatch(subMesh);
                 }
             }
@@ -727,18 +774,26 @@
                 }
 
                 mesh.computeWorldMatrix();
-                mesh._preActivate();
 
                 // Intersections
                 if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
                     this._meshesForIntersections.pushNoDuplicate(mesh);
                 }
 
-                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) != 0) && mesh.isInFrustum(this._frustumPlanes)) {
+                // Switch to current LOD
+                var meshLOD = mesh.getLOD(this.activeCamera);
+
+                if (!meshLOD) {
+                    continue;
+                }
+
+                mesh._preActivate();
+
+                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && ((mesh.layerMask & this.activeCamera.layerMask) !== 0) && mesh.isInFrustum(this._frustumPlanes)) {
                     this._activeMeshes.push(mesh);
                     mesh._activate(this._renderId);
 
-                    this._activeMesh(mesh);
+                    this._activeMesh(meshLOD);
                 }
             }
 
@@ -764,35 +819,33 @@
         };
 
         Scene.prototype._activeMesh = function (mesh) {
-            if (mesh.skeleton) {
+            if (mesh.skeleton && this.skeletonsEnabled) {
                 this._activeSkeletons.pushNoDuplicate(mesh.skeleton);
             }
 
-            if (mesh.showBoundingBox) {
+            if (mesh.showBoundingBox || this.forceShowBoundingBoxes) {
                 this._boundingBoxRenderer.renderList.push(mesh.getBoundingInfo().boundingBox);
             }
 
-            var activeMesh = mesh.getLOD(this.activeCamera);
-
-            if (activeMesh && activeMesh.subMeshes) {
+            if (mesh && mesh.subMeshes) {
                 // Submeshes Octrees
                 var len;
                 var subMeshes;
 
-                if (activeMesh._submeshesOctree && activeMesh.useOctreeForRenderingSelection) {
-                    var intersections = activeMesh._submeshesOctree.select(this._frustumPlanes);
+                if (mesh._submeshesOctree && mesh.useOctreeForRenderingSelection) {
+                    var intersections = mesh._submeshesOctree.select(this._frustumPlanes);
 
                     len = intersections.length;
                     subMeshes = intersections.data;
                 } else {
-                    subMeshes = activeMesh.subMeshes;
+                    subMeshes = mesh.subMeshes;
                     len = subMeshes.length;
                 }
 
                 for (var subIndex = 0; subIndex < len; subIndex++) {
                     var subMesh = subMeshes[subIndex];
 
-                    this._evaluateSubMesh(subMesh, activeMesh);
+                    this._evaluateSubMesh(subMesh, mesh);
                 }
             }
         };
@@ -833,6 +886,8 @@
                 var skeleton = this._activeSkeletons.data[skeletonIndex];
 
                 skeleton.prepare();
+
+                this._activeBones += skeleton.bones.length;
             }
 
             // Render targets
@@ -922,7 +977,7 @@
         };
 
         Scene.prototype._processSubCameras = function (camera) {
-            if (camera.subCameras.length == 0) {
+            if (camera.subCameras.length === 0) {
                 this._renderForCamera(camera);
                 return;
             }
@@ -945,17 +1000,17 @@
                 for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
                     var action = sourceMesh.actionManager.actions[actionIndex];
 
-                    if (action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
+                    if (action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
                         var otherMesh = action.getTriggerParameter();
 
                         var areIntersecting = otherMesh.intersectsMesh(sourceMesh, false);
                         var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
 
-                        if (areIntersecting && currentIntersectionInProgress === -1 && action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger) {
-                            sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
+                        if (areIntersecting && currentIntersectionInProgress === -1 && action.trigger === BABYLON.ActionManager.OnIntersectionEnterTrigger) {
+                            action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
                             sourceMesh._intersectionsInProgress.push(otherMesh);
-                        } else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
-                            sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionExitTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
+                        } else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger === BABYLON.ActionManager.OnIntersectionExitTrigger) {
+                            action._executeCurrent(BABYLON.ActionEvent.CreateNew(sourceMesh));
 
                             var indexOfOther = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
 
@@ -974,10 +1029,14 @@
             this._spritesDuration = 0;
             this._activeParticles = 0;
             this._renderDuration = 0;
+            this._renderTargetsDuration = 0;
             this._evaluateActiveMeshesDuration = 0;
             this._totalVertices = 0;
             this._activeVertices = 0;
+            this._activeBones = 0;
+            this.getEngine().resetDrawCalls();
             this._meshesForIntersections.reset();
+            this.resetCachedMaterial();
 
             BABYLON.Tools.StartPerformanceCounter("Scene rendering");
 
@@ -1054,7 +1113,7 @@
             }
 
             // Clear
-            this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe, true);
+            this._engine.clear(this.clearColor, this.autoClear || this.forceWireframe || this.forcePointsCloud, true);
 
             // Shadows
             if (this.shadowsEnabled) {
@@ -1089,11 +1148,18 @@
             // Intersection checks
             this._checkIntersections();
 
+            // Update the audio listener attached to the camera
+            this._updateAudioParameters();
+
             // After render
             if (this.afterRender) {
                 this.afterRender();
             }
 
+            for (callbackIndex = 0; callbackIndex < this._onAfterRenderCallbacks.length; callbackIndex++) {
+                this._onAfterRenderCallbacks[callbackIndex]();
+            }
+
             for (var index = 0; index < this._toBeDisposed.length; index++) {
                 this._toBeDisposed.data[index].dispose();
                 this._toBeDisposed[index] = null;
@@ -1105,6 +1171,39 @@
             this._lastFrameDuration = BABYLON.Tools.Now - startDate;
         };
 
+        Scene.prototype._updateAudioParameters = function () {
+            var listeningCamera;
+            var audioEngine = this._engine.getAudioEngine();
+
+            if (this.activeCameras.length > 0) {
+                listeningCamera = this.activeCameras[0];
+            } else {
+                listeningCamera = this.activeCamera;
+            }
+
+            if (listeningCamera && audioEngine.canUseWebAudio) {
+                audioEngine.audioContext.listener.setPosition(listeningCamera.position.x, listeningCamera.position.y, listeningCamera.position.z);
+                var mat = BABYLON.Matrix.Invert(listeningCamera.getViewMatrix());
+                var cameraDirection = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -1), mat);
+                cameraDirection.normalize();
+                audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
+                for (var i = 0; i < this.mainSoundTrack.soundCollection.length; i++) {
+                    var sound = this.mainSoundTrack.soundCollection[i];
+                    if (sound.useBabylonJSAttenuation) {
+                        sound.updateDistanceFromListener();
+                    }
+                }
+                for (var i = 0; i < this.soundTracks.length; i++) {
+                    for (var j = 0; i < this.soundTracks[i].soundCollection.length; j++) {
+                        var sound = this.soundTracks[i].soundCollection[j];
+                        if (sound.useBabylonJSAttenuation) {
+                            sound.updateDistanceFromListener();
+                        }
+                    }
+                }
+            }
+        };
+
         Scene.prototype.dispose = function () {
             this.beforeRender = null;
             this.afterRender = null;
@@ -1113,11 +1212,17 @@
 
             this._boundingBoxRenderer.dispose();
 
+            // Debug layer
+            this.debugLayer.hide();
+
             // Events
             if (this.onDispose) {
                 this.onDispose();
             }
 
+            this._onBeforeRenderCallbacks = [];
+            this._onAfterRenderCallbacks = [];
+
             this.detachControl();
 
             // Detach cameras
@@ -1214,7 +1319,7 @@
                 return;
             }
 
-            if (velocity.x != 0 || velocity.y != 0 || velocity.z != 0) {
+            if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
                 collider._getResponse(position, velocity);
             }
 

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


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

@@ -185,13 +185,13 @@ namespace Max2Babylon
             ExportAnimation(property, animations, extractValueFunc, BabylonAnimation.DataType.Float);
         }
 
-        static void EliminateLinearAnimationKeys(List<BabylonAnimationKey> keys)
+        static void RemoveLinearAnimationKeys(List<BabylonAnimationKey> keys)
         {
             for(int ixFirst = keys.Count-3; ixFirst >=0; --ixFirst)
             {
                 while (keys.Count - ixFirst >= 3)
                 {
-                    if(!EliminateAnimationKey(keys, ixFirst))
+                    if(!RemoveAnimationKey(keys, ixFirst))
                     {
                         break;
                     }
@@ -211,9 +211,7 @@ namespace Max2Babylon
             return result;
         }
 
-
-
-        private static bool EliminateAnimationKey(List<BabylonAnimationKey> keys, int ixFirst)
+        private static bool RemoveAnimationKey(List<BabylonAnimationKey> keys, int ixFirst)
         {
             var first = keys[ixFirst];
             var middle = keys[ixFirst + 1];
@@ -258,7 +256,7 @@ namespace Max2Babylon
 
                 previous = current;
             }
-            EliminateLinearAnimationKeys(keys);
+            RemoveLinearAnimationKeys(keys);
             if (keys.Count > 0)
             {
                 var animationPresent = true;

+ 32 - 39
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Light.cs

@@ -46,8 +46,6 @@ namespace Max2Babylon
             var lightState = Loader.Global.LightState.Create();
             maxLight.EvalLightState(0, Tools.Forever, lightState);
 
-            var directionScale = -1;
-
             switch (lightState.Type)
             {
                 case LightType.OmniLgt:
@@ -64,7 +62,6 @@ namespace Max2Babylon
                 case LightType.AmbientLgt:
                     babylonLight.type = 3;
                     babylonLight.groundColor = new float[] { 0, 0, 0 };
-                    directionScale = 1;
                     break;
             }
 
@@ -82,31 +79,30 @@ namespace Max2Babylon
                 }
             }
 
+            // Position
+            var wm = lightNode.GetObjectTM(0);
+            var position = wm.Translation;
+            babylonLight.position = new float[] { position.X, position.Y, position.Z };
+
+            // Direction
+            var target = gameLight.LightTarget;
+            if (target != null)
             {
-                // Position
-                var wm = lightNode.GetObjectTM(0);
-                var position = wm.Translation;
-                babylonLight.position = new float[] { position.X, position.Y, position.Z };
-
-                // Direction
-                var target = gameLight.LightTarget;
-                if (target != null)
-                {
-                    var targetWm = target.GetObjectTM(0);
-                    var targetPosition = targetWm.Translation;
+                var targetWm = target.GetObjectTM(0);
+                var targetPosition = targetWm.Translation;
 
-                    var direction = targetPosition.Subtract(position).Normalize;
-                    babylonLight.direction = new float[] { direction.X, direction.Y, direction.Z };
-                }
-                else
-                {
-                    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 };
-                }
+                var direction = targetPosition.Subtract(position).Normalize;
+                babylonLight.direction = new float[] { direction.X, direction.Y, direction.Z };
+            }
+            else
+            {
+                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 };
             }
 
             var maxScene = Loader.Core.RootNode;
+
             // Exclusion
             var inclusion = maxLight.ExclList.TestFlag(1); //NT_INCLUDE 
             var checkExclusionList = maxLight.ExclList.TestFlag(2); //NT_AFFECT_ILLUM
@@ -157,33 +153,30 @@ namespace Max2Babylon
             // Animations
             var animations = new List<BabylonAnimation>();
 
-            //if (!ExportVector3Controller(lightNode.TMController.PositionController, "position", animations))
-            //{
-                ExportVector3Animation("position", animations, key =>
-                {
-                    var mat = lightNode.GetObjectTM(key);
-                    var pos = mat.Translation;
-                    return new float[] { pos.X, pos.Y, pos.Z };
-                });
-            //}
+            ExportVector3Animation("position", animations, key =>
+            {
+                var mat = lightNode.GetObjectTM(key);
+                var pos = mat.Translation;
+                return new float[] { pos.X, pos.Y, pos.Z };
+            });
 
             ExportVector3Animation("direction", animations, key =>
             {
-                var wm = lightNode.GetObjectTM(key);
-                var position = wm.Translation;
-                var target = gameLight.LightTarget;
-                if (target != null)
+                var wmLight = lightNode.GetObjectTM(key);
+                var positionLight = wmLight.Translation;
+                var lightTarget = gameLight.LightTarget;
+                if (lightTarget != null)
                 {
-                    var targetWm = target.GetObjectTM(key);
+                    var targetWm = lightTarget.GetObjectTM(key);
                     var targetPosition = targetWm.Translation;
 
-                    var direction = targetPosition.Subtract(position).Normalize;
+                    var direction = targetPosition.Subtract(positionLight).Normalize;
                     return new float[] { direction.X, direction.Y, direction.Z };
                 }
                 else
                 {
                     var vDir = Loader.Global.Point3.Create(0, -1, 0);
-                    vDir = wm.ExtractMatrix3().VectorTransform(vDir).Normalize;
+                    vDir = wmLight.ExtractMatrix3().VectorTransform(vDir).Normalize;
                     return new float[] { vDir.X, vDir.Y, vDir.Z };
                 }
             });

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

@@ -48,7 +48,6 @@ namespace Max2Babylon
                 return;
             }
 
-
             var babylonMaterial = new BabylonMaterial
             {
                 name = name,

+ 29 - 69
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

@@ -111,7 +111,6 @@ namespace Max2Babylon
             List<int> boneIds = null;
             if (isSkinned)
             {
-                //unskinnedMesh = skin.InitialPose;
                 bonesCount = skin.TotalSkinBoneCount;
                 skins.Add(skin);
 
@@ -124,39 +123,21 @@ namespace Max2Babylon
 
             // Position / rotation / scaling
             {
-                //var localTM = unskinnedMesh.IGameObjectTM;
-                //var worldTM = meshNode.GetWorldTM(0);
                 var localTM = meshNode.GetObjectTM(0);
 
                 var meshTrans = localTM.Translation;
                 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 };
                 babylonMesh.scaling = new float[] { meshScale.X, meshScale.Y, meshScale.Z };
             }
-            //// Pivot // something to do with GameMesh ?
-            //meshNode.GetObjectTM
-            //var pivotMatrix = Tools.Identity;
-            //pivotMatrix.PreTranslate(meshNode.ObjOffsetPos);
-            //Loader.Global.PreRotateMatrix(pivotMatrix, meshNode.ObjOffsetRot);
-            //Loader.Global.ApplyScaling(pivotMatrix, meshNode.ObjOffsetScale);
-            //babylonMesh.pivotMatrix = pivotMatrix.ToArray();
 
             // Mesh
-
             RaiseMessage(meshNode.Name, 1);
 
             if (unskinnedMesh != null && unskinnedMesh.IGameType == Autodesk.Max.IGameObject.ObjectTypes.Mesh && unskinnedMesh.MaxMesh != null)
             {
-
-
                 if (unskinnedMesh.NumberOfFaces < 1)
                 {
                     RaiseError(string.Format("Mesh {0} has no face", babylonMesh.name), 2);
@@ -200,13 +181,13 @@ namespace Max2Babylon
                     IntPtr indexer = new IntPtr(i);
                     var channelNum = mappingChannels[indexer];
                     if (channelNum == 1)
-                    {
+                {
                         hasUV = true;
-                    }
+                }
                     else if (channelNum == 2)
-                    {
+                {
                         hasUV2 = true;
-                    }
+                }
                 }
                 var hasColor = unskinnedMesh.NumberOfColorVerts > 0;
                 var hasAlpha = unskinnedMesh.GetNumberOfMapVerts(-2) > 0;
@@ -216,7 +197,6 @@ namespace Max2Babylon
 
 
                 // Compute normals
-                // VNormal[] vnorms = Tools.ComputeNormals(mesh, optimizeVertices);
                 List<GlobalVertex>[] verticesAlreadyExported = null;
 
                 if (optimizeVertices)
@@ -227,9 +207,14 @@ namespace Max2Babylon
                 var subMeshes = new List<BabylonSubMesh>();
                 var indexStart = 0;
 
-
+                
                 for (int i = 0; i < multiMatsCount; ++i)
                 {
+                    if (meshNode.NodeMaterial == null)
+                    {
+                        continue;
+                    }
+
                     int materialId = meshNode.NodeMaterial.GetMaterialID(i);
                     ITab<IFaceEx> materialFaces = null;
                     var indexCount = 0;
@@ -259,11 +244,7 @@ namespace Max2Babylon
                             ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds);
                         }
                     }
-
-
-
-
-
+                    
                     if (indexCount != 0)
                     {
 
@@ -277,11 +258,9 @@ namespace Max2Babylon
                     }
                 }
 
-
-
                 if (vertices.Count >= 65536)
                 {
-                    RaiseError(string.Format("Mesh {0} has too many vertices: {1} (limit is 65535)", babylonMesh.name, vertices.Count), 2);
+                    RaiseWarning(string.Format("Mesh {0} has {1} vertices. This may prevent your scene to work on low end devices where 32 bits indice are not supported", babylonMesh.name, vertices.Count), 2);
 
                     if (!optimizeVertices)
                     {
@@ -315,19 +294,13 @@ namespace Max2Babylon
                     babylonMesh.hasVertexAlpha = hasAlpha;
                 }
 
-
-
                 babylonMesh.subMeshes = subMeshes.ToArray();
 
-
                 // Buffers - Indices
                 babylonMesh.indices = indices.ToArray();
 
             }
 
-            // handle instances and animations
-
-
             // Instances
             var tabs = Loader.Global.NodeTab.Create();
 
@@ -357,8 +330,6 @@ namespace Max2Babylon
 
                     var localTM = meshNode.GetObjectTM(0);
 
-                    //var worldTM = meshNode.GetWorldTM(0);
-                    //var objTM = meshNode.GetObjectTM(0);
                     var meshTrans = localTM.Translation;
                     var meshRotation = localTM.Rotation;
                     var meshScale = localTM.Scaling;
@@ -383,7 +354,7 @@ namespace Max2Babylon
             // Animations
             var animations = new List<BabylonAnimation>();
             GenerateCoordinatesAnimations(meshNode, animations);
-
+            
 
             if (!ExportFloatController(meshNode.MaxNode.VisController, "visibility", animations))
             {
@@ -448,42 +419,31 @@ namespace Max2Babylon
         }
 
         public static void GenerateCoordinatesAnimations(IIGameNode meshNode, List<BabylonAnimation> animations)
-        {
-            //if (!ExportVector3Controller(meshNode.TMController.PositionController, "position", animations))
-            //{
-            ExportVector3Animation("position", animations, key =>
             {
+                ExportVector3Animation("position", animations, key =>
+                {
                 var worldMatrix = meshNode.GetObjectTM(key);
                 var trans = worldMatrix.Translation;
                 return new float[] { trans.X, trans.Y, trans.Z };
-            });
-            //}
-
-
-            //if (!ExportQuaternionController(meshNode.TMController.RotationController, "rotationQuaternion", animations))
-            //{
-            ExportQuaternionAnimation("rotationQuaternion", animations, key =>
-            {
-                var worldMatrix = meshNode.GetObjectTM(key);
+                });
 
+                ExportQuaternionAnimation("rotationQuaternion", animations, key =>
+                {
+                    var worldMatrix = meshNode.GetObjectTM(key);
 
 
-                var rot = worldMatrix.Rotation;
-                return new float[] { rot.X, rot.Y, rot.Z, -rot.W };
-            });
-            //}
 
+                    var rot = worldMatrix.Rotation;
+                    return new float[] { rot.X, rot.Y, rot.Z, -rot.W };
+                });
 
-            //if (!ExportVector3Controller(meshNode.TMController.ScaleController, "scaling", animations))
-            //{
-            ExportVector3Animation("scaling", animations, key =>
-            {
-                var worldMatrix = meshNode.GetObjectTM(key);
-                var scale = worldMatrix.Scaling;
+                ExportVector3Animation("scaling", animations, key =>
+                {
+                    var worldMatrix = meshNode.GetObjectTM(key);
+                    var scale = worldMatrix.Scaling;
 
-                return new float[] { scale.X, scale.Y, scale.Z };
-            });
-            // }
+                    return new float[] { scale.X, scale.Y, scale.Z };
+                });
         }
 
 
@@ -495,7 +455,7 @@ namespace Max2Babylon
             {
                 BaseIndex = vertexIndex,
                 Position = mesh.GetVertex(vertexIndex, true),
-                Normal = mesh.GetNormal((int)face.Norm[facePart], true) //vnorms[vertexIndex].GetNormal(verticesAlreadyExported != null ? 1 : faceObject.SmGroup)
+                Normal = mesh.GetNormal((int)face.Norm[facePart], true)
             };
 
             if (hasUV)

+ 52 - 244
Exporters/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs

@@ -16,94 +16,6 @@ namespace Max2Babylon
         readonly List<IIGameSkin> skins = new List<IIGameSkin>();
         readonly List<IIGameNode> skinnedNodes = new List<IIGameNode>();
 
-        //IISkin GetSkinModifier(IINode node, out IModifier skinModifier)
-        //{
-        //    skinModifier = null;
-        //    var obj = node.ObjectRef;
-
-        //    if (obj.SuperClassID != SClass_ID.GenDerivob)
-        //    {
-        //        return null;
-        //    }
-
-        //    var derivedObject = obj as IIDerivedObject;
-
-        //    if (derivedObject == null)
-        //    {
-        //        return null;
-        //    }
-
-        //    for (var index = 0; index < derivedObject.NumModifiers; index++)
-        //    {
-        //        var modifier = derivedObject.GetModifier(index);
-
-        //        if (modifier.ClassID.PartA == 9815843 && modifier.ClassID.PartB == 87654) // Skin
-        //        {
-        //            var skin = modifier.GetInterface((InterfaceID)0x00010000) as IISkin;
-
-        //            if (!skins.Contains(skin))
-        //            {
-        //                skins.Add(skin);
-        //            }
-        //            skinModifier = modifier;
-        //            return skin;
-        //        }
-        //    }
-
-
-        //    return null;
-        //}
-
-
-        //float[] GetBoneBindPoseLocalMatrix(IISkin skin, IINode bone, bool hasParent)
-        //{
-        //    var matrix = Loader.Global.Matrix3.Create();
-        //    var result = skin.GetBoneInitTM(bone, matrix, false);
-        //    if (!hasParent)
-        //    {
-        //        return matrix.ToArray();
-        //    }
-        //    else
-        //    {
-        //        var parentInverse = Loader.Global.Matrix3.Create();
-
-        //        result = skin.GetBoneInitTM(bone.ParentNode, matrix, false);
-        //        parentInverse.Invert();
-        //        return matrix.Multiply(parentInverse).ToArray();
-        //    }
-
-        //}
-        //float[] GetBoneMatrixForFrame(IINode bone, int frame, bool hasParent)
-        //{
-        //    //            var nodeTM2 = bone.GetNodeTM(frame, Tools.Forever);
-        //    //            var parent = bone.ParentNode;
-
-        //    //            if (!hasParent)
-        //    //            {
-        //    //                parent = bone;
-        //    //            }
-        //    //            else
-        //    //            {
-        //    //                parent = bone.ParentNode;
-        //    //            }
-        //    //            var inverseParentTM = parent.GetNodeTM(frame, Tools.Forever);
-        //    //            inverseParentTM.Invert();
-        //    //            var localTransform = nodeTM2.Multiply(inverseParentTM);
-        //    //            var vLocalPos = localTransform.Trans;
-        //    //            var parts = Loader.Global.AffineParts.Create();
-        //    //            Loader.Global.DecompAffine(localTransform, parts);
-        //    //            IPoint3 eulerAngs = Loader.Global.Point3.Create();
-        //    //#if MAX2015
-        //    //            var eulerAngsPtr = eulerAngs.NativePointer;
-        //    //#else
-        //    //            var eulerAngsPtr = eulerAngs.Handle;
-        //    //#endif
-        //    //            //Loader.Global.QuatToEuler(parts.Q, eulerAngsPtr);
-
-        //    //            return ( Matrix.RotationQuaternion(new Quaternion(parts.Q.X, parts.Q.Y, parts.Q.Z, parts.Q.W))*Matrix.Translation(vLocalPos.X, vLocalPos.Z, vLocalPos.Y)).ToArray();
-        //    return Matrix.Identity.ToArray();
-        //}
-
         IGMatrix WithNoScale(IGMatrix mat)
         {
             var mat3 = mat.ExtractMatrix3();
@@ -144,11 +56,11 @@ namespace Max2Babylon
                     bones[index] = new BabylonBone { index = index, name = gameBone.Name };
                     //IGMatrix boneInitMatrix = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
 
-                    //skin.GetInitBoneTM(gameBone, boneInitMatrix);
-                    var boneInitMatrix = gameBone.GetObjectTM(0);
+                var boneInitMatrix = gameBone.GetObjectTM(0);
                     bindPoseInfos[index] = new BonePoseInfo { AbsoluteTransform = boneInitMatrix };
                 }
             }
+
             // fix hierarchy an generate animation keys
             for (var index = 0; index < skin.TotalSkinBoneCount; index++)
             {
@@ -162,178 +74,74 @@ namespace Max2Babylon
                 }
                 else
                 {
-                    var parent = gameBone.NodeParent;
-                    var babBone = bones[index];
-                    if (parent != null)
-                    {
-                        babBone.parentBoneIndex = boneIds.IndexOf(parent.NodeID);
-                    }
-                    if (babBone.parentBoneIndex == -1)
-                    {
+                var parent = gameBone.NodeParent;
+                var babBone = bones[index];
+                if (parent != null)
+                {
+                    babBone.parentBoneIndex = boneIds.IndexOf(parent.NodeID);
+                }
+                if (babBone.parentBoneIndex == -1)
+                {
                         bindPoseInfos[index].LocalTransform = bindPoseInfos[index].AbsoluteTransform.Multiply(meshInitMatrix.Inverse);
+                }
+                else
+                {
+                    var parentBindPoseInfos = bindPoseInfos[babBone.parentBoneIndex];
+                    bindPoseInfos[index].LocalTransform = bindPoseInfos[index].AbsoluteTransform.Multiply(parentBindPoseInfos.AbsoluteTransform.Inverse);
+                }
+                babBone.matrix = bindPoseInfos[index].LocalTransform.ToArray();
+
+                var babylonAnimation = new BabylonAnimation
+                {
+                    name = gameBone.Name + "Animation",
+                    property = "_matrix",
+                    dataType = BabylonAnimation.DataType.Matrix,
+                    loopBehavior = BabylonAnimation.LoopBehavior.Cycle,
+                    framePerSecond = Loader.Global.FrameRate
+                };
+
+                var start = Loader.Core.AnimRange.Start;
+                var end = Loader.Core.AnimRange.End;
+
+                float[] previous = null;
+                var keys = new List<BabylonAnimationKey>();
+                for (var key = start; key <= end; key += Ticks)
+                {
+                    var objectTM = gameBone.GetObjectTM(key);
+                    var parentNode = gameBone.NodeParent;
+                    IGMatrix mat;
+                    if (parentNode == null || babBone.parentBoneIndex == -1)
+                    {
+                        mat = objectTM.Multiply(meshNode.GetObjectTM(key).Inverse);
                     }
                     else
                     {
-                        var parentBindPoseInfos = bindPoseInfos[babBone.parentBoneIndex];
-                        bindPoseInfos[index].LocalTransform = bindPoseInfos[index].AbsoluteTransform.Multiply(parentBindPoseInfos.AbsoluteTransform.Inverse);
+                        mat = objectTM.Multiply(parentNode.GetObjectTM(key).Inverse);
                     }
-                    babBone.matrix = bindPoseInfos[index].LocalTransform.ToArray();
-
-                    var babylonAnimation = new BabylonAnimation
-                    {
-                        name = gameBone.Name + "Animation",
-                        property = "_matrix",
-                        dataType = BabylonAnimation.DataType.Matrix,
-                        loopBehavior = BabylonAnimation.LoopBehavior.Cycle,
-                        framePerSecond = Loader.Global.FrameRate
-                    };
-
-                    var start = Loader.Core.AnimRange.Start;
-                    var end = Loader.Core.AnimRange.End;
 
-                    float[] previous = null;
-                    var keys = new List<BabylonAnimationKey>();
-                    for (var key = start; key <= end; key += Ticks)
+                    var current = mat.ToArray();
+                    if (key == start || key == end || !(previous.IsEqualTo(current)))
                     {
-                        var objectTM = gameBone.GetObjectTM(key);
-                        var parentNode = gameBone.NodeParent;
-                        IGMatrix mat;
-                        if (parentNode == null || babBone.parentBoneIndex == -1)
+                        keys.Add(new BabylonAnimationKey
                         {
-                            mat = objectTM.Multiply(meshNode.GetObjectTM(key).Inverse);
-                        }
-                        else
-                        {
-                            mat = objectTM.Multiply(parentNode.GetObjectTM(key).Inverse);
-                        }
-
-                        var current = mat.ToArray();
-                        if (key == start || key == end || !(previous.IsEqualTo(current)))
-                        {
-                            keys.Add(new BabylonAnimationKey
-                            {
-                                frame = key / Ticks,
-                                values = current
-                            });
-                        }
-
-                        previous = current;
+                            frame = key / Ticks,
+                            values = current
+                        });
                     }
 
-                    babylonAnimation.keys = keys.ToArray();
-                    babBone.animation = babylonAnimation;
+                    previous = current;
+                }
+
+                babylonAnimation.keys = keys.ToArray();
+                babBone.animation = babylonAnimation;
                 }
 
             }
 
-            //FixupHierarchy(Loader.Core.RootNode, skin.GetBone(0), bones);
 
             babylonSkeleton.bones = bones;
 
             babylonScene.SkeletonsList.Add(babylonSkeleton);
         }
-
-        //private void ExportSkin(IISkin skin, BabylonScene babylonScene)
-        //{
-
-        //    var babylonSkeleton = new BabylonSkeleton { id = skins.IndexOf(skin) };
-        //    babylonSkeleton.name = "skeleton #" + babylonSkeleton.id;
-
-        //    RaiseMessage(babylonSkeleton.name, 1);
-
-        //    var bones = new List<BabylonBone>();
-
-        //    for (var index = 0; index < skin.NumBones; index++)
-        //    {
-        //        var bone = new BabylonBone { name = skin.GetBoneName(index), index = index };
-
-        //        var maxBone = skin.GetBone(index);
-        //        var parentNode = maxBone.ParentNode;
-
-        //        if (parentNode != null)
-        //        {
-        //            for (var recurseIndex = 0; recurseIndex < index; recurseIndex++)
-        //            {
-        //                if (skin.GetBone(recurseIndex).GetGuid() == parentNode.GetGuid())
-        //                {
-        //                    bone.parentBoneIndex = recurseIndex;
-        //                    break;
-        //                }
-        //            }
-        //        }
-        //        var hasParent = bone.parentBoneIndex != -1;
-        //        var currentBoneNeutralMatrix = GetBoneBindPoseLocalMatrix(skin, maxBone, hasParent);
-        //        bone.matrix = currentBoneNeutralMatrix;
-
-        //        // Animation
-        //        var babylonAnimation = new BabylonAnimation
-        //        {
-        //            name = bone.name + "Animation",
-        //            property = "_matrix",
-        //            dataType = BabylonAnimation.DataType.Matrix,
-        //            loopBehavior = BabylonAnimation.LoopBehavior.Cycle,
-        //            framePerSecond = Loader.Global.FrameRate
-        //        };
-
-        //        var start = Loader.Core.AnimRange.Start;
-        //        var end = Loader.Core.AnimRange.End;
-
-        //        float[] previous = null;
-        //        var keys = new List<BabylonAnimationKey>();
-        //        for (var key = start; key <= end; key += Ticks)
-        //        {
-        //            var current = GetBoneMatrixForFrame(maxBone, key, hasParent);
-
-        //            if (key == start || key == end || !(previous.IsEqualTo(current)))
-        //            {
-        //                keys.Add(new BabylonAnimationKey
-        //                {
-        //                    frame = key / Ticks,
-        //                    values = current
-        //                });
-        //            }
-
-        //            previous = current;
-        //        }
-
-        //        babylonAnimation.keys = keys.ToArray();
-        //        bone.animation = babylonAnimation;
-
-        //        bones.Add(bone);
-        //    }
-        //    //FixupHierarchy(Loader.Core.RootNode, skin.GetBone(0), bones);
-
-        //    babylonSkeleton.bones = bones.ToArray();
-
-        //    babylonScene.SkeletonsList.Add(babylonSkeleton);
-        //}
-
-        //private void FixupHierarchy(IINode sceneRoot, IINode skeletonRoot, List<BabylonBone> bones)
-        //{
-        //    var skeletonTransforms = new NodeTransforms(skeletonRoot, 0);
-        //    var sceneRootTransforms = new NodeTransforms(sceneRoot, 0);
-        //    var skelAbs = skeletonTransforms.AbsoluteTransform;
-        //    var invSceneAbs = sceneRootTransforms.AbsoluteTransform;
-        //    invSceneAbs.Invert();
-        //    var skelAbsInvSceneAbs = skelAbs.Multiply(invSceneAbs);
-        //    var invSkelLocalTransform = skeletonTransforms.LocalTransform;
-        //    invSkelLocalTransform.Invert();
-        //    var skelAbsInvSceneAbsXinvSkelLocalTransform = skelAbsInvSceneAbs.Multiply(invSkelLocalTransform);
-        //    bones[0].matrix = skelAbsInvSceneAbs.ToArray();
-        //    var matskelAbsInvSceneAbsXinvSkelLocalTransform = new Matrix(skelAbsInvSceneAbsXinvSkelLocalTransform.ToArray());
-        //    foreach (var b in bones)
-        //    {
-        //        var oldTransform = new Matrix(b.matrix);
-        //        b.matrix = (oldTransform * matskelAbsInvSceneAbsXinvSkelLocalTransform).ToArray();
-        //        foreach(var frame in b.animation.keys)
-        //        {
-
-        //            var oldTransform2 = new Matrix(frame.values);
-        //            frame.values = (oldTransform2 * matskelAbsInvSceneAbsXinvSkelLocalTransform).ToArray();
-        //        }
-        //    }
-
-
-        //}
     }
 }

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

@@ -135,7 +135,7 @@ namespace Max2Babylon
 
             RaiseMessage("Exporting cameras");
             var camerasTab = gameScene.GetIGameNodeByType(Autodesk.Max.IGameObject.ObjectTypes.Camera);
-            for(int ix = 0; ix < camerasTab.Count; ++ix)
+            for (int ix = 0; ix < camerasTab.Count; ++ix)
             {
                 var indexer = new IntPtr(ix);
                 var cameraNode = camerasTab[indexer];
@@ -151,7 +151,6 @@ namespace Max2Babylon
                 }
             }
 
-
             if (mainCamera == null)
             {
                 RaiseWarning("No camera defined", 1);
@@ -170,7 +169,7 @@ namespace Max2Babylon
                 {
                     var fog = atmospheric as IStdFog;
 
-                        RaiseMessage("Exporting fog");
+                    RaiseMessage("Exporting fog");
 
                     if (fog != null)
                     {
@@ -186,8 +185,8 @@ namespace Max2Babylon
                         babylonScene.fogMode = 3;
                     }
 #endif
-                        if (mainCamera != null)
-                        {
+                    if (mainCamera != null)
+                    {
                         babylonScene.fogStart = mainCameraNode.GetEnvRange(0, 0, Tools.Forever);
                         babylonScene.fogEnd = mainCameraNode.GetEnvRange(0, 1, Tools.Forever);
                     }
@@ -201,7 +200,7 @@ namespace Max2Babylon
             var progressionStep = 80.0f / meshes.Count;
             var progression = 10.0f;
             for (int ix = 0; ix < meshes.Count; ++ix)
-                {
+            {
                 var indexer = new IntPtr(ix);
                 var meshNode = meshes[indexer];
                 Marshal.FreeHGlobal(indexer);
@@ -227,8 +226,8 @@ namespace Max2Babylon
             // Lights
             RaiseMessage("Exporting lights");
             var lightNodes = gameScene.GetIGameNodeByType(Autodesk.Max.IGameObject.ObjectTypes.Light);
-            for(var i=0;i< lightNodes.Count; ++i)
-                {
+            for (var i = 0; i < lightNodes.Count; ++i)
+            {
                 ExportLight(lightNodes[new IntPtr(i)], babylonScene);
                 CheckCancelled();
             }
@@ -283,6 +282,6 @@ namespace Max2Babylon
             RaiseMessage(string.Format("Exportation done in {0:0.00}s", watch.ElapsedMilliseconds / 1000.0), Color.Blue);
         }
 
-        
+
     }
 }

+ 1 - 0
Exporters/3ds Max/readme.md

@@ -55,6 +55,7 @@ To export you can use the [Babylon] menu in the main menu bar.
  - Emissive color and texture
  - Opacity texture
  - Reflection texture
+ - Fresnel for diffuse, emissive, opacity and reflection
 - *Textures*
  - UV offset / scaling / angle
  - Level

+ 7 - 17
babylon.2.0-alpha.debug.js

@@ -10600,7 +10600,7 @@ var BABYLON;
             this._physicsFriction = options.friction;
             this._physicRestitution = options.restitution;
 
-            physicsEngine._registerMesh(this, impostor, options);
+            return physicsEngine._registerMesh(this, impostor, options);
         };
 
         AbstractMesh.prototype.getPhysicsImpostor = function () {
@@ -12642,9 +12642,9 @@ var BABYLON;
             this._alphaTestSubMeshes = new BABYLON.SmartArray(256);
             this._scene = scene;
         }
-        RenderingGroup.prototype.render = function (customRenderFunction, beforeTransparents) {
+        RenderingGroup.prototype.render = function (customRenderFunction) {
             if (customRenderFunction) {
-                customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes, beforeTransparents);
+                customRenderFunction(this._opaqueSubMeshes, this._alphaTestSubMeshes, this._transparentSubMeshes);
                 return true;
             }
 
@@ -12672,10 +12672,6 @@ var BABYLON;
             }
             engine.setAlphaTesting(false);
 
-            if (beforeTransparents) {
-                beforeTransparents();
-            }
-
            
             if (this._transparentSubMeshes.length) {
                 for (subIndex = 0; subIndex < this._transparentSubMeshes.length; subIndex++) {
@@ -12798,23 +12794,17 @@ var BABYLON;
         };
 
         RenderingManager.prototype.render = function (customRenderFunction, activeMeshes, renderParticles, renderSprites) {
-            var _this = this;
             for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
 
                 if (renderingGroup) {
                     this._clearDepthBuffer();
-                    if (!renderingGroup.render(customRenderFunction, function () {
-                        if (renderSprites) {
-                            _this._renderSprites(index);
-                        }
-                    })) {
+                    if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
-                    } else if (renderSprites) {
-                        this._renderSprites(index);
                     }
                 }
+                this._renderSprites(index);
                 if (renderParticles) {
                     this._renderParticles(index, activeMeshes);
                 }
@@ -16472,7 +16462,7 @@ var BABYLON;
                 this._appendSpriteVertex(offset++, sprite, 1, 1, rowSize);
                 this._appendSpriteVertex(offset++, sprite, 0, 1, rowSize);
             }
-            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices, max * this._vertexStrideSize);
+            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices);
 
            
             var effect = this._effectBase;
@@ -17027,7 +17017,7 @@ var BABYLON;
                 this._appendParticleVertex(offset++, particle, 0, 1);
             }
             var engine = this._scene.getEngine();
-            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices, this.particles.length * this._vertexStrideSize);
+            engine.updateDynamicVertexBuffer(this._vertexBuffer, this._vertices);
         };
 
         ParticleSystem.prototype.render = function () {

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 5 - 5
babylon.2.0-alpha.js