Add removeSelection() to SelectionOutlineLayer#18233
Add removeSelection() to SelectionOutlineLayer#18233regnaio wants to merge 6 commits intoBabylonJS:masterfrom
removeSelection() to SelectionOutlineLayer#18233Conversation
|
The And this is just my personal opinion, but even cutting-edge models like Opus 4.6 aren’t capable of writing code that fully understands the context of Babylon.js. This is because the generated code gives the impression that it understands the context, even though it doesn’t actually understand anything, making it more confusing to read than code written by a human. |
|
Ah thank you for your explanation, @noname0310! I now understand your concern about the selection instance ID, which is incremented for every mesh or mesh group added. My apologies for the hard-to-read diff. I tried to not duplicate code by reusing your cleanup code in If you would be so kind to quickly glance over the diff again to see if it's in the right direction, I'd be really thankful. I was just curious: If we have hundreds of meshes in the |
Selection IDs are stored as floats (exact integers only up to 2^24). Without ID reuse, repeated add/remove cycles would exhaust the ID space and silently break outline grouping — which is why removeSelection was intentionally omitted in the original design. This adds removeSelection while solving the ID exhaustion problem via a free list: when all meshes sharing an ID are removed, that ID is returned to a pool and reused by the next addSelection call. The ID space is now bounded by the max number of concurrent selections, not the total lifetime add/remove count. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4c7e016 to
e8f47d4
Compare
Without cleanup, removing an instanced mesh from the selection leaves its stale selection ID in the per-instance attribute buffer. If other instances of the same source mesh are still selected, the removed instance would incorrectly appear in the outline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ction Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ong storage Read from _userThinInstanceBuffersStorage (thin instances) instead of _userInstancedBuffersStorage (regular instances). The wrong property caused selection IDs to silently leak, defeating free-list recycling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
_disposeMesh already provides the same value as removeSelection. However, to use this, users must understand that empty IDs are produced as they continue to use the remove and add operations. To hide these internal details, |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Under normal usage, to remove a specific element from the list, you must call As mentioned earlier, using Before discussing the Selection Outline, I’d like to talk about the GPU Picker. Initially, the GPU Picker only allowed setting the picking list via Therefore, I modified the GPU Picker to remove the restriction that previously only allowed setting the picking list, enabling the ability to append items as well. I applied the same constraint when creating the Selection Outline, which is why it now supports the add operation. Essentially, the Selection Outline is designed to operate by setting a list. Also, the main point of my comment about AI-generated PRs isn’t that the diff is hard to read, but simply that reading something generated by AI is tiring in itself. |
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
|
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18233/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/18233/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/18233/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. |
|
WebGL2 visualization test reporter: |
|
Visualization tests for WebGPU |
|
Thank you so much, @noname0310 , I completely understand where you're coming from. Let me close this PR, since it does seem to add unnecessary complexity. It's great to hear that It seems that |
|
To be more precise, i expect issues to arise once the value exceeds the maximum safe integer for 32-bit floating-point numbers. In this case, the outlines of two objects that should be distinct may merge and be rendered as a single object. Therefore, users can implement the following strategy: By storing the selection state externally, clearing it after the “add selection” operation has been performed a certain number of times, and then resynchronizing the Selection Outline Layer’s state with the external state, the system should function without major issues. |
|
Thank you, @noname0310 , for all your explanations 😄 If I ever do a PR in the future for |
Description and code entirely from Claude:
I built the snapshot
babylon.jsand tested thatremoveSelection()works in my project.@Popov72 , @noname0310 , @Fuyutami , when you have time, could you please review this PR? I'm unsure if Claude wrote the code the way you deem best, so please feel free to edit the code in any way.
Thank you so much for your time and help!
If it also sounds good with you all, a future optimization I'd like to make with the help of Claude is to have a Map search instead of an array search like
this._selection.indexOf(mesh)