Reputation: 1780
I'll preface this by saying I'm new to Blender / 3DS MAX / ThreeJS and graphics programming.
I exported an animation of a Mutalisk (from StarCraft) flapping its wings from the StarCraft editor as an .m3 file, which I imported into Blender. Upon exporting, I am able to import the resulting .json into my ES6 application, but for some reason, using a THREE.Animation, while the position of the imported Mutalisk properly changes, it bobs around, the actual flapping of the Mutalisk object doesn't occur.
My renderer looks like this:
import THREE from 'three';
export default class Renderer {
constructor(game, canvas) {
this.game = game;
this.canvas = canvas;
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(75, this.canvas.width / this.canvas.height, 1, 10000);
this.camera.position.z = 2;
this.camera.position.y = 1;
this.clock = new THREE.Clock;
this.renderer = new THREE.WebGLRenderer({ canvas: this.canvas });
this.renderer.setSize( this.canvas.width, this.canvas.height );
}
// called by my Game class, which waits for the mesh to load before attempting to add it to the scene
addMeshToScene(mesh) {
this.mesh = mesh;
this.scene.add(this.mesh);
this.animation = new THREE.Animation(
this.mesh,
this.mesh.geometry.animations[ 2 ]
);
this.animation.play();
}
renderFrame() {
THREE.AnimationHandler.update(this.clock.getDelta());
this.renderer.render(this.scene, this.camera);
}
}
And here's the render. As I said, the Mutalisk in my browser is bouncing along the Y-axis, but not flapping.
Can anyone shed some light on why the movement happens, but not the flapping?
Edit: here are my Blender export settings.
Upvotes: 1
Views: 1166
Reputation: 1780
Solved. The issue was that materials have to be in skinning mode to properly wrap the skeleton. When I created my mesh from JSON, I had to set material.skinning = true
import THREE from 'three';
export default class Mesh {
constructor(name) {
this.name = name;
this.loaded = false;
this.filepath = `./meshes/${this.name}.json`
this.load();
}
load() {
var loader = new THREE.JSONLoader();
loader.load(this.filepath, (geometry) => {
this.geometry = geometry;
var material = new THREE.MeshBasicMaterial( { color: 0x00ffff, wireframe: true } );
material.skinning = true; // this is where the magic happens
this.mesh = new THREE.SkinnedMesh(geometry, material);
this.loaded = true;
});
}
}
Upvotes: 0