I’m trying to follow threejs.org/examples/webgl_loader_fbx and import an fbx with an animation.
Im using the same fbx as the example, and I am able to display the model. Just no animations. I do:
addModelToScene(position, string, materialName)
{
//var loader = new THREE.ObjectLoader();
var localThis = this;
//const texture = new THREE.TextureLoader().load( "./src/images/cartdiff.jpg");
const texture = new THREE.TextureLoader().load( "./src/images/DeadEnds_globalmaterial.png");
texture.encoding = THREE.sRGBEncoding;
var material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.5,
metalness: 0.5,
refractionRatio: 0.98,
envMapIntensity: 1.0,
map: texture,
//normalMap: materials.normalMap,
//roughnessMap: materials.roughnessMap,
//metalnessMap: materials.metalnessMap,
//envMap: me.reflectionCube,
normalScale: new THREE.Vector2( 1, -1 )
});
switch(materialName)
{
case 'globalMat':
material = new THREE.MeshPhysicalMaterial({
color: '#00ff00',
metalness: .58,
emissive: '#000000',
roughness: .05,
});
model.material.needsUpdate = true;
break;
default:
console.log("no material for custom model");
break;
}
var geoFromScene = new THREE.Geometry();
var FBXLoader = require('three-fbx-loader');
var loader = new FBXLoader();
loader.load( string, function ( object ) {
localThis.mixer = new THREE.AnimationMixer( object );
var action = localThis.mixer.clipAction( object.animations[ 0 ] );
action.play();
object.traverse( function ( child ) {
if ( child.isMesh ) {
child.castShadow = true;
child.receiveShadow = true;
}
} );
object.position.set(5,5,-8)
object.scale.set(0.1, 0.1, 0.1);
localThis.scene.add( object );
} );
```
Then in my animate() function which IS CALLED every frame, I do:
animate() {
this.draw();
const resistance = 0.002;
this.target.x = ( 1 - this.mouse.x ) * resistance;
this.target.y = ( 1 - this.mouse.y ) * resistance;
this.camera.rotation.x += 0.05 * ( this.target.y - this.camera.rotation.x );
this.camera.rotation.y += 0.05 * ( this.target.x - this.camera.rotation.y );
//anything glass
this.sphere.visible = false;
//this.refractSphereCamera.clear();
//this.refractSphereCamera.updateCubeMap( this.renderer, this.scene );
//this.refractSphereCamera.update();
this.sphere.visible = true;
this.renderer.render(this.scene, this.camera);
requestAnimationFrame(this.animate.bind(this));
console.log(this.mixer);
this.mixer.update(this.clock.getDelta());
}
Yet nothing. What is happening here? Have the model, just no animations. Console.log mixer DOES return the mixer.