Search code examples
three.jsbuffer-geometry

InstancedBufferGeometry.copy error in three.js


I am running a three.js example code, its three.js version is 0.124.

createObj() {
    const geometry = new THREE.InstancedBufferGeometry();
    const baseGeometry = new THREE.BoxGeometry(2, 2, 20, 2, 2, 6);
    
    // Copy attributes of the base Geometry to the instancing Geometry
    geometry.copy(baseGeometry);
}

when the code is running in 'geometry.copy(baseGeometry);', an error is popping up as showed as

TypeError: Cannot read properties of undefined (reading 'clone')
    at InstancedBufferGeometry.copy (three.module.js?cf64:10935)
    at InstancedBufferGeometry.copy (three.module.js?cf64:40628)
    at createObj (Clouds.js?d048:24)

Solution

  • InstancedBufferGeometry.copy() only accepts another InstancedBufferGeometry object as the argument. You're trying to pass a legacy Geometry object (THREE.Geometry was part of the core up until r125, and you're using r124), so it breaks when performing that method when it notices that it's missing all the instancing properties.

    See here in the docs for using the copy() method