Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directly constructed Nodes to rootNodes #15089

Merged
merged 1 commit into from May 13, 2024

Conversation

ryantrem
Copy link
Member

@ryantrem ryantrem commented May 10, 2024

This is in response to this forum post: https://forum.babylonjs.com/t/root-node-not-shown-in-inspector-but-transformnodes-are/50432

When a Node is created directly (not a subclass of Node), it does not get added to the rootNodes of the Scene. However, if you set the parent on that Node and then set it back to null, then it does get added to rootNodes. From what I can tell, this is just wrong behavior and is a bug. My proposed fix is to add an optional parameter to the Node constructor that controls whether it gets added to the rootNodes. This is the same pattern that already existed for the same purpose with TransformNode and it's derived classes (e.g. AbstratMesh). That said, I personally don't love this pattern because as far as I can tell the isPure idea is meant to be an implementation detail to deal with the subclassing, but is publicly exposed (I know there is already a lot of this across the API). An alternative would be to just add this to the Node constructor and not change any of the subclasses:

if (this.constructor === Node) {
    this._addToSceneRootNodes();
}

This would just be saying "if a Node is directly constructed, add it to the scene's rootNodes, otherwise it must be a subclass, and the subclass is responsible for deciding how to add it to the rootNodes." Thoughts @deltakosh or anyone else?

@bjsplat
Copy link
Collaborator

bjsplat commented May 10, 2024

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
Collaborator

bjsplat commented May 10, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented May 10, 2024

Visualization tests for WebGPU (Experimental)
Important - these might fail sporadically. This is an optional test.

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/15089/merge/testResults/webgpuplaywright/index.html

@bjsplat
Copy link
Collaborator

bjsplat commented May 10, 2024

@ryantrem ryantrem added the bug label May 11, 2024
@RaananW
Copy link
Member

RaananW commented May 13, 2024

This is in response to this forum post: https://forum.babylonjs.com/t/root-node-not-shown-in-inspector-but-transformnodes-are/50432

When a Node is created directly (not a subclass of Node), it does not get added to the rootNodes of the Scene. However, if you set the parent on that Node and then set it back to null, then it does get added to rootNodes. From what I can tell, this is just wrong behavior and is a bug. My proposed fix is to add an optional parameter to the Node constructor that controls whether it gets added to the rootNodes. This is the same pattern that already existed for the same purpose with TransformNode and it's derived classes (e.g. AbstratMesh). That said, I personally don't love this pattern because as far as I can tell the isPure idea is meant to be an implementation detail to deal with the subclassing, but is publicly exposed (I know there is already a lot of this across the API). An alternative would be to just add this to the Node constructor and not change any of the subclasses:

if (this.constructor === Node) {
    this._addToSceneRootNodes();
}

This would just be saying "if a Node is directly constructed, add it to the scene's rootNodes, otherwise it must be a subclass, and the subclass is responsible for deciding how to add it to the rootNodes." Thoughts @deltakosh or anyone else?

As you say, this exists extensively in the framework. I like this solution more than the this.constructor one, but both do solve the problem, so - IMO - whatever you feel is cleaner.

Copy link
Contributor

@deltakosh deltakosh left a comment

Choose a reason for hiding this comment

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

Both work for me.

@ryantrem ryantrem marked this pull request as ready for review May 13, 2024 16:19
@ryantrem
Copy link
Member Author

Ok, it sounds like overall their is a slight preference for the isPure approach, so I'll just stick with that.

@ryantrem ryantrem merged commit 4cf7f4d into BabylonJS:master May 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants