Explorar o código

fixed setParent

David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
0929adaf4c

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2503 - 2502
dist/preview release/babylon.d.ts


+ 11 - 17
src/Mesh/babylon.transformNode.ts

@@ -438,10 +438,12 @@ module BABYLON {
 
         /**
          * Defines the passed node as the parent of the current node.  
+         * The node will remain exactly where it is and its position / rotation will be updated accordingly
          * Returns the TransformNode.
          */
         public setParent(node: Nullable<TransformNode>): TransformNode {
 
+            this.computeWorldMatrix(true);
             if (node == null) {
                 var rotation = Tmp.Quaternion[0];
                 var position = Tmp.Vector3[0];
@@ -450,7 +452,6 @@ module BABYLON {
                 if (this.parent && (<TransformNode>this.parent).computeWorldMatrix) {
                     (<TransformNode>this.parent).computeWorldMatrix(true);
                 }
-                this.computeWorldMatrix(true);
                 this.getWorldMatrix().decompose(scale, rotation, position);
 
                 if (this.rotationQuaternion) {
@@ -466,20 +467,13 @@ module BABYLON {
                 var rotation = Tmp.Quaternion[0];
                 var position = Tmp.Vector3[0];
                 var scale = Tmp.Vector3[1];
-                var m0 = Tmp.Matrix[0];
-                var m1 = Tmp.Matrix[1];
-                var invParentMatrix = Tmp.Matrix[2];
+                var diffMatrix = Tmp.Matrix[0];
+                var invParentMatrix = Tmp.Matrix[1];
 
                 node.computeWorldMatrix(true);
-                node.getWorldMatrix().decompose(scale, rotation, position);
-
-                rotation.toRotationMatrix(m0);
-                m1.setTranslation(position);
-                m1.multiplyToRef(m0, m0);
-                m0.invertToRef(invParentMatrix);
-
-                this.getWorldMatrix().multiplyToRef(invParentMatrix, m0);
-                m0.decompose(scale, rotation, position);
+                node.getWorldMatrix().invertToRef(invParentMatrix);
+                this.getWorldMatrix().multiplyToRef(invParentMatrix, diffMatrix);
+                diffMatrix.decompose(scale, rotation, position);
 
                 if (this.rotationQuaternion) {
                     this.rotationQuaternion.copyFrom(rotation);
@@ -487,13 +481,13 @@ module BABYLON {
                     rotation.toEulerAnglesToRef(this.rotation);
                 }
 
-                node.getWorldMatrix().invertToRef(invParentMatrix);
-                this.getWorldMatrix().multiplyToRef(invParentMatrix, m0);
-                m0.decompose(scale, rotation, position);
-
                 this.position.x = position.x;
                 this.position.y = position.y;
                 this.position.z = position.z;
+
+                this.scaling.x = scale.x;
+                this.scaling.y = scale.y;
+                this.scaling.z = scale.z;
             }
 
             this.parent = node;

BIN=BIN
tests/validation/ReferenceImages/Billboard.png


+ 13 - 1
tests/validation/config.json

@@ -285,12 +285,24 @@
       "referenceImage": "DefaultRenderingPipeline.png"
     },
     {
+      "title": "Billboard",
+      "renderCount": 20,
+      "playgroundId": "#UJEIL#13",
+      "referenceImage": "Billboard.png"
+    },
+    {
+      "title": "setParent",
+      "renderCount": 20,
+      "playgroundId": "#JD49CT#2",
+      "referenceImage": "setParent.png"
+    },
+    {
       "title": "GUI",
       "renderCount": 20,
       "scriptToRun": "/Demos/GUI/gui.js",
       "functionToCall": "createScene",
       "referenceImage": "GUI.png"
-    },    
+    },
     {
       "title": "Water material (only visual check)",
       "renderCount": 10,