Skip to content

Add scene options to set default layer masks#18382

Open
tholub99 wants to merge 1 commit intoBabylonJS:masterfrom
tholub99:master
Open

Add scene options to set default layer masks#18382
tholub99 wants to merge 1 commit intoBabylonJS:masterfrom
tholub99:master

Conversation

@tholub99
Copy link
Copy Markdown
Contributor

This adds scene optional scene options to set default layerMask values for when the scene creates new cameras and renderable objects that use the layerMask property.

If left undefined the normal 0x0FFFFFFF layerMask is used.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@tholub99 tholub99 marked this pull request as draft April 25, 2026 03:11
@tholub99 tholub99 marked this pull request as ready for review April 25, 2026 03:11
@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

Snapshot stored with reference name:
refs/pull/18382/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18382/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18382/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18382/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18382/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18382/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18382/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18382/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented Apr 25, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 25, 2026

@tholub99
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 18382 in repo BabylonJS/Babylon.js

Popov72

This comment was marked as off-topic.

Comment thread packages/dev/core/src/Particles/thinParticleSystem.ts
Comment thread packages/dev/core/src/Particles/gpuParticleSystem.ts
Comment thread packages/dev/core/src/Cameras/camera.ts Outdated
Comment thread packages/dev/core/src/Meshes/abstractMesh.ts
Comment thread packages/dev/core/src/Layers/layer.ts Outdated
Comment thread packages/dev/core/src/Sprites/spriteManager.ts Outdated
Comment thread packages/dev/core/src/Particles/baseParticleSystem.ts Outdated
Comment thread packages/dev/core/src/scene.ts
Comment thread packages/dev/core/src/scene.ts Outdated
Comment thread packages/dev/core/src/scene.ts
@tholub99 tholub99 force-pushed the master branch 2 times, most recently from 655a2eb to d8aa11e Compare April 27, 2026 19:08
@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 27, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@tholub99 tholub99 requested a review from Popov72 April 27, 2026 19:11
@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 27, 2026

Snapshot stored with reference name:
refs/pull/18382/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18382/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18382/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18382/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18382/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18382/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18382/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18382/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 27, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 27, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 27, 2026

scene: Scene
) {
this._scene = scene || EngineStore.LastCreatedScene;
this.layerMask = scene.defaultRenderableLayerMask;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.layerMask = scene.defaultRenderableLayerMask;
this.layerMask = this._scene.defaultRenderableLayerMask;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swapped to class field call

* @internal
* Gets or sets the default layerMask used for cameras created in this scene.
*/
public defaultCameraLayerMask: number;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning — drop the @internal tag from both fields. These two new public fields (here and defaultRenderableLayerMask on line 1833) are the whole point of the PR — they're meant to be user-configurable defaults, both at construction (via SceneOptions) and afterwards (the doc comment correctly says "Gets or sets …"). Marking them @internal excludes them from the public typings rollup / API docs and signals to consumers that they shouldn't touch them, which contradicts the intent. Please remove the @internal line from both JSDoc blocks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs updated

super(name, scene, false);

this.layerMask = this.getScene().defaultRenderableLayerMask;
scene = this.getScene();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — redundant getScene() call. this.getScene() is called on line 1002 and again on line 1003. Cleaner as:

scene = this.getScene();
this.layerMask = scene.defaultRenderableLayerMask;
scene.addMesh(this);

Copy link
Copy Markdown
Contributor Author

@tholub99 tholub99 Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ordered

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 28, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 28, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 28, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants