Sfoglia il codice sorgente

Fixed bugs with parenting and billboards

David Catuhe 9 anni fa
parent
commit
3f365abfbc

File diff suppressed because it is too large
+ 18 - 18
dist/preview release/babylon.core.js


File diff suppressed because it is too large
+ 1020 - 1020
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 27 - 27
dist/preview release/babylon.js


+ 15 - 1
dist/preview release/babylon.max.js

@@ -8889,7 +8889,21 @@ var BABYLON;
             BABYLON.Tmp.Matrix[4].multiplyToRef(BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Matrix[5]);
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
-                var localPosition = this.position.clone();
+                BABYLON.Tmp.Vector3[0].copyFrom(this.position);
+                var localPosition = BABYLON.Tmp.Vector3[0];
+                if (this.parent && this.parent.getWorldMatrix) {
+                    this._markSyncedWithParent();
+                    var parentMatrix;
+                    if (this._meshToBoneReferal) {
+                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), BABYLON.Tmp.Matrix[6]);
+                        parentMatrix = BABYLON.Tmp.Matrix[6];
+                    }
+                    else {
+                        parentMatrix = this.parent.getWorldMatrix();
+                    }
+                    BABYLON.Vector3.TransformCoordinatesToRef(localPosition, parentMatrix, BABYLON.Tmp.Vector3[1]);
+                    localPosition = BABYLON.Tmp.Vector3[1];
+                }
                 var zero = this.getScene().activeCamera.globalPosition.clone();
                 if (this.parent && this.parent.position) {
                     localPosition.addInPlace(this.parent.position);

File diff suppressed because it is too large
+ 27 - 27
dist/preview release/babylon.noworker.js


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

@@ -29,6 +29,7 @@
     - class `SolidParticleSystem` documented
     - class `MeshBuilder` documented
   - **Bug fixes**
+    - Fixed bug with billboards and parenting ([deltakosh](https://github.com/deltakosh))
     - Fixed bug with ArcRotateCamera.setTarget ([deltakosh](https://github.com/deltakosh))
   - **Breaking changes**
     - `VertexData.CreateLines()` removed as `MeshBuilder.CreateLines()` now calls `MeshBuilder.CreateLineSystem()`

+ 15 - 1
src/Mesh/babylon.abstractMesh.js

@@ -568,7 +568,21 @@ var BABYLON;
             BABYLON.Tmp.Matrix[4].multiplyToRef(BABYLON.Tmp.Matrix[0], BABYLON.Tmp.Matrix[5]);
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
-                var localPosition = this.position.clone();
+                BABYLON.Tmp.Vector3[0].copyFrom(this.position);
+                var localPosition = BABYLON.Tmp.Vector3[0];
+                if (this.parent && this.parent.getWorldMatrix) {
+                    this._markSyncedWithParent();
+                    var parentMatrix;
+                    if (this._meshToBoneReferal) {
+                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), BABYLON.Tmp.Matrix[6]);
+                        parentMatrix = BABYLON.Tmp.Matrix[6];
+                    }
+                    else {
+                        parentMatrix = this.parent.getWorldMatrix();
+                    }
+                    BABYLON.Vector3.TransformCoordinatesToRef(localPosition, parentMatrix, BABYLON.Tmp.Vector3[1]);
+                    localPosition = BABYLON.Tmp.Vector3[1];
+                }
                 var zero = this.getScene().activeCamera.globalPosition.clone();
                 if (this.parent && this.parent.position) {
                     localPosition.addInPlace(this.parent.position);

+ 18 - 1
src/Mesh/babylon.abstractMesh.ts

@@ -618,7 +618,24 @@
 
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
-                var localPosition = this.position.clone();
+                Tmp.Vector3[0].copyFrom(this.position);
+                var localPosition = Tmp.Vector3[0];
+
+                if (this.parent && this.parent.getWorldMatrix) {
+                    this._markSyncedWithParent();
+
+                    var parentMatrix: Matrix;
+                    if (this._meshToBoneReferal) {
+                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), Tmp.Matrix[6]);
+                        parentMatrix = Tmp.Matrix[6];
+                    } else {
+                        parentMatrix = this.parent.getWorldMatrix();
+                    }
+
+                    Vector3.TransformCoordinatesToRef(localPosition, parentMatrix, Tmp.Vector3[1]);
+                    localPosition = Tmp.Vector3[1];
+                }
+
                 var zero = this.getScene().activeCamera.globalPosition.clone();
 
                 if (this.parent && (<any>this.parent).position) {