How do I access the transformedPosition of objects?

I am trying to get the position of a light from a GLTF file so I can position a sphere created in Babylonjs in the same place.

The x, y, z position of the light are all 0 so I can’t use that.

The transformedPosition coordinates are correct and I can see them in chrome inspector, but when I console.log it, it comes out as undefined. I’m not sure why. How can I get those coordinates?

Thanks

Could you create a repro in the playground ? it sounds hard to help without it ?

Hello @mpg just checking in if you still have an issue and if so, if you can provide us with a Babylon.js Playground (babylonjs.com) example so we can help further.

Hello @carolhmj, @sebavan,

I am sorry for such a late reply. I got overwhelmed with stuff to do.

Here is an example of what I mean:

See the comments for my question and the screenshot for what Chrome inspector shows.

The problem was that I couldn’t access the xyz coordinates of the light from the gltf file.

I already found a solution to get the xyz, but there are things I don’t understand still. Please see the comments in the code.

Thanks

Seems that in your GLB model light position and light rotation are made with the help of TransformNode.
You may check these lines at https://playground.babylonjs.com/#R2B8EF#10


console.log(scene.getTransformNodeByName("Light").position)
console.log(scene.getTransformNodeByName("Light").rotationQuaternion)

Please note that there is also another TransformNode Light_Orientation which has rotation -90 degrees in X axis.

1 Like

Thank you!