• 3D
  • Ray casting not using collisions shapes?

Is it possible? Currently I generate a trimesh_shape from my mesh so that I can ray cast the objects on screen and selected them. I don't really need the collision shapes for anything else and they are usually updated in real-time when the user changes the mesh. So it has the potential to be rather slow in some cases.

Is there a way get the object the mouse is over without using collision shapes? I know some 3D editors use some technique that utilises shaders - not sure how exactly but I think the fragment shaders sets a unique flat pixel color at every pixel the object is visible to another texture buffer, and then the user can sample the resulting texture and get the object that set that color.

Any ideas?

Yes, it's called picking. You add a shader to each pickable object with a unique RGB color. Then when you click you take a texture sample (you want to disable filtering and mip mapping) and the resulting color is the index of your object. On some newer hardware like PS4 they actually just write the object id number into the texture so you don't have to do the conversion, but if you are doing it manually in OpenGL, then the color method is probably the easiest.

But without doing shader programming, and easier thing to do would be to have 2 collision meshes. The trimesh and an AABB. The first mouse click checks all the AABBs (basically a cube that encloses the object fully) and then if it hits (or it hits multiple AABBs) then you do the trimesh calculation, but only on the 1 or 2 objects that were hit. This should be fast enough.

Yeah that's the word I'm looking for, thanks. Does Godot support this or is it a DIY solution?

Thanks for the speed tips too, I'm sure that'll help a lot.