ChrisU
ChrisU

Reputation: 236

threejs performance - merging and picking

I learned that to increase performance in three.js, we need to minimize the number of draw calls. This can be done by merging geometries using GeometryUtils.merge.

However after merging, it is not possible anymore to pick individual geometries using raycasting. I understand the reason for it but I wonder if there are other techniques that allow picking individual geometries after merging?

Upvotes: 4

Views: 866

Answers (2)

Eerik Kivistik
Eerik Kivistik

Reputation: 176

A memory inefficient, but quick way would be to keep 2 sets of geometries. A merged geometry for rendering and an unmerged one for raycasting. So you would raycast on the geometry that is never rendered. If you don't have tight memory constraints, just a lot of objects, this might make sense.
Another, but a more complex way, would be to implement an index that maps faces to original geometries.

Upvotes: 1

dennis
dennis

Reputation: 865

This example shows how to change the color of a clicked face of a sphere geometry: http://stemkoski.github.io/Three.js/Mouse-Click.html

Does that help? What exactly do you want to do with the picked geometry object?

/edit: Thinking about it again, that probably won't help because you want to raycast a complete geometry object, not single faces of it..

Upvotes: 0

Related Questions