没有工作,除非源被修改three.js所骨骼动画 [英] Three.js skeletal animations not working unless source is modified

查看:149
本文介绍了没有工作,除非源被修改three.js所骨骼动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用three.js所R68 +我一直需要以非常轻微修改源让我的动画工作正常。未修改仅在每个类型的模型中的一个动画(有每种型号的多产卵)。

Using Three.js r68+ I have been needing to very slightly modify the source to get my animations working correctly. Unmodified only one of each type of model are animated (there are multiple spawns of each type of model).

这是行29407修改后的源(贴code开头的29389):

This is the modified source at line 29407 (posted code beginning at 29389):

THREE.AnimationHandler = {

LINEAR: 0,
CATMULLROM: 1,
CATMULLROM_FORWARD: 2,

//

add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); },
get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); },
remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); },

//

animations: [],

init: function ( data ) {

    // original -> if ( data.initialized === true ) return;
    if ( data.initialized === true ) return data; //<-- modified

该功能现在如果初始化返回动画数据。我假设它不这样做,因为缓存等等。我的问题是什么是动画具有相同名称的动画多种模式的最佳实践?我想唯一命名它们每个型号名称,即:Death_MaleWarrior,但这并没有影响

The function now returns the animation data if initialized. I'm assuming it doesn't do so because of caching. My question is what is the best practice for animating multiple models that have the same animation names? I tried naming them uniquely per model name ie: "Death_MaleWarrior" but this had no effect.

目前我的模型和动画都像这样处理的:

Currently my models and animations are handled like so:

var modelArray = [];
var geoCache   = [];
var loader     = new THREE.JSONLoader(true);

var _MODEL = function(data){

  this.data       = data;  
  this.mesh       = null;
  this.animations = {};
  this.canAnimate = false;

  this.parseAnimations = function () {

    var len,i,anim;

    if (this.mesh) {

          if( this.mesh.geometry.animations ){
              this.canAnimate = true;
              len = this.mesh.geometry.animations.length;
              if( len ){
                  for(i=0;i<len;i++){
                      anim = this.mesh.geometry.animations[i];
                      if( anim ){
                        this.animations[anim.name] = new THREE.Animation( this.mesh, anim );
                      }
                  }
              }
          }
      }
  };

  this.playAnimation = function(label){

    if (this.canAnimate) {
      if( this.animations[label] ){
        //if( this.animations[label].data ){
          this.animations[label].play(0,1);
        //}
      }
    }
    return false;

  };

  this.load = function(geo){

    var mat;

    mat = new THREE.MeshPhongMaterial({color:somecolor, skinning:true})

    this.mesh = new THREE.SkinnedMesh(geo,mat);

    this.mesh.position.x = this.data.position[0];
    this.mesh.position.y = this.data.position[1];
    this.mesh.position.z = this.data.position[2];

    this.parseAnimations();

    scene.add(this.mesh);

    this.playAnimation('Idle');

  };

  this.init = function(){

    var geo;

    if( geoCache[this.data.name] ){
      geo = geoCache[this.data.name];
      this.load(geo); 
    }else{
       geo = loader.parse(JSON.parse(this.data.json)).geometry;
       geoCache[this.data.name] = geo;
       this.load(geo);            
    }        

  };

  this.init();

};

var dataArray = [{name:'MaleWarrior',json:'json_data',position:[x,y,z]},{name:'FemaleWarrior',json:'json_data',position:[x,y,z]},{name:'MaleWarrior',json:'json_data',position:[x,y,z]}];

for(var i=0, len=objectArray.length; i<len; i++){
  modelArray.push(new _MODEL(dataArray[i]) );
}

在这个例子中,第一MaleWarrior将动画但第二不会。如果有一个第二阴她不会动画或者作为动画(即使它是一个新的THREE.Animation())将被视为初始化并且不会返回任何数据。如果我没有检查animations.data在playAnimation存在我得到的错误,未捕获类型错误:无法读取属性'名'未定义上线29665

In this example the first MaleWarrior will animate but the second will not. If there was a second female she would not be animated either as the animation (even though it is a new THREE.Animation() ) will be considered initialized and will not return any data. If I do not check for the existence of animations.data in playAnimation I get the error ""Uncaught TypeError: Cannot read property 'name' of undefined " on line 29665".

是我在做什么绕过动画缓存和伤害的表现?我觉得我失去了一些东西。如何将一个动画没有数据玩?

Is what I'm doing bypassing animation caching and hurting performance? I feel like I'm missing something. How will an animation play without data?

所有的动画名称是相同的,每模式空闲,运行,攻击等。

All animation names are the same for every model "Idle", "Run", "Attack" etc.

任何帮助将是AP preciated。如果我不是足够清楚的,请让我知道。我加入了更多细节。

Any help would be appreciated. If I'm not being clear enough please let me know. I have added additional detail.

推荐答案

这竟然是一个官方three.js所的bug。

This turned out to be an official three.js bug.

https://github.com/mrdoob/three.js/issues/5516

这篇关于没有工作,除非源被修改three.js所骨骼动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆