user14440113
user14440113

Reputation:

Get Local Position for Object in React-three-fiber

Briefing: I'm attempting to parent a "drei Text" element to a point on the outside of a sphere near the pins in a react-three-fiber scene. So that when the sphere is rotated, or the camera rotates around the sphere, the Texts position is centered on the outside of the sphere.

An example: three.js text alignment

Questions:

How do I find the local and world space positions of an object or parts/points of an object?

How do I parent that objects position to a child object, such that when the parent moves, the child moves with it?

Does a scene have a world position that is relative to the axis at [0,0,0] and a local position that is relative to an object?

My Code Sandbox: earth with locations

Upvotes: 3

Views: 7403

Answers (1)

Hayden Linder
Hayden Linder

Reputation: 890

Check out Object3d, the base class for many objects in three.js, including the scene itself. It has properties and functions that can help you like .position and .getWorldPosition().

Note that the position of any object in the scene is relative to its parent. You can add children to an object with .add(child), but a better way to group objects might be with a Group.

Upvotes: 0

Related Questions