@bendyline/molen-client 0.0.11 → 0.0.13
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 +9 -31
- package/dist/aircraft.mjs +279 -219
- 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 +250 -0
- package/dist/index.d.mts +14 -3
- package/dist/index.mjs +577 -147
- package/dist/{livery-C0abgthY.mjs → livery-qcDLzbU9.mjs} +7 -2
- package/dist/navigation.d.mts +19 -6
- package/dist/navigation.mjs +133 -83
- package/dist/{renderer-Dzus24ZF.d.mts → renderer-DAk7C8jH.d.mts} +234 -17
- package/dist/vehicle-interior-B8TpzTAx.d.mts +56 -0
- package/dist/vehicle-interior-DJ4cXTsQ.mjs +468 -0
- package/dist/vehicles.d.mts +25 -20
- package/dist/vehicles.mjs +271 -66
- 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
package/dist/vehicles.mjs
CHANGED
|
@@ -1,8 +1,263 @@
|
|
|
1
1
|
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
2
|
+
import { createGlassVisual } from "./glass.mjs";
|
|
3
|
+
import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
|
|
4
|
+
import { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.mjs";
|
|
4
5
|
import * as THREE from "three";
|
|
5
|
-
|
|
6
|
+
//#region src/vehicle-proxy.ts
|
|
7
|
+
const templates = /* @__PURE__ */ new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Shared street-distance silhouette for parked cars and instanced traffic. Painted faces come
|
|
10
|
+
* first so a static batch can tint the body and roof without tinting the glass, tyres or lamps.
|
|
11
|
+
* 148 triangles, one material, no textures or model downloads. Never dispose the cached result.
|
|
12
|
+
*/
|
|
13
|
+
function vehicleProxyGeometry(spec) {
|
|
14
|
+
const { width: w, length: l, height: h, wheelbase, wheelTrack, wheelRadius: r } = spec;
|
|
15
|
+
const key = `${w}:${l}:${h}:${wheelbase}:${wheelTrack}:${r}`;
|
|
16
|
+
const cached = templates.get(key);
|
|
17
|
+
if (cached) return cached;
|
|
18
|
+
const positions = [];
|
|
19
|
+
const colors = [];
|
|
20
|
+
const paint = new THREE.Color("#ffffff");
|
|
21
|
+
const glass = new THREE.Color("#4d6178");
|
|
22
|
+
const tyre = new THREE.Color("#20242a");
|
|
23
|
+
const wheelFace = new THREE.Color("#424950");
|
|
24
|
+
const headlamp = new THREE.Color("#eee9d4");
|
|
25
|
+
const tailLamp = new THREE.Color("#b82323");
|
|
26
|
+
const triangle = (a, b, c, color) => {
|
|
27
|
+
positions.push(...a, ...b, ...c);
|
|
28
|
+
for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
|
|
29
|
+
};
|
|
30
|
+
const quad = (a, b, c, d, color = paint) => {
|
|
31
|
+
triangle(a, b, d, color);
|
|
32
|
+
triangle(b, c, d, color);
|
|
33
|
+
};
|
|
34
|
+
const bottom = r * 1.2;
|
|
35
|
+
const belt = h * .57;
|
|
36
|
+
const tall = h / w > .9;
|
|
37
|
+
const hatch = tall || l / w < 2.4;
|
|
38
|
+
const rearBase = l * (hatch ? -.44 : -.32);
|
|
39
|
+
const rearRoof = l * (hatch ? -.34 : -.18);
|
|
40
|
+
const frontBase = l * .27;
|
|
41
|
+
const frontRoof = l * (tall ? .15 : .1);
|
|
42
|
+
const rings = [
|
|
43
|
+
[
|
|
44
|
+
-.5,
|
|
45
|
+
.44,
|
|
46
|
+
h * .48
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
rearBase / l,
|
|
50
|
+
.48,
|
|
51
|
+
belt
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
frontBase / l,
|
|
55
|
+
.48,
|
|
56
|
+
belt
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
.5,
|
|
60
|
+
.44,
|
|
61
|
+
h * .46
|
|
62
|
+
]
|
|
63
|
+
].map(([z = 0, x = 0, y = 0]) => [
|
|
64
|
+
[
|
|
65
|
+
-w * x,
|
|
66
|
+
bottom,
|
|
67
|
+
l * z
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
w * x,
|
|
71
|
+
bottom,
|
|
72
|
+
l * z
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
w * x,
|
|
76
|
+
y,
|
|
77
|
+
l * z
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
-w * x,
|
|
81
|
+
y,
|
|
82
|
+
l * z
|
|
83
|
+
]
|
|
84
|
+
]);
|
|
85
|
+
for (let i = 1; i < rings.length; i++) {
|
|
86
|
+
const a = rings[i - 1];
|
|
87
|
+
const b = rings[i];
|
|
88
|
+
for (let j = 0; j < 4; j++) quad(a[j], a[(j + 1) % 4], b[(j + 1) % 4], b[j]);
|
|
89
|
+
}
|
|
90
|
+
const rear = rings[0];
|
|
91
|
+
const front = rings[3];
|
|
92
|
+
quad(rear[3], rear[2], rear[1], rear[0]);
|
|
93
|
+
quad(front[0], front[1], front[2], front[3]);
|
|
94
|
+
const lower = w * .44;
|
|
95
|
+
const upper = w * .36;
|
|
96
|
+
const back = [
|
|
97
|
+
[
|
|
98
|
+
-lower,
|
|
99
|
+
belt,
|
|
100
|
+
rearBase
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
lower,
|
|
104
|
+
belt,
|
|
105
|
+
rearBase
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
upper,
|
|
109
|
+
h,
|
|
110
|
+
rearRoof
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
-upper,
|
|
114
|
+
h,
|
|
115
|
+
rearRoof
|
|
116
|
+
]
|
|
117
|
+
];
|
|
118
|
+
const nose = [
|
|
119
|
+
[
|
|
120
|
+
-lower,
|
|
121
|
+
belt,
|
|
122
|
+
frontBase
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
lower,
|
|
126
|
+
belt,
|
|
127
|
+
frontBase
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
upper,
|
|
131
|
+
h,
|
|
132
|
+
frontRoof
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
-upper,
|
|
136
|
+
h,
|
|
137
|
+
frontRoof
|
|
138
|
+
]
|
|
139
|
+
];
|
|
140
|
+
const cabinFaces = [
|
|
141
|
+
[
|
|
142
|
+
back[0],
|
|
143
|
+
nose[0],
|
|
144
|
+
nose[3],
|
|
145
|
+
back[3]
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
nose[1],
|
|
149
|
+
back[1],
|
|
150
|
+
back[2],
|
|
151
|
+
nose[2]
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
back[1],
|
|
155
|
+
back[0],
|
|
156
|
+
back[3],
|
|
157
|
+
back[2]
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
nose[0],
|
|
161
|
+
nose[1],
|
|
162
|
+
nose[2],
|
|
163
|
+
nose[3]
|
|
164
|
+
]
|
|
165
|
+
];
|
|
166
|
+
for (const face of cabinFaces) quad(...face);
|
|
167
|
+
quad(back[3], nose[3], nose[2], back[2]);
|
|
168
|
+
const bodyVertices = positions.length / 3;
|
|
169
|
+
for (let side = 0; side < cabinFaces.length; side++) {
|
|
170
|
+
const [a, b, c, d] = cabinFaces[side];
|
|
171
|
+
const normal = new THREE.Vector3().subVectors(new THREE.Vector3(...b), new THREE.Vector3(...a)).cross(new THREE.Vector3().subVectors(new THREE.Vector3(...d), new THREE.Vector3(...a))).normalize().multiplyScalar(.003);
|
|
172
|
+
const point = (u, v) => new THREE.Vector3(...a).lerp(new THREE.Vector3(...b), u).lerp(new THREE.Vector3(...d).lerp(new THREE.Vector3(...c), u), v).add(normal).toArray();
|
|
173
|
+
for (const [start = 0, end = 1] of side < 2 ? [[.06, .47], [.53, .94]] : [[.07, .93]]) quad(point(start, .12), point(end, .12), point(end, .9), point(start, .9), glass);
|
|
174
|
+
}
|
|
175
|
+
const halfTyre = Math.max(w * .05, (w - wheelTrack) / 2);
|
|
176
|
+
for (const sign of [-1, 1]) {
|
|
177
|
+
const inner = sign * (wheelTrack / 2 - halfTyre);
|
|
178
|
+
const outer = sign * (wheelTrack / 2 + halfTyre);
|
|
179
|
+
for (const z of [-wheelbase / 2, wheelbase / 2]) {
|
|
180
|
+
const rim = [];
|
|
181
|
+
const inside = [];
|
|
182
|
+
for (let i = 0; i < 8; i++) {
|
|
183
|
+
const angle = sign * i * Math.PI / 4;
|
|
184
|
+
const y = r + Math.cos(angle) * r;
|
|
185
|
+
const depth = z + Math.sin(angle) * r;
|
|
186
|
+
rim.push([
|
|
187
|
+
outer,
|
|
188
|
+
y,
|
|
189
|
+
depth
|
|
190
|
+
]);
|
|
191
|
+
inside.push([
|
|
192
|
+
inner,
|
|
193
|
+
y,
|
|
194
|
+
depth
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
for (let i = 0; i < 8; i++) {
|
|
198
|
+
const j = (i + 1) % 8;
|
|
199
|
+
quad(inside[i], inside[j], rim[j], rim[i], tyre);
|
|
200
|
+
}
|
|
201
|
+
for (let i = 1; i < 7; i++) triangle(rim[0], rim[i], rim[i + 1], wheelFace);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const end of [-1, 1]) {
|
|
205
|
+
const z = end * (l / 2 + .003);
|
|
206
|
+
const y = h * (end > 0 ? .46 : .48);
|
|
207
|
+
for (const side of [-1, 1]) {
|
|
208
|
+
const x = side * w * .31;
|
|
209
|
+
const a = [
|
|
210
|
+
x - w * .095,
|
|
211
|
+
y - h * .1,
|
|
212
|
+
z
|
|
213
|
+
];
|
|
214
|
+
const b = [
|
|
215
|
+
x + w * .095,
|
|
216
|
+
y - h * .1,
|
|
217
|
+
z
|
|
218
|
+
];
|
|
219
|
+
const c = [
|
|
220
|
+
b[0],
|
|
221
|
+
y - h * .025,
|
|
222
|
+
z
|
|
223
|
+
];
|
|
224
|
+
const d = [
|
|
225
|
+
a[0],
|
|
226
|
+
c[1],
|
|
227
|
+
z
|
|
228
|
+
];
|
|
229
|
+
if (end > 0) quad(a, b, c, d, headlamp);
|
|
230
|
+
else quad(d, c, b, a, tailLamp);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
quad([
|
|
234
|
+
-w * .18,
|
|
235
|
+
bottom,
|
|
236
|
+
l / 2 + .004
|
|
237
|
+
], [
|
|
238
|
+
w * .18,
|
|
239
|
+
bottom,
|
|
240
|
+
l / 2 + .004
|
|
241
|
+
], [
|
|
242
|
+
w * .18,
|
|
243
|
+
h * .36,
|
|
244
|
+
l / 2 + .004
|
|
245
|
+
], [
|
|
246
|
+
-w * .18,
|
|
247
|
+
h * .36,
|
|
248
|
+
l / 2 + .004
|
|
249
|
+
], tyre);
|
|
250
|
+
const geometry = new THREE.BufferGeometry();
|
|
251
|
+
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
|
252
|
+
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
|
|
253
|
+
geometry.computeVertexNormals();
|
|
254
|
+
geometry.computeBoundingBox();
|
|
255
|
+
geometry.computeBoundingSphere();
|
|
256
|
+
geometry.userData.bodyVertices = bodyVertices;
|
|
257
|
+
templates.set(key, geometry);
|
|
258
|
+
return geometry;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
6
261
|
//#region src/vehicle-camera.ts
|
|
7
262
|
/** Seat-space cockpit and collision-shortened chase views for any vehicle host. */
|
|
8
263
|
function vehicleCameraPose(transform, spec, options) {
|
|
@@ -43,7 +298,7 @@ const travel = new THREE.Vector3();
|
|
|
43
298
|
* each moves along the body's up axis to keep its centre at its resting height, so the outside
|
|
44
299
|
* wheels stay on the road in a turn rather than sinking into it.
|
|
45
300
|
*/
|
|
46
|
-
function createVehicleVisual(model, vehicle, livery) {
|
|
301
|
+
function createVehicleVisual(model, vehicle, livery, glassData) {
|
|
47
302
|
const interior = vehicle.visual.interior === void 0 ? void 0 : createVehicleInteriorVisual(model, vehicle.visual.interior);
|
|
48
303
|
const animation = vehicle.visual.animation === void 0 ? void 0 : createModelSignalVisual(model, vehicle.visual.animation);
|
|
49
304
|
const nodes = /* @__PURE__ */ new Map();
|
|
@@ -65,6 +320,7 @@ function createVehicleVisual(model, vehicle, livery) {
|
|
|
65
320
|
return material;
|
|
66
321
|
});
|
|
67
322
|
object.material = Array.isArray(object.material) ? cloned : cloned[0];
|
|
323
|
+
drawGlassInOnePass(object);
|
|
68
324
|
}
|
|
69
325
|
});
|
|
70
326
|
model.updateMatrixWorld(true);
|
|
@@ -82,15 +338,19 @@ function createVehicleVisual(model, vehicle, livery) {
|
|
|
82
338
|
}
|
|
83
339
|
if (vehicle.visual.steeringWheelNode !== void 0) steeringWheel = nodes.get(vehicle.visual.steeringWheelNode)?.[0];
|
|
84
340
|
let appearance = livery === void 0 ? void 0 : applyLivery(model, livery);
|
|
341
|
+
const glass = glassData === void 0 ? void 0 : createGlassVisual(model, glassData);
|
|
342
|
+
const damage = createAircraftDamageVisual(model, { collisionParts: vehicle.spec?.collisionParts });
|
|
85
343
|
return {
|
|
86
344
|
setLivery(data) {
|
|
87
345
|
appearance?.dispose();
|
|
346
|
+
damage.reset();
|
|
88
347
|
appearance = data === void 0 ? void 0 : applyLivery(model, data);
|
|
89
348
|
},
|
|
90
349
|
object: model,
|
|
91
350
|
interior,
|
|
92
351
|
animation,
|
|
93
|
-
|
|
352
|
+
glass,
|
|
353
|
+
update(steer, angle, signals, timeSeconds, glassState, damageState) {
|
|
94
354
|
const roll = signals?.bodyRoll ?? 0;
|
|
95
355
|
const pitch = signals?.bodyPitch ?? 0;
|
|
96
356
|
const lean = Number.isFinite(roll) && Number.isFinite(pitch) && (roll !== 0 || pitch !== 0);
|
|
@@ -113,8 +373,12 @@ function createVehicleVisual(model, vehicle, livery) {
|
|
|
113
373
|
};
|
|
114
374
|
interior?.update(telemetry, timeSeconds);
|
|
115
375
|
animation?.update(telemetry, timeSeconds);
|
|
376
|
+
glass?.update(glassState, timeSeconds ?? 0);
|
|
377
|
+
damage.update(damageState ?? {});
|
|
116
378
|
},
|
|
117
379
|
dispose() {
|
|
380
|
+
damage.reset();
|
|
381
|
+
glass?.dispose();
|
|
118
382
|
appearance?.dispose();
|
|
119
383
|
const geometries = /* @__PURE__ */ new Set();
|
|
120
384
|
const materials = /* @__PURE__ */ new Set();
|
|
@@ -134,69 +398,10 @@ const parkedMaterial = new THREE.MeshStandardMaterial({
|
|
|
134
398
|
roughness: .55,
|
|
135
399
|
metalness: .12
|
|
136
400
|
});
|
|
137
|
-
const parkedTemplates = /* @__PURE__ */ new Map();
|
|
138
401
|
const paints = /* @__PURE__ */ new Map();
|
|
139
|
-
function coloredBox(x, y, z, width, height, length, color) {
|
|
140
|
-
const geometry = new THREE.BoxGeometry(width, height, length).translate(x, y, z).toNonIndexed();
|
|
141
|
-
geometry.deleteAttribute("uv");
|
|
142
|
-
const tint = new THREE.Color(color);
|
|
143
|
-
const colors = new Float32Array(geometry.getAttribute("position").count * 3);
|
|
144
|
-
for (let i = 0; i < colors.length; i += 3) {
|
|
145
|
-
colors[i] = tint.r;
|
|
146
|
-
colors[i + 1] = tint.g;
|
|
147
|
-
colors[i + 2] = tint.b;
|
|
148
|
-
}
|
|
149
|
-
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
|
150
|
-
return geometry;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The parked-car proxy shape with a white body, for instanced rendering: per-instance paint comes
|
|
154
|
-
* from `instanceColor` (three multiplies vertex colours by it, so glass and tyres stay dark).
|
|
155
|
-
* Cached by dimensions; never dispose the returned geometry.
|
|
156
|
-
*/
|
|
157
|
-
function vehicleProxyGeometry(dimensions) {
|
|
158
|
-
return parkedTemplate(dimensions);
|
|
159
|
-
}
|
|
160
402
|
/** The shared vertex-coloured material of parked and proxy vehicles. */
|
|
161
403
|
const vehicleProxyMaterial = parkedMaterial;
|
|
162
404
|
/**
|
|
163
|
-
* Generic dimension-driven proxy used only for large dormant parking batches, its body white:
|
|
164
|
-
* the body is its first `userData.bodyVertices` vertices, painted as a batch bakes it. A template
|
|
165
|
-
* per paint as well was dozens built for a tile's first cars, 7 ms of one frame.
|
|
166
|
-
*/
|
|
167
|
-
function parkedTemplate(spec) {
|
|
168
|
-
const key = `${spec.width}:${spec.length}:${spec.height}:${spec.wheelbase}`;
|
|
169
|
-
const cached = parkedTemplates.get(key);
|
|
170
|
-
if (cached !== void 0) return cached;
|
|
171
|
-
const body = coloredBox(0, spec.height * .34, 0, spec.width, spec.height * .48, spec.length, "#ffffff");
|
|
172
|
-
const bodyVertices = body.getAttribute("position").count;
|
|
173
|
-
const parts = [body, coloredBox(0, spec.height * .72, -spec.length * .06, spec.width * .82, spec.height * .42, spec.length * .52, "#526b78")];
|
|
174
|
-
for (const x of [-spec.wheelTrack / 2, spec.wheelTrack / 2]) for (const z of [-spec.wheelbase / 2, spec.wheelbase / 2]) {
|
|
175
|
-
const wheel = new THREE.CylinderGeometry(spec.wheelRadius, spec.wheelRadius, spec.width * .1, 8);
|
|
176
|
-
wheel.rotateZ(Math.PI / 2);
|
|
177
|
-
wheel.translate(x, spec.wheelRadius, z);
|
|
178
|
-
const wheelGeometry = wheel.toNonIndexed();
|
|
179
|
-
wheelGeometry.deleteAttribute("uv");
|
|
180
|
-
const charcoal = new THREE.Color("#20242a");
|
|
181
|
-
const colors = new Float32Array(wheelGeometry.getAttribute("position").count * 3);
|
|
182
|
-
for (let i = 0; i < colors.length; i += 3) {
|
|
183
|
-
colors[i] = charcoal.r;
|
|
184
|
-
colors[i + 1] = charcoal.g;
|
|
185
|
-
colors[i + 2] = charcoal.b;
|
|
186
|
-
}
|
|
187
|
-
wheelGeometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
|
188
|
-
parts.push(wheelGeometry);
|
|
189
|
-
wheel.dispose();
|
|
190
|
-
}
|
|
191
|
-
const geometry = mergeGeometries(parts);
|
|
192
|
-
for (const part of parts) part.dispose();
|
|
193
|
-
geometry.computeBoundingBox();
|
|
194
|
-
geometry.computeBoundingSphere();
|
|
195
|
-
geometry.userData.bodyVertices = bodyVertices;
|
|
196
|
-
parkedTemplates.set(key, geometry);
|
|
197
|
-
return geometry;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
405
|
* Dormant terrain-owned cars merged into one static mesh per tile. A plain mesh shares its
|
|
201
406
|
* compiled shader with every other tile; an instanced batch per model and paint would build one
|
|
202
407
|
* of its own. `userData.vehicleIds[i]` owns vertex range `userData.vehicleRanges[2i..2i+1]`;
|
|
@@ -206,7 +411,7 @@ function createParkedVehicleBatch(placements, origin = [0, 0]) {
|
|
|
206
411
|
const group = new THREE.Group();
|
|
207
412
|
group.name = "surface:parked-cars";
|
|
208
413
|
if (placements.length === 0) return group;
|
|
209
|
-
const templates = placements.map((placement) =>
|
|
414
|
+
const templates = placements.map((placement) => vehicleProxyGeometry(placement.spec));
|
|
210
415
|
const vertices = templates.reduce((sum, template) => sum + template.getAttribute("position").count, 0);
|
|
211
416
|
const positions = new Float32Array(vertices * 3);
|
|
212
417
|
const normals = new Float32Array(vertices * 3);
|
|
@@ -314,4 +519,4 @@ function setParkedVehicleHidden(batch, index, hidden) {
|
|
|
314
519
|
return true;
|
|
315
520
|
}
|
|
316
521
|
//#endregion
|
|
317
|
-
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, vehicleProxyGeometry, vehicleProxyMaterial };
|
|
522
|
+
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, aircraftObstacleContacts as vehicleObstacleContacts, vehicleProxyGeometry, vehicleProxyMaterial };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import "./clouds-DmASLVoe.mjs";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import { Break, Discard, Fn, If, Loop, abs, attribute, cameraPosition, clamp, dot, exp, exp2, float, floor, fract, lightPosition, lightTargetPosition, log2, max, min, mix, normalize, positionWorld, pow, renderGroup, screenCoordinate, select, smoothstep, texture, texture3D, uniform, vec2, vec3, vec4 } from "three/tsl";
|
|
4
|
+
import { DirectionalLightNode, MeshBasicNodeMaterial } from "three/webgpu";
|
|
5
|
+
//#region src/three/webgpu-clouds.ts
|
|
6
|
+
/** WebGPU deck material reading `u` and `t` by reference. */
|
|
7
|
+
function createWebGpuCloudMaterial(u, t) {
|
|
8
|
+
const slab = uniform(u.slab);
|
|
9
|
+
const field = uniform(u.field);
|
|
10
|
+
const weights = uniform(u.mix);
|
|
11
|
+
const form = uniform(u.form);
|
|
12
|
+
const erode = uniform(u.erode);
|
|
13
|
+
const relief = uniform(u.relief);
|
|
14
|
+
const shapeUv = uniform(u.shape);
|
|
15
|
+
const detailUv = uniform(u.detail);
|
|
16
|
+
const march = uniform(u.march);
|
|
17
|
+
const sun = uniform(u.sun);
|
|
18
|
+
const sunColor = uniform(u.sunColor);
|
|
19
|
+
const ambientTop = uniform(u.ambientTop);
|
|
20
|
+
const ambientBottom = uniform(u.ambientBottom);
|
|
21
|
+
const phase = uniform(u.phase);
|
|
22
|
+
const fog = uniform(u.fog);
|
|
23
|
+
const fogColor = uniform(u.fogColor);
|
|
24
|
+
const density = (detailed) => Fn(([p, lod]) => {
|
|
25
|
+
const d = float(0).toVar();
|
|
26
|
+
const h = p.y.sub(slab.x).mul(slab.z).toVar();
|
|
27
|
+
If(h.greaterThan(0).and(h.lessThan(1)), () => {
|
|
28
|
+
const uv = p.xz.mul(field.x).add(field.yz).toVar();
|
|
29
|
+
const w = texture(t.weather, uv, lod).toVar();
|
|
30
|
+
const strength = dot(w, weights).toVar();
|
|
31
|
+
const soft = erode.z.mul(lod.mul(.6).add(1));
|
|
32
|
+
const threshold = field.w.mul(soft.add(1)).oneMinus();
|
|
33
|
+
const hn = h.div(mix(form.x, 1, w.g).mul(relief.x.mul(strength.oneMinus()).oneMinus())).toVar();
|
|
34
|
+
If(hn.lessThan(1), () => {
|
|
35
|
+
const spread = form.w.mul(smoothstep(.55, .9, hn)).toVar();
|
|
36
|
+
If(spread.greaterThan(0), () => {
|
|
37
|
+
const wide = dot(texture(t.weather, uv, lod.add(relief.z)), weights).add(relief.w);
|
|
38
|
+
strength.assign(mix(strength, max(strength, wide), spread));
|
|
39
|
+
});
|
|
40
|
+
const cover = clamp(strength.sub(threshold).sub(relief.y.mul(hn).mul(spread.oneMinus())).div(soft), 0, 1);
|
|
41
|
+
const profile = smoothstep(0, form.y, hn).mul(smoothstep(form.z, 1, hn).oneMinus());
|
|
42
|
+
const body = cover.mul(mix(profile, 1, spread.mul(.5))).toVar();
|
|
43
|
+
If(body.greaterThan(0), () => {
|
|
44
|
+
const carve = erode.x.mul(mix(.3, 1, smoothstep(0, .3, hn))).mul(smoothstep(2, 4.5, lod).oneMinus()).toVar();
|
|
45
|
+
const s = float(1).toVar();
|
|
46
|
+
If(carve.greaterThan(0), () => {
|
|
47
|
+
s.assign(mix(1, texture3D(t.shape, p.mul(shapeUv.x).add(shapeUv.yzw), 0).r, carve));
|
|
48
|
+
});
|
|
49
|
+
d.assign(clamp(s.sub(1).add(body).div(max(body, .001)), 0, 1).mul(body));
|
|
50
|
+
if (detailed) If(erode.y.greaterThan(0).and(d.greaterThan(0)).and(lod.lessThan(2)), () => {
|
|
51
|
+
const n = texture3D(t.detail, p.mul(detailUv.x).add(detailUv.yzw), 0).r.toVar();
|
|
52
|
+
const wear = mix(n, n.oneMinus(), clamp(hn.mul(3), 0, 1)).mul(erode.y).toVar();
|
|
53
|
+
d.assign(clamp(d.sub(wear).div(wear.oneMinus()), 0, 1));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return d;
|
|
59
|
+
});
|
|
60
|
+
const full = density(true);
|
|
61
|
+
const cheap = density(false);
|
|
62
|
+
const lightDepth = Fn(([p, lod]) => {
|
|
63
|
+
const edge = select(sun.y.greaterThan(0), slab.y, slab.x);
|
|
64
|
+
const len = select(abs(sun.y).greaterThan(1e-4), min(sun.w, edge.sub(p.y).div(sun.y)), sun.w).div(exp2(march.y).sub(1)).toVar();
|
|
65
|
+
const depth = float(0).toVar();
|
|
66
|
+
const along = float(0).toVar();
|
|
67
|
+
Loop(6, ({ i }) => {
|
|
68
|
+
If(float(i).greaterThanEqual(march.y), () => {
|
|
69
|
+
Break();
|
|
70
|
+
});
|
|
71
|
+
const q = p.add(sun.xyz.mul(along.add(len.mul(.5))));
|
|
72
|
+
depth.addAssign(cheap(q, lod).mul(len));
|
|
73
|
+
along.addAssign(len);
|
|
74
|
+
len.mulAssign(2);
|
|
75
|
+
});
|
|
76
|
+
return depth.mul(march.w);
|
|
77
|
+
});
|
|
78
|
+
const hg = (c, g) => {
|
|
79
|
+
const g2 = g.mul(g);
|
|
80
|
+
return g2.oneMinus().div(pow(max(g2.add(1).sub(g.mul(c).mul(2)), 1e-4), 1.5));
|
|
81
|
+
};
|
|
82
|
+
const cloud = Fn(() => {
|
|
83
|
+
const ro = cameraPosition;
|
|
84
|
+
const toProxy = positionWorld.sub(ro).toVar();
|
|
85
|
+
const t0 = toProxy.length().toVar();
|
|
86
|
+
const rd = toProxy.div(t0).toVar();
|
|
87
|
+
const range = attribute("cloudRange", "vec2");
|
|
88
|
+
const enter = float(0).toVar();
|
|
89
|
+
const leave = float(1e9).toVar();
|
|
90
|
+
If(abs(rd.y).greaterThan(1e-5), () => {
|
|
91
|
+
const tb = slab.x.sub(ro.y).div(rd.y);
|
|
92
|
+
const tt = slab.y.sub(ro.y).div(rd.y);
|
|
93
|
+
enter.assign(max(min(tb, tt), 0));
|
|
94
|
+
leave.assign(max(tb, tt));
|
|
95
|
+
}).ElseIf(ro.y.lessThanEqual(slab.x).or(ro.y.greaterThanEqual(slab.y)), () => {
|
|
96
|
+
leave.assign(-1);
|
|
97
|
+
});
|
|
98
|
+
const a = max(t0, enter).toVar();
|
|
99
|
+
const b = min(min(leave, range.x), min(slab.w, a.add(march.z))).toVar();
|
|
100
|
+
const steps = max(2, floor(march.x.mul(range.y).add(.5))).toVar();
|
|
101
|
+
const c = dot(rd, sun.xyz);
|
|
102
|
+
const lobes = mix(hg(c, phase.x), hg(c, phase.y), phase.z).toVar();
|
|
103
|
+
const jitter = fract(fract(dot(screenCoordinate.xy, vec2(.06711056, .00583715))).mul(52.9829189)).toVar();
|
|
104
|
+
const span = mix(6, 1.5, smoothstep(2, 8, b.sub(a).mul(slab.z))).toVar();
|
|
105
|
+
const growth = pow(span, float(1).div(steps)).toVar();
|
|
106
|
+
const offset = pow(growth, jitter);
|
|
107
|
+
const first = b.sub(a).mul(growth.sub(1)).div(span.sub(1));
|
|
108
|
+
const ds = first.mul(offset).toVar();
|
|
109
|
+
const t = a.add(first.mul(offset.sub(1)).div(growth.sub(1))).toVar();
|
|
110
|
+
const transmittance = float(1).toVar();
|
|
111
|
+
const color = vec3(0).toVar();
|
|
112
|
+
If(b.greaterThan(a), () => {
|
|
113
|
+
Loop(64, ({ i }) => {
|
|
114
|
+
If(float(i).greaterThanEqual(steps).or(transmittance.lessThan(.01)), () => {
|
|
115
|
+
Break();
|
|
116
|
+
});
|
|
117
|
+
const p = ro.add(rd.mul(t)).toVar();
|
|
118
|
+
const length = float(ds).toVar();
|
|
119
|
+
t.addAssign(ds);
|
|
120
|
+
ds.mulAssign(growth);
|
|
121
|
+
const lod = clamp(log2(length.mul(field.x).mul(256)), 0, 6).toVar();
|
|
122
|
+
const d = full(p, lod).toVar();
|
|
123
|
+
If(d.greaterThan(0), () => {
|
|
124
|
+
const depth = lightDepth(p, lod).toVar();
|
|
125
|
+
const sunlight = exp(depth.negate()).mul(lobes).add(float(.3).div(depth.mul(.08).add(1)));
|
|
126
|
+
const h = p.y.sub(slab.x).mul(slab.z);
|
|
127
|
+
const light = sunColor.mul(sunlight).add(mix(ambientBottom, ambientTop, h));
|
|
128
|
+
const step = exp(d.mul(march.w).mul(length).negate()).toVar();
|
|
129
|
+
color.addAssign(light.mul(transmittance.mul(step.oneMinus())));
|
|
130
|
+
transmittance.mulAssign(step);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
const opacity = transmittance.oneMinus().toVar();
|
|
135
|
+
const alpha = opacity.mul(smoothstep(slab.w.mul(phase.w), slab.w, a).oneMinus()).toVar();
|
|
136
|
+
Discard(alpha.lessThan(.002));
|
|
137
|
+
const hazeDepth = a.mul(mix(1, .35, smoothstep(.05, .5, abs(rd.y))));
|
|
138
|
+
const hazed = select(fog.w.lessThan(.5), float(0), select(fog.w.lessThan(1.5), smoothstep(fog.x, fog.y, hazeDepth), exp(fog.z.mul(fog.z).mul(hazeDepth).mul(hazeDepth).negate()).oneMinus()));
|
|
139
|
+
return vec4(mix(color.div(max(opacity, 1e-4)), fogColor.xyz, hazed), alpha.mul(hazed.mul(fogColor.w).oneMinus()));
|
|
140
|
+
});
|
|
141
|
+
const material = new MeshBasicNodeMaterial({
|
|
142
|
+
name: "molen:clouds",
|
|
143
|
+
transparent: true,
|
|
144
|
+
depthWrite: false,
|
|
145
|
+
side: THREE.DoubleSide,
|
|
146
|
+
fog: false
|
|
147
|
+
});
|
|
148
|
+
material.colorNode = cloud();
|
|
149
|
+
material.forceSinglePass = true;
|
|
150
|
+
return material;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Multiply every directional light by the cloud shadow, as the WebGL hook in cloud-shadows.ts
|
|
154
|
+
* does. Call before the renderer builds its first lit material.
|
|
155
|
+
*/
|
|
156
|
+
function installWebGpuCloudShadows(renderer, uniforms) {
|
|
157
|
+
const map = uniforms.molenCloudMap.value;
|
|
158
|
+
const shadow = uniform(uniforms.molenCloudShadow.value).setGroup(renderGroup);
|
|
159
|
+
const field = uniform(uniforms.molenCloudField.value).setGroup(renderGroup);
|
|
160
|
+
const weights = uniform(uniforms.molenCloudMix.value).setGroup(renderGroup);
|
|
161
|
+
const fit = uniform(uniforms.molenCloudFit.value).setGroup(renderGroup);
|
|
162
|
+
const factor = (light) => {
|
|
163
|
+
const toLight = normalize(lightPosition(light).sub(lightTargetPosition(light))).toVar();
|
|
164
|
+
const world = positionWorld;
|
|
165
|
+
const cast = mix(shadow.y, shadow.z, fit.z);
|
|
166
|
+
const w = texture(map, world.xz.add(toLight.xz.mul(max(cast.sub(world.y), 0).div(max(toLight.y, .05)))).mul(field.x).add(field.yz), 0);
|
|
167
|
+
const soft = fit.x;
|
|
168
|
+
const cell = dot(w, weights).toVar();
|
|
169
|
+
const cover = clamp(cell.add(field.w.mul(soft.add(1))).sub(1).div(soft), 0, 1).mul(fit.w.mul(cell.oneMinus()).oneMinus());
|
|
170
|
+
const strength = select(toLight.y.greaterThan(0), shadow.x.mul(smoothstep(shadow.y, shadow.z, world.y).oneMinus()), float(0));
|
|
171
|
+
return mix(float(1), exp(cover.mul(fit.y).negate()), strength);
|
|
172
|
+
};
|
|
173
|
+
class CloudShadowedLightNode extends DirectionalLightNode {
|
|
174
|
+
setupDirect(builder) {
|
|
175
|
+
const direct = super.setupDirect(builder);
|
|
176
|
+
const light = this.light;
|
|
177
|
+
return {
|
|
178
|
+
...direct,
|
|
179
|
+
lightColor: direct.lightColor.mul(factor(light))
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
renderer.library?.lightNodes?.set(THREE.DirectionalLight, CloudShadowedLightNode);
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { createWebGpuCloudMaterial, installWebGpuCloudShadows };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/molen-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"audio"
|
|
30
30
|
],
|
|
31
31
|
"exports": {
|
|
32
|
+
"./glass": {
|
|
33
|
+
"types": "./dist/glass.d.mts",
|
|
34
|
+
"default": "./dist/glass.mjs"
|
|
35
|
+
},
|
|
32
36
|
"./text": {
|
|
33
37
|
"types": "./dist/text.d.mts",
|
|
34
38
|
"default": "./dist/text.mjs"
|
|
@@ -75,8 +79,8 @@
|
|
|
75
79
|
"NOTICE.md"
|
|
76
80
|
],
|
|
77
81
|
"dependencies": {
|
|
78
|
-
"@bendyline/molen-materials": "0.0.
|
|
79
|
-
"@bendyline/molen-schema": "0.0.
|
|
82
|
+
"@bendyline/molen-materials": "0.0.11",
|
|
83
|
+
"@bendyline/molen-schema": "0.0.10",
|
|
80
84
|
"zod": "^4.6.5"
|
|
81
85
|
},
|
|
82
86
|
"peerDependencies": {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
|
|
2
|
-
import { VehicleInteriorSpec, VehicleSpec } from "@bendyline/molen-schema";
|
|
3
|
-
import { Object3D } from "three";
|
|
4
|
-
|
|
5
|
-
//#region src/vehicle-camera.d.ts
|
|
6
|
-
interface VehicleCameraOptions {
|
|
7
|
-
view: "cockpit" | "chase";
|
|
8
|
-
lookYaw?: number;
|
|
9
|
-
lookPitch?: number;
|
|
10
|
-
/** Distance to the first static obstruction between two absolute world points. */
|
|
11
|
-
obstructionDistance?: (from: [number, number, number], to: [number, number, number]) => number | undefined;
|
|
12
|
-
}
|
|
13
|
-
interface VehicleCameraPose {
|
|
14
|
-
position: [number, number, number];
|
|
15
|
-
lookAt: [number, number, number];
|
|
16
|
-
yaw: number;
|
|
17
|
-
pitch: number;
|
|
18
|
-
}
|
|
19
|
-
/** Seat-space cockpit and collision-shortened chase views for any vehicle host. */
|
|
20
|
-
declare function vehicleCameraPose(transform: {
|
|
21
|
-
pos: [number, number, number];
|
|
22
|
-
rot: [number, number, number, number];
|
|
23
|
-
}, spec: Pick<VehicleSpec, "driverEye" | "length">, options: VehicleCameraOptions): VehicleCameraPose;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/vehicle-interior.d.ts
|
|
26
|
-
type VehicleInteriorSignals = ModelSignals;
|
|
27
|
-
type VehicleInteriorVisual = ModelSignalVisual;
|
|
28
|
-
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
29
|
-
declare function createVehicleInteriorVisual(model: Object3D, spec: VehicleInteriorSpec): VehicleInteriorVisual;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { VehicleCameraPose as a, VehicleCameraOptions as i, VehicleInteriorVisual as n, vehicleCameraPose as o, createVehicleInteriorVisual as r, VehicleInteriorSignals as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
|
-
//#region src/vehicle-interior.ts
|
|
3
|
-
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
4
|
-
function createVehicleInteriorVisual(model, spec) {
|
|
5
|
-
const visual = createModelSignalVisual(model, spec);
|
|
6
|
-
return {
|
|
7
|
-
...visual,
|
|
8
|
-
get missingSignals() {
|
|
9
|
-
return visual.missingSignals;
|
|
10
|
-
},
|
|
11
|
-
missingNodes: [...new Set([...spec.nodes.filter((name) => !model.getObjectByName(name)), ...visual.missingNodes])]
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createVehicleInteriorVisual as t };
|