【问题标题】:BufferGeometryUtils.mergeVertices - seems not to merge all identical vertices in three.jsBufferGeometryUtils.mergeVertices - 似乎没有合并three.js中的所有相同顶点
【发布时间】:2022-01-22 06:22:16
【问题描述】:

我对 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发布

【问题讨论】:

    标签: three.js


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢。完全有道理。我太专注于纯粹的职位
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 2022-06-15
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多