ThreeJS车辆简单渲染及控制系统

简单的PBR应用,该例子仅有简单全局光,多依赖环境光,优化金属光泽及车漆效果,材质直接使用threejs editor编辑好导出glb直接使用。已开发控制遥杆进行运动控制。

缩略图
主要运动控制代码:

        var brakingDeceleration = 1;
        if (this.touchControls.brake) brakingDeceleration = this.brakePower;
        if (this.touchControls.moveForward) {
            this.speed = THREE.Math.clamp(this.speed - delta * this.acceleration, maxSpeedReverse, this.maxSpeed);
            acceleration = THREE.Math.clamp(acceleration - delta, -1, 1);
        }
        if (this.touchControls.moveBackward) {
            this.speed = THREE.Math.clamp(this.speed + delta * accelerationReverse, maxSpeedReverse, this.maxSpeed);
            acceleration = THREE.Math.clamp(acceleration + delta, -1, 1);
        }
        if (this.touchControls.moveLeft) {
            wheelOrientation = THREE.Math.clamp(wheelOrientation + delta * steeringWheelSpeed, -maxSteeringRotation, maxSteeringRotation);
        }
        if (this.touchControls.moveRight) {
            wheelOrientation = THREE.Math.clamp(wheelOrientation - delta * steeringWheelSpeed, -maxSteeringRotation, maxSteeringRotation);
        }
        // this.speed decay
        if (!(this.touchControls.moveForward || this.touchControls.moveBackward)) {
            if (this.speed > 0) {
                var k = exponentialEaseOut(this.speed / this.maxSpeed);
                this.speed = THREE.Math.clamp(this.speed - k * delta * deceleration * brakingDeceleration, 0, this.maxSpeed);
                acceleration = THREE.Math.clamp(acceleration - k * delta, 0, 1);
            } else {
                var k = exponentialEaseOut(this.speed / maxSpeedReverse);
                this.speed = THREE.Math.clamp(this.speed + k * delta * accelerationReverse * brakingDeceleration, maxSpeedReverse, 0);
                acceleration = THREE.Math.clamp(acceleration + k * delta, -1, 0);
            }
        }

演示地址:
点我

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值