Using LineGeometry for InstancedMesh

Hi all,

I would like to use LineGeometry to create an InstancedMesh.

This is my current pseudo code.

let line = new LineGeometry();

    0, 0, 0,
    0, 1, 0,
    1, 1, 0,
    1, 0, 0,
    0, 0, 0

let mesh = new THREE.InstancedMesh (
    new LineMaterial({ linewidth: 0.005, color: 0x051a36}),

let props = [ //properties ]

for ( let i=0; i<count; i++) {
    transform(props[i], i);

transform(prop, idx) {
    // create matrix using the variable prop here
    matrix.compose(position, quaternion, scale);
    mesh.setMatrixAt(idx, matrix);

However, the count variable affects not the number of instances of LineGeometry, but count of number of line segments in the LineGeometry. For example, if the InstanceMesh count is 1, the LineGeometry will show the first segment of the LineGeometry. If the InstanceMesh count is 2, the LineGeometry will show the second segment of the LineGeometry, and so on.

E.g. Given the above vertices in the pseudocode:

InstanceMesh Count = 1

InstanceMesh Count = 2

InstanceMesh Count = 3

InstanceMesh Count = 4

InstanceMesh Count > 4
Nothing else happens here on the viewport as there are no more vertices except for the fact the InstanceMesh count increases accordingly if InstanceMesh is logged out in console. It may be that InstanceMesh the line segments of the InstanceMesh repeats itself again accordingly in the viewport although it cannot be seen as the line segments would be occupying the same space in the viewport.

The position of the LineGeometry is unaffected when using .setMatrixAt().

May I ask why is this happening and how should I resolve this?

Thanks in advance.

LineGeometry extends LineSegmentsGeometry, that extends InstancedBufferGeometry.
Thus, using it with InstancedMesh, you’re doing instancing on instancing.



The issue has been resolved after your tip.

Thank you for the help.

1 Like