Understanding relative/absolute/word positions of (child) meshes


I have just confused myself into a total dead end.

Say you have a Blender character model that is split in different body parts (head, body,…) resulting in a BAbylon hierarchy as follows:

_root → armature → [head, eyes, body, …].

You want to get the location of the eyes from where to cast a ray later on (let’s say it’s a pirate). You need a source vector for the raycast. I assume the source vector is in some sort of a “world coordinate space”.

This world coordinate space seems to work perfectly fine when applied to root nodes. For instance, I can apply a “world” vector to the root node of my character model and it visually relocates as expected.

However, when I query the location of the eyes (child mesh) with getAbsolutePosition() I get a position equal to the root node. But this clearly is not the “world” position of the eyes. FYI, all child meshes (body parts) return the same position equal to the root node.

I mean at some point there must be the relational data that locate the body parts (child meshes) in a way as to make them appear as a character. I would assume this data must be in some common world space?

Anyway, I did get it to work by using mesh.getBoundingInfo().boundingBox.centerWorld (as suggested here).

But why? Why would the bounding box have different coordinates than the bound mesh and why would both mesh and box render perfectly fine on screen - in the same location?

Hoping for some clarifying words :confused:

Best wishes

getAbsolutePosition should work so I am not sure what could go wrong in your case :frowning: maybe the matrices have not been computed so far when you call it. In this case you could force computing it before with mesh.computeWorldMatrix(true) but a playground repro would really help here ?

1 Like

Oh! Ok. That was unexpected. In that case I am going to isolate the case and post my results.

I did cheat a bit and used an existing playground. But as far as I can tell it reflects my problem:

Please see console.log output. The lines with getAbsolutePosition return 0 while the getBoundingInfo lines seem to work.

I also tried to comment out the dude transformation stuff. No difference.

I think that the problem is in the imported 3d-model itself. At least in this playground example the pivots of all child meshes are actually in same position as the _root node (0,0,0). I added the axis viewers to all child meshes and those seems to be in zero point. You have to reset mesh pivots in 3d-editor (Blender / 3dsmax) to the desired location and then export model again. Then you get those points with getAbsolutePosition().


Yes, works :smiley:

Checked my Blender file and indeed, origin what set to 0 for all child meshes. So in conclusion:

if mesh.getAbsolutePosition() fails

  • make sure the pivot is set to mesh center (or wherever), e.g. in Blender Object->Set origin
  • depending on your use case, make sure you call mesh.computeWorldMatrix(true). In my case (not sure about the playground) this was necessary.