2

I need to move a grandchild object to a given target postition and orientation in world space. The grand child (child 2) has to be moved by manipulating the grandparents (root) position and rotation.

If I have a given world matrix of the target, what matrix do I have to apply to the grandparent to make the grandchild match the target?

before transformation before transformation

after transformation, child 2 moved to target after transformation, child 2 moved to target

My question is different since I'm not lopking for a "usable IK System". I just need to compute the matrix of a grandparent. I gained into your answers, but none of them seemd to evaluate the right matrix. In the mean time I figured out a working solution. I'll do some cleanup in my code and post it.

  • I think you're talking about inverse kinematics. This is a difficult question. This question is a duplicate, even though this question is posed in a better, more succinct manner. See [this answer](https://stackoverflow.com/questions/14421031/inverse-kinematic-animation) and also [the git repo mentioned](https://github.com/lo-th/fullik). – Radio Oct 31 '17 at 11:39
  • Possible duplicate of [Inverse kinematic animation](https://stackoverflow.com/questions/14421031/inverse-kinematic-animation) – Radio Oct 31 '17 at 11:41

2 Answers2

0

You want to apply a matrix to the grandparent object so that the world matrix of a grandchild object matches the world matrix of a target object.

To do so, use the following pattern:

var matrix = new THREE.Matrix4(); //create once and reuse

. . .

scene.updateMatrixWorld(); // the renderer does this for you in the render loop

matrix.getInverse( gchild.matrixWorld ).premultiply( target.matrixWorld );

parent.applyMatrix( matrix );

Now that you know the answer, it should be obvious to you why it works.

three.js r.87

WestLangley
  • 102,557
  • 10
  • 276
  • 276
-2

For a point in an object's local coordinate system,

object.localToWorld( point );

will return the world coordinates of the point, assuming the same transform is applied to the point as is applied to the object.

THREE.js: Calculate world space position of a point on an object

Martin
  • 2,575
  • 6
  • 32
  • 53