@babylonjs-toolkit/next 9.20.0 → 9.20.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 +1 -1
package/lib/scenemanager.js
CHANGED
|
@@ -98,7 +98,7 @@ import { ShadowOnlyMaterial } from '@babylonjs/materials/shadowOnly/shadowOnlyMa
|
|
|
98
98
|
import { SkyMaterial } from '@babylonjs/materials/sky/skyMaterial';
|
|
99
99
|
import { WaterMaterial } from '@babylonjs/materials/water/waterMaterial';
|
|
100
100
|
export class SceneManager {
|
|
101
|
-
static get Version() { return "9.20.
|
|
101
|
+
static get Version() { return "9.20.1 - R1"; }
|
|
102
102
|
static get Copyright() { return "All rights reserved (c) 2024 Mackey Kinard"; }
|
|
103
103
|
static GetEngine(scene) {
|
|
104
104
|
let result = null;
|
|
@@ -2658,7 +2658,7 @@ SceneManager.DirectionalLightIntensity = 1.0;
|
|
|
2658
2658
|
SceneManager.FogExpDensityScale = 1.0;
|
|
2659
2659
|
SceneManager.FogExp2DensityScale = 1.0;
|
|
2660
2660
|
SceneManager.FogLinearDensityScale = 1.0;
|
|
2661
|
-
SceneManager.TerrainColorCorrection =
|
|
2661
|
+
SceneManager.TerrainColorCorrection = 1.0;
|
|
2662
2662
|
SceneManager.AllowCameraMovement = true;
|
|
2663
2663
|
SceneManager.AllowCameraRotation = true;
|
|
2664
2664
|
SceneManager.VirtualJoystickEnabled = false;
|
|
@@ -3378,6 +3378,7 @@ export class SceneController extends ScriptComponent {
|
|
|
3378
3378
|
SceneManager.ScenePlaying = true;
|
|
3379
3379
|
if (this.autoHideSplashScreen)
|
|
3380
3380
|
SceneManager.HideSplashScreen(this.scene, this.scenePrewarmDurationMs);
|
|
3381
|
+
SceneManager.FocusRenderCanvas(this.scene);
|
|
3381
3382
|
}
|
|
3382
3383
|
}
|
|
3383
3384
|
}
|
|
@@ -3819,6 +3820,9 @@ export class CVTOOLS_unity_metadata {
|
|
|
3819
3820
|
internal._sphericalPolynomialComputed = true;
|
|
3820
3821
|
}
|
|
3821
3822
|
}
|
|
3823
|
+
static IsNonColorDataSampler(samplerName) {
|
|
3824
|
+
return CVTOOLS_unity_metadata.NonColorDataSamplers.indexOf(samplerName) >= 0;
|
|
3825
|
+
}
|
|
3822
3826
|
constructor(loader) {
|
|
3823
3827
|
this.name = SceneManager.CVTOOLS_NAME;
|
|
3824
3828
|
this.enabled = false;
|
|
@@ -5377,6 +5381,8 @@ export class CVTOOLS_unity_metadata {
|
|
|
5377
5381
|
for (const tkey in commonConstant.customTextures) {
|
|
5378
5382
|
const tvalue = commonConstant.customTextures[tkey];
|
|
5379
5383
|
if (tvalue != null) {
|
|
5384
|
+
if (CVTOOLS_unity_metadata.IsNonColorDataSampler(tkey))
|
|
5385
|
+
tvalue.nonColorData = true;
|
|
5380
5386
|
universalMaterial.checkSampler(tkey);
|
|
5381
5387
|
promises.push(this._loader.loadTextureInfoAsync(context + "/" + tkey, tvalue, (texture) => {
|
|
5382
5388
|
if (tkey === "detailsSampler" || tkey === "normalsSampler") {
|
|
@@ -5420,6 +5426,8 @@ export class CVTOOLS_unity_metadata {
|
|
|
5420
5426
|
for (const tkey in commonConstant.customTextures) {
|
|
5421
5427
|
const tvalue = commonConstant.customTextures[tkey];
|
|
5422
5428
|
if (tvalue != null && Utilities.HasOwnProperty(commonMaterial, tkey)) {
|
|
5429
|
+
if (CVTOOLS_unity_metadata.IsNonColorDataSampler(tkey))
|
|
5430
|
+
tvalue.nonColorData = true;
|
|
5423
5431
|
promises.push(this._loader.loadTextureInfoAsync(context + "/" + tkey, tvalue, (texture) => {
|
|
5424
5432
|
if (tkey === "detailsSampler" || tkey === "normalsSampler") {
|
|
5425
5433
|
texture.name = `${sourceMaterial.name} (Atlas)`;
|
|
@@ -5633,6 +5641,7 @@ export class CVTOOLS_unity_metadata {
|
|
|
5633
5641
|
CVTOOLS_unity_metadata.IBL_TINY_VALUE = 0.001;
|
|
5634
5642
|
CVTOOLS_unity_metadata.IBL_SPEC_FACTOR = 1.0;
|
|
5635
5643
|
CVTOOLS_unity_metadata.IBL_PROBE_FACTOR = 1.0;
|
|
5644
|
+
CVTOOLS_unity_metadata.NonColorDataSamplers = ["normalsSampler", "splatmapSampler"];
|
|
5636
5645
|
CVTOOLS_unity_metadata._boxProjectionShaderPatched = false;
|
|
5637
5646
|
CVTOOLS_unity_metadata.ScriptBundleCache = {};
|
|
5638
5647
|
export class CVTOOLS_babylon_mesh {
|
|
@@ -33948,6 +33957,9 @@ var PROJECT;
|
|
|
33948
33957
|
if (this._engineAudioSource == null)
|
|
33949
33958
|
SceneManager.LogWarning("No engine audio source manager found for: " + this.transform.name);
|
|
33950
33959
|
this._rigidbody = this.getComponent("RigidbodyPhysics");
|
|
33960
|
+
if (this._rigidbody == null) {
|
|
33961
|
+
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.");
|
|
33962
|
+
}
|
|
33951
33963
|
if (this._rigidbody != null) {
|
|
33952
33964
|
this.raycastVehicle = RaycastVehicle.GetInstance(this.scene, this._rigidbody);
|
|
33953
33965
|
if (this.transform.physicsBody != null && this._rigidbody != null && this.raycastVehicle != null) {
|
|
@@ -36047,6 +36059,483 @@ var PROJECT;
|
|
|
36047
36059
|
StandardCarController.SimplexNoise2D = SimplexNoise.createNoise2D();
|
|
36048
36060
|
PROJECT.StandardCarController = StandardCarController;
|
|
36049
36061
|
})(PROJECT || (PROJECT = {}));
|
|
36062
|
+
(function (PROJECT) {
|
|
36063
|
+
class StandardKartController extends ScriptComponent {
|
|
36064
|
+
constructor() {
|
|
36065
|
+
super(...arguments);
|
|
36066
|
+
this.chassisTransform = null;
|
|
36067
|
+
this.exhaustLeftTransform = null;
|
|
36068
|
+
this.exhaustRightTransform = null;
|
|
36069
|
+
this.frontLeftWheelTrans = null;
|
|
36070
|
+
this.frontRightWheelTrans = null;
|
|
36071
|
+
this.backLeftWheelTrans = null;
|
|
36072
|
+
this.backRightWheelTrans = null;
|
|
36073
|
+
this.frontLeftWheelCollider = null;
|
|
36074
|
+
this.frontRightWheelCollider = null;
|
|
36075
|
+
this.backLeftWheelCollider = null;
|
|
36076
|
+
this.backRightWheelCollider = null;
|
|
36077
|
+
this.frontLeftWheelMesh = null;
|
|
36078
|
+
this.frontRightWheelMesh = null;
|
|
36079
|
+
this.backLeftWheelMesh = null;
|
|
36080
|
+
this.backRightWheelMesh = null;
|
|
36081
|
+
this.topSpeed = 25.0;
|
|
36082
|
+
this.accelerationTime = 2.2;
|
|
36083
|
+
this.coastDeceleration = 6.0;
|
|
36084
|
+
this.brakeDeceleration = 18.0;
|
|
36085
|
+
this.gravitationalForce = 2.2;
|
|
36086
|
+
this.steeringYawRate = 1.1;
|
|
36087
|
+
this.steeringRamp = 0.18;
|
|
36088
|
+
this.maxSteeringAngle = 28.0;
|
|
36089
|
+
this.driftEnabled = true;
|
|
36090
|
+
this.driftYawRate = 1.658;
|
|
36091
|
+
this.driftStickShare = 0.5;
|
|
36092
|
+
this.driftBaseShare = 0.5;
|
|
36093
|
+
this.driftTargetAngle = 45.0;
|
|
36094
|
+
this.driftMaxAngle = 60.0;
|
|
36095
|
+
this.driftAngleRampRate = 223.0;
|
|
36096
|
+
this.driftAngleUnwindRate = 48.0;
|
|
36097
|
+
this.hopDuration = 0.25;
|
|
36098
|
+
this.hopImpulse = 4.5;
|
|
36099
|
+
this.minimumDriftSpeed = 13.75;
|
|
36100
|
+
this.driftLatchThreshold = 0.2;
|
|
36101
|
+
this.driftSpeedRetention = 1.0;
|
|
36102
|
+
this.driftFrictionSlip = 0.05;
|
|
36103
|
+
this.miniTurboEnabled = true;
|
|
36104
|
+
this.miniTurboTime = 0.6;
|
|
36105
|
+
this.superMiniTurboTime = 1.6;
|
|
36106
|
+
this.ultraMiniTurboTime = 2.8;
|
|
36107
|
+
this.boostSpeedFactor = 1.35;
|
|
36108
|
+
this.boostDurationMini = 0.6;
|
|
36109
|
+
this.boostDurationSuper = 1.1;
|
|
36110
|
+
this.boostDurationUltra = 1.8;
|
|
36111
|
+
this._rigidbody = null;
|
|
36112
|
+
this._raycastVehicle = null;
|
|
36113
|
+
this._engineAudioSource = null;
|
|
36114
|
+
this.FRONT_LEFT = -1;
|
|
36115
|
+
this.FRONT_RIGHT = -1;
|
|
36116
|
+
this.BACK_LEFT = -1;
|
|
36117
|
+
this.BACK_RIGHT = -1;
|
|
36118
|
+
this._defaultFriction = 10.0;
|
|
36119
|
+
this._steer = 0;
|
|
36120
|
+
this._throttle = 0;
|
|
36121
|
+
this._brake = 0;
|
|
36122
|
+
this._driftHeld = false;
|
|
36123
|
+
this._driftWasHeld = false;
|
|
36124
|
+
this._steerRequest = 0;
|
|
36125
|
+
this._driftRequest = false;
|
|
36126
|
+
this._externalBoost = 0;
|
|
36127
|
+
this._driftState = 0;
|
|
36128
|
+
this._driftDirection = 0;
|
|
36129
|
+
this._driftStage = 0;
|
|
36130
|
+
this._driftTime = 0;
|
|
36131
|
+
this._hopTime = 0;
|
|
36132
|
+
this._hopSteer = 0;
|
|
36133
|
+
this._hopPending = false;
|
|
36134
|
+
this._driftAngle = 0;
|
|
36135
|
+
this._yawRate = 0;
|
|
36136
|
+
this._planarSpeed = 0;
|
|
36137
|
+
this._groundedWheels = 0;
|
|
36138
|
+
this._airborneTime = 0;
|
|
36139
|
+
this._boostTimer = 0;
|
|
36140
|
+
this._boostFactor = 1.0;
|
|
36141
|
+
this._groundNormal = new Vector3(0, 1, 0);
|
|
36142
|
+
this._groundForward = new Vector3(0, 0, 1);
|
|
36143
|
+
this._velocity = new Vector3();
|
|
36144
|
+
this._angular = new Vector3();
|
|
36145
|
+
this._travel = new Vector3();
|
|
36146
|
+
this._scratchA = new Vector3();
|
|
36147
|
+
this._scratchB = new Vector3();
|
|
36148
|
+
this._worldMatrix = new Matrix();
|
|
36149
|
+
}
|
|
36150
|
+
get currentSpeed() { return this._planarSpeed; }
|
|
36151
|
+
get slideAngle() { return this._driftAngle; }
|
|
36152
|
+
get driftState() { return this._driftState; }
|
|
36153
|
+
get driftDirection() { return this._driftDirection; }
|
|
36154
|
+
get driftStage() { return this._driftStage; }
|
|
36155
|
+
get isAirborne() { return this._groundedWheels <= 0; }
|
|
36156
|
+
awake() { this.awakeKartState(); }
|
|
36157
|
+
start() { this.initKartState(); }
|
|
36158
|
+
update() { this.updateKartState(); }
|
|
36159
|
+
step() { this.stepKartState(); }
|
|
36160
|
+
destroy() { this.destroyKartState(); }
|
|
36161
|
+
awakeKartState() {
|
|
36162
|
+
this.topSpeed = this.getProperty("topSpeed", this.topSpeed);
|
|
36163
|
+
this.accelerationTime = this.getProperty("accelerationTime", this.accelerationTime);
|
|
36164
|
+
this.coastDeceleration = this.getProperty("coastDeceleration", this.coastDeceleration);
|
|
36165
|
+
this.brakeDeceleration = this.getProperty("brakeDeceleration", this.brakeDeceleration);
|
|
36166
|
+
this.gravitationalForce = this.getProperty("gravitationalForce", this.gravitationalForce);
|
|
36167
|
+
this.steeringYawRate = this.getProperty("steeringYawRate", this.steeringYawRate);
|
|
36168
|
+
this.steeringRamp = this.getProperty("steeringRamp", this.steeringRamp);
|
|
36169
|
+
this.maxSteeringAngle = this.getProperty("maxSteeringAngle", this.maxSteeringAngle);
|
|
36170
|
+
this.driftEnabled = this.getProperty("driftEnabled", this.driftEnabled);
|
|
36171
|
+
this.driftYawRate = this.getProperty("driftYawRate", this.driftYawRate);
|
|
36172
|
+
this.driftStickShare = this.getProperty("driftStickShare", this.driftStickShare);
|
|
36173
|
+
this.driftBaseShare = this.getProperty("driftBaseShare", this.driftBaseShare);
|
|
36174
|
+
this.driftTargetAngle = this.getProperty("driftTargetAngle", this.driftTargetAngle);
|
|
36175
|
+
this.driftMaxAngle = this.getProperty("driftMaxAngle", this.driftMaxAngle);
|
|
36176
|
+
this.driftAngleRampRate = this.getProperty("driftAngleRampRate", this.driftAngleRampRate);
|
|
36177
|
+
this.driftAngleUnwindRate = this.getProperty("driftAngleUnwindRate", this.driftAngleUnwindRate);
|
|
36178
|
+
this.hopDuration = this.getProperty("hopDuration", this.hopDuration);
|
|
36179
|
+
this.hopImpulse = this.getProperty("hopImpulse", this.hopImpulse);
|
|
36180
|
+
this.minimumDriftSpeed = this.getProperty("minimumDriftSpeed", this.minimumDriftSpeed);
|
|
36181
|
+
this.driftLatchThreshold = this.getProperty("driftLatchThreshold", this.driftLatchThreshold);
|
|
36182
|
+
this.driftSpeedRetention = this.getProperty("driftSpeedRetention", this.driftSpeedRetention);
|
|
36183
|
+
this.driftFrictionSlip = this.getProperty("driftFrictionSlip", this.driftFrictionSlip);
|
|
36184
|
+
this.miniTurboEnabled = this.getProperty("miniTurboEnabled", this.miniTurboEnabled);
|
|
36185
|
+
this.miniTurboTime = this.getProperty("miniTurboTime", this.miniTurboTime);
|
|
36186
|
+
this.superMiniTurboTime = this.getProperty("superMiniTurboTime", this.superMiniTurboTime);
|
|
36187
|
+
this.ultraMiniTurboTime = this.getProperty("ultraMiniTurboTime", this.ultraMiniTurboTime);
|
|
36188
|
+
this.boostSpeedFactor = this.getProperty("boostSpeedFactor", this.boostSpeedFactor);
|
|
36189
|
+
this.boostDurationMini = this.getProperty("boostDurationMini", this.boostDurationMini);
|
|
36190
|
+
this.boostDurationSuper = this.getProperty("boostDurationSuper", this.boostDurationSuper);
|
|
36191
|
+
this.boostDurationUltra = this.getProperty("boostDurationUltra", this.boostDurationUltra);
|
|
36192
|
+
this.frontLeftWheelTrans = this.getProperty("frontLeftWheel");
|
|
36193
|
+
this.frontRightWheelTrans = this.getProperty("frontRightWheel");
|
|
36194
|
+
this.backLeftWheelTrans = this.getProperty("backLeftWheel");
|
|
36195
|
+
this.backRightWheelTrans = this.getProperty("backRightWheel");
|
|
36196
|
+
this.frontLeftWheelCollider = this.getProperty("frontLeftCollider");
|
|
36197
|
+
this.frontRightWheelCollider = this.getProperty("frontRightCollider");
|
|
36198
|
+
this.backLeftWheelCollider = this.getProperty("backLeftCollider");
|
|
36199
|
+
this.backRightWheelCollider = this.getProperty("backRightCollider");
|
|
36200
|
+
}
|
|
36201
|
+
initKartState() {
|
|
36202
|
+
const chassis = this.getProperty("chassisTransform");
|
|
36203
|
+
if (chassis != null && chassis.name != null && chassis.name !== "") {
|
|
36204
|
+
this.chassisTransform = this.getChildNode(chassis.name, SearchType.IndexOf, false);
|
|
36205
|
+
}
|
|
36206
|
+
const exhaustL = this.getProperty("exhaustLeftTransform");
|
|
36207
|
+
if (exhaustL != null && exhaustL.name != null && exhaustL.name !== "") {
|
|
36208
|
+
this.exhaustLeftTransform = this.getChildNode(exhaustL.name, SearchType.IndexOf, false);
|
|
36209
|
+
}
|
|
36210
|
+
const exhaustR = this.getProperty("exhaustRightTransform");
|
|
36211
|
+
if (exhaustR != null && exhaustR.name != null && exhaustR.name !== "") {
|
|
36212
|
+
this.exhaustRightTransform = this.getChildNode(exhaustR.name, SearchType.IndexOf, false);
|
|
36213
|
+
}
|
|
36214
|
+
this._engineAudioSource = this.getComponent("AudioSource");
|
|
36215
|
+
this._rigidbody = this.getComponent("RigidbodyPhysics");
|
|
36216
|
+
if (this._rigidbody == null) {
|
|
36217
|
+
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.");
|
|
36218
|
+
return;
|
|
36219
|
+
}
|
|
36220
|
+
this._raycastVehicle = RaycastVehicle.GetInstance(this.scene, this._rigidbody);
|
|
36221
|
+
if (this._raycastVehicle == null || this.transform.physicsBody == null) {
|
|
36222
|
+
SceneManager.LogWarning("StandardKartController: no raycast vehicle on " + this.transform.name);
|
|
36223
|
+
return;
|
|
36224
|
+
}
|
|
36225
|
+
this.transform.physicsBody.setGravityFactor(this.gravitationalForce);
|
|
36226
|
+
this.resolveWheelIndexes();
|
|
36227
|
+
this.captureDefaultFriction();
|
|
36228
|
+
}
|
|
36229
|
+
resolveWheelIndexes() {
|
|
36230
|
+
const nameOf = (o) => (o != null && o.name != null && o.name !== "") ? o.name : null;
|
|
36231
|
+
const fl = nameOf(this.frontLeftWheelCollider);
|
|
36232
|
+
const fr = nameOf(this.frontRightWheelCollider);
|
|
36233
|
+
const bl = nameOf(this.backLeftWheelCollider);
|
|
36234
|
+
const br = nameOf(this.backRightWheelCollider);
|
|
36235
|
+
if (fl != null)
|
|
36236
|
+
this.FRONT_LEFT = this._raycastVehicle.getWheelIndexByName(fl);
|
|
36237
|
+
if (fr != null)
|
|
36238
|
+
this.FRONT_RIGHT = this._raycastVehicle.getWheelIndexByName(fr);
|
|
36239
|
+
if (bl != null)
|
|
36240
|
+
this.BACK_LEFT = this._raycastVehicle.getWheelIndexByName(bl);
|
|
36241
|
+
if (br != null)
|
|
36242
|
+
this.BACK_RIGHT = this._raycastVehicle.getWheelIndexByName(br);
|
|
36243
|
+
const bind = (trans, index) => {
|
|
36244
|
+
if (trans == null || trans.name == null || trans.name === "" || index < 0)
|
|
36245
|
+
return null;
|
|
36246
|
+
const mesh = this.getChildNode(trans.name, SearchType.IndexOf, false);
|
|
36247
|
+
if (mesh != null)
|
|
36248
|
+
this._raycastVehicle.setWheelTransformMesh(index, mesh);
|
|
36249
|
+
return mesh;
|
|
36250
|
+
};
|
|
36251
|
+
this.frontLeftWheelMesh = bind(this.frontLeftWheelTrans, this.FRONT_LEFT);
|
|
36252
|
+
this.frontRightWheelMesh = bind(this.frontRightWheelTrans, this.FRONT_RIGHT);
|
|
36253
|
+
this.backLeftWheelMesh = bind(this.backLeftWheelTrans, this.BACK_LEFT);
|
|
36254
|
+
this.backRightWheelMesh = bind(this.backRightWheelTrans, this.BACK_RIGHT);
|
|
36255
|
+
}
|
|
36256
|
+
captureDefaultFriction() {
|
|
36257
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
36258
|
+
for (let i = 0; i < count; i++) {
|
|
36259
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
36260
|
+
if (info != null && info.frictionSlip != null) {
|
|
36261
|
+
this._defaultFriction = info.frictionSlip;
|
|
36262
|
+
break;
|
|
36263
|
+
}
|
|
36264
|
+
}
|
|
36265
|
+
}
|
|
36266
|
+
destroyKartState() {
|
|
36267
|
+
this.restoreFriction();
|
|
36268
|
+
this._raycastVehicle = null;
|
|
36269
|
+
this._rigidbody = null;
|
|
36270
|
+
this._engineAudioSource = null;
|
|
36271
|
+
}
|
|
36272
|
+
updateKartState() {
|
|
36273
|
+
if (this._raycastVehicle == null)
|
|
36274
|
+
return;
|
|
36275
|
+
const dt = this.getDeltaSeconds();
|
|
36276
|
+
if (!(dt > 0))
|
|
36277
|
+
return;
|
|
36278
|
+
this.readInput(dt);
|
|
36279
|
+
this.readGroundFrame();
|
|
36280
|
+
this.advanceMachine(dt);
|
|
36281
|
+
this.integrateDriftAngle(dt);
|
|
36282
|
+
this.applyFrictionOwnership();
|
|
36283
|
+
this.updateBoost(dt);
|
|
36284
|
+
this.updateWheelVisuals();
|
|
36285
|
+
}
|
|
36286
|
+
drive(throttle, steering, drifting, booster = 0) {
|
|
36287
|
+
const t = Scalar.Clamp(throttle, -1, 1);
|
|
36288
|
+
this._throttle = t > 0 ? t : 0;
|
|
36289
|
+
this._brake = t < 0 ? -t : 0;
|
|
36290
|
+
this._steerRequest = Scalar.Clamp(steering, -1, 1);
|
|
36291
|
+
this._driftRequest = drifting === true;
|
|
36292
|
+
this._externalBoost = Scalar.Clamp(booster, 0, 1);
|
|
36293
|
+
}
|
|
36294
|
+
readInput(dt) {
|
|
36295
|
+
const rate = this.steeringRamp > 0 ? dt / this.steeringRamp : Number.POSITIVE_INFINITY;
|
|
36296
|
+
this._steer = StandardKartController.MoveTowards(this._steer, this._steerRequest, rate);
|
|
36297
|
+
this._driftWasHeld = this._driftHeld;
|
|
36298
|
+
this._driftHeld = this._driftRequest;
|
|
36299
|
+
}
|
|
36300
|
+
readGroundFrame() {
|
|
36301
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
36302
|
+
this._groundedWheels = 0;
|
|
36303
|
+
this._scratchA.setAll(0);
|
|
36304
|
+
for (let i = 0; i < count; i++) {
|
|
36305
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
36306
|
+
if (info == null || info.raycastInfo == null)
|
|
36307
|
+
continue;
|
|
36308
|
+
if (info.raycastInfo.isInContact !== true)
|
|
36309
|
+
continue;
|
|
36310
|
+
this._groundedWheels++;
|
|
36311
|
+
this._scratchA.addInPlace(info.raycastInfo.contactNormalWS);
|
|
36312
|
+
}
|
|
36313
|
+
if (this._groundedWheels > 0 && this._scratchA.lengthSquared() > 1e-8) {
|
|
36314
|
+
this._groundNormal.copyFrom(this._scratchA).normalize();
|
|
36315
|
+
this._airborneTime = 0;
|
|
36316
|
+
}
|
|
36317
|
+
else {
|
|
36318
|
+
this._airborneTime += this.getDeltaSeconds();
|
|
36319
|
+
this.transform.computeWorldMatrix(true);
|
|
36320
|
+
this._worldMatrix.copyFrom(this.transform.getWorldMatrix());
|
|
36321
|
+
this._groundNormal.set(this._worldMatrix.m[4], this._worldMatrix.m[5], this._worldMatrix.m[6]).normalize();
|
|
36322
|
+
}
|
|
36323
|
+
this.transform.computeWorldMatrix(true);
|
|
36324
|
+
this._worldMatrix.copyFrom(this.transform.getWorldMatrix());
|
|
36325
|
+
this._groundForward.set(this._worldMatrix.m[8], this._worldMatrix.m[9], this._worldMatrix.m[10]);
|
|
36326
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(Vector3.Dot(this._groundForward, this._groundNormal));
|
|
36327
|
+
this._groundForward.subtractInPlace(this._scratchB);
|
|
36328
|
+
if (this._groundForward.lengthSquared() > 1e-8)
|
|
36329
|
+
this._groundForward.normalize();
|
|
36330
|
+
if (this.transform.physicsBody != null) {
|
|
36331
|
+
this.transform.physicsBody.getLinearVelocityToRef(this._velocity);
|
|
36332
|
+
const vertical = Vector3.Dot(this._velocity, this._groundNormal);
|
|
36333
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(vertical);
|
|
36334
|
+
this._planarSpeed = this._velocity.subtract(this._scratchB).length();
|
|
36335
|
+
}
|
|
36336
|
+
}
|
|
36337
|
+
advanceMachine(dt) {
|
|
36338
|
+
const pressed = this._driftHeld === true && this._driftWasHeld !== true;
|
|
36339
|
+
const grounded = this._groundedWheels > 0;
|
|
36340
|
+
if (this._driftState === 1) {
|
|
36341
|
+
this._hopTime += dt;
|
|
36342
|
+
this._yawRate = this._hopSteer * this.steeringYawRate * StandardKartController.HOP_TURN_BOOST;
|
|
36343
|
+
if (this._hopTime >= this.hopDuration && grounded === true) {
|
|
36344
|
+
const latched = this._driftHeld === true
|
|
36345
|
+
&& Math.abs(this._steer) >= this.driftLatchThreshold
|
|
36346
|
+
&& this._planarSpeed >= this.minimumDriftSpeed;
|
|
36347
|
+
if (latched === true) {
|
|
36348
|
+
this._driftDirection = this._steer > 0 ? 1 : -1;
|
|
36349
|
+
this._driftState = 2;
|
|
36350
|
+
this._driftTime = 0;
|
|
36351
|
+
this._driftStage = 0;
|
|
36352
|
+
}
|
|
36353
|
+
else {
|
|
36354
|
+
this._driftState = 0;
|
|
36355
|
+
this._driftDirection = 0;
|
|
36356
|
+
}
|
|
36357
|
+
}
|
|
36358
|
+
return;
|
|
36359
|
+
}
|
|
36360
|
+
if (this._driftState === 2) {
|
|
36361
|
+
if (this._driftHeld !== true || this._planarSpeed < this.minimumDriftSpeed) {
|
|
36362
|
+
this.releaseDrift();
|
|
36363
|
+
return;
|
|
36364
|
+
}
|
|
36365
|
+
this._driftTime += dt;
|
|
36366
|
+
const realTurn = this.driftStickShare * this._steer + this.driftBaseShare * this._driftDirection;
|
|
36367
|
+
this._yawRate = realTurn * this.driftYawRate;
|
|
36368
|
+
if (this.miniTurboEnabled === true)
|
|
36369
|
+
this.updateDriftStage();
|
|
36370
|
+
return;
|
|
36371
|
+
}
|
|
36372
|
+
this._yawRate = this._steer * this.steeringYawRate;
|
|
36373
|
+
if (this.driftEnabled === true && pressed === true && grounded === true
|
|
36374
|
+
&& this._planarSpeed >= this.minimumDriftSpeed) {
|
|
36375
|
+
this._driftState = 1;
|
|
36376
|
+
this._hopTime = 0;
|
|
36377
|
+
this._hopPending = true;
|
|
36378
|
+
this._hopSteer = Math.abs(this._steer) >= this.driftLatchThreshold ? (this._steer > 0 ? 1 : -1) : 0;
|
|
36379
|
+
}
|
|
36380
|
+
}
|
|
36381
|
+
updateDriftStage() {
|
|
36382
|
+
let stage = 0;
|
|
36383
|
+
if (this._driftTime >= this.ultraMiniTurboTime)
|
|
36384
|
+
stage = 3;
|
|
36385
|
+
else if (this._driftTime >= this.superMiniTurboTime)
|
|
36386
|
+
stage = 2;
|
|
36387
|
+
else if (this._driftTime >= this.miniTurboTime)
|
|
36388
|
+
stage = 1;
|
|
36389
|
+
this._driftStage = stage;
|
|
36390
|
+
}
|
|
36391
|
+
releaseDrift() {
|
|
36392
|
+
if (this.miniTurboEnabled === true && this._driftStage > 0) {
|
|
36393
|
+
this._boostFactor = this.boostSpeedFactor;
|
|
36394
|
+
this._boostTimer = this._driftStage === 3 ? this.boostDurationUltra
|
|
36395
|
+
: this._driftStage === 2 ? this.boostDurationSuper
|
|
36396
|
+
: this.boostDurationMini;
|
|
36397
|
+
}
|
|
36398
|
+
this._driftState = 0;
|
|
36399
|
+
this._driftDirection = 0;
|
|
36400
|
+
this._driftStage = 0;
|
|
36401
|
+
this._driftTime = 0;
|
|
36402
|
+
}
|
|
36403
|
+
integrateDriftAngle(dt) {
|
|
36404
|
+
if (this._airborneTime > StandardKartController.AIRBORNE_ANGLE_HOLD)
|
|
36405
|
+
return;
|
|
36406
|
+
const limit = this.driftMaxAngle * System.Deg2Rad;
|
|
36407
|
+
if (this._driftState === 2 && this._driftDirection !== 0) {
|
|
36408
|
+
const outward = -this._driftDirection * this._driftAngle;
|
|
36409
|
+
const target = Scalar.Clamp(this.driftTargetAngle * System.Deg2Rad, 0, limit);
|
|
36410
|
+
const next = StandardKartController.MoveTowards(outward, target, this.driftAngleRampRate * System.Deg2Rad * dt);
|
|
36411
|
+
this._driftAngle = -this._driftDirection * Scalar.Clamp(next, -limit, limit);
|
|
36412
|
+
return;
|
|
36413
|
+
}
|
|
36414
|
+
this._driftAngle = StandardKartController.MoveTowards(this._driftAngle, 0, this.driftAngleUnwindRate * System.Deg2Rad * dt);
|
|
36415
|
+
}
|
|
36416
|
+
ownsGroundPlane() {
|
|
36417
|
+
if (this._driftState !== 0)
|
|
36418
|
+
return true;
|
|
36419
|
+
return Math.abs(this._driftAngle) > 0.0017;
|
|
36420
|
+
}
|
|
36421
|
+
applyFrictionOwnership() {
|
|
36422
|
+
const owns = this.ownsGroundPlane();
|
|
36423
|
+
const target = owns === true ? this.driftFrictionSlip : this._defaultFriction;
|
|
36424
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
36425
|
+
for (let i = 0; i < count; i++) {
|
|
36426
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
36427
|
+
if (info != null)
|
|
36428
|
+
info.frictionSlip = target;
|
|
36429
|
+
}
|
|
36430
|
+
}
|
|
36431
|
+
updateBoost(dt) {
|
|
36432
|
+
if (this._boostTimer > 0) {
|
|
36433
|
+
this._boostTimer -= dt;
|
|
36434
|
+
if (this._boostTimer <= 0)
|
|
36435
|
+
this._boostFactor = 1.0;
|
|
36436
|
+
}
|
|
36437
|
+
}
|
|
36438
|
+
stepKartState() {
|
|
36439
|
+
if (this._raycastVehicle == null || this.transform.physicsBody == null)
|
|
36440
|
+
return;
|
|
36441
|
+
const body = this.transform.physicsBody;
|
|
36442
|
+
const dt = this.getDeltaSeconds();
|
|
36443
|
+
if (!(dt > 0))
|
|
36444
|
+
return;
|
|
36445
|
+
if (this._hopPending === true) {
|
|
36446
|
+
this._hopPending = false;
|
|
36447
|
+
this._scratchA.copyFrom(this._groundNormal).scaleInPlace(this.hopImpulse);
|
|
36448
|
+
body.applyImpulse(this._scratchA, this.transform.getAbsolutePosition());
|
|
36449
|
+
}
|
|
36450
|
+
if (this._groundedWheels <= 0)
|
|
36451
|
+
return;
|
|
36452
|
+
this.integratePace(dt);
|
|
36453
|
+
this.applyTravelDirection(body, dt);
|
|
36454
|
+
this.applyYawRate(body);
|
|
36455
|
+
}
|
|
36456
|
+
integratePace(dt) {
|
|
36457
|
+
const top = this.topSpeed * this._boostFactor * (1 + this._externalBoost * (this.boostSpeedFactor - 1));
|
|
36458
|
+
if (this._brake > 0) {
|
|
36459
|
+
this._planarSpeed = Math.max(0, this._planarSpeed - this.brakeDeceleration * this._brake * dt);
|
|
36460
|
+
}
|
|
36461
|
+
else if (this._throttle > 0) {
|
|
36462
|
+
const accel = this.accelerationTime > 0 ? this.topSpeed / this.accelerationTime : top;
|
|
36463
|
+
this._planarSpeed = Math.min(top, this._planarSpeed + accel * this._throttle * dt);
|
|
36464
|
+
}
|
|
36465
|
+
else {
|
|
36466
|
+
this._planarSpeed = Math.max(0, this._planarSpeed - this.coastDeceleration * dt);
|
|
36467
|
+
}
|
|
36468
|
+
if (this._driftState === 2 && this.driftSpeedRetention < 1) {
|
|
36469
|
+
this._planarSpeed *= Math.pow(this.driftSpeedRetention, dt);
|
|
36470
|
+
}
|
|
36471
|
+
}
|
|
36472
|
+
applyTravelDirection(body, dt) {
|
|
36473
|
+
if (this.ownsGroundPlane() !== true)
|
|
36474
|
+
return;
|
|
36475
|
+
if (this._planarSpeed <= StandardKartController.RESTING_SPEED)
|
|
36476
|
+
return;
|
|
36477
|
+
Vector3.CrossToRef(this._groundNormal, this._groundForward, this._scratchA);
|
|
36478
|
+
this._travel.copyFrom(this._groundForward).scaleInPlace(Math.cos(this._driftAngle));
|
|
36479
|
+
this._scratchA.scaleInPlace(Math.sin(this._driftAngle));
|
|
36480
|
+
this._travel.addInPlace(this._scratchA);
|
|
36481
|
+
if (this._travel.lengthSquared() <= 1e-8)
|
|
36482
|
+
return;
|
|
36483
|
+
this._travel.normalize();
|
|
36484
|
+
body.getLinearVelocityToRef(this._velocity);
|
|
36485
|
+
const vertical = Vector3.Dot(this._velocity, this._groundNormal);
|
|
36486
|
+
this._scratchB.copyFrom(this._groundNormal).scaleInPlace(vertical);
|
|
36487
|
+
this._velocity.copyFrom(this._travel).scaleInPlace(this._planarSpeed).addInPlace(this._scratchB);
|
|
36488
|
+
body.setLinearVelocity(this._velocity);
|
|
36489
|
+
}
|
|
36490
|
+
applyYawRate(body) {
|
|
36491
|
+
body.getAngularVelocityToRef(this._angular);
|
|
36492
|
+
const spin = Vector3.Dot(this._angular, this._groundNormal);
|
|
36493
|
+
this._scratchA.copyFrom(this._groundNormal).scaleInPlace(this._yawRate - spin);
|
|
36494
|
+
this._angular.addInPlace(this._scratchA);
|
|
36495
|
+
body.setAngularVelocity(this._angular);
|
|
36496
|
+
}
|
|
36497
|
+
updateWheelVisuals() {
|
|
36498
|
+
const angle = this._steer * this.maxSteeringAngle * System.Deg2Rad;
|
|
36499
|
+
if (this.frontLeftWheelMesh != null)
|
|
36500
|
+
this.frontLeftWheelMesh.rotation.y = angle;
|
|
36501
|
+
if (this.frontRightWheelMesh != null)
|
|
36502
|
+
this.frontRightWheelMesh.rotation.y = angle;
|
|
36503
|
+
}
|
|
36504
|
+
restoreFriction() {
|
|
36505
|
+
if (this._raycastVehicle == null)
|
|
36506
|
+
return;
|
|
36507
|
+
const count = this._raycastVehicle.getNumWheels();
|
|
36508
|
+
for (let i = 0; i < count; i++) {
|
|
36509
|
+
const info = this._raycastVehicle.getWheelInfo(i);
|
|
36510
|
+
if (info != null)
|
|
36511
|
+
info.frictionSlip = this._defaultFriction;
|
|
36512
|
+
}
|
|
36513
|
+
}
|
|
36514
|
+
clearDrift() {
|
|
36515
|
+
this._driftState = 0;
|
|
36516
|
+
this._driftDirection = 0;
|
|
36517
|
+
this._driftStage = 0;
|
|
36518
|
+
this._driftTime = 0;
|
|
36519
|
+
this._driftAngle = 0;
|
|
36520
|
+
this._hopPending = false;
|
|
36521
|
+
this.restoreFriction();
|
|
36522
|
+
}
|
|
36523
|
+
static MoveTowards(current, target, maxDelta) {
|
|
36524
|
+
if (!(maxDelta > 0))
|
|
36525
|
+
return target;
|
|
36526
|
+
const d = target - current;
|
|
36527
|
+
if (d > maxDelta)
|
|
36528
|
+
return current + maxDelta;
|
|
36529
|
+
if (d < -maxDelta)
|
|
36530
|
+
return current - maxDelta;
|
|
36531
|
+
return target;
|
|
36532
|
+
}
|
|
36533
|
+
}
|
|
36534
|
+
StandardKartController.HOP_TURN_BOOST = 1.4;
|
|
36535
|
+
StandardKartController.AIRBORNE_ANGLE_HOLD = 0.083;
|
|
36536
|
+
StandardKartController.RESTING_SPEED = 1e-4;
|
|
36537
|
+
PROJECT.StandardKartController = StandardKartController;
|
|
36538
|
+
})(PROJECT || (PROJECT = {}));
|
|
36050
36539
|
(function (PROJECT) {
|
|
36051
36540
|
class VehicleCameraManager extends ScriptComponent {
|
|
36052
36541
|
constructor(transform, scene, properties = {}, alias = "VehicleCameraManager") {
|