-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Cast rays towards specific instances of an instanced mesh. #24171
Conversation
src/core/Raycaster.js
Outdated
|
||
} | ||
|
||
intersectInstancedMesh( mesh, instances, intersects = [] ) { |
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.
A InstancedMesh
specific method in Raycaster
seems not right to me. Raycaster
should not be aware about specific 3D objects.
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 can move this to another place. Is there a good place to put "util" like functions?
TBH, I think the signature of The average raycasting performance of |
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.
Thanks for the feedback!
If I were to move this logic out of Raycaster.js
to something with application logic, where would the right place be? Would I be right in thinking that it'd go in something like https://github.com/mrdoob/three.js/tree/dev/examples/js/raycasting/InstancedRaycast.js
?
src/core/Raycaster.js
Outdated
|
||
} | ||
|
||
intersectInstancedMesh( mesh, instances, intersects = [] ) { |
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 can move this to another place. Is there a good place to put "util" like functions?
Actually I was suggesting to not add this code to the library but use it as a part of your custom code. |
Lemme see if that's possible - I'm currently working with a forked version of three with the code in this PR, but if I can extract it out 100% to the application level then I'll close the PR. Otherwise I'll let you know the bits that would need to be exposed. |
I tested it out in my custom code & getting Would it make sense to slim down the PR to only have |
TBH, I'm not in favor of having a raycasting method that selectively performs tests based on a bunch of instance IDs. The problem is how are users find out the appropriate range of instance IDs for an intersection test. This might be clear for your specific use case but not for others. I think it's better to not provide an API that requires inputs which are hard to determine. |
In my case, I'm developing a rhythm game where each tile is an instanced mesh, and different tiles become touchable based on different states in the game, but only a small subset are ever touchable at one time. So the instance IDs used for raycasting are used in the same places as I'm very new to three I don't have a good sense of the culture of how the API evolves, but as this change is not breaking & it accommodates a use case that's common from my experience in rhythm game development, I hope it or a variation of it can make it in the code base. That said, I have a working example now that uses my own subclass, so all is good atm. But the subclass is 90% copy/paste from |
It's very common for people to request that changes be made to core three.js code that could be handled at the app level. In this case if you know which instances you care to check it's very possible to do so yourself with no changes to three by extracting the matrixWorld of the given instance id, applying it to a regular |
@gkjohnson is there a example we could look at it, best with three-mesh-bvh |
👍 this is how I'm currently handing it, and it's also what the current implementation of In this PR, it's a <10 loc change to implement I definitely understand the reluctance to add stuff to the lib that can be accomplished on the application level. Here, my gut feeling is that the tradeoff is acceptable, but as I said above, I don't have a good sense in this project of what makes the cut for changing core vs not. |
Sorry, I think we should not add this code to the lib. The solution explained by @gkjohnson in #24171 (comment) sounds like the better approach for this use case. At least for now. Nevertheless, thanks for making the PR. |
Description
Raycasting against instanced meshes is currently an expensive operation when there are many instances but we only want to check for a few intersections. This adds the ability to raycast against a specific set of instances.