Estoy tratando de recrear un salón de clases con estudiantes y muebles individuales. Debe ser un grupo individual de modelos que luego se pueden asignar a una base de datos para activar y desactivar a voluntad para simular quién asiste y quién falta en clase. Este es mi bloque de código para cargar un modelo de tres js nativo llamado "escritorio" y un modelo GLTF animado en la escena:
import {GLTFLoader} from "./GLTFLoader.js" import * as THREE from 'three' var unit = new THREE.Group(); var deskGeometry = new THREE.BoxBufferGeometry(10, 2, 50 ); var deskMaterial = new THREE.MeshPhongMaterial({ color: 0x49311c, side: THREE.DoubleSide }); var desk = new THREE.Mesh(deskGeometry, deskMaterial); unit.add(desk); //IMPORT GLTF MODEL var loader = new GLTFLoader(); var clock, mixer; clock = new THREE.Clock(); loader.load("./models/salary/scene.gltf", function(gltf){ gltf.scene.traverse( function( node ){ if(node.isMesh){node.castShadow = true, node.receiveShadow = false;} }); //add and position the GLTF model var obj = gltf.scene; gltf.scene.scale.set( 8, 8, 8 ); gltf.scene.position.x = -10; gltf.scene.position.y = -5; gltf.scene.position.z = 3; gltf.scene.rotation.y = 1.07; scene.add(obj); unit.add(obj); // unit is part of an array that the model is nested in, //to create a THREE.group consisted of the student's desk, pc and the student //Playing Animation mixer = new THREE.AnimationMixer( gltf.scene ); console.log( gltf.animations ); mixer.clipAction( gltf.animations[ 0 ] ).play(); }); return unit; } function animate(){ requestAnimationFrame(animate); renderer.setAnimationLoop(()=>renderer.tick()); //for GLTF if ( mixer ) mixer.update( clock.getDelta() ); }El código anterior también implica que el modelo GLTF es parte de un grupo de modelos llamado "unidad", y que hay modelos de tres js nativos mezclados. En un futuro cercano, deseo reemplazar "escritorio" con un modelo GLTF adecuado. Así que intenté usar la promesa para cargar varios modelos como este https://redstapler.co/load-multiple-model-three-js-promise/ , sin embargo, solo mostraba cómo importar modelos estáticos sin animaciones.
¿Cómo debo usar la promesa para cargar varias animaciones también, mientras están anidadas dentro de un grupo TRES?