Javascript 尝试在three.js中渲染圆柱体,失败,错误为“0”;无法读取属性';类型';“未定义”的定义;
我有一个很大的three.js代码,当我向其中添加一个简单的圆柱体时,它会使渲染器崩溃:Javascript 尝试在three.js中渲染圆柱体,失败,错误为“0”;无法读取属性';类型';“未定义”的定义;,javascript,three.js,Javascript,Three.js,我有一个很大的three.js代码,当我向其中添加一个简单的圆柱体时,它会使渲染器崩溃: const lineGeometry=new Three.CylinderBufferGeometry(1.0,//radiusTop 1.0,//半径底部 1.0,//高度 7,1)//径向/高度段 this.line=新的三点网格(线几何体、材质) this.add(this.line) // ... 后来。。。 viewer.render() 崩溃发生在渲染期间,在renderBufferDirec
const lineGeometry=new Three.CylinderBufferGeometry(1.0,//radiusTop
1.0,//半径底部
1.0,//高度
7,1)//径向/高度段
this.line=新的三点网格(线几何体、材质)
this.add(this.line)
// ... 后来。。。
viewer.render()
崩溃发生在渲染期间,在renderBufferDirect
(实际上是renderer.setIndex
)中,并且似乎是由于此几何体具有index
属性而导致的。three.js WebGLRenderer.js中崩溃的代码如下:
if(索引!==null){
attribute=attributes.get(index);//返回未定义的
渲染器=IndexedBufferrender;
renderer.setIndex(attribute);//此处未定义属性,导致崩溃
}
失败是由于属性未定义。几何体本身只有属性position
、normal
和uv
,但我不确定这就是它失败的原因
我试图减少这种情况,但当然在一个小例子中效果很好-(
看起来索引
是位置
数组中的一组有效索引:
index: Uint16BufferAttribute {name: "", array: Uint16Array(84), itemSize: 1, count: 84, normalized: false, …}
attributes:
position: Float32BufferAttribute {name: "", array: Float32Array(138), itemSize: 3, count: 46, normalized: false, …}
normal: Float32BufferAttribute {name: "", array: Float32Array(138), itemSize: 3, count: 46, normalized: false, …}
uv: Float32BufferAttribute {name: "", array: Float32Array(92), itemSize: 2, count: 46, normalized: false, …}
所以我不确定attributes.get(index)
应该做什么,以及我需要为它提供什么才能使它工作。任何帮助都非常感谢
这是使用three.js r111顺便说一句。嗯,我算出来了。我的lineGeometry
有一个重复的buffergeometry.id
,所以它在WebGLObjects.update()中被跳过
从未更新过。至于我是如何得到一个重复的ID的,这仍然有待解决。在一个有效的简化示例中,行attribute=attributes.get(index)
返回一个包含WebGLBuffer
的对象,该对象看起来像索引数组的表示形式。那么,我搞砸了什么会导致失败呢?我有两个three.js的副本——一个由子模块导入并“汇总”,另一个由模块导入。所以他们在争夺ID。