浏览代码

billboard hell

David Catuhe 8 年之前
父节点
当前提交
4579d23fdb

文件差异内容过多而无法显示
+ 24 - 24
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 1801 - 1797
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 34 - 34
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 45 - 21
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 1801 - 1797
dist/preview release/babylon.module.d.ts


文件差异内容过多而无法显示
+ 33 - 33
dist/preview release/babylon.noworker.js


+ 10 - 0
src/Math/babylon.math.ts

@@ -2947,6 +2947,16 @@
             return new Vector3(this.m[12], this.m[13], this.m[14]);
         }
         /**
+         * Fill a Vector3 with the extracted translation from the Matrix.  
+         */
+        public getTranslationToRef(result:Vector3): Matrix {
+            result.x = this.m[12];
+            result.y = this.m[13];
+            result.z = this.m[14];
+
+            return this;
+        }
+        /**
          * Remove rotation and scaling part from the Matrix. 
          * Returns the updated Matrix. 
          */

+ 37 - 23
src/Mesh/babylon.abstractMesh.ts

@@ -868,39 +868,54 @@
             this._pivotMatrix.multiplyToRef(Tmp.Matrix[1], Tmp.Matrix[4]);
             Tmp.Matrix[4].multiplyToRef(Tmp.Matrix[0], Tmp.Matrix[5]);
 
+            // Mesh referal
+            var completeMeshReferalMatrix = Tmp.Matrix[6];
+            if (this._meshToBoneReferal && this.parent && this.parent.getWorldMatrix) {
+                this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), completeMeshReferalMatrix);
+            }
+
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
-                Tmp.Matrix[1].copyFrom(this.getScene().activeCamera.getViewMatrix());
-
-                Tmp.Matrix[1].setTranslationFromFloats(0, 0, 0);
-                Tmp.Matrix[1].invertToRef(Tmp.Matrix[0]);
+                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) !== AbstractMesh.BILLBOARDMODE_ALL) {
+                    // Need to decompose each rotation here
+                    var currentPosition = Tmp.Vector3[3];
+
+                    if (this.parent && this.parent.getWorldMatrix) {
+                        if (this._meshToBoneReferal) {
+                            completeMeshReferalMatrix.getTranslationToRef(currentPosition);
+                        } else {
+                            this.parent.getWorldMatrix().getTranslationToRef(currentPosition);
+                        }
+                        currentPosition.addInPlace(this.position);
+                    } else
+                    {
+                        currentPosition.copyFrom(this.position);
+                    }
 
-                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) !== AbstractMesh.BILLBOARDMODE_ALL)
-                {
-                    // Need to extract rotation vectors
-                    var scale = Tmp.Vector3[2];
-                    var rotation = Tmp.Quaternion[0];
-                    var translation = Tmp.Vector3[3];
-                    Tmp.Matrix[0].decompose(scale, rotation, translation);
+                    currentPosition.subtractInPlace(this.getScene().activeCamera.globalPosition);
 
-                    var finalQuaternion = Tmp.Quaternion[1];
-                    finalQuaternion.copyFrom(rotation);
-                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_X) !== AbstractMesh.BILLBOARDMODE_X)
+                    var finalEuler = Tmp.Vector3[4].copyFromFloats(0, 0, 0);
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_X) === AbstractMesh.BILLBOARDMODE_X)
                     {
-                        finalQuaternion.x = 0;
+                        finalEuler.x = Math.atan2(-currentPosition.y, currentPosition.z);
                     }
                     
-                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Y) !== AbstractMesh.BILLBOARDMODE_Y)
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Y) === AbstractMesh.BILLBOARDMODE_Y)
                     {
-                        finalQuaternion.y = 0;
+                        finalEuler.y = Math.atan2(currentPosition.x, currentPosition.z);
                     }
                     
-                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Z) !== AbstractMesh.BILLBOARDMODE_Z)
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Z) === AbstractMesh.BILLBOARDMODE_Z)
                     {
-                        finalQuaternion.z = 0;
+                        finalEuler.z = Math.atan2(currentPosition.y, currentPosition.x);
                     }
  
-                    Matrix.ComposeToRef(scale, finalQuaternion, translation, Tmp.Matrix[0]);
+                    Matrix.RotationYawPitchRollToRef(finalEuler.y, finalEuler.x, finalEuler.z, Tmp.Matrix[0]);
+                } else{
+                    Tmp.Matrix[1].copyFrom(this.getScene().activeCamera.getViewMatrix());
+
+                    Tmp.Matrix[1].setTranslationFromFloats(0, 0, 0);
+                    Tmp.Matrix[1].invertToRef(Tmp.Matrix[0]);
                 }
 
                 Tmp.Matrix[1].copyFrom(Tmp.Matrix[5]);
@@ -916,7 +931,7 @@
 
                 if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE) {
                     if (this._meshToBoneReferal) {
-                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), Tmp.Matrix[5]);
+                        Tmp.Matrix[5].copyFrom(completeMeshReferalMatrix);
                     } else {
                         Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix());
                     }
@@ -925,8 +940,7 @@
                     this._localWorld.multiplyToRef(Tmp.Matrix[5], this._worldMatrix);
                 } else {
                     if (this._meshToBoneReferal) {
-                        this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), Tmp.Matrix[6]);
-                        Tmp.Matrix[6].multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                        this._localWorld.multiplyToRef(completeMeshReferalMatrix, this._worldMatrix);
                     } else {
                         this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
                     }