Browse Source

Merge remote-tracking branch 'remotes/BabylonJS/master' into BabylonJS-master

Gwenaël Hagenmuller 11 năm trước cách đây
mục cha
commit
1860b1d7cb

+ 30 - 27
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -7,12 +7,12 @@ var BABYLON = BABYLON || {};
 
     BABYLON.ArcRotateCamera = function (name, alpha, beta, radius, target, scene) {
         BABYLON.Camera.call(this, name, BABYLON.Vector3.Zero(), scene);
-        
+
         this.alpha = alpha;
         this.beta = beta;
         this.radius = radius;
         this.target = target;
-        
+
         this._keys = [];
         this.keysUp = [38];
         this.keysDown = [40];
@@ -22,10 +22,10 @@ var BABYLON = BABYLON || {};
         this._viewMatrix = new BABYLON.Matrix();
 
         BABYLON.ArcRotateCamera.prototype._initCache.call(this);
-        
+
         this.getViewMatrix();
     };
-    
+
     BABYLON.ArcRotateCamera.prototype = Object.create(BABYLON.Camera.prototype);
 
     // Members
@@ -43,7 +43,7 @@ var BABYLON = BABYLON || {};
     BABYLON.ArcRotateCamera.prototype._getTargetPosition = function () {
         return this.target.position || this.target;
     };
-    
+
     // Cache
     BABYLON.ArcRotateCamera.prototype._initCache = function () {
         this._cache.target = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
@@ -53,9 +53,9 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.ArcRotateCamera.prototype._updateCache = function (ignoreParentClass) {
-        if(!ignoreParentClass)
+        if (!ignoreParentClass)
             BABYLON.Camera.prototype._updateCache.call(this);
-        
+
         this._cache.target.copyFrom(this._getTargetPosition());
         this._cache.alpha = this.alpha;
         this._cache.beta = this.beta;
@@ -66,19 +66,19 @@ var BABYLON = BABYLON || {};
     BABYLON.ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
         if (!BABYLON.Camera.prototype._isSynchronizedViewMatrix.call(this))
             return false;
-        
+
         return this._cache.target.equals(this._getTargetPosition())
             && this._cache.alpha === this.alpha
             && this._cache.beta === this.beta
             && this._cache.radius === this.radius;
     };
-    
+
     // Methods
-    BABYLON.ArcRotateCamera.prototype.attachControl = function(canvas, noPreventDefault) {
+    BABYLON.ArcRotateCamera.prototype.attachControl = function (canvas, noPreventDefault) {
         var previousPosition;
         var that = this;
         var pointerId;
-        
+
         if (this._attachedCanvas) {
             return;
         }
@@ -87,7 +87,7 @@ var BABYLON = BABYLON || {};
         var engine = this._scene.getEngine();
 
         if (this._onPointerDown === undefined) {
-            this._onPointerDown = function(evt) {
+            this._onPointerDown = function (evt) {
 
                 if (pointerId) {
                     return;
@@ -105,7 +105,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onPointerUp = function(evt) {
+            this._onPointerUp = function (evt) {
                 previousPosition = null;
                 pointerId = null;
                 if (!noPreventDefault) {
@@ -113,7 +113,8 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onPointerMove = function(evt) {
+
+            this._onPointerMove = function (evt) {
                 if (!previousPosition) {
                     return;
                 }
@@ -138,7 +139,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onMouseMove = function(evt) {
+            this._onMouseMove = function (evt) {
                 if (!engine.isPointerLock) {
                     return;
                 }
@@ -154,7 +155,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._wheel = function(event) {
+            this._wheel = function (event) {
                 var delta = 0;
                 if (event.wheelDelta) {
                     delta = event.wheelDelta / 120;
@@ -172,7 +173,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onKeyDown = function(evt) {
+            this._onKeyDown = function (evt) {
                 if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
                     that.keysDown.indexOf(evt.keyCode) !== -1 ||
                     that.keysLeft.indexOf(evt.keyCode) !== -1 ||
@@ -191,7 +192,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onKeyUp = function(evt) {
+            this._onKeyUp = function (evt) {
                 if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
                     that.keysDown.indexOf(evt.keyCode) !== -1 ||
                     that.keysLeft.indexOf(evt.keyCode) !== -1 ||
@@ -210,7 +211,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._onLostFocus = function() {
+            this._onLostFocus = function () {
                 that._keys = [];
                 pointerId = null;
             };
@@ -228,9 +229,10 @@ var BABYLON = BABYLON || {};
                 that._MSGestureHandler.addPointer(e.pointerId);
             };
 
-            this._onGesture = function(e) {
+            this._onGesture = function (e) {
                 that.radius *= e.scale;
 
+
                 if (e.preventDefault) {
                     if (!noPreventDefault) {
                         e.stopPropagation();
@@ -239,7 +241,7 @@ var BABYLON = BABYLON || {};
                 }
             };
 
-            this._reset = function() {
+            this._reset = function () {
                 that._keys = [];
                 that.inertialAlphaOffset = 0;
                 that.inertialBetaOffset = 0;
@@ -260,7 +262,7 @@ var BABYLON = BABYLON || {};
         window.addEventListener('mousewheel', this._wheel, false);
         window.addEventListener("blur", this._onLostFocus, false);
     };
-    
+
     BABYLON.ArcRotateCamera.prototype.detachControl = function (canvas) {
         if (this._attachedCanvas != canvas) {
             return;
@@ -301,7 +303,7 @@ var BABYLON = BABYLON || {};
                 this.inertialBetaOffset += 0.01;
             }
         }
-        
+
         // Inertia
         if (this.inertialAlphaOffset != 0 || this.inertialBetaOffset != 0 || this.inertialRadiusOffset != 0) {
 
@@ -322,7 +324,7 @@ var BABYLON = BABYLON || {};
             if (Math.abs(this.inertialRadiusOffset) < BABYLON.Engine.epsilon)
                 this.inertialRadiusOffset = 0;
         }
-        
+
         // Limits
         if (this.lowerAlphaLimit && this.alpha < this.lowerAlphaLimit) {
             this.alpha = this.lowerAlphaLimit;
@@ -344,7 +346,7 @@ var BABYLON = BABYLON || {};
         }
     };
 
-    BABYLON.ArcRotateCamera.prototype.setPosition = function(position) {
+    BABYLON.ArcRotateCamera.prototype.setPosition = function (position) {
         var radiusv3 = position.subtract(this._getTargetPosition());
         this.radius = radiusv3.length();
 
@@ -366,10 +368,11 @@ var BABYLON = BABYLON || {};
         var sinb = Math.sin(this.beta);
 
         var target = this._getTargetPosition();
-        
+
         target.addToRef(new BABYLON.Vector3(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb), this.position);
         BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._viewMatrix);
 
         return this._viewMatrix;
     };
-})();
+})();
+

+ 38 - 37
Babylon/Cameras/babylon.camera.js

@@ -4,15 +4,12 @@ var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Camera = function (name, position, scene) {
-        BABYLON.Node.call(this);
-        
+        BABYLON.Node.call(this, scene);
+
         this.name = name;
         this.id = name;
         this.position = position;
         this.upVector = BABYLON.Vector3.Up();
-        this._childrenFlag = true;
-
-        this._scene = scene;
 
         scene.cameras.push(this);
 
@@ -28,10 +25,10 @@ var BABYLON = BABYLON || {};
 
         // Postprocesses
         this.postProcesses = [];
-        
+
         // Viewport
         this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
-        
+
         //Cache
         BABYLON.Camera.prototype._initCache.call(this);
     };
@@ -57,7 +54,9 @@ var BABYLON = BABYLON || {};
     BABYLON.Camera.prototype.getScene = function () {
         return this._scene;
     };
-    
+
+    // Methods
+
     //Cache
     BABYLON.Camera.prototype._initCache = function () {
         this._cache.position = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
@@ -79,9 +78,12 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Camera.prototype._updateCache = function (ignoreParentClass) {
-        if(!ignoreParentClass)
+        if (!ignoreParentClass) {
             BABYLON.Node.prototype._updateCache.call(this);
-        
+        }
+
+        var engine = this._scene.getEngine();
+
         this._cache.position.copyFrom(this.position);
         this._cache.upVector.copyFrom(this.upVector);
 
@@ -90,9 +92,6 @@ var BABYLON = BABYLON || {};
         this._cache.maxZ = this.maxZ;
 
         this._cache.fov = this.fov;
-
-        var engine = this._scene.getEngine();
-
         this._cache.aspectRatio = engine.getAspectRatio();
 
         this._cache.orthoLeft = this.orthoLeft;
@@ -103,6 +102,11 @@ var BABYLON = BABYLON || {};
         this._cache.renderHeight = engine.getRenderHeight();
     };
 
+    BABYLON.Camera.prototype._updateFromScene = function () {
+        this.updateCache();
+        this._update();
+    };
+
     // Synchronized
     BABYLON.Camera.prototype._isSynchronized = function () {
         return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();
@@ -111,38 +115,40 @@ var BABYLON = BABYLON || {};
     BABYLON.Camera.prototype._isSynchronizedViewMatrix = function () {
         if (!BABYLON.Node.prototype._isSynchronized.call(this))
             return false;
-        
-        return this._cache.position.equals(this.position) 
-            && this._cache.upVector.equals(this.upVector);
+
+        return this._cache.position.equals(this.position)
+            && this._cache.upVector.equals(this.upVector)
+            && this.isSynchronizedWithParent();
     };
 
     BABYLON.Camera.prototype._isSynchronizedProjectionMatrix = function () {
-        var r = this._cache.mode === this.mode
+        var check = this._cache.mode === this.mode
              && this._cache.minZ === this.minZ
              && this._cache.maxZ === this.maxZ;
-             
-        if (!r)
-            return false;
 
+        if (!check) {
+            return false;
+        }
 
         var engine = this._scene.getEngine();
 
         if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
-            r = this._cache.fov === this.fov
+            check = this._cache.fov === this.fov
                  && this._cache.aspectRatio === engine.getAspectRatio();
         }
         else {
-            r = this._cache.orthoLeft === this.orthoLeft
+            check = this._cache.orthoLeft === this.orthoLeft
                  && this._cache.orthoRight === this.orthoRight
                  && this._cache.orthoBottom === this.orthoBottom
                  && this._cache.orthoTop === this.orthoTop
                  && this._cache.renderWidth === engine.getRenderWidth()
                  && this._cache.renderHeight === engine.getRenderHeight();
         }
-        return r;
+
+        return check;
     };
 
-    // Methods
+    // Controls
     BABYLON.Camera.prototype.attachControl = function (canvas) {
     };
 
@@ -151,17 +157,12 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Camera.prototype._update = function () {
     };
-    
-    BABYLON.Camera.prototype._updateFromScene = function () {
-        this.updateCache();
-        this._update();
-    };
 
     BABYLON.Camera.prototype.getWorldMatrix = function () {
         if (!this._worldMatrix) {
             this._worldMatrix = BABYLON.Matrix.Identity();
         }
-        
+
         var viewMatrix = this.getViewMatrix();
 
         viewMatrix.invertToRef(this._worldMatrix);
@@ -176,8 +177,8 @@ var BABYLON = BABYLON || {};
     BABYLON.Camera.prototype.getViewMatrix = function () {
         this._computedViewMatrix = this._computeViewMatrix();
 
-        if(!this.parent 
-            ||  !this.parent.getWorldMatrix
+        if (!this.parent
+            || !this.parent.getWorldMatrix
             || (!this.hasNewParent() && this.parent.isSynchronized())) {
             return this._computedViewMatrix;
         }
@@ -185,7 +186,7 @@ var BABYLON = BABYLON || {};
         if (!this._worldMatrix) {
             this._worldMatrix = BABYLON.Matrix.Identity();
         }
-        
+
         this._computedViewMatrix.invertToRef(this._worldMatrix);
 
         this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
@@ -194,18 +195,18 @@ var BABYLON = BABYLON || {};
 
         return this._computedViewMatrix;
     };
-    
+
     BABYLON.Camera.prototype._computeViewMatrix = function (force) {
         if (!force && this._isSynchronizedViewMatrix()) {
             return this._computedViewMatrix;
         }
-        
+        this._syncChildFlag();
         this._computedViewMatrix = this._getViewMatrix();
         return this._computedViewMatrix;
     };
 
     BABYLON.Camera.prototype.getProjectionMatrix = function (force) {
-        if(!force && this._isSynchronizedProjectionMatrix()) {
+        if (!force && this._isSynchronizedProjectionMatrix()) {
             return this._projectionMatrix;
         }
 
@@ -225,7 +226,7 @@ var BABYLON = BABYLON || {};
         // Remove from scene
         var index = this._scene.cameras.indexOf(this);
         this._scene.cameras.splice(index, 1);
-        
+
         // Postprocesses
         while (this.postProcesses.length) {
             this.postProcesses[0].dispose();

+ 34 - 24
Babylon/Cameras/babylon.freeCamera.js

@@ -5,7 +5,7 @@ var BABYLON = BABYLON || {};
 (function () {
     BABYLON.FreeCamera = function (name, position, scene) {
         BABYLON.Camera.call(this, name, position, scene);
-        
+
         this.cameraDirection = new BABYLON.Vector3(0, 0, 0);
         this.cameraRotation = new BABYLON.Vector2(0, 0);
         this.rotation = new BABYLON.Vector3(0, 0, 0);
@@ -34,7 +34,7 @@ var BABYLON = BABYLON || {};
         this._newPosition = BABYLON.Vector3.Zero();
         this._lookAtTemp = BABYLON.Matrix.Zero();
         this._tempMatrix = BABYLON.Matrix.Zero();
-        
+
         BABYLON.FreeCamera.prototype._initCache.call(this);
     };
 
@@ -49,10 +49,11 @@ var BABYLON = BABYLON || {};
     BABYLON.FreeCamera.prototype.lockedTarget = null;
     BABYLON.FreeCamera.prototype.onCollide = null;
 
-    BABYLON.FreeCamera.prototype._getLockedTargetPosition = function () {       
-        if(!this.lockedTarget)
+    BABYLON.FreeCamera.prototype._getLockedTargetPosition = function () {
+        if (!this.lockedTarget) {
             return null;
-        
+        }
+
         return this.lockedTarget.position || this.lockedTarget;
     };
 
@@ -63,34 +64,35 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.FreeCamera.prototype._updateCache = function (ignoreParentClass) {
-        if(!ignoreParentClass)
+        if (!ignoreParentClass)
             BABYLON.Camera.prototype._updateCache.call(this);
-        
+
         var lockedTargetPosition = this._getLockedTargetPosition();
         if (!lockedTargetPosition) {
             this._cache.lockedTarget = null;
         }
         else {
-            if (!this._cache.lockedTarget) 
+            if (!this._cache.lockedTarget)
                 this._cache.lockedTarget = lockedTargetPosition.clone();
             else
                 this._cache.lockedTarget.copyFrom(lockedTargetPosition);
         }
-        
+
         this._cache.rotation.copyFrom(this.rotation);
     };
 
     // Synchronized
     BABYLON.FreeCamera.prototype._isSynchronizedViewMatrix = function () {
-        if (!BABYLON.Camera.prototype._isSynchronizedViewMatrix.call(this))
+        if (!BABYLON.Camera.prototype._isSynchronizedViewMatrix.call(this)) {
             return false;
+        }
 
         var lockedTargetPosition = this._getLockedTargetPosition();
- 
+
         return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
             && this._cache.rotation.equals(this.rotation);
-    };    
-    
+    };
+
     // Methods
     BABYLON.FreeCamera.prototype._computeLocalCameraSpeed = function () {
         return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
@@ -99,7 +101,7 @@ var BABYLON = BABYLON || {};
     // Target
     BABYLON.FreeCamera.prototype.setTarget = function (target) {
         this.upVector.normalize();
-        
+
         BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
         this._camMatrix.invert();
 
@@ -115,14 +117,17 @@ var BABYLON = BABYLON || {};
 
         this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
 
-        if (isNaN(this.rotation.x))
+        if (isNaN(this.rotation.x)) {
             this.rotation.x = 0;
+        }
 
-        if (isNaN(this.rotation.y))
+        if (isNaN(this.rotation.y)) {
             this.rotation.y = 0;
+        }
 
-        if (isNaN(this.rotation.z))
+        if (isNaN(this.rotation.z)) {
             this.rotation.z = 0;
+        }
     };
 
     // Controls
@@ -130,7 +135,7 @@ var BABYLON = BABYLON || {};
         var previousPosition;
         var that = this;
         var engine = this._scene.getEngine();
-        
+
         if (this._attachedCanvas) {
             return;
         }
@@ -227,7 +232,7 @@ var BABYLON = BABYLON || {};
                 that._keys = [];
             };
 
-            this._reset = function() {
+            this._reset = function () {
                 that._keys = [];
                 previousPosition = null;
                 that.cameraDirection = new BABYLON.Vector3(0, 0, 0);
@@ -256,7 +261,7 @@ var BABYLON = BABYLON || {};
         window.removeEventListener("keydown", this._onKeyDown);
         window.removeEventListener("keyup", this._onKeyUp);
         window.removeEventListener("blur", this._onLostFocus);
-        
+
         this._attachedCanvas = null;
         if (this._reset) {
             this._reset();
@@ -316,6 +321,7 @@ var BABYLON = BABYLON || {};
             if (this.checkCollisions && this._scene.collisionsEnabled) {
                 this._collideWithWorld(this.cameraDirection);
 
+
                 if (this.applyGravity) {
                     var oldPosition = this.position;
                     this._collideWithWorld(this._scene.gravity);
@@ -331,9 +337,11 @@ var BABYLON = BABYLON || {};
             this.rotation.x += this.cameraRotation.x;
             this.rotation.y += this.cameraRotation.y;
 
+
             if (!this.noRotationConstraint) {
                 var limit = (Math.PI / 2) * 0.95;
 
+
                 if (this.rotation.x > limit)
                     this.rotation.x = limit;
                 if (this.rotation.x < -limit)
@@ -351,7 +359,7 @@ var BABYLON = BABYLON || {};
 
             if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.epsilon)
                 this.cameraDirection.z = 0;
-        
+
             this.cameraDirection.scaleInPlace(this.inertia);
         }
         if (needToRotate) {
@@ -360,7 +368,7 @@ var BABYLON = BABYLON || {};
 
             if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.epsilon)
                 this.cameraRotation.y = 0;
-        
+
             this.cameraRotation.scaleInPlace(this.inertia);
         }
     };
@@ -374,6 +382,7 @@ var BABYLON = BABYLON || {};
                 BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
                 BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
 
+
                 this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
                 this._lookAtTemp.invert();
                 this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
@@ -388,8 +397,9 @@ var BABYLON = BABYLON || {};
         } else {
             this._currentTarget.copyFrom(this._getLockedTargetPosition());
         }
-        
+
         BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
         return this._viewMatrix;
     };
-})();
+})();
+

+ 1 - 1
Babylon/Culling/Octrees/babylon.octreeBlock.js

@@ -78,7 +78,7 @@ var BABYLON = BABYLON || {};
             }
             return;
         }
-        if (BABYLON.BoundingBox.IsInFrustrum(this._boundingVectors, frustumPlanes)) {
+        if (BABYLON.BoundingBox.IsInFrustum(this._boundingVectors, frustumPlanes)) {
             selection.push(this);
         }
     };

+ 3 - 3
Babylon/Culling/babylon.boundingBox.js

@@ -80,8 +80,8 @@ var BABYLON = BABYLON || {};
         BABYLON.Vector3.FromArrayToRef(world.m, 8, this.directions[2]);
     };
 
-    BABYLON.BoundingBox.prototype.isInFrustrum = function (frustumPlanes) {
-        return BABYLON.BoundingBox.IsInFrustrum(this.vectorsWorld, frustumPlanes);
+    BABYLON.BoundingBox.prototype.isInFrustum = function (frustumPlanes) {
+        return BABYLON.BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);
     };
 
     BABYLON.BoundingBox.prototype.intersectsPoint = function (point) {
@@ -130,7 +130,7 @@ var BABYLON = BABYLON || {};
         return true;
     };
     
-    BABYLON.BoundingBox.IsInFrustrum = function (boundingVectors, frustumPlanes) {
+    BABYLON.BoundingBox.IsInFrustum = function (boundingVectors, frustumPlanes) {
         for (var p = 0; p < 6; p++) {
             var inCount = 8;
 

+ 3 - 3
Babylon/Culling/babylon.boundingInfo.js

@@ -39,11 +39,11 @@ var BABYLON = BABYLON || {};
         return extentsOverlap(result0.min, result0.max, result1.min, result1.max);
     };
 
-    BABYLON.BoundingInfo.prototype.isInFrustrum = function (frustumPlanes) {
-        if (!this.boundingSphere.isInFrustrum(frustumPlanes))
+    BABYLON.BoundingInfo.prototype.isInFrustum = function (frustumPlanes) {
+        if (!this.boundingSphere.isInFrustum(frustumPlanes))
             return false;
 
-        return this.boundingBox.isInFrustrum(frustumPlanes);
+        return this.boundingBox.isInFrustum(frustumPlanes);
     };
 
     BABYLON.BoundingInfo.prototype._checkCollision = function (collider) {

+ 1 - 1
Babylon/Culling/babylon.boundingSphere.js

@@ -22,7 +22,7 @@ var BABYLON = BABYLON || {};
         this.radiusWorld = this.radius * scale;
     };
     
-    BABYLON.BoundingSphere.prototype.isInFrustrum = function (frustumPlanes) {
+    BABYLON.BoundingSphere.prototype.isInFrustum = function (frustumPlanes) {
         for (var i = 0; i < 6; i++) {
             if (frustumPlanes[i].dotCoordinate(this.centerWorld) <= -this.radiusWorld)
                 return false;

BIN
Babylon/JSKompactor.exe


+ 5 - 4
Babylon/Lights/babylon.light.js

@@ -4,11 +4,10 @@ var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Light = function (name, scene) {
+        BABYLON.Node.call(this, scene);
+
         this.name = name;
         this.id = name;
-        this._childrenFlag = true;
-
-        this._scene = scene;
 
         scene.lights.push(this);
         
@@ -37,7 +36,9 @@ var BABYLON = BABYLON || {};
     BABYLON.Light.prototype.transferToEffect = function() {
     };
 
-    BABYLON.Light.prototype.getWorldMatrix = function() {
+    BABYLON.Light.prototype.getWorldMatrix = function () {
+        this._syncChildFlag();
+
         var worldMatrix = this._getWorldMatrix();
 
         if (this.parent && this.parent.getWorldMatrix) {

+ 85 - 62
Babylon/Mesh/babylon.mesh.js

@@ -4,11 +4,10 @@ var BABYLON = BABYLON || {};
 
 (function () {
     BABYLON.Mesh = function (name, scene) {
-        BABYLON.Node.call(this);
-        
+        BABYLON.Node.call(this, scene);
+
         this.name = name;
         this.id = name;
-        this._scene = scene;
 
         this._totalVertices = 0;
         this._worldMatrix = BABYLON.Matrix.Identity();
@@ -28,16 +27,14 @@ var BABYLON = BABYLON || {};
         this._renderId = 0;
 
         this._onBeforeRenderCallbacks = [];
-        
+
         // Animations
         this.animations = [];
 
-        this._positions = null;
-        
         // Cache
+        this._positions = null;
         BABYLON.Mesh.prototype._initCache.call(this);
 
-        this._childrenFlag = false;
         this._localScaling = BABYLON.Matrix.Zero();
         this._localRotation = BABYLON.Matrix.Zero();
         this._localTranslation = BABYLON.Matrix.Zero();
@@ -53,7 +50,7 @@ var BABYLON = BABYLON || {};
 
         this._absolutePosition = BABYLON.Vector3.Zero();
     };
-    
+
     BABYLON.Mesh.prototype = Object.create(BABYLON.Node.prototype);
 
     // Constants
@@ -77,9 +74,9 @@ var BABYLON = BABYLON || {};
     BABYLON.Mesh.prototype.onDispose = null;
 
     BABYLON.Mesh.prototype.skeleton = null;
-    
+
     BABYLON.Mesh.prototype.renderingGroupId = 0;
-    
+
     BABYLON.Mesh.prototype.infiniteDistance = false;
 
     // Properties
@@ -98,11 +95,11 @@ var BABYLON = BABYLON || {};
         }
         return this._worldMatrix;
     };
-    
+
     BABYLON.Mesh.prototype.getAbsolutePosition = function () {
         return this._absolutePosition;
     };
-        
+
     BABYLON.Mesh.prototype.getTotalVertices = function () {
         return this._totalVertices;
     };
@@ -112,7 +109,7 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Mesh.prototype.isVerticesDataPresent = function (kind) {
-        if (!this._vertexBuffers && this._delayInfo) {            
+        if (!this._vertexBuffers && this._delayInfo) {
             return this._delayInfo.indexOf(kind) !== -1;
         }
 
@@ -147,7 +144,7 @@ var BABYLON = BABYLON || {};
         if (this._cache.pivotMatrixUpdated) {
             return false;
         }
-        
+
         if (this.infiniteDistance) {
             return false;
         }
@@ -180,15 +177,23 @@ var BABYLON = BABYLON || {};
     BABYLON.Mesh.prototype.isDisposed = function () {
         return this._isDisposed;
     };
-    
+
     // Methods
+    BABYLON.Mesh.prototype._initCache = function () {
+        this._cache.localMatrixUpdated = false;
+        this._cache.position = BABYLON.Vector3.Zero();
+        this._cache.scaling = BABYLON.Vector3.Zero();
+        this._cache.rotation = BABYLON.Vector3.Zero();
+        this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
+    };
+
     BABYLON.Mesh.prototype.markAsDirty = function (property) {
         if (property === "rotation") {
             this.rotationQuaternion = null;
         }
-        this._childrenFlag = true;
+        this._syncChildFlag();
     };
-    
+
     BABYLON.Mesh.prototype.refreshBoundingInfo = function () {
         var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
 
@@ -202,11 +207,11 @@ var BABYLON = BABYLON || {};
         for (var index = 0; index < this.subMeshes.length; index++) {
             this.subMeshes[index].refreshBoundingInfo();
         }
-        
+
         this._updateBoundingInfo();
     };
 
-    BABYLON.Mesh.prototype._updateBoundingInfo = function() {
+    BABYLON.Mesh.prototype._updateBoundingInfo = function () {
         if (this._boundingInfo) {
             this._scaleFactor = Math.max(this.scaling.x, this.scaling.y);
             this._scaleFactor = Math.max(this._scaleFactor, this.scaling.z);
@@ -226,11 +231,10 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Mesh.prototype.computeWorldMatrix = function (force) {
         if (!force && (this._currentRenderId == this._scene.getRenderId() || this.isSynchronized(true))) {
-            this._childrenFlag = false;
             return this._worldMatrix;
         }
 
-        this._childrenFlag = true;
+        this._syncChildFlag();
         this._cache.position.copyFrom(this.position);
         this._cache.scaling.copyFrom(this.scaling);
         this._cache.pivotMatrixUpdated = false;
@@ -289,7 +293,7 @@ var BABYLON = BABYLON || {};
             this._localPivotScalingRotation.multiplyToRef(this._localBillboard, this._localWorld);
             this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotation);
         }
-        
+
         // Local world
         this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
 
@@ -297,9 +301,6 @@ var BABYLON = BABYLON || {};
         if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.Mesh.BILLBOARDMODE_NONE) {
             this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
         } else {
-            // multiplyToRef instead of this._worldMatrix = this._localWorld;
-            // to be sure not to have a bug with a call to this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
-            // Moreover multiplyToRef is more efficient than clone
             this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._worldMatrix);
         }
 
@@ -312,6 +313,7 @@ var BABYLON = BABYLON || {};
         return this._worldMatrix;
     };
 
+
     BABYLON.Mesh.prototype._createGlobalSubMesh = function () {
         if (!this._totalVertices || !this._indices) {
             return null;
@@ -395,7 +397,7 @@ var BABYLON = BABYLON || {};
         // Draw order
         engine.draw(useTriangles, useTriangles ? subMesh.indexStart : 0, useTriangles ? subMesh.indexCount : subMesh.linesIndexCount);
     };
-    
+
     BABYLON.Mesh.prototype.registerBeforeRender = function (func) {
         this._onBeforeRenderCallbacks.push(func);
     };
@@ -412,11 +414,11 @@ var BABYLON = BABYLON || {};
         if (!this._vertexBuffers || !this._indexBuffer) {
             return;
         }
-        
+
         for (var callbackIndex = 0; callbackIndex < this._onBeforeRenderCallbacks.length; callbackIndex++) {
             this._onBeforeRenderCallbacks[callbackIndex]();
         }
-        
+
         // World
         var world = this.getWorldMatrix();
 
@@ -477,13 +479,13 @@ var BABYLON = BABYLON || {};
         return results;
     };
 
-    BABYLON.Mesh.prototype.isInFrustrum = function (frustumPlanes) {
+    BABYLON.Mesh.prototype.isInFrustum = function (frustumPlanes) {
         if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
             return false;
         }
 
-        var result = this._boundingInfo.isInFrustrum(frustumPlanes);
-        
+        var result = this._boundingInfo.isInFrustum(frustumPlanes);
+
         if (result && this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
             var that = this;
@@ -530,8 +532,8 @@ var BABYLON = BABYLON || {};
     };
 
     // Geometry
-    // deprecated: use setPositionWithLocalVector instead. It fixes setLocalTranslation.
-    BABYLON.Mesh.prototype.setLocalTranslation = function(vector3) {
+    // Deprecated: use setPositionWithLocalVector instead 
+    BABYLON.Mesh.prototype.setLocalTranslation = function (vector3) {
         console.warn("deprecated: use setPositionWithLocalVector instead");
         this.computeWorldMatrix();
         var worldMatrix = this._worldMatrix.clone();
@@ -539,8 +541,8 @@ var BABYLON = BABYLON || {};
 
         this.position = BABYLON.Vector3.TransformCoordinates(vector3, worldMatrix);
     };
-    
-    // deprecated: use getPositionExpressedInLocalSpace instead. It fixes getLocalTranslation.
+
+    // Deprecated: use getPositionExpressedInLocalSpace instead 
     BABYLON.Mesh.prototype.getLocalTranslation = function () {
         console.warn("deprecated: use getPositionExpressedInLocalSpace instead");
         this.computeWorldMatrix();
@@ -550,10 +552,10 @@ var BABYLON = BABYLON || {};
 
         return BABYLON.Vector3.TransformCoordinates(this.position, invWorldMatrix);
     };
-    
-    BABYLON.Mesh.prototype.setPositionWithLocalVector = function(vector3) {
+
+    BABYLON.Mesh.prototype.setPositionWithLocalVector = function (vector3) {
         this.computeWorldMatrix();
-        
+
         this.position = BABYLON.Vector3.TransformNormal(vector3, this._localWorld);
     };
 
@@ -564,10 +566,10 @@ var BABYLON = BABYLON || {};
 
         return BABYLON.Vector3.TransformNormal(this.position, invLocalWorldMatrix);
     };
-    
-    BABYLON.Mesh.prototype.locallyTranslate = function(vector3) {
+
+    BABYLON.Mesh.prototype.locallyTranslate = function (vector3) {
         this.computeWorldMatrix();
-        
+
         this.position = BABYLON.Vector3.TransformCoordinates(vector3, this._localWorld);
     };
 
@@ -600,6 +602,25 @@ var BABYLON = BABYLON || {};
         this.setVerticesData(temp, BABYLON.VertexBuffer.NormalKind, this._vertexBuffers[BABYLON.VertexBuffer.NormalKind].isUpdatable());
     };
 
+    BABYLON.Mesh.prototype.lookAt = function (targetPoint, yawCor, pitchCor, rollCor) {
+        /// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
+        /// <param name="targetPoint" type="BABYLON.Vector3">The position (must be in same space as current mesh) to look at</param>
+        /// <param name="yawCor" type="Number">optional yaw (y-axis) correction in radians</param>
+        /// <param name="pitchCor" type="Number">optional pitch (x-axis) correction in radians</param>
+        /// <param name="rollCor" type="Number">optional roll (z-axis) correction in radians</param>
+        /// <returns>Mesh oriented towards targetMesh</returns>
+
+        yawCor = yawCor || 0; // default to zero if undefined 
+        pitchCor = pitchCor || 0;
+        rollCor = rollCor || 0;
+
+        var dv = targetPoint.subtract(this.position);
+        var yaw = -Math.atan2(dv.z, dv.x) - Math.PI / 2;
+        var len = Math.sqrt(dv.x * dv.x + dv.z * dv.z);
+        var pitch = Math.atan2(dv.y, len);
+        this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw + yawCor, pitch + pitchCor, rollCor);
+    };
+
     // Cache
     BABYLON.Mesh.prototype._resetPointsArrayCache = function () {
         this._positions = null;
@@ -776,6 +797,8 @@ var BABYLON = BABYLON || {};
             }
         }
 
+        result.computeWorldMatrix(true);
+
         return result;
     };
 
@@ -813,6 +836,14 @@ var BABYLON = BABYLON || {};
                     objects[index].dispose();
                 }
             }
+        } else {
+            for (var index = 0; index < this._scene.meshes.length; index++) {
+                var obj = this._scene.meshes[index];
+                if (obj.parent === this) {
+                    obj.parent = null;
+                    obj.computeWorldMatrix(true);
+                }
+            }
         }
 
         this._isDisposed = true;
@@ -822,16 +853,16 @@ var BABYLON = BABYLON || {};
             this.onDispose();
         }
     };
-    
+
     // Physics
-    BABYLON.Mesh.prototype.setPhysicsState = function(options) {
+    BABYLON.Mesh.prototype.setPhysicsState = function (options) {
         if (!this._scene._physicsEngine) {
             return;
         }
 
         options.impostor = options.impostor || BABYLON.PhysicsEngine.NoImpostor;
         options.mass = options.mass || 0;
-        options.friction = options.friction || 0.0;
+        options.friction = options.friction || 0.2;
         options.restitution = options.restitution || 0.9;
 
         this._physicImpostor = options.impostor;
@@ -843,11 +874,11 @@ var BABYLON = BABYLON || {};
             this._scene._physicsEngine._unregisterMesh(this);
             return;
         }
-        
+
         this._scene._physicsEngine._registerMesh(this, options);
     };
 
-    BABYLON.Mesh.prototype.getPhysicsImpostor = function() {
+    BABYLON.Mesh.prototype.getPhysicsImpostor = function () {
         if (!this._physicImpostor) {
             return BABYLON.PhysicsEngine.NoImpostor;
         }
@@ -855,14 +886,14 @@ var BABYLON = BABYLON || {};
         return this._physicImpostor;
     };
 
-    BABYLON.Mesh.prototype.getPhysicsMass = function() {
+    BABYLON.Mesh.prototype.getPhysicsMass = function () {
         if (!this._physicsMass) {
             return 0;
         }
 
         return this._physicsMass;
     };
-    
+
     BABYLON.Mesh.prototype.getPhysicsFriction = function () {
         if (!this._physicsFriction) {
             return 0;
@@ -870,7 +901,7 @@ var BABYLON = BABYLON || {};
 
         return this._physicsFriction;
     };
-    
+
     BABYLON.Mesh.prototype.getPhysicsRestitution = function () {
         if (!this._physicRestitution) {
             return 0;
@@ -879,7 +910,7 @@ var BABYLON = BABYLON || {};
         return this._physicRestitution;
     };
 
-    BABYLON.Mesh.prototype.applyImpulse = function(force, contactPoint) {
+    BABYLON.Mesh.prototype.applyImpulse = function (force, contactPoint) {
         if (!this._physicImpostor) {
             return;
         }
@@ -887,11 +918,11 @@ var BABYLON = BABYLON || {};
         this._scene._physicsEngine._applyImpulse(this, force, contactPoint);
     };
 
-    BABYLON.Mesh.prototype.setPhysicsLinkWith = function(otherMesh, pivot1, pivot2) {
+    BABYLON.Mesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2) {
         if (!this._physicImpostor) {
             return;
         }
-        
+
         this._scene._physicsEngine._createLink(this, otherMesh, pivot1, pivot2);
     };
 
@@ -1038,7 +1069,7 @@ var BABYLON = BABYLON || {};
 
         var createCylinderCap = function (isTop) {
             var radius = isTop ? radiusTop : radiusBottom;
-            
+
             if (radius == 0) {
                 return
             }
@@ -1125,7 +1156,7 @@ var BABYLON = BABYLON || {};
         cylinder.setIndices(indices);
 
         return cylinder;
-    };    
+    };
 
     // Torus  (Code from SharpDX.org)
     BABYLON.Mesh.CreateTorus = function (name, diameter, thickness, tessellation, scene, updatable) {
@@ -1348,14 +1379,6 @@ var BABYLON = BABYLON || {};
 
         return ground;
     };
-    
-    BABYLON.Mesh.prototype._initCache = function () {
-        this._cache.localMatrixUpdated = false;
-        this._cache.position = BABYLON.Vector3.Zero();
-        this._cache.scaling = BABYLON.Vector3.Zero();
-        this._cache.rotation = BABYLON.Vector3.Zero();
-        this._cache.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 0);
-    };
 
     // Tools
     BABYLON.Mesh.ComputeNormal = function (positions, normals, indices) {

+ 2 - 2
Babylon/Mesh/babylon.subMesh.js

@@ -58,8 +58,8 @@ var BABYLON = BABYLON || {};
         this._boundingInfo._update(world, scale);
     };
 
-    BABYLON.SubMesh.prototype.isInFrustrum = function (frustumPlanes) {
-        return this._boundingInfo.isInFrustrum(frustumPlanes);
+    BABYLON.SubMesh.prototype.isInFrustum = function (frustumPlanes) {
+        return this._boundingInfo.isInFrustum(frustumPlanes);
     };
 
     BABYLON.SubMesh.prototype.render = function () {

+ 136 - 29
Babylon/Physics/babylon.physicsEngine.js

@@ -3,31 +3,35 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.PhysicsEngine = function (gravity) {
-        this.gravity = gravity || new BABYLON.Vector3(0, 0, -9.82);
-
+    BABYLON.PhysicsEngine = function (gravity, iterations) {
         this._world = new CANNON.World();
         this._world.broadphase = new CANNON.NaiveBroadphase();
-        this._world.gravity.set(this.gravity.x, this.gravity.y, this.gravity.z);
+        this._world.solver.iterations = iterations;
 
         this._registeredMeshes = [];
         this._physicsMaterials = [];
+
+        this._setGravity(gravity);
     };
 
     BABYLON.PhysicsEngine.prototype._runOneStep = function (delta) {
-        if (delta > 1.0) {
-            delta = 1.0;
+        if (delta > 0.1) {
+            delta = 0.1;
         }
-            
+
         this._world.step(delta);
-        
+
         for (var index = 0; index < this._registeredMeshes.length; index++) {
             var registeredMesh = this._registeredMeshes[index];
 
+            if (registeredMesh.isChild) {
+                continue;
+            }
+
             registeredMesh.mesh.position.x = registeredMesh.body.position.x;
             registeredMesh.mesh.position.y = registeredMesh.body.position.z;
             registeredMesh.mesh.position.z = registeredMesh.body.position.y;
-            
+
             if (!registeredMesh.mesh.rotationQuaternion) {
                 registeredMesh.mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
             }
@@ -45,7 +49,7 @@ var BABYLON = BABYLON || {};
 
         for (index = 0; index < this._physicsMaterials.length; index++) {
             mat = this._physicsMaterials[index];
-            
+
             if (mat.friction === friction && mat.restitution === restitution) {
                 return mat;
             }
@@ -58,8 +62,11 @@ var BABYLON = BABYLON || {};
 
         for (index = 0; index < this._physicsMaterials.length; index++) {
             mat = this._physicsMaterials[index];
-            
-            var contactMaterial = new CANNON.ContactMaterial(mat, currentMat, Math.max(mat.friction, currentMat.friction), mat.restitution * currentMat.restitution);
+
+            var contactMaterial = new CANNON.ContactMaterial(mat, currentMat, mat.friction * currentMat.friction, mat.restitution * currentMat.restitution);
+            contactMaterial.contactEquationStiffness = 1e10;
+            contactMaterial.contactEquationRegularizationTime = 10;
+
             this._world.addContactMaterial(contactMaterial);
         }
 
@@ -67,12 +74,23 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.PhysicsEngine.prototype._setGravity = function (gravity) {
-        this._world.gravity.set(this.gravity.x, this.gravity.y, this.gravity.z);
+        this.gravity = gravity || new BABYLON.Vector3(0, -9.82, 0);
+        this._world.gravity.set(this.gravity.x, this.gravity.z, this.gravity.y);
+    };
+
+    BABYLON.PhysicsEngine.prototype._checkWithEpsilon = function (value) {
+        return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
     };
 
-    BABYLON.PhysicsEngine.prototype._registerMesh = function (mesh, options) {
+    BABYLON.PhysicsEngine.prototype._registerMesh = function (mesh, options, onlyShape) {
         var shape = null;
-        
+        var initialRotation;
+
+        if (mesh.rotationQuaternion) {
+            initialRotation = mesh.rotationQuaternion.clone();
+            mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+        }
+
         this._unregisterMesh(mesh);
 
         mesh.computeWorldMatrix(true);
@@ -83,43 +101,128 @@ var BABYLON = BABYLON || {};
                 var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                 var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                 var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
-                
-                shape = new CANNON.Sphere(Math.max(radiusX, radiusY, radiusZ) / 2);
+
+                shape = new CANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
                 break;
             case BABYLON.PhysicsEngine.BoxImpostor:
                 var bbox = mesh.getBoundingInfo().boundingBox;
                 var min = bbox.minimumWorld;
                 var max = bbox.maximumWorld;
                 var box = max.subtract(min).scale(0.5);
-                shape = new CANNON.Box(new CANNON.Vec3(box.x, box.z, box.y));
+                shape = new CANNON.Box(new CANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.z), this._checkWithEpsilon(box.y)));
                 break;
             case BABYLON.PhysicsEngine.PlaneImpostor:
                 shape = new CANNON.Plane();
                 break;
+            case BABYLON.PhysicsEngine.MeshImpostor:
+                var rawVerts = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+                var rawFaces = mesh.getIndices();
+
+                var verts = [], faces = [];
+
+                mesh.computeWorldMatrix(true);
+
+                // Get vertices
+                for (var i = 0; i < rawVerts.length; i += 3) {
+                    var transformed = BABYLON.Vector3.Zero();
+
+                    BABYLON.Vector3.TransformNormalFromFloatsToRef(rawVerts[i], rawVerts[i + 1], rawVerts[i + 2], mesh.getWorldMatrix(), transformed);
+                    verts.push(new CANNON.Vec3(transformed.x, transformed.z, transformed.y));
+                }
+
+                // Get faces
+                for (var j = 0; j < rawFaces.length; j += 3) {
+                    faces.push([rawFaces[j], rawFaces[j + 2], rawFaces[j + 1]]);
+                }
+
+                // Construct polyhedron
+                shape = new CANNON.ConvexPolyhedron(verts, faces);
+                break;
         }
-        
+
+        if (onlyShape) {
+            return shape;
+        }
+
         var material = this._addMaterial(options.friction, options.restitution);
         var body = new CANNON.RigidBody(options.mass, shape, material);
-        
+
+        if (initialRotation) {
+            body.quaternion.x = initialRotation.x;
+            body.quaternion.z = initialRotation.y;
+            body.quaternion.y = initialRotation.z;
+            body.quaternion.w = -initialRotation.w;
+        }
+
         body.position.set(mesh.position.x, mesh.position.z, mesh.position.y);
         this._world.add(body);
 
-        this._registeredMeshes.push({ mesh: mesh, body: body, material:material});
+        this._registeredMeshes.push({ mesh: mesh, body: body, material: material });
+
+        return body;
+    };
+
+    BABYLON.PhysicsEngine.prototype._registerCompound = function (options) {
+        var compoundShape = new CANNON.Compound();
+        var initialMesh = options.parts[0].mesh;
+        var initialPosition = initialMesh.position;
+
+        for (var index = 0; index < options.parts.length; index++) {
+            var mesh = options.parts[index].mesh;
+
+            var shape = this._registerMesh(mesh, options.parts[index], true);
+
+            if (index == 0) { // Parent
+                compoundShape.addChild(shape, new CANNON.Vec3(0, 0, 0));
+            } else {
+                compoundShape.addChild(shape, new CANNON.Vec3(mesh.position.x, mesh.position.z, mesh.position.y));
+            }
+        }
+
+        var material = this._addMaterial(options.friction, options.restitution);
+        var body = new CANNON.RigidBody(options.mass, compoundShape, material);
+
+        body.position.set(initialPosition.x, initialPosition.z, initialPosition.y);
+        this._world.add(body);
+
+        for (var index = 0; index < options.parts.length; index++) {
+            var mesh = options.parts[index].mesh;
+            this._registeredMeshes.push({ mesh: mesh, body: body, material: material, isChild: index != 0 });
+        }
+
+        body.parts = options.parts;
+
+        return body;
     };
-    
+
+    BABYLON.PhysicsEngine.prototype._unbindBody = function (body) {
+        for (var index = 0; index < this._registeredMeshes.length; index++) {
+            var registeredMesh = this._registeredMeshes[index];
+
+            if (registeredMesh.body === body) {
+                registeredMesh.body = null;
+            }
+        }
+    };
+
     BABYLON.PhysicsEngine.prototype._unregisterMesh = function (mesh) {
         for (var index = 0; index < this._registeredMeshes.length; index++) {
             var registeredMesh = this._registeredMeshes[index];
 
             if (registeredMesh.mesh === mesh) {
-                // Remove
-                this._world.remove(registeredMesh.body);
+                // Remove body
+                if (registeredMesh.body) {
+                    this._world.remove(registeredMesh.body);
+
+                    this._unbindBody(registeredMesh.body);
+                }
+
                 this._registeredMeshes.splice(index, 1);
                 return;
             }
         }
     };
-    
+
     BABYLON.PhysicsEngine.prototype._applyImpulse = function (mesh, force, contactPoint) {
         var worldPoint = new CANNON.Vec3(contactPoint.x, contactPoint.z, contactPoint.y);
         var impulse = new CANNON.Vec3(force.x, force.z, force.y);
@@ -143,13 +246,13 @@ var BABYLON = BABYLON || {};
                 body1 = registeredMesh.body;
             } else if (registeredMesh.mesh === mesh2) {
                 body2 = registeredMesh.body;
-            } 
+            }
         }
-        
+
         if (!body1 || !body2) {
             return;
         }
-        
+
         var constraint = new CANNON.PointToPointConstraint(body1, new CANNON.Vec3(pivot1.x, pivot1.z, pivot1.y), body2, new CANNON.Vec3(pivot2.x, pivot2.z, pivot2.y));
         this._world.addConstraint(constraint);
     };
@@ -161,7 +264,7 @@ var BABYLON = BABYLON || {};
     };
 
     // Statics
-    BABYLON.PhysicsEngine.IsSupported = function() {
+    BABYLON.PhysicsEngine.IsSupported = function () {
         return CANNON !== undefined;
     };
 
@@ -169,4 +272,8 @@ var BABYLON = BABYLON || {};
     BABYLON.PhysicsEngine.SphereImpostor = 1;
     BABYLON.PhysicsEngine.BoxImpostor = 2;
     BABYLON.PhysicsEngine.PlaneImpostor = 3;
+    BABYLON.PhysicsEngine.CompoundImpostor = 4;
+    BABYLON.PhysicsEngine.MeshImpostor = 4;
+
+    BABYLON.PhysicsEngine.Epsilon = 0.001;
 })();

+ 1 - 1
Babylon/Tools/babylon.filesInput.js

@@ -12,7 +12,7 @@ var BABYLON = BABYLON || {};
         that = this;
         this.engine = p_engine;
         this.canvas = p_canvas;
-        this.originalScene = p_scene;
+        this.currentScene = p_scene;
         this.sceneLoadedCallback = p_sceneLoadedCallback;
         this.progressCallback = p_progressCallback;
         this.additionnalRenderLoopLogicCallback = p_additionnalRenderLoopLogicCallback;

+ 55 - 19
Babylon/Tools/babylon.math.js

@@ -1154,29 +1154,65 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Matrix.prototype.multiplyToArray = function (other, result, offset) {
-        result[offset] = this.m[0] * other.m[0] + this.m[1] * other.m[4] + this.m[2] * other.m[8] + this.m[3] * other.m[12];
-        result[offset + 1] = this.m[0] * other.m[1] + this.m[1] * other.m[5] + this.m[2] * other.m[9] + this.m[3] * other.m[13];
-        result[offset + 2] = this.m[0] * other.m[2] + this.m[1] * other.m[6] + this.m[2] * other.m[10] + this.m[3] * other.m[14];
-        result[offset + 3] = this.m[0] * other.m[3] + this.m[1] * other.m[7] + this.m[2] * other.m[11] + this.m[3] * other.m[15];
 
-        result[offset + 4] = this.m[4] * other.m[0] + this.m[5] * other.m[4] + this.m[6] * other.m[8] + this.m[7] * other.m[12];
-        result[offset + 5] = this.m[4] * other.m[1] + this.m[5] * other.m[5] + this.m[6] * other.m[9] + this.m[7] * other.m[13];
-        result[offset + 6] = this.m[4] * other.m[2] + this.m[5] * other.m[6] + this.m[6] * other.m[10] + this.m[7] * other.m[14];
-        result[offset + 7] = this.m[4] * other.m[3] + this.m[5] * other.m[7] + this.m[6] * other.m[11] + this.m[7] * other.m[15];
-
-        result[offset + 8] = this.m[8] * other.m[0] + this.m[9] * other.m[4] + this.m[10] * other.m[8] + this.m[11] * other.m[12];
-        result[offset + 9] = this.m[8] * other.m[1] + this.m[9] * other.m[5] + this.m[10] * other.m[9] + this.m[11] * other.m[13];
-        result[offset + 10] = this.m[8] * other.m[2] + this.m[9] * other.m[6] + this.m[10] * other.m[10] + this.m[11] * other.m[14];
-        result[offset + 11] = this.m[8] * other.m[3] + this.m[9] * other.m[7] + this.m[10] * other.m[11] + this.m[11] * other.m[15];
-
-        result[offset + 12] = this.m[12] * other.m[0] + this.m[13] * other.m[4] + this.m[14] * other.m[8] + this.m[15] * other.m[12];
-        result[offset + 13] = this.m[12] * other.m[1] + this.m[13] * other.m[5] + this.m[14] * other.m[9] + this.m[15] * other.m[13];
-        result[offset + 14] = this.m[12] * other.m[2] + this.m[13] * other.m[6] + this.m[14] * other.m[10] + this.m[15] * other.m[14];
-        result[offset + 15] = this.m[12] * other.m[3] + this.m[13] * other.m[7] + this.m[14] * other.m[11] + this.m[15] * other.m[15];
+        var tm0 = this.m[0];
+        var tm1 = this.m[1];
+        var tm2 = this.m[2];
+        var tm3 = this.m[3];
+        var tm4 = this.m[4];
+        var tm5 = this.m[5];
+        var tm6 = this.m[6];
+        var tm7 = this.m[7];
+        var tm8 = this.m[8];
+        var tm9 = this.m[9];
+        var tm10 = this.m[10];
+        var tm11 = this.m[11];
+        var tm12 = this.m[12];
+        var tm13 = this.m[13];
+        var tm14 = this.m[14];
+        var tm15 = this.m[15];
+
+        var om0 = other.m[0];
+        var om1 = other.m[1];
+        var om2 = other.m[2];
+        var om3 = other.m[3];
+        var om4 = other.m[4];
+        var om5 = other.m[5];
+        var om6 = other.m[6];
+        var om7 = other.m[7];
+        var om8 = other.m[8];
+        var om9 = other.m[9];
+        var om10 = other.m[10];
+        var om11 = other.m[11];
+        var om12 = other.m[12];
+        var om13 = other.m[13];
+        var om14 = other.m[14];
+        var om15 = other.m[15];
+
+        result[offset] = tm0 * om0 + tm1 * om4 + tm2 * om8 + tm3 * om12;
+        result[offset + 1] = tm0 * om1 + tm1 * om5 + tm2 * om9 + tm3 * om13;
+        result[offset + 2] = tm0 * om2 + tm1 * om6 + tm2 * om10 + tm3 * om14;
+        result[offset + 3] = tm0 * om3 + tm1 * om7 + tm2 * om11 + tm3 * om15;
+
+        result[offset + 4] = tm4 * om0 + tm5 * om4 + tm6 * om8 + tm7 * om12;
+        result[offset + 5] = tm4 * om1 + tm5 * om5 + tm6 * om9 + tm7 * om13;
+        result[offset + 6] = tm4 * om2 + tm5 * om6 + tm6 * om10 + tm7 * om14;
+        result[offset + 7] = tm4 * om3 + tm5 * om7 + tm6 * om11 + tm7 * om15;
+
+        result[offset + 8] = tm8 * om0 + tm9 * om4 + tm10 * om8 + tm11 * om12;
+        result[offset + 9] = tm8 * om1 + tm9 * om5 + tm10 * om9 + tm11 * om13;
+        result[offset + 10] = tm8 * om2 + tm9 * om6 + tm10 * om10 + tm11 * om14;
+        result[offset + 11] = tm8 * om3 + tm9 * om7 + tm10 * om11 + tm11 * om15;
+
+        result[offset + 12] = tm12 * om0 + tm13 * om4 + tm14 * om8 + tm15 * om12;
+        result[offset + 13] = tm12 * om1 + tm13 * om5 + tm14 * om9 + tm15 * om13;
+        result[offset + 14] = tm12 * om2 + tm13 * om6 + tm14 * om10 + tm15 * om14;
+        result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;
     };
 
     BABYLON.Matrix.prototype.equals = function (value) {
-        return value && (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] &&
+        return value &&
+               (this.m[0] === value.m[0] && this.m[1] === value.m[1] && this.m[2] === value.m[2] && this.m[3] === value.m[3] &&
                 this.m[4] === value.m[4] && this.m[5] === value.m[5] && this.m[6] === value.m[6] && this.m[7] === value.m[7] &&
                 this.m[8] === value.m[8] && this.m[9] === value.m[9] && this.m[10] === value.m[10] && this.m[11] === value.m[11] &&
                 this.m[12] === value.m[12] && this.m[13] === value.m[13] && this.m[14] === value.m[14] && this.m[15] === value.m[15]);

+ 22 - 19
Babylon/Tools/babylon.sceneLoader.js

@@ -1,6 +1,6 @@
-"use strict";
+"use strict";
 
-var BABYLON = BABYLON || {}; 
+var BABYLON = BABYLON || {};
 
 (function () {
     var loadCubeTexture = function (rootUrl, parsedTexture, scene) {
@@ -160,13 +160,13 @@ var BABYLON = BABYLON || {};
 
         return multiMaterial;
     };
-    
+
     var parseLensFlareSystem = function (parsedLensFlareSystem, scene, rootUrl) {
         var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
 
         var lensFlareSystem = new BABYLON.LensFlareSystem("lensFlareSystem#" + parsedLensFlareSystem.emitterId, emitter, scene);
         lensFlareSystem.borderLimit = parsedLensFlareSystem.borderLimit;
-        
+
         for (var index = 0; index < parsedLensFlareSystem.flares.length; index++) {
             var parsedFlare = parsedLensFlareSystem.flares[index];
             var flare = new BABYLON.LensFlare(parsedFlare.size, parsedFlare.position, BABYLON.Color3.FromArray(parsedFlare.color), rootUrl + parsedFlare.textureName, lensFlareSystem);
@@ -303,7 +303,7 @@ var BABYLON = BABYLON || {};
         } else {
             camera.rotation = BABYLON.Vector3.FromArray(parsedCamera.rotation);
         }
-        
+
         // Locked target
         if (parsedCamera.lockedTargetId) {
             camera._waitingLockedTargetId = parsedCamera.lockedTargetId;
@@ -357,7 +357,7 @@ var BABYLON = BABYLON || {};
         mesh.setEnabled(parsedMesh.isEnabled);
         mesh.isVisible = parsedMesh.isVisible;
         mesh.infiniteDistance = parsedMesh.infiniteDistance;
-        
+
         mesh.receiveShadows = parsedMesh.receiveShadows;
 
         mesh.billboardMode = parsedMesh.billboardMode;
@@ -415,7 +415,7 @@ var BABYLON = BABYLON || {};
         if (parsedMesh.skeletonId > -1) {
             mesh.skeleton = scene.getLastSkeletonByID(parsedMesh.skeletonId);
         }
-        
+
         // Physics
         if (parsedMesh.physicsImpostor) {
             if (!scene.isPhysicsEnabled()) {
@@ -448,14 +448,15 @@ var BABYLON = BABYLON || {};
         return mesh;
     };
 
+
     var isDescendantOf = function (mesh, names, hierarchyIds) {
-		names = (names instanceof Array) ? names : [names];
-		for(var i in names){
-			if (mesh.name === names[i]) {
-				hierarchyIds.push(mesh.id);
-				return true;
-			}
-		}
+        names = (names instanceof Array) ? names : [names];
+        for (var i in names) {
+            if (mesh.name === names[i]) {
+                hierarchyIds.push(mesh.id);
+                return true;
+            }
+        }
 
         if (mesh.parentId && hierarchyIds.indexOf(mesh.parentId) !== -1) {
             hierarchyIds.push(mesh.id);
@@ -543,9 +544,11 @@ var BABYLON = BABYLON || {};
                     var parsedMesh = parsedData.meshes[index];
 
                     if (!meshesNames || isDescendantOf(parsedMesh, meshesNames, hierarchyIds)) {
-						// Remove found mesh name from list.
-						delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
-						
+                        if (meshesNames instanceof Array) {
+                            // Remove found mesh name from list.
+                            delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
+                        }
+
                         // Material ?
                         if (parsedMesh.materialId) {
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
@@ -729,10 +732,10 @@ var BABYLON = BABYLON || {};
 
                 BABYLON.Tools.LoadFile(rootUrl + sceneFilename, loadSceneFromData, progressCallBack, database);
             }
-            // Loading file from disk via input file or drag'n'drop
+                // Loading file from disk via input file or drag'n'drop
             else {
                 BABYLON.Tools.ReadFile(sceneFilename, loadSceneFromData, progressCallBack);
             }
         }
     };
-})();
+})();

+ 1 - 1
Babylon/Tools/babylon.tools.js

@@ -151,6 +151,7 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Tools.LoadImage = function (url, onload, onerror, database) {  
         var img = new Image();
+        img.crossOrigin = 'anonymous';
 
         img.onload = function () {
             onload(img);
@@ -161,7 +162,6 @@ var BABYLON = BABYLON || {};
         };
 
         var noIndexedDB = function () {
-            img.crossOrigin = 'anonymous';
             img.src = url;
         };
 

+ 40 - 25
Babylon/babylon.node.js

@@ -1,21 +1,24 @@
 "use strict";
 
+
 var BABYLON = BABYLON || {};
 
+
 (function () {
-    BABYLON.Node = function () {
+    BABYLON.Node = function (scene) {
+        this._scene = scene;
         BABYLON.Node.prototype._initCache.call(this);
     };
-    
+
     // Properties
     BABYLON.Node.prototype.parent = null;
-    BABYLON.Node.prototype._childrenFlag = false;
+    BABYLON.Node.prototype._childrenFlag = -1;
     BABYLON.Node.prototype._isReady = true;
     BABYLON.Node.prototype._isEnabled = true;
 
     // Cache
     BABYLON.Node.prototype._cache = null;
-    
+
     // override it in derived class if you add new variables to the cache
     // and call it in the constructor of your class like this
     // BABYLON.YourClass.prototype._initCache.call(this)
@@ -28,9 +31,9 @@ var BABYLON = BABYLON || {};
     BABYLON.Node.prototype.updateCache = function (force) {
         if (!force && this.isSynchronized())
             return;
-        
+
         this._cache.parent = this.parent;
-        
+
         this._updateCache();
     };
 
@@ -47,65 +50,76 @@ var BABYLON = BABYLON || {};
         return true;
     };
 
+    BABYLON.Node.prototype._syncChildFlag = function() {
+        this._childrenFlag = this.parent ? this.parent._childrenFlag : this._scene.getRenderId();
+    };
+
+    BABYLON.Node.prototype.isSynchronizedWithParent = function() {
+        return this.parent ? !this.parent._needToSynchonizeChildren(this._childrenFlag) : true;
+    };
+
     BABYLON.Node.prototype.isSynchronized = function (updateCache) {
-        var r = this.hasNewParent();
+        var check = this.hasNewParent();
+
+        check = check || !this.isSynchronizedWithParent();
+
+        check = check || !this._isSynchronized();
 
-        r = r || (this.parent && this.parent._needToSynchonizeChildren());
-        
-        r = r || !this._isSynchronized();
-        
-        if(updateCache)
+        if (updateCache)
             this.updateCache(true);
-        
-        return !r;
+
+        return !check;
     };
 
     BABYLON.Node.prototype.hasNewParent = function (update) {
         if (this._cache.parent === this.parent)
             return false;
-        
-        if(update)
+
+        if (update)
             this._cache.parent = this.parent;
-        
+
         return true;
     };
-    
-    BABYLON.Node.prototype._needToSynchonizeChildren = function () {
-        return this._childrenFlag;
+
+    BABYLON.Node.prototype._needToSynchonizeChildren = function (childFlag) {
+        return this._childrenFlag != childFlag;
     };
-    
+
     BABYLON.Node.prototype.isReady = function () {
         return this._isReady;
     };
-    
+
     BABYLON.Node.prototype.isEnabled = function () {
         if (!this.isReady() || !this._isEnabled) {
             return false;
         }
 
+
         if (this.parent) {
             return this.parent.isEnabled();
         }
 
+
         return true;
     };
 
     BABYLON.Node.prototype.setEnabled = function (value) {
         this._isEnabled = value;
     };
-    
+
     BABYLON.Node.prototype.isDescendantOf = function (ancestor) {
         if (this.parent) {
             if (this.parent === ancestor) {
                 return true;
             }
 
+
             return this.parent.isDescendantOf(ancestor);
         }
         return false;
     };
 
-    BABYLON.Node.prototype._getDescendants = function(list, results) {
+    BABYLON.Node.prototype._getDescendants = function (list, results) {
         for (var index = 0; index < list.length; index++) {
             var item = list[index];
             if (item.isDescendantOf(this)) {
@@ -123,4 +137,5 @@ var BABYLON = BABYLON || {};
         return results;
     };
 
-})();
+})();
+

+ 35 - 6
Babylon/babylon.scene.js

@@ -134,6 +134,10 @@ var BABYLON = BABYLON || {};
         return this._evaluateActiveMeshesDuration;
     };
 
+    BABYLON.Scene.prototype.geActiveMeshes = function () {
+        return this._activeMeshes;
+    };
+
     BABYLON.Scene.prototype.getRenderTargetsDuration = function () {
         return this._renderTargetsDuration;
     };
@@ -446,7 +450,7 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
-        if (mesh.subMeshes.length == 1 || subMesh.isInFrustrum(this._frustumPlanes)) {
+        if (mesh.subMeshes.length == 1 || subMesh.isInFrustum(this._frustumPlanes)) {
             var material = subMesh.getMaterial();
 
             if (material) {
@@ -500,7 +504,7 @@ var BABYLON = BABYLON || {};
                         mesh._renderId = 0;
                     }
 
-                    if (mesh._renderId === this._renderId || (mesh._renderId === 0 && mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && mesh.isInFrustrum(this._frustumPlanes))) {
+                    if (mesh._renderId === this._renderId || (mesh._renderId === 0 && mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && mesh.isInFrustum(this._frustumPlanes))) {
                         if (mesh._renderId === 0) {
                             this._activeMeshes.push(mesh);
                         }
@@ -538,7 +542,7 @@ var BABYLON = BABYLON || {};
 
                 mesh.computeWorldMatrix();
 
-                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && mesh.isInFrustrum(this._frustumPlanes)) {
+                if (mesh.isEnabled() && mesh.isVisible && mesh.visibility > 0 && mesh.isInFrustum(this._frustumPlanes)) {
                     this._activeMeshes.push(mesh);
 
                     if (mesh.skeleton) {
@@ -880,7 +884,7 @@ var BABYLON = BABYLON || {};
         for (var index = 0; index < this.meshes.length; index++) {
             var mesh = this.meshes[index];
 
-            mesh.computeWorldMatrix();
+            mesh.computeWorldMatrix(true);
             var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
             var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
 
@@ -960,7 +964,7 @@ var BABYLON = BABYLON || {};
     };
     
     // Physics
-    BABYLON.Scene.prototype.enablePhysics = function(gravity) {
+    BABYLON.Scene.prototype.enablePhysics = function(gravity, iterations) {
         if (this._physicsEngine) {
             return true;
         }
@@ -969,7 +973,7 @@ var BABYLON = BABYLON || {};
             return false;
         }
 
-        this._physicsEngine = new BABYLON.PhysicsEngine(gravity);
+        this._physicsEngine = new BABYLON.PhysicsEngine(gravity, iterations || 10);
 
         return true;
     };
@@ -995,6 +999,31 @@ var BABYLON = BABYLON || {};
         this._physicsEngine._setGravity(gravity);
     };
 
+    BABYLON.Scene.prototype.createCompoundImpostor = function (options) {
+        if (!this._physicsEngine) {
+            return null;
+        }
+
+        for (var index = 0; index < options.parts.length; index++) {
+            var mesh = options.parts[index].mesh;
+
+            mesh._physicImpostor = options.parts[index].impostor;
+            mesh._physicsMass = options.mass / options.parts.length;
+            mesh._physicsFriction = options.friction;
+            mesh._physicRestitution = options.restitution;
+        }
+
+        return this._physicsEngine._registerCompound(options);
+    };
+
+    BABYLON.Scene.prototype.deleteCompoundImpostor = function (compound) {
+        for (var index = 0; index < compound.parts.length; index++) {
+            var mesh = compound.parts[index].mesh;
+            mesh._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
+            this._scene._physicsEngine._unregisterMesh(mesh);
+        }
+    };
+
     // Statics
     BABYLON.Scene.FOGMODE_NONE = 0;
     BABYLON.Scene.FOGMODE_EXP = 1;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 0
Babylon/jscompaktor.bat


+ 1 - 1
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/OBJ/ObjExporter.cs

@@ -80,7 +80,7 @@ namespace BabylonExport.Core.Exporters
                             normals.Add(line.ToVector3());
                             break;
                         case ObjHeader.Group:
-                            currentName = line.Tokens[1];
+                            currentName = line.Tokens.Length > 1 ? line.Tokens[1] : "noname";
                             break;
                         case ObjHeader.Faces:
                             AppendFace(line);

+ 1 - 2
Exporters/XNA - OBJ/BabylonExport.Core/Exporters/ThroughXNA/XNAExporter.cs

@@ -215,12 +215,11 @@ namespace BabylonExport.Core.Exporters.XNA
                         }
                     }
 
-                    mesh.AddPart(modelMesh.Name+"#"+indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
+                    mesh.AddPart(modelMesh.Name + "#" + indexName.ToString(), vertices.ToList(), indices.Select(i => (int)i).ToList());
                     mesh.CreateBabylonMesh(scene, proxyID, skeleton);
                 }
                 else
                 {
-                    if (part.VertexBuffer.VertexDeclaration.VertexStride < PositionNormalTextured.Stride) return; // Error: Not a PositionNormalTextured mesh!
                     var mesh = new Mesh<PositionNormalTextured>(material);
                     var vertices = new PositionNormalTextured[part.NumVertices];
                     part.VertexBuffer.GetData(part.VertexOffset * part.VertexBuffer.VertexDeclaration.VertexStride, vertices, 0, vertices.Length, part.VertexBuffer.VertexDeclaration.VertexStride);

BIN
Samples/Assets/logo50.png


+ 33 - 14
Samples/Scenes/Customs/physics.js

@@ -1,9 +1,9 @@
-var CreatePhysicsScene = function(engine) {
+var CreatePhysicsScene = function (engine) {
     var scene = new BABYLON.Scene(engine);
     var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene);
     camera.checkCollisions = true;
     camera.applyGravity = true;
-    
+
     var light = new BABYLON.DirectionalLight("dir02", new BABYLON.Vector3(0.2, -1, 0), scene);
     light.position = new BABYLON.Vector3(0, 80, 0);
 
@@ -13,18 +13,18 @@
     materialAmiga.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5);
     materialAmiga.diffuseTexture.uScale = 5;
     materialAmiga.diffuseTexture.vScale = 5;
-    
+
     var materialAmiga2 = new BABYLON.StandardMaterial("amiga", scene);
     materialAmiga2.diffuseTexture = new BABYLON.Texture("assets/mosaic.jpg", scene);
     materialAmiga2.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5);
-    
+
     // Shadows
     var shadowGenerator = new BABYLON.ShadowGenerator(2048, light);
     shadowGenerator.getShadowMap().renderList.push(box0);
 
     // Physics
     scene.enablePhysics();
-    
+
     // Spheres
     var y = 0;
     for (var index = 0; index < 32; index++) {
@@ -34,12 +34,12 @@
         sphere.position = new BABYLON.Vector3(Math.random() * 20 - 10, y, Math.random() * 10 - 5);
 
         shadowGenerator.getShadowMap().renderList.push(sphere);
-        
+
         sphere.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 });
 
-        y += 2;        
+        y += 2;
     }
-    
+
     // Link
     var spheres = [];
     for (var index = 0; index < 10; index++) {
@@ -67,6 +67,19 @@
 
     shadowGenerator.getShadowMap().renderList.push(box0);
 
+    // Compound
+    var part0 = BABYLON.Mesh.CreateBox("part0", 3, scene);
+    part0.position = new BABYLON.Vector3(3, 30, 0);
+    part0.material = materialWood;
+
+    var part1 = BABYLON.Mesh.CreateBox("part1", 3, scene);
+    part1.parent = part0; // We need a hierarchy for compound objects
+    part1.position = new BABYLON.Vector3(0, 3, 0);
+    part1.material = materialWood;
+
+    shadowGenerator.getShadowMap().renderList.push(part0);
+    shadowGenerator.getShadowMap().renderList.push(part1);
+
     // Playground
     var ground = BABYLON.Mesh.CreateBox("Ground", 1, scene);
     ground.scaling = new BABYLON.Vector3(100, 1, 100);
@@ -78,25 +91,25 @@
     border0.position.y = -5.0;
     border0.position.x = -50.0;
     border0.checkCollisions = true;
-    
+
     var border1 = BABYLON.Mesh.CreateBox("border1", 1, scene);
     border1.scaling = new BABYLON.Vector3(1, 100, 100);
     border1.position.y = -5.0;
     border1.position.x = 50.0;
     border1.checkCollisions = true;
-    
+
     var border2 = BABYLON.Mesh.CreateBox("border2", 1, scene);
     border2.scaling = new BABYLON.Vector3(100, 100, 1);
     border2.position.y = -5.0;
     border2.position.z = 50.0;
     border2.checkCollisions = true;
-    
+
     var border3 = BABYLON.Mesh.CreateBox("border3", 1, scene);
     border3.scaling = new BABYLON.Vector3(100, 100, 1);
     border3.position.y = -5.0;
     border3.position.z = -50.0;
     border3.checkCollisions = true;
-    
+
     camera.setTarget(new BABYLON.Vector3(0, 0, 0));
 
     var groundMat = new BABYLON.StandardMaterial("groundMat", scene);
@@ -108,7 +121,7 @@
     border2.material = groundMat;
     border3.material = groundMat;
     ground.receiveShadows = true;
-        
+
     // Physics
     box0.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 2, friction: 0.4, restitution: 0.3 });
     ground.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 0.7 });
@@ -116,6 +129,12 @@
     border1.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0 });
     border2.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0 });
     border3.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0 });
-    
+
+    scene.createCompoundImpostor({
+        mass: 2, friction: 0.4, restitution: 0.3, parts: [
+        { mesh: part0, impostor: BABYLON.PhysicsEngine.BoxImpostor },
+        { mesh: part1, impostor: BABYLON.PhysicsEngine.BoxImpostor }]
+    });
+
     return scene;
 };

BIN
Samples/Screenshots/tour.jpg


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2 - 2
Samples/babylon.js


+ 2 - 1
Samples/index.js

@@ -104,7 +104,8 @@ var onload = function () {
     { title: "GALLERY", url: "http://guillaume.carlander.fr/Babylon/Gallery/", screenshot: "gallery.png", size: "by G. Carlander" },
     { title: "Catalog3D", url: "http://apps.microsoft.com/windows/en-gb/app/catalog-3d-by-sokrate/43771ce3-02f0-4365-98c3-557cd8acdad2", screenshot: "sokrate3D.jpg", size: "by SOKRATE" },
     { title: "PSN TELECENTRES", url: "http://psntelecentres.com/visite_virtuelle.html", screenshot: "psn.jpg", size: "by SOKRATE" },
-    { title: "VIRTUAL EXPO", url: "http://www.sokrate.fr/expovirtuelle/index.htm", screenshot: "expo.jpg", size: "by SOKRATE" }
+    { title: "VIRTUAL EXPO", url: "http://www.sokrate.fr/expovirtuelle/index.htm", screenshot: "expo.jpg", size: "by SOKRATE" },
+    { title: "3delyvisions SKYBOX TOUR", url: "http://urbanproductions.com/wingy/babylon/skyboxes/skybox_tour.htm", screenshot: "tour.jpg", size: "by Wingnut" }
     ];
 
     // UI

BIN
Tools/Visual Studio Extensions/Babylon.VSIX.vsix


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 22
babylon.1.8.0.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 22 - 0
babylon.1.8.5.js


+ 17 - 1
what's new.md

@@ -1,5 +1,21 @@
-Changes list
+Changes list
 ============
+- 1.8.5:
+ - **Major updates**
+ - Visual Studio 2013 templates for Windows 8.1 and nuget packages ([pierlag](http://www.github.com/pierlag))
+ - **Updates**
+ - New ```matrix.multiply``` function (up to 50% faster) ([deltakosh](http://www.github.com/deltakosh))
+ - New matrices cache system for camera (view and projection matrices) ([juliengobin](http://www.github.com/juliengobin))
+ - New physics impostor: compound and mesh (still really slow) ([deltakosh](http://www.github.com/deltakosh))
+ - Set crossOrigin flag for support CORS ([vbouzon](http://www.github.com/vbouzon))
+ - XNA importer: Changes for Right-Left Coordinate Systems & Prefixed Mesh Parts with Mesh Name ([professorF](http://www.github.com/professorF))
+ - Fixing getPivotMatrix ([gwenael-hagenmuller](http://www.github.com/gwenael-hagenmuller))
+ - New geometry functions: getLocalTranslation, setPositionWithLocalVector, getPositionExpressedInLocalSpace,locallyTranslate ([gwenael-hagenmuller](http://www.github.com/gwenael-hagenmuller))
+ - Adding multi mesh import from same file([nicolas-obre](http://www.github.com/nicolas-obre)) 
+ - **Bugfixes**
+ - Fixing issue when disposing a parent and not its children ([deltakosh](http://www.github.com/deltakosh))
+ - Fixing .obj importer ([deltakosh](http://www.github.com/deltakosh))
+ - Added guardband checks for impostors' size ([deltakosh](http://www.github.com/deltakosh))
 - 1.8.0:
  - **Major updates**
  - Support for [physics engine](http://www.babylonjs.com/index.html?PHYSICS) thanks to cannon.js ([deltakosh](http://www.github.com/deltakosh))