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

Octree: Add layers property for filtering objects. #28116

Merged
merged 2 commits into from Apr 11, 2024
Merged

Conversation

RemusMar
Copy link
Contributor

This is a very useful feature (especially in games), it's 100% backwards compatible with the exisiting users logic and I thought to share it.
Long story short: many times you need to ignore a list of models/meshes when performing collisions or raycasting.
Think about the vegetation in a 3D world for example.
And here is this feature in action: https://necromanthus.com/Test/html5/SMC_Octree.html

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 11, 2024

Would you be okay if we implement this differently via layers similar to Raycaster? Meaning:

  • Adding a new layers property to Octree.
  • Make a layer test in fromGraphNode().
if ( this.layers.test( object.layers ) ) {

    // add to octree

}

If you shift objects to different layers, they should be excluded from the addition.

@Mugen87 Mugen87 added this to the r164 milestone Apr 11, 2024
@RemusMar
Copy link
Contributor Author

Hi Michael,
Sure, but I thought the current solution is the easiest and the fastest.

Also, I hope you noticed the "per material name" instead of "per mesh name" approach.
I think the "per material name" is the best solution, at least for 2 reasons:

  1. think about 100 bushes sharing the same material.
    You want to add a single entry in that array, not 100
  2. think about trees: you want collisions for the tree bark, but not for the upper part.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 11, 2024

Yeah, that makes sense. But if the class works with layers, the app can use whatever criteria to configure the layers setting.

@RemusMar
Copy link
Contributor Author

OK.
I've added Layers to Octree and updated the sample file: https://necromanthus.com/Test/html5/SMC_Octree.html
Same good result with only difference that the filtering is executed on the "client side" now:

	if (["palm1","palm2","palm3","bush1","bush2","bush3"].includes(child.material.name) ) {
		child.layers.set( 1 );
	}
// ...
camera.layers.enable( 1 );

@Mugen87 Mugen87 merged commit fa03a01 into mrdoob:dev Apr 11, 2024
11 checks passed
@Mugen87 Mugen87 changed the title Octree and ignore certain meshes Octree: Add layers property for filtering objects. Apr 11, 2024
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.

None yet

2 participants