What exactly does Object3D.getWorldPosition() returns?

It is said that .getWorldPosition() Returns a vector representing the position of the object in world space. Is the returned position the centre of the 3D object? If so, how can we get the world position of a point in the object ?

1 Like

The difference between .position and worldPosition is that object.position represents “local position” of the object - his position in his so called “local space”.

The reason there is a difference is because an object’s position is not only influanced by it’s .position, but also the .position of it’s parent. In Three.js you create parent-child relations with

parent.add( child );

Now child object is a child of the parent object. Children become sort of “attached” to the parent - not emotionally, but in relation to it’s transform (object’s transform is it’s scale, rotation and position).

It might seem confusing, but think of it this way:

  • There is a mother who is pregnant :pregnant_woman: - mother.add( child ); :baby:
  • She carries the child in her belly. The mother walks 10 steps to the right - mother.position.set( 10, 0, 0 ); :walking_woman:
  • Now the child’s world position will be (10, 0, 0), BUT it’s local position - child.position - will be (0, 0, 0), because the child itself did not move :no_pedestrians:
    It was “attached” to the mother and SHE carried it over 10 steps to the right.
  • The same happens with 2 other transform properties - scale and rotation. If the mother starts spinning around mother.rotation.y += 3; :dancer: the child will also rotate.
    If a piano falls on the mother :musical_keyboard::musical_note::musical_score::hammer: she will get squashed - mother.scale.y = 0.1; - and the baby will get squashed as well :baby:. The child’s world scale will be (1, 0.1, 1), but it’s local scale - child.scale - is still (1, 1, 1).
  • Parents can be chained :chains::pregnant_woman::chains:, so
    mother.add( child ); :pregnant_woman::baby:
    car.add( mother ); :oncoming_automobile::pregnant_woman::baby:
    scene.add( car ); :earth_africa::oncoming_automobile::pregnant_woman::baby:
    Now the mother is in the car, so if the car moves 100 steps to the left, the mother’s and the child’s world positions will change to (-100, 0, 0), but only the car’s local position - car.position - will be (-100, 0, 0).

Okay, so that’s world position.

Is the returned position the centre of the 3D object?

You can say that, but really it’s just an abstract point in 3D space, which represents it’s world position, so it won’t necessarily be the exact center of it’s volume or geometry.

If so, how can we get the world position of a point in the object ?

I think that depends on your use case. Hard to guess what you mean by just “a point in the object”.


Hey your explaination on parent-child relation felt like icing on the cake. kudoos to that :smiley:

What I meant is that I have a 3D object,say, a cube. At a specific point,say, on the center of one of its face,. I need to attach another object. So I need to know some properties of that point(center of one of the face of the cube), right?. I thought knowing the coordinates(position , not to confuse) of that point will make it easier to attach the objects.

Thanks, it’s not something parenting books would teach you.

It sounds like your objects could use parent-child relations. What you wanna do first is put the parent at position (0, 0, 0) and find the offset position for the child. Let’s say the position, where you want to attach the second object is 1 meter to the right of the main object. Then you would do:

mainObject.add( secondObject );
secondObject.position.set(1, 0, 0);

Aaaand you have an object attached to your main model, with an offset of (1, 0, 0).

Feel free to use the Three.js Editor to experiment around with that. You can parent objects there, by dragging the child’s name onto the parent’s name in the scene graph outliner.

I tried doing it, but then scaling problem pops up :dizzy_face: When I add 2nd object as child of 1st object, 2nd object is too tiny to be visible on the scene :face_with_monocle: