![](/img/trans.png)
[英]Three.js “Uncaught TypeError: Cannot read property 'render' of undefined” error with object literal
[英]Trying to render cylinder in three.js, failing with err "Cannot read property 'type' of undefined"
我有一個很大的three.js代碼,當我向它添加一個簡單的圓柱體時,它會導致渲染器崩潰:
const lineGeometry = new Three.CylinderBufferGeometry(1.0, // radiusTop
1.0, // radiusBottom
1.0, // height
7, 1) // radial/height segments
this.line = new Three.Mesh(lineGeometry, material)
this.add(this.line)
// ... later ...
viewer.render()
崩潰發生在渲染期間,在renderBufferDirect中的renderBufferDirect
(實際上是renderer.setIndex
)中,並且似乎是由於該幾何體具有index
屬性這一事實引起的。 Three.js WebGLRenderer.js 中崩潰的代碼是這樣的:
if ( index !== null ) {
attribute = attributes.get( index ); // this returns undefined
renderer = indexedBufferRenderer;
renderer.setIndex( attribute ); // attribute is undefined here, causes crash
}
失敗是由於attribute
未定義。 幾何本身只有屬性position
, normal
和uv
,但我不確定這就是它失敗的原因。
我試圖減少它,但當然在一個小例子中它工作正常。 :-(
看起來index
是position
數組中的一組有效索引:
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 btw。
嗯,我想通了,有點。 我的lineGeometry
有一個重復的buffergeometry.id
,所以它在WebGLObjects.update()
被跳過並且永遠不會更新。 至於我是如何得到重復ID的,還有待弄清楚。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.