Threejs缩放功能

ThreeJs 缩放功能


本文实现了Threejs+tween对场景中某个位置进行视角转换以及放大效果

animateMove(currentOne, targetOne, currentTwo, targetTwo) {
		//视角转换部分
        let that = this
        let position = {
            x1: currentOne.x,
            y1: currentOne.y,
            z1: currentOne.z,
            x2: targetOne.x,
            y2: targetOne.y,
            z2: targetOne.z
        };
        //关闭控制器
        CONTROLS.enabled = false;

        this.tween = new TWEEN.Tween(position);
        this.tween.to({
            x1: currentTwo.x,
            y1: currentTwo.y,
            z1: currentTwo.z,
            x2: targetTwo.x,
            y2: targetTwo.y,
            z2: targetTwo.z
        }, 1000);

        this.tween.onUpdate(function () {
            CAMERA.position.set(position.x1, position.y1, position.z1)
            CONTROLS.target.set(position.x2, position.y2, position.z2)
            CONTROLS.update();

        })

        this.tween.onComplete(function () {
            ///开启控制器
            CONTROLS.enabled = true;
        })

        this.tween.easing(TWEEN.Easing.Cubic.InOut);
        this.tween.start();
		//放大部分
        const r = {
            scale: 1
        }
        that.tweenScale = new TWEEN.Tween(r);
        that.tweenScale.to({
            scale: 5
        }, 1000)
        that.tweenScale.easing(TWEEN.Easing.Sinusoidal.InOut).repeat(Infinity)
        that.tweenScale.onUpdate(function (e) {

            that.group.scale.set(e.scale, e.scale, e.scale)
            if (e.scale == 5) {
                that.tweenScale.stop()
            }
        });

        that.tweenScale.start();

    }
//调用代码部分 
 that.animateMove(CAMERA.position, CONTROLS.target, new Vector3(-695, 21, 209), new Vector3(-200, -300, -100))
 const rendererOut = () => {
            requestAnimationFrame(rendererOut);
            TWEEN.update()
        };

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值