How to change the default xyz axes alignment between local space and world space

The document said:
Each mesh in the scene also has its own Local Space.
Meshes are created with their local space origin at the world space origin and with their local space x, y and z axes aligned with the x, y and z axes of the world space.

Is there a way to change the default xyz axes alignment between local space and world space?
I mean, when I create a new mesh, I want to change the mesh Local Space xyz axes rotation some value (such as Math.PI / 4) relative to the world space.

so, I can move the mesh along the Local Space xyz axes, such as:

 // the value 2 is along the `Local Space` X axis (that has rotate Math.PI / 4 to world space X axis).
mesh.position.x += 2;  

playground:

As the box rotates so does its local axes

You can move the mesh relative to the local axes using, mesh.translate, mesh.setPositionWithLocalVector, and mesh.locallyTranslate as described further down on the page you quoted from

@JohnK
Thanks for your quick reply.
I think this is not my requirement.
I have update the question description.

For rotation / move a mesh locally we need 2 things:

  1. transformation center: we can change the transformation center by setPivotPoint
  2. transformation axes: is there a way we can change the axes to not aligned with the x, y and z axes of the world space?

Do you mean set new axes on a mesh independently of the current mesh axes?

Can you give your use case for this?

If you have three axes, axis1, axis2, axis 3 all unit vectors and you want to move (p, q, r) in this frame of reference then

mesh.position = axis1.scale(p).add(axis2.scale(q)).add(axis3.scale(r));

rotation about these axes is possible but a lot trickier to work out.

Do you mean set new axes on a mesh independently of the current mesh axes?
Yes:
I need to move/rotation the mesh along the given axes instead of the default local axes.

Can you give your use case for this?
Yes:
Imagine you have many meshes on a circle, and need to move the mesh along the radius or along the tangent.

My case it’s more complex than this (it’s not on a circle, on Irregular curve load from stl file)
Take one mesh as example:

  • I have the mesh center
  • I have the move values (x,y,z) and rotation values (alpha, beta, gamma)
  • I can compute the move / rotation directions (axis1, axis2, axis3)
  • I need to do the compute many times on give move/rotation data array
    =====
    I think for this issue there are two ways:
  1. Transform the move values (x,y,z) and rotation values to default local axes
  2. use my own move / rotation directions (axis1, axis2, axis3)

#1 is the general way, but I do not know how to compute, is there an example for this.

so, I ask this question for #2 method, you said:
“rotation about these axes is possible but a lot trickier to work out”
may you help to make an example like position transform?

This may help Target Axes Alignment | Babylon.js Documentation

Hello @jtcheng just checking in, was your question answered?

1 Like