-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
Remove CSS2DObject from CSS2DRender when Object3D is Removed #25083
Conversation
@@ -18,6 +18,17 @@ class CSS2DObject extends Object3D { | |||
this.element.style.userSelect = 'none'; | |||
|
|||
this.element.setAttribute( 'draggable', false ); | |||
|
|||
const _this = this; | |||
this.addEventListener( 'added', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the right fix for the problem.
I wonder if it wouldn't be better to solve this issue on Object3D
level. Meaning when a 3D object is added or removed to/from the scene graph, descendants receive an event as well since they are indirectly affected by this operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe having this particular event logic in the CSS2DObject
level provides a unique solution for objects that also contain HTML DOM references.
CSS2DObject
types do not have descendants, so it makes sense to require event listeners to their parent rather than assigning events externally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSS2DObject types do not have descendants
Um, I don't think this assumptions is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, my assumption was not true. I tried nesting a CSS2DObject
within another CSS2DObject
and they render HTML on top of each other (not pretty, but still optional). The solution I provided in this PR still work when ancestors invoke clear()
or removeFromParent()
.
Do you have any pseudo code in mind for adding events to descendants within the Object3D
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing. This isn't the right fix for the issue. We should reconsider to thoughts raised in #22416. The issue in |
Description
The Problem: When Object3D objects are removed, their child CSS2DObject types are not removed from the CSS2DRenderer.
The Solution: CSS2DObject types will now be removed when the parent Object3D type is removed. The CSS2DObject "removed" event is safely invoked after it is added to the parent Object3D.
Use cases: