Kaynağa Gözat

Merge remote-tracking branch 'upstream/master' into feature.createRibbon

Conflicts:
	Babylon/Debug/babylon.debugLayer.js.map
	Babylon/Mesh/babylon.mesh.js
	Babylon/Mesh/babylon.mesh.vertexData.js
jbousquie 10 yıl önce
ebeveyn
işleme
fc6d8e9fa1

+ 28 - 18
Babylon/Debug/babylon.debugLayer.js

@@ -3,6 +3,7 @@ var BABYLON;
     var DebugLayer = (function () {
         function DebugLayer(scene) {
             var _this = this;
+            this._transformationMatrix = BABYLON.Matrix.Identity();
             this._enabled = false;
             this._labelsEnabled = false;
             this._displayStatistics = true;
@@ -82,16 +83,17 @@ var BABYLON;
                     }
                 }
                 if (_this._labelsEnabled || !_this._showUI) {
+                    _this._camera.getViewMatrix().multiplyToRef(_this._camera.getProjectionMatrix(), _this._transformationMatrix);
                     _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
                     var engine = _this._scene.getEngine();
-                    var viewport = _this._scene.activeCamera.viewport;
+                    var viewport = _this._camera.viewport;
                     var globalViewport = viewport.toGlobal(engine);
                     // Meshes
                     var meshes = _this._scene.getActiveMeshes();
                     for (var index = 0; index < meshes.length; index++) {
                         var mesh = meshes.data[index];
                         var position = mesh.getBoundingInfo().boundingSphere.center;
-                        var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
+                        var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._transformationMatrix, globalViewport);
                         if (mesh.renderOverlay || _this.shouldDisplayAxis && _this.shouldDisplayAxis(mesh)) {
                             _this._renderAxis(projectedPosition, mesh, globalViewport);
                         }
@@ -107,15 +109,15 @@ var BABYLON;
                     var cameras = _this._scene.cameras;
                     for (index = 0; index < cameras.length; index++) {
                         var camera = cameras[index];
-                        if (camera === _this._scene.activeCamera) {
+                        if (camera === _this._camera) {
                             continue;
                         }
-                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._transformationMatrix, globalViewport);
                         if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(camera)) {
                             _this._renderLabel(camera.name, projectedPosition, 12, function () {
-                                _this._scene.activeCamera.detachControl(engine.getRenderingCanvas());
-                                _this._scene.activeCamera = camera;
-                                _this._scene.activeCamera.attachControl(engine.getRenderingCanvas());
+                                _this._camera.detachControl(engine.getRenderingCanvas());
+                                _this._camera = camera;
+                                _this._camera.attachControl(engine.getRenderingCanvas());
                             }, function () {
                                 return "purple";
                             });
@@ -126,7 +128,7 @@ var BABYLON;
                     for (index = 0; index < lights.length; index++) {
                         var light = lights[index];
                         if (light.position) {
-                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._transformationMatrix, globalViewport);
                             if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
                                 _this._renderLabel(light.name, projectedPosition, -20, function () {
                                     light.setEnabled(!light.isEnabled());
@@ -176,16 +178,16 @@ var BABYLON;
         DebugLayer.prototype._renderAxis = function (projectedPosition, mesh, globalViewport) {
             var position = mesh.getBoundingInfo().boundingSphere.center;
             var worldMatrix = mesh.getWorldMatrix();
-            var unprojectedVector = BABYLON.Vector3.UnprojectFromTransform(projectedPosition.add(new BABYLON.Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._scene.getTransformMatrix());
+            var unprojectedVector = BABYLON.Vector3.UnprojectFromTransform(projectedPosition.add(new BABYLON.Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._transformationMatrix);
             var unit = (unprojectedVector.subtract(position)).length();
-            var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, xAxis, xAxisText, "x", "#FF0000");
-            var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, yAxis, yAxisText, "y", "#00FF00");
-            var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._transformationMatrix, globalViewport);
+            var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, zAxis, zAxisText, "z", "#0000FF");
         };
         DebugLayer.prototype._renderLabel = function (text, projectedPosition, labelOffset, onClick, getFillStyle) {
@@ -194,7 +196,8 @@ var BABYLON;
                 var textMetrics = this._drawingContext.measureText(text);
                 var centerX = projectedPosition.x - textMetrics.width / 2;
                 var centerY = projectedPosition.y;
-                if (this._isClickInsideRect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
+                var clientRect = this._drawingCanvas.getBoundingClientRect();
+                if (this._isClickInsideRect(clientRect.left * this._ratio + centerX - 5, clientRect.top * this._ratio + centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
                     onClick();
                 }
                 this._drawingContext.beginPath();
@@ -257,11 +260,18 @@ var BABYLON;
             this._scene.renderTargetsEnabled = true;
             engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
         };
-        DebugLayer.prototype.show = function (showUI) {
+        DebugLayer.prototype.show = function (showUI, camera) {
             if (showUI === void 0) { showUI = true; }
+            if (camera === void 0) { camera = null; }
             if (this._enabled) {
                 return;
             }
+            if (camera) {
+                this._camera = camera;
+            }
+            else {
+                this._camera = this._scene.activeCamera;
+            }
             this._enabled = true;
             this._showUI = showUI;
             var engine = this._scene.getEngine();
@@ -568,4 +578,4 @@ var BABYLON;
     BABYLON.DebugLayer = DebugLayer;
 })(BABYLON || (BABYLON = {}));
 
-//# sourceMappingURL=../Debug/babylon.debugLayer.js.map
+//# sourceMappingURL=../Debug/babylon.debugLayer.js.map

Dosya farkı çok büyük olduğundan ihmal edildi
+ 5 - 1
Babylon/Debug/babylon.debugLayer.js.map


+ 29 - 17
Babylon/Debug/babylon.debugLayer.ts

@@ -1,6 +1,8 @@
 module BABYLON {
     export class DebugLayer {
         private _scene: Scene;
+        private _camera: Camera;
+        private _transformationMatrix = Matrix.Identity();
         private _enabled: boolean = false;
         private _labelsEnabled: boolean = false;
         private _displayStatistics = true;
@@ -130,10 +132,13 @@
                 }
 
                 if (this._labelsEnabled || !this._showUI) {
+
+                    this._camera.getViewMatrix().multiplyToRef(this._camera.getProjectionMatrix(), this._transformationMatrix);
+
                     this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
 
                     var engine = this._scene.getEngine();
-                    var viewport = this._scene.activeCamera.viewport;
+                    var viewport = this._camera.viewport;
                     var globalViewport = viewport.toGlobal(engine);
 
                     // Meshes
@@ -143,7 +148,7 @@
 
                         var position = mesh.getBoundingInfo().boundingSphere.center;
 
-                        var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), this._scene.getTransformMatrix(), globalViewport);
+                        var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), this._transformationMatrix, globalViewport);
 
                         if (mesh.renderOverlay || this.shouldDisplayAxis && this.shouldDisplayAxis(mesh)) {
                             this._renderAxis(projectedPosition, mesh, globalViewport);
@@ -161,18 +166,18 @@
                     for (index = 0; index < cameras.length; index++) {
                         var camera = cameras[index];
 
-                        if (camera === this._scene.activeCamera) {
+                        if (camera === this._camera) {
                             continue;
                         }
 
-                        projectedPosition = Vector3.Project(Vector3.Zero(), camera.getWorldMatrix(), this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = Vector3.Project(Vector3.Zero(), camera.getWorldMatrix(), this._transformationMatrix, globalViewport);
 
                         if (!this.shouldDisplayLabel || this.shouldDisplayLabel(camera)) {
                             this._renderLabel(camera.name, projectedPosition, 12,
                                 () => {
-                                    this._scene.activeCamera.detachControl(engine.getRenderingCanvas());
-                                    this._scene.activeCamera = camera;
-                                    this._scene.activeCamera.attachControl(engine.getRenderingCanvas());
+                                    this._camera.detachControl(engine.getRenderingCanvas());
+                                    this._camera = camera;
+                                    this._camera.attachControl(engine.getRenderingCanvas());
                                 },
                                 () => { return "purple"; });
                         }
@@ -185,7 +190,7 @@
 
                         if (light.position) {
 
-                            projectedPosition = Vector3.Project(light.getAbsolutePosition(), this._identityMatrix, this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = Vector3.Project(light.getAbsolutePosition(), this._identityMatrix, this._transformationMatrix, globalViewport);
 
                             if (!this.shouldDisplayLabel || this.shouldDisplayLabel(light)) {
                                 this._renderLabel(light.name, projectedPosition, -20,
@@ -250,21 +255,21 @@
             var position = mesh.getBoundingInfo().boundingSphere.center;
             var worldMatrix = mesh.getWorldMatrix();
 
-            var unprojectedVector = Vector3.UnprojectFromTransform(projectedPosition.add(new Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._scene.getTransformMatrix());
+            var unprojectedVector = Vector3.UnprojectFromTransform(projectedPosition.add(new Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._transformationMatrix);
             var unit = (unprojectedVector.subtract(position)).length();
 
-            var xAxis = Vector3.Project(position.add(new Vector3(unit, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var xAxisText = Vector3.Project(position.add(new Vector3(unit * 1.5, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var xAxis = Vector3.Project(position.add(new Vector3(unit, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var xAxisText = Vector3.Project(position.add(new Vector3(unit * 1.5, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
 
             this._renderSingleAxis(projectedPosition, xAxis, xAxisText, "x", "#FF0000");
 
-            var yAxis = Vector3.Project(position.add(new Vector3(0, unit, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var yAxisText = Vector3.Project(position.add(new Vector3(0, unit * 1.5, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var yAxis = Vector3.Project(position.add(new Vector3(0, unit, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var yAxisText = Vector3.Project(position.add(new Vector3(0, unit * 1.5, 0)), worldMatrix, this._transformationMatrix, globalViewport);
 
             this._renderSingleAxis(projectedPosition, yAxis, yAxisText, "y", "#00FF00");
 
-            var zAxis = Vector3.Project(position.add(new Vector3(0, 0, unit)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var zAxisText = Vector3.Project(position.add(new Vector3(0, 0, unit * 1.5)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var zAxis = Vector3.Project(position.add(new Vector3(0, 0, unit)), worldMatrix, this._transformationMatrix, globalViewport);
+            var zAxisText = Vector3.Project(position.add(new Vector3(0, 0, unit * 1.5)), worldMatrix, this._transformationMatrix, globalViewport);
 
             this._renderSingleAxis(projectedPosition, zAxis, zAxisText, "z", "#0000FF");
         }
@@ -275,8 +280,9 @@
                 var textMetrics = this._drawingContext.measureText(text);
                 var centerX = projectedPosition.x - textMetrics.width / 2;
                 var centerY = projectedPosition.y;
+                var clientRect = this._drawingCanvas.getBoundingClientRect();
 
-                if (this._isClickInsideRect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
+                if (this._isClickInsideRect(clientRect.left * this._ratio + centerX - 5, clientRect.top * this._ratio + centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
                     onClick();
                 }
 
@@ -358,11 +364,17 @@
             engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
         }
 
-        public show(showUI: boolean = true) {
+        public show(showUI: boolean = true, camera: Camera = null) {
             if (this._enabled) {
                 return;
             }
 
+            if (camera) {
+                this._camera = camera;
+            } else {
+                this._camera = this._scene.activeCamera;
+            }
+
             this._enabled = true;
             this._showUI = showUI;
 

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1065 - 1
Babylon/Mesh/babylon.mesh.js


+ 13 - 13
Babylon/Mesh/babylon.mesh.ts

@@ -1,4 +1,4 @@
-module BABYLON {
+module BABYLON {
     export class _InstancesBatch {
         public mustReturn = false;
         public visibleInstances = new Array<Array<InstancedMesh>>();
@@ -732,7 +732,7 @@ module BABYLON {
 
                     this.delayLoadState = Engine.DELAYLOADSTATE_LOADED;
                     scene._removePendingData(this);
-                },() => { }, scene.database, getBinaryData);
+                }, () => { }, scene.database, getBinaryData);
             }
         }
 
@@ -889,7 +889,7 @@ module BABYLON {
                 }
             };
 
-            Tools.LoadImage(url, onload,() => { }, scene.database);
+            Tools.LoadImage(url, onload, () => { }, scene.database);
         }
 
         public applyDisplacementMapFromBuffer(buffer: Uint8Array, heightMapWidth: number, heightMapHeight: number, minHeight: number, maxHeight: number): void {
@@ -910,7 +910,7 @@ module BABYLON {
             for (var index = 0; index < positions.length; index += 3) {
                 Vector3.FromArrayToRef(positions, index, position);
                 Vector3.FromArrayToRef(normals, index, normal);
-                Vector2.FromArrayToRef(uvs,(index / 3) * 2, uv);
+                Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
 
                 // Compute height
                 var u = ((Math.abs(uv.x) * heightMapWidth) % heightMapWidth) | 0;
@@ -991,8 +991,8 @@ module BABYLON {
                 indices[index + 2] = index + 2;
 
                 var p1 = Vector3.FromArray(positions, index * 3);
-                var p2 = Vector3.FromArray(positions,(index + 1) * 3);
-                var p3 = Vector3.FromArray(positions,(index + 2) * 3);
+                var p2 = Vector3.FromArray(positions, (index + 1) * 3);
+                var p3 = Vector3.FromArray(positions, (index + 2) * 3);
 
                 var p1p2 = p1.subtract(p2);
                 var p3p2 = p3.subtract(p2);
@@ -1060,7 +1060,7 @@ module BABYLON {
                 //parallel simplifier
                 settings.forEach((setting) => {
                     var simplifier = getSimplifier();
-                    simplifier.simplify(setting,(newMesh) => {
+                    simplifier.simplify(setting, (newMesh) => {
                         this.addLODLevel(setting.distance, newMesh);
                         //check if it is the last
                         if (setting.quality === settings[settings.length - 1].quality && successCallback) {
@@ -1074,18 +1074,18 @@ module BABYLON {
                 var simplifier = getSimplifier();
 
                 var runDecimation = (setting: ISimplificationSettings, callback: () => void) => {
-                    simplifier.simplify(setting,(newMesh) => {
+                    simplifier.simplify(setting, (newMesh) => {
                         this.addLODLevel(setting.distance, newMesh);
                         //run the next quality level
                         callback();
                     });
                 }
 
-                AsyncLoop.Run(settings.length,(loop: AsyncLoop) => {
-                    runDecimation(settings[loop.index],() => {
+                AsyncLoop.Run(settings.length, (loop: AsyncLoop) => {
+                    runDecimation(settings[loop.index], () => {
                         loop.executeNext();
                     });
-                },() => {
+                }, () => {
                         //execution ended, run the success callback.
                         if (successCallback) {
                             successCallback();
@@ -1103,7 +1103,7 @@ module BABYLON {
 
             return ribbon;
         }
-        
+
         public static CreateBox(name: string, size: number, scene: Scene, updatable?: boolean): Mesh {
             var box = new Mesh(name, scene);
             var vertexData = VertexData.CreateBox(size);
@@ -1237,7 +1237,7 @@ module BABYLON {
                 }
             };
 
-            Tools.LoadImage(url, onload,() => { }, scene.database);
+            Tools.LoadImage(url, onload, () => { }, scene.database);
 
             return ground;
         }

+ 71 - 25
Babylon/Mesh/babylon.mesh.vertexData.js

@@ -190,7 +190,7 @@ var BABYLON;
             return VertexData._ExtractFrom(geometry);
         };
         VertexData._ExtractFrom = function (meshOrGeometry) {
-            var result = new BABYLON.VertexData();
+            var result = new VertexData();
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
                 result.positions = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             }
@@ -245,7 +245,11 @@ var BABYLON;
             // positions and horizontal distances (u)
             var idc = 0;
             minlg = pathArray[0].length;
+<<<<<<< HEAD
             for (var p = 0; p < pathArray.length; p++) {
+=======
+            for (p = 0; p < pathArray.length; p++) {
+>>>>>>> upstream/master
                 uTotalDistance[p] = 0;
                 us[p] = [0];
                 var path = pathArray[p];
@@ -265,12 +269,18 @@ var BABYLON;
                     j++;
                 }
                 if (closePath) {
+<<<<<<< HEAD
                     var vectlg = path[0].subtract(path[j - 1]).length();
                     var dist = vectlg + uTotalDistance[p];
+=======
+                    vectlg = path[0].subtract(path[j - 1]).length();
+                    dist = vectlg + uTotalDistance[p];
+>>>>>>> upstream/master
                     uTotalDistance[p] = dist;
                 }
                 idc += l;
             }
+<<<<<<< HEAD
             for (var i = 0; i < minlg; i++) {
                 vTotalDistance[i] = 0;
                 vs[i] = [0];
@@ -279,10 +289,21 @@ var BABYLON;
                     var path2 = pathArray[p + 1];
                     var vectlg = path2[i].subtract(path1[i]).length();
                     var dist = vectlg + vTotalDistance[i];
+=======
+            for (i = 0; i < minlg; i++) {
+                vTotalDistance[i] = 0;
+                vs[i] = [0];
+                for (p = 0; p < pathArray.length - 1; p++) {
+                    var path1 = pathArray[p];
+                    var path2 = pathArray[p + 1];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+>>>>>>> upstream/master
                     vs[i].push(dist);
                     vTotalDistance[i] = dist;
                 }
                 if (closeArray) {
+<<<<<<< HEAD
                     var path1 = pathArray[p];
                     var path2 = pathArray[0];
                     var vectlg = path2[i].subtract(path1[i]).length();
@@ -292,6 +313,17 @@ var BABYLON;
             }
             for (var p = 0; p < pathArray.length; p++) {
                 for (var i = 0; i < minlg; i++) {
+=======
+                    path1 = pathArray[p];
+                    path2 = pathArray[0];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+                    vTotalDistance[i] = dist;
+                }
+            }
+            for (p = 0; p < pathArray.length; p++) {
+                for (i = 0; i < minlg; i++) {
+>>>>>>> upstream/master
                     var u = us[p][i] / uTotalDistance[p];
                     var v = vs[i][p] / vTotalDistance[i];
                     uvs.push(u, v);
@@ -314,7 +346,11 @@ var BABYLON;
                 indices.push(i, i + shft, i + 1);
                 indices.push(i + shft + 1, i + 1, i + shft);
                 i += 1;
+<<<<<<< HEAD
                 if (i == min) {
+=======
+                if (i === min) {
+>>>>>>> upstream/master
                     if (closePath) {
                         indices.push(i, i + shft, idx[p]);
                         indices.push(idx[p] + shft, idx[p], i + shft);
@@ -322,7 +358,11 @@ var BABYLON;
                         t4 = idx[p] + shft;
                     }
                     p++;
+<<<<<<< HEAD
                     if (p == lg.length - 1) {
+=======
+                    if (p === lg.length - 1) {
+>>>>>>> upstream/master
                         shft = idx[0] - idx[p];
                         l1 = lg[p] - 1;
                         l2 = lg[0] - 1;
@@ -337,9 +377,15 @@ var BABYLON;
                 }
             }
             // normals
+<<<<<<< HEAD
             BABYLON.VertexData.ComputeNormals(positions, indices, normals);
             // Result
             var vertexData = new BABYLON.VertexData();
+=======
+            VertexData.ComputeNormals(positions, indices, normals);
+            // Result
+            var vertexData = new VertexData();
+>>>>>>> upstream/master
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -392,7 +438,7 @@ var BABYLON;
                 uvs.push(1.0, 0.0);
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -438,7 +484,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -467,7 +513,7 @@ var BABYLON;
             };
             var createCylinderCap = function (isTop) {
                 var radius = isTop ? radiusTop : radiusBottom;
-                if (radius == 0) {
+                if (radius === 0) {
                     return;
                 }
                 var vbase = positions.length / 3;
@@ -477,14 +523,14 @@ var BABYLON;
                     offset.scaleInPlace(-1);
                     textureScale.x = -textureScale.x;
                 }
-                for (i = 0; i < tessellation; i++) {
+                for (var i = 0; i < tessellation; i++) {
                     var circleVector = getCircleVector(i);
                     var position = circleVector.scale(radius).add(offset);
                     var textureCoordinate = new BABYLON.Vector2(circleVector.x * textureScale.x + 0.5, circleVector.z * textureScale.y + 0.5);
                     positions.push(position.x, position.y, position.z);
                     uvs.push(textureCoordinate.x, textureCoordinate.y);
                 }
-                for (var i = 0; i < tessellation - 2; i++) {
+                for (i = 0; i < tessellation - 2; i++) {
                     if (!isTop) {
                         indices.push(vbase);
                         indices.push(vbase + (i + 2) % tessellation);
@@ -516,8 +562,8 @@ var BABYLON;
                 }
             }
             subdivisions += 1;
-            for (var s = 0; s < subdivisions - 1; s++) {
-                for (var i = 0; i <= tessellation; i++) {
+            for (s = 0; s < subdivisions - 1; s++) {
+                for (i = 0; i <= tessellation; i++) {
                     indices.push(i * subdivisions + s);
                     indices.push((i * subdivisions + (s + subdivisions)) % (stride * subdivisions));
                     indices.push(i * subdivisions + (s + 1));
@@ -530,9 +576,9 @@ var BABYLON;
             createCylinderCap(true);
             createCylinderCap(false);
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -578,7 +624,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -596,7 +642,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             return vertexData;
@@ -630,7 +676,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -653,11 +699,6 @@ var BABYLON;
                 'w': (xmax - xmin) / subdivisions.w,
                 'h': (zmax - zmin) / subdivisions.h
             };
-            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
-                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
-                    applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
-                }
-            }
             function applyTile(xTileMin, zTileMin, xTileMax, zTileMax) {
                 // Indices
                 var base = positions.length / 3;
@@ -692,8 +733,13 @@ var BABYLON;
                     }
                 }
             }
+            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
+                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
+                    applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
+                }
+            }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -735,9 +781,9 @@ var BABYLON;
                 }
             }
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -772,7 +818,7 @@ var BABYLON;
             indices.push(2);
             indices.push(3);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -841,9 +887,9 @@ var BABYLON;
                 }
             }
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -893,4 +939,4 @@ var BABYLON;
     BABYLON.VertexData = VertexData;
 })(BABYLON || (BABYLON = {}));
 
-//# sourceMappingURL=../Mesh/babylon.mesh.vertexData.js.map
+//# sourceMappingURL=../Mesh/babylon.mesh.vertexData.js.map

+ 258 - 260
Babylon/Mesh/babylon.mesh.vertexData.ts

@@ -1,4 +1,4 @@
-module BABYLON {
+module BABYLON {
     export interface IGetSetVerticesData {
         isVerticesDataPresent(kind: string): boolean;
         getVerticesData(kind: string): number[];
@@ -20,25 +20,25 @@ module BABYLON {
 
         public set(data: number[], kind: string) {
             switch (kind) {
-                case BABYLON.VertexBuffer.PositionKind:
+                case VertexBuffer.PositionKind:
                     this.positions = data;
                     break;
-                case BABYLON.VertexBuffer.NormalKind:
+                case VertexBuffer.NormalKind:
                     this.normals = data;
                     break;
-                case BABYLON.VertexBuffer.UVKind:
+                case VertexBuffer.UVKind:
                     this.uvs = data;
                     break;
-                case BABYLON.VertexBuffer.UV2Kind:
+                case VertexBuffer.UV2Kind:
                     this.uv2s = data;
                     break;
-                case BABYLON.VertexBuffer.ColorKind:
+                case VertexBuffer.ColorKind:
                     this.colors = data;
                     break;
-                case BABYLON.VertexBuffer.MatricesIndicesKind:
+                case VertexBuffer.MatricesIndicesKind:
                     this.matricesIndices = data;
                     break;
-                case BABYLON.VertexBuffer.MatricesWeightsKind:
+                case VertexBuffer.MatricesWeightsKind:
                     this.matricesWeights = data;
                     break;
             }
@@ -62,31 +62,31 @@ module BABYLON {
 
         private _applyTo(meshOrGeometry: IGetSetVerticesData, updatable?: boolean) {
             if (this.positions) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.PositionKind, this.positions, updatable);
             }
 
             if (this.normals) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.NormalKind, this.normals, updatable);
             }
 
             if (this.uvs) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.UVKind, this.uvs, updatable);
             }
 
             if (this.uv2s) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uv2s, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.UV2Kind, this.uv2s, updatable);
             }
 
             if (this.colors) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.ColorKind, this.colors, updatable);
             }
 
             if (this.matricesIndices) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updatable);
             }
 
             if (this.matricesWeights) {
-                meshOrGeometry.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);
+                meshOrGeometry.setVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updatable);
             }
 
             if (this.indices) {
@@ -96,31 +96,31 @@ module BABYLON {
 
         private _update(meshOrGeometry: IGetSetVerticesData, updateExtends?: boolean, makeItUnique?: boolean) {
             if (this.positions) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.PositionKind, this.positions, updateExtends, makeItUnique);
             }
 
             if (this.normals) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
             }
 
             if (this.uvs) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
             }
 
             if (this.uv2s) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.UV2Kind, this.uv2s, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.UV2Kind, this.uv2s, updateExtends, makeItUnique);
             }
 
             if (this.colors) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.ColorKind, this.colors, updateExtends, makeItUnique);
             }
 
             if (this.matricesIndices) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.MatricesIndicesKind, this.matricesIndices, updateExtends, makeItUnique);
             }
 
             if (this.matricesWeights) {
-                meshOrGeometry.updateVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);
+                meshOrGeometry.updateVerticesData(VertexBuffer.MatricesWeightsKind, this.matricesWeights, updateExtends, makeItUnique);
             }
 
             if (this.indices) {
@@ -129,15 +129,15 @@ module BABYLON {
         }
 
         public transform(matrix: Matrix): void {
-            var transformed = BABYLON.Vector3.Zero();
+            var transformed = Vector3.Zero();
 
             if (this.positions) {
-                var position = BABYLON.Vector3.Zero();
+                var position = Vector3.Zero();
 
                 for (var index = 0; index < this.positions.length; index += 3) {
-                    BABYLON.Vector3.FromArrayToRef(this.positions, index, position);
+                    Vector3.FromArrayToRef(this.positions, index, position);
 
-                    BABYLON.Vector3.TransformCoordinatesToRef(position, matrix, transformed);
+                    Vector3.TransformCoordinatesToRef(position, matrix, transformed);
                     this.positions[index] = transformed.x;
                     this.positions[index + 1] = transformed.y;
                     this.positions[index + 2] = transformed.z;
@@ -145,12 +145,12 @@ module BABYLON {
             }
 
             if (this.normals) {
-                var normal = BABYLON.Vector3.Zero();
+                var normal = Vector3.Zero();
 
                 for (index = 0; index < this.normals.length; index += 3) {
-                    BABYLON.Vector3.FromArrayToRef(this.normals, index, normal);
+                    Vector3.FromArrayToRef(this.normals, index, normal);
 
-                    BABYLON.Vector3.TransformNormalToRef(normal, matrix, transformed);
+                    Vector3.TransformNormalToRef(normal, matrix, transformed);
                     this.normals[index] = transformed.x;
                     this.normals[index + 1] = transformed.y;
                     this.normals[index + 2] = transformed.z;
@@ -245,34 +245,34 @@ module BABYLON {
         }
 
         private static _ExtractFrom(meshOrGeometry: IGetSetVerticesData): VertexData {
-            var result = new BABYLON.VertexData();
+            var result = new VertexData();
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
-                result.positions = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.PositionKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.PositionKind)) {
+                result.positions = meshOrGeometry.getVerticesData(VertexBuffer.PositionKind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
-                result.normals = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.NormalKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.NormalKind)) {
+                result.normals = meshOrGeometry.getVerticesData(VertexBuffer.NormalKind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
-                result.uvs = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UVKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UVKind)) {
+                result.uvs = meshOrGeometry.getVerticesData(VertexBuffer.UVKind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
-                result.uv2s = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.UV2Kind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+                result.uv2s = meshOrGeometry.getVerticesData(VertexBuffer.UV2Kind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
-                result.colors = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.ColorKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.ColorKind)) {
+                result.colors = meshOrGeometry.getVerticesData(VertexBuffer.ColorKind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
-                result.matricesIndices = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {
+                result.matricesIndices = meshOrGeometry.getVerticesData(VertexBuffer.MatricesIndicesKind);
             }
 
-            if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
-                result.matricesWeights = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
+            if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+                result.matricesWeights = meshOrGeometry.getVerticesData(VertexBuffer.MatricesWeightsKind);
             }
 
             result.indices = meshOrGeometry.getIndices();
@@ -280,166 +280,164 @@ module BABYLON {
             return result;
         }
 
-		public static CreateRibbon(pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number): VertexData {
-			
-			closeArray = closeArray || false;
-  			closePath = closePath || false;
-  			var defaultOffset = Math.floor(pathArray[0].length / 2);
-  			offset = offset || defaultOffset;
-  			offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
-			
-			
-			var positions = [];
-		  	var indices = [];
-		  	var normals = [];
-		  	var uvs = [];
-		  	
-		  	var us = [];        		// us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id
-		  	var vs = [];        		// vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutives paths from pathArray
-		  	var uTotalDistance = []; 	// uTotalDistance[p] : total distance of path p
-		  	var vTotalDistance = []; 	//  vTotalDistance[i] : total distance between points i of first and last path from pathArray
-		  	var minlg;          		// minimal length among all paths from pathArray
-		  	var lg = [];        		// array of path lengths : nb of vertex per path
-		  	var idx = [];       		// array of path indexes : index of each path (first vertex) in positions array
-		  	
-		  	// if single path in pathArray
-			if ( pathArray.length < 2) {
-			    var ar1 = [];
-			    var ar2 = [];
-			    for (var i = 0; i < pathArray[0].length - offset; i++) {
-			      ar1.push(pathArray[0][i]);
-			      ar2.push(pathArray[0][i+offset]);
-			    }
-			    pathArray = [ar1, ar2];
-			}
-			
-			// positions and horizontal distances (u)
-			var idc = 0;
-			minlg = pathArray[0].length;
-			for(var p = 0; p < pathArray.length; p++) {
-			    uTotalDistance[p] = 0;
-			    us[p] = [0];
-			    var path = pathArray[p];
-			    var l = path.length;
-			    minlg = (minlg < l) ? minlg : l;
-			    lg[p] = l;
-			    idx[p] = idc;
-			    var j = 0;
-			    while (j < l) {
-			      	positions.push(path[j].x, path[j].y, path[j].z);
-			      	if (j > 0) {
-			        	var vectlg = path[j].subtract(path[j-1]).length();
-			        	var dist = vectlg + uTotalDistance[p];
-			        	us[p].push(dist);
-			        	uTotalDistance[p] = dist;
-			      	}
-			      	j++;
-			    }
-			    if ( closePath ) {
-			      	var vectlg = path[0].subtract(path[j-1]).length();
-			      	var dist = vectlg + uTotalDistance[p];
-			      	uTotalDistance[p] = dist;
-			    }
-			    idc += l;
-			  }			
-			
-			  // vertical distances (v)
-			  for(var i = 0; i < minlg; i++) {
-			    vTotalDistance[i] = 0;
-			    vs[i] =[0];
-				    for (var p = 0; p < pathArray.length-1; p++) {
-				    var path1 = pathArray[p];
-				    var path2 = pathArray[p+1];
-				    var vectlg = path2[i].subtract(path1[i]).length();
-				    var dist =  vectlg + vTotalDistance[i];
-				    vs[i].push(dist);
-				    vTotalDistance[i] = dist;
-			    }
-			    if (closeArray) {
-					var path1 = pathArray[p];
-					var path2 = pathArray[0];
-					var vectlg = path2[i].subtract(path1[i]).length();
-					var dist =  vectlg + vTotalDistance[i];
-					vTotalDistance[i] = dist;
-			    }
-			  }			
-		
-		
-			// uvs
-			for(var p = 0; p < pathArray.length; p++) {
-				for(var i = 0; i < minlg; i++) {
-				    var u = us[p][i] / uTotalDistance[p];
-				    var v = vs[i][p] / vTotalDistance[i];
-				    uvs.push(u, v);
-				}
-			}
-			
-			// indices
-			var p = 0;                    		// path index
-			var i = 0;                    		// positions array index
-			var l1 = lg[p] - 1;           		// path1 length
-			var l2 = lg[p+1] - 1;         		// path2 length
-			var min = ( l1 < l2 ) ? l1 : l2 ;   // current path stop index
-			var shft = idx[1] - idx[0];         // shift 
-			var path1nb = closeArray ? lg.length : lg.length -1;     // number of path1 to iterate	
-			
-			
-			while ( i <= min && p < path1nb ) {       //  stay under min and don't go over next to last path
-				// draw two triangles between path1 (p1) and path2 (p2) : (p1.i, p2.i, p1.i+1) and (p2.i+1, p1.i+1, p2.i) clockwise
-				var t1 = i;
-				var t2 = i + shft;
-				var t3 = i +1;
-				var t4 = i + shft + 1;
-			
-				indices.push(i, i+shft, i+1);
-				indices.push(i+shft+1, i+1, i+shft);  
-			  	i += 1;
-			  	if ( i == min  ) {                   			// if end of one of two consecutive paths reached, go next existing path
-			    	if (closePath) {                          	// if closePath, add last triangles between start and end of the paths
-			      		indices.push(i, i+shft, idx[p]);
-			      		indices.push(idx[p]+shft, idx[p], i+shft);
-			      		t3 = idx[p];
-			      		t4 = idx[p] + shft;
-			    	}
-			    	p++; 
-			    	if ( p == lg.length - 1 ) {                 // last path of pathArray reached <=> closeArray == true
-			      		shft = idx[0] - idx[p];
-			      		l1 = lg[p] - 1;
-			      		l2 = lg[0] - 1; 
-			    	}
-			    	else {  
-			      		shft = idx[p+1] - idx[p]; 
-			      		l1 = lg[p] - 1;
-			      		l2 = lg[p+1] - 1;         
-			    	}   
-			
-			    	i = idx[p];
-			    	min = ( l1 < l2 ) ? l1 + i : l2 + i;
-			  	}
-			} 		
-			
-			// normals
-			BABYLON.VertexData.ComputeNormals(positions, indices, normals);
-            
+        public static CreateRibbon(pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number): VertexData {
+            closeArray = closeArray || false;
+            closePath = closePath || false;
+            var defaultOffset = Math.floor(pathArray[0].length / 2);
+            offset = offset || defaultOffset;
+            offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
+
+            var positions = [];
+            var indices = [];
+            var normals = [];
+            var uvs = [];
+
+            var us = [];        		// us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id
+            var vs = [];        		// vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutives paths from pathArray
+            var uTotalDistance = []; 	// uTotalDistance[p] : total distance of path p
+            var vTotalDistance = []; 	//  vTotalDistance[i] : total distance between points i of first and last path from pathArray
+            var minlg;          		// minimal length among all paths from pathArray
+            var lg = [];        		// array of path lengths : nb of vertex per path
+            var idx = [];       		// array of path indexes : index of each path (first vertex) in positions array
+
+            // if single path in pathArray
+            if (pathArray.length < 2) {
+                var ar1 = [];
+                var ar2 = [];
+                for (var i = 0; i < pathArray[0].length - offset; i++) {
+                    ar1.push(pathArray[0][i]);
+                    ar2.push(pathArray[0][i + offset]);
+                }
+                pathArray = [ar1, ar2];
+            }
+
+            // positions and horizontal distances (u)
+            var idc = 0;
+            minlg = pathArray[0].length;
+            for (p = 0; p < pathArray.length; p++) {
+                uTotalDistance[p] = 0;
+                us[p] = [0];
+                var path = pathArray[p];
+                var l = path.length;
+                minlg = (minlg < l) ? minlg : l;
+                lg[p] = l;
+                idx[p] = idc;
+                var j = 0;
+                while (j < l) {
+                    positions.push(path[j].x, path[j].y, path[j].z);
+                    if (j > 0) {
+                        var vectlg = path[j].subtract(path[j - 1]).length();
+                        var dist = vectlg + uTotalDistance[p];
+                        us[p].push(dist);
+                        uTotalDistance[p] = dist;
+                    }
+                    j++;
+                }
+                if (closePath) {
+                    vectlg = path[0].subtract(path[j - 1]).length();
+                    dist = vectlg + uTotalDistance[p];
+                    uTotalDistance[p] = dist;
+                }
+                idc += l;
+            }
+
+            // vertical distances (v)
+            for (i = 0; i < minlg; i++) {
+                vTotalDistance[i] = 0;
+                vs[i] = [0];
+                for (p = 0; p < pathArray.length - 1; p++) {
+                    var path1 = pathArray[p];
+                    var path2 = pathArray[p + 1];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+                    vs[i].push(dist);
+                    vTotalDistance[i] = dist;
+                }
+                if (closeArray) {
+                    path1 = pathArray[p];
+                    path2 = pathArray[0];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+                    vTotalDistance[i] = dist;
+                }
+            }
+
+
+            // uvs
+            for (p = 0; p < pathArray.length; p++) {
+                for (i = 0; i < minlg; i++) {
+                    var u = us[p][i] / uTotalDistance[p];
+                    var v = vs[i][p] / vTotalDistance[i];
+                    uvs.push(u, v);
+                }
+            }
+
+            // indices
+            var p = 0;                    		// path index
+            var i = 0;                    		// positions array index
+            var l1 = lg[p] - 1;           		// path1 length
+            var l2 = lg[p + 1] - 1;         		// path2 length
+            var min = (l1 < l2) ? l1 : l2;   // current path stop index
+            var shft = idx[1] - idx[0];         // shift 
+            var path1nb = closeArray ? lg.length : lg.length - 1;     // number of path1 to iterate	
+
+
+            while (i <= min && p < path1nb) {       //  stay under min and don't go over next to last path
+                // draw two triangles between path1 (p1) and path2 (p2) : (p1.i, p2.i, p1.i+1) and (p2.i+1, p1.i+1, p2.i) clockwise
+                var t1 = i;
+                var t2 = i + shft;
+                var t3 = i + 1;
+                var t4 = i + shft + 1;
+
+                indices.push(i, i + shft, i + 1);
+                indices.push(i + shft + 1, i + 1, i + shft);
+                i += 1;
+                if (i === min) {                   			// if end of one of two consecutive paths reached, go next existing path
+                    if (closePath) {                          	// if closePath, add last triangles between start and end of the paths
+                        indices.push(i, i + shft, idx[p]);
+                        indices.push(idx[p] + shft, idx[p], i + shft);
+                        t3 = idx[p];
+                        t4 = idx[p] + shft;
+                    }
+                    p++;
+                    if (p === lg.length - 1) {                 // last path of pathArray reached <=> closeArray == true
+                        shft = idx[0] - idx[p];
+                        l1 = lg[p] - 1;
+                        l2 = lg[0] - 1;
+                    }
+                    else {
+                        shft = idx[p + 1] - idx[p];
+                        l1 = lg[p] - 1;
+                        l2 = lg[p + 1] - 1;
+                    }
+
+                    i = idx[p];
+                    min = (l1 < l2) ? l1 + i : l2 + i;
+                }
+            }
+
+            // normals
+            VertexData.ComputeNormals(positions, indices, normals);
+
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
-            vertexData.uvs = uvs;			
-				
-			return vertexData;
-		}
+            vertexData.uvs = uvs;
+
+            return vertexData;
+        }
 
         public static CreateBox(size: number): VertexData {
             var normalsSource = [
-                new BABYLON.Vector3(0, 0, 1),
-                new BABYLON.Vector3(0, 0, -1),
-                new BABYLON.Vector3(1, 0, 0),
-                new BABYLON.Vector3(-1, 0, 0),
-                new BABYLON.Vector3(0, 1, 0),
-                new BABYLON.Vector3(0, -1, 0)
+                new Vector3(0, 0, 1),
+                new Vector3(0, 0, -1),
+                new Vector3(1, 0, 0),
+                new Vector3(-1, 0, 0),
+                new Vector3(0, 1, 0),
+                new Vector3(0, -1, 0)
             ];
 
             var indices = [];
@@ -454,8 +452,8 @@ module BABYLON {
                 var normal = normalsSource[index];
 
                 // Get two vectors perpendicular to the face normal and to each other.
-                var side1 = new BABYLON.Vector3(normal.y, normal.z, normal.x);
-                var side2 = BABYLON.Vector3.Cross(normal, side1);
+                var side1 = new Vector3(normal.y, normal.z, normal.x);
+                var side2 = Vector3.Cross(normal, side1);
 
                 // Six indices (two triangles) per face.
                 var verticesLength = positions.length / 3;
@@ -490,7 +488,7 @@ module BABYLON {
             }
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -524,13 +522,13 @@ module BABYLON {
 
                     var angleY = normalizedY * Math.PI * 2;
 
-                    var rotationZ = BABYLON.Matrix.RotationZ(-angleZ);
-                    var rotationY = BABYLON.Matrix.RotationY(angleY);
-                    var afterRotZ = BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.Up(), rotationZ);
-                    var complete = BABYLON.Vector3.TransformCoordinates(afterRotZ, rotationY);
+                    var rotationZ = Matrix.RotationZ(-angleZ);
+                    var rotationY = Matrix.RotationY(angleY);
+                    var afterRotZ = Vector3.TransformCoordinates(Vector3.Up(), rotationZ);
+                    var complete = Vector3.TransformCoordinates(afterRotZ, rotationY);
 
                     var vertex = complete.scale(radius);
-                    var normal = BABYLON.Vector3.Normalize(vertex);
+                    var normal = Vector3.Normalize(vertex);
 
                     positions.push(vertex.x, vertex.y, vertex.z);
                     normals.push(normal.x, normal.y, normal.z);
@@ -552,7 +550,7 @@ module BABYLON {
             }
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -582,19 +580,19 @@ module BABYLON {
                 var dx = Math.cos(angle);
                 var dz = Math.sin(angle);
 
-                return new BABYLON.Vector3(dx, 0, dz);
+                return new Vector3(dx, 0, dz);
             };
 
             var createCylinderCap = isTop => {
                 var radius = isTop ? radiusTop : radiusBottom;
 
-                if (radius == 0) {
+                if (radius === 0) {
                     return;
                 }
                 var vbase = positions.length / 3;
 
-                var offset = new BABYLON.Vector3(0, height / 2, 0);
-                var textureScale = new BABYLON.Vector2(0.5, 0.5);
+                var offset = new Vector3(0, height / 2, 0);
+                var textureScale = new Vector2(0.5, 0.5);
 
                 if (!isTop) {
                     offset.scaleInPlace(-1);
@@ -602,10 +600,10 @@ module BABYLON {
                 }
 
                 // Positions, normals & uvs
-                for (i = 0; i < tessellation; i++) {
+                for (var i = 0; i < tessellation; i++) {
                     var circleVector = getCircleVector(i);
                     var position = circleVector.scale(radius).add(offset);
-                    var textureCoordinate = new BABYLON.Vector2(
+                    var textureCoordinate = new Vector2(
                         circleVector.x * textureScale.x + 0.5,
                         circleVector.z * textureScale.y + 0.5
                         );
@@ -615,7 +613,7 @@ module BABYLON {
                 }
 
                 // Indices
-                for (var i = 0; i < tessellation - 2; i++) {
+                for (i = 0; i < tessellation - 2; i++) {
                     if (!isTop) {
                         indices.push(vbase);
                         indices.push(vbase + (i + 2) % tessellation);
@@ -628,15 +626,15 @@ module BABYLON {
                 }
             };
 
-            var base = new BABYLON.Vector3(0, -1, 0).scale(height / 2);
-            var offset = new BABYLON.Vector3(0, 1, 0).scale(height / subdivisions);
+            var base = new Vector3(0, -1, 0).scale(height / 2);
+            var offset = new Vector3(0, 1, 0).scale(height / subdivisions);
             var stride = tessellation + 1;
 
             // Positions, normals & uvs
             for (var i = 0; i <= tessellation; i++) {
                 var circleVector = getCircleVector(i);
-                var textureCoordinate = new BABYLON.Vector2(i / tessellation, 0);
-                var position, radius = radiusBottom;
+                var textureCoordinate = new Vector2(i / tessellation, 0);
+                var position: Vector3, radius = radiusBottom;
 
                 for (var s = 0; s <= subdivisions; s++) {
                     // Update variables
@@ -653,8 +651,8 @@ module BABYLON {
 
             subdivisions += 1;
             // Indices
-            for (var s = 0; s < subdivisions - 1; s++) {
-                for (var i = 0; i <= tessellation; i++) {
+            for (s = 0; s < subdivisions - 1; s++) {
+                for (i = 0; i <= tessellation; i++) {
                     indices.push(i * subdivisions + s);
                     indices.push((i * subdivisions + (s + subdivisions)) % (stride * subdivisions));
                     indices.push(i * subdivisions + (s + 1));
@@ -670,10 +668,10 @@ module BABYLON {
             createCylinderCap(false);
 
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -700,7 +698,7 @@ module BABYLON {
 
                 var outerAngle = i * Math.PI * 2.0 / tessellation - Math.PI / 2.0;
 
-                var transform = BABYLON.Matrix.Translation(diameter / 2.0, 0, 0).multiply(BABYLON.Matrix.RotationY(outerAngle));
+                var transform = Matrix.Translation(diameter / 2.0, 0, 0).multiply(Matrix.RotationY(outerAngle));
 
                 for (var j = 0; j <= tessellation; j++) {
                     var v = 1 - j / tessellation;
@@ -710,12 +708,12 @@ module BABYLON {
                     var dy = Math.sin(innerAngle);
 
                     // Create a vertex.
-                    var normal = new BABYLON.Vector3(dx, dy, 0);
+                    var normal = new Vector3(dx, dy, 0);
                     var position = normal.scale(thickness / 2);
-                    var textureCoordinate = new BABYLON.Vector2(u, v);
+                    var textureCoordinate = new Vector2(u, v);
 
-                    position = BABYLON.Vector3.TransformCoordinates(position, transform);
-                    normal = BABYLON.Vector3.TransformNormal(normal, transform);
+                    position = Vector3.TransformCoordinates(position, transform);
+                    normal = Vector3.TransformNormal(normal, transform);
 
                     positions.push(position.x, position.y, position.z);
                     normals.push(normal.x, normal.y, normal.z);
@@ -736,7 +734,7 @@ module BABYLON {
             }
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -760,7 +758,7 @@ module BABYLON {
             }
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -773,7 +771,7 @@ module BABYLON {
             var positions = [];
             var normals = [];
             var uvs = [];
-            var row, col;
+            var row: number, col: number;
 
             width = width || 1;
             height = height || 1;
@@ -781,8 +779,8 @@ module BABYLON {
 
             for (row = 0; row <= subdivisions; row++) {
                 for (col = 0; col <= subdivisions; col++) {
-                    var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
-                    var normal = new BABYLON.Vector3(0, 1.0, 0);
+                    var position = new Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
+                    var normal = new Vector3(0, 1.0, 0);
 
                     positions.push(position.x, position.y, position.z);
                     normals.push(normal.x, normal.y, normal.z);
@@ -803,7 +801,7 @@ module BABYLON {
             }
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -818,7 +816,7 @@ module BABYLON {
             var positions = [];
             var normals = [];
             var uvs = [];
-            var row, col, tileRow, tileCol;
+            var row: number, col: number, tileRow: number, tileCol: number;
 
             subdivisions.h = (subdivisions.w < 1) ? 1 : subdivisions.h;
             subdivisions.w = (subdivisions.w < 1) ? 1 : subdivisions.w;
@@ -830,17 +828,6 @@ module BABYLON {
                 'h': (zmax - zmin) / subdivisions.h
             };
 
-            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
-                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
-                    applyTile(
-                        xmin + tileCol * tileSize.w,
-                        zmin + tileRow * tileSize.h,
-                        xmin + (tileCol + 1) * tileSize.w,
-                        zmin + (tileRow + 1) * tileSize.h
-                        );
-                }
-            }
-
             function applyTile(xTileMin: number, zTileMin: number, xTileMax: number, zTileMax: number) {
                 // Indices
                 var base = positions.length / 3;
@@ -864,8 +851,8 @@ module BABYLON {
                 }
 
                 // Position, normals and uvs
-                var position = BABYLON.Vector3.Zero();
-                var normal = new BABYLON.Vector3(0, 1.0, 0);
+                var position = Vector3.Zero();
+                var normal = new Vector3(0, 1.0, 0);
                 for (row = 0; row <= precision.h; row++) {
                     position.z = (row * (zTileMax - zTileMin)) / precision.h + zTileMin;
                     for (col = 0; col <= precision.w; col++) {
@@ -879,8 +866,19 @@ module BABYLON {
                 }
             }
 
+            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
+                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
+                    applyTile(
+                        xmin + tileCol * tileSize.w,
+                        zmin + tileRow * tileSize.h,
+                        xmin + (tileCol + 1) * tileSize.w,
+                        zmin + (tileRow + 1) * tileSize.h
+                        );
+                }
+            }
+
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -900,7 +898,7 @@ module BABYLON {
             // Vertices
             for (row = 0; row <= subdivisions; row++) {
                 for (col = 0; col <= subdivisions; col++) {
-                    var position = new BABYLON.Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
+                    var position = new Vector3((col * width) / subdivisions - (width / 2.0), 0, ((subdivisions - row) * height) / subdivisions - (height / 2.0));
 
                     // Compute height
                     var heightMapX = (((position.x + width / 2) / width) * (bufferWidth - 1)) | 0;
@@ -936,10 +934,10 @@ module BABYLON {
             }
 
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -985,7 +983,7 @@ module BABYLON {
             indices.push(3);
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -1021,7 +1019,7 @@ module BABYLON {
                 var ty = radius * (2 + cs) * su * 0.5;
                 var tz = radius * Math.sin(quOverP) * 0.5;
 
-                return new BABYLON.Vector3(tx, ty, tz);
+                return new Vector3(tx, ty, tz);
             };
 
             // Vertices
@@ -1033,8 +1031,8 @@ module BABYLON {
                 var tang = p2.subtract(p1);
                 var n = p2.add(p1);
 
-                var bitan = BABYLON.Vector3.Cross(tang, n);
-                n = BABYLON.Vector3.Cross(bitan, tang);
+                var bitan = Vector3.Cross(tang, n);
+                n = Vector3.Cross(bitan, tang);
 
                 bitan.normalize();
                 n.normalize();
@@ -1068,10 +1066,10 @@ module BABYLON {
             }
 
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
 
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
 
             vertexData.indices = indices;
             vertexData.positions = positions;
@@ -1088,7 +1086,7 @@ module BABYLON {
             var index;
 
             for (index = 0; index < positions.length; index += 3) {
-                var vector3 = new BABYLON.Vector3(positions[index], positions[index + 1], positions[index + 2]);
+                var vector3 = new Vector3(positions[index], positions[index + 1], positions[index + 2]);
                 positionVectors.push(vector3);
                 facesOfVertices.push([]);
             }
@@ -1106,7 +1104,7 @@ module BABYLON {
                 var p1p2 = p1.subtract(p2);
                 var p3p2 = p3.subtract(p2);
 
-                facesNormals[index] = BABYLON.Vector3.Normalize(BABYLON.Vector3.Cross(p1p2, p3p2));
+                facesNormals[index] = Vector3.Normalize(Vector3.Cross(p1p2, p3p2));
                 facesOfVertices[i1].push(index);
                 facesOfVertices[i2].push(index);
                 facesOfVertices[i3].push(index);
@@ -1115,12 +1113,12 @@ module BABYLON {
             for (index = 0; index < positionVectors.length; index++) {
                 var faces = facesOfVertices[index];
 
-                var normal = BABYLON.Vector3.Zero();
+                var normal = Vector3.Zero();
                 for (var faceIndex = 0; faceIndex < faces.length; faceIndex++) {
                     normal.addInPlace(facesNormals[faces[faceIndex]]);
                 }
 
-                normal = BABYLON.Vector3.Normalize(normal.scale(1.0 / faces.length));
+                normal = Vector3.Normalize(normal.scale(1.0 / faces.length));
 
                 normals[index * 3] = normal.x;
                 normals[index * 3 + 1] = normal.y;
@@ -1128,4 +1126,4 @@ module BABYLON {
             }
         }
     }
-} 
+} 

+ 31 - 49
Babylon/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -46,27 +46,27 @@ var BABYLON;
             var body = null;
             this.unregisterMesh(mesh);
             mesh.computeWorldMatrix(true);
+            var initialRotation = null;
+            if (mesh.rotationQuaternion) {
+                initialRotation = mesh.rotationQuaternion.clone();
+                mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+                mesh.computeWorldMatrix(true);
+            }
+            var bbox = mesh.getBoundingInfo().boundingBox;
+            // The delta between the mesh position and the mesh bounding box center
+            var deltaPosition = mesh.position.subtract(bbox.center);
+            // Transform delta position with the rotation
+            if (initialRotation) {
+                var m = new BABYLON.Matrix();
+                initialRotation.toRotationMatrix(m);
+                deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
+            }
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
-                    var initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
-                    var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
                     var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
-                    // The delta between the mesh position and the mesh bounding box center
-                    var deltaPosition = mesh.position.subtract(bbox.center);
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        var m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
                     body = new OIMO.Body({
                         type: 'sphere',
                         size: [size],
@@ -76,39 +76,16 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
-                    // Restore rotation
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
                 case BABYLON.PhysicsEngine.PlaneImpostor:
+                case BABYLON.PhysicsEngine.CylinderImpostor:
                 case BABYLON.PhysicsEngine.BoxImpostor:
-                    initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
-                    bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min);
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
-                    // The delta between the mesh position and the mesh boudning box center
-                    deltaPosition = mesh.position.subtract(bbox.center);
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
                     body = new OIMO.Body({
                         type: 'box',
                         size: [sizeX, sizeY, sizeZ],
@@ -118,16 +95,21 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
             }
+            //If quaternion was set as the rotation of the object
+            if (initialRotation) {
+                //We have to access the rigid body's properties to set the quaternion. 
+                //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
+                body.body.orientation = new OIMO.Quat(initialRotation.w, initialRotation.x, initialRotation.y, initialRotation.z);
+                //update the internal rotation matrix
+                body.body.syncShapes();
+            }
+            this._registeredMeshes.push({
+                mesh: mesh,
+                body: body,
+                delta: deltaPosition
+            });
             return body;
         };
         OimoJSPlugin.prototype.registerMeshesAsCompound = function (parts, options) {
@@ -318,7 +300,7 @@ var BABYLON;
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         }
-                        mesh.rotationQuaternion.fromRotationMatrix(mtx);
+                        BABYLON.Quaternion.FromRotationMatrixToRef(mtx, mesh.rotationQuaternion);
                         mesh.computeWorldMatrix();
                     }
                 }
@@ -329,4 +311,4 @@ var BABYLON;
     BABYLON.OimoJSPlugin = OimoJSPlugin;
 })(BABYLON || (BABYLON = {}));
 
-//# sourceMappingURL=../../Physics/Plugins/babylon.oimoJSPlugin.js.map
+//# sourceMappingURL=../../Physics/Plugins/babylon.oimoJSPlugin.js.map

+ 40 - 57
Babylon/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -23,18 +23,31 @@ module BABYLON {
             this.unregisterMesh(mesh);
             mesh.computeWorldMatrix(true);
 
+
+            var initialRotation = null;
+            if (mesh.rotationQuaternion) {
+                initialRotation = mesh.rotationQuaternion.clone();
+                mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+                mesh.computeWorldMatrix(true);
+            }
+
+            var bbox = mesh.getBoundingInfo().boundingBox;
+
+            // The delta between the mesh position and the mesh bounding box center
+            var deltaPosition = mesh.position.subtract(bbox.center);
+
+            // Transform delta position with the rotation
+            if (initialRotation) {
+                var m = new BABYLON.Matrix();
+                initialRotation.toRotationMatrix(m);
+                deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
+            }
+
             // register mesh
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
 
-                    var initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
 
-                    var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
@@ -44,16 +57,6 @@ module BABYLON {
                         this._checkWithEpsilon(radiusY),
                         this._checkWithEpsilon(radiusZ)) / 2;
 
-                    // The delta between the mesh position and the mesh bounding box center
-                    var deltaPosition = mesh.position.subtract(bbox.center);
-
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        var m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
-
                     body = new OIMO.Body({
                         type: 'sphere',
                         size: [size],
@@ -64,29 +67,13 @@ module BABYLON {
                         world: this._world
                     });
 
-                    // Restore rotation
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
 
-                case BABYLON.PhysicsEngine.PlaneImpostor:
-                case BABYLON.PhysicsEngine.BoxImpostor:
-
-                    initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
+                case PhysicsEngine.PlaneImpostor:
+                //Oimo "fakes" a cylinder as a box, so why don't we!
+                case PhysicsEngine.CylinderImpostor:
+                case PhysicsEngine.BoxImpostor:
 
-                    bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min);
@@ -94,16 +81,6 @@ module BABYLON {
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
 
-                    // The delta between the mesh position and the mesh boudning box center
-                    deltaPosition = mesh.position.subtract(bbox.center);
-
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
-
                     body = new OIMO.Body({
                         type: 'box',
                         size: [sizeX, sizeY, sizeZ],
@@ -114,18 +91,24 @@ module BABYLON {
                         world: this._world
                     });
 
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
+            }
 
+            //If quaternion was set as the rotation of the object
+            if (initialRotation) {
+                //We have to access the rigid body's properties to set the quaternion. 
+                //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
+                body.body.orientation = new OIMO.Quat(initialRotation.w, initialRotation.x, initialRotation.y, initialRotation.z);
+                //update the internal rotation matrix
+                body.body.syncShapes();
             }
+
+            this._registeredMeshes.push({
+                mesh: mesh,
+                body: body,
+                delta: deltaPosition
+            });
+
             return body;
         }
 
@@ -386,7 +369,7 @@ module BABYLON {
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         }
-                        mesh.rotationQuaternion.fromRotationMatrix(mtx);
+                        Quaternion.FromRotationMatrixToRef(mtx, mesh.rotationQuaternion);
                         mesh.computeWorldMatrix();
                     }
                 }

+ 6 - 1
Babylon/Rendering/babylon.renderingManager.js

@@ -49,10 +49,12 @@ var BABYLON;
             for (var index = 0; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
+                var needToStepBack = false;
                 if (renderingGroup) {
                     this._clearDepthBuffer();
                     if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
+                        needToStepBack = true;
                     }
                 }
                 if (renderSprites) {
@@ -61,6 +63,9 @@ var BABYLON;
                 if (renderParticles) {
                     this._renderParticles(index, activeMeshes);
                 }
+                if (needToStepBack) {
+                    index--;
+                }
             }
         };
         RenderingManager.prototype.reset = function () {
@@ -83,4 +88,4 @@ var BABYLON;
     BABYLON.RenderingManager = RenderingManager;
 })(BABYLON || (BABYLON = {}));
 
-//# sourceMappingURL=../Rendering/babylon.renderingManager.js.map
+//# sourceMappingURL=../Rendering/babylon.renderingManager.js.map

+ 6 - 0
Babylon/Rendering/babylon.renderingManager.ts

@@ -65,11 +65,13 @@
             for (var index = 0; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
+                var needToStepBack = false;
 
                 if (renderingGroup) {
                     this._clearDepthBuffer();
                     if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
+                        needToStepBack = true;
                     }
                 }
 
@@ -80,6 +82,10 @@
                 if (renderParticles) {
                     this._renderParticles(index, activeMeshes);
                 }
+
+                if (needToStepBack) {
+                    index--;
+                }
             }
         }
 

+ 223 - 89
babylon.2.1-alpha.debug.js

@@ -10875,6 +10875,12 @@ var BABYLON;
             }
         };
         // Statics
+        Mesh.CreateRibbon = function (name, pathArray, closeArray, closePath, offset, scene, updatable) {
+            var ribbon = new Mesh(name, scene);
+            var vertexData = BABYLON.VertexData.CreateRibbon(pathArray, closeArray, closePath, offset);
+            vertexData.applyToMesh(ribbon, updatable);
+            return ribbon;
+        };
         Mesh.CreateBox = function (name, size, scene, updatable) {
             var box = new Mesh(name, scene);
             var vertexData = BABYLON.VertexData.CreateBox(size);
@@ -11628,10 +11634,12 @@ var BABYLON;
             for (var index = 0; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
                 this._depthBufferAlreadyCleaned = false;
                 var renderingGroup = this._renderingGroups[index];
+                var needToStepBack = false;
                 if (renderingGroup) {
                     this._clearDepthBuffer();
                     if (!renderingGroup.render(customRenderFunction)) {
                         this._renderingGroups.splice(index, 1);
+                        needToStepBack = true;
                     }
                 }
                 if (renderSprites) {
@@ -11640,6 +11648,9 @@ var BABYLON;
                 if (renderParticles) {
                     this._renderParticles(index, activeMeshes);
                 }
+                if (needToStepBack) {
+                    index--;
+                }
             }
         };
         RenderingManager.prototype.reset = function () {
@@ -17089,27 +17100,27 @@ var BABYLON;
             var body = null;
             this.unregisterMesh(mesh);
             mesh.computeWorldMatrix(true);
+            var initialRotation = null;
+            if (mesh.rotationQuaternion) {
+                initialRotation = mesh.rotationQuaternion.clone();
+                mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
+                mesh.computeWorldMatrix(true);
+            }
+            var bbox = mesh.getBoundingInfo().boundingBox;
+            // The delta between the mesh position and the mesh bounding box center
+            var deltaPosition = mesh.position.subtract(bbox.center);
+            // Transform delta position with the rotation
+            if (initialRotation) {
+                var m = new BABYLON.Matrix();
+                initialRotation.toRotationMatrix(m);
+                deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
+            }
             switch (impostor) {
                 case BABYLON.PhysicsEngine.SphereImpostor:
-                    var initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
-                    var bbox = mesh.getBoundingInfo().boundingBox;
                     var radiusX = bbox.maximumWorld.x - bbox.minimumWorld.x;
                     var radiusY = bbox.maximumWorld.y - bbox.minimumWorld.y;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
                     var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
-                    // The delta between the mesh position and the mesh bounding box center
-                    var deltaPosition = mesh.position.subtract(bbox.center);
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        var m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
                     body = new OIMO.Body({
                         type: 'sphere',
                         size: [size],
@@ -17119,39 +17130,16 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
-                    // Restore rotation
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
                 case BABYLON.PhysicsEngine.PlaneImpostor:
+                case BABYLON.PhysicsEngine.CylinderImpostor:
                 case BABYLON.PhysicsEngine.BoxImpostor:
-                    initialRotation = null;
-                    if (mesh.rotationQuaternion) {
-                        initialRotation = mesh.rotationQuaternion.clone();
-                        mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
-                        mesh.computeWorldMatrix(true);
-                    }
-                    bbox = mesh.getBoundingInfo().boundingBox;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min);
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
-                    // The delta between the mesh position and the mesh boudning box center
-                    deltaPosition = mesh.position.subtract(bbox.center);
-                    // Transform delta position with the rotation
-                    if (initialRotation) {
-                        m = new BABYLON.Matrix();
-                        initialRotation.toRotationMatrix(m);
-                        deltaPosition = BABYLON.Vector3.TransformCoordinates(deltaPosition, m);
-                    }
                     body = new OIMO.Body({
                         type: 'box',
                         size: [sizeX, sizeY, sizeZ],
@@ -17161,16 +17149,21 @@ var BABYLON;
                         config: [options.mass, options.friction, options.restitution],
                         world: this._world
                     });
-                    if (initialRotation) {
-                        body.setQuaternion(initialRotation);
-                    }
-                    this._registeredMeshes.push({
-                        mesh: mesh,
-                        body: body,
-                        delta: deltaPosition
-                    });
                     break;
             }
+            //If quaternion was set as the rotation of the object
+            if (initialRotation) {
+                //We have to access the rigid body's properties to set the quaternion. 
+                //The setQuaternion function of Oimo only sets the newOrientation that is only set after an impulse is given or a collision.
+                body.body.orientation = new OIMO.Quat(initialRotation.w, initialRotation.x, initialRotation.y, initialRotation.z);
+                //update the internal rotation matrix
+                body.body.syncShapes();
+            }
+            this._registeredMeshes.push({
+                mesh: mesh,
+                body: body,
+                delta: deltaPosition
+            });
             return body;
         };
         OimoJSPlugin.prototype.registerMeshesAsCompound = function (parts, options) {
@@ -17361,7 +17354,7 @@ var BABYLON;
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                         }
-                        mesh.rotationQuaternion.fromRotationMatrix(mtx);
+                        BABYLON.Quaternion.FromRotationMatrixToRef(mtx, mesh.rotationQuaternion);
                         mesh.computeWorldMatrix();
                     }
                 }
@@ -20914,7 +20907,7 @@ var BABYLON;
             return VertexData._ExtractFrom(geometry);
         };
         VertexData._ExtractFrom = function (meshOrGeometry) {
-            var result = new BABYLON.VertexData();
+            var result = new VertexData();
             if (meshOrGeometry.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
                 result.positions = meshOrGeometry.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             }
@@ -20939,6 +20932,137 @@ var BABYLON;
             result.indices = meshOrGeometry.getIndices();
             return result;
         };
+        VertexData.CreateRibbon = function (pathArray, closeArray, closePath, offset) {
+            closeArray = closeArray || false;
+            closePath = closePath || false;
+            var defaultOffset = Math.floor(pathArray[0].length / 2);
+            offset = offset || defaultOffset;
+            offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
+            var positions = [];
+            var indices = [];
+            var normals = [];
+            var uvs = [];
+            var us = []; // us[path_id] = [uDist1, uDist2, uDist3 ... ] distances between points on path path_id
+            var vs = []; // vs[i] = [vDist1, vDist2, vDist3, ... ] distances between points i of consecutives paths from pathArray
+            var uTotalDistance = []; // uTotalDistance[p] : total distance of path p
+            var vTotalDistance = []; //  vTotalDistance[i] : total distance between points i of first and last path from pathArray
+            var minlg; // minimal length among all paths from pathArray
+            var lg = []; // array of path lengths : nb of vertex per path
+            var idx = []; // array of path indexes : index of each path (first vertex) in positions array
+            // if single path in pathArray
+            if (pathArray.length < 2) {
+                var ar1 = [];
+                var ar2 = [];
+                for (var i = 0; i < pathArray[0].length - offset; i++) {
+                    ar1.push(pathArray[0][i]);
+                    ar2.push(pathArray[0][i + offset]);
+                }
+                pathArray = [ar1, ar2];
+            }
+            // positions and horizontal distances (u)
+            var idc = 0;
+            minlg = pathArray[0].length;
+            for (p = 0; p < pathArray.length; p++) {
+                uTotalDistance[p] = 0;
+                us[p] = [0];
+                var path = pathArray[p];
+                var l = path.length;
+                minlg = (minlg < l) ? minlg : l;
+                lg[p] = l;
+                idx[p] = idc;
+                var j = 0;
+                while (j < l) {
+                    positions.push(path[j].x, path[j].y, path[j].z);
+                    if (j > 0) {
+                        var vectlg = path[j].subtract(path[j - 1]).length();
+                        var dist = vectlg + uTotalDistance[p];
+                        us[p].push(dist);
+                        uTotalDistance[p] = dist;
+                    }
+                    j++;
+                }
+                if (closePath) {
+                    vectlg = path[0].subtract(path[j - 1]).length();
+                    dist = vectlg + uTotalDistance[p];
+                    uTotalDistance[p] = dist;
+                }
+                idc += l;
+            }
+            for (i = 0; i < minlg; i++) {
+                vTotalDistance[i] = 0;
+                vs[i] = [0];
+                for (p = 0; p < pathArray.length - 1; p++) {
+                    var path1 = pathArray[p];
+                    var path2 = pathArray[p + 1];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+                    vs[i].push(dist);
+                    vTotalDistance[i] = dist;
+                }
+                if (closeArray) {
+                    path1 = pathArray[p];
+                    path2 = pathArray[0];
+                    vectlg = path2[i].subtract(path1[i]).length();
+                    dist = vectlg + vTotalDistance[i];
+                    vTotalDistance[i] = dist;
+                }
+            }
+            for (p = 0; p < pathArray.length; p++) {
+                for (i = 0; i < minlg; i++) {
+                    var u = us[p][i] / uTotalDistance[p];
+                    var v = vs[i][p] / vTotalDistance[i];
+                    uvs.push(u, v);
+                }
+            }
+            // indices
+            var p = 0; // path index
+            var i = 0; // positions array index
+            var l1 = lg[p] - 1; // path1 length
+            var l2 = lg[p + 1] - 1; // path2 length
+            var min = (l1 < l2) ? l1 : l2; // current path stop index
+            var shft = idx[1] - idx[0]; // shift 
+            var path1nb = closeArray ? lg.length : lg.length - 1; // number of path1 to iterate	
+            while (i <= min && p < path1nb) {
+                // draw two triangles between path1 (p1) and path2 (p2) : (p1.i, p2.i, p1.i+1) and (p2.i+1, p1.i+1, p2.i) clockwise
+                var t1 = i;
+                var t2 = i + shft;
+                var t3 = i + 1;
+                var t4 = i + shft + 1;
+                indices.push(i, i + shft, i + 1);
+                indices.push(i + shft + 1, i + 1, i + shft);
+                i += 1;
+                if (i === min) {
+                    if (closePath) {
+                        indices.push(i, i + shft, idx[p]);
+                        indices.push(idx[p] + shft, idx[p], i + shft);
+                        t3 = idx[p];
+                        t4 = idx[p] + shft;
+                    }
+                    p++;
+                    if (p === lg.length - 1) {
+                        shft = idx[0] - idx[p];
+                        l1 = lg[p] - 1;
+                        l2 = lg[0] - 1;
+                    }
+                    else {
+                        shft = idx[p + 1] - idx[p];
+                        l1 = lg[p] - 1;
+                        l2 = lg[p + 1] - 1;
+                    }
+                    i = idx[p];
+                    min = (l1 < l2) ? l1 + i : l2 + i;
+                }
+            }
+            // normals
+            VertexData.ComputeNormals(positions, indices, normals);
+            // Result
+            var vertexData = new VertexData();
+            vertexData.indices = indices;
+            vertexData.positions = positions;
+            vertexData.normals = normals;
+            vertexData.uvs = uvs;
+            return vertexData;
+        };
         VertexData.CreateBox = function (size) {
             var normalsSource = [
                 new BABYLON.Vector3(0, 0, 1),
@@ -20985,7 +21109,7 @@ var BABYLON;
                 uvs.push(1.0, 0.0);
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21031,7 +21155,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21060,7 +21184,7 @@ var BABYLON;
             };
             var createCylinderCap = function (isTop) {
                 var radius = isTop ? radiusTop : radiusBottom;
-                if (radius == 0) {
+                if (radius === 0) {
                     return;
                 }
                 var vbase = positions.length / 3;
@@ -21070,14 +21194,14 @@ var BABYLON;
                     offset.scaleInPlace(-1);
                     textureScale.x = -textureScale.x;
                 }
-                for (i = 0; i < tessellation; i++) {
+                for (var i = 0; i < tessellation; i++) {
                     var circleVector = getCircleVector(i);
                     var position = circleVector.scale(radius).add(offset);
                     var textureCoordinate = new BABYLON.Vector2(circleVector.x * textureScale.x + 0.5, circleVector.z * textureScale.y + 0.5);
                     positions.push(position.x, position.y, position.z);
                     uvs.push(textureCoordinate.x, textureCoordinate.y);
                 }
-                for (var i = 0; i < tessellation - 2; i++) {
+                for (i = 0; i < tessellation - 2; i++) {
                     if (!isTop) {
                         indices.push(vbase);
                         indices.push(vbase + (i + 2) % tessellation);
@@ -21109,8 +21233,8 @@ var BABYLON;
                 }
             }
             subdivisions += 1;
-            for (var s = 0; s < subdivisions - 1; s++) {
-                for (var i = 0; i <= tessellation; i++) {
+            for (s = 0; s < subdivisions - 1; s++) {
+                for (i = 0; i <= tessellation; i++) {
                     indices.push(i * subdivisions + s);
                     indices.push((i * subdivisions + (s + subdivisions)) % (stride * subdivisions));
                     indices.push(i * subdivisions + (s + 1));
@@ -21123,9 +21247,9 @@ var BABYLON;
             createCylinderCap(true);
             createCylinderCap(false);
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21171,7 +21295,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21189,7 +21313,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             return vertexData;
@@ -21223,7 +21347,7 @@ var BABYLON;
                 }
             }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21246,11 +21370,6 @@ var BABYLON;
                 'w': (xmax - xmin) / subdivisions.w,
                 'h': (zmax - zmin) / subdivisions.h
             };
-            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
-                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
-                    applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
-                }
-            }
             function applyTile(xTileMin, zTileMin, xTileMax, zTileMax) {
                 // Indices
                 var base = positions.length / 3;
@@ -21285,8 +21404,13 @@ var BABYLON;
                     }
                 }
             }
+            for (tileRow = 0; tileRow < subdivisions.h; tileRow++) {
+                for (tileCol = 0; tileCol < subdivisions.w; tileCol++) {
+                    applyTile(xmin + tileCol * tileSize.w, zmin + tileRow * tileSize.h, xmin + (tileCol + 1) * tileSize.w, zmin + (tileRow + 1) * tileSize.h);
+                }
+            }
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21328,9 +21452,9 @@ var BABYLON;
                 }
             }
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21365,7 +21489,7 @@ var BABYLON;
             indices.push(2);
             indices.push(3);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -21434,9 +21558,9 @@ var BABYLON;
                 }
             }
             // Normals
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+            VertexData.ComputeNormals(positions, indices, normals);
             // Result
-            var vertexData = new BABYLON.VertexData();
+            var vertexData = new VertexData();
             vertexData.indices = indices;
             vertexData.positions = positions;
             vertexData.normals = normals;
@@ -26054,6 +26178,7 @@ var BABYLON;
     var DebugLayer = (function () {
         function DebugLayer(scene) {
             var _this = this;
+            this._transformationMatrix = BABYLON.Matrix.Identity();
             this._enabled = false;
             this._labelsEnabled = false;
             this._displayStatistics = true;
@@ -26133,16 +26258,17 @@ var BABYLON;
                     }
                 }
                 if (_this._labelsEnabled || !_this._showUI) {
+                    _this._camera.getViewMatrix().multiplyToRef(_this._camera.getProjectionMatrix(), _this._transformationMatrix);
                     _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
                     var engine = _this._scene.getEngine();
-                    var viewport = _this._scene.activeCamera.viewport;
+                    var viewport = _this._camera.viewport;
                     var globalViewport = viewport.toGlobal(engine);
                     // Meshes
                     var meshes = _this._scene.getActiveMeshes();
                     for (var index = 0; index < meshes.length; index++) {
                         var mesh = meshes.data[index];
                         var position = mesh.getBoundingInfo().boundingSphere.center;
-                        var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
+                        var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._transformationMatrix, globalViewport);
                         if (mesh.renderOverlay || _this.shouldDisplayAxis && _this.shouldDisplayAxis(mesh)) {
                             _this._renderAxis(projectedPosition, mesh, globalViewport);
                         }
@@ -26158,15 +26284,15 @@ var BABYLON;
                     var cameras = _this._scene.cameras;
                     for (index = 0; index < cameras.length; index++) {
                         var camera = cameras[index];
-                        if (camera === _this._scene.activeCamera) {
+                        if (camera === _this._camera) {
                             continue;
                         }
-                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
+                        projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._transformationMatrix, globalViewport);
                         if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(camera)) {
                             _this._renderLabel(camera.name, projectedPosition, 12, function () {
-                                _this._scene.activeCamera.detachControl(engine.getRenderingCanvas());
-                                _this._scene.activeCamera = camera;
-                                _this._scene.activeCamera.attachControl(engine.getRenderingCanvas());
+                                _this._camera.detachControl(engine.getRenderingCanvas());
+                                _this._camera = camera;
+                                _this._camera.attachControl(engine.getRenderingCanvas());
                             }, function () {
                                 return "purple";
                             });
@@ -26177,7 +26303,7 @@ var BABYLON;
                     for (index = 0; index < lights.length; index++) {
                         var light = lights[index];
                         if (light.position) {
-                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
+                            projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._transformationMatrix, globalViewport);
                             if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
                                 _this._renderLabel(light.name, projectedPosition, -20, function () {
                                     light.setEnabled(!light.isEnabled());
@@ -26227,16 +26353,16 @@ var BABYLON;
         DebugLayer.prototype._renderAxis = function (projectedPosition, mesh, globalViewport) {
             var position = mesh.getBoundingInfo().boundingSphere.center;
             var worldMatrix = mesh.getWorldMatrix();
-            var unprojectedVector = BABYLON.Vector3.UnprojectFromTransform(projectedPosition.add(new BABYLON.Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._scene.getTransformMatrix());
+            var unprojectedVector = BABYLON.Vector3.UnprojectFromTransform(projectedPosition.add(new BABYLON.Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._transformationMatrix);
             var unit = (unprojectedVector.subtract(position)).length();
-            var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, xAxis, xAxisText, "x", "#FF0000");
-            var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._transformationMatrix, globalViewport);
+            var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, yAxis, yAxisText, "y", "#00FF00");
-            var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
-            var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
+            var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._transformationMatrix, globalViewport);
+            var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._transformationMatrix, globalViewport);
             this._renderSingleAxis(projectedPosition, zAxis, zAxisText, "z", "#0000FF");
         };
         DebugLayer.prototype._renderLabel = function (text, projectedPosition, labelOffset, onClick, getFillStyle) {
@@ -26245,7 +26371,8 @@ var BABYLON;
                 var textMetrics = this._drawingContext.measureText(text);
                 var centerX = projectedPosition.x - textMetrics.width / 2;
                 var centerY = projectedPosition.y;
-                if (this._isClickInsideRect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
+                var clientRect = this._drawingCanvas.getBoundingClientRect();
+                if (this._isClickInsideRect(clientRect.left * this._ratio + centerX - 5, clientRect.top * this._ratio + centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
                     onClick();
                 }
                 this._drawingContext.beginPath();
@@ -26308,11 +26435,18 @@ var BABYLON;
             this._scene.renderTargetsEnabled = true;
             engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
         };
-        DebugLayer.prototype.show = function (showUI) {
+        DebugLayer.prototype.show = function (showUI, camera) {
             if (showUI === void 0) { showUI = true; }
+            if (camera === void 0) { camera = null; }
             if (this._enabled) {
                 return;
             }
+            if (camera) {
+                this._camera = camera;
+            }
+            else {
+                this._camera = this._scene.activeCamera;
+            }
             this._enabled = true;
             this._showUI = showUI;
             var engine = this._scene.getEngine();

Dosya farkı çok büyük olduğundan ihmal edildi
+ 11 - 11
babylon.2.1-alpha.js