InstanceMesh DynamicDrawUsage

I have a odd error happening so I want to check the limitations on InstanceMesh.
The instance mesh I created is dynamic, so the count will change.

this.mesh = new InstancedMesh(new PlaneGeometry(), this.material, count);
this.mesh.instanceMatrix.setUsage(DynamicDrawUsage);

I am using a CurvePath and add some curves to hit that includes
QuadraticBezierCurve3
CubicBezierCurve3 and
Several LineCurve3

I update the vectors of two LineCurve3 and then need to do an update.

The drawing I am doing is to render a plane on the path given an amount of space.

        this.mesh.count = count;

        for (let i = 0; i <= count; i++) {
            const norm = i / count;
            const tangent = this.curvePath.getTangent(norm);

            axis.crossVectors(up, tangent).normalize();
            const radians = Math.acos(up.dot(tangent));
            const point = this.curvePath.getPointAt(norm);

            this.dummy.position.copy(point);
            this.dummy.scale.set(this.xScale, this.yScale, 1);
            this.dummy.quaternion.setFromAxisAngle(axis, radians);
            this.dummy.updateMatrix();

            this.mesh.setMatrixAt(i, this.dummy.matrix);
        }

        this.mesh.instanceMatrix.needsUpdate = true;

This works fine when you have a small curve set but when the count gets to 85 ish count on the instance mesh I get a draw call error.

[.WebGL-00006DD400213B80] GL_INVALID_OPERATION: Internal error: 0x00000502: Vertex buffer is not big enough for the draw call.
:8000/#curves:1 WebGL: too many errors, no more errors will be reported to the console for this context.

Any idea as to why I am getting this error and what I can do to have a larger instance mesh?

Full source can be found at

update method.

Any assistance will be greatly appreciated.

commenting out
this.mesh.count = count;

The error goes away and if I hardcode the count to something like 500 everything works as expected.
Seems pretty like a waist though.

I assume instance mesh is the right option to use in these scenarios?

When creating an instanced mesh, you have to apply the maximum count of instances you are going to render. You can’t exceed count after the object creation.

1 Like

Thank you for the reply.
Will have to come up with a dynamic strategy of replacing the mesh if it exceeds initial count then.

Any plans or progress on making that a bit more flexible?

TBH, no. Otherwise users are going to think it’s okay to arbitrarily change buffer sizes. The engine can’t hide this complexity in an appropriate way so it’s better to handle it on app level.

1 Like