In three, the performance is greatly improved by the combination of a plurality of mesh components by TREE.BufferGeometry.merge()
, but there is a problem that never knows how to solve it 1. How do I get the information of a single component and change the color by means of raycaster? 2. How do I get the corresponding component information from the consolidated geometry?
If you have a single merged geometry, working with individual components is initially not possible. However, you can save additional information about the each component in a separate data structure. E.g. the face indices that belong to a single component or the data range in the merged buffers. This will enable you to identify which component was selected. By using vertex colors, you can also change the color of a single component without loosing the performance benefit of a merged geometry. Notice that using multiple materials will result in additional draw calls again. Avoiding this is one primary reasons for merging geometries.
Is it through the addAttributes property to set the relevant data information before the merger, the overall operation is still some strange, there are no relevant cases or learning materials to provide it? Thank you
Is it through the addAttributes property to set the relevant data information before the merger
No, you would have to maintain a custom data structure.
Instead of doing so, you can also start with two set of geometries. You are using the merged one just for rendering. The second one represents the unmerged state, so individual objects. You are using them just for interaction.
Maybe you can start with this approach and see how it goes?
I probably get it. I’ll try it first. Thank you for your advice.
Hello, through the ideas you provide I have been able to achieve the merger of multiple mesh and mouse click effect. Now I have a new question is how to hide the merged model for a single mesh. I have recorded the starting position and the total number of each mesh vertex, and can change the color of a single mesh. I just don’t know how to hide a single mesh. Can you provide some methods or ideas? Thank you