I called a method and it returned me this JSON but each time I tried to get “mesh” , “anims” or “mixer” y returned me a null response. My main target is to get geometry and material inside mesh to clone an object (fbx).
var models in Models js:
var models =
{ scSubj01:
{ obj: man_nodding_obj, txt: man_walking_txt, mesh: null, name: "scSubj01", mixer: null, anims: null, x: -91.67, y: 0, z: -1132.19, rot: leftV, scale: 1.7, action: true, promise: null}
}
Method I called
loadAllObjects()
{
let self = this;
let models = Models.getModels();
for( var model in models)
{
var txt = null;
(function (key)
{
let promise_obj = new Promise( resolve =>
{
self.loader.load(models[key].obj, function (object)
{
resolve(object);
if (models[key].txt != null) { txt = new THREE.TextureLoader().load(models[key].txt); }
object.traverse( function (child) {
if (child.isMesh)
{
child.castShadow = true;
child.receiveShadow = true;
if (txt != null) { child.material.map = txt; }
}
});
if (models[key].action && object.animations[0] != null)
{
models[key].mixer = new THREE.AnimationMixer(object);
models[key].mixer.timeScale = 4;
models[key].anims = object.animations[0];
const act = models[key].mixer.clipAction(models[key].anims);
act.play();
}
models[key].mesh = object.children[0].clone();
object.position.set(models[key].x, models[key].y, models[key].z);
const size = models[key].scale;
object.scale.set(size, size, size);
object.rotation.set(0, models[key].rot, 0);
self.scene.add(object);
}); //, resolve
});
models[key].promise = promise_obj;
})(model);
}
return models;
}