@gnsx/genesys.sdk 4.2.9
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 -0
- package/dist/src/asset-pack/eslint.config.js +58 -0
- package/dist/src/asset-pack/scripts/post-install.js +64 -0
- package/dist/src/asset-pack/src/index.js +1 -0
- package/dist/src/core/cli.js +303 -0
- package/dist/src/core/common.js +325 -0
- package/dist/src/core/index.js +6 -0
- package/dist/src/core/tools/build-project.js +456 -0
- package/dist/src/core/tools/index.js +2 -0
- package/dist/src/core/tools/new-asset-pack.js +153 -0
- package/dist/src/core/tools/new-project.js +293 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/dependencies.js +84 -0
- package/dist/src/electron/IpcSerializableError.js +38 -0
- package/dist/src/electron/api.js +7 -0
- package/dist/src/electron/backend/actions.js +56 -0
- package/dist/src/electron/backend/handler.js +452 -0
- package/dist/src/electron/backend/logging.js +41 -0
- package/dist/src/electron/backend/main.js +369 -0
- package/dist/src/electron/backend/menu.js +196 -0
- package/dist/src/electron/backend/state.js +201 -0
- package/dist/src/electron/backend/telemetry.js +9 -0
- package/dist/src/electron/backend/tools/const.js +9 -0
- package/dist/src/electron/backend/tools/file-server.js +383 -0
- package/dist/src/electron/backend/tools/open-project.js +249 -0
- package/dist/src/electron/backend/window.js +161 -0
- package/dist/src/templates/eslint.config.js +58 -0
- package/dist/src/templates/scripts/genesys/build-project.js +42 -0
- package/dist/src/templates/scripts/genesys/calc-bounding-box.js +205 -0
- package/dist/src/templates/scripts/genesys/common.js +36 -0
- package/dist/src/templates/scripts/genesys/const.js +9 -0
- package/dist/src/templates/scripts/genesys/dev/dump-default-scene.js +8 -0
- package/dist/src/templates/scripts/genesys/dev/generate-manifest.js +116 -0
- package/dist/src/templates/scripts/genesys/dev/launcher.js +39 -0
- package/dist/src/templates/scripts/genesys/dev/storage-provider.js +188 -0
- package/dist/src/templates/scripts/genesys/dev/update-template-scenes.js +67 -0
- package/dist/src/templates/scripts/genesys/doc-server.js +12 -0
- package/dist/src/templates/scripts/genesys/genesys-mcp.js +413 -0
- package/dist/src/templates/scripts/genesys/mcp/doc-tools.js +70 -0
- package/dist/src/templates/scripts/genesys/mcp/editor-functions.js +123 -0
- package/dist/src/templates/scripts/genesys/mcp/editor-tools.js +51 -0
- package/dist/src/templates/scripts/genesys/mcp/get-scene-state.js +26 -0
- package/dist/src/templates/scripts/genesys/mcp/run-subprocess.js +23 -0
- package/dist/src/templates/scripts/genesys/mcp/search-actors.js +703 -0
- package/dist/src/templates/scripts/genesys/mcp/search-assets.js +296 -0
- package/dist/src/templates/scripts/genesys/mcp/utils.js +234 -0
- package/dist/src/templates/scripts/genesys/migrate-scenes-and-prefabs.js +252 -0
- package/dist/src/templates/scripts/genesys/misc.js +32 -0
- package/dist/src/templates/scripts/genesys/mock.js +5 -0
- package/dist/src/templates/scripts/genesys/place-actors.js +112 -0
- package/dist/src/templates/scripts/genesys/post-install.js +33 -0
- package/dist/src/templates/scripts/genesys/remove-engine-comments.js +113 -0
- package/dist/src/templates/scripts/genesys/storageProvider.js +146 -0
- package/dist/src/templates/scripts/genesys/validate-prefabs.js +115 -0
- package/dist/src/templates/src/index.js +20 -0
- package/dist/src/templates/src/templates/firstPerson/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/firstPerson/src/game.js +30 -0
- package/dist/src/templates/src/templates/firstPerson/src/player.js +55 -0
- package/dist/src/templates/src/templates/fps/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/fps/src/game.js +30 -0
- package/dist/src/templates/src/templates/fps/src/player.js +60 -0
- package/dist/src/templates/src/templates/fps/src/weapon.js +54 -0
- package/dist/src/templates/src/templates/freeCamera/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/freeCamera/src/game.js +30 -0
- package/dist/src/templates/src/templates/freeCamera/src/player.js +38 -0
- package/dist/src/templates/src/templates/sideScroller/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/sideScroller/src/const.js +43 -0
- package/dist/src/templates/src/templates/sideScroller/src/game.js +102 -0
- package/dist/src/templates/src/templates/sideScroller/src/level-generator.js +249 -0
- package/dist/src/templates/src/templates/sideScroller/src/player.js +100 -0
- package/dist/src/templates/src/templates/thirdPerson/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/thirdPerson/src/game.js +30 -0
- package/dist/src/templates/src/templates/thirdPerson/src/player.js +58 -0
- package/dist/src/templates/src/templates/vehicle/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/vehicle/src/base-vehicle.js +122 -0
- package/dist/src/templates/src/templates/vehicle/src/game.js +33 -0
- package/dist/src/templates/src/templates/vehicle/src/mesh-vehicle.js +188 -0
- package/dist/src/templates/src/templates/vehicle/src/player.js +97 -0
- package/dist/src/templates/src/templates/vehicle/src/primitive-vehicle.js +258 -0
- package/dist/src/templates/src/templates/vehicle/src/ui-hints.js +100 -0
- package/dist/src/templates/src/templates/vr-game/src/auto-imports.js +1 -0
- package/dist/src/templates/src/templates/vr-game/src/game.js +55 -0
- package/dist/src/templates/src/templates/vr-game/src/sample-vr-actor.js +29 -0
- package/dist/src/templates/vite.config.js +46 -0
- package/package.json +181 -0
- package/scripts/post-install.ts +143 -0
- package/src/asset-pack/.gitattributes +89 -0
- package/src/asset-pack/.github/workflows/publish.yml +90 -0
- package/src/asset-pack/eslint.config.js +59 -0
- package/src/asset-pack/gitignore +11 -0
- package/src/asset-pack/scripts/post-install.ts +81 -0
- package/src/asset-pack/src/index.ts +0 -0
- package/src/asset-pack/tsconfig.json +34 -0
- package/src/templates/.cursor/mcp.json +20 -0
- package/src/templates/.cursorignore +2 -0
- package/src/templates/.gitattributes +89 -0
- package/src/templates/.vscode/settings.json +6 -0
- package/src/templates/AGENTS.md +104 -0
- package/src/templates/CLAUDE.md +1 -0
- package/src/templates/README.md +24 -0
- package/src/templates/eslint.config.js +60 -0
- package/src/templates/gitignore +11 -0
- package/src/templates/index.html +34 -0
- package/src/templates/pnpm-lock.yaml +3676 -0
- package/src/templates/scripts/genesys/build-project.ts +51 -0
- package/src/templates/scripts/genesys/calc-bounding-box.ts +272 -0
- package/src/templates/scripts/genesys/common.ts +46 -0
- package/src/templates/scripts/genesys/const.ts +9 -0
- package/src/templates/scripts/genesys/dev/dump-default-scene.ts +11 -0
- package/src/templates/scripts/genesys/dev/generate-manifest.ts +146 -0
- package/src/templates/scripts/genesys/dev/launcher.ts +46 -0
- package/src/templates/scripts/genesys/dev/storage-provider.ts +229 -0
- package/src/templates/scripts/genesys/dev/update-template-scenes.ts +84 -0
- package/src/templates/scripts/genesys/doc-server.ts +16 -0
- package/src/templates/scripts/genesys/genesys-mcp.ts +526 -0
- package/src/templates/scripts/genesys/mcp/doc-tools.ts +86 -0
- package/src/templates/scripts/genesys/mcp/editor-functions.ts +151 -0
- package/src/templates/scripts/genesys/mcp/editor-tools.ts +73 -0
- package/src/templates/scripts/genesys/mcp/get-scene-state.ts +35 -0
- package/src/templates/scripts/genesys/mcp/run-subprocess.ts +30 -0
- package/src/templates/scripts/genesys/mcp/search-actors.ts +858 -0
- package/src/templates/scripts/genesys/mcp/search-assets.ts +380 -0
- package/src/templates/scripts/genesys/mcp/utils.ts +281 -0
- package/src/templates/scripts/genesys/migrate-scenes-and-prefabs.ts +301 -0
- package/src/templates/scripts/genesys/misc.ts +42 -0
- package/src/templates/scripts/genesys/mock.ts +6 -0
- package/src/templates/scripts/genesys/place-actors.ts +179 -0
- package/src/templates/scripts/genesys/post-install.ts +39 -0
- package/src/templates/scripts/genesys/prefab.schema.json +85 -0
- package/src/templates/scripts/genesys/remove-engine-comments.ts +135 -0
- package/src/templates/scripts/genesys/run-mcp-inspector.bat +5 -0
- package/src/templates/scripts/genesys/storageProvider.ts +182 -0
- package/src/templates/scripts/genesys/validate-prefabs.ts +138 -0
- package/src/templates/src/index.ts +22 -0
- package/src/templates/src/templates/firstPerson/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/firstPerson/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/firstPerson/src/game.ts +39 -0
- package/src/templates/src/templates/firstPerson/src/player.ts +59 -0
- package/src/templates/src/templates/fps/assets/default.genesys-scene +9460 -0
- package/src/templates/src/templates/fps/assets/models/SM_Beam_400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_ChamferCube.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thick_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thick_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thin_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Floor_Thin_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Ramp_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Rifle.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x200.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x200_Orange.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x400.glb +0 -0
- package/src/templates/src/templates/fps/assets/models/SM_Wall_Thin_400x400_Orange.glb +0 -0
- package/src/templates/src/templates/fps/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/fps/src/game.ts +39 -0
- package/src/templates/src/templates/fps/src/player.ts +66 -0
- package/src/templates/src/templates/fps/src/weapon.ts +47 -0
- package/src/templates/src/templates/freeCamera/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/freeCamera/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/freeCamera/src/game.ts +39 -0
- package/src/templates/src/templates/freeCamera/src/player.ts +40 -0
- package/src/templates/src/templates/sideScroller/assets/default.genesys-scene +122 -0
- package/src/templates/src/templates/sideScroller/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/sideScroller/src/const.ts +46 -0
- package/src/templates/src/templates/sideScroller/src/game.ts +121 -0
- package/src/templates/src/templates/sideScroller/src/level-generator.ts +361 -0
- package/src/templates/src/templates/sideScroller/src/player.ts +123 -0
- package/src/templates/src/templates/thirdPerson/assets/default.genesys-scene +166 -0
- package/src/templates/src/templates/thirdPerson/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/thirdPerson/src/game.ts +39 -0
- package/src/templates/src/templates/thirdPerson/src/player.ts +58 -0
- package/src/templates/src/templates/vehicle/assets/default.genesys-scene +226 -0
- package/src/templates/src/templates/vehicle/assets/models/cyberTruck/chassis.glb +0 -0
- package/src/templates/src/templates/vehicle/assets/models/cyberTruck/wheel.glb +0 -0
- package/src/templates/src/templates/vehicle/src/auto-imports.ts +0 -0
- package/src/templates/src/templates/vehicle/src/base-vehicle.ts +145 -0
- package/src/templates/src/templates/vehicle/src/game.ts +43 -0
- package/src/templates/src/templates/vehicle/src/mesh-vehicle.ts +189 -0
- package/src/templates/src/templates/vehicle/src/player.ts +106 -0
- package/src/templates/src/templates/vehicle/src/primitive-vehicle.ts +264 -0
- package/src/templates/src/templates/vehicle/src/ui-hints.ts +101 -0
- package/src/templates/src/templates/vr-game/assets/default.genesys-scene +247 -0
- package/src/templates/src/templates/vr-game/src/auto-imports.ts +1 -0
- package/src/templates/src/templates/vr-game/src/game.ts +66 -0
- package/src/templates/src/templates/vr-game/src/sample-vr-actor.ts +26 -0
- package/src/templates/tsconfig.json +35 -0
- package/src/templates/vite.config.ts +52 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as ENGINE from '@gnsx/genesys.js';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import './auto-imports.js';
|
|
4
|
+
import { VehiclePlayer } from './player.js';
|
|
5
|
+
import { UIHints } from './ui-hints.js';
|
|
6
|
+
class MyGame extends ENGINE.BaseGameLoop {
|
|
7
|
+
pawn = null;
|
|
8
|
+
controller = null;
|
|
9
|
+
createLoadingScreen() {
|
|
10
|
+
// enable the default loading screen
|
|
11
|
+
return new ENGINE.DefaultLoadingScreen();
|
|
12
|
+
}
|
|
13
|
+
async preStart() {
|
|
14
|
+
// default spawn location
|
|
15
|
+
const position = new THREE.Vector3(0, ENGINE.CHARACTER_HEIGHT / 2, 0);
|
|
16
|
+
// create the pawn
|
|
17
|
+
this.pawn = VehiclePlayer.create({ position });
|
|
18
|
+
// create the controller and possess the pawn
|
|
19
|
+
this.controller = ENGINE.PlayerController.create();
|
|
20
|
+
this.controller.possess(this.pawn);
|
|
21
|
+
// create UI hints
|
|
22
|
+
const uiHints = UIHints.create();
|
|
23
|
+
// add all actors to the world
|
|
24
|
+
this.world.addActors(this.pawn, this.controller, uiHints);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function main(container, gameId) {
|
|
28
|
+
const game = new MyGame(container, {
|
|
29
|
+
...ENGINE.BaseGameLoop.DEFAULT_OPTIONS,
|
|
30
|
+
gameId
|
|
31
|
+
});
|
|
32
|
+
return game;
|
|
33
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var MeshVehicle_1;
|
|
8
|
+
import * as ENGINE from '@gnsx/genesys.js';
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { BaseVehicle } from './base-vehicle.js';
|
|
11
|
+
/**
|
|
12
|
+
* A vehicle that uses a 3D mesh model for visual representation
|
|
13
|
+
*
|
|
14
|
+
* Key points:
|
|
15
|
+
* - Uses invisible collision box for physics simulation (separate from visual mesh)
|
|
16
|
+
* - Loads GLB model for visual representation via GLTFMeshComponent
|
|
17
|
+
* - Movement parameters configured in createVehicleMovementComponent
|
|
18
|
+
* - No component is persisted (root is transient) in order to support recreating all the components in code (which is desired)
|
|
19
|
+
* - Do not create the builtin wheel mesh since the GLB models are used instead (createWheelMeshes = false)
|
|
20
|
+
* - Visual mesh is positioned and scaled to match collision box
|
|
21
|
+
* - Wheel mesh transforms are updated using the onWheelUpdated delegate
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
let MeshVehicle = MeshVehicle_1 = class MeshVehicle extends BaseVehicle {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
// the root component is only used for collision and physics simulation
|
|
28
|
+
const rootComponent = ENGINE.MeshComponent.create({
|
|
29
|
+
geometry: new THREE.BoxGeometry(2.77, 1.79, 5.75),
|
|
30
|
+
material: new THREE.MeshStandardMaterial({
|
|
31
|
+
color: 0x4444FF,
|
|
32
|
+
roughness: 0.7,
|
|
33
|
+
metalness: 0.3,
|
|
34
|
+
visible: false,
|
|
35
|
+
transparent: true,
|
|
36
|
+
opacity: 0.5,
|
|
37
|
+
}),
|
|
38
|
+
physicsOptions: {
|
|
39
|
+
enabled: true,
|
|
40
|
+
motionType: ENGINE.PhysicsMotionType.Dynamic,
|
|
41
|
+
generateCollisionEvents: true,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
rootComponent.name = 'root';
|
|
45
|
+
this.setRootComponent(rootComponent, true);
|
|
46
|
+
// mark the component as transient, this prevents all the components from being saved since we're recreating them in code
|
|
47
|
+
rootComponent.setTransient(true);
|
|
48
|
+
const chassisComponent = ENGINE.GLTFMeshComponent.create({
|
|
49
|
+
modelUrl: '@project/assets/models/cyberTruck/chassis.glb',
|
|
50
|
+
position: new THREE.Vector3(0, 0, -0.75),
|
|
51
|
+
material: new THREE.MeshStandardMaterial({
|
|
52
|
+
color: 0x4444FF,
|
|
53
|
+
roughness: 0.7,
|
|
54
|
+
metalness: 0.3,
|
|
55
|
+
}),
|
|
56
|
+
physicsOptions: {
|
|
57
|
+
enabled: false,
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
chassisComponent.castShadow = true;
|
|
61
|
+
chassisComponent.name = 'chassis';
|
|
62
|
+
rootComponent.add(chassisComponent);
|
|
63
|
+
const wheelMeshes = [];
|
|
64
|
+
for (let i = 0; i < 4; i++) {
|
|
65
|
+
const wheelComponent = ENGINE.GLTFMeshComponent.create({
|
|
66
|
+
modelUrl: '@project/assets/models/cyberTruck/wheel.glb',
|
|
67
|
+
material: new THREE.MeshStandardMaterial({
|
|
68
|
+
color: 0x44FF44,
|
|
69
|
+
roughness: 0.7,
|
|
70
|
+
metalness: 0.3,
|
|
71
|
+
}),
|
|
72
|
+
physicsOptions: {
|
|
73
|
+
enabled: false,
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
wheelComponent.castShadow = true;
|
|
77
|
+
wheelComponent.name = `wheel_${i}`;
|
|
78
|
+
wheelMeshes.push(wheelComponent);
|
|
79
|
+
}
|
|
80
|
+
rootComponent.add(...wheelMeshes);
|
|
81
|
+
const vehicleMovementComponent = MeshVehicle_1.createVehicleMovementComponent();
|
|
82
|
+
this.movementComponent = vehicleMovementComponent;
|
|
83
|
+
const wheelComponents = this.getComponents(ENGINE.GLTFMeshComponent).filter(component => component.name.startsWith('wheel_'));
|
|
84
|
+
vehicleMovementComponent.onWheelUpdated.add((component, wheelIndex, wheelState) => {
|
|
85
|
+
// The first mesh component is the chassis component, so we need to skip it
|
|
86
|
+
const wheelMesh = wheelComponents[wheelIndex];
|
|
87
|
+
// Apply the final transformation to the wheel mesh
|
|
88
|
+
wheelMesh.position.copy(wheelState.relativePosition);
|
|
89
|
+
wheelMesh.quaternion.copy(wheelState.relativeQuaternion);
|
|
90
|
+
// Apply additional 180-degree rotation around Y-axis for wheels 0 and 2
|
|
91
|
+
if (wheelIndex === 0 || wheelIndex === 2) {
|
|
92
|
+
const yRotation = new THREE.Quaternion();
|
|
93
|
+
yRotation.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI);
|
|
94
|
+
wheelMesh.quaternion.multiplyQuaternions(wheelMesh.quaternion, yRotation);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static createVehicleMovementComponent() {
|
|
99
|
+
const wheelBaseWidth = 3.2;
|
|
100
|
+
const wheelBaseLength = 3.8;
|
|
101
|
+
const wheelBaseHeight = -0.5;
|
|
102
|
+
const wheelRadius = 0.55;
|
|
103
|
+
const suspensionRestLength = 0.8;
|
|
104
|
+
const wheelWidth = 0.53;
|
|
105
|
+
const suspensionStiffness = 20;
|
|
106
|
+
const suspensionCompression = 1.83;
|
|
107
|
+
const suspensionRelaxation = 1.88;
|
|
108
|
+
const sideFrictionStiffness = 2;
|
|
109
|
+
const frictionSlip = 50;
|
|
110
|
+
// Create vehicle movement component
|
|
111
|
+
const vehicleMovement = ENGINE.VehicleMovementComponent.create({
|
|
112
|
+
createWheelMeshes: false,
|
|
113
|
+
maxEnginePower: 100,
|
|
114
|
+
maxBrakeForce: 1.5,
|
|
115
|
+
maxSteeringAngle: Math.PI / 6, // 30 degrees
|
|
116
|
+
engineResponseRate: 8.0,
|
|
117
|
+
steeringResponseRate: 12.0,
|
|
118
|
+
brakeResponseRate: 15.0,
|
|
119
|
+
wheelMaterialColor: 0x333333,
|
|
120
|
+
autoBreakWhenNotPossessed: 1,
|
|
121
|
+
autoStopBreak: 1,
|
|
122
|
+
wheels: [
|
|
123
|
+
// Default 4-wheel configuration
|
|
124
|
+
{
|
|
125
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front left
|
|
126
|
+
radius: wheelRadius,
|
|
127
|
+
width: wheelWidth,
|
|
128
|
+
canSteer: true,
|
|
129
|
+
isPowered: false,
|
|
130
|
+
canBrake: true,
|
|
131
|
+
suspensionRestLength,
|
|
132
|
+
suspensionStiffness,
|
|
133
|
+
suspensionCompression,
|
|
134
|
+
suspensionRelaxation,
|
|
135
|
+
sideFrictionStiffness,
|
|
136
|
+
frictionSlip,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front right
|
|
140
|
+
radius: wheelRadius,
|
|
141
|
+
width: wheelWidth,
|
|
142
|
+
canSteer: true,
|
|
143
|
+
isPowered: false,
|
|
144
|
+
canBrake: true,
|
|
145
|
+
suspensionRestLength,
|
|
146
|
+
suspensionStiffness,
|
|
147
|
+
suspensionCompression,
|
|
148
|
+
suspensionRelaxation,
|
|
149
|
+
sideFrictionStiffness,
|
|
150
|
+
frictionSlip,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear left
|
|
154
|
+
radius: wheelRadius,
|
|
155
|
+
width: wheelWidth,
|
|
156
|
+
canSteer: false,
|
|
157
|
+
isPowered: true,
|
|
158
|
+
canBrake: true,
|
|
159
|
+
suspensionRestLength,
|
|
160
|
+
suspensionStiffness,
|
|
161
|
+
suspensionCompression,
|
|
162
|
+
suspensionRelaxation,
|
|
163
|
+
sideFrictionStiffness,
|
|
164
|
+
frictionSlip,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear right
|
|
168
|
+
radius: wheelRadius,
|
|
169
|
+
width: wheelWidth,
|
|
170
|
+
canSteer: false,
|
|
171
|
+
isPowered: true,
|
|
172
|
+
canBrake: true,
|
|
173
|
+
suspensionRestLength,
|
|
174
|
+
suspensionStiffness,
|
|
175
|
+
suspensionCompression,
|
|
176
|
+
suspensionRelaxation,
|
|
177
|
+
sideFrictionStiffness,
|
|
178
|
+
frictionSlip,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
return vehicleMovement;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
MeshVehicle = MeshVehicle_1 = __decorate([
|
|
186
|
+
ENGINE.GameClass()
|
|
187
|
+
], MeshVehicle);
|
|
188
|
+
export { MeshVehicle };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import * as ENGINE from '@gnsx/genesys.js';
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { BaseVehicle } from './base-vehicle.js';
|
|
10
|
+
/**
|
|
11
|
+
* A vehicle player class.
|
|
12
|
+
*
|
|
13
|
+
* Key points:
|
|
14
|
+
* - No need to provide movementComponent and camera, they are created internally
|
|
15
|
+
* - The pawn is set to be transient so it's never saved in the level
|
|
16
|
+
* - The directional light follows the player for consistent shadows
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
let VehiclePlayer = class VehiclePlayer extends ENGINE.ThirdPersonCharacterPawn {
|
|
20
|
+
// Omit all the options that are created internally
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
// simple camera component - contains a perspective camera by default
|
|
24
|
+
const camera = new THREE.PerspectiveCamera(ENGINE.CAMERA_FOV, 1, 0.1, 1000);
|
|
25
|
+
// set camera position for third person view
|
|
26
|
+
camera.position.set(0, ENGINE.CHARACTER_HEIGHT * 1.3, ENGINE.CHARACTER_HEIGHT * 2);
|
|
27
|
+
camera.lookAt(0, 0, 0);
|
|
28
|
+
// use capsule root component for collision
|
|
29
|
+
const rootComponent = ENGINE.MeshComponent.create({
|
|
30
|
+
geometry: ENGINE.GameBuilder.createDefaultPawnCapsuleGeometry(),
|
|
31
|
+
material: new THREE.MeshStandardMaterial({ color: ENGINE.Color.YELLOW, visible: false, transparent: true, opacity: 0.5 }),
|
|
32
|
+
physicsOptions: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
// KinematicVelocityBased is required to use the physics character controller
|
|
35
|
+
motionType: ENGINE.PhysicsMotionType.KinematicVelocityBased,
|
|
36
|
+
collisionProfile: ENGINE.DefaultCollisionProfile.Character,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
this.setRootComponent(rootComponent, true);
|
|
40
|
+
this.rootComponent.add(camera);
|
|
41
|
+
// use third person movement mechanics
|
|
42
|
+
const movementComponent = ENGINE.CharacterMovementComponent.create({
|
|
43
|
+
movementType: ENGINE.CharacterMovementType.ThirdPerson,
|
|
44
|
+
});
|
|
45
|
+
this.movementComponent = movementComponent;
|
|
46
|
+
// Character model settings
|
|
47
|
+
this.enableDirectionalLightFollowing = true;
|
|
48
|
+
this.configUrl = '@engine/assets/character/config/mannequin-anim.json';
|
|
49
|
+
this.meshComponent.position.copy(new THREE.Vector3(0, -ENGINE.CHARACTER_HEIGHT / 2, 0));
|
|
50
|
+
this.meshComponent.rotation.copy(new THREE.Euler(0, Math.PI, 0));
|
|
51
|
+
rootComponent.add(this.meshComponent);
|
|
52
|
+
// set the pawn to be transient so it's never saved in the level
|
|
53
|
+
this.setTransient(true);
|
|
54
|
+
}
|
|
55
|
+
doBeginPlay() {
|
|
56
|
+
super.doBeginPlay();
|
|
57
|
+
this.setupVehicleInteraction();
|
|
58
|
+
}
|
|
59
|
+
setupVehicleInteraction() {
|
|
60
|
+
// Add E key input handler for vehicle possession
|
|
61
|
+
this.onKeyDown.add((e) => {
|
|
62
|
+
if (e.key.toLowerCase() === 'e') {
|
|
63
|
+
this.tryEnterVehicle();
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
tryEnterVehicle() {
|
|
70
|
+
// Find nearby vehicles that can be entered
|
|
71
|
+
const vehicles = this.world.getActors(BaseVehicle);
|
|
72
|
+
for (const vehicle of vehicles) {
|
|
73
|
+
if (vehicle.canBeEntered() && vehicle.getNearbyPlayer() === this) {
|
|
74
|
+
this.enterVehicle(vehicle);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
enterVehicle(vehicle) {
|
|
80
|
+
// Get the current player controller
|
|
81
|
+
const controller = this.getPlayerController();
|
|
82
|
+
if (controller) {
|
|
83
|
+
// Set this player as the entered player in the vehicle
|
|
84
|
+
vehicle.setEnteredPlayer(this);
|
|
85
|
+
// Unpossess current pawn and possess the vehicle
|
|
86
|
+
controller.unpossess();
|
|
87
|
+
controller.possess(vehicle);
|
|
88
|
+
// Hide the player character
|
|
89
|
+
this.rootComponent.visible = false;
|
|
90
|
+
this.rootComponent.setPhysicsEnabled(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
VehiclePlayer = __decorate([
|
|
95
|
+
ENGINE.GameClass()
|
|
96
|
+
], VehiclePlayer);
|
|
97
|
+
export { VehiclePlayer };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var PrimitiveVehicle_1;
|
|
8
|
+
import * as ENGINE from '@gnsx/genesys.js';
|
|
9
|
+
import * as THREE from 'three';
|
|
10
|
+
import { BaseVehicle } from './base-vehicle.js';
|
|
11
|
+
/**
|
|
12
|
+
* A simple vehicle with a box geometry
|
|
13
|
+
*
|
|
14
|
+
* Key points:
|
|
15
|
+
* - Movement parameters configured in createVehicleMovementComponent
|
|
16
|
+
* - No component is persisted (root is transient) in order to support recreating all the components in code (which is desired)
|
|
17
|
+
* - Rely on the builtin feature to create the wheel mesh (createWheelMeshes = true), no need to create them manually
|
|
18
|
+
* - All decorative meshes have physics disabled won't mess with the handling
|
|
19
|
+
* - Find the tail light meshes after the constructor so it works with deserialized actor
|
|
20
|
+
* - Rely on the base vehicle class to handle the camera and player interaction
|
|
21
|
+
*/
|
|
22
|
+
let PrimitiveVehicle = PrimitiveVehicle_1 = class PrimitiveVehicle extends BaseVehicle {
|
|
23
|
+
tailLightComponents = [];
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
// Create chassis mesh
|
|
27
|
+
const rootComponent = ENGINE.MeshComponent.create({
|
|
28
|
+
geometry: new THREE.BoxGeometry(2, 1, 4),
|
|
29
|
+
material: new THREE.MeshStandardMaterial({
|
|
30
|
+
color: 0x4444FF,
|
|
31
|
+
roughness: 0.7,
|
|
32
|
+
metalness: 0.3,
|
|
33
|
+
}),
|
|
34
|
+
physicsOptions: {
|
|
35
|
+
enabled: true,
|
|
36
|
+
motionType: ENGINE.PhysicsMotionType.Dynamic,
|
|
37
|
+
generateCollisionEvents: true,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
rootComponent.castShadow = true;
|
|
41
|
+
rootComponent.name = 'chassis';
|
|
42
|
+
// mark the component as transient, this prevents all the components from being saved since we're recreating them in code
|
|
43
|
+
rootComponent.setTransient(true);
|
|
44
|
+
this.setRootComponent(rootComponent, true);
|
|
45
|
+
// create decorative meshes
|
|
46
|
+
PrimitiveVehicle_1.createDecorativeMeshes(rootComponent);
|
|
47
|
+
this.movementComponent = PrimitiveVehicle_1.createVehicleMovementComponent();
|
|
48
|
+
this.tailLightComponents = this.getComponents(ENGINE.MeshComponent)
|
|
49
|
+
.filter((component) => component.name.includes('_taillight'));
|
|
50
|
+
}
|
|
51
|
+
tickPrePhysics(deltaTime) {
|
|
52
|
+
super.tickPrePhysics(deltaTime);
|
|
53
|
+
this.updateBrakeLights();
|
|
54
|
+
}
|
|
55
|
+
updateBrakeLights() {
|
|
56
|
+
if (!this.movementComponent || this.tailLightComponents.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
const inputState = this.movementComponent.getInputState();
|
|
59
|
+
const isBraking = inputState.brakeInput > 0;
|
|
60
|
+
for (const tailLightComponent of this.tailLightComponents) {
|
|
61
|
+
const mesh = tailLightComponent.getMesh();
|
|
62
|
+
if (mesh && mesh.material) {
|
|
63
|
+
const material = mesh.material;
|
|
64
|
+
if (isBraking) {
|
|
65
|
+
material.color.setHex(0xFF0000);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
material.color.setHex(0xFFFFFF);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static createDecorativeMeshes(rootComponent) {
|
|
74
|
+
// Add windshield
|
|
75
|
+
const windshieldComponent = ENGINE.MeshComponent.create({
|
|
76
|
+
geometry: new THREE.BoxGeometry(1.8, 1.8, 0.1),
|
|
77
|
+
material: new THREE.MeshStandardMaterial({
|
|
78
|
+
color: 0x87CEEB,
|
|
79
|
+
transparent: true,
|
|
80
|
+
opacity: 0.5,
|
|
81
|
+
roughness: 0.1,
|
|
82
|
+
metalness: 0.1,
|
|
83
|
+
}),
|
|
84
|
+
physicsOptions: {
|
|
85
|
+
enabled: false,
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
windshieldComponent.position.set(0, 0.4, -1.5);
|
|
89
|
+
windshieldComponent.rotation.x = Math.PI / 8; // Slight tilt
|
|
90
|
+
windshieldComponent.name = 'windshield';
|
|
91
|
+
rootComponent.add(windshieldComponent);
|
|
92
|
+
// Add left headlight
|
|
93
|
+
const leftHeadlightComponent = ENGINE.MeshComponent.create({
|
|
94
|
+
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
95
|
+
material: new THREE.MeshStandardMaterial({
|
|
96
|
+
color: 0xFFFFFF,
|
|
97
|
+
emissive: 0xFFFFAA,
|
|
98
|
+
emissiveIntensity: 0.3,
|
|
99
|
+
}),
|
|
100
|
+
physicsOptions: {
|
|
101
|
+
enabled: false,
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
leftHeadlightComponent.position.set(-0.7, 0.1, -2.05);
|
|
105
|
+
leftHeadlightComponent.rotation.z = Math.PI / 2;
|
|
106
|
+
leftHeadlightComponent.name = 'left_headlight';
|
|
107
|
+
rootComponent.add(leftHeadlightComponent);
|
|
108
|
+
// Add right headlight
|
|
109
|
+
const rightHeadlightComponent = ENGINE.MeshComponent.create({
|
|
110
|
+
geometry: new THREE.CylinderGeometry(0.15, 0.15, 0.1, 8),
|
|
111
|
+
material: new THREE.MeshStandardMaterial({
|
|
112
|
+
color: 0xFFFFFF,
|
|
113
|
+
emissive: 0xFFFFAA,
|
|
114
|
+
emissiveIntensity: 0.3,
|
|
115
|
+
}),
|
|
116
|
+
physicsOptions: {
|
|
117
|
+
enabled: false,
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
rightHeadlightComponent.position.set(0.7, 0.1, -2.05);
|
|
121
|
+
rightHeadlightComponent.rotation.z = Math.PI / 2;
|
|
122
|
+
rightHeadlightComponent.name = 'right_headlight';
|
|
123
|
+
rootComponent.add(rightHeadlightComponent);
|
|
124
|
+
// Add left tail light
|
|
125
|
+
const leftTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
126
|
+
color: 0xFF0000,
|
|
127
|
+
emissive: 0x440000,
|
|
128
|
+
emissiveIntensity: 0.2,
|
|
129
|
+
});
|
|
130
|
+
const leftTaillightComponent = ENGINE.MeshComponent.create({
|
|
131
|
+
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
132
|
+
material: leftTaillightMaterial,
|
|
133
|
+
physicsOptions: {
|
|
134
|
+
enabled: false,
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
leftTaillightComponent.position.set(-0.7, 0.1, 2.05);
|
|
138
|
+
leftTaillightComponent.rotation.z = Math.PI / 2;
|
|
139
|
+
leftTaillightComponent.name = 'left_taillight';
|
|
140
|
+
rootComponent.add(leftTaillightComponent);
|
|
141
|
+
// Add right tail light
|
|
142
|
+
const rightTaillightMaterial = new THREE.MeshStandardMaterial({
|
|
143
|
+
color: 0xFF0000,
|
|
144
|
+
emissive: 0x440000,
|
|
145
|
+
emissiveIntensity: 0.2,
|
|
146
|
+
});
|
|
147
|
+
const rightTaillightComponent = ENGINE.MeshComponent.create({
|
|
148
|
+
geometry: new THREE.CylinderGeometry(0.1, 0.1, 0.1, 8),
|
|
149
|
+
material: rightTaillightMaterial,
|
|
150
|
+
physicsOptions: {
|
|
151
|
+
enabled: false,
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
rightTaillightComponent.position.set(0.7, 0.1, 2.05);
|
|
155
|
+
rightTaillightComponent.rotation.z = Math.PI / 2;
|
|
156
|
+
rightTaillightComponent.name = 'right_taillight';
|
|
157
|
+
rootComponent.add(rightTaillightComponent);
|
|
158
|
+
}
|
|
159
|
+
static createVehicleMovementComponent() {
|
|
160
|
+
const wheelBaseWidth = 2.6;
|
|
161
|
+
const wheelBaseLength = 3.0;
|
|
162
|
+
const wheelBaseHeight = 0;
|
|
163
|
+
const suspensionRestLength = 0.6;
|
|
164
|
+
const wheelRadius = 0.5;
|
|
165
|
+
const wheelWidth = 0.4;
|
|
166
|
+
const suspensionStiffness = 20;
|
|
167
|
+
const suspensionCompression = 0.83;
|
|
168
|
+
const suspensionRelaxation = 0.88;
|
|
169
|
+
const maxSuspensionForce = 6000.0;
|
|
170
|
+
const maxSuspensionTravel = 5.0;
|
|
171
|
+
const sideFrictionStiffness = 2;
|
|
172
|
+
const frictionSlip = 8;
|
|
173
|
+
const options = {
|
|
174
|
+
maxEnginePower: 35,
|
|
175
|
+
maxSteeringAngle: Math.PI / 6, // 30 degrees
|
|
176
|
+
maxBrakeForce: 1,
|
|
177
|
+
engineResponseRate: 8.0,
|
|
178
|
+
steeringResponseRate: 12.0,
|
|
179
|
+
brakeResponseRate: 15.0,
|
|
180
|
+
createWheelMeshes: true,
|
|
181
|
+
wheelMaterialColor: 0x333333,
|
|
182
|
+
autoBreakWhenNotPossessed: 1,
|
|
183
|
+
autoStopBreak: 0.5,
|
|
184
|
+
wheels: [
|
|
185
|
+
// Default 4-wheel configuration
|
|
186
|
+
{
|
|
187
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front left
|
|
188
|
+
radius: wheelRadius,
|
|
189
|
+
width: wheelWidth,
|
|
190
|
+
canSteer: true,
|
|
191
|
+
isPowered: false,
|
|
192
|
+
canBrake: true,
|
|
193
|
+
suspensionRestLength,
|
|
194
|
+
suspensionStiffness,
|
|
195
|
+
suspensionCompression,
|
|
196
|
+
suspensionRelaxation,
|
|
197
|
+
maxSuspensionForce,
|
|
198
|
+
maxSuspensionTravel,
|
|
199
|
+
sideFrictionStiffness,
|
|
200
|
+
frictionSlip,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, -wheelBaseLength / 2), // Front right
|
|
204
|
+
radius: wheelRadius,
|
|
205
|
+
width: wheelWidth,
|
|
206
|
+
canSteer: true,
|
|
207
|
+
isPowered: false,
|
|
208
|
+
canBrake: true,
|
|
209
|
+
suspensionRestLength,
|
|
210
|
+
suspensionStiffness,
|
|
211
|
+
suspensionCompression,
|
|
212
|
+
suspensionRelaxation,
|
|
213
|
+
maxSuspensionForce,
|
|
214
|
+
maxSuspensionTravel,
|
|
215
|
+
sideFrictionStiffness,
|
|
216
|
+
frictionSlip,
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
position: new THREE.Vector3(-wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear left
|
|
220
|
+
radius: wheelRadius,
|
|
221
|
+
width: wheelWidth,
|
|
222
|
+
canSteer: false,
|
|
223
|
+
isPowered: true,
|
|
224
|
+
canBrake: true,
|
|
225
|
+
suspensionRestLength,
|
|
226
|
+
suspensionStiffness,
|
|
227
|
+
suspensionCompression,
|
|
228
|
+
suspensionRelaxation,
|
|
229
|
+
maxSuspensionForce,
|
|
230
|
+
maxSuspensionTravel,
|
|
231
|
+
sideFrictionStiffness,
|
|
232
|
+
frictionSlip,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
position: new THREE.Vector3(wheelBaseWidth / 2, wheelBaseHeight, wheelBaseLength / 2), // Rear right
|
|
236
|
+
radius: wheelRadius,
|
|
237
|
+
width: wheelWidth,
|
|
238
|
+
canSteer: false,
|
|
239
|
+
isPowered: true,
|
|
240
|
+
canBrake: true,
|
|
241
|
+
suspensionRestLength,
|
|
242
|
+
suspensionStiffness,
|
|
243
|
+
suspensionCompression,
|
|
244
|
+
suspensionRelaxation,
|
|
245
|
+
maxSuspensionForce,
|
|
246
|
+
maxSuspensionTravel,
|
|
247
|
+
sideFrictionStiffness,
|
|
248
|
+
frictionSlip,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
return ENGINE.VehicleMovementComponent.create(options);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
PrimitiveVehicle = PrimitiveVehicle_1 = __decorate([
|
|
256
|
+
ENGINE.GameClass()
|
|
257
|
+
], PrimitiveVehicle);
|
|
258
|
+
export { PrimitiveVehicle };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import * as ENGINE from '@gnsx/genesys.js';
|
|
8
|
+
/**
|
|
9
|
+
* Dismissable UI component that displays control hints when the game starts
|
|
10
|
+
*/
|
|
11
|
+
let UIHints = class UIHints extends ENGINE.Actor {
|
|
12
|
+
uiElement = null;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.setTransient(true); // Don't save this UI element to the level
|
|
16
|
+
}
|
|
17
|
+
doBeginPlay() {
|
|
18
|
+
super.doBeginPlay();
|
|
19
|
+
this.createHUD();
|
|
20
|
+
}
|
|
21
|
+
doEndPlay() {
|
|
22
|
+
this.removeHUD();
|
|
23
|
+
super.doEndPlay();
|
|
24
|
+
}
|
|
25
|
+
createHUD() {
|
|
26
|
+
const uiManager = this.world.uiManager;
|
|
27
|
+
// Create the UI element using the engine's UI system
|
|
28
|
+
this.uiElement = uiManager.createElement('game-hints', {
|
|
29
|
+
style: {
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
top: '50px',
|
|
32
|
+
right: '50px',
|
|
33
|
+
background: 'rgba(0, 0, 0, 0.9)',
|
|
34
|
+
color: 'white',
|
|
35
|
+
padding: '25px',
|
|
36
|
+
borderRadius: '12px',
|
|
37
|
+
fontFamily: 'Arial, sans-serif',
|
|
38
|
+
fontSize: '16px',
|
|
39
|
+
lineHeight: '1.5',
|
|
40
|
+
maxWidth: '400px',
|
|
41
|
+
border: '2px solid rgba(76, 175, 80, 0.6)',
|
|
42
|
+
boxShadow: '0 8px 32px rgba(0, 0, 0, 0.8)',
|
|
43
|
+
zIndex: '1001'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// Set the HTML content
|
|
47
|
+
this.uiElement.setHTML(`
|
|
48
|
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
|
|
49
|
+
<div style="font-weight: bold; color: #4CAF50; font-size: 18px;">
|
|
50
|
+
🎮 Vehicle Game Controls
|
|
51
|
+
</div>
|
|
52
|
+
<button id="closeHints" style="
|
|
53
|
+
background: #f44336;
|
|
54
|
+
color: white;
|
|
55
|
+
border: none;
|
|
56
|
+
border-radius: 50%;
|
|
57
|
+
width: 30px;
|
|
58
|
+
height: 30px;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
font-size: 16px;
|
|
61
|
+
font-weight: bold;
|
|
62
|
+
">×</button>
|
|
63
|
+
</div>
|
|
64
|
+
<div style="margin-bottom: 12px;">
|
|
65
|
+
<span style="color: #FFA726; font-weight: bold;">Movement:</span>
|
|
66
|
+
<br>• WASD or Arrow Keys - Move/Drive
|
|
67
|
+
<br>• Mouse - Camera control
|
|
68
|
+
</div>
|
|
69
|
+
<div style="margin-bottom: 12px;">
|
|
70
|
+
<span style="color: #FFA726; font-weight: bold;">Vehicle Interaction:</span>
|
|
71
|
+
<br>• E - Enter/Exit vehicle (when nearby)
|
|
72
|
+
<br>• F - Flip vehicle (when inside)
|
|
73
|
+
</div>
|
|
74
|
+
<div style="font-size: 14px; color: #CCCCCC; margin-top: 15px; text-align: center; font-style: italic;">
|
|
75
|
+
💡 Walk near a vehicle and press E to enter
|
|
76
|
+
</div>
|
|
77
|
+
`);
|
|
78
|
+
// Add close button functionality
|
|
79
|
+
const closeButton = this.uiElement.querySelector('#closeHints');
|
|
80
|
+
if (closeButton) {
|
|
81
|
+
closeButton.addEventListener('click', () => {
|
|
82
|
+
this.removeHUD();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Auto-close after 10 seconds
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
this.removeHUD();
|
|
88
|
+
}, 10000);
|
|
89
|
+
}
|
|
90
|
+
removeHUD() {
|
|
91
|
+
if (this.uiElement) {
|
|
92
|
+
this.uiElement.remove();
|
|
93
|
+
this.uiElement = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
UIHints = __decorate([
|
|
98
|
+
ENGINE.GameClass()
|
|
99
|
+
], UIHints);
|
|
100
|
+
export { UIHints };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './sample-vr-actor.ts';
|