Hello,
I am currently working on a project where I need to display solar panels on a roof. For this I use THREE.InstancedMesh
because the geometry remains the same. Now I would like to draw the solar panel edges in black.
The naive first implementation looked like this:
const instancedPanel = new THREE.InstancedMesh(/* Properly initialized */);
for (const [index, matrix] of matrices.entries()) {
instancedPanel.setMatrixAt(index, matrix);
const edges = new THREE.EdgesGeometry(instancedPanel.geometry);
const lines = new THREE.LineSegments(edges, lineMaterial);
lines.matrix = matrix;
lines.matrixAutoUpdate = false;
// Add to scene
}
This created the expected output but was too slow for large roofs with tens of thousands of solar panels.
In the next approach I tried using another instanced mesh to display the edges.
const instancedPanel = new THREE.InstancedMesh(/* Properly initialized */);
const edges = new THREE.EdgesGeometry(instancedPanel.geometry);
const lines = new THREE.LineSegments(edges);
const instancedEdges = new THREE.InstancedMesh(lines.geometry, lineMaterial, total)
for (const [index, matrix] of matrices.entries()) {
instancedPanel.setMatrixAt(index, matrix);
instancedEdges.setMatrixAt(index, matrix);
// Add to scene
}
Which results in the following:
Am I doing something wrong? / What is the best way to draw edges of an instanced mesh?