You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

three.js 0.124版本调用InstancedBufferGeometry.copy报clone相关TypeError如何解决

问题原因
  • three.js r124版本中,InstancedBufferGeometry的copy方法仅支持接收同类型的InstancedBufferGeometry实例作为入参,你传入的BoxGeometry是普通BufferGeometry的子类,不存在InstancedBufferGeometry特有的instancedAttributes属性,方法内部尝试对这个不存在的属性下的元素调用clone方法时就会触发该报错。
解决方法
  • 方案1:手动拷贝基础几何体的标准属性,不要调用copy方法:
createObj() {
    const geometry = new THREE.InstancedBufferGeometry();
    const baseGeometry = new THREE.BoxGeometry(2, 2, 20, 2, 2, 6);
    
    // 手动拷贝所有基础属性
    geometry.index = baseGeometry.index;
    geometry.attributes = baseGeometry.attributes;
    // 如有需要可以手动拷贝groups等其他普通BufferGeometry属性
    geometry.groups = baseGeometry.groups;
}
  • 方案2:如果需要做实例化渲染,在手动拷贝基础属性后,再补充所需的实例化属性即可,示例如下:
// 示例:补充实例化位置属性,假设有100个实例
const instanceCount = 100;
const positions = new Float32Array(instanceCount * 3);
// 此处省略给positions赋值每个实例位置坐标的逻辑
geometry.setAttribute('instancePosition', new THREE.InstancedBufferAttribute(positions, 3));
geometry.instanceCount = instanceCount;

内容的提问来源于stack exchange,提问作者user824624

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 12:45:03