Search the Community
Showing results for tags 'decompse'.
-
Not sure if this is a bug or just my misunderstanding. I am trying to make a mesh parent of another mesh without changing the transforms (position, rotation and scaling) of the child mesh in the world frame of reference Similar to this discussion Keep child's world position when parenting As shown in the above discussion I use the following kind of function to do this function makeParent(child, parent) { var invParentMatrix = Matrix.Invert(parent.getWorldMatrix()); var newMatrix = child.getWorldMatrix().multiply(invParentMatrix); newMatrix.decompose(child.scaling, child.rotationQuaternion, child.position); child.parent = parent; } This works fine as long as the scaling of the parent is the same in x, y and z direction. It breaks down if I change the parent scaling in any one of those direction. Here is a playground example http://www.babylonjs-playground.com/#28IXSE#4 Here we have two meshes - box1 and box2. I am trying to make box1 parent of box2. Clicking the canvas calls a parenting function (similar to the one above) to do so. To try First time, do a Run and then click the canvas. box1 will become parent of box2 and nothing will change on the screen - as expected. Second time uncomment line 19 - this changes the scale of box1 in the z direction. Again click run and then click the canvas. This time box2 is distorted. Sorry for the long post. I have spent hours on this and can't figure out what's wrong