How to rotate instanced mesh along specific direction in world space?

Hi!

I’m trying to solve more Math issue with matricies and don’t know how to do it in threejs to make rotation in world space of some object along specific direction (see attached image) when object not parallel to any of axis? Because of an instanced mesh It is really pain in the ass to do all that math calculations with matricies… I need rotate some of instanced mesh object that already positioned and rotated in world space along its specific direction that not parallel to any of world axis and represented by object rotation angle in space…lets say I need turn object left or right around self origin at given position with respect to its rotation !
Thanks in advance!

It seems you want to apply a rotation expressed in the axis-angle form. The axis is a unit vector which representing the direction and an angle representing the magnitude of the rotation around that axis.

In three.js you can do this by calling Object3D.setRotationFromAxisAngle().

I’ve tryed to figure out how to use this but result was always not that I want… object is instanced, added to scene (world axis) and got world position,rotation settings from one of the bone that already some how rotated and can has parent that can be rotated too…so I’ve got end world position and rotation for that instanced object that is away from origin of world axis and should be rotated in its “local space” to left/right… the only wierd solution I’ve found for now looks not nice for me… that is create dummy Object3D that got same position and rotation of that instanced object and add it to scene, then create another dummy Object3D that is added to this dummy object, rotate it (for example, rotate y by +10deg) in his local axis and then decompose position and rotation from worldMatrix after update… I wonder Is there any simple and more efficient with respect to performance solution for this? I don’t know how to perform rotation in this case using quaternions only… but when I’m played with rotation of instanced mesh in stats form manually…I’ve found that I can resolve what I want by rotating x and z (only by using visual control), when changed y by 10deg, for example. But I can’t figure out by what formulas x & z should be changed with respect of changing y by known amount (from visual control it is not obvious) to get same effect I’ve described above in wierd solution of this.

I’ve corrected my previous image to get more clearly understanding what I want (rotate by Z only)