@bendyline/molen-client 0.0.10 → 0.0.12
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 +1 -0
- package/dist/aircraft.d.mts +89 -4
- package/dist/aircraft.mjs +737 -8
- package/dist/audio.d.mts +10 -1
- package/dist/audio.mjs +131 -6
- package/dist/camera-track.d.mts +1 -1
- package/dist/clouds-DmASLVoe.mjs +862 -0
- package/dist/glass.d.mts +19 -0
- package/dist/glass.mjs +249 -0
- package/dist/index.d.mts +34 -6
- package/dist/index.mjs +917 -171
- package/dist/{input-BVZjf4T-.mjs → input-BliZYUY1.mjs} +42 -12
- package/dist/{input-CD-dHuv0.d.mts → input-Ckev_Kvj.d.mts} +9 -0
- package/dist/livery-qcDLzbU9.mjs +307 -0
- package/dist/navigation.d.mts +54 -10
- package/dist/navigation.mjs +646 -220
- package/dist/{renderer-CtEtmwJG.d.mts → renderer-DAk7C8jH.d.mts} +318 -24
- package/dist/vehicle-interior-B8TpzTAx.d.mts +56 -0
- package/dist/vehicle-interior-CeyzF5El.mjs +455 -0
- package/dist/vehicles.d.mts +26 -20
- package/dist/vehicles.mjs +317 -71
- package/dist/webgpu-clouds-H03g7ID1.mjs +186 -0
- package/package.json +7 -3
- package/dist/vehicle-interior-BgcC750p.d.mts +0 -31
- package/dist/vehicle-interior-DfpZwWEh.mjs +0 -15
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { inputProfileIssues, inputProfileSchema } from "@bendyline/molen-schema";
|
|
2
2
|
//#region src/input.ts
|
|
3
|
+
/** With no gamepad announced, the browser's pads are still polled every this many updates. */
|
|
4
|
+
const IDLE_POLL = 120;
|
|
3
5
|
/** Resolve a key or Mouse<button> code to its bound action. */
|
|
4
6
|
function resolveAction(bindings, code) {
|
|
5
7
|
return Object.hasOwn(bindings, code) ? bindings[code] : void 0;
|
|
@@ -59,6 +61,13 @@ var InputMap = class {
|
|
|
59
61
|
provider;
|
|
60
62
|
listeners = [];
|
|
61
63
|
status = "unavailable";
|
|
64
|
+
/**
|
|
65
|
+
* With the browser's own gamepads and a target that reports `gamepadconnected`, the pads
|
|
66
|
+
* connected since (and the updates since the last poll): `navigator.getGamepads()` blocked
|
|
67
|
+
* Chrome's main thread several milliseconds a frame on Windows with no gamepad attached.
|
|
68
|
+
*/
|
|
69
|
+
padsAnnounced;
|
|
70
|
+
idleUpdates = 0;
|
|
62
71
|
constructor(opts) {
|
|
63
72
|
this.base = copyProfile({
|
|
64
73
|
bindings: opts.bindings,
|
|
@@ -72,6 +81,19 @@ var InputMap = class {
|
|
|
72
81
|
this.provider = opts.getGamepads ?? (() => typeof navigator !== "undefined" && typeof navigator.getGamepads === "function" ? navigator.getGamepads() : []);
|
|
73
82
|
if (opts.getGamepads || typeof navigator !== "undefined" && typeof navigator.getGamepads === "function") this.status = "available";
|
|
74
83
|
if (this.target) this.attach(this.target);
|
|
84
|
+
if (opts.getGamepads === void 0 && this.target && this.status === "available") {
|
|
85
|
+
this.padsAnnounced = 0;
|
|
86
|
+
const add = (type, fn) => {
|
|
87
|
+
this.target?.addEventListener(type, fn);
|
|
88
|
+
this.listeners.push([type, fn]);
|
|
89
|
+
};
|
|
90
|
+
add("gamepadconnected", () => {
|
|
91
|
+
this.padsAnnounced = (this.padsAnnounced ?? 0) + 1;
|
|
92
|
+
});
|
|
93
|
+
add("gamepaddisconnected", () => {
|
|
94
|
+
this.padsAnnounced = Math.max(0, (this.padsAnnounced ?? 0) - 1);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
75
97
|
}
|
|
76
98
|
get accepting() {
|
|
77
99
|
return this.enabled && this.focused && this.suspensions === 0;
|
|
@@ -123,19 +145,23 @@ var InputMap = class {
|
|
|
123
145
|
/** Poll fresh browser objects; unplugging or losing permission releases affected controls. */
|
|
124
146
|
update() {
|
|
125
147
|
if (this.disposed) return;
|
|
148
|
+
const quiet = this.padsAnnounced === 0 && this.pads.length === 0 && this.idleUpdates++ % IDLE_POLL !== 0;
|
|
126
149
|
try {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
150
|
+
if (quiet) this.pads = [];
|
|
151
|
+
else {
|
|
152
|
+
this.pads = this.provider().filter((pad) => pad?.connected === true).map((pad) => ({
|
|
153
|
+
id: pad.id,
|
|
154
|
+
index: pad.index,
|
|
155
|
+
connected: pad.connected,
|
|
156
|
+
mapping: pad.mapping,
|
|
157
|
+
axes: Array.from(pad.axes),
|
|
158
|
+
buttons: Array.from(pad.buttons, (button) => ({
|
|
159
|
+
pressed: button.pressed,
|
|
160
|
+
value: button.value
|
|
161
|
+
}))
|
|
162
|
+
}));
|
|
163
|
+
if (this.status === "blocked") this.status = "available";
|
|
164
|
+
}
|
|
139
165
|
} catch {
|
|
140
166
|
this.pads = [];
|
|
141
167
|
this.status = "blocked";
|
|
@@ -262,6 +288,10 @@ var InputMap = class {
|
|
|
262
288
|
value(action) {
|
|
263
289
|
return this.values.get(action) ?? 0;
|
|
264
290
|
}
|
|
291
|
+
/** Whether an enabled, connected axis supplies this action, including a zero reading. */
|
|
292
|
+
hasAxis(action) {
|
|
293
|
+
return !this.disposed && this.accepting && (this.profile.axes ?? []).some((binding) => binding.action === action && this.pads.some((pad) => matches(binding.device, pad) && Number.isFinite(pad.axes[binding.axis])));
|
|
294
|
+
}
|
|
265
295
|
isActive(action) {
|
|
266
296
|
return this.value(action) !== 0;
|
|
267
297
|
}
|
|
@@ -64,6 +64,13 @@ declare class InputMap {
|
|
|
64
64
|
private readonly provider;
|
|
65
65
|
private readonly listeners;
|
|
66
66
|
private status;
|
|
67
|
+
/**
|
|
68
|
+
* With the browser's own gamepads and a target that reports `gamepadconnected`, the pads
|
|
69
|
+
* connected since (and the updates since the last poll): `navigator.getGamepads()` blocked
|
|
70
|
+
* Chrome's main thread several milliseconds a frame on Windows with no gamepad attached.
|
|
71
|
+
*/
|
|
72
|
+
private padsAnnounced;
|
|
73
|
+
private idleUpdates;
|
|
67
74
|
constructor(opts: InputMapOptions);
|
|
68
75
|
private get accepting();
|
|
69
76
|
private get profile();
|
|
@@ -98,6 +105,8 @@ declare class InputMap {
|
|
|
98
105
|
clearVirtual(source?: string): void;
|
|
99
106
|
/** Numeric action value; strongest absolute contribution wins, keyboard wins ties. */
|
|
100
107
|
value(action: string): number;
|
|
108
|
+
/** Whether an enabled, connected axis supplies this action, including a zero reading. */
|
|
109
|
+
hasAxis(action: string): boolean;
|
|
101
110
|
isActive(action: string): boolean;
|
|
102
111
|
activeActions(): Set<string>;
|
|
103
112
|
private contribute;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { DecalGeometry } from "three/addons/geometries/DecalGeometry.js";
|
|
3
|
+
//#region src/livery.ts
|
|
4
|
+
function inside(x, y, points) {
|
|
5
|
+
let hit = false;
|
|
6
|
+
for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
|
|
7
|
+
const a = points[i], b = points[j];
|
|
8
|
+
if (a[1] > y !== b[1] > y && x < (b[0] - a[0]) * (y - a[1]) / (b[1] - a[1]) + a[0]) hit = !hit;
|
|
9
|
+
}
|
|
10
|
+
return hit;
|
|
11
|
+
}
|
|
12
|
+
function textureFrom(bytes, size) {
|
|
13
|
+
const texture = new THREE.DataTexture(bytes, size, size);
|
|
14
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
15
|
+
texture.magFilter = THREE.LinearFilter;
|
|
16
|
+
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
17
|
+
texture.generateMipmaps = true;
|
|
18
|
+
texture.needsUpdate = true;
|
|
19
|
+
return texture;
|
|
20
|
+
}
|
|
21
|
+
/** Flat vector artwork, including outlined text; no browser fonts or image downloads. */
|
|
22
|
+
function liveryGraphicTexture(graphic, size = 256) {
|
|
23
|
+
const bytes = new Uint8Array(size * size * 4);
|
|
24
|
+
for (const shape of graphic.shapes) {
|
|
25
|
+
const hex = Number.parseInt(shape.color.slice(1), 16);
|
|
26
|
+
const xs = shape.points.map((p) => p[0]), ys = shape.points.map((p) => p[1]);
|
|
27
|
+
const x0 = Math.max(0, Math.floor(Math.min(...xs) * size)), x1 = Math.min(size, Math.ceil(Math.max(...xs) * size));
|
|
28
|
+
const y0 = Math.max(0, Math.floor(Math.min(...ys) * size)), y1 = Math.min(size, Math.ceil(Math.max(...ys) * size));
|
|
29
|
+
for (let y = y0; y < y1; y++) for (let x = x0; x < x1; x++) {
|
|
30
|
+
if (!inside((x + .5) / size, (y + .5) / size, shape.points)) continue;
|
|
31
|
+
const i = (y * size + x) * 4;
|
|
32
|
+
bytes[i] = hex >> 16 & 255;
|
|
33
|
+
bytes[i + 1] = hex >> 8 & 255;
|
|
34
|
+
bytes[i + 2] = hex & 255;
|
|
35
|
+
bytes[i + 3] = 255;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return textureFrom(bytes, size);
|
|
39
|
+
}
|
|
40
|
+
function camouflageTexture(pattern, channel) {
|
|
41
|
+
const size = 128, bytes = new Uint8Array(size * size * 4);
|
|
42
|
+
const hash = (x, y) => {
|
|
43
|
+
let h = Math.imul((x & 7) + 31 * (y & 7), 374761393) ^ pattern.seed;
|
|
44
|
+
h = Math.imul(h ^ h >>> 13, 1274126177);
|
|
45
|
+
return ((h ^ h >>> 16) >>> 0) / 4294967296;
|
|
46
|
+
};
|
|
47
|
+
for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {
|
|
48
|
+
const fx = x * 8 / size, fy = y * 8 / size, ix = Math.floor(fx), iy = Math.floor(fy);
|
|
49
|
+
let u = fx - ix, v = fy - iy;
|
|
50
|
+
u = u * u * (3 - 2 * u);
|
|
51
|
+
v = v * v * (3 - 2 * v);
|
|
52
|
+
const n = THREE.MathUtils.lerp(THREE.MathUtils.lerp(hash(ix, iy), hash(ix + 1, iy), u), THREE.MathUtils.lerp(hash(ix, iy + 1), hash(ix + 1, iy + 1), u), v);
|
|
53
|
+
const color = pattern.colors[Math.min(pattern.colors.length - 1, Math.floor(n * pattern.colors.length))];
|
|
54
|
+
const hex = Number.parseInt(color.slice(1), 16), i = (y * size + x) * 4;
|
|
55
|
+
bytes[i] = hex >> 16 & 255;
|
|
56
|
+
bytes[i + 1] = hex >> 8 & 255;
|
|
57
|
+
bytes[i + 2] = hex & 255;
|
|
58
|
+
bytes[i + 3] = 255;
|
|
59
|
+
}
|
|
60
|
+
const texture = textureFrom(bytes, size);
|
|
61
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
62
|
+
texture.channel = channel;
|
|
63
|
+
texture.repeat.setScalar(pattern.scale);
|
|
64
|
+
return texture;
|
|
65
|
+
}
|
|
66
|
+
const materialsOf = (mesh) => Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
67
|
+
const restMatrices = /* @__PURE__ */ new WeakMap();
|
|
68
|
+
/** Extract just a slot's triangles, including material arrays with geometry groups. */
|
|
69
|
+
function surfaceGeometry(mesh, names) {
|
|
70
|
+
const source = mesh.geometry.index ? mesh.geometry.toNonIndexed() : mesh.geometry.clone();
|
|
71
|
+
const materials = materialsOf(mesh), groups = Array.isArray(mesh.material) ? source.groups : [{
|
|
72
|
+
start: 0,
|
|
73
|
+
count: source.getAttribute("position").count,
|
|
74
|
+
materialIndex: 0
|
|
75
|
+
}];
|
|
76
|
+
const positions = [], normals = [];
|
|
77
|
+
const p = source.getAttribute("position"), n = source.getAttribute("normal");
|
|
78
|
+
for (const group of groups) {
|
|
79
|
+
if (!names.has(materials[group.materialIndex ?? 0]?.name ?? "")) continue;
|
|
80
|
+
for (let i = group.start; i < Math.min(p.count, group.start + group.count); i++) {
|
|
81
|
+
positions.push(p.getX(i), p.getY(i), p.getZ(i));
|
|
82
|
+
if (n) normals.push(n.getX(i), n.getY(i), n.getZ(i));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
source.dispose();
|
|
86
|
+
const geometry = new THREE.BufferGeometry();
|
|
87
|
+
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
|
88
|
+
if (normals.length) geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
|
|
89
|
+
else geometry.computeVertexNormals();
|
|
90
|
+
return geometry;
|
|
91
|
+
}
|
|
92
|
+
function projectPaint(mesh, bounds, transform, names, channel) {
|
|
93
|
+
const geometry = mesh.geometry.index ? mesh.geometry.toNonIndexed() : mesh.geometry.clone();
|
|
94
|
+
const attribute = channel === 0 ? "uv" : `uv${channel}`;
|
|
95
|
+
const p = geometry.getAttribute("position"), uv = geometry.getAttribute(attribute) ? Float32Array.from(geometry.getAttribute(attribute).array) : new Float32Array(p.count * 2);
|
|
96
|
+
const selected = new Uint8Array(p.count);
|
|
97
|
+
if (!Array.isArray(mesh.material)) selected.fill(1);
|
|
98
|
+
else for (const group of geometry.groups) {
|
|
99
|
+
if (!names.includes(mesh.material[group.materialIndex ?? 0]?.name ?? "")) continue;
|
|
100
|
+
selected.fill(1, group.start, Math.min(p.count, group.start + group.count));
|
|
101
|
+
}
|
|
102
|
+
const extent = bounds.getSize(new THREE.Vector3()), scale = Math.max(extent.x, extent.y, extent.z, .001);
|
|
103
|
+
const a = new THREE.Vector3(), b = new THREE.Vector3(), c = new THREE.Vector3();
|
|
104
|
+
for (let i = 0; i < p.count; i += 3) {
|
|
105
|
+
if (!selected[i]) continue;
|
|
106
|
+
a.fromBufferAttribute(p, i).applyMatrix4(transform);
|
|
107
|
+
b.fromBufferAttribute(p, i + 1).applyMatrix4(transform);
|
|
108
|
+
c.fromBufferAttribute(p, i + 2).applyMatrix4(transform);
|
|
109
|
+
const normal = b.clone().sub(a).cross(c.clone().sub(a));
|
|
110
|
+
const axis = Math.abs(normal.y) >= Math.max(Math.abs(normal.x), Math.abs(normal.z)) ? "y" : Math.abs(normal.x) > Math.abs(normal.z) ? "x" : "z";
|
|
111
|
+
for (const [j, point] of [
|
|
112
|
+
a,
|
|
113
|
+
b,
|
|
114
|
+
c
|
|
115
|
+
].entries()) {
|
|
116
|
+
uv[(i + j) * 2] = ((axis === "x" ? point.z : point.x) - (axis === "x" ? bounds.min.z : bounds.min.x)) / scale;
|
|
117
|
+
uv[(i + j) * 2 + 1] = ((axis === "y" ? point.z : point.y) - (axis === "y" ? bounds.min.z : bounds.min.y)) / scale;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
geometry.setAttribute(attribute, new THREE.BufferAttribute(uv, 2));
|
|
121
|
+
return geometry;
|
|
122
|
+
}
|
|
123
|
+
/** Apply to an instance, never a cache template. Does not mutate shared materials or geometry. */
|
|
124
|
+
function applyLivery(model, data) {
|
|
125
|
+
const variant = data.variants.find((v) => v.id === data.selected);
|
|
126
|
+
if (!variant) throw new Error(`Unknown livery: ${data.selected}`);
|
|
127
|
+
const warnings = [];
|
|
128
|
+
const originals = /* @__PURE__ */ new Map();
|
|
129
|
+
const materials = /* @__PURE__ */ new Set(), geometries = /* @__PURE__ */ new Set(), textures = /* @__PURE__ */ new Set();
|
|
130
|
+
const decals = [];
|
|
131
|
+
const remember = (mesh) => {
|
|
132
|
+
if (!originals.has(mesh)) originals.set(mesh, {
|
|
133
|
+
material: mesh.material,
|
|
134
|
+
geometry: mesh.geometry
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
model.updateWorldMatrix(true, true);
|
|
138
|
+
const rootInverse = model.matrixWorld.clone().invert();
|
|
139
|
+
let rest = restMatrices.get(model);
|
|
140
|
+
if (!rest) {
|
|
141
|
+
rest = /* @__PURE__ */ new Map();
|
|
142
|
+
model.traverse((object) => {
|
|
143
|
+
if (object instanceof THREE.Mesh) rest?.set(object, rootInverse.clone().multiply(object.matrixWorld));
|
|
144
|
+
});
|
|
145
|
+
restMatrices.set(model, rest);
|
|
146
|
+
}
|
|
147
|
+
const matrix = (mesh) => (rest?.get(mesh) ?? rootInverse.clone().multiply(mesh.matrixWorld)).clone();
|
|
148
|
+
const slots = /* @__PURE__ */ new Map();
|
|
149
|
+
for (const [name, binding] of Object.entries(data.slots)) {
|
|
150
|
+
const subtree = binding.node === void 0 ? model : model.getObjectByName(binding.node);
|
|
151
|
+
const meshes = [], bounds = new THREE.Box3();
|
|
152
|
+
const collect = (object) => {
|
|
153
|
+
if (!(object instanceof THREE.Mesh) || meshes.includes(object) || !materialsOf(object).some((m) => binding.materials.includes(m.name))) return;
|
|
154
|
+
if (object.isSkinnedMesh || object.morphTargetInfluences?.length) {
|
|
155
|
+
warnings.push(`Slot ${name}: deforming mesh ${object.name} is unsupported`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
meshes.push(object);
|
|
159
|
+
const surface = surfaceGeometry(object, new Set(binding.materials));
|
|
160
|
+
surface.applyMatrix4(matrix(object));
|
|
161
|
+
surface.computeBoundingBox();
|
|
162
|
+
if (surface.boundingBox) bounds.union(surface.boundingBox);
|
|
163
|
+
surface.dispose();
|
|
164
|
+
};
|
|
165
|
+
subtree?.traverse(collect);
|
|
166
|
+
if (binding.node !== void 0) model.traverse((object) => {
|
|
167
|
+
const sources = object.userData.liverySourceNodes;
|
|
168
|
+
if (Array.isArray(sources) && sources.includes(binding.node)) collect(object);
|
|
169
|
+
});
|
|
170
|
+
if (!meshes.length || bounds.isEmpty()) warnings.push(`Slot ${name}: no matching surface`);
|
|
171
|
+
slots.set(name, {
|
|
172
|
+
meshes,
|
|
173
|
+
bounds,
|
|
174
|
+
binding
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const painted = /* @__PURE__ */ new Map();
|
|
178
|
+
const occupiedChannels = /* @__PURE__ */ new Set();
|
|
179
|
+
model.traverse((object) => {
|
|
180
|
+
if (!(object instanceof THREE.Mesh)) return;
|
|
181
|
+
for (const material of materialsOf(object)) for (const value of Object.values(material)) if (value instanceof THREE.Texture) occupiedChannels.add(value.channel);
|
|
182
|
+
});
|
|
183
|
+
const channel = [
|
|
184
|
+
3,
|
|
185
|
+
2,
|
|
186
|
+
1,
|
|
187
|
+
0
|
|
188
|
+
].find((candidate) => !occupiedChannels.has(candidate));
|
|
189
|
+
for (const [name, paint] of Object.entries(variant.paints)) {
|
|
190
|
+
const slot = slots.get(name);
|
|
191
|
+
if (!slot || slot.bounds.isEmpty()) {
|
|
192
|
+
warnings.push(`Paint ${name}: missing slot`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const clones = /* @__PURE__ */ new Map();
|
|
196
|
+
if (paint.camouflage && channel === void 0) warnings.push(`Paint ${name}: no unused UV channel for camouflage; using the base color`);
|
|
197
|
+
const texture = paint.camouflage && channel !== void 0 ? camouflageTexture(paint.camouflage, channel) : void 0;
|
|
198
|
+
if (texture) textures.add(texture);
|
|
199
|
+
for (const mesh of slot.meshes) {
|
|
200
|
+
remember(mesh);
|
|
201
|
+
const used = painted.get(mesh) ?? /* @__PURE__ */ new Set();
|
|
202
|
+
painted.set(mesh, used);
|
|
203
|
+
const next = materialsOf(mesh).map((source, index) => {
|
|
204
|
+
if (!slot.binding.materials.includes(source.name)) return source;
|
|
205
|
+
if (used.has(index)) {
|
|
206
|
+
warnings.push(`Paint ${name}: overlapping slot on ${mesh.name}`);
|
|
207
|
+
return source;
|
|
208
|
+
}
|
|
209
|
+
used.add(index);
|
|
210
|
+
let clone = clones.get(source);
|
|
211
|
+
if (!clone) {
|
|
212
|
+
clone = source.clone();
|
|
213
|
+
clones.set(source, clone);
|
|
214
|
+
materials.add(clone);
|
|
215
|
+
if ("color" in clone) clone.color.set(paint.color);
|
|
216
|
+
if ("roughness" in clone && paint.roughness !== void 0) clone.roughness = paint.roughness;
|
|
217
|
+
if ("metalness" in clone && paint.metalness !== void 0) clone.metalness = paint.metalness;
|
|
218
|
+
if ("map" in clone) clone.map = texture ?? null;
|
|
219
|
+
if (texture && "color" in clone) clone.color.set("#ffffff");
|
|
220
|
+
clone.needsUpdate = true;
|
|
221
|
+
}
|
|
222
|
+
return clone;
|
|
223
|
+
});
|
|
224
|
+
mesh.material = Array.isArray(mesh.material) ? next : next[0];
|
|
225
|
+
if (texture) {
|
|
226
|
+
mesh.geometry = projectPaint(mesh, slot.bounds, matrix(mesh), slot.binding.materials, texture.channel);
|
|
227
|
+
geometries.add(mesh.geometry);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const marking of variant.markings ?? []) {
|
|
232
|
+
const anchor = data.anchors?.[marking.anchor], slot = anchor && slots.get(anchor.slot);
|
|
233
|
+
if (!anchor || !slot || slot.bounds.isEmpty()) {
|
|
234
|
+
warnings.push(`Marking ${marking.anchor}: missing surface`);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const extent = slot.bounds.getSize(new THREE.Vector3());
|
|
238
|
+
const position = new THREE.Vector3(...anchor.position).multiply(extent).add(slot.bounds.min);
|
|
239
|
+
const size = new THREE.Vector3(...anchor.size).multiplyScalar(Math.max(extent.x, extent.y, extent.z));
|
|
240
|
+
const rotation = new THREE.Euler(...anchor.rotation);
|
|
241
|
+
const direction = new THREE.Vector3(0, 0, 1).applyEuler(rotation);
|
|
242
|
+
const texture = liveryGraphicTexture(marking.graphic);
|
|
243
|
+
textures.add(texture);
|
|
244
|
+
const material = new THREE.MeshStandardMaterial({
|
|
245
|
+
map: texture,
|
|
246
|
+
transparent: true,
|
|
247
|
+
depthWrite: false,
|
|
248
|
+
roughness: .65,
|
|
249
|
+
polygonOffset: true,
|
|
250
|
+
polygonOffsetFactor: -2,
|
|
251
|
+
polygonOffsetUnits: -2
|
|
252
|
+
});
|
|
253
|
+
materials.add(material);
|
|
254
|
+
let count = 0;
|
|
255
|
+
for (const mesh of slot.meshes) {
|
|
256
|
+
const surface = surfaceGeometry(mesh, new Set(slot.binding.materials));
|
|
257
|
+
const toRoot = matrix(mesh);
|
|
258
|
+
surface.applyMatrix4(toRoot);
|
|
259
|
+
const p = surface.getAttribute("position"), n = surface.getAttribute("normal"), indices = [];
|
|
260
|
+
const doubleSided = materialsOf(mesh).some((m) => slot.binding.materials.includes(m.name) && m.side === THREE.DoubleSide);
|
|
261
|
+
for (let i = 0; i < p.count; i += 3) {
|
|
262
|
+
const facing = new THREE.Vector3().fromBufferAttribute(n, i).dot(direction);
|
|
263
|
+
if (facing > .05) indices.push(i, i + 1, i + 2);
|
|
264
|
+
else if (doubleSided && facing < -.05) {
|
|
265
|
+
indices.push(i, i + 2, i + 1);
|
|
266
|
+
for (let j = i; j < i + 3; j++) n.setXYZ(j, -n.getX(j), -n.getY(j), -n.getZ(j));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
surface.setIndex(indices);
|
|
270
|
+
const geometry = new DecalGeometry(new THREE.Mesh(surface), position, rotation, size);
|
|
271
|
+
surface.dispose();
|
|
272
|
+
if (!geometry.getAttribute("position").count) {
|
|
273
|
+
geometry.dispose();
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
geometry.applyMatrix4(toRoot.invert());
|
|
277
|
+
geometries.add(geometry);
|
|
278
|
+
const decal = new THREE.Mesh(geometry, material);
|
|
279
|
+
decal.name = `livery:${marking.anchor}`;
|
|
280
|
+
decal.userData.liveryMarking = true;
|
|
281
|
+
decal.receiveShadow = true;
|
|
282
|
+
decal.renderOrder = 1;
|
|
283
|
+
mesh.add(decal);
|
|
284
|
+
decals.push(decal);
|
|
285
|
+
count++;
|
|
286
|
+
}
|
|
287
|
+
if (!count) warnings.push(`Marking ${marking.anchor}: projector misses its surface`);
|
|
288
|
+
}
|
|
289
|
+
let disposed = false;
|
|
290
|
+
return {
|
|
291
|
+
warnings,
|
|
292
|
+
dispose() {
|
|
293
|
+
if (disposed) return;
|
|
294
|
+
disposed = true;
|
|
295
|
+
for (const decal of decals) decal.removeFromParent();
|
|
296
|
+
for (const [mesh, original] of originals) {
|
|
297
|
+
mesh.material = original.material;
|
|
298
|
+
mesh.geometry = original.geometry;
|
|
299
|
+
}
|
|
300
|
+
for (const geometry of geometries) geometry.dispose();
|
|
301
|
+
for (const material of materials) material.dispose();
|
|
302
|
+
for (const texture of textures) texture.dispose();
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
export { liveryGraphicTexture as n, applyLivery as t };
|
package/dist/navigation.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as InputGamepad, r as InputMap } from "./input-
|
|
1
|
+
import { n as InputGamepad, r as InputMap } from "./input-Ckev_Kvj.mjs";
|
|
2
2
|
import { InputProfile } from "@bendyline/molen-schema";
|
|
3
3
|
import * as THREE from "three";
|
|
4
4
|
import { Octree } from "three/addons/math/Octree.js";
|
|
@@ -165,8 +165,10 @@ declare const NAVIGATION_ACTIONS: {
|
|
|
165
165
|
readonly jump: "nav-jump";
|
|
166
166
|
readonly interact: "nav-interact";
|
|
167
167
|
readonly view: "nav-view";
|
|
168
|
+
readonly boost: "nav-boost";
|
|
168
169
|
readonly throttleUp: "nav-throttle-up";
|
|
169
170
|
readonly throttleDown: "nav-throttle-down";
|
|
171
|
+
readonly power: "nav-power";
|
|
170
172
|
readonly yawLeft: "nav-yaw-left";
|
|
171
173
|
readonly yawRight: "nav-yaw-right";
|
|
172
174
|
readonly engine: "nav-engine";
|
|
@@ -181,14 +183,17 @@ type NavigationProfileName = "orbit" | "fly" | "walk" | "drive" | "pilot";
|
|
|
181
183
|
* Default key/gamepad bindings per navigation mode. Orbit and fly use Q/E for down/up; walk and
|
|
182
184
|
* drive use E to interact (board or leave a vehicle), Space to jump or brake, Shift to sprint
|
|
183
185
|
* or pull the handbrake, and V to switch the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
184
|
-
* bank,
|
|
186
|
+
* bank, Z/C work the rudder or pedals, =/− (or numpad +/−, Page Up/Down) set throttle or
|
|
185
187
|
* collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space
|
|
186
|
-
* brakes, V switches the view and E leaves.
|
|
188
|
+
* brakes, V switches the view and E leaves. T toggles travel boost in walk, drive and pilot.
|
|
189
|
+
* Hosts may replace any profile through
|
|
187
190
|
* `InputMap.defineProfile`.
|
|
188
191
|
*/
|
|
189
192
|
declare function navigationInputProfiles(): Record<NavigationProfileName, InputProfile>;
|
|
190
193
|
/** Flight controls beyond pitch (`-move.forward`) and roll (`move.right`), in the pilot profile. */
|
|
191
194
|
interface PilotInput {
|
|
195
|
+
/** Absolute throttle/collective, 0..1, only while a mapped hardware axis is connected. */
|
|
196
|
+
power?: number;
|
|
192
197
|
/** Held throttle or collective change, -1..1 (more power positive). */
|
|
193
198
|
throttle: number;
|
|
194
199
|
/** Held rudder or pedals, -1..1 (right positive). */
|
|
@@ -203,6 +208,10 @@ interface PilotInput {
|
|
|
203
208
|
}
|
|
204
209
|
/** Everything a navigation controller reads in one frame. */
|
|
205
210
|
interface NavigationInput {
|
|
211
|
+
/** Repair presses in the drive profile (R); the host requires a stopped vehicle. */
|
|
212
|
+
recover?: number;
|
|
213
|
+
/** Edge-triggered model mechanism toggles; unsupported mechanisms are ignored by hosts. */
|
|
214
|
+
actuators?: Record<string, number>;
|
|
206
215
|
/** Movement intent, each -1..1 (forward, right, up). */
|
|
207
216
|
move: {
|
|
208
217
|
forward: number;
|
|
@@ -224,6 +233,8 @@ interface NavigationInput {
|
|
|
224
233
|
interact: number;
|
|
225
234
|
/** Presses of the view toggle since the previous frame (edge-triggered). */
|
|
226
235
|
view: number;
|
|
236
|
+
/** Presses of the 4× travel boost toggle (T), edge-triggered. */
|
|
237
|
+
boost?: number;
|
|
227
238
|
/** Clicks/taps in element-relative CSS pixels. */
|
|
228
239
|
taps: Array<{
|
|
229
240
|
x: number;
|
|
@@ -263,6 +274,8 @@ declare class NavigationInputSource {
|
|
|
263
274
|
readonly pointer: NavigationPointer;
|
|
264
275
|
private interactPresses;
|
|
265
276
|
private viewPresses;
|
|
277
|
+
private boostPresses;
|
|
278
|
+
private actuatorPresses;
|
|
266
279
|
private profile;
|
|
267
280
|
private readonly pilotPresses;
|
|
268
281
|
private readonly lookSpeed;
|
|
@@ -274,6 +287,20 @@ declare class NavigationInputSource {
|
|
|
274
287
|
dispose(): void;
|
|
275
288
|
}
|
|
276
289
|
//#endregion
|
|
290
|
+
//#region src/navigation/controls.d.ts
|
|
291
|
+
interface NavigationControlsOptions {
|
|
292
|
+
/** Button destination. The editor opens in a modal dialog. */
|
|
293
|
+
container: HTMLElement;
|
|
294
|
+
focusTarget: HTMLElement;
|
|
295
|
+
/** Opt into localStorage persistence; use the same key to share mappings between hosts. */
|
|
296
|
+
storageKey?: string;
|
|
297
|
+
}
|
|
298
|
+
interface NavigationControls {
|
|
299
|
+
dispose(): void;
|
|
300
|
+
}
|
|
301
|
+
/** Controller discovery and raw axis/button mapping for the built-in navigation profiles. */
|
|
302
|
+
declare function createNavigationControls(source: NavigationInputSource, options: NavigationControlsOptions): NavigationControls;
|
|
303
|
+
//#endregion
|
|
277
304
|
//#region src/navigation/orbit.d.ts
|
|
278
305
|
/** The orbit camera's framing. */
|
|
279
306
|
interface OrbitState {
|
|
@@ -514,11 +541,17 @@ interface WalkCollisionOptions {
|
|
|
514
541
|
/**
|
|
515
542
|
* A small collision neighborhood in metric coordinates, independent of floating-origin shifts.
|
|
516
543
|
* Only visible, resident geometry under `root` participates; evicted tiles and hidden layers
|
|
517
|
-
* disappear on the next scan,
|
|
518
|
-
*
|
|
544
|
+
* disappear on the next scan, including meshes with all render layers disabled unless marked
|
|
545
|
+
* `userData.walkCollisionOnly` (for example, a smooth staircase proxy). Instance
|
|
546
|
+
* transforms are expanded only inside the neighborhood. Large geometries (terrain tiles,
|
|
547
|
+
* building cells) are walked through a per-geometry
|
|
519
548
|
* spatial index, so a rebuild costs the triangles near the subject rather than the whole tile.
|
|
520
549
|
* Meshes opt out with `userData.walkIgnore`, and water materials (`userData.terrainWaterMaterial`)
|
|
521
|
-
*
|
|
550
|
+
* are never solid. Land cover is a solid walking surface: its visible elevation can differ from
|
|
551
|
+
* bare terrain, and full-tile land cover can replace the bare surface altogether.
|
|
552
|
+
* A group whose contents lie within an X/Z rectangle of its own frame declares it as
|
|
553
|
+
* `userData.walkFootprint` (`[minX, minZ, maxX, maxZ]`, like a terrain tile): a scan skips the
|
|
554
|
+
* whole group when that rectangle is out of reach.
|
|
522
555
|
*/
|
|
523
556
|
declare class WalkCollision {
|
|
524
557
|
readonly origin: THREE.Vector3;
|
|
@@ -556,6 +589,7 @@ declare class WalkCollision {
|
|
|
556
589
|
declare const WALK_EYE_HEIGHT: number;
|
|
557
590
|
declare const WALK_SPEED: number;
|
|
558
591
|
declare const RUN_SPEED: number;
|
|
592
|
+
declare const SWIM_SPEED: number;
|
|
559
593
|
/**
|
|
560
594
|
* How far from the requested spot `place` may land the body, including its radius: the ground a
|
|
561
595
|
* host should have loaded (terrain and anything built on it) before calling `place`.
|
|
@@ -572,22 +606,32 @@ interface WalkInput {
|
|
|
572
606
|
* First-person walking over streamed geometry: a 1.8 m capsule with gravity, jumping, wall
|
|
573
607
|
* sliding and a 50° walkable-slope limit, integrated at a fixed 120 Hz so results agree across
|
|
574
608
|
* frame rates. `feet` is the world position; put the camera `WALK_EYE_HEIGHT` above it. Missing
|
|
575
|
-
* terrain pauses movement (it is never a bottomless pit) until coverage arrives.
|
|
609
|
+
* terrain pauses movement (it is never a bottomless pit) until coverage arrives. Set
|
|
610
|
+
* `sampleWaterHeight` to float in deep water and automatically walk again in the shallows.
|
|
576
611
|
*/
|
|
577
612
|
declare class WalkController {
|
|
613
|
+
/** Four times walking/running/swimming speed; jump height and look response stay normal. */
|
|
614
|
+
boostMode: boolean;
|
|
578
615
|
readonly feet: THREE.Vector3;
|
|
579
616
|
readonly velocity: THREE.Vector3;
|
|
580
617
|
grounded: boolean;
|
|
618
|
+
swimming: boolean;
|
|
619
|
+
/** Water surface in world meters; null means dry, undefined means coverage is loading. */
|
|
620
|
+
sampleWaterHeight?: (x: number, z: number) => number | null | undefined;
|
|
581
621
|
ready: boolean;
|
|
582
622
|
waitingForTerrain: boolean;
|
|
583
623
|
private accumulator;
|
|
584
624
|
private jumpHeld;
|
|
585
625
|
private readonly capsule;
|
|
586
626
|
reset(x: number, z: number): void;
|
|
587
|
-
/**
|
|
588
|
-
|
|
627
|
+
/**
|
|
628
|
+
* Find supported open ground. A separate `groundCollision` can exclude vehicles from the
|
|
629
|
+
* landing ray while `collision` still rejects body overlaps, placing people beside cars.
|
|
630
|
+
* Deep water supports placement even when no solid lake bed is rendered.
|
|
631
|
+
*/
|
|
632
|
+
place(collision: WalkCollision, sampleHeight: (x: number, z: number) => number | undefined, groundCollision?: WalkCollision): boolean;
|
|
589
633
|
update(dt: number, input: WalkInput, collision: WalkCollision, sampleHeight: (x: number, z: number) => number | undefined): void;
|
|
590
634
|
private setCapsule;
|
|
591
635
|
}
|
|
592
636
|
//#endregion
|
|
593
|
-
export { type CameraOrientation, CollisionTree, FlyController, type FlyControllerOptions, FollowController, type FollowControllerOptions, type FollowSubject, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, type NavigationEnvironment, type NavigationGestures, type NavigationInput, NavigationInputSource, type NavigationInputSourceOptions, type NavigationKeyTarget, NavigationPointer, type NavigationPointerEvent, type NavigationPointerOptions, type NavigationPointerSurface, type NavigationPose, type NavigationProfileName, type NavigationVector, type NavigationWheelEvent, OrbitController, type OrbitControllerOptions, type OrbitFlyToOptions, type OrbitState, type PilotInput, RUN_SPEED, type TouchJoystick, type TouchJoystickOptions, TouchStick, type TouchStickOptions, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, type WalkCollisionOptions, WalkController, type WalkInput, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|
|
637
|
+
export { type CameraOrientation, CollisionTree, FlyController, type FlyControllerOptions, FollowController, type FollowControllerOptions, type FollowSubject, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, type NavigationControls, type NavigationControlsOptions, type NavigationEnvironment, type NavigationGestures, type NavigationInput, NavigationInputSource, type NavigationInputSourceOptions, type NavigationKeyTarget, NavigationPointer, type NavigationPointerEvent, type NavigationPointerOptions, type NavigationPointerSurface, type NavigationPose, type NavigationProfileName, type NavigationVector, type NavigationWheelEvent, OrbitController, type OrbitControllerOptions, type OrbitFlyToOptions, type OrbitState, type PilotInput, RUN_SPEED, SWIM_SPEED, type TouchJoystick, type TouchJoystickOptions, TouchStick, type TouchStickOptions, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, type WalkCollisionOptions, WalkController, type WalkInput, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createNavigationControls, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|