Following the guidance of the folks above in the comments, I discovered that the reason for the strange behavior in my code (the console.logs indicated that each Object3D
in the object-literal was being filled with meshes during the run, but at the end all but the last Object3D
were empty) was that meshes can be used only once and I needed to copy them into the Object3Ds
, otherwise they were simply jumping from one to the next as I assigned them. Oi!
The fix was quick and easy - simply add .clone()
to the end of the mesh variable in the .add()
function:
var objSet = {
thing1: new THREE.Object3D(),
thing2: new THREE.Object3D(),
thing3: new THREE.Object3D()
};
for (key in objSet) {
objSet[key].add(aMesh.clone());
objSet[key].add(anotherMesh.clone());
objSet[key].add(yetAnotherMesh.clone());
};
Thanks all!