Dynamically change vertex coloring on line geometry not working since r72

Before r72 I was able to create a Line geometry without any vertex coloring by setting the Line material’s vertexColors to THREE.NoColors) and later I would set it to THREE.VertexColors along with setting the Line geometry’s colors array to a new array with one new THREE.Color for each vertex as well as setting the geometry’s colorNeedUpdate flag. The next render call did respect this. Since r72 this doesn’t seem to work anymore. Rendering fails with: [.WebGLRenderingContext-0x3ed1656ee000]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1

I looked into three.js and found the problem is very likely when the (now) LineSegment BufferGeometry is updated from its Geometry through BufferGeometry.updateFromObject: In copyColorsArray the new colors should be copied into the typed array of the attribute. However, this silently fails. The typed array has a length of zero and doesn’t resize dynamically. Copying colors from the colors array doesn’t have any effect and the colors attribute stays empty. I suspect this buffer is expected to have the correct size when used later on in the glDrawArrays() call.

Or is there anything that I missed in this updated that would re-initialize the typed array (like another flag or a call)?

Author: Fantashit

1 thought on “Dynamically change vertex coloring on line geometry not working since r72

  1. Sorry this was overlooked…

    I think this is known-behavior similar to #7179 (comment).

    Add vertex colors at the start.

    geometry = new THREE.Geometry();
    geometry.colors = [ new THREE.Color(), new THREE.Color(), new THREE.Color(), new THREE.Color() ];
    

    And then change the colors like so:

    geometry.colors[ 0 ].setRGB( 1, 0, 0 );
    ...
    geometry.colorsNeedUpdate = true;
    material.vertexColors = THREE.VertexColors;
    material.needsUpdate = true;
    

Comments are closed.