且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

三个JS中的动画

更新时间:2023-10-25 09:07:34

新系统可与动画剪辑配合使用(如果正确,则自r74起). 这是我的Blender导出的JSON模型的示例.

New System works with animation clips (since r74 if im right). Heres a sample of my Blender exported JSON models.

var mixer;
var actions = {};
var loader = new THREE.JSONLoader();

loader.load( "webgl/models/model.json", function ( geometry, materials ) {

    model = new THREE.SkinnedMesh( geometry, materials, false );
    for(var x=0;x<materials.length();x++) materials[x].skinning = true;
    mixer = new THREE.AnimationMixer(model );

    //idle
    actions.idle = mixer.clipAction(geometry.animations[0]);
    actions.idle.setLoop(THREE.LoopRepeat);
    actions.idle.clampWhenFinished = true;
    actions.idle.play();

    //walk
    actions.walk = mixer.clipAction(geometry.animations[1]);
    actions.walk.setLoop(THREE.LoopRepeat);
    actions.walk.clampWhenFinished = true;

    scene.add( model );

}

每个导出的动画都存储在array.animations数组中. 在我的示例中,我明确地知道哪个索引是哪个动画,但是通过名称(geometry.animations[x].name)手动对其进行映射也非常容易.

Every exported Animation gets stored in the array geometry.animations. In my example i explicitly know which index is which animation but its also very easy to map it manually by name: (geometry.animations[x].name).

然后在动画循环中,您必须定期更新混音器
if(typeof mixer != "undefined") mixer.update(delta);

In the animation loop you then have to update the mixer regularly
if(typeof mixer != "undefined") mixer.update(delta);

http://yomotsu.net获得了我的信息/blog/2015/10/31/three-r73-anim.html

以下是动画动作的相关源代码: https://github.com/mrdoob/three.js/blob/ab93512c7a44bd98e669592b3db441c04a2057f4/src/animation/AnimationAction.js

Also heres the regarding sourcecode for an animation action: https://github.com/mrdoob/three.js/blob/ab93512c7a44bd98e669592b3db441c04a2057f4/src/animation/AnimationAction.js

从Blender导出有很多可能的陷阱,尤其是当 使用骨骼网格动画(!=变形).

The Export from Blender has A LOT of possible snares especially when using Skeletal mesh animations (!= morphs).

  • 所有骨骼/骨架/网格的比例值应精确为"1",并且 永远不会再被感动:)
    (关键帧还应仅具有键设置LocRot)
  • 导出时应用修改器"按钮总是使我失真
  • 在导出时仅选择网格(而不是骨架或骨骼)
  • Scale values of all bones / Armature / mesh should be exactly "1" and never ever be touched again :)
    (Keyframes also should only have keying set LocRot)
  • "apply modifiers" button while export always caused me distortions
  • select only the mesh while exporting (not the armature or bones)

我的导出设置:

my export settings:

希望对未来的探险家有帮助:)

Hope that helps future explorers :)