Object3D: Add removeAll or clear.
See original GitHub issueI’d like to have removeAll or clear method in Object3D.
remove: function ( object ) {
if ( arguments.length > 1 ) {
for ( let i = 0; i < arguments.length; i ++ ) {
this.remove( arguments[ i ] );
}
return this;
}
const index = this.children.indexOf( object );
if ( index !== - 1 ) {
object.parent = null;
this.children.splice( index, 1 );
object.dispatchEvent( _removedEvent );
}
return this;
}
remove
find child within children with indexOf
and remove it using splice
which becomes bottleneck when there are a lot of children objects and I need to remove them all which I am experiencing now.
So i suggest to add removeAll
method.
removeAll: function ( ) {
for ( let i = 0; i < this.children.length; i ++ ) {
let object = this.children[i];
object.parent = null;
object.dispatchEvent( _removedEvent );
}
this.children = [];
return this;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Object3D#remove – three.js docs
This value allows the default rendering order of scene graph objects to be overridden although opaque and transparent objects remain sorted independently. When ......
Read more >Remove child objects from Object3D - javascript
add (mesh); } scene.add(group);. How, then, do I remove those objects from that group? I tried doing this...
Read more >Three.js Cleanup
Unlike most JavaScript, three.js can not automatically clean these resources up. ... And then let's write some code to add and remove things...
Read more >How to delete markers from a ros3djs viewer? - ROS Answers
It is working by searching for the scene that his the parent of the PointCloud2 object then we remove this scene from the...
Read more >Removing elements: remove, clear, removeWhere
`clear` - removes every element from the list, but retains the list itself and ... void addPet(Pet pet, bool shouldFeed) { allPets.add(pet); ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Then what about
this.children.length = 0
?In order to get this issue closed, I’ve filed a PR 😇 .