Baylon.js 第三节 连接动画

首先要定义一个接下来展示的动画,获取一个动画使用:

    var nextAnimation=function (){
        scene.beginDirectAnimation(box,[up],0,4*framerate,true)
    }

 然后展示动画:

scene.beginDirectAnimation(box,[rotation],0,4*framerate,false,0.5,nextAnimation)

 其中的参数Loop必须为false,0.5是动画的相对播放速度,nextAnimation就是即将播放的下一个动画。

	let camera=lightAndCamera()
    let ground=BABYLON.MeshBuilder.CreateGround('ground',
        {width:100,height:100},scene)
    let box=BABYLON.MeshBuilder.CreateBox('box',{width:5,height:3,depth:2},scene)
    const framerate=10
    const up=new BABYLON.Animation('animation','position',framerate,
        BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
        BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE)
    const keysFrames=[]
    keysFrames.push({
        frame:framerate,
        value:new BABYLON.Vector3(0,0,0)
    })
    keysFrames.push({
        frame:2*framerate,
        value:new BABYLON.Vector3(10,5,0)
    })
    keysFrames.push({
        frame:4*framerate,
        value:new BABYLON.Vector3(6,10,10)
    })
    up.setKeys(keysFrames)
    let rotation=new BABYLON.Animation('animation','rotation.x',framerate,
        BABYLON.Animation.ANIMATIONTYPE_FLOAT,
        BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE)
    const framArr=[]
    framArr.push({
        frame:framerate,
        value:0
    })
    framArr.push({
        frame:2*framerate,
        value:Math.PI
    })
    framArr.push({
        frame:4*framerate,
        value:Math.PI*2
    })
    rotation.setKeys(framArr)
    //scene.beginDirectAnimation(box,[rotation,up],0,4*framerate,true)
    var nextAnimation=function (){
        scene.beginDirectAnimation(box,[up],0,4*framerate,true)
    }
    scene.beginDirectAnimation(box,[rotation],0,4*framerate,false,0.5,nextAnimation)
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值