loader.load(
fileName,
function (gltf) {
model = gltf.scene;
scene.add(model);
loaderBaju.load(
fileNameBaju,
function (gltfBaju) {
modelBaju = gltfBaju.scene;
scene.add(modelBaju);
modelBaju.position.y = -90;
addLight();
adjustModelAndCameraBaju();
mixer3 = new THREE.AnimationMixer(modelBaju);
const animationActionBaju = mixer3.clipAction(animasi); // Assuming the first animation
animationActionBaju.play();
// Apply the saved animation clip from mixer1 to mixer2
if (saveAnimationClip) {
mixer3.stopAllAction(); // Stop any ongoing actions on mixer2
const animationActionForMixer3 = mixer3.clipAction(saveAnimationClip);
animationActionForMixer3.play();
}
scene.add(camera);
// animate();
animateModel3();
},
undefined,
function (e) {
console.error(e);
}
);
loaderCelana.load(
fileNameCelana,
function (gltfCelana) {
modelCelana = gltfCelana.scene;
scene.add(modelCelana);
modelCelana.position.y = -90;
addLight();
setTexture();
adjustModelAndCameraCelana();
mixer2 = new THREE.AnimationMixer(modelCelana);
const animationActionCelana = mixer2.clipAction(animasi); // Assuming the first animation
animationActionCelana.play();
// Apply the saved animation clip from mixer1 to mixer2
if (saveAnimationClip) {
mixer2.stopAllAction(); // Stop any ongoing actions on mixer2
const animationActionForMixer2 = mixer2.clipAction(saveAnimationClip);
animationActionForMixer2.play();
}
scene.add(camera);
// animate();
animateModel2();
},
undefined,
function (e) {
console.error(e);
}
);
addLight();
adjustModelAndCamera();
mixer1 = new THREE.AnimationMixer(model);
animasi = gltf.animations[0];
animationAction = mixer1.clipAction(gltf.animations[0]);
animationAction.play();
saveAnimationClip = gltf.animations[0].clone();
scene.add(camera);
animateModel1();
return animasi;
},
undefined,
function (e) {
console.error(e);
}
);
function adjustModelAndCameraCelana() {
// Perform adjustments for the second model (model2)
const boxCelana = new THREE.Box3().setFromObject(modelCelana);
const sizeCelana = boxCelana.getSize(new THREE.Vector3()).length();
const centerCelana = boxCelana.getCenter(new THREE.Vector3());
// Adjust the second model’s position
modelCelana.position.x -= centerCelana.x;
modelCelana.position.y -= centerCelana.y + 25;
modelCelana.position.z -= centerCelana.z + 3.5;
camera.near = sizeCelana / 100;
camera.far = sizeCelana * 100;
camera.updateProjectionMatrix();
// Set the second camera’s position and lookAt
const cameraPositionCelana = new THREE.Vector3(
centerCelana.x + sizeCelana / 0.2,
centerCelana.y + sizeCelana / 2,
centerCelana.z + sizeCelana / 100
);
camera.position.copy(cameraPositionCelana);
camera.lookAt(centerCelana);
}
function adjustModelAndCameraBaju() {
// Perform adjustments for the third model (model3)
const boxBaju = new THREE.Box3().setFromObject(modelBaju);
const sizeBaju = boxBaju.getSize(new THREE.Vector3()).length();
const centerBaju = boxBaju.getCenter(new THREE.Vector3());
// Adjust the third model’s position
modelBaju.position.x -= centerBaju.x;
modelBaju.position.y -= centerBaju.y - 100;
modelBaju.position.z -= centerBaju.z + 3.5;
console.log(modelBaju.position.x);
console.log(modelBaju.position.y);
camera.near = sizeBaju / 100;
camera.far = sizeBaju * 100;
camera.updateProjectionMatrix();
// Set the third camera’s position and lookAt
const cameraPositionBaju = new THREE.Vector3(
centerBaju.x + sizeBaju / 0.2,
centerBaju.y + sizeBaju / 2,
centerBaju.z + sizeBaju / 100
);
camera.position.copy(cameraPositionBaju);
camera.lookAt(centerBaju);
}
function adjustModelAndCamera() {
// Perform adjustments for the first model (model1)
const box = new THREE.Box3().setFromObject(model);
const size = box.getSize(new THREE.Vector3()).length();
const center = box.getCenter(new THREE.Vector3());
// Adjust the model’s position
model.position.x -= center.x;
model.position.y -= center.y;
model.position.z -= center.z;
camera.near = size / 200;
camera.far = size * 200;
camera.updateProjectionMatrix();
// Set the camera’s position and lookAt
const cameraPosition = new THREE.Vector3(
center.x + size / 0.2,
center.y + size / 2,
center.z + size / 100
);
camera.position.copy(cameraPosition);
camera.lookAt(center);
}
Posisiton modelBaju cannot change, can you solve this ?