Mr Bell
Mr Bell

Reputation: 9364

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

Upvotes: 5

Views: 4889

Answers (1)

WestLangley
WestLangley

Reputation: 104783

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

Upvotes: 8

Related Questions