#negate position and rotation of an object using a group

2 messages · Page 1 of 1 (latest)

tropic sand
#

i have an object, that has the position (4,4,4) and the rotation (1,2,1)
i need to negate the position and rotation using a group, so that the object appears to be at (0,0,0) without rotation.
the position and rotation of the original object should not be changed. just the values on the group.

(i need that for an editor, so the original positions of the object must not be modified, this would cause errors in my usecase).

const object = new Mesh();
object.position.set(4,4,4)
object.rotation.set(1,2,1)

const mdlgrp = new THREE.Group();
mdlgrp.add(object);
mdlgrp.position.sub(object.position);
mdlgrp.rotation.sub(object.rotation)

i cannot do that, because after adding the element to the group, it still would have its position relative to the group center. so i need a different way to rotate the it. i guess that involves some weird math stuff, using matrices or so, but thats ahead of me.
can anybody help?

thanks in advance!

tropic sand
#

nevermind, i think, i sovled it:

    model.updateWorldMatrix(true);
    const m = new THREE.Matrix4();
    m.copy(model.matrixWorld).invert();
    mdlgrp.add(model);
    mdlgrp.applyMatrix4(m);
    mdlgrp.updateWorldMatrix(true, true);

    this.scene.add(mdlgrp);