Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

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

+ 2 - 0
dist/preview release/what's new.md

@@ -35,6 +35,7 @@
   - Added an option `useClonedMeshhMap` in the `Scene` constructor options. When set to true, each `Mesh` will have and will keep up-to-date a map of cloned meshes. This is to avoid browsing all the meshes of the scene to retrieve the ones that have the current mesh as source mesh. Disabled by default
   - Added `blockfreeActiveMeshesAndRenderingGroups` property in the `Scene`, following the same model as `blockMaterialDirtyMechanism`. This is to avoid calling `Scene.freeActiveMeshes` and `Scene.freeRenderingGroups` for each disposed mesh when we dispose several meshes in a row. One have to set `blockfreeActiveMeshesAndRenderingGroups` to `true` just before disposing the meshes, and set it back to `false` just after
   - Prevented code from doing useless and possible time consuming computation when disposing the `ShaderMaterial` of a `LinesMesh`
+  - Make a better use of the `isIdentity` cached value wihtin a `Matrix`
 - Align `BoundingBox` and `BoundingSphere` API and behavior for clarity and simplicity. As a consequence, the `BoundingBox`'s method `setWorldMatrix` has been removed and the underlying world matrix cannot be modified but by calling `reConstruct` or `update`. ([barroij](https://github.com/barroij))
 
 ### glTF Loader
@@ -67,3 +68,4 @@
 - `Database.openAsync` was renamed by `Database.open` ([Deltakosh](https://github.com/deltakosh))
 - `scene.database` was renamed to `scene.offlineProvider` ([Deltakosh](https://github.com/deltakosh))
 - `BoundingBox.setWorldMatrix` was removed. `BoundingBox.getWorldMatrix` now returns a `Readonly<Matrix>` ([barroij](https://github.com/barroij))
+- `Matrix`'s accessor `m` and method `toArray` and `asArray` now returns a `Readonly<Float32Array>` as the matrix underlying array is not supposed to be modified manually from the outside of the class ([barroij](https://github.com/barroij))

+ 6 - 4
postProcessLibrary/src/digitalRain/babylon.digitalRainPostProcess.ts

@@ -247,10 +247,12 @@ module BABYLON {
 
             var alpha = 0.0;
             var cosTimeZeroOne = 0.0;
-            var matrix = new Matrix();
-            for (let i = 0; i < 16; i++) {
-                matrix.m[i] = Math.random();
-            }
+            var matrix = Matrix.FromValues(
+                Math.random(), Math.random(), Math.random(), Math.random(),
+                Math.random(), Math.random(), Math.random(), Math.random(),
+                Math.random(), Math.random(), Math.random(), Math.random(),
+                Math.random(), Math.random(), Math.random(), Math.random()
+            );
 
             this.onApply = (effect: Effect) => {
                 effect.setTexture("digitalRainFont", this._digitalRainFontTexture);

+ 21 - 37
src/Bones/babylon.bone.ts

@@ -413,9 +413,9 @@ module BABYLON {
             var lm = this.getLocalMatrix();
 
             if (space == Space.LOCAL) {
-                lm.m[12] += vec.x;
-                lm.m[13] += vec.y;
-                lm.m[14] += vec.z;
+                lm.addAtIndex(12, vec.x);
+                lm.addAtIndex(13, vec.y);
+                lm.addAtIndex(14, vec.z);
             } else {
                 var wm: Nullable<Matrix> = null;
 
@@ -437,17 +437,13 @@ module BABYLON {
                     }
                 }
 
-                tmat.m[12] = 0;
-                tmat.m[13] = 0;
-                tmat.m[14] = 0;
-
+                tmat.setTranslationFromFloats(0, 0, 0);
                 tmat.invert();
                 Vector3.TransformCoordinatesToRef(vec, tmat, tvec);
 
-                lm.m[12] += tvec.x;
-                lm.m[13] += tvec.y;
-                lm.m[14] += tvec.z;
-
+                lm.addAtIndex(12, tvec.x);
+                lm.addAtIndex(13, tvec.y);
+                lm.addAtIndex(14, tvec.z);
             }
 
             this._markAsDirtyAndDecompose();
@@ -463,9 +459,7 @@ module BABYLON {
             var lm = this.getLocalMatrix();
 
             if (space == Space.LOCAL) {
-                lm.m[12] = position.x;
-                lm.m[13] = position.y;
-                lm.m[14] = position.z;
+                lm.setTranslationFromFloats(position.x, position.y, position.z);
             } else {
                 var wm: Nullable<Matrix> = null;
 
@@ -490,11 +484,7 @@ module BABYLON {
 
                 tmat.invert();
                 Vector3.TransformCoordinatesToRef(position, tmat, vec);
-
-                lm.m[12] = vec.x;
-                lm.m[13] = vec.y;
-                lm.m[14] = vec.z;
-
+                lm.setTranslationFromFloats(vec.x, vec.y, vec.z);
             }
 
             this._markAsDirtyAndDecompose();
@@ -530,9 +520,9 @@ module BABYLON {
             for (var child of this.children) {
                 var cm = child.getLocalMatrix();
                 cm.multiplyToRef(scaleMat, cm);
-                cm.m[12] *= x;
-                cm.m[13] *= y;
-                cm.m[14] *= z;
+                cm.multiplyAtIndex(12, x);
+                cm.multiplyAtIndex(13, y);
+                cm.multiplyAtIndex(14, z);
 
                 child._markAsDirtyAndDecompose();
             }
@@ -612,12 +602,8 @@ module BABYLON {
          */
         public rotate(axis: Vector3, amount: number, space = Space.LOCAL, mesh?: AbstractMesh): void {
             var rmat = Bone._tmpMats[0];
-            rmat.m[12] = 0;
-            rmat.m[13] = 0;
-            rmat.m[14] = 0;
-
+            rmat.setTranslationFromFloats(0, 0, 0);
             Matrix.RotationAxisToRef(axis, amount, rmat);
-
             this._rotateWithMatrix(rmat, space, mesh);
         }
 
@@ -751,9 +737,7 @@ module BABYLON {
                 }
             }
 
-            lmat.m[12] = lx;
-            lmat.m[13] = ly;
-            lmat.m[14] = lz;
+            lmat.setTranslationFromFloats(lx, ly, lz);
 
             this.computeAbsoluteTransforms();
             this._markAsDirtyAndDecompose();
@@ -775,7 +759,7 @@ module BABYLON {
                 return false;
             }
 
-            scaleMatrix.m[0] *= this._scalingDeterminant;
+            scaleMatrix.multiplyAtIndex(0, this._scalingDeterminant);
             rotMatInv.multiplyToRef(scaleMatrix, rotMatInv);
 
             return true;
@@ -986,9 +970,9 @@ module BABYLON {
                     mat.copyFrom(amat);
                 }
 
-                mat.m[0] *= this._scalingDeterminant;
-                mat.m[1] *= this._scalingDeterminant;
-                mat.m[2] *= this._scalingDeterminant;
+                mat.multiplyAtIndex(0, this._scalingDeterminant);
+                mat.multiplyAtIndex(1, this._scalingDeterminant);
+                mat.multiplyAtIndex(2, this._scalingDeterminant);
 
                 mat.decompose(undefined, result, undefined);
             }
@@ -1028,9 +1012,9 @@ module BABYLON {
                     mat.copyFrom(amat);
                 }
 
-                mat.m[0] *= this._scalingDeterminant;
-                mat.m[1] *= this._scalingDeterminant;
-                mat.m[2] *= this._scalingDeterminant;
+                mat.multiplyAtIndex(0, this._scalingDeterminant);
+                mat.multiplyAtIndex(1, this._scalingDeterminant);
+                mat.multiplyAtIndex(2, this._scalingDeterminant);
 
                 mat.getRotationMatrixToRef(result);
             }

+ 9 - 15
src/Cameras/VR/babylon.webVRCamera.ts

@@ -256,7 +256,7 @@ module BABYLON {
             });
 
             if (typeof (VRFrameData) !== "undefined") {
-                this._frameData = new VRFrameData();
+                this._frameData = new VRFrameData();
             }
 
             /**
@@ -320,11 +320,9 @@ module BABYLON {
                     this._standingMatrix = new Matrix();
                     Matrix.FromFloat32ArrayToRefScaled(result.vrDisplay.stageParameters.sittingToStandingTransform, 0, 1, this._standingMatrix);
                     if (!this.getScene().useRightHandedSystem) {
-                        [2, 6, 8, 9, 14].forEach((num) => {
-                            if (this._standingMatrix) {
-                                this._standingMatrix.m[num] *= -1;
-                            }
-                        });
+                        if (this._standingMatrix) {
+                            this._standingMatrix.toggleModelMatrixHandInPlace();
+                        }
                     }
                     callback(true);
                 }
@@ -634,9 +632,7 @@ module BABYLON {
             Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);
 
             if (!this.getScene().useRightHandedSystem) {
-                [2, 6, 8, 9, 14].forEach((num) => {
-                    this._webvrViewMatrix.m[num] *= -1;
-                });
+                this._webvrViewMatrix.toggleModelMatrixHandInPlace();
             }
 
             // update the camera rotation matrix
@@ -651,9 +647,9 @@ module BABYLON {
                 this._webvrViewMatrix.invert();
                 // scale the position, if set
                 if (parentCamera.deviceScaleFactor) {
-                    this._webvrViewMatrix.m[12] *= parentCamera.deviceScaleFactor;
-                    this._webvrViewMatrix.m[13] *= parentCamera.deviceScaleFactor;
-                    this._webvrViewMatrix.m[14] *= parentCamera.deviceScaleFactor;
+                    this._webvrViewMatrix.multiplyAtIndex(12, parentCamera.deviceScaleFactor);
+                    this._webvrViewMatrix.multiplyAtIndex(13, parentCamera.deviceScaleFactor);
+                    this._webvrViewMatrix.multiplyAtIndex(14, parentCamera.deviceScaleFactor);
                 }
 
                 this._webvrViewMatrix.invert();
@@ -686,9 +682,7 @@ module BABYLON {
 
             //babylon compatible matrix
             if (!this.getScene().useRightHandedSystem) {
-                [8, 9, 10, 11].forEach((num) => {
-                    this._projectionMatrix.m[num] *= -1;
-                });
+                this._projectionMatrix.toggleProjectionMatrixHandInPlace();
             }
 
             return this._projectionMatrix;

+ 4 - 4
src/Cameras/babylon.arcRotateCamera.ts

@@ -927,8 +927,8 @@ module BABYLON {
 
                 this._computeViewMatrix(this.position, target, up);
 
-                this._viewMatrix.m[12] += this.targetScreenOffset.x;
-                this._viewMatrix.m[13] += this.targetScreenOffset.y;
+                this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);
+                this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);
             }
             this._currentTarget = target;
             return this._viewMatrix;
@@ -972,8 +972,8 @@ module BABYLON {
             }
 
             this._computeViewMatrix(this.position, target, up);
-            this._viewMatrix.m[12] += this.targetScreenOffset.x;
-            this._viewMatrix.m[13] += this.targetScreenOffset.y;
+            this._viewMatrix.addAtIndex(12, this.targetScreenOffset.x);
+            this._viewMatrix.addAtIndex(13, this.targetScreenOffset.y);
 
             this._collisionTriggered = false;
         }

+ 1 - 3
src/Debug/babylon.skeletonViewer.ts

@@ -65,9 +65,7 @@ module BABYLON.Debug {
             if (x !== 0 || y !== 0 || z !== 0) {
                 var tmat2 = Tmp.Matrix[1];
                 BABYLON.Matrix.IdentityToRef(tmat2);
-                tmat2.m[12] = x;
-                tmat2.m[13] = y;
-                tmat2.m[14] = z;
+                tmat2.setTranslationFromFloats(x, y, z);
                 tmat2.multiplyToRef(tmat, tmat);
             }
 

+ 14 - 13
src/Materials/Textures/babylon.texture.ts

@@ -430,10 +430,13 @@ module BABYLON {
             this._t1.subtractInPlace(this._t0);
             this._t2.subtractInPlace(this._t0);
 
-            Matrix.IdentityToRef(this._cachedTextureMatrix);
-            this._cachedTextureMatrix.m[0] = this._t1.x; this._cachedTextureMatrix.m[1] = this._t1.y; this._cachedTextureMatrix.m[2] = this._t1.z;
-            this._cachedTextureMatrix.m[4] = this._t2.x; this._cachedTextureMatrix.m[5] = this._t2.y; this._cachedTextureMatrix.m[6] = this._t2.z;
-            this._cachedTextureMatrix.m[8] = this._t0.x; this._cachedTextureMatrix.m[9] = this._t0.y; this._cachedTextureMatrix.m[10] = this._t0.z;
+            Matrix.FromValuesToRef(
+                this._t1.x, this._t1.y, this._t1.z, 0.0,
+                this._t2.x, this._t2.y, this._t2.z, 0.0,
+                this._t0.x, this._t0.y, this._t0.z, 0.0,
+                       0.0,        0.0,        0.0, 1.0,
+                this._cachedTextureMatrix
+            );
 
             let scene = this.getScene();
 
@@ -497,15 +500,13 @@ module BABYLON {
                     (<any>this._cachedTextureMatrix)[13] = this.vOffset;
                     break;
                 case Texture.PROJECTION_MODE:
-                    Matrix.IdentityToRef(this._projectionModeMatrix);
-
-                    this._projectionModeMatrix.m[0] = 0.5;
-                    this._projectionModeMatrix.m[5] = -0.5;
-                    this._projectionModeMatrix.m[10] = 0.0;
-                    this._projectionModeMatrix.m[12] = 0.5;
-                    this._projectionModeMatrix.m[13] = 0.5;
-                    this._projectionModeMatrix.m[14] = 1.0;
-                    this._projectionModeMatrix.m[15] = 1.0;
+                    Matrix.FromValuesToRef(
+                        0.5,  0.0, 0.0, 0.0,
+                        0.0, -0.5, 0.0, 0.0,
+                        0.0,  0.0, 0.0, 0.0,
+                        0.5,  0.5, 1.0, 1.0,
+                        this._projectionModeMatrix
+                    );
 
                     let projectionMatrix = scene.getProjectionMatrix();
                     this._cachedProjectionMatrixId = projectionMatrix.updateFlag;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 541 - 598
src/Math/babylon.math.ts