@bendyline/molen-client 0.0.12 → 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/dist/aircraft.d.mts
CHANGED
|
@@ -89,10 +89,12 @@ interface AircraftVisual {
|
|
|
89
89
|
animation?: ModelSignalVisual;
|
|
90
90
|
update(state: AircraftStateData, input: AircraftInputData, altitude: number, signals?: ModelSignals, timeSeconds?: number): void;
|
|
91
91
|
/**
|
|
92
|
-
* The camera, in the coordinates of `object.position`. Cabin nodes (the spec's interior
|
|
93
|
-
* drawn only near it: from farther away a cockpit is a few pixels
|
|
94
|
-
* most of an aircraft's draw calls, and as many again in the
|
|
95
|
-
* views are always near enough
|
|
92
|
+
* The camera, in the coordinates of `object.position`. Cabin nodes (the spec's interior and the
|
|
93
|
+
* generated flight controls) are drawn only near it: from farther away a cockpit is a few pixels
|
|
94
|
+
* behind the canopy, yet it held most of an aircraft's draw calls, and as many again in the
|
|
95
|
+
* shadow pass. Boarded and chase views are always near enough, but within the cabin a part too
|
|
96
|
+
* small to see from the camera (CABIN_DETAIL_ANGLE) leaves the frame through its render layers,
|
|
97
|
+
* so a binding's or damage's own `visible` is never overridden.
|
|
96
98
|
*/
|
|
97
99
|
updateView(camera: readonly [number, number, number]): void;
|
|
98
100
|
dispose(): void;
|
package/dist/aircraft.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
2
|
import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
|
|
3
|
-
import { n as
|
|
3
|
+
import { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.mjs";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
//#region src/aircraft-controls.ts
|
|
6
6
|
/** Discover moving controls from their authored input bindings, never from instrument needles. */
|
|
@@ -342,15 +342,17 @@ function createAircraftPropellers(model, spec) {
|
|
|
342
342
|
disk,
|
|
343
343
|
blades: blades.map(({ mesh }) => {
|
|
344
344
|
const original = mesh.material;
|
|
345
|
+
const faded = (Array.isArray(original) ? original : [original]).map((m) => {
|
|
346
|
+
const clone = m.clone();
|
|
347
|
+
clone.transparent = true;
|
|
348
|
+
clone.depthWrite = false;
|
|
349
|
+
return clone;
|
|
350
|
+
});
|
|
351
|
+
mesh.userData.materialVariants = [...Array.isArray(original) ? original : [original], ...faded];
|
|
345
352
|
return {
|
|
346
353
|
mesh,
|
|
347
354
|
original,
|
|
348
|
-
faded
|
|
349
|
-
const clone = m.clone();
|
|
350
|
-
clone.transparent = true;
|
|
351
|
-
clone.depthWrite = false;
|
|
352
|
-
return clone;
|
|
353
|
-
}),
|
|
355
|
+
faded,
|
|
354
356
|
shadow: mesh.castShadow
|
|
355
357
|
};
|
|
356
358
|
})
|
|
@@ -372,8 +374,10 @@ function createAircraftPropellers(model, spec) {
|
|
|
372
374
|
material.opacity = source.opacity * (1 - blend);
|
|
373
375
|
material.visible = source.visible && blend < 1;
|
|
374
376
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
+
const ready = mesh.userData.materialReady;
|
|
378
|
+
const fading = blend > 0 && (ready === void 0 || faded.filter((material) => !ready(material)).length === 0);
|
|
379
|
+
mesh.material = !fading ? original : Array.isArray(original) ? faded : faded[0];
|
|
380
|
+
mesh.castShadow = shadow && !fading;
|
|
377
381
|
}
|
|
378
382
|
}
|
|
379
383
|
},
|
|
@@ -675,6 +679,15 @@ function bindActiveCockpitPointer(options) {
|
|
|
675
679
|
}
|
|
676
680
|
//#endregion
|
|
677
681
|
//#region src/aircraft.ts
|
|
682
|
+
/** The group the cockpit-controls generator adds beside a model's cockpit: levers and legends. */
|
|
683
|
+
const FLIGHT_CONTROLS_NODE = "flight-controls";
|
|
684
|
+
/**
|
|
685
|
+
* Angular radius (radians) below which a cabin part is left out of the frame: under four pixels
|
|
686
|
+
* across in a 1080p view with a 60° field of view. From a chase camera fifteen meters back,
|
|
687
|
+
* gauges, needles and switches are each smaller than that behind the canopy, and each was a draw:
|
|
688
|
+
* the P-51's cockpit, 415 meshes, was a quarter of a takeoff's draws in chase view.
|
|
689
|
+
*/
|
|
690
|
+
const CABIN_DETAIL_ANGLE = .002;
|
|
678
691
|
/**
|
|
679
692
|
* Takes ownership of a loaded library GLB. The named nodes remain editable in a DCC.
|
|
680
693
|
*
|
|
@@ -692,6 +705,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
692
705
|
if (o instanceof THREE.Mesh) {
|
|
693
706
|
o.castShadow = !o.name.includes("canopy") && !o.name.includes("bubble");
|
|
694
707
|
o.receiveShadow = true;
|
|
708
|
+
drawGlassInOnePass(o);
|
|
695
709
|
}
|
|
696
710
|
const list = moving.get(o.name) ?? [];
|
|
697
711
|
list.push(o);
|
|
@@ -701,7 +715,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
701
715
|
for (const node of moving.get(name) ?? []) node.rotation[axis] = angle;
|
|
702
716
|
};
|
|
703
717
|
let appearance = livery === void 0 ? void 0 : applyLivery(model, livery);
|
|
704
|
-
const cabin =
|
|
718
|
+
const cabin = [...spec.visual.interior?.nodes ?? [], FLIGHT_CONTROLS_NODE].flatMap((name) => moving.get(name) ?? []);
|
|
705
719
|
for (const node of cabin) node.traverse((object) => {
|
|
706
720
|
if (object.isMesh) object.userData.walkIgnore = true;
|
|
707
721
|
});
|
|
@@ -709,6 +723,25 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
709
723
|
const damage = createAircraftDamageVisual(model, spec);
|
|
710
724
|
let propellers = createAircraftPropellers(model, spec);
|
|
711
725
|
let cabinShown = true;
|
|
726
|
+
model.updateMatrixWorld(true);
|
|
727
|
+
const modelScale = model.matrixWorld.getMaxScaleOnAxis();
|
|
728
|
+
const details = [];
|
|
729
|
+
const listed = /* @__PURE__ */ new Set();
|
|
730
|
+
for (const node of cabin) node.traverse((object) => {
|
|
731
|
+
const mesh = object;
|
|
732
|
+
if (!mesh.isMesh || listed.has(mesh)) return;
|
|
733
|
+
listed.add(mesh);
|
|
734
|
+
if (mesh.geometry.boundingSphere === null) mesh.geometry.computeBoundingSphere();
|
|
735
|
+
const radius = (mesh.geometry.boundingSphere?.radius ?? 0) * mesh.matrixWorld.getMaxScaleOnAxis() / modelScale;
|
|
736
|
+
details.push({
|
|
737
|
+
mesh,
|
|
738
|
+
reach: radius / CABIN_DETAIL_ANGLE,
|
|
739
|
+
layers: mesh.layers.mask
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
details.sort((a, b) => b.reach - a.reach);
|
|
743
|
+
let detailed = details.length;
|
|
744
|
+
const eye = new THREE.Vector3();
|
|
712
745
|
return {
|
|
713
746
|
setLivery(data) {
|
|
714
747
|
propellers.dispose();
|
|
@@ -820,9 +853,22 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
820
853
|
if (cabin.length === 0) return;
|
|
821
854
|
const p = model.position;
|
|
822
855
|
const shown = Math.hypot(p.x - camera[0], p.y - camera[1], p.z - camera[2]) < cabinRange * (cabinShown ? 1.1 : 1);
|
|
823
|
-
if (shown
|
|
824
|
-
|
|
825
|
-
|
|
856
|
+
if (shown !== cabinShown) {
|
|
857
|
+
cabinShown = shown;
|
|
858
|
+
for (const node of cabin) node.visible = shown;
|
|
859
|
+
}
|
|
860
|
+
if (!shown) return;
|
|
861
|
+
eye.fromArray(spec.pilotEye).applyQuaternion(model.quaternion).add(p);
|
|
862
|
+
const near = Math.hypot(eye.x - camera[0], eye.y - camera[1], eye.z - camera[2]);
|
|
863
|
+
for (let next = details[detailed]; next !== void 0 && near < next.reach;) {
|
|
864
|
+
next.mesh.layers.mask = next.layers;
|
|
865
|
+
next = details[++detailed];
|
|
866
|
+
}
|
|
867
|
+
for (let last = details[detailed - 1]; last !== void 0 && near > last.reach * 1.1;) {
|
|
868
|
+
last.layers = last.mesh.layers.mask;
|
|
869
|
+
last.mesh.layers.mask = 0;
|
|
870
|
+
last = details[--detailed - 1];
|
|
871
|
+
}
|
|
826
872
|
},
|
|
827
873
|
dispose() {
|
|
828
874
|
damage.reset();
|
package/dist/glass.mjs
CHANGED
|
@@ -110,7 +110,8 @@ function createGlassVisual(model, data) {
|
|
|
110
110
|
transparent: true,
|
|
111
111
|
opacity: .36,
|
|
112
112
|
depthWrite: false,
|
|
113
|
-
side: THREE.DoubleSide
|
|
113
|
+
side: THREE.DoubleSide,
|
|
114
|
+
forceSinglePass: true
|
|
114
115
|
});
|
|
115
116
|
const { geometry, centers, edges } = cells(spec);
|
|
116
117
|
const mesh = new THREE.Mesh(geometry, material);
|
|
@@ -439,6 +439,19 @@ function aircraftObstacleContacts(probes, scene) {
|
|
|
439
439
|
return contacts;
|
|
440
440
|
}
|
|
441
441
|
//#endregion
|
|
442
|
+
//#region src/vehicle-glass.ts
|
|
443
|
+
/**
|
|
444
|
+
* Draw a model's double-sided transparent materials (canopies, windscreens, instrument covers) in
|
|
445
|
+
* one pass. Three otherwise draws each such mesh twice, back faces then front, and flags the
|
|
446
|
+
* material for a new program before each pass: two program lookups and two full uniform uploads
|
|
447
|
+
* per pane, every frame. A P-51 on an apron of parked aircraft switched 52 programs a frame that
|
|
448
|
+
* way. The panes are thin and blended without depth writes (glTF BLEND), so only the order in
|
|
449
|
+
* which a pane's two faces blend can change.
|
|
450
|
+
*/
|
|
451
|
+
function drawGlassInOnePass(mesh) {
|
|
452
|
+
for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) if (material.transparent && material.side === THREE.DoubleSide) material.forceSinglePass = true;
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
442
455
|
//#region src/vehicle-interior.ts
|
|
443
456
|
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
444
457
|
function createVehicleInteriorVisual(model, spec) {
|
|
@@ -452,4 +465,4 @@ function createVehicleInteriorVisual(model, spec) {
|
|
|
452
465
|
};
|
|
453
466
|
}
|
|
454
467
|
//#endregion
|
|
455
|
-
export {
|
|
468
|
+
export { createAircraftDamageVisual as i, drawGlassInOnePass as n, aircraftObstacleContacts as r, createVehicleInteriorVisual as t };
|
package/dist/vehicles.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
2
|
import { createGlassVisual } from "./glass.mjs";
|
|
3
3
|
import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
|
|
4
|
-
import { n as
|
|
4
|
+
import { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.mjs";
|
|
5
5
|
import * as THREE from "three";
|
|
6
6
|
//#region src/vehicle-proxy.ts
|
|
7
7
|
const templates = /* @__PURE__ */ new Map();
|
|
@@ -320,6 +320,7 @@ function createVehicleVisual(model, vehicle, livery, glassData) {
|
|
|
320
320
|
return material;
|
|
321
321
|
});
|
|
322
322
|
object.material = Array.isArray(object.material) ? cloned : cloned[0];
|
|
323
|
+
drawGlassInOnePass(object);
|
|
323
324
|
}
|
|
324
325
|
});
|
|
325
326
|
model.updateMatrixWorld(true);
|