我无法从 bufferGeometry 中获取位置属性

I can't get position attribute off a bufferGeometry

我随机得到了一条线 "walking around my scene"(某种 3D 蛇),接下来我想要实现的是在它的头部周围设置一个方框。 bufferGeometry 行由

设置
        var positions1 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
        var positions2 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
        buffGeometry1.addAttribute( 'position', new THREE.BufferAttribute( positions1, 3 ) );
        buffGeometry2.addAttribute( 'position', new THREE.BufferAttribute( positions2, 3 ) );

我选择在它周围设置一个立方体(boxGeometry 对象),我使用以下代码行来尝试实现它:

            var positioning = buffGeometry1.getAttribute('position');
            cube.position.x = positioning[0];//(line1.geometry.attributes.position.array[drawCount]);
            cube.position.y = positioning[1];//(line1.geometry.attributes.position.array[drawCount + 1]);
            cube.position.z = positioning[2];

在调试时,我发现我的 positioning 数组未定义。所以我想出了什么问题。

谢谢。

尝试:

console.log(buffGeometry1.getAttribute('position'))

我的 THREE.BufferGeometry 显示顶点存储在 positioning.array 中,因此您应该通过以下方式评估它们:

positioning.array[0]
positioning.array[1]
positioning.array[2]