objectDirection
Provides a normalized vec3 representing the object's forward direction (its local -Z axis) in world space.
Core Advantages
Drastically simplifies getting an object's world orientation. It dynamically responds to rotation and allows a shader effect to be bound to the orientation of any specified object in the scene.
Common Uses
Creating directional shields or energy fields, e.g., an effect that is stronger on the front.
Defining the central axis for cone-shaped light effects like vehicle headlights or flashlights.
Simulating the different visual impact of wind or water flow on an object's windward/leeward sides.
How to adjust
Change the output by rotating its target `Object3D` in JavaScript. Additionally, its `.object3d` property can be set at construction or runtime to make it track the orientation of any specific object in the scene.
Code Examples
1// Calculate the dot product of the object's direction and the world X-axis
2const alignment = objectDirection().dot( vec3( 1, 0, 0 ) );
3
4// Use the alignment to control green intensity for an orientation-based color
5const factor = smoothstep( -1, 1, alignment );
6material.colorNode = vec3( 0, 1, 0 ).mul( factor );