动态更改Three.js中的顶点颜色

Cry*_*tal 3 three.js

我使用的是Three.js 57版本.现在我正在使用JSONLoader进行动画制作.我成功地获得了动画.但我想为动画中的每个帧更新网格的完整顶点颜色.这可能是three.js

提前致谢

Wes*_*ley 8

目前不支持顶点颜色CanvasRenderer.

以下是您需要遵循的模式WebGLRenderer:

THREE.VertexColors为网格创建材质时设置;

material.vertexColors = THREE.VertexColors;
Run Code Online (Sandbox Code Playgroud)

还要确保vertexColors为几何体的每个面定义.

geometry.faces[ faceIndex ].vertexColors[ vertexIndex ] = new THREE.Color( 0xff0000 );
Run Code Online (Sandbox Code Playgroud)

然后在渲染循环中,要更改顶点颜色,请执行以下操作:

geometry.faces[ faceIndex ].vertexColors[ vertexIndex ].setHSL( Math.random(), 0.5, 0.5 );
mesh.geometry.colorsNeedUpdate = true;
Run Code Online (Sandbox Code Playgroud)

three.js r.59

  • @Paul见http://stackoverflow.com/questions/37358419/how-to-update-colors-after-vertex-colors-are-changed/37368746#37368746 (2认同)