Spotlight absolutePosition()

Playing with the spotlight, I noticed some odd behavior.
When parenting the spotlight to another mesh, its getAbsolutePosition() does NOT update when the parent mesh is moved:

This is very hard to understand and confusing to me. In the example workspace you can also see that another child node, attached to the spotlight does update correctly. Is this a bug? If not, the documentation should be more explicit on how to get the world-position of a spotlight. My feeling is, that the argument would be that “position” is only indicating the relative position from where the spotlight shines, but this is not in line with what position means everywhere else in conjunction with parenting etc.

Hello!
I checked the SpotLight class to understand its behavior, and its inheritance chain is SpotLight → ShadowLight → Light → Node. So, it doesn’t inherit from TransformNode, whose getAbsolutePosition method computes the world matrix then gets the transformed absolute position: Babylon.js/packages/dev/core/src/Meshes/transformNode.ts at c670e814b67be2f7be66ecafebe3119aa49278c7 · BabylonJS/Babylon.js · GitHub. It instead inherits from ShadowLight’s getAbsolutePosition, which returns the untransformed position in case the transformed position hasn’t been calculated yet: Babylon.js/packages/dev/core/src/Lights/shadowLight.ts at c670e814b67be2f7be66ecafebe3119aa49278c7 · BabylonJS/Babylon.js · GitHub. If you calculate the transformed position with computeTransformedInformation, then the result of getAbsolutePosition is really the transformed one: Spotlight Not Blocked By Mesh | Babylon.js Playground (babylonjs.com). I’m not sure if getAbsolutePosition doesn’t call computeTransformedInformation beforehand for some purpose (which in case we should document this requirement), or if it is an oversight (in which case we should correct the method) - let me ping @sebavan to check :slight_smile:

It is by design to save perf so we do not do any extra calls but I agree it might be confusing.

I would be in favor of highlighting the behavior in the doc :slight_smile: @carolhmj would you mind adding it ?

1 Like

Complemented the docstring with this info: Add clarification about transformed position in shadowLight. by carolhmj · Pull Request #14689 · BabylonJS/Babylon.js (github.com)

2 Likes

you are the best @carolhmj