-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Layers: Add recursive property #32619
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1080,6 +1080,37 @@ class Object3D extends EventDispatcher { | |
|
|
||
| } | ||
|
|
||
| /** | ||
| * Like {@link Object3D#traverseVisible}, but the callback will only be executed | ||
| * for visible 3D objects that pass the layer test. Descendants of invisible | ||
| * 3D objects and objects with recursive layers that fail the test are not traversed. | ||
| * | ||
| * Note: Modifying the scene graph inside the callback is discouraged. | ||
| * | ||
| * @param {Layers} cameraLayers - The camera layers to test against. | ||
| * @param {Function} callback - A callback function that allows to process the current 3D object. | ||
| */ | ||
| traverseVisibleWithLayers( cameraLayers, callback, inheritedLayers = null ) { | ||
|
|
||
| if ( this.visible === false ) return; | ||
|
|
||
| const effectiveLayers = inheritedLayers !== null ? inheritedLayers : this.layers; | ||
| const layerVisible = effectiveLayers.test( cameraLayers ); | ||
|
|
||
| if ( ! layerVisible && effectiveLayers.recursive ) return; | ||
|
|
||
| if ( layerVisible ) callback( this ); | ||
|
|
||
| const childInheritedLayers = this.layers.recursive ? this.layers : inheritedLayers; | ||
|
|
||
| for ( let i = 0, l = this.children.length; i < l; i ++ ) { | ||
|
|
||
| this.children[ i ].traverseVisibleWithLayers( cameraLayers, callback, childInheritedLayers ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
Comment on lines
+1083
to
+1113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 HIGH - New traverseVisibleWithLayers method lacks test coverage Category: quality Description: Suggestion: Confidence: 92% |
||
| /** | ||
| * Like {@link Object3D#traverse}, but the callback will only be executed for all ancestors. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,11 +233,16 @@ function ascSort( a, b ) { | |
|
|
||
| } | ||
|
|
||
| function intersect( object, raycaster, intersects, recursive ) { | ||
| function intersect( object, raycaster, intersects, recursive, inheritedLayers = null ) { | ||
|
|
||
| const effectiveLayers = inheritedLayers !== null ? inheritedLayers : object.layers; | ||
| const visible = effectiveLayers.test( raycaster.layers ); | ||
|
|
||
| if ( visible === false && effectiveLayers.recursive === true ) return; | ||
|
|
||
| let propagate = true; | ||
|
|
||
| if ( object.layers.test( raycaster.layers ) ) { | ||
| if ( visible ) { | ||
|
|
||
| const result = object.raycast( raycaster, intersects ); | ||
|
|
||
|
|
@@ -247,11 +252,13 @@ function intersect( object, raycaster, intersects, recursive ) { | |
|
|
||
| if ( propagate === true && recursive === true ) { | ||
|
|
||
| const childInheritedLayers = object.layers.recursive === true ? object.layers : inheritedLayers; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 HIGH - Incorrect layer inheritance in raycasting - using object.layers instead of effectiveLayers Category: bug Description: Suggestion: Confidence: 85% |
||
|
|
||
| const children = object.children; | ||
|
|
||
| for ( let i = 0, l = children.length; i < l; i ++ ) { | ||
|
|
||
| intersect( children[ i ], raycaster, intersects, true ); | ||
| intersect( children[ i ], raycaster, intersects, true, childInheritedLayers ); | ||
|
|
||
| } | ||
|
|
||
|
|
||
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.
🟠 HIGH - Incorrect layer inheritance - using object.layers instead of effectiveLayers
Agent: Delegated (architecture, bugs, documentation, performance)
Category: bug
Description:
When an object has recursive=true, children should inherit the effectiveLayers (which may have been inherited from an ancestor), not object.layers. The code checks object.layers.recursive instead of effectiveLayers.recursive, causing children to inherit the wrong layer mask when their parent inherited layers from an ancestor with recursive=true.
Suggestion:
Change line 1104 from 'const childInheritedLayers = this.layers.recursive ? this.layers : inheritedLayers;' to 'const childInheritedLayers = effectiveLayers.recursive ? effectiveLayers : inheritedLayers;'
Confidence: 85%
Review ID:
18426889-7dd5-4a37-bc33-d2c4c0357982Rate it 👍 or 👎 to improve future reviews | Powered by diffray