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 check for Object3D.add and Object3D.remove #16115

Closed
wants to merge 3 commits into from
Closed

Conversation

speigg
Copy link
Contributor

@speigg speigg commented Mar 31, 2019

Adds a fast path when the result of Object3D.add or Object3D.remove should be a no-op.

Sometimes it is convenient to use add and remove methods in a context where they will be called each frame, potentially on the same parent/child objects:

function animate() {
  // ...
  const intersection = raycaster.intersectObject(scene, true)[0]
  if (intersection) intersection.object.add(cursor) // <-- may be added to the same object every frame
}

This change prevents unnecessary work in the add and remove methods when sequentially adding/removing the same object to to/from the same parent, including preventing the "added" and "removed" events from being dispatched repeatedly.

speigg added 3 commits March 31, 2019 11:09
Adds a fast path when the result of `Object3D.add` or `Object3D.remove` should be a no-op.
@yomboprime
Copy link
Collaborator

For this use case I'd rather use cursor.visible and change its position.

@speigg
Copy link
Contributor Author

speigg commented Mar 31, 2019

That particular use case is a contrived example.

@mrdoob
Copy link
Owner

mrdoob commented Mar 31, 2019

function animate() {
  // ...
  const intersection = raycaster.intersectObject(scene, true)[0]
  if (intersection && cursor.parent !== intersection.object) intersection.object.add(cursor);
}

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