@bendyline/molen-client 0.0.13 → 0.0.15

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.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
2
2
  import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
3
- import { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.mjs";
3
+ import { a as createAircraftDamageVisual, i as aircraftObstacleContacts, n as drawGlassInOnePass, r as isGlass, t as createVehicleInteriorVisual } from "./vehicle-interior-CNLLi38s.mjs";
4
+ import { boostSpeedMultiplier } from "@bendyline/molen-schema";
4
5
  import * as THREE from "three";
5
6
  //#region src/aircraft-controls.ts
6
7
  /** Discover moving controls from their authored input bindings, never from instrument needles. */
@@ -361,7 +362,7 @@ function createAircraftPropellers(model, spec) {
361
362
  }
362
363
  }
363
364
  return {
364
- update(state) {
365
+ update(state, castShadows = true) {
365
366
  for (const prop of propellers) {
366
367
  const rpm = (prop.engine === void 0 ? void 0 : state.engines?.[prop.engine])?.rpm ?? state.rpm;
367
368
  const blend = prop.parts.some((part) => state.damage?.[part]?.detached) || !Number.isFinite(rpm) ? 0 : THREE.MathUtils.smoothstep(Math.abs(rpm * prop.speed), 20, 60);
@@ -377,7 +378,7 @@ function createAircraftPropellers(model, spec) {
377
378
  const ready = mesh.userData.materialReady;
378
379
  const fading = blend > 0 && (ready === void 0 || faded.filter((material) => !ready(material)).length === 0);
379
380
  mesh.material = !fading ? original : Array.isArray(original) ? faded : faded[0];
380
- mesh.castShadow = shadow && !fading;
381
+ mesh.castShadow = shadow && !fading && castShadows;
381
382
  }
382
383
  }
383
384
  },
@@ -678,6 +679,503 @@ function bindActiveCockpitPointer(options) {
678
679
  };
679
680
  }
680
681
  //#endregion
682
+ //#region src/pilot-motion.ts
683
+ /**
684
+ * The tuned defaults, sized to be felt more than seen. Flown through the kernel's flight model:
685
+ * a 6 g pull in the P-51 lowers the eye 3 cm, presses it over 1 cm back and drops the chin 1.5°,
686
+ * and on release the pilot comes up nearly 1 cm past rest before settling; 8.5 g in an F-16
687
+ * sinks 3.8 cm. Full brakes at 0.75 g throw the pilot nearly 3 cm forward, half of which they
688
+ * recover as they brace; full power presses them 1 cm back. A 60° bank tilts the head 3° toward
689
+ * the horizon.
690
+ */
691
+ const DEFAULT_PILOT_MOTION = {
692
+ enabled: true,
693
+ intensity: 1,
694
+ maxLoad: 12,
695
+ braceTime: 1.2,
696
+ heave: {
697
+ travel: .008,
698
+ limit: [.045, .025],
699
+ frequency: 2.6,
700
+ damping: .5,
701
+ brace: .3
702
+ },
703
+ surge: {
704
+ travel: .025,
705
+ limit: [.015, .06],
706
+ frequency: 1.8,
707
+ damping: .55,
708
+ brace: .5
709
+ },
710
+ sway: {
711
+ travel: .03,
712
+ limit: [.05, .05],
713
+ frequency: 1.6,
714
+ damping: .55,
715
+ brace: .6
716
+ },
717
+ head: {
718
+ nod: .006,
719
+ surgeNod: .04,
720
+ swayTilt: .05,
721
+ lag: .004,
722
+ horizonLean: .12,
723
+ limit: .1,
724
+ neck: .12,
725
+ frequency: 2.4,
726
+ damping: .6
727
+ }
728
+ };
729
+ /** A {@link PilotMotionSample} from a vehicle's transform and state. */
730
+ function pilotMotionSample(time, transform, state) {
731
+ return {
732
+ time,
733
+ position: transform.pos,
734
+ rotation: transform.rot,
735
+ velocity: state.velocity,
736
+ travelScale: boostSpeedMultiplier(state.boosted)
737
+ };
738
+ }
739
+ const G = 9.81;
740
+ /** Longest integration step, seconds: several per cycle of the stiffest spring. */
741
+ const MAX_STEP = 1 / 120;
742
+ /** A gap this long between samples (a pause, a tab in the background) starts afresh. */
743
+ const MAX_GAP = .5;
744
+ /** Turn rates beyond this, rad/s, are a respawn or a reset rather than a maneuver. */
745
+ const MAX_TURN_RATE = 25;
746
+ /** Angular acceleration, rad/s², beyond which the head's lag is clipped. */
747
+ const MAX_TURN_ACCELERATION = 40;
748
+ /** `value` held within `-negative..positive`, easing into either end. */
749
+ function soften(value, negative, positive) {
750
+ const limit = value < 0 ? negative : positive;
751
+ return limit > 0 ? limit * Math.tanh(value / limit) : 0;
752
+ }
753
+ const clamp = (value, limit) => Math.max(-limit, Math.min(limit, value));
754
+ /** A damped spring's next `[value, rate]` after `h` seconds of pulling toward `target`. */
755
+ function spring(value, rate, target, frequency, damping, h) {
756
+ const stiffness = 2 * Math.PI * frequency;
757
+ const next = rate + h * (stiffness * stiffness * (target - value) - 2 * damping * stiffness * rate);
758
+ return [value + h * next, next];
759
+ }
760
+ /** World vector `v` as the frame with orientation `q` sees it: `v` rotated by `q`'s inverse. */
761
+ function intoFrame(q, v) {
762
+ const [x, y, z, w] = q;
763
+ const cx = y * v[2] - z * v[1], cy = z * v[0] - x * v[2], cz = x * v[1] - y * v[0];
764
+ return [
765
+ v[0] - 2 * (w * cx - (y * cz - z * cy)),
766
+ v[1] - 2 * (w * cy - (z * cx - x * cz)),
767
+ v[2] - 2 * (w * cz - (x * cy - y * cx))
768
+ ];
769
+ }
770
+ /** The rotation from `a` to `b` as a rotation vector in `a`'s own frame (radians). */
771
+ function turnBetween(a, b) {
772
+ let x = a[3] * b[0] - a[0] * b[3] - a[1] * b[2] + a[2] * b[1];
773
+ let y = a[3] * b[1] + a[0] * b[2] - a[1] * b[3] - a[2] * b[0];
774
+ let z = a[3] * b[2] - a[0] * b[1] + a[1] * b[0] - a[2] * b[3];
775
+ let w = a[3] * b[3] + a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
776
+ if (w < 0) {
777
+ x = -x;
778
+ y = -y;
779
+ z = -z;
780
+ w = -w;
781
+ }
782
+ const sine = Math.hypot(x, y, z);
783
+ if (sine < 1e-9) return [
784
+ 2 * x,
785
+ 2 * y,
786
+ 2 * z
787
+ ];
788
+ const scale = 2 * Math.atan2(sine, w) / sine;
789
+ return [
790
+ x * scale,
791
+ y * scale,
792
+ z * scale
793
+ ];
794
+ }
795
+ /**
796
+ * A complete tuning: `base` (the defaults when omitted) with `settings` over it. `true` and
797
+ * `false` only switch the effect; an object changes the fields it names.
798
+ */
799
+ function pilotMotionTuning(settings = {}, base = DEFAULT_PILOT_MOTION) {
800
+ const overrides = typeof settings === "boolean" ? { enabled: settings } : settings;
801
+ return {
802
+ enabled: overrides.enabled ?? base.enabled,
803
+ intensity: overrides.intensity ?? base.intensity,
804
+ maxLoad: overrides.maxLoad ?? base.maxLoad,
805
+ braceTime: overrides.braceTime ?? base.braceTime,
806
+ heave: {
807
+ ...base.heave,
808
+ ...overrides.heave
809
+ },
810
+ surge: {
811
+ ...base.surge,
812
+ ...overrides.surge
813
+ },
814
+ sway: {
815
+ ...base.sway,
816
+ ...overrides.sway
817
+ },
818
+ head: {
819
+ ...base.head,
820
+ ...overrides.head
821
+ }
822
+ };
823
+ }
824
+ /** The body's axes in seat order: X (left), Y (up), Z (forward). */
825
+ const AXES = [
826
+ "sway",
827
+ "heave",
828
+ "surge"
829
+ ];
830
+ const XYZ = [
831
+ 0,
832
+ 1,
833
+ 2
834
+ ];
835
+ /**
836
+ * The pilot's body in the seat. Feed it the vehicle's motion once a frame with {@link update}
837
+ * and pass the pose it returns to `aircraftCameraPose` as `motion`.
838
+ *
839
+ * What the pilot feels is the specific force in the seat frame: the vehicle's acceleration less
840
+ * gravity, 1 g straight up through the seat when parked or in level flight. The body is three
841
+ * damped springs driven by how far that is from 1 g up, and the head three more.
842
+ */
843
+ var PilotMotion = class {
844
+ /** Live tuning: change a field and the next {@link update} uses it. */
845
+ tuning;
846
+ /**
847
+ * The load last felt, in g, in the seat frame (+X left, +Y up, +Z forward): [0, 1, 0] parked
848
+ * or in level flight, [0, 4, 0] in a 4 g pull. For a HUD or for tuning.
849
+ */
850
+ load = [
851
+ 0,
852
+ 1,
853
+ 0
854
+ ];
855
+ current = {
856
+ offset: [
857
+ 0,
858
+ 0,
859
+ 0
860
+ ],
861
+ pitch: 0,
862
+ yaw: 0,
863
+ roll: 0
864
+ };
865
+ previous;
866
+ travel = [
867
+ 0,
868
+ 0,
869
+ 0
870
+ ];
871
+ travelRate = [
872
+ 0,
873
+ 0,
874
+ 0
875
+ ];
876
+ braced = [
877
+ 0,
878
+ 0,
879
+ 0
880
+ ];
881
+ head = [
882
+ 0,
883
+ 0,
884
+ 0
885
+ ];
886
+ headRate = [
887
+ 0,
888
+ 0,
889
+ 0
890
+ ];
891
+ constructor(settings = {}) {
892
+ this.tuning = pilotMotionTuning(settings);
893
+ }
894
+ /** Change some of the tuning; `true` and `false` switch the whole effect. */
895
+ configure(settings) {
896
+ this.tuning = pilotMotionTuning(settings, this.tuning);
897
+ }
898
+ /** The pose as of the last {@link update}. */
899
+ get pose() {
900
+ return this.current;
901
+ }
902
+ /** Forget the motion so far: for a new seat. The next sample starts settled in it. */
903
+ reset() {
904
+ this.previous = void 0;
905
+ for (const values of [
906
+ this.travel,
907
+ this.travelRate,
908
+ this.braced,
909
+ this.head,
910
+ this.headRate
911
+ ]) values.fill(0);
912
+ this.load[0] = 0;
913
+ this.load[1] = 1;
914
+ this.load[2] = 0;
915
+ this.write();
916
+ }
917
+ /** Advance to `sample.time` and return where the pilot's eyes now are. */
918
+ update(sample) {
919
+ if (!this.tuning.enabled) {
920
+ if (this.previous !== void 0) this.reset();
921
+ return this.current;
922
+ }
923
+ const scale = sample.travelScale && sample.travelScale > 0 ? sample.travelScale : 1;
924
+ const velocity = [
925
+ sample.velocity[0] / scale,
926
+ sample.velocity[1] / scale,
927
+ sample.velocity[2] / scale
928
+ ];
929
+ const position = [...sample.position];
930
+ const rotation = [...sample.rotation];
931
+ const upward = intoFrame(rotation, [
932
+ 0,
933
+ 1,
934
+ 0
935
+ ]);
936
+ const last = this.previous;
937
+ const dt = last === void 0 ? 0 : sample.time - last.time;
938
+ if (last !== void 0 && dt === 0) return this.current;
939
+ let turn;
940
+ let fresh = last === void 0 || dt < 0 || dt > MAX_GAP;
941
+ if (last !== void 0 && !fresh) {
942
+ const moved = Math.hypot(position[0] - last.position[0], position[1] - last.position[1], position[2] - last.position[2]);
943
+ const reach = Math.max(Math.hypot(...velocity), Math.hypot(...last.velocity)) * scale * dt;
944
+ turn = turnBetween(last.rotation, rotation).map((v) => v / dt);
945
+ if (moved > 2 * reach + 3 || Math.hypot(...turn) > MAX_TURN_RATE) fresh = true;
946
+ }
947
+ if (last === void 0 || fresh) {
948
+ this.reset();
949
+ this.previous = {
950
+ time: sample.time,
951
+ position,
952
+ rotation,
953
+ velocity,
954
+ turn: void 0
955
+ };
956
+ const deviation = [
957
+ upward[0],
958
+ upward[1] - 1,
959
+ upward[2]
960
+ ];
961
+ this.load[0] = upward[0];
962
+ this.load[1] = upward[1];
963
+ this.load[2] = upward[2];
964
+ const targets = this.targets(deviation, deviation, upward, [
965
+ 0,
966
+ 0,
967
+ 0
968
+ ]);
969
+ for (const i of XYZ) {
970
+ this.braced[i] = deviation[i];
971
+ this.travel[i] = targets.travel[i];
972
+ this.head[i] = targets.head[i];
973
+ }
974
+ this.write();
975
+ return this.current;
976
+ }
977
+ const felt = intoFrame(rotation, [
978
+ (velocity[0] - last.velocity[0]) / dt / G,
979
+ (velocity[1] - last.velocity[1]) / dt / G + 1,
980
+ (velocity[2] - last.velocity[2]) / dt / G
981
+ ]);
982
+ this.load[0] = felt[0];
983
+ this.load[1] = felt[1];
984
+ this.load[2] = felt[2];
985
+ const limit = Math.max(0, this.tuning.maxLoad);
986
+ const deviation = [
987
+ clamp(felt[0], limit),
988
+ clamp(felt[1] - 1, limit),
989
+ clamp(felt[2], limit)
990
+ ];
991
+ const turning = turn ?? [
992
+ 0,
993
+ 0,
994
+ 0
995
+ ];
996
+ const before = last.turn;
997
+ const spin = before === void 0 ? [
998
+ 0,
999
+ 0,
1000
+ 0
1001
+ ] : [
1002
+ clamp((turning[0] - before[0]) / dt, MAX_TURN_ACCELERATION),
1003
+ clamp((turning[1] - before[1]) / dt, MAX_TURN_ACCELERATION),
1004
+ clamp((turning[2] - before[2]) / dt, MAX_TURN_ACCELERATION)
1005
+ ];
1006
+ this.previous = {
1007
+ time: sample.time,
1008
+ position,
1009
+ rotation,
1010
+ velocity,
1011
+ turn: turning
1012
+ };
1013
+ const steps = Math.max(1, Math.ceil(dt / MAX_STEP));
1014
+ const h = dt / steps;
1015
+ const { head } = this.tuning;
1016
+ const bracing = 1 - Math.exp(-h / Math.max(.001, this.tuning.braceTime));
1017
+ for (let n = 0; n < steps; n++) {
1018
+ const targets = this.targets(deviation, this.braced, upward, spin);
1019
+ for (const i of XYZ) {
1020
+ const axis = this.tuning[AXES[i]];
1021
+ [this.travel[i], this.travelRate[i]] = spring(this.travel[i], this.travelRate[i], targets.travel[i], axis.frequency, axis.damping, h);
1022
+ [this.head[i], this.headRate[i]] = spring(this.head[i], this.headRate[i], targets.head[i], head.frequency, head.damping, h);
1023
+ this.braced[i] += bracing * (deviation[i] - this.braced[i]);
1024
+ }
1025
+ }
1026
+ this.write();
1027
+ return this.current;
1028
+ }
1029
+ /**
1030
+ * Where the springs are heading: body travel per axis and the head's rotation vector, for a
1031
+ * load `deviation` from 1 g up of which the pilot has `braced` against a share.
1032
+ */
1033
+ targets(deviation, braced, upward, spin) {
1034
+ const { head, sway, heave, surge } = this.tuning;
1035
+ const held = [
1036
+ deviation[0] - sway.brace * braced[0],
1037
+ deviation[1] - heave.brace * braced[1],
1038
+ deviation[2] - surge.brace * braced[2]
1039
+ ];
1040
+ return {
1041
+ travel: [
1042
+ -sway.travel * held[0],
1043
+ -heave.travel * held[1],
1044
+ -surge.travel * held[2]
1045
+ ],
1046
+ head: [
1047
+ head.nod * held[1] - head.surgeNod * Math.min(0, held[2]) - head.lag * spin[0],
1048
+ -head.lag * spin[1],
1049
+ head.swayTilt * held[0] - head.horizonLean * upward[0] * Math.max(0, upward[1]) - head.lag * spin[2]
1050
+ ]
1051
+ };
1052
+ }
1053
+ write() {
1054
+ const { intensity, head } = this.tuning;
1055
+ const turn = this.head.map((v) => soften(v * intensity, head.limit, head.limit));
1056
+ const pose = this.current;
1057
+ for (const i of XYZ) {
1058
+ const axis = this.tuning[AXES[i]];
1059
+ pose.offset[i] = soften(this.travel[i] * intensity, axis.limit[0], axis.limit[1]);
1060
+ }
1061
+ pose.offset[0] -= head.neck * Math.sin(turn[2]);
1062
+ pose.offset[2] += head.neck * Math.sin(turn[0]);
1063
+ pose.pitch = -turn[0];
1064
+ pose.yaw = turn[1];
1065
+ pose.roll = turn[2];
1066
+ }
1067
+ };
1068
+ //#endregion
1069
+ //#region src/rotor-blur.ts
1070
+ /**
1071
+ * Blades turn faster than a display can sample them. A C182 at 2400 rpm moves 240 degrees between
1072
+ * 60 Hz frames, exactly two blade spacings of its three-blade propeller, so drawn blades look
1073
+ * stopped at full power. An eye sees a faint disc instead, so draw one: below these speeds the
1074
+ * blades stay crisp, and between them the blades cross-fade into the disc. In radians per second,
1075
+ * about 20 and 45 degrees per frame at 60 Hz.
1076
+ */
1077
+ const BLUR_START = 35;
1078
+ const BLUR_FULL = 78;
1079
+ const DISC_OPACITY = .09;
1080
+ const TIP_OPACITY = .14;
1081
+ /** A mesh reaching past this share of the radius is a blade; anything shorter is hub or spinner. */
1082
+ const HUB_SHARE = .4;
1083
+ const ACROSS = {
1084
+ x: [1, 2],
1085
+ y: [0, 2],
1086
+ z: [0, 1]
1087
+ };
1088
+ const ALONG = {
1089
+ x: 0,
1090
+ y: 1,
1091
+ z: 2
1092
+ };
1093
+ /**
1094
+ * Prepares one rotor node. It reads the blades' real extent from the model, so nothing in the spec
1095
+ * needs a radius or blade count. Returns undefined for a node with no geometry. The disc and the
1096
+ * cloned blade materials join the model, so the visual's dispose releases them.
1097
+ */
1098
+ function createRotorBlur(node, axis) {
1099
+ node.updateWorldMatrix(true, true);
1100
+ const toNode = node.matrixWorld.clone().invert();
1101
+ const [u, v] = ACROSS[axis];
1102
+ const along = ALONG[axis];
1103
+ const reach = /* @__PURE__ */ new Map();
1104
+ const point = new THREE.Vector3();
1105
+ let radius = 0;
1106
+ let plane = 0;
1107
+ let vertices = 0;
1108
+ node.traverse((object) => {
1109
+ if (!(object instanceof THREE.Mesh)) return;
1110
+ const position = object.geometry.getAttribute("position");
1111
+ if (position === void 0) return;
1112
+ const toRotor = toNode.clone().multiply(object.matrixWorld);
1113
+ let furthest = 0;
1114
+ for (let i = 0; i < position.count; i++) {
1115
+ point.fromBufferAttribute(position, i).applyMatrix4(toRotor);
1116
+ furthest = Math.max(furthest, Math.hypot(point.getComponent(u), point.getComponent(v)));
1117
+ }
1118
+ reach.set(object, furthest);
1119
+ radius = Math.max(radius, furthest);
1120
+ });
1121
+ if (radius === 0) return void 0;
1122
+ const blades = [];
1123
+ const copies = /* @__PURE__ */ new Map();
1124
+ for (const [mesh, furthest] of reach) {
1125
+ if (furthest < radius * HUB_SHARE || Array.isArray(mesh.material)) continue;
1126
+ const original = mesh.material;
1127
+ let copy = copies.get(original);
1128
+ if (copy === void 0) {
1129
+ copy = original.clone();
1130
+ copy.transparent = true;
1131
+ copies.set(original, copy);
1132
+ blades.push(copy);
1133
+ }
1134
+ mesh.material = copy;
1135
+ const position = mesh.geometry.getAttribute("position");
1136
+ const toRotor = toNode.clone().multiply(mesh.matrixWorld);
1137
+ for (let i = 0; i < position.count; i++) {
1138
+ plane += point.fromBufferAttribute(position, i).applyMatrix4(toRotor).getComponent(along);
1139
+ vertices++;
1140
+ }
1141
+ }
1142
+ const height = vertices === 0 ? 0 : plane / vertices;
1143
+ const ring = (inner, outer) => {
1144
+ const geometry = new THREE.RingGeometry(inner, outer, 48);
1145
+ if (axis === "x") geometry.rotateY(Math.PI / 2);
1146
+ if (axis === "y") geometry.rotateX(Math.PI / 2);
1147
+ const disc = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({
1148
+ color: 3422268,
1149
+ transparent: true,
1150
+ opacity: 0,
1151
+ side: THREE.DoubleSide,
1152
+ depthWrite: false
1153
+ }));
1154
+ disc.position.setComponent(along, height);
1155
+ disc.visible = false;
1156
+ disc.castShadow = false;
1157
+ disc.receiveShadow = false;
1158
+ disc.userData.vehicleGeometry = true;
1159
+ node.add(disc);
1160
+ return disc;
1161
+ };
1162
+ const disc = ring(radius * .12, radius * .94);
1163
+ const tip = ring(radius * .94, radius);
1164
+ return { update(angularSpeed) {
1165
+ const t = THREE.MathUtils.clamp((Math.abs(angularSpeed) - BLUR_START) / (BLUR_FULL - BLUR_START), 0, 1);
1166
+ const blur = t * t * (3 - 2 * t);
1167
+ for (const material of blades) {
1168
+ material.opacity = 1 - blur;
1169
+ material.depthWrite = blur < .5;
1170
+ }
1171
+ for (const [mesh, opacity] of [[disc, DISC_OPACITY], [tip, TIP_OPACITY]]) {
1172
+ mesh.visible = blur > 0;
1173
+ mesh.material.opacity = opacity * blur;
1174
+ }
1175
+ for (const mesh of reach.keys()) if (blades.includes(mesh.material)) mesh.visible = blur < 1;
1176
+ } };
1177
+ }
1178
+ //#endregion
681
1179
  //#region src/aircraft.ts
682
1180
  /** The group the cockpit-controls generator adds beside a model's cockpit: levers and legends. */
683
1181
  const FLIGHT_CONTROLS_NODE = "flight-controls";
@@ -689,6 +1187,15 @@ const FLIGHT_CONTROLS_NODE = "flight-controls";
689
1187
  */
690
1188
  const CABIN_DETAIL_ANGLE = .002;
691
1189
  /**
1190
+ * Sun shadow-map texel (meters) beyond which the map no longer resolves an aircraft's own canopy
1191
+ * frame, seat and panels. Coarser, their shadows on the aircraft fall in blocks that jump as it
1192
+ * slides across the map's texel grid: at 0.2 m (100 m above the ground on High) about 1% of an
1193
+ * F-15C's cockpit view changed from frame to frame in straight flight, at 0.8 m 10%, a cockpit
1194
+ * flickering in the sun. It comes back once texels are SELF_SHADOW_RETURN or finer.
1195
+ */
1196
+ const SELF_SHADOW_TEXEL = .15;
1197
+ const SELF_SHADOW_RETURN = .12;
1198
+ /**
692
1199
  * Takes ownership of a loaded library GLB. The named nodes remain editable in a DCC.
693
1200
  *
694
1201
  * The gear and flaps follow `state.gearPosition` and `state.flapPosition` as they travel, or the
@@ -703,7 +1210,7 @@ function createAircraftVisual(model, spec, livery) {
703
1210
  model.traverse((o) => {
704
1211
  o.userData.vehicleGeometry = true;
705
1212
  if (o instanceof THREE.Mesh) {
706
- o.castShadow = !o.name.includes("canopy") && !o.name.includes("bubble");
1213
+ o.castShadow = !o.name.includes("canopy") && !o.name.includes("bubble") && !isGlass(o);
707
1214
  o.receiveShadow = true;
708
1215
  drawGlassInOnePass(o);
709
1216
  }
@@ -722,6 +1229,22 @@ function createAircraftVisual(model, spec, livery) {
722
1229
  const cabinRange = Math.max(60, 3 * Math.max(spec.length, spec.span));
723
1230
  const damage = createAircraftDamageVisual(model, spec);
724
1231
  let propellers = createAircraftPropellers(model, spec);
1232
+ const rotorEngines = spec.engines ?? (spec.engine ? [{
1233
+ ...spec.engine,
1234
+ id: "main"
1235
+ }] : []);
1236
+ const ownPropeller = (binding) => {
1237
+ if (spec.model !== "airplane") return false;
1238
+ const engine = binding.engine === void 0 ? rotorEngines[0] : rotorEngines.find((e) => e.id === binding.engine);
1239
+ return engine !== void 0 && engine.propulsion !== "jet";
1240
+ };
1241
+ const blurs = /* @__PURE__ */ new Map();
1242
+ for (const binding of spec.visual.rotors) {
1243
+ if (ownPropeller(binding)) continue;
1244
+ const prepared = (moving.get(binding.node) ?? []).flatMap((node) => createRotorBlur(node, binding.axis) ?? []);
1245
+ if (prepared.length > 0) blurs.set(binding, prepared);
1246
+ }
1247
+ const shaftSpeed = (id) => (id === void 0 ? void 0 : spec.engines?.find((engine) => engine.id === id)?.rotorAngularSpeed) ?? spec.engine?.rotorAngularSpeed ?? spec.engines?.[0]?.rotorAngularSpeed ?? 0;
725
1248
  let cabinShown = true;
726
1249
  model.updateMatrixWorld(true);
727
1250
  const modelScale = model.matrixWorld.getMaxScaleOnAxis();
@@ -742,13 +1265,32 @@ function createAircraftVisual(model, spec, livery) {
742
1265
  details.sort((a, b) => b.reach - a.reach);
743
1266
  let detailed = details.length;
744
1267
  const eye = new THREE.Vector3();
1268
+ let shadowsOut = false;
1269
+ const unshadowed = [];
1270
+ const castShadows = (cast) => {
1271
+ shadowsOut = !cast;
1272
+ if (cast) {
1273
+ for (const mesh of unshadowed) mesh.castShadow = true;
1274
+ unshadowed.length = 0;
1275
+ return;
1276
+ }
1277
+ model.traverse((object) => {
1278
+ const mesh = object;
1279
+ if (!mesh.isMesh || !mesh.castShadow) return;
1280
+ mesh.castShadow = false;
1281
+ unshadowed.push(mesh);
1282
+ });
1283
+ };
745
1284
  return {
746
1285
  setLivery(data) {
1286
+ const out = shadowsOut;
1287
+ if (out) castShadows(true);
747
1288
  propellers.dispose();
748
1289
  appearance?.dispose();
749
1290
  damage.reset();
750
1291
  appearance = data === void 0 ? void 0 : applyLivery(model, data);
751
1292
  propellers = createAircraftPropellers(model, spec);
1293
+ if (out) castShadows(false);
752
1294
  },
753
1295
  object: model,
754
1296
  cockpit,
@@ -760,6 +1302,8 @@ function createAircraftVisual(model, spec, livery) {
760
1302
  for (const binding of spec.visual.rotors) {
761
1303
  const engine = binding.engine === void 0 ? void 0 : state.engines?.[binding.engine];
762
1304
  turn(binding.node, binding.axis, (engine?.rotorAngle ?? state.rotorAngle) * binding.multiplier);
1305
+ const speed = Math.min(1, engine?.rpm ?? state.rpm ?? 0) * shaftSpeed(binding.engine) * binding.multiplier;
1306
+ for (const blur of blurs.get(binding) ?? []) blur.update(speed);
763
1307
  }
764
1308
  for (const name of spec.visual.gearNodes) {
765
1309
  if (articulatedGear.has(name)) continue;
@@ -846,9 +1390,13 @@ function createAircraftVisual(model, spec, livery) {
846
1390
  });
847
1391
  interior?.update(telemetry, timeSeconds);
848
1392
  animation?.update(telemetry, timeSeconds);
849
- propellers.update(state);
1393
+ propellers.update(state, !shadowsOut);
850
1394
  damage.update(state);
851
1395
  },
1396
+ updateShadows(texel) {
1397
+ const out = texel !== void 0 && texel > (shadowsOut ? SELF_SHADOW_RETURN : SELF_SHADOW_TEXEL);
1398
+ if (out !== shadowsOut) castShadows(!out);
1399
+ },
852
1400
  updateView(camera) {
853
1401
  if (cabin.length === 0) return;
854
1402
  const p = model.position;
@@ -891,10 +1439,23 @@ function aircraftCameraPose(transform, spec, options) {
891
1439
  const q = new THREE.Quaternion().fromArray(transform.rot);
892
1440
  const origin = new THREE.Vector3().fromArray(transform.pos);
893
1441
  const look = new THREE.Quaternion().setFromEuler(new THREE.Euler(-(options.lookPitch ?? 0), -(options.lookYaw ?? 0), 0, "YXZ"));
894
- const direction = new THREE.Vector3(0, 0, 1).applyQuaternion(look).applyQuaternion(q);
895
- let position = new THREE.Vector3().fromArray(spec.pilotEye).applyQuaternion(q).add(origin);
1442
+ const motion = options.view === "chase" ? void 0 : options.motion;
1443
+ const seat = motion ? q.clone().multiply(new THREE.Quaternion().setFromEuler(new THREE.Euler(-motion.pitch, motion.yaw, motion.roll, "YXZ"))) : q;
1444
+ const direction = new THREE.Vector3(0, 0, 1).applyQuaternion(look).applyQuaternion(seat);
1445
+ const eye = new THREE.Vector3().fromArray(spec.pilotEye);
1446
+ if (motion) eye.add(new THREE.Vector3().fromArray(motion.offset));
1447
+ let position = eye.applyQuaternion(q).add(origin);
896
1448
  let target = position.clone().add(direction);
897
- let up = new THREE.Vector3(0, 1, 0).applyQuaternion(q);
1449
+ let up = new THREE.Vector3(0, 1, 0).applyQuaternion(seat);
1450
+ const shake = options.view === "chase" ? 0 : Math.min(1, options.shake?.amount ?? 0);
1451
+ if (shake > 0) {
1452
+ const time = options.shake?.time ?? 0;
1453
+ const wobble = (rate, phase) => Math.sin(time * rate + phase) + .5 * Math.sin(time * rate * 1.73 + phase * 2.1);
1454
+ const left = new THREE.Vector3(1, 0, 0).applyQuaternion(q);
1455
+ position.addScaledVector(up, .0085 * shake * wobble(64, 0)).addScaledVector(left, .0035 * shake * wobble(47, 1));
1456
+ target = position.clone().add(direction).addScaledVector(up, .0028 * shake * wobble(58, 2)).addScaledVector(left, .0014 * shake * wobble(49, .7));
1457
+ up = up.addScaledVector(left, .0042 * shake * wobble(67, 3)).normalize();
1458
+ }
898
1459
  if (options.view === "chase") {
899
1460
  target = origin.clone().add(new THREE.Vector3(0, 1.5, 0));
900
1461
  position = target.clone().addScaledVector(direction, -spec.length * 1.5).add(new THREE.Vector3(0, 4.5, 0));
@@ -917,4 +1478,4 @@ function aircraftCameraPose(transform, spec, options) {
917
1478
  };
918
1479
  }
919
1480
  //#endregion
920
- export { AircraftPointerAxes, aircraftCameraPose, aircraftControlValue, aircraftObstacleContacts, applyAircraftControl, bindAircraftCockpitPointer, createAircraftCockpit, createAircraftVisual };
1481
+ export { AircraftPointerAxes, DEFAULT_PILOT_MOTION, PilotMotion, aircraftCameraPose, aircraftControlValue, aircraftObstacleContacts, applyAircraftControl, bindAircraftCockpitPointer, createAircraftCockpit, createAircraftVisual, pilotMotionSample, pilotMotionTuning };
@@ -1,4 +1,4 @@
1
- import { n as CameraPose } from "./renderer-DAk7C8jH.mjs";
1
+ import { n as CameraPose } from "./renderer-4kSVioiH.mjs";
2
2
 
3
3
  //#region src/camera-track.d.ts
4
4
  interface CameraTrackKeyframe {