Threejs 3D头像滚动抽奖

  <div
      ref="threeContainer"
      style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: flex-start"
    ></div>

核心代码 

// helix 螺旋
      var vector = new THREE.Vector3();
      let arrIndex = 72;

      for (var i = 0, l = this.objects.length; i < l; i++) {
        var phi = (i / 2) * 0.175 + Math.PI;
        var object = new THREE.Object3D();
        object.position.x = 1600 * Math.sin(phi);
        object.position.y = -(parseInt(i / arrIndex) * 120);
        object.position.z = 1600 * Math.cos(phi);
        vector.x = object.position.x * 2;
        vector.y = object.position.y;
        vector.z = object.position.z * 2;
        object.lookAt(vector);
        this.targets.helix.push(object);
      }
      function play() {
        // 放大进入动画
        that.parent.visible = true;
        // that.parent.scale.set(.8, .8, .8)
        var enterBlowUp = new TWEEN.Tween({
          z: 0.01,
        })
          .to(
            {
              z: 3,
            },
            2e3,
          )
          .onUpdate(function (t) {
            that.parent.scale.set(t, t, t);
          });
        // 停止缩小动画
        var stopShrink = new TWEEN.Tween(that.parent.scale)
          .to(
            {
              x: 0.01,
              y: 0.01,
              z: 0.01,
            },
            0.6e3,
          )
          .onComplete(function (t) {
            destroyed();
          });
        // 放大动画
        var runBlowUp = new TWEEN.Tween(that.parent.scale)
          .to(
            {
              x: 2.8,
              y: 2.8,
              z: 2.8,
            },
            2e3,
          )
          .delay(5e3);
        // 缩小动画
        var runShrink = new TWEEN.Tween(that.parent.scale)
          .to(
            {
              x: 0.8,
              y: 0.8,
              z: 0.8,
            },
            2e3,
          )
          .delay(3e3);
        // 循环旋转动画
        var rotateLoop = new TWEEN.Tween(that.parent.rotation)
          .to(
            {
              y: -2 * Math.PI,
            },
            12e3,
          )
          .repeat(1 / 0)
          .onComplete(function () {
            that.parent.rotation.y = 0;
          })
          .onUpdate(function () {
            that.lotteryPlayState == 'stop' &&
              (runShrink.stop(), runBlowUp.stop(), rotateLoop.stop(), stopShrink.start());
          });

        rotateLoop.start();
        runShrink.chain(runBlowUp);
        runBlowUp.chain(runShrink);
        // enterBlowUp.onComplete(function(e){
        runBlowUp.start();
        // });
        // enterBlowUp.start();

        that.lotteryTweenArr.push(enterBlowUp);
        that.lotteryTweenArr.push(stopShrink);
        that.lotteryTweenArr.push(runBlowUp);
        that.lotteryTweenArr.push(runShrink);
        that.lotteryTweenArr.push(rotateLoop);
      }

      function stop() {
        that.lotteryPlayState = 'stop';
      }

      return {
        play: play,
        stop: stop,
        playing: false,
      };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

斥方遒(Oliver)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值