@bendyline/molen-client 0.0.10 → 0.0.11
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/dist/aircraft.d.mts +112 -3
- package/dist/aircraft.mjs +721 -6
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +23 -6
- package/dist/index.mjs +345 -29
- 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-C0abgthY.mjs +302 -0
- package/dist/navigation.d.mts +37 -6
- package/dist/navigation.mjs +518 -142
- package/dist/{renderer-CtEtmwJG.d.mts → renderer-Dzus24ZF.d.mts} +85 -8
- package/dist/vehicles.d.mts +3 -2
- package/dist/vehicles.mjs +62 -20
- package/package.json +3 -3
|
@@ -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,302 @@
|
|
|
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
|
+
subtree?.traverse((object) => {
|
|
153
|
+
if (!(object instanceof THREE.Mesh) || !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
|
+
if (!meshes.length || bounds.isEmpty()) warnings.push(`Slot ${name}: no matching surface`);
|
|
166
|
+
slots.set(name, {
|
|
167
|
+
meshes,
|
|
168
|
+
bounds,
|
|
169
|
+
binding
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const painted = /* @__PURE__ */ new Map();
|
|
173
|
+
const occupiedChannels = /* @__PURE__ */ new Set();
|
|
174
|
+
model.traverse((object) => {
|
|
175
|
+
if (!(object instanceof THREE.Mesh)) return;
|
|
176
|
+
for (const material of materialsOf(object)) for (const value of Object.values(material)) if (value instanceof THREE.Texture) occupiedChannels.add(value.channel);
|
|
177
|
+
});
|
|
178
|
+
const channel = [
|
|
179
|
+
3,
|
|
180
|
+
2,
|
|
181
|
+
1,
|
|
182
|
+
0
|
|
183
|
+
].find((candidate) => !occupiedChannels.has(candidate));
|
|
184
|
+
for (const [name, paint] of Object.entries(variant.paints)) {
|
|
185
|
+
const slot = slots.get(name);
|
|
186
|
+
if (!slot || slot.bounds.isEmpty()) {
|
|
187
|
+
warnings.push(`Paint ${name}: missing slot`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const clones = /* @__PURE__ */ new Map();
|
|
191
|
+
if (paint.camouflage && channel === void 0) warnings.push(`Paint ${name}: no unused UV channel for camouflage; using the base color`);
|
|
192
|
+
const texture = paint.camouflage && channel !== void 0 ? camouflageTexture(paint.camouflage, channel) : void 0;
|
|
193
|
+
if (texture) textures.add(texture);
|
|
194
|
+
for (const mesh of slot.meshes) {
|
|
195
|
+
remember(mesh);
|
|
196
|
+
const used = painted.get(mesh) ?? /* @__PURE__ */ new Set();
|
|
197
|
+
painted.set(mesh, used);
|
|
198
|
+
const next = materialsOf(mesh).map((source, index) => {
|
|
199
|
+
if (!slot.binding.materials.includes(source.name)) return source;
|
|
200
|
+
if (used.has(index)) {
|
|
201
|
+
warnings.push(`Paint ${name}: overlapping slot on ${mesh.name}`);
|
|
202
|
+
return source;
|
|
203
|
+
}
|
|
204
|
+
used.add(index);
|
|
205
|
+
let clone = clones.get(source);
|
|
206
|
+
if (!clone) {
|
|
207
|
+
clone = source.clone();
|
|
208
|
+
clones.set(source, clone);
|
|
209
|
+
materials.add(clone);
|
|
210
|
+
if ("color" in clone) clone.color.set(paint.color);
|
|
211
|
+
if ("roughness" in clone && paint.roughness !== void 0) clone.roughness = paint.roughness;
|
|
212
|
+
if ("metalness" in clone && paint.metalness !== void 0) clone.metalness = paint.metalness;
|
|
213
|
+
if ("map" in clone) clone.map = texture ?? null;
|
|
214
|
+
if (texture && "color" in clone) clone.color.set("#ffffff");
|
|
215
|
+
clone.needsUpdate = true;
|
|
216
|
+
}
|
|
217
|
+
return clone;
|
|
218
|
+
});
|
|
219
|
+
mesh.material = Array.isArray(mesh.material) ? next : next[0];
|
|
220
|
+
if (texture) {
|
|
221
|
+
mesh.geometry = projectPaint(mesh, slot.bounds, matrix(mesh), slot.binding.materials, texture.channel);
|
|
222
|
+
geometries.add(mesh.geometry);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const marking of variant.markings ?? []) {
|
|
227
|
+
const anchor = data.anchors?.[marking.anchor], slot = anchor && slots.get(anchor.slot);
|
|
228
|
+
if (!anchor || !slot || slot.bounds.isEmpty()) {
|
|
229
|
+
warnings.push(`Marking ${marking.anchor}: missing surface`);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const extent = slot.bounds.getSize(new THREE.Vector3());
|
|
233
|
+
const position = new THREE.Vector3(...anchor.position).multiply(extent).add(slot.bounds.min);
|
|
234
|
+
const size = new THREE.Vector3(...anchor.size).multiplyScalar(Math.max(extent.x, extent.y, extent.z));
|
|
235
|
+
const rotation = new THREE.Euler(...anchor.rotation);
|
|
236
|
+
const direction = new THREE.Vector3(0, 0, 1).applyEuler(rotation);
|
|
237
|
+
const texture = liveryGraphicTexture(marking.graphic);
|
|
238
|
+
textures.add(texture);
|
|
239
|
+
const material = new THREE.MeshStandardMaterial({
|
|
240
|
+
map: texture,
|
|
241
|
+
transparent: true,
|
|
242
|
+
depthWrite: false,
|
|
243
|
+
roughness: .65,
|
|
244
|
+
polygonOffset: true,
|
|
245
|
+
polygonOffsetFactor: -2,
|
|
246
|
+
polygonOffsetUnits: -2
|
|
247
|
+
});
|
|
248
|
+
materials.add(material);
|
|
249
|
+
let count = 0;
|
|
250
|
+
for (const mesh of slot.meshes) {
|
|
251
|
+
const surface = surfaceGeometry(mesh, new Set(slot.binding.materials));
|
|
252
|
+
const toRoot = matrix(mesh);
|
|
253
|
+
surface.applyMatrix4(toRoot);
|
|
254
|
+
const p = surface.getAttribute("position"), n = surface.getAttribute("normal"), indices = [];
|
|
255
|
+
const doubleSided = materialsOf(mesh).some((m) => slot.binding.materials.includes(m.name) && m.side === THREE.DoubleSide);
|
|
256
|
+
for (let i = 0; i < p.count; i += 3) {
|
|
257
|
+
const facing = new THREE.Vector3().fromBufferAttribute(n, i).dot(direction);
|
|
258
|
+
if (facing > .05) indices.push(i, i + 1, i + 2);
|
|
259
|
+
else if (doubleSided && facing < -.05) {
|
|
260
|
+
indices.push(i, i + 2, i + 1);
|
|
261
|
+
for (let j = i; j < i + 3; j++) n.setXYZ(j, -n.getX(j), -n.getY(j), -n.getZ(j));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
surface.setIndex(indices);
|
|
265
|
+
const geometry = new DecalGeometry(new THREE.Mesh(surface), position, rotation, size);
|
|
266
|
+
surface.dispose();
|
|
267
|
+
if (!geometry.getAttribute("position").count) {
|
|
268
|
+
geometry.dispose();
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
geometry.applyMatrix4(toRoot.invert());
|
|
272
|
+
geometries.add(geometry);
|
|
273
|
+
const decal = new THREE.Mesh(geometry, material);
|
|
274
|
+
decal.name = `livery:${marking.anchor}`;
|
|
275
|
+
decal.userData.liveryMarking = true;
|
|
276
|
+
decal.receiveShadow = true;
|
|
277
|
+
decal.renderOrder = 1;
|
|
278
|
+
mesh.add(decal);
|
|
279
|
+
decals.push(decal);
|
|
280
|
+
count++;
|
|
281
|
+
}
|
|
282
|
+
if (!count) warnings.push(`Marking ${marking.anchor}: projector misses its surface`);
|
|
283
|
+
}
|
|
284
|
+
let disposed = false;
|
|
285
|
+
return {
|
|
286
|
+
warnings,
|
|
287
|
+
dispose() {
|
|
288
|
+
if (disposed) return;
|
|
289
|
+
disposed = true;
|
|
290
|
+
for (const decal of decals) decal.removeFromParent();
|
|
291
|
+
for (const [mesh, original] of originals) {
|
|
292
|
+
mesh.material = original.material;
|
|
293
|
+
mesh.geometry = original.geometry;
|
|
294
|
+
}
|
|
295
|
+
for (const geometry of geometries) geometry.dispose();
|
|
296
|
+
for (const material of materials) material.dispose();
|
|
297
|
+
for (const texture of textures) texture.dispose();
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
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";
|
|
@@ -183,12 +185,15 @@ type NavigationProfileName = "orbit" | "fly" | "walk" | "drive" | "pilot";
|
|
|
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
186
|
* bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, 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). */
|
|
@@ -224,6 +229,8 @@ interface NavigationInput {
|
|
|
224
229
|
interact: number;
|
|
225
230
|
/** Presses of the view toggle since the previous frame (edge-triggered). */
|
|
226
231
|
view: number;
|
|
232
|
+
/** Presses of the 4× travel boost toggle (T), edge-triggered. */
|
|
233
|
+
boost?: number;
|
|
227
234
|
/** Clicks/taps in element-relative CSS pixels. */
|
|
228
235
|
taps: Array<{
|
|
229
236
|
x: number;
|
|
@@ -263,6 +270,7 @@ declare class NavigationInputSource {
|
|
|
263
270
|
readonly pointer: NavigationPointer;
|
|
264
271
|
private interactPresses;
|
|
265
272
|
private viewPresses;
|
|
273
|
+
private boostPresses;
|
|
266
274
|
private profile;
|
|
267
275
|
private readonly pilotPresses;
|
|
268
276
|
private readonly lookSpeed;
|
|
@@ -274,6 +282,20 @@ declare class NavigationInputSource {
|
|
|
274
282
|
dispose(): void;
|
|
275
283
|
}
|
|
276
284
|
//#endregion
|
|
285
|
+
//#region src/navigation/controls.d.ts
|
|
286
|
+
interface NavigationControlsOptions {
|
|
287
|
+
/** Button destination. The editor opens in a modal dialog. */
|
|
288
|
+
container: HTMLElement;
|
|
289
|
+
focusTarget: HTMLElement;
|
|
290
|
+
/** Opt into localStorage persistence; use the same key to share mappings between hosts. */
|
|
291
|
+
storageKey?: string;
|
|
292
|
+
}
|
|
293
|
+
interface NavigationControls {
|
|
294
|
+
dispose(): void;
|
|
295
|
+
}
|
|
296
|
+
/** Controller discovery and raw axis/button mapping for the built-in navigation profiles. */
|
|
297
|
+
declare function createNavigationControls(source: NavigationInputSource, options: NavigationControlsOptions): NavigationControls;
|
|
298
|
+
//#endregion
|
|
277
299
|
//#region src/navigation/orbit.d.ts
|
|
278
300
|
/** The orbit camera's framing. */
|
|
279
301
|
interface OrbitState {
|
|
@@ -518,7 +540,11 @@ interface WalkCollisionOptions {
|
|
|
518
540
|
* neighborhood. Large geometries (terrain tiles, building cells) are walked through a per-geometry
|
|
519
541
|
* spatial index, so a rebuild costs the triangles near the subject rather than the whole tile.
|
|
520
542
|
* Meshes opt out with `userData.walkIgnore`, and water materials (`userData.terrainWaterMaterial`)
|
|
521
|
-
*
|
|
543
|
+
* are never solid. Land cover is a solid walking surface: its visible elevation can differ from
|
|
544
|
+
* bare terrain, and full-tile land cover can replace the bare surface altogether.
|
|
545
|
+
* A group whose contents lie within an X/Z rectangle of its own frame declares it as
|
|
546
|
+
* `userData.walkFootprint` (`[minX, minZ, maxX, maxZ]`, like a terrain tile): a scan skips the
|
|
547
|
+
* whole group when that rectangle is out of reach.
|
|
522
548
|
*/
|
|
523
549
|
declare class WalkCollision {
|
|
524
550
|
readonly origin: THREE.Vector3;
|
|
@@ -575,6 +601,8 @@ interface WalkInput {
|
|
|
575
601
|
* terrain pauses movement (it is never a bottomless pit) until coverage arrives.
|
|
576
602
|
*/
|
|
577
603
|
declare class WalkController {
|
|
604
|
+
/** Four times walking/running speed; jump height and look response stay normal. */
|
|
605
|
+
boostMode: boolean;
|
|
578
606
|
readonly feet: THREE.Vector3;
|
|
579
607
|
readonly velocity: THREE.Vector3;
|
|
580
608
|
grounded: boolean;
|
|
@@ -584,10 +612,13 @@ declare class WalkController {
|
|
|
584
612
|
private jumpHeld;
|
|
585
613
|
private readonly capsule;
|
|
586
614
|
reset(x: number, z: number): void;
|
|
587
|
-
/**
|
|
588
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Find supported open ground. A separate `groundCollision` can exclude vehicles from the
|
|
617
|
+
* landing ray while `collision` still rejects body overlaps, placing people beside cars.
|
|
618
|
+
*/
|
|
619
|
+
place(collision: WalkCollision, sampleHeight: (x: number, z: number) => number | undefined, groundCollision?: WalkCollision): boolean;
|
|
589
620
|
update(dt: number, input: WalkInput, collision: WalkCollision, sampleHeight: (x: number, z: number) => number | undefined): void;
|
|
590
621
|
private setCapsule;
|
|
591
622
|
}
|
|
592
623
|
//#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 };
|
|
624
|
+
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, 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 };
|