Rotate a Vector3

I have a project where I’m trying to connect to different components of a structure (space station).

Each component has an array of connectors with a position and rotation that should be applied to the connected component.

See the repro.

I think we need to know more precisely what you want to achieve?

Are you able to setup a simpler repro that would demonstrate what you want to do but not succeed? Demonstrates correct behavior with the I connecter attaching to the core, though this does not account for rotating the connecter points. Has a second I connecter attached to the first, though rather than the “pole” coming off of the core doubling in size (which is expected), the “pole” does not change in size.

This gets more confusing since connectors can have any rotation.

Essentially, what I want when the core has connectors 0 and 1 attached with I connectors:

For this, I need to offset the I connector position by the I connecter’s connecter position rotated by the core’s connecter rotation (not to mention rotating the I connecter by both rotations).

Hence, I need to rotate a given position vector (P) by a rotation vector (R). I’m looking to do something like P.rotate(R).

Edit: This Stack Overflow post is very helpful.

I like using a matrix method sometimes too:

const direction = new Vector3(0, 0, 1);
const rotation = Quaternion.FromEulerAngles(0, Math.PI * 0.5, 0);
const rotMat = Matrix.Zero();
const newDirection = Vector3.TransformCoordinates(direction, rotMat);

If you are going to be doing a lot of rotations you dont have to make a new matrix Instance each time, you can cache it on your own script or use one of BJS temporary ones that they have already cached for you.

const newDirection = Vector3.TransformCoordinates(direction, BABYLON.TmpVectors.Matrix);

Interesting… Seems to have the positions somewhat correct, though the rotations are incorrect Almost seems like it is correct though the position is still not rotated (they are all centered at -0.5 z) Swapping stuff did not fix it More swapping still did not fix it

Sounds like you are not getting the correct rotation vector then. You need to basically construct a lookAt rotation vector from the nodes origin to the connectors origin and use that as the rotation value.