threebox
threebox copied to clipboard
Removing and reloading a 3D object causes it to disconnect from the map
Describe the bug Removing and reloading a 3D object causes it to disconnect from the map. This only seems to occur when:
- Using the threebox cache (e.g.
options.cloneis not set tofalse) - 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

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.
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)