BufferGeometryUtils.mergeVertices - 似乎没有合并 Three.js 中所有相同的顶点

Tom*_*Tom 5 three.js

我对 BufferGeometryUtils.mergeVertices 方法有一个奇怪的问题

我从 jsfiddle 中取出了一个简单的立方体并执行了 mergeVertices,看起来 mergeVertices 并没有像它应该的那样合并所有相同的顶点。参见https://jsfiddle.net/tomfree/vpdwmycn/

例如,mergeVertices 返回的 indexGeometry 中给出的顶点是

Index 0 = (-1, -1, 1, )
index 1 = (1, -1, 1,)
index 2= (-1, 1, 1, )
index 3= (1, 1, 1,)
index 4= (1, -1, 1)
Run Code Online (Sandbox Code Playgroud)

即位置 1 和 4 处的顶点似乎相同,但根据我的理解,在 mergeVertices 之后不应相同。我很确定我错过了某事。有人能指出我正确的方向吗?

干杯汤姆

ps:也在Three.js 论坛中发布为https://discourse.thirdjs.org/t/buffergeometryutils-mergevertices-seems-not-to-merge-all-identical-vertices/33890

Mar*_*zzo 7

合并过程正在按预期运行。如果查看原始的每个属性的计数,geometry您将得到 36,但如果您查看合并的每个属性的计数indexedGeo,您将得到 24:

console.log(geometry.getAttribute("position").count);    // 36
console.log(indexedGeo.getAttribute("position").count);  // 24
Run Code Online (Sandbox Code Playgroud)

您遇到的问题是合并方法在合并之前查看所有属性。就你而言,position, normal, uv. 长方体的角有 3 个顶点,每个顶点都有自己的法线指向 3 个方向(例如,一个朝上、一个朝右、一个朝前)。由于每个顶点都包含normal有关如何渲染其各自面的唯一数据,因此无法合并这些顶点。虽然地位相同,但其他属性却不同。