question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object3D: Add removeAll or clear.

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bianyunzhi95commented, Sep 25, 2020

Then what about this.children.length = 0?

1reaction
Mugen87commented, Oct 8, 2020

In order to get this issue closed, I’ve filed a PR 😇 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found