@directivegames/genesys.sdk 3.2.2 → 3.2.4
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/README.md +60 -60
- package/dist/src/core/cli.js +22 -22
- package/dist/src/templates/scripts/genesys/genesys-mcp.js +25 -25
- package/dist/src/templates/scripts/genesys/mcp/editor-functions.js +4 -4
- package/dist/src/templates/src/templates/vehicle/src/ui-hints.js +30 -30
- package/package.json +176 -176
- package/scripts/post-install.ts +143 -143
- package/src/asset-pack/.gitattributes +88 -88
- package/src/asset-pack/eslint.config.js +45 -45
- package/src/asset-pack/gitignore +11 -11
- package/src/asset-pack/scripts/postinstall.ts +81 -81
- package/src/asset-pack/tsconfig.json +33 -33
- package/src/templates/.cursor/mcp.json +20 -20
- package/src/templates/.cursorignore +2 -2
- package/src/templates/.gitattributes +88 -88
- package/src/templates/.vscode/settings.json +6 -6
- package/src/templates/AGENTS.md +86 -86
- package/src/templates/README.md +24 -24
- package/src/templates/eslint.config.js +45 -45
- package/src/templates/gitignore +11 -11
- package/src/templates/index.html +34 -34
- package/src/templates/pnpm-lock.yaml +3676 -3676
- package/src/templates/scripts/genesys/build-project.ts +51 -51
- package/src/templates/scripts/genesys/calc-bounding-box.ts +272 -272
- package/src/templates/scripts/genesys/common.ts +46 -46
- package/src/templates/scripts/genesys/const.ts +9 -9
- package/src/templates/scripts/genesys/dev/dump-default-scene.ts +11 -11
- package/src/templates/scripts/genesys/dev/generate-manifest.ts +146 -146
- package/src/templates/scripts/genesys/dev/launcher.ts +46 -46
- package/src/templates/scripts/genesys/dev/storage-provider.ts +229 -229
- package/src/templates/scripts/genesys/dev/update-template-scenes.ts +84 -84
- package/src/templates/scripts/genesys/doc-server.ts +16 -16
- package/src/templates/scripts/genesys/genesys-mcp.ts +526 -526
- package/src/templates/scripts/genesys/mcp/doc-tools.ts +86 -86
- package/src/templates/scripts/genesys/mcp/editor-functions.ts +151 -151
- package/src/templates/scripts/genesys/mcp/editor-tools.ts +73 -73
- package/src/templates/scripts/genesys/mcp/get-scene-state.ts +35 -35
- package/src/templates/scripts/genesys/mcp/run-subprocess.ts +30 -30
- package/src/templates/scripts/genesys/mcp/search-actors.ts +858 -858
- package/src/templates/scripts/genesys/mcp/search-assets.ts +380 -380
- package/src/templates/scripts/genesys/mcp/utils.ts +281 -281
- package/src/templates/scripts/genesys/misc.ts +42 -42
- package/src/templates/scripts/genesys/mock.ts +6 -6
- package/src/templates/scripts/genesys/place-actors.ts +179 -179
- package/src/templates/scripts/genesys/post-install.ts +30 -30
- package/src/templates/scripts/genesys/prefab.schema.json +84 -84
- package/src/templates/scripts/genesys/remove-engine-comments.ts +134 -134
- package/src/templates/scripts/genesys/run-mcp-inspector.bat +4 -4
- package/src/templates/scripts/genesys/storageProvider.ts +182 -182
- package/src/templates/scripts/genesys/validate-prefabs.ts +138 -138
- package/src/templates/src/index.ts +22 -22
- package/src/templates/src/templates/firstPerson/assets/default.genesys-scene +165 -165
- package/src/templates/src/templates/firstPerson/src/game.ts +39 -39
- package/src/templates/src/templates/firstPerson/src/player.ts +63 -63
- package/src/templates/src/templates/fps/assets/default.genesys-scene +9459 -9459
- package/src/templates/src/templates/fps/src/game.ts +39 -39
- package/src/templates/src/templates/fps/src/player.ts +69 -69
- package/src/templates/src/templates/fps/src/weapon.ts +54 -54
- package/src/templates/src/templates/freeCamera/assets/default.genesys-scene +165 -165
- package/src/templates/src/templates/freeCamera/src/game.ts +39 -39
- package/src/templates/src/templates/freeCamera/src/player.ts +45 -45
- package/src/templates/src/templates/sideScroller/assets/default.genesys-scene +121 -121
- package/src/templates/src/templates/sideScroller/src/const.ts +45 -45
- package/src/templates/src/templates/sideScroller/src/game.ts +122 -122
- package/src/templates/src/templates/sideScroller/src/level-generator.ts +361 -361
- package/src/templates/src/templates/sideScroller/src/player.ts +125 -125
- package/src/templates/src/templates/thirdPerson/assets/default.genesys-scene +165 -165
- package/src/templates/src/templates/thirdPerson/src/game.ts +39 -39
- package/src/templates/src/templates/thirdPerson/src/player.ts +61 -61
- package/src/templates/src/templates/vehicle/assets/default.genesys-scene +225 -225
- package/src/templates/src/templates/vehicle/src/base-vehicle.ts +145 -145
- package/src/templates/src/templates/vehicle/src/game.ts +43 -43
- package/src/templates/src/templates/vehicle/src/mesh-vehicle.ts +191 -191
- package/src/templates/src/templates/vehicle/src/player.ts +109 -109
- package/src/templates/src/templates/vehicle/src/primitive-vehicle.ts +266 -266
- package/src/templates/src/templates/vehicle/src/ui-hints.ts +101 -101
- package/src/templates/src/templates/vr-game/assets/default.genesys-scene +246 -246
- package/src/templates/src/templates/vr-game/src/auto-imports.ts +1 -1
- package/src/templates/src/templates/vr-game/src/game.ts +66 -66
- package/src/templates/src/templates/vr-game/src/sample-vr-actor.ts +26 -26
- package/src/templates/tsconfig.json +34 -34
- package/src/templates/vite.config.ts +52 -52
|
@@ -1,266 +1,266 @@
|
|
|
1
|
-
import * as ENGINE from 'genesys.js';
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
|
|
4
|
-
import { BaseVehicle } from './base-vehicle.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A simple vehicle with a box geometry
|
|
9
|
-
*
|
|
10
|
-
* Key points:
|
|
11
|
-
* - Movement parameters configured in createVehicleMovementComponent
|
|
12
|
-
* - No component is persisted (root is transient) in order to support recreating all the components in code (which is desired)
|
|
13
|
-
* - Rely on the builtin feature to create the wheel mesh (createWheelMeshes = true), no need to create them manually
|
|
14
|
-
* - All decorative meshes have physics disabled won't mess with the handling
|
|
15
|
-
* - Find the tail light meshes after the constructor so it works with deserialized actor
|
|
16
|
-
* - Rely on the base vehicle class to handle the camera and player interaction
|
|
17
|
-
*/
|
|
18
|
-
@ENGINE.GameClass()
|
|
19
|
-
export class PrimitiveVehicle extends BaseVehicle {
|
|
20
|
-
private tailLightComponents: ENGINE.MeshComponent[] = [];
|
|
21
|
-
|
|
22
|
-
constructor(options: ENGINE.PawnOptions) {
|
|
23
|
-
|
|
24
|
-
// Create chassis mesh
|
|
25
|
-
const rootComponent = new ENGINE.MeshComponent({
|
|
26
|
-
geometry: new THREE.BoxGeometry(2, 1, 4),
|
|
27
|
-
material: new THREE.MeshStandardMaterial({
|
|
28
|
-
color: 0x4444FF,
|
|
29
|
-
roughness: 0.7,
|
|
30
|
-
metalness: 0.3,
|
|
31
|
-
}),
|
|
32
|
-
physicsOptions: {
|
|
33
|
-
enabled: true,
|
|
34
|
-
motionType: ENGINE.PhysicsMotionType.Dynamic,
|
|
35
|
-
generateCollisionEvents: true,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
rootComponent.castShadow = true;
|
|
39
|
-
rootComponent.name = 'chassis';
|
|
40
|
-
// mark the component as transient, this prevents all the components from being saved since we're recreating them in code
|
|
41
|
-
rootComponent.setTransient(true);
|
|
42
|
-
options.rootComponent = rootComponent;
|
|
43
|
-
// create decorative meshes
|
|
44
|
-
PrimitiveVehicle.createDecorativeMeshes(rootComponent);
|
|
45
|
-
options.movementComponent = PrimitiveVehicle.createVehicleMovementComponent();
|
|
46
|
-
|
|
47
|
-
super(options);
|
|
48
|
-
|
|
49
|
-
this.tailLightComponents = this.getComponents(ENGINE.MeshComponent)
|
|
50
|
-
.filter((component) => component.name.includes('_taillight'));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public override tickPrePhysics(deltaTime: number): void {
|
|
54
|
-
super.tickPrePhysics(deltaTime);
|
|
55
|
-
this.updateBrakeLights();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private updateBrakeLights(): void {
|
|
59
|
-
if (!this.movementComponent || this.tailLightComponents.length === 0) return;
|
|
60
|
-
|
|
61
|
-
const inputState = this.movementComponent.getInputState() as ENGINE.VehicleMovementInputState;
|
|
62
|
-
const isBraking = inputState.brakeInput > 0;
|
|
63
|
-
|
|
64
|
-
for (const tailLightComponent of this.tailLightComponents) {
|
|
65
|
-
const mesh = tailLightComponent.getMesh();
|
|
66
|
-
if (mesh && mesh.material) {
|
|
67
|
-
const material = mesh.material as THREE.MeshStandardMaterial;
|
|
68
|
-
if (isBraking) {
|
|
69
|
-
material.color.setHex(0xFF0000);
|
|
70
|
-
} else {
|
|
71
|
-
material.color.setHex(0xFFFFFF);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
static createDecorativeMeshes(rootComponent: ENGINE.MeshComponent): void {
|
|
78
|
-
// Add windshield
|
|
79
|
-
const windshieldComponent = new ENGINE.MeshComponent({
|
|
80
|
-
geometry: new THREE.BoxGeometry(1.8, 1.8, 0.1),
|
|
81
|
-
material: new THREE.MeshStandardMaterial({
|
|
82
|
-
color: 0x87CEEB,
|
|
83
|
-
transparent: true,
|
|
84
|
-
opacity: 0.5,
|
|
85
|
-
roughness: 0.1,
|
|
86
|
-
metalness: 0.1,
|
|
87
|
-
}),
|
|
88
|
-
physicsOptions: {
|
|
89
|
-
enabled: false,
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
windshieldComponent.position.set(0, 0.4, -1.5);
|
|
93
|
-
windshieldComponent.rotation.x = Math.PI / 8; // Slight tilt
|
|
94
|
-
windshieldComponent.name = 'windshield';
|
|
95
|
-
rootComponent.add(windshieldComponent);
|
|
96
|
-
|
|
97
|
-
// Add left headlight
|
|
98
|
-
const leftHeadlightComponent = new ENGINE.MeshComponent({
|
|
99
|
-
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
100
|
-
material: new THREE.MeshStandardMaterial({
|
|
101
|
-
color: 0xFFFFFF,
|
|
102
|
-
emissive: 0xFFFFAA,
|
|
103
|
-
emissiveIntensity: 0.3,
|
|
104
|
-
}),
|
|
105
|
-
physicsOptions: {
|
|
106
|
-
enabled: false,
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
leftHeadlightComponent.position.set(-0.7, 0.1, -2.05);
|
|
110
|
-
leftHeadlightComponent.rotation.z = Math.PI / 2;
|
|
111
|
-
leftHeadlightComponent.name = 'left_headlight';
|
|
112
|
-
rootComponent.add(leftHeadlightComponent);
|
|
113
|
-
|
|
114
|
-
// Add right headlight
|
|
115
|
-
const rightHeadlightComponent = new ENGINE.MeshComponent({
|
|
116
|
-
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
117
|
-
material: new THREE.MeshStandardMaterial({
|
|
118
|
-
color: 0xFFFFFF,
|
|
119
|
-
emissive: 0xFFFFAA,
|
|
120
|
-
emissiveIntensity: 0.3,
|
|
121
|
-
}),
|
|
122
|
-
physicsOptions: {
|
|
123
|
-
enabled: false,
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
rightHeadlightComponent.position.set(0.7, 0.1, -2.05);
|
|
127
|
-
rightHeadlightComponent.rotation.z = Math.PI / 2;
|
|
128
|
-
rightHeadlightComponent.name = 'right_headlight';
|
|
129
|
-
rootComponent.add(rightHeadlightComponent);
|
|
130
|
-
|
|
131
|
-
// Add left tail light
|
|
132
|
-
const leftTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
133
|
-
color: 0xFF0000,
|
|
134
|
-
emissive: 0x440000,
|
|
135
|
-
emissiveIntensity: 0.2,
|
|
136
|
-
});
|
|
137
|
-
const leftTaillightComponent = new ENGINE.MeshComponent({
|
|
138
|
-
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
139
|
-
material: leftTaillightMaterial,
|
|
140
|
-
physicsOptions: {
|
|
141
|
-
enabled: false,
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
leftTaillightComponent.position.set(-0.7, 0.1, 2.05);
|
|
145
|
-
leftTaillightComponent.rotation.z = Math.PI / 2;
|
|
146
|
-
leftTaillightComponent.name = 'left_taillight';
|
|
147
|
-
rootComponent.add(leftTaillightComponent);
|
|
148
|
-
|
|
149
|
-
// Add right tail light
|
|
150
|
-
const rightTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
151
|
-
color: 0xFF0000,
|
|
152
|
-
emissive: 0x440000,
|
|
153
|
-
emissiveIntensity: 0.2,
|
|
154
|
-
});
|
|
155
|
-
const rightTaillightComponent = new ENGINE.MeshComponent({
|
|
156
|
-
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
157
|
-
material: rightTaillightMaterial,
|
|
158
|
-
physicsOptions: {
|
|
159
|
-
enabled: false,
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
rightTaillightComponent.position.set(0.7, 0.1, 2.05);
|
|
163
|
-
rightTaillightComponent.rotation.z = Math.PI / 2;
|
|
164
|
-
rightTaillightComponent.name = 'right_taillight';
|
|
165
|
-
rootComponent.add(rightTaillightComponent);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
static createVehicleMovementComponent(): ENGINE.VehicleMovementComponent {
|
|
169
|
-
const wheelBaseWidth = 2.6;
|
|
170
|
-
const wheelBaseLength = 3.0;
|
|
171
|
-
const wheelBaseHeight = 0;
|
|
172
|
-
const suspensionRestLength = 0.6;
|
|
173
|
-
const wheelRadius = 0.5;
|
|
174
|
-
const wheelWidth = 0.4;
|
|
175
|
-
const suspensionStiffness = 20;
|
|
176
|
-
const suspensionCompression = 0.83;
|
|
177
|
-
const suspensionRelaxation = 0.88;
|
|
178
|
-
const maxSuspensionForce = 6000.0;
|
|
179
|
-
const maxSuspensionTravel = 5.0;
|
|
180
|
-
const sideFrictionStiffness = 2;
|
|
181
|
-
const frictionSlip = 8;
|
|
182
|
-
|
|
183
|
-
const options = {
|
|
184
|
-
...ENGINE.BasePawnMovementComponent.DEFAULT_OPTIONS,
|
|
185
|
-
maxEnginePower: 35,
|
|
186
|
-
maxSteeringAngle: Math.PI / 6, // 30 degrees
|
|
187
|
-
maxBrakeForce: 1,
|
|
188
|
-
engineResponseRate: 8.0,
|
|
189
|
-
steeringResponseRate: 12.0,
|
|
190
|
-
brakeResponseRate: 15.0,
|
|
191
|
-
createWheelMeshes: true,
|
|
192
|
-
wheelMaterialColor: 0x333333,
|
|
193
|
-
autoBreakWhenNotPossessed: 1,
|
|
194
|
-
autoStopBreak: 0.5,
|
|
195
|
-
wheels: [
|
|
196
|
-
// Default 4-wheel configuration
|
|
197
|
-
{
|
|
198
|
-
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front left
|
|
199
|
-
radius: wheelRadius,
|
|
200
|
-
width: wheelWidth,
|
|
201
|
-
canSteer: true,
|
|
202
|
-
isPowered: false,
|
|
203
|
-
canBrake: true,
|
|
204
|
-
suspensionRestLength,
|
|
205
|
-
suspensionStiffness,
|
|
206
|
-
suspensionCompression,
|
|
207
|
-
suspensionRelaxation,
|
|
208
|
-
maxSuspensionForce,
|
|
209
|
-
maxSuspensionTravel,
|
|
210
|
-
sideFrictionStiffness,
|
|
211
|
-
frictionSlip,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front right
|
|
215
|
-
radius: wheelRadius,
|
|
216
|
-
width: wheelWidth,
|
|
217
|
-
canSteer: true,
|
|
218
|
-
isPowered: false,
|
|
219
|
-
canBrake: true,
|
|
220
|
-
suspensionRestLength,
|
|
221
|
-
suspensionStiffness,
|
|
222
|
-
suspensionCompression,
|
|
223
|
-
suspensionRelaxation,
|
|
224
|
-
maxSuspensionForce,
|
|
225
|
-
maxSuspensionTravel,
|
|
226
|
-
sideFrictionStiffness,
|
|
227
|
-
frictionSlip,
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear left
|
|
231
|
-
radius: wheelRadius,
|
|
232
|
-
width: wheelWidth,
|
|
233
|
-
canSteer: false,
|
|
234
|
-
isPowered: true,
|
|
235
|
-
canBrake: true,
|
|
236
|
-
suspensionRestLength,
|
|
237
|
-
suspensionStiffness,
|
|
238
|
-
suspensionCompression,
|
|
239
|
-
suspensionRelaxation,
|
|
240
|
-
maxSuspensionForce,
|
|
241
|
-
maxSuspensionTravel,
|
|
242
|
-
sideFrictionStiffness,
|
|
243
|
-
frictionSlip,
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear right
|
|
247
|
-
radius: wheelRadius,
|
|
248
|
-
width: wheelWidth,
|
|
249
|
-
canSteer: false,
|
|
250
|
-
isPowered: true,
|
|
251
|
-
canBrake: true,
|
|
252
|
-
suspensionRestLength,
|
|
253
|
-
suspensionStiffness,
|
|
254
|
-
suspensionCompression,
|
|
255
|
-
suspensionRelaxation,
|
|
256
|
-
maxSuspensionForce,
|
|
257
|
-
maxSuspensionTravel,
|
|
258
|
-
sideFrictionStiffness,
|
|
259
|
-
frictionSlip,
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
return new ENGINE.VehicleMovementComponent(options);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
1
|
+
import * as ENGINE from 'genesys.js';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
|
|
4
|
+
import { BaseVehicle } from './base-vehicle.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A simple vehicle with a box geometry
|
|
9
|
+
*
|
|
10
|
+
* Key points:
|
|
11
|
+
* - Movement parameters configured in createVehicleMovementComponent
|
|
12
|
+
* - No component is persisted (root is transient) in order to support recreating all the components in code (which is desired)
|
|
13
|
+
* - Rely on the builtin feature to create the wheel mesh (createWheelMeshes = true), no need to create them manually
|
|
14
|
+
* - All decorative meshes have physics disabled won't mess with the handling
|
|
15
|
+
* - Find the tail light meshes after the constructor so it works with deserialized actor
|
|
16
|
+
* - Rely on the base vehicle class to handle the camera and player interaction
|
|
17
|
+
*/
|
|
18
|
+
@ENGINE.GameClass()
|
|
19
|
+
export class PrimitiveVehicle extends BaseVehicle {
|
|
20
|
+
private tailLightComponents: ENGINE.MeshComponent[] = [];
|
|
21
|
+
|
|
22
|
+
constructor(options: ENGINE.PawnOptions) {
|
|
23
|
+
|
|
24
|
+
// Create chassis mesh
|
|
25
|
+
const rootComponent = new ENGINE.MeshComponent({
|
|
26
|
+
geometry: new THREE.BoxGeometry(2, 1, 4),
|
|
27
|
+
material: new THREE.MeshStandardMaterial({
|
|
28
|
+
color: 0x4444FF,
|
|
29
|
+
roughness: 0.7,
|
|
30
|
+
metalness: 0.3,
|
|
31
|
+
}),
|
|
32
|
+
physicsOptions: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
motionType: ENGINE.PhysicsMotionType.Dynamic,
|
|
35
|
+
generateCollisionEvents: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
rootComponent.castShadow = true;
|
|
39
|
+
rootComponent.name = 'chassis';
|
|
40
|
+
// mark the component as transient, this prevents all the components from being saved since we're recreating them in code
|
|
41
|
+
rootComponent.setTransient(true);
|
|
42
|
+
options.rootComponent = rootComponent;
|
|
43
|
+
// create decorative meshes
|
|
44
|
+
PrimitiveVehicle.createDecorativeMeshes(rootComponent);
|
|
45
|
+
options.movementComponent = PrimitiveVehicle.createVehicleMovementComponent();
|
|
46
|
+
|
|
47
|
+
super(options);
|
|
48
|
+
|
|
49
|
+
this.tailLightComponents = this.getComponents(ENGINE.MeshComponent)
|
|
50
|
+
.filter((component) => component.name.includes('_taillight'));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public override tickPrePhysics(deltaTime: number): void {
|
|
54
|
+
super.tickPrePhysics(deltaTime);
|
|
55
|
+
this.updateBrakeLights();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private updateBrakeLights(): void {
|
|
59
|
+
if (!this.movementComponent || this.tailLightComponents.length === 0) return;
|
|
60
|
+
|
|
61
|
+
const inputState = this.movementComponent.getInputState() as ENGINE.VehicleMovementInputState;
|
|
62
|
+
const isBraking = inputState.brakeInput > 0;
|
|
63
|
+
|
|
64
|
+
for (const tailLightComponent of this.tailLightComponents) {
|
|
65
|
+
const mesh = tailLightComponent.getMesh();
|
|
66
|
+
if (mesh && mesh.material) {
|
|
67
|
+
const material = mesh.material as THREE.MeshStandardMaterial;
|
|
68
|
+
if (isBraking) {
|
|
69
|
+
material.color.setHex(0xFF0000);
|
|
70
|
+
} else {
|
|
71
|
+
material.color.setHex(0xFFFFFF);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static createDecorativeMeshes(rootComponent: ENGINE.MeshComponent): void {
|
|
78
|
+
// Add windshield
|
|
79
|
+
const windshieldComponent = new ENGINE.MeshComponent({
|
|
80
|
+
geometry: new THREE.BoxGeometry(1.8, 1.8, 0.1),
|
|
81
|
+
material: new THREE.MeshStandardMaterial({
|
|
82
|
+
color: 0x87CEEB,
|
|
83
|
+
transparent: true,
|
|
84
|
+
opacity: 0.5,
|
|
85
|
+
roughness: 0.1,
|
|
86
|
+
metalness: 0.1,
|
|
87
|
+
}),
|
|
88
|
+
physicsOptions: {
|
|
89
|
+
enabled: false,
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
windshieldComponent.position.set(0, 0.4, -1.5);
|
|
93
|
+
windshieldComponent.rotation.x = Math.PI / 8; // Slight tilt
|
|
94
|
+
windshieldComponent.name = 'windshield';
|
|
95
|
+
rootComponent.add(windshieldComponent);
|
|
96
|
+
|
|
97
|
+
// Add left headlight
|
|
98
|
+
const leftHeadlightComponent = new ENGINE.MeshComponent({
|
|
99
|
+
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
100
|
+
material: new THREE.MeshStandardMaterial({
|
|
101
|
+
color: 0xFFFFFF,
|
|
102
|
+
emissive: 0xFFFFAA,
|
|
103
|
+
emissiveIntensity: 0.3,
|
|
104
|
+
}),
|
|
105
|
+
physicsOptions: {
|
|
106
|
+
enabled: false,
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
leftHeadlightComponent.position.set(-0.7, 0.1, -2.05);
|
|
110
|
+
leftHeadlightComponent.rotation.z = Math.PI / 2;
|
|
111
|
+
leftHeadlightComponent.name = 'left_headlight';
|
|
112
|
+
rootComponent.add(leftHeadlightComponent);
|
|
113
|
+
|
|
114
|
+
// Add right headlight
|
|
115
|
+
const rightHeadlightComponent = new ENGINE.MeshComponent({
|
|
116
|
+
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
117
|
+
material: new THREE.MeshStandardMaterial({
|
|
118
|
+
color: 0xFFFFFF,
|
|
119
|
+
emissive: 0xFFFFAA,
|
|
120
|
+
emissiveIntensity: 0.3,
|
|
121
|
+
}),
|
|
122
|
+
physicsOptions: {
|
|
123
|
+
enabled: false,
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
rightHeadlightComponent.position.set(0.7, 0.1, -2.05);
|
|
127
|
+
rightHeadlightComponent.rotation.z = Math.PI / 2;
|
|
128
|
+
rightHeadlightComponent.name = 'right_headlight';
|
|
129
|
+
rootComponent.add(rightHeadlightComponent);
|
|
130
|
+
|
|
131
|
+
// Add left tail light
|
|
132
|
+
const leftTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
133
|
+
color: 0xFF0000,
|
|
134
|
+
emissive: 0x440000,
|
|
135
|
+
emissiveIntensity: 0.2,
|
|
136
|
+
});
|
|
137
|
+
const leftTaillightComponent = new ENGINE.MeshComponent({
|
|
138
|
+
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
139
|
+
material: leftTaillightMaterial,
|
|
140
|
+
physicsOptions: {
|
|
141
|
+
enabled: false,
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
leftTaillightComponent.position.set(-0.7, 0.1, 2.05);
|
|
145
|
+
leftTaillightComponent.rotation.z = Math.PI / 2;
|
|
146
|
+
leftTaillightComponent.name = 'left_taillight';
|
|
147
|
+
rootComponent.add(leftTaillightComponent);
|
|
148
|
+
|
|
149
|
+
// Add right tail light
|
|
150
|
+
const rightTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
151
|
+
color: 0xFF0000,
|
|
152
|
+
emissive: 0x440000,
|
|
153
|
+
emissiveIntensity: 0.2,
|
|
154
|
+
});
|
|
155
|
+
const rightTaillightComponent = new ENGINE.MeshComponent({
|
|
156
|
+
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
157
|
+
material: rightTaillightMaterial,
|
|
158
|
+
physicsOptions: {
|
|
159
|
+
enabled: false,
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
rightTaillightComponent.position.set(0.7, 0.1, 2.05);
|
|
163
|
+
rightTaillightComponent.rotation.z = Math.PI / 2;
|
|
164
|
+
rightTaillightComponent.name = 'right_taillight';
|
|
165
|
+
rootComponent.add(rightTaillightComponent);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static createVehicleMovementComponent(): ENGINE.VehicleMovementComponent {
|
|
169
|
+
const wheelBaseWidth = 2.6;
|
|
170
|
+
const wheelBaseLength = 3.0;
|
|
171
|
+
const wheelBaseHeight = 0;
|
|
172
|
+
const suspensionRestLength = 0.6;
|
|
173
|
+
const wheelRadius = 0.5;
|
|
174
|
+
const wheelWidth = 0.4;
|
|
175
|
+
const suspensionStiffness = 20;
|
|
176
|
+
const suspensionCompression = 0.83;
|
|
177
|
+
const suspensionRelaxation = 0.88;
|
|
178
|
+
const maxSuspensionForce = 6000.0;
|
|
179
|
+
const maxSuspensionTravel = 5.0;
|
|
180
|
+
const sideFrictionStiffness = 2;
|
|
181
|
+
const frictionSlip = 8;
|
|
182
|
+
|
|
183
|
+
const options = {
|
|
184
|
+
...ENGINE.BasePawnMovementComponent.DEFAULT_OPTIONS,
|
|
185
|
+
maxEnginePower: 35,
|
|
186
|
+
maxSteeringAngle: Math.PI / 6, // 30 degrees
|
|
187
|
+
maxBrakeForce: 1,
|
|
188
|
+
engineResponseRate: 8.0,
|
|
189
|
+
steeringResponseRate: 12.0,
|
|
190
|
+
brakeResponseRate: 15.0,
|
|
191
|
+
createWheelMeshes: true,
|
|
192
|
+
wheelMaterialColor: 0x333333,
|
|
193
|
+
autoBreakWhenNotPossessed: 1,
|
|
194
|
+
autoStopBreak: 0.5,
|
|
195
|
+
wheels: [
|
|
196
|
+
// Default 4-wheel configuration
|
|
197
|
+
{
|
|
198
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front left
|
|
199
|
+
radius: wheelRadius,
|
|
200
|
+
width: wheelWidth,
|
|
201
|
+
canSteer: true,
|
|
202
|
+
isPowered: false,
|
|
203
|
+
canBrake: true,
|
|
204
|
+
suspensionRestLength,
|
|
205
|
+
suspensionStiffness,
|
|
206
|
+
suspensionCompression,
|
|
207
|
+
suspensionRelaxation,
|
|
208
|
+
maxSuspensionForce,
|
|
209
|
+
maxSuspensionTravel,
|
|
210
|
+
sideFrictionStiffness,
|
|
211
|
+
frictionSlip,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front right
|
|
215
|
+
radius: wheelRadius,
|
|
216
|
+
width: wheelWidth,
|
|
217
|
+
canSteer: true,
|
|
218
|
+
isPowered: false,
|
|
219
|
+
canBrake: true,
|
|
220
|
+
suspensionRestLength,
|
|
221
|
+
suspensionStiffness,
|
|
222
|
+
suspensionCompression,
|
|
223
|
+
suspensionRelaxation,
|
|
224
|
+
maxSuspensionForce,
|
|
225
|
+
maxSuspensionTravel,
|
|
226
|
+
sideFrictionStiffness,
|
|
227
|
+
frictionSlip,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear left
|
|
231
|
+
radius: wheelRadius,
|
|
232
|
+
width: wheelWidth,
|
|
233
|
+
canSteer: false,
|
|
234
|
+
isPowered: true,
|
|
235
|
+
canBrake: true,
|
|
236
|
+
suspensionRestLength,
|
|
237
|
+
suspensionStiffness,
|
|
238
|
+
suspensionCompression,
|
|
239
|
+
suspensionRelaxation,
|
|
240
|
+
maxSuspensionForce,
|
|
241
|
+
maxSuspensionTravel,
|
|
242
|
+
sideFrictionStiffness,
|
|
243
|
+
frictionSlip,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear right
|
|
247
|
+
radius: wheelRadius,
|
|
248
|
+
width: wheelWidth,
|
|
249
|
+
canSteer: false,
|
|
250
|
+
isPowered: true,
|
|
251
|
+
canBrake: true,
|
|
252
|
+
suspensionRestLength,
|
|
253
|
+
suspensionStiffness,
|
|
254
|
+
suspensionCompression,
|
|
255
|
+
suspensionRelaxation,
|
|
256
|
+
maxSuspensionForce,
|
|
257
|
+
maxSuspensionTravel,
|
|
258
|
+
sideFrictionStiffness,
|
|
259
|
+
frictionSlip,
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
return new ENGINE.VehicleMovementComponent(options);
|
|
265
|
+
}
|
|
266
|
+
}
|