hi I have a js file importing 2 mixamo characters and 3 animations each, these could change, but the animation is really odd, I have tried several things before my brains was fried and now looking for some help here, if anyone can please take a look at the file provided below and instruct in proper direction would be really appreciated.
File: test.zip
/*
██ ██ █████ ██████ ███████
██ ██ ██ ██ ██ ██ ██
██ ██ ███████ ██████ ███████
██ ██ ██ ██ ██ ██ ██
████ ██ ██ ██ ██ ███████
*/
var width = window.innerWidth;
var height = window.innerHeight;
var fov = 80;
var aspect = width / height;
var near = 0.01;
var far = 10000;
var mouseX = 0;
var mouseY = 0;
var windowHalfX = width / 2;
var windowHalfY = height / 2;
var theta = 0;
var antialias = true;
var alpha = true;
var canvas = $("#canvas")[0];
var camera_init_pos = [550,50,850];
var camera_init_lookAt = [0,0,0];
var showDirections = true;
const clock = new THREE.Clock();
var mixers = [], mixer;
const renderer = new THREE.WebGLRenderer({canvas: canvas, antialias: antialias, alpha: alpha});
renderer.setSize(width, height);
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(camera_init_pos[0], camera_init_pos[1], camera_init_pos[2]);
camera.lookAt(camera_init_lookAt[0], camera_init_lookAt[1], camera_init_lookAt[2]);
const scene = new THREE.Scene();
const controls = new THREE.OrbitControls( camera, renderer.domElement );
const light = new THREE.DirectionalLight( 0xffffff, 0.5 );
light.position.set(5,10,7.5);
scene.add(light);
if (showDirections) {
var arrowPos = new THREE.Vector3( 0,0,0 );
scene.add( new THREE.ArrowHelper( new THREE.Vector3( 1,0,0 ), arrowPos, 20000, 0x7F2020, 20, 10 ) );
scene.add( new THREE.ArrowHelper( new THREE.Vector3( 0,1,0 ), arrowPos, 20000, 0x207F20, 20, 10 ) );
scene.add( new THREE.ArrowHelper( new THREE.Vector3( 0,0,1 ), arrowPos, 20000, 0x20207F, 20, 10 ) );
}
function animate() {
requestAnimationFrame( animate );
controls.update();
const time = Date.now() * 0.001;
let delta = clock.getDelta();
for ( let i = 0, l = mixers.length; i < l; i ++ ) {
mixers[ i ].update( delta );
}
render();
}
function render() {
renderer.render( scene, camera );
}
function resize(){
renderer.setSize(width,height);
camera.aspect = aspect;
camera.updateProjectionMatrix();
}
/*
██████ ███████ ██████ ██ ███ ██
██ ██ ██ ██ ██ ████ ██
██████ █████ ██ ███ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██████ ██ ██ ████
*/
var models = [];
var fbxLoader = new THREE.FBXLoader();
//models
fbxLoader.load('assets/fbx/model1.fbx', function(fbx) {
var model = fbx;
model.position.set(0,0,0);
models.push(model.uuid);
model.animations = [];
var mixer = new THREE.AnimationMixer( model );
mixers.push(mixer);
scene.add(model);
});
fbxLoader.load('assets/fbx/model2.fbx', function(fbx) {
var model = fbx;
model.position.set(300,0,0);
models.push(model.uuid);
model.animations = [];
var mixer = new THREE.AnimationMixer( model );
mixers.push(mixer);
scene.add(model);
});
console.log('models', models, 'mixers', mixers);
// animations
setTimeout(function() {
//model0
fbxLoader.load('assets/fbx/anim1.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[0];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
fbxLoader.load('assets/fbx/anim2.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[0];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
fbxLoader.load('assets/fbx/anim3.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[0];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
//model1
fbxLoader.load('assets/fbx/anim1.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[1];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
fbxLoader.load('assets/fbx/anim2.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[1];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
fbxLoader.load('assets/fbx/anim3.fbx', function(fbx) {
var anim = fbx.animations[0];
var uuid = models[1];
var model = scene.getObjectByProperty('uuid',uuid);
model.animations.push(anim);
var mixer = mixers.filter(function(m) {return m.getRoot().uuid == uuid})[0];
mixer.clipAction(anim);
});
setTimeout(function() {
mixers.forEach(function ( mixer ) {
var model = mixer.getRoot();
if (model.animations && model.animations.length > 0) {
$.each(model.animations, function(a,clip) {
var action = mixer.clipAction( clip )
action
.reset()
.setEffectiveTimeScale( 1 )
.setEffectiveWeight( 1 )
// .setLoop(THREE.LoopOnce)
.fadeIn( 1 )
.play();
action.clampWhenFinished = true;
});
}
});
console.log(scene);
}, 3000);
}, 5000);
animate();
window.addEventListener('resize',resize);