threebox icon indicating copy to clipboard operation
threebox copied to clipboard

Removing and reloading a 3D object causes it to disconnect from the map

Open josh-cloudscape opened this issue 3 years ago • 1 comments

Describe the bug Removing and reloading a 3D object causes it to disconnect from the map. This only seems to occur when:

  1. Using the threebox cache (e.g. options.clone is not set to false)
  2. The glb file contains animations

Afterwards moving the map does not move the model position.

To Reproduce

const options = {
    obj: '/soldier.glb',
    type: 'gltf',
    scale: 20,
    units: 'meters',
    rotation: { x: 90, y: 0, z: 0 },
    adjustment: { x: 0, y: 0, z: 0 },
    feature,
}

let soldier;
const load = () => {
    tb.loadObj(options, function (model) {
        soldier = model.setCoords(feature.geometry.coordinates);
        tb.add(soldier);
    })
}

load();
setTimeout(() => tb.remove(soldier), 2000);
setTimeout(() => load(), 4000);

Example output

Additional context

  • Version 2.2.7

My guess is something in the duplicate function is not quite right? I couldn't see anything obvious but might not have been looking in the right spot.

josh-cloudscape avatar Jul 20 '22 03:07 josh-cloudscape

It seems to be fixed by changing the clone method in objects.js from

let dupe = obj.clone(true)

to

// SkeletonUtils can be copied from https://github.com/mrdoob/three.js/blob/r132/examples/jsm/utils/SkeletonUtils.js
const SkeletonUtils = require("../SkeletonUtils.js");
...
let dupe = SkeletonUtils.clone(obj)

josh-cloudscape avatar Dec 20 '22 02:12 josh-cloudscape