【问题标题】:Mesh with multiple animations具有多个动画的网格
【发布时间】:2015-03-07 15:12:16
【问题描述】:

我试图理解 Three.js 中的这个例子:http://threejs.org/examples/#webgl_animation_skinning_blending。我对这部分代码(BlendCharacter.js 文件)有一些问题。

this.load = function ( url, onLoad ) {

    var scope = this;

    var loader = new THREE.JSONLoader();
    loader.load( url, function( geometry, materials ) {

        var originalMaterial = materials[ 0 ];
        originalMaterial.skinning = true;

        THREE.SkinnedMesh.call( scope, geometry, originalMaterial ); // QUESTION (2)

        // Create the animations

        for ( var i = 0; i < geometry.animations.length; ++i ) {

            var animName = geometry.animations[ i ].name; // QUESTION (1)
            scope.animations[ animName ] = new THREE.Animation( scope, geometry.animations[ i ] );

        }

        (...)

    } );
};

我有两个问题:

  • (Main) 3D 对象(Three.js 格式)如何已经有了带名称的动画?在 for 循环中,"geometry.animation[i].name""walk", "idle" and "run"。我用 maya 和 blender(初级)制作了动画,但我不知道如何在同一个网格上导出多个动画,以及如何命名它们。

  • (Less) 这是 JavaScript 语法的问题。为什么"var scope = this;"?我试图在"THREE.SkinnedMesh.call(scope, geometry, originalMaterial);" 中将"scope" 替换为"this",但这使它不再有效。

感谢您阅读我的问题!

PS : 对不起我的英语...

【问题讨论】:

标签: javascript 3d three.js blender maya


【解决方案1】:

(主要)问题:当您使用 Blender 并创建动画时,它会自动为动画创建名称,您可以在动作编辑器上更改名称。现在可以为网格导出多个动画。在 javascript 代码中,您可以通过 id (geometry.animations[id]) 调用每个动画。

【讨论】:

  • 是的,我花了一段时间才发现这一点。我看过很多项目,他们只有一个动画,但是搅拌机中的这个可以在“/examples/models/skinned/marine/marine_anims_core.blend”找到(在github下载three.js代码)。打开后,您可以轻松地在操作编辑器菜单中找到。祝你好运!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 2015-04-18
  • 1970-01-01
  • 2019-11-17
相关资源
最近更新 更多