Optional scene parameter in JavaScript causes issues in Typescript

@RaananW @roland

This is a follow on from

https://forum.babylonjs.com/t/backwards-compatibility-broken-in-showworldaxis-example/27039/25

and related to Quest to create a Hologram with a JPEG! (how to? using Thin Instances, Matrix, Arrays) - #69 by JohnK

The scene parameter appears optional in the Javascript playgrounds in many creation functions for cameras, lights, material. This is then beginning to cause issues for the few (increasing?) people using Typescript as it is not set as an optional parameter.

Whilst it’s is clearly not shown as an optional parameter in the API docs to help avoid confusion should, where it is dealt with as optional in JavaScript, be made an optional parameter in the source code?

1 Like

Which functions are we talking about? I’m happy to flag the parameter as optional

2 Likes

There is quite a few I think. Cameras , lights, and materials constructors at least.

It is already optional using BABYLON.MeshBuilder.Create… but not the now depreciated BABYLON.Mesh.Create… so they could be left as those using Typescript are unlikely to use these.

1 Like

I’ll have a look

Yep, the scene variable should be optional. It’s a case in different classes. @Deltakosh , let me know if you are going to take care of it, otherwise i’ll jump in.

2 Likes

Hi! I am moving my very first steps in Babylon.js and I’ve just found that sometimes the scene parameter is mandatory and sometimes is optional. For example:

const light = new HemisphericLight('h-light', new Vector3(1, 1, 0), scene); // mandatory
const box = MeshBuilder.CreateBox('box', {}, scene); // optional

Can you help me understand the reasoning behind this?

typescript:4.7.4
@babylonjs/core: 5.16.0

Welcome to the forum !!!

We tried to make it optional in most cases to reuse the latest created scene but might have missed some spots :slight_smile: There are no other reasons.

1 Like

Ah ok, thanks!