@babylonjs-toolkit/next 9.20.0 → 9.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/project.d.ts +123 -0
- package/lib/project.d.ts.map +1 -1
- package/lib/project.js +478 -1
- package/lib/scenemanager.d.ts +2 -0
- package/lib/scenemanager.d.ts.map +1 -1
- package/lib/scenemanager.js +491 -2
- package/package.json +13 -13
package/lib/project.js
CHANGED
|
@@ -2024,6 +2024,9 @@ export class StandardCarController extends ScriptComponent {
|
|
|
2024
2024
|
if (this._engineAudioSource == null)
|
|
2025
2025
|
SceneManager.LogWarning("No engine audio source manager found for: " + this.transform.name);
|
|
2026
2026
|
this._rigidbody = this.getComponent("RigidbodyPhysics");
|
|
2027
|
+
if (this._rigidbody == null) {
|
|
2028
|
+
SceneManager.LogWarning("No rigidbody physics component found for: " + this.transform.name + " - vehicle control is disabled. If this transform was set up in code, check that its components were not constructed with _registerComponentAlias set to false.");
|
|
2029
|
+
}
|
|
2027
2030
|
if (this._rigidbody != null) {
|
|
2028
2031
|
this.raycastVehicle = RaycastVehicle.GetInstance(this.scene, this._rigidbody);
|
|
2029
2032
|
if (this.transform.physicsBody != null && this._rigidbody != null && this.raycastVehicle != null) {
|
|
@@ -4121,6 +4124,480 @@ StandardCarController.DEFAULT_SPEED_FACTOR = 1.0;
|
|
|
4121
4124
|
StandardCarController.DEFAULT_DONUT_FACTOR = 1.0;
|
|
4122
4125
|
StandardCarController.DEFAULT_BRAKE_DEADZONE = 0.5;
|
|
4123
4126
|
StandardCarController.SimplexNoise2D = SimplexNoise.createNoise2D();
|
|
4127
|
+
export class StandardKartController extends ScriptComponent {
|
|
4128
|
+
constructor() {
|
|
4129
|
+
super(...arguments);
|
|
4130
|
+
this.chassisTransform = null;
|
|
4131
|
+
this.exhaustLeftTransform = null;
|
|
4132
|
+
this.exhaustRightTransform = null;
|
|
4133
|
+
this.frontLeftWheelTrans = null;
|
|
4134
|
+
this.frontRightWheelTrans = null;
|
|
4135
|
+
this.backLeftWheelTrans = null;
|
|
4136
|
+
this.backRightWheelTrans = null;
|
|
4137
|
+
this.frontLeftWheelCollider = null;
|
|
4138
|
+
this.frontRightWheelCollider = null;
|
|
4139
|
+
this.backLeftWheelCollider = null;
|
|
4140
|
+
this.backRightWheelCollider = null;
|
|
4141
|
+
this.frontLeftWheelMesh = null;
|
|
4142
|
+
this.frontRightWheelMesh = null;
|
|
4143
|
+
this.backLeftWheelMesh = null;
|
|
4144
|
+
this.backRightWheelMesh = null;
|
|
4145
|
+
this.topSpeed = 25.0;
|
|
4146
|
+
this.accelerationTime = 2.2;
|
|
4147
|
+
this.coastDeceleration = 6.0;
|
|
4148
|
+
this.brakeDeceleration = 18.0;
|
|
4149
|
+
this.gravitationalForce = 2.2;
|
|
4150
|
+
this.steeringYawRate = 1.1;
|
|
4151
|
+
this.steeringRamp = 0.18;
|
|
4152
|
+
this.maxSteeringAngle = 28.0;
|
|
4153
|
+
this.driftEnabled = true;
|
|
4154
|
+
this.driftYawRate = 1.658;
|
|
4155
|
+
this.driftStickShare = 0.5;
|
|
4156
|
+
this.driftBaseShare = 0.5;
|
|
4157
|
+
this.driftTargetAngle = 45.0;
|
|
4158
|
+
this.driftMaxAngle = 60.0;
|
|
4159
|
+
this.driftAngleRampRate = 223.0;
|
|
4160
|
+
this.driftAngleUnwindRate = 48.0;
|
|
4161
|
+
this.hopDuration = 0.25;
|
|
4162
|
+
this.hopImpulse = 4.5;
|
|
4163
|
+
this.minimumDriftSpeed = 13.75;
|
|
4164
|
+
this.driftLatchThreshold = 0.2;
|
|
4165
|
+
this.driftSpeedRetention = 1.0;
|
|
4166
|
+
this.driftFrictionSlip = 0.05;
|
|
4167
|
+
this.miniTurboEnabled = true;
|
|
4168
|
+
this.miniTurboTime = 0.6;
|
|
4169
|
+
this.superMiniTurboTime = 1.6;
|
|
4170
|
+
this.ultraMiniTurboTime = 2.8;
|
|
4171
|
+
this.boostSpeedFactor = 1.35;
|
|
4172
|
+
this.boostDurationMini = 0.6;
|
|
4173
|
+
this.boostDurationSuper = 1.1;
|
|
4174
|
+
this.boostDurationUltra = 1.8;
|
|
4175
|
+
this._rigidbody = null;
|
|
4176
|
+
this._raycastVehicle = null;
|
|
4177
|
+
this._engineAudioSource = null;
|
|
4178
|
+
this.FRONT_LEFT = -1;
|
|
4179
|
+
this.FRONT_RIGHT = -1;
|
|
4180
|
+
this.BACK_LEFT = -1;
|
|
4181
|
+
this.BACK_RIGHT = -1;
|
|
4182
|
+
this._defaultFriction = 10.0;
|
|
4183
|
+
this._steer = 0;
|
|
4184
|
+
this._throttle = 0;
|
|
4185
|
+
this._brake = 0;
|
|
4186
|
+
this._driftHeld = false;
|
|
4187
|
+
this._driftWasHeld = false;
|
|
4188
|
+
this._steerRequest = 0;
|
|
4189
|
+
this._driftRequest = false;
|
|
4190
|
+
this._externalBoost = 0;
|
|
4191
|
+
this._driftState = 0;
|
|
4192
|
+
this._driftDirection = 0;
|
|
4193
|
+
this._driftStage = 0;
|
|
4194
|
+
this._driftTime = 0;
|
|
4195
|
+
this._hopTime = 0;
|
|
4196
|
+
this._hopSteer = 0;
|
|
4197
|
+
this._hopPending = false;
|
|
4198
|
+
this._driftAngle = 0;
|
|
4199
|
+
this._yawRate = 0;
|
|
4200
|
+
this._planarSpeed = 0;
|
|
4201
|
+
this._groundedWheels = 0;
|
|
4202
|
+
this._airborneTime = 0;
|
|
4203
|
+
this._boostTimer = 0;
|
|
4204
|
+
this._boostFactor = 1.0;
|
|
4205
|
+
this._groundNormal = new BABYLON.Vector3(0, 1, 0);
|
|
4206
|
+
this._groundForward = new BABYLON.Vector3(0, 0, 1);
|
|
4207
|
+
this._velocity = new BABYLON.Vector3();
|
|
4208
|
+
this._angular = new BABYLON.Vector3();
|
|
4209
|
+
this._travel = new BABYLON.Vector3();
|
|
4210
|
+
this._scratchA = new BABYLON.Vector3();
|
|
4211
|
+
this._scratchB = new BABYLON.Vector3();
|
|
4212
|
+
this._worldMatrix = new BABYLON.Matrix();
|
|
4213
|
+
}
|
|
4214
|
+
get currentSpeed() { return this._planarSpeed; }
|
|
4215
|
+
get slideAngle() { return this._driftAngle; }
|
|
4216
|
+
get driftState() { return this._driftState; }
|
|
4217
|
+
get driftDirection() { return this._driftDirection; }
|
|
4218
|
+
get driftStage() { return this._driftStage; }
|
|
4219
|
+
get isAirborne() { return this._groundedWheels <= 0; }
|
|
4220
|
+
awake() { this.awakeKartState(); }
|
|
4221
|
+
start() { this.initKartState(); }
|
|
4222
|
+
update() { this.updateKartState(); }
|
|
4223
|
+
step() { this.stepKartState(); }
|
|
4224
|
+
destroy() { this.destroyKartState(); }
|
|
4225
|
+
awakeKartState() {
|
|
4226
|
+
this.topSpeed = this.getProperty("topSpeed", this.topSpeed);
|
|
4227
|
+
this.accelerationTime = this.getProperty("accelerationTime", this.accelerationTime);
|
|
4228
|
+
this.coastDeceleration = this.getProperty("coastDeceleration", this.coastDeceleration);
|
|
4229
|
+
this.brakeDeceleration = this.getProperty("brakeDeceleration", this.brakeDeceleration);
|
|
4230
|
+
this.gravitationalForce = this.getProperty("gravitationalForce", this.gravitationalForce);
|
|
4231
|
+
this.steeringYawRate = this.getProperty("steeringYawRate", this.steeringYawRate);
|
|
4232
|
+
this.steeringRamp = this.getProperty("steeringRamp", this.steeringRamp);
|
|
4233
|
+
this.maxSteeringAngle = this.getProperty("maxSteeringAngle", this.maxSteeringAngle);
|
|
4234
|
+
this.driftEnabled = this.getProperty("driftEnabled", this.driftEnabled);
|
|
4235
|
+
this.driftYawRate = this.getProperty("driftYawRate", this.driftYawRate);
|
|
4236
|
+
this.driftStickShare = this.getProperty("driftStickShare", this.driftStickShare);
|
|
4237
|
+
this.driftBaseShare = this.getProperty("driftBaseShare", this.driftBaseShare);
|
|
4238
|
+
this.driftTargetAngle = this.getProperty("driftTargetAngle", this.driftTargetAngle);
|
|
4239
|
+
this.driftMaxAngle = this.getProperty("driftMaxAngle", this.driftMaxAngle);
|
|
4240
|
+
this.driftAngleRampRate = this.getProperty("driftAngleRampRate", this.driftAngleRampRate);
|
|
4241
|
+
this.driftAngleUnwindRate = this.getProperty("driftAngleUnwindRate", this.driftAngleUnwindRate);
|
|
4242
|
+
this.hopDuration = this.getProperty("hopDuration", this.hopDuration);
|
|
4243
|
+
this.hopImpulse = this.getProperty("hopImpulse", this.hopImpulse);
|
|
4244
|
+
this.minimumDriftSpeed = this.getProperty("minimumDriftSpeed", this.minimumDriftSpeed);
|
|
4245
|
+
this.driftLatchThreshold = this.getProperty("driftLatchThreshold", this.driftLatchThreshold);
|
|
4246
|
+
this.driftSpeedRetention = this.getProperty("driftSpeedRetention", this.driftSpeedRetention);
|
|
4247
|
+
this.driftFrictionSlip = this.getProperty("driftFrictionSlip", this.driftFrictionSlip);
|
|
4248
|
+
this.miniTurboEnabled = this.getProperty("miniTurboEnabled", this.miniTurboEnabled);
|
|
4249
|
+
this.miniTurboTime = this.getProperty("miniTurboTime", this.miniTurboTime);
|
|
4250
|
+
this.superMiniTurboTime = this.getProperty("superMiniTurboTime", this.superMiniTurboTime);
|
|
4251
|
+
this.ultraMiniTurboTime = this.getProperty("ultraMiniTurboTime", this.ultraMiniTurboTime);
|
|
4252
|
+
this.boostSpeedFactor = this.getProperty("boostSpeedFactor", this.boostSpeedFactor);
|
|
4253
|
+
this.boostDurationMini = this.getProperty("boostDurationMini", this.boostDurationMini);
|
|
4254
|
+
this.boostDurationSuper = this.getProperty("boostDurationSuper", this.boostDurationSuper);
|
|
4255
|
+
this.boostDurationUltra = this.getProperty("boostDurationUltra", this.boostDurationUltra);
|
|
4256
|
+
this.frontLeftWheelTrans = this.getProperty("frontLeftWheel");
|
|
4257
|
+
this.frontRightWheelTrans = this.getProperty("frontRightWheel");
|
|
4258
|
+
this.backLeftWheelTrans = this.getProperty("backLeftWheel");
|
|
4259
|
+
this.backRightWheelTrans = this.getProperty("backRightWheel");
|
|
4260
|
+
this.frontLeftWheelCollider = this.getProperty("frontLeftCollider");
|
|
4261
|
+
this.frontRightWheelCollider = this.getProperty("frontRightCollider");
|
|
4262
|
+
this.backLeftWheelCollider = this.getProperty("backLeftCollider");
|
|
4263
|
+
this.backRightWheelCollider = this.getProperty("backRightCollider");
|
|
4264
|
+
}
|
|
4265
|
+
initKartState() {
|
|
4266
|
+
const chassis = this.getProperty("chassisTransform");
|
|
4267
|
+
if (chassis != null && chassis.name != null && chassis.name !== "") {
|
|
4268
|
+
this.chassisTransform = this.getChildNode(chassis.name, SearchType.IndexOf, false);
|
|
4269
|
+
}
|
|
4270
|
+
const exhaustL = this.getProperty("exhaustLeftTransform");
|
|
4271
|
+
if (exhaustL != null && exhaustL.name != null && exhaustL.name !== "") {
|
|
4272
|
+
this.exhaustLeftTransform = this.getChildNode(exhaustL.name, SearchType.IndexOf, false);
|
|
4273
|
+
}
|
|
4274
|
+
const exhaustR = this.getProperty("exhaustRightTransform");
|
|
4275
|
+
if (exhaustR != null && exhaustR.name != null && exhaustR.name !== "") {
|
|
4276
|
+
this.exhaustRightTransform = this.getChildNode(exhaustR.name, SearchType.IndexOf, false);
|
|
4277
|
+
}
|
|
4278
|
+
this._engineAudioSource = this.getComponent("AudioSource");
|
|
4279
|
+
this._rigidbody = this.getComponent("RigidbodyPhysics");
|
|
4280
|
+
if (this._rigidbody == null) {
|
|
4281
|
+
SceneManager.LogWarning("No rigidbody physics component found for: " + this.transform.name + " - kart control is disabled. If this transform was set up in code, check that its components were not constructed with _registerComponentAlias set to false.");
|
|
4282
|
+
return;
|
|
4283
|
+
}
|
|
4284
|
+
this._raycastVehicle = RaycastVehicle.GetInstance(this.scene, this._rigidbody);
|
|
4285
|
+
if (this._raycastVehicle == null || this.transform.physicsBody == null) {
|
|
4286
|
+
SceneManager.LogWarning("StandardKartController: no raycast vehicle on " + this.transform.name);
|
|
4287
|
+
return;
|
|
4288
|
+
}
|
|
4289
|
+
this.transform.physicsBody.setGravityFactor(this.gravitationalForce);
|
|
4290
|
+
this.resolveWheelIndexes();
|
|
4291
|
+
this.captureDefaultFriction();
|
|
4292
|
+
}
|
|
4293
|
+
resolveWheelIndexes() {
|
|
4294
|
+
const nameOf = (o) => (o != null && o.name != null && o.name !== "") ? o.name : null;
|
|
4295
|
+
const fl = nameOf(this.frontLeftWheelCollider);
|
|
4296
|
+
const fr = nameOf(this.frontRightWheelCollider);
|
|
4297
|
+
const bl = nameOf(this.backLeftWheelCollider);
|
|
4298
|
+
const br = nameOf(this.backRightWheelCollider);
|
|
4299
|
+
if (fl != null)
|
|
4300
|
+
this.FRONT_LEFT = this._raycastVehicle.getWheelIndexByName(fl);
|
|
4301
|
+
if (fr != null)
|
|
4302
|
+
this.FRONT_RIGHT = this._raycastVehicle.getWheelIndexByName(fr);
|
|
4303
|
+
if (bl != null)
|
|
4304
|
+
this.BACK_LEFT = this._raycastVehicle.getWheelIndexByName(bl);
|
|
4305
|
+
if (br != null)
|
|
4306
|
+
this.BACK_RIGHT = this._raycastVehicle.getWheelIndexByName(br);
|
|
4307
|
+
const bind = (trans, index) => {
|
|
4308
|
+
if (trans == null || trans.name == null || trans.name === "" || index < 0)
|
|
4309
|
+
return null;
|
|
4310
|
+
const mesh = this.getChildNode(trans.name, SearchType.IndexOf, false);
|
|
4311
|
+
if (mesh != null)
|
|
4312
|
+
this._raycastVehicle.setWheelTransformMesh(index, mesh);
|
|
4313
|
+
return mesh;
|
|
4314
|
+
};
|
|
4315
|
+
this.frontLeftWheelMesh = bind(this.frontLeftWheelTrans, this.FRONT_LEFT);
|
|
4316
|
+
this.frontRightWheelMesh = bind(this.frontRightWheelTrans, this.FRONT_RIGHT);
|
|
4317
|
+
this.backLeftWheelMesh = bind(this.backLeftWheelTrans, this.BACK_LEFT);
|
|
4318
|
+
this.backRightWheelMesh = bind(this.backRightWheelTrans, this.BACK_RIGHT);
|
|
4319
|
+
}
|
|
4320
|
+
captureDefaultFriction() {
|
|
4321
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
4322
|
+
for (let i = 0; i < count; i++) {
|
|
4323
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
4324
|
+
if (info != null && info.frictionSlip != null) {
|
|
4325
|
+
this._defaultFriction = info.frictionSlip;
|
|
4326
|
+
break;
|
|
4327
|
+
}
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
destroyKartState() {
|
|
4331
|
+
this.restoreFriction();
|
|
4332
|
+
this._raycastVehicle = null;
|
|
4333
|
+
this._rigidbody = null;
|
|
4334
|
+
this._engineAudioSource = null;
|
|
4335
|
+
}
|
|
4336
|
+
updateKartState() {
|
|
4337
|
+
if (this._raycastVehicle == null)
|
|
4338
|
+
return;
|
|
4339
|
+
const dt = this.getDeltaSeconds();
|
|
4340
|
+
if (!(dt > 0))
|
|
4341
|
+
return;
|
|
4342
|
+
this.readInput(dt);
|
|
4343
|
+
this.readGroundFrame();
|
|
4344
|
+
this.advanceMachine(dt);
|
|
4345
|
+
this.integrateDriftAngle(dt);
|
|
4346
|
+
this.applyFrictionOwnership();
|
|
4347
|
+
this.updateBoost(dt);
|
|
4348
|
+
this.updateWheelVisuals();
|
|
4349
|
+
}
|
|
4350
|
+
drive(throttle, steering, drifting, booster = 0) {
|
|
4351
|
+
const t = BABYLON.Scalar.Clamp(throttle, -1, 1);
|
|
4352
|
+
this._throttle = t > 0 ? t : 0;
|
|
4353
|
+
this._brake = t < 0 ? -t : 0;
|
|
4354
|
+
this._steerRequest = BABYLON.Scalar.Clamp(steering, -1, 1);
|
|
4355
|
+
this._driftRequest = drifting === true;
|
|
4356
|
+
this._externalBoost = BABYLON.Scalar.Clamp(booster, 0, 1);
|
|
4357
|
+
}
|
|
4358
|
+
readInput(dt) {
|
|
4359
|
+
const rate = this.steeringRamp > 0 ? dt / this.steeringRamp : Number.POSITIVE_INFINITY;
|
|
4360
|
+
this._steer = StandardKartController.MoveTowards(this._steer, this._steerRequest, rate);
|
|
4361
|
+
this._driftWasHeld = this._driftHeld;
|
|
4362
|
+
this._driftHeld = this._driftRequest;
|
|
4363
|
+
}
|
|
4364
|
+
readGroundFrame() {
|
|
4365
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
4366
|
+
this._groundedWheels = 0;
|
|
4367
|
+
this._scratchA.setAll(0);
|
|
4368
|
+
for (let i = 0; i < count; i++) {
|
|
4369
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
4370
|
+
if (info == null || info.raycastInfo == null)
|
|
4371
|
+
continue;
|
|
4372
|
+
if (info.raycastInfo.isInContact !== true)
|
|
4373
|
+
continue;
|
|
4374
|
+
this._groundedWheels++;
|
|
4375
|
+
this._scratchA.addInPlace(info.raycastInfo.contactNormalWS);
|
|
4376
|
+
}
|
|
4377
|
+
if (this._groundedWheels > 0 && this._scratchA.lengthSquared() > 1e-8) {
|
|
4378
|
+
this._groundNormal.copyFrom(this._scratchA).normalize();
|
|
4379
|
+
this._airborneTime = 0;
|
|
4380
|
+
}
|
|
4381
|
+
else {
|
|
4382
|
+
this._airborneTime += this.getDeltaSeconds();
|
|
4383
|
+
this.transform.computeWorldMatrix(true);
|
|
4384
|
+
this._worldMatrix.copyFrom(this.transform.getWorldMatrix());
|
|
4385
|
+
this._groundNormal.set(this._worldMatrix.m[4], this._worldMatrix.m[5], this._worldMatrix.m[6]).normalize();
|
|
4386
|
+
}
|
|
4387
|
+
this.transform.computeWorldMatrix(true);
|
|
4388
|
+
this._worldMatrix.copyFrom(this.transform.getWorldMatrix());
|
|
4389
|
+
this._groundForward.set(this._worldMatrix.m[8], this._worldMatrix.m[9], this._worldMatrix.m[10]);
|
|
4390
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(BABYLON.Vector3.Dot(this._groundForward, this._groundNormal));
|
|
4391
|
+
this._groundForward.subtractInPlace(this._scratchB);
|
|
4392
|
+
if (this._groundForward.lengthSquared() > 1e-8)
|
|
4393
|
+
this._groundForward.normalize();
|
|
4394
|
+
if (this.transform.physicsBody != null) {
|
|
4395
|
+
this.transform.physicsBody.getLinearVelocityToRef(this._velocity);
|
|
4396
|
+
const vertical = BABYLON.Vector3.Dot(this._velocity, this._groundNormal);
|
|
4397
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(vertical);
|
|
4398
|
+
this._planarSpeed = this._velocity.subtract(this._scratchB).length();
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
advanceMachine(dt) {
|
|
4402
|
+
const pressed = this._driftHeld === true && this._driftWasHeld !== true;
|
|
4403
|
+
const grounded = this._groundedWheels > 0;
|
|
4404
|
+
if (this._driftState === 1) {
|
|
4405
|
+
this._hopTime += dt;
|
|
4406
|
+
this._yawRate = this._hopSteer * this.steeringYawRate * StandardKartController.HOP_TURN_BOOST;
|
|
4407
|
+
if (this._hopTime >= this.hopDuration && grounded === true) {
|
|
4408
|
+
const latched = this._driftHeld === true
|
|
4409
|
+
&& Math.abs(this._steer) >= this.driftLatchThreshold
|
|
4410
|
+
&& this._planarSpeed >= this.minimumDriftSpeed;
|
|
4411
|
+
if (latched === true) {
|
|
4412
|
+
this._driftDirection = this._steer > 0 ? 1 : -1;
|
|
4413
|
+
this._driftState = 2;
|
|
4414
|
+
this._driftTime = 0;
|
|
4415
|
+
this._driftStage = 0;
|
|
4416
|
+
}
|
|
4417
|
+
else {
|
|
4418
|
+
this._driftState = 0;
|
|
4419
|
+
this._driftDirection = 0;
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
if (this._driftState === 2) {
|
|
4425
|
+
if (this._driftHeld !== true || this._planarSpeed < this.minimumDriftSpeed) {
|
|
4426
|
+
this.releaseDrift();
|
|
4427
|
+
return;
|
|
4428
|
+
}
|
|
4429
|
+
this._driftTime += dt;
|
|
4430
|
+
const realTurn = this.driftStickShare * this._steer + this.driftBaseShare * this._driftDirection;
|
|
4431
|
+
this._yawRate = realTurn * this.driftYawRate;
|
|
4432
|
+
if (this.miniTurboEnabled === true)
|
|
4433
|
+
this.updateDriftStage();
|
|
4434
|
+
return;
|
|
4435
|
+
}
|
|
4436
|
+
this._yawRate = this._steer * this.steeringYawRate;
|
|
4437
|
+
if (this.driftEnabled === true && pressed === true && grounded === true
|
|
4438
|
+
&& this._planarSpeed >= this.minimumDriftSpeed) {
|
|
4439
|
+
this._driftState = 1;
|
|
4440
|
+
this._hopTime = 0;
|
|
4441
|
+
this._hopPending = true;
|
|
4442
|
+
this._hopSteer = Math.abs(this._steer) >= this.driftLatchThreshold ? (this._steer > 0 ? 1 : -1) : 0;
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
updateDriftStage() {
|
|
4446
|
+
let stage = 0;
|
|
4447
|
+
if (this._driftTime >= this.ultraMiniTurboTime)
|
|
4448
|
+
stage = 3;
|
|
4449
|
+
else if (this._driftTime >= this.superMiniTurboTime)
|
|
4450
|
+
stage = 2;
|
|
4451
|
+
else if (this._driftTime >= this.miniTurboTime)
|
|
4452
|
+
stage = 1;
|
|
4453
|
+
this._driftStage = stage;
|
|
4454
|
+
}
|
|
4455
|
+
releaseDrift() {
|
|
4456
|
+
if (this.miniTurboEnabled === true && this._driftStage > 0) {
|
|
4457
|
+
this._boostFactor = this.boostSpeedFactor;
|
|
4458
|
+
this._boostTimer = this._driftStage === 3 ? this.boostDurationUltra
|
|
4459
|
+
: this._driftStage === 2 ? this.boostDurationSuper
|
|
4460
|
+
: this.boostDurationMini;
|
|
4461
|
+
}
|
|
4462
|
+
this._driftState = 0;
|
|
4463
|
+
this._driftDirection = 0;
|
|
4464
|
+
this._driftStage = 0;
|
|
4465
|
+
this._driftTime = 0;
|
|
4466
|
+
}
|
|
4467
|
+
integrateDriftAngle(dt) {
|
|
4468
|
+
if (this._airborneTime > StandardKartController.AIRBORNE_ANGLE_HOLD)
|
|
4469
|
+
return;
|
|
4470
|
+
const limit = this.driftMaxAngle * System.Deg2Rad;
|
|
4471
|
+
if (this._driftState === 2 && this._driftDirection !== 0) {
|
|
4472
|
+
const outward = -this._driftDirection * this._driftAngle;
|
|
4473
|
+
const target = BABYLON.Scalar.Clamp(this.driftTargetAngle * System.Deg2Rad, 0, limit);
|
|
4474
|
+
const next = StandardKartController.MoveTowards(outward, target, this.driftAngleRampRate * System.Deg2Rad * dt);
|
|
4475
|
+
this._driftAngle = -this._driftDirection * BABYLON.Scalar.Clamp(next, -limit, limit);
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4478
|
+
this._driftAngle = StandardKartController.MoveTowards(this._driftAngle, 0, this.driftAngleUnwindRate * System.Deg2Rad * dt);
|
|
4479
|
+
}
|
|
4480
|
+
ownsGroundPlane() {
|
|
4481
|
+
if (this._driftState !== 0)
|
|
4482
|
+
return true;
|
|
4483
|
+
return Math.abs(this._driftAngle) > 0.0017;
|
|
4484
|
+
}
|
|
4485
|
+
applyFrictionOwnership() {
|
|
4486
|
+
const owns = this.ownsGroundPlane();
|
|
4487
|
+
const target = owns === true ? this.driftFrictionSlip : this._defaultFriction;
|
|
4488
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
4489
|
+
for (let i = 0; i < count; i++) {
|
|
4490
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
4491
|
+
if (info != null)
|
|
4492
|
+
info.frictionSlip = target;
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
updateBoost(dt) {
|
|
4496
|
+
if (this._boostTimer > 0) {
|
|
4497
|
+
this._boostTimer -= dt;
|
|
4498
|
+
if (this._boostTimer <= 0)
|
|
4499
|
+
this._boostFactor = 1.0;
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
stepKartState() {
|
|
4503
|
+
if (this._raycastVehicle == null || this.transform.physicsBody == null)
|
|
4504
|
+
return;
|
|
4505
|
+
const body = this.transform.physicsBody;
|
|
4506
|
+
const dt = this.getDeltaSeconds();
|
|
4507
|
+
if (!(dt > 0))
|
|
4508
|
+
return;
|
|
4509
|
+
if (this._hopPending === true) {
|
|
4510
|
+
this._hopPending = false;
|
|
4511
|
+
this._scratchA.copyFrom(this._groundNormal).scaleInPlace(this.hopImpulse);
|
|
4512
|
+
body.applyImpulse(this._scratchA, this.transform.getAbsolutePosition());
|
|
4513
|
+
}
|
|
4514
|
+
if (this._groundedWheels <= 0)
|
|
4515
|
+
return;
|
|
4516
|
+
this.integratePace(dt);
|
|
4517
|
+
this.applyTravelDirection(body, dt);
|
|
4518
|
+
this.applyYawRate(body);
|
|
4519
|
+
}
|
|
4520
|
+
integratePace(dt) {
|
|
4521
|
+
const top = this.topSpeed * this._boostFactor * (1 + this._externalBoost * (this.boostSpeedFactor - 1));
|
|
4522
|
+
if (this._brake > 0) {
|
|
4523
|
+
this._planarSpeed = Math.max(0, this._planarSpeed - this.brakeDeceleration * this._brake * dt);
|
|
4524
|
+
}
|
|
4525
|
+
else if (this._throttle > 0) {
|
|
4526
|
+
const accel = this.accelerationTime > 0 ? this.topSpeed / this.accelerationTime : top;
|
|
4527
|
+
this._planarSpeed = Math.min(top, this._planarSpeed + accel * this._throttle * dt);
|
|
4528
|
+
}
|
|
4529
|
+
else {
|
|
4530
|
+
this._planarSpeed = Math.max(0, this._planarSpeed - this.coastDeceleration * dt);
|
|
4531
|
+
}
|
|
4532
|
+
if (this._driftState === 2 && this.driftSpeedRetention < 1) {
|
|
4533
|
+
this._planarSpeed *= Math.pow(this.driftSpeedRetention, dt);
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
applyTravelDirection(body, dt) {
|
|
4537
|
+
if (this.ownsGroundPlane() !== true)
|
|
4538
|
+
return;
|
|
4539
|
+
if (this._planarSpeed <= StandardKartController.RESTING_SPEED)
|
|
4540
|
+
return;
|
|
4541
|
+
BABYLON.Vector3.CrossToRef(this._groundNormal, this._groundForward, this._scratchA);
|
|
4542
|
+
this._travel.copyFrom(this._groundForward).scaleInPlace(Math.cos(this._driftAngle));
|
|
4543
|
+
this._scratchA.scaleInPlace(Math.sin(this._driftAngle));
|
|
4544
|
+
this._travel.addInPlace(this._scratchA);
|
|
4545
|
+
if (this._travel.lengthSquared() <= 1e-8)
|
|
4546
|
+
return;
|
|
4547
|
+
this._travel.normalize();
|
|
4548
|
+
body.getLinearVelocityToRef(this._velocity);
|
|
4549
|
+
const vertical = BABYLON.Vector3.Dot(this._velocity, this._groundNormal);
|
|
4550
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(vertical);
|
|
4551
|
+
this._velocity.copyFrom(this._travel).scaleInPlace(this._planarSpeed).addInPlace(this._scratchB);
|
|
4552
|
+
body.setLinearVelocity(this._velocity);
|
|
4553
|
+
}
|
|
4554
|
+
applyYawRate(body) {
|
|
4555
|
+
body.getAngularVelocityToRef(this._angular);
|
|
4556
|
+
const spin = BABYLON.Vector3.Dot(this._angular, this._groundNormal);
|
|
4557
|
+
this._scratchA.copyFrom(this._groundNormal).scaleInPlace(this._yawRate - spin);
|
|
4558
|
+
this._angular.addInPlace(this._scratchA);
|
|
4559
|
+
body.setAngularVelocity(this._angular);
|
|
4560
|
+
}
|
|
4561
|
+
updateWheelVisuals() {
|
|
4562
|
+
const angle = this._steer * this.maxSteeringAngle * System.Deg2Rad;
|
|
4563
|
+
if (this.frontLeftWheelMesh != null)
|
|
4564
|
+
this.frontLeftWheelMesh.rotation.y = angle;
|
|
4565
|
+
if (this.frontRightWheelMesh != null)
|
|
4566
|
+
this.frontRightWheelMesh.rotation.y = angle;
|
|
4567
|
+
}
|
|
4568
|
+
restoreFriction() {
|
|
4569
|
+
if (this._raycastVehicle == null)
|
|
4570
|
+
return;
|
|
4571
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
4572
|
+
for (let i = 0; i < count; i++) {
|
|
4573
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
4574
|
+
if (info != null)
|
|
4575
|
+
info.frictionSlip = this._defaultFriction;
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
clearDrift() {
|
|
4579
|
+
this._driftState = 0;
|
|
4580
|
+
this._driftDirection = 0;
|
|
4581
|
+
this._driftStage = 0;
|
|
4582
|
+
this._driftTime = 0;
|
|
4583
|
+
this._driftAngle = 0;
|
|
4584
|
+
this._hopPending = false;
|
|
4585
|
+
this.restoreFriction();
|
|
4586
|
+
}
|
|
4587
|
+
static MoveTowards(current, target, maxDelta) {
|
|
4588
|
+
if (!(maxDelta > 0))
|
|
4589
|
+
return target;
|
|
4590
|
+
const d = target - current;
|
|
4591
|
+
if (d > maxDelta)
|
|
4592
|
+
return current + maxDelta;
|
|
4593
|
+
if (d < -maxDelta)
|
|
4594
|
+
return current - maxDelta;
|
|
4595
|
+
return target;
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
StandardKartController.HOP_TURN_BOOST = 1.4;
|
|
4599
|
+
StandardKartController.AIRBORNE_ANGLE_HOLD = 0.083;
|
|
4600
|
+
StandardKartController.RESTING_SPEED = 1e-4;
|
|
4124
4601
|
export class VehicleCameraManager extends ScriptComponent {
|
|
4125
4602
|
constructor(transform, scene, properties = {}, alias = "VehicleCameraManager") {
|
|
4126
4603
|
super(transform, scene, properties, alias);
|
|
@@ -10490,5 +10967,5 @@ SceneManager.RegisterClass("SoundManager", SoundManager);
|
|
|
10490
10967
|
if (typeof window !== 'undefined') {
|
|
10491
10968
|
if (!window.TOOLKIT)
|
|
10492
10969
|
window.TOOLKIT = Object.assign({}, _ToolkitRef);
|
|
10493
|
-
window.PROJECT = Object.assign(window.PROJECT || {}, { CheckpointManager, RoutePoint, PlayerRaceStats, RaceTrackManager, RemoteCarController, SideCameraController, SkidMarkSection, SkidMarkManager, StandardCarController, VehicleCameraManager, VehicleInputController, VehicleNetworkLabel, DoubleSided, VertexSplat, VertexSplatPlugin, DefaultCameraSystem, DebugInformation, AssetExporter, AssetPreloader, NodeMaterialInstance, NodeMaterialParticle, NodeMaterialProcess, NodeMaterialTexture, MobileInputController, FreeCameraTouchJoystickInput, MobileOccludeMaterial, MobileShadowMaterial, BallSocketJoint, DistanceJoint, FixedHingeJoint, LockedJoint, PrismaticJoint, SixdofJoint, SliderJoint, RemotePlayerController, StandardPlayerController, PlayerInputControl, PlayerMoveDirection, ActionAnimationType, ThirdPersonPlayerController, ThirdPersonControl, FxParticleSystem, SkyMaterialSystem, WaterMaterialSystem, SnapshotManager, SnapshotRenderer, DefaultMuteButton, SceneSoundSystem, SoundManager });
|
|
10970
|
+
window.PROJECT = Object.assign(window.PROJECT || {}, { CheckpointManager, RoutePoint, PlayerRaceStats, RaceTrackManager, RemoteCarController, SideCameraController, SkidMarkSection, SkidMarkManager, StandardCarController, StandardKartController, VehicleCameraManager, VehicleInputController, VehicleNetworkLabel, DoubleSided, VertexSplat, VertexSplatPlugin, DefaultCameraSystem, DebugInformation, AssetExporter, AssetPreloader, NodeMaterialInstance, NodeMaterialParticle, NodeMaterialProcess, NodeMaterialTexture, MobileInputController, FreeCameraTouchJoystickInput, MobileOccludeMaterial, MobileShadowMaterial, BallSocketJoint, DistanceJoint, FixedHingeJoint, LockedJoint, PrismaticJoint, SixdofJoint, SliderJoint, RemotePlayerController, StandardPlayerController, PlayerInputControl, PlayerMoveDirection, ActionAnimationType, ThirdPersonPlayerController, ThirdPersonControl, FxParticleSystem, SkyMaterialSystem, WaterMaterialSystem, SnapshotManager, SnapshotRenderer, DefaultMuteButton, SceneSoundSystem, SoundManager });
|
|
10494
10971
|
}
|
package/lib/scenemanager.d.ts
CHANGED
|
@@ -814,6 +814,8 @@ export declare class CVTOOLS_unity_metadata implements IGLTFLoaderExtension {
|
|
|
814
814
|
static readonly IBL_PROBE_FACTOR: number;
|
|
815
815
|
static SuppressReflectionProbeDiffuse(texture: BaseTexture): void;
|
|
816
816
|
static ApplyGlobalReflectionProbeDiffuse(texture: BaseTexture, scene: Scene, createPolynomialsFromFaces?: boolean): void;
|
|
817
|
+
private static readonly NonColorDataSamplers;
|
|
818
|
+
static IsNonColorDataSampler(samplerName: string): boolean;
|
|
817
819
|
private static _boxProjectionShaderPatched;
|
|
818
820
|
enabled: boolean;
|
|
819
821
|
private _webgpu;
|