I’m trying to add a skinned model into a scene using glft loader. The problem is that I’m not sure how to do it and I get weird results. When I imported my model into the scene it looked squashed but then I tested it in the gltf viewer it worked perfectly.
To give you an idea of what the problem looks like, I have also tested it with the Cesium man model and here is what happens:
I have been reading about mesh skinning but the examples I saw were using json/js files so I’m not sure if I have to use THREE.SkinnedMesh three.js docs?
When looking at the gltf extensions example, I could just find:
var animations = gltf.animations;
if ( animations && animations.length ) {
mixer = new THREE.AnimationMixer( object );
for ( var i = 0; i < animations.length; i ++ ) {
var animation = animations[ i ];
// There's .3333 seconds junk at the tail of the Monster animation that
// keeps it from looping cleanly. Clip it at 3 seconds
if ( sceneInfo.animationTime )
animation.duration = sceneInfo.animationTime;
mixer.clipAction( animation ).play();
}
}
I tried it but it didn’t work. I think I’m missing something simple in the process.
Any help or advice will be much appreciated! Thanks
loader.load( '/gltf-skin/assets/models/CesiumMan.gltf', function ( gltf ) {
var object = gltf.scene;
var animations = gltf.animations;
if ( animations && animations.length ) {
mixer = new THREE.AnimationMixer( object );
for ( var i = 0; i < animations.length; i ++ ) {
mixer.clipAction( animations[ i ] ).play();
}
}
scene.add( object );
} );
There are a couple more questions I have for this topic:
How do I export multiple animations from blender to gltf? I can see that the cesium man has multiple animations to it, but when working on my model and exporting to gltf, it exports only the current one.
EDIT: I have now found a solution that works for me: instead of using the glTF-Blender_exporter, I tried the Kupoman blendertogltf and it exported all the animations. I’m not sure whether I was putting the wrong settings in the other exporter, or it didn’t have the feature.
For my project I want to use multiple animations of the same character that will be activated by different events - the basic example that I have uploaded is on click: I have now added a new file to my git repo with working skins: gltf-skin/anim-click.html at master · m-a-y/gltf-skin · GitHub also: Gltf - skin test
The code works as expected but I’m not sure if this is the right/best way to achieve it. For example, can I use multiple mixers on the same object? Is there a better or cleaner way to achieve the effect?
The glTF 2.0 Exporter for Blender can only export a single action right now.
You should have a single mixer per object. For a simple switch between two animations, just stop the first action and then play the second. Crossfading between animations is also supported:
That makes sense. I have now added an updated file that is using one mixer for two animations but am still not sure if I’m doing it correctly: demo, github code
And thanks for suggesting crossfade - I like the effect and will probably give it a try for my project.