【ThreeJS 源码修改】多个动画的协同播放

animation/tracks/AnimationMixer.js

//修改后
// advance the time and update apply the animation
update: function ( deltaTime ,myTrackIndex) {
		deltaTime *= this.timeScale;
		const actions = this._actions,
			nActions = this._nActiveActions,
			time = this.time += deltaTime,
			timeDirection = Math.sign( deltaTime ),
			accuIndex = this._accuIndex ^= 1;//0变1 1变0
		// a=b^=k  表示a和b均变为b对应数据二进制的异或

		// run active actions
		for ( let i = 0; i !== nActions; ++ i ) {
			const action = actions[ i ];
			action._update( time, deltaTime, timeDirection, accuIndex );
		}

		// update scene graph
		const bindings = this._bindings,
			nBindings = this._nActiveBindings;
		if(typeof (myTrackIndex)==="undefined"){//使用固定的track
			//nBindings是动画轨迹track的个数
			for ( let i = 0; i !== nBindings; ++ i ) {
				bindings[ i ].apply( accuIndex );
				//accuIndex似乎是0和1的交替
			}
		}else{
			for(var k=0;k< myTrackIndex.length;k++){
				var index=myTrackIndex[k];
				bindings[index].apply( accuIndex );
			}
		}
		return this;
	}

使用方法

//设置动画头部动画
var arr1=[9,10,11,12];
var arr2=[];
var arr0=arr1;
for(var i1=0;i1<glb.animations[0].tracks.length;i1++){
    for(var i2=0;i2<arr0.length;i2++)
        if(arr0[i2]===i1)break;
        if(i2===arr0.length)
            arr2.push(i1)
 }

var mixer1 = new AnimationMixer(glb.scene);
mixer1.clipAction(glb.animations[1]).play();
setInterval(()=>mixer1.update(0.01,arr1),10)

var mixer2 = new AnimationMixer(glb.scene);
mixer2.clipAction(glb.animations[2]).play();
setInterval(()=>mixer.update(0.01,arr2),10)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值