Why is constructor scene arg optional for many `Node`s, but not for `Light`?

This is valid:

new TransformNode('node') // no type error, scene arg is omitted

while this makes a type error:

new DirectionalLight('light_directional', direction); // type error, missing scene arg

both of these eventually inherit from Node, which adds nodes to the last created scene. However the scene arg for various Node constructors seems to be arbitrarily optional only for some nodes despite that they all get the default scene treatment from Node here:

Why is Babylon’s API inconsistent like this? Did someone forget to finish updating all the class types at some point?

This is probably because different people coded different parts of the engine. Or perhaps Engine.LastCreatedScene didn’t exist at one point, and when it was added, it was used as the default value for the scene parameter when it wasn’t passed in (for all new code added at that time)?

In any case, it seems reasonable to add this behavior to the light constructor as well, so if you’d like to make a PR, we’d be happy to review it!

2 Likes