Three.js基于顶点颜色的颜色面

时间:2022-03-07 05:53:05

I have a mesh that and have set the vertex colors as shown:

我有一个网格,并设置了顶点颜色,如下所示:

var vertColors = MyPolygonProto.polygons[iBorderCounter].polyMesh.geometry.colors;
vertColors[vertCount] = new THREE.Color(finalColor.r, finalColor.g, finalColor.b);

Where polyMesh is a mesh. I'd like to change the colors of the faces based on the geometries.

其中polyMesh是网格。我想根据几何图形改变面的颜色。

I was able to implement the technique shown here: How to change face color in Three.js

我能够实现这里显示的技术:如何在Three.js中更改面部颜色

But it seems like inefficient to have to go over the same vertex multiple times when they are shared by multiple faces. A technique in which each face automatically interpolated it's color based on the color of its vertices as listed in the mesh.geometry.colors array would seem more efficient.

但是当它们被多个面共享时,必须多次遍历同一个顶点似乎效率低下。一种技术,其中每个面基于其在mesh.geometry.colors数组中列出的顶点颜色自动内插它的颜色似乎更有效。

Does this capability exist in Three.js?

Three.js中是否存在此功能?

1 个解决方案

#1


According to the three.js documentation vertex colors can't be used this way. You have to use per-face vertex colors.

根据three.js文档,顶点颜色不能以这种方式使用。您必须使用每面顶点颜色。

Documentation for vertex colors:

顶点颜色的文档:

Array of vertex colors, matching number and order of vertices. Used in PointCloud and Line. Meshes use per-face-use-of-vertex colors embedded directly in faces. To signal an update in this array, Geometry.colorsNeedUpdate needs to be set to true.

顶点颜色数组,匹配数字和顶点顺序。用于PointCloud和Line。网格使用直接嵌入面中的每面使用顶点颜色。要发出此数组中的更新信号,需要将Geometry.colorsNeedUpdate设置为true。

#1


According to the three.js documentation vertex colors can't be used this way. You have to use per-face vertex colors.

根据three.js文档,顶点颜色不能以这种方式使用。您必须使用每面顶点颜色。

Documentation for vertex colors:

顶点颜色的文档:

Array of vertex colors, matching number and order of vertices. Used in PointCloud and Line. Meshes use per-face-use-of-vertex colors embedded directly in faces. To signal an update in this array, Geometry.colorsNeedUpdate needs to be set to true.

顶点颜色数组,匹配数字和顶点顺序。用于PointCloud和Line。网格使用直接嵌入面中的每面使用顶点颜色。要发出此数组中的更新信号,需要将Geometry.colorsNeedUpdate设置为true。