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

BufferGeometryUtils.mergeVertices - seems not to merge all identical vertices in 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)

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

干杯 汤姆

ps:也在 three.js 论坛

中以 https://discourse.threejs.org/t/buffergeometryutils-mergevertices-seems-not-to-merge-all-identical-vertices/33890 的身份发帖

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

console.log(geometry.getAttribute("position").count);    // 36
console.log(indexedGeo.getAttribute("position").count);  // 24

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