Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transform direction from local to world space in three.js

You can transform a local position vector to world space using myObject.localToWorld(vector) and back to local with myObject.worldToLocal(vector)

Is there a similar convenient way to transform direction vectors between world and local space?

in Unity this would be myObject.TransformDirection and myObject.InverseTransformDirection

like image 782
Mr Bell Avatar asked Dec 14 '16 21:12

Mr Bell


1 Answers

You can transform a Vector3, representing a direction vector, from an object's local space to world space like so:

vector.transformDirection( object.matrixWorld );

Friendly tip: direction vectors in three.js are assumed to be normalized; that is, have length equal to 1. It is a good idea to adhere to that convention.

three.js r.82

like image 162
WestLangley Avatar answered Oct 16 '22 06:10

WestLangley