@bendyline/molen-ambient 0.0.8 → 0.0.9

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.
Files changed (2) hide show
  1. package/dist/client.mjs +74 -1
  2. package/package.json +7 -7
package/dist/client.mjs CHANGED
@@ -489,6 +489,72 @@ function ambientVehicleKind(options = {}) {
489
489
  * Aircraft overhead: content models (propellers or fans turning) when the host supplies them,
490
490
  * otherwise instanced proxies drawn by the vehicle batches.
491
491
  */
492
+ /** Node names the aircraft visual moves or toggles; everything else on an ambient copy is still. */
493
+ function movingNodes(spec) {
494
+ const visual = spec.visual;
495
+ return new Set([
496
+ ...visual.rotors.map((binding) => binding.node),
497
+ ...visual.gearNodes,
498
+ ...visual.flaps.map((binding) => binding.node),
499
+ ...visual.ailerons.map((binding) => binding.node),
500
+ ...visual.controlStick !== void 0 ? [visual.controlStick.node] : [],
501
+ ...visual.collective !== void 0 ? [visual.collective.node] : []
502
+ ]);
503
+ }
504
+ /**
505
+ * An aircraft overhead is seen from hundreds of meters, so its hundreds of still parts (fuselage,
506
+ * wings, canopy frame, cockpit) merge into one mesh per material: a copy costs a draw per
507
+ * material plus its moving parts, instead of one per part (281 for the P-51). Moving parts keep
508
+ * their nodes and bindings. The visual is built without the interior, which is never animated
509
+ * overhead. Exported for tests.
510
+ */
511
+ function mergeStaticAircraftParts(model, spec) {
512
+ const moving = movingNodes(spec);
513
+ model.updateMatrixWorld(true);
514
+ const toModel = new THREE.Matrix4().copy(model.matrixWorld).invert();
515
+ const groups = /* @__PURE__ */ new Map();
516
+ const merged = [];
517
+ const visit = (object) => {
518
+ if (moving.has(object.name)) return;
519
+ for (const child of [...object.children]) visit(child);
520
+ const mesh = object;
521
+ if (!mesh.isMesh || Array.isArray(mesh.material) || mesh.isSkinnedMesh) return;
522
+ const source = mesh.geometry;
523
+ if (source.morphAttributes.position !== void 0) return;
524
+ const geometry = new THREE.BufferGeometry();
525
+ for (const name of [
526
+ "position",
527
+ "normal",
528
+ "color"
529
+ ]) {
530
+ const attribute = source.getAttribute(name);
531
+ if (attribute === void 0) continue;
532
+ const copy = new Float32Array(attribute.count * attribute.itemSize);
533
+ for (let i = 0; i < attribute.count; i++) for (let c = 0; c < attribute.itemSize; c++) copy[i * attribute.itemSize + c] = attribute.getComponent(i, c);
534
+ geometry.setAttribute(name, new THREE.BufferAttribute(copy, attribute.itemSize));
535
+ }
536
+ if (source.index !== null) geometry.setIndex(source.index.clone());
537
+ geometry.applyMatrix4(new THREE.Matrix4().multiplyMatrices(toModel, mesh.matrixWorld));
538
+ const key = `${mesh.material.uuid}|${[...Object.keys(geometry.attributes)].sort().join()}|${geometry.index !== null}`;
539
+ const group = groups.get(key) ?? {
540
+ material: mesh.material,
541
+ parts: []
542
+ };
543
+ group.parts.push(geometry);
544
+ groups.set(key, group);
545
+ mesh.removeFromParent();
546
+ };
547
+ visit(model);
548
+ for (const { material, parts } of groups.values()) {
549
+ const geometry = mergeGeometries(parts, false);
550
+ for (const part of parts) part.dispose();
551
+ if (geometry === null) continue;
552
+ const mesh = new THREE.Mesh(geometry, material);
553
+ mesh.name = `ambient-merged:${material.name}`;
554
+ merged.push(mesh);
555
+ }
556
+ for (const mesh of merged) model.add(mesh);
557
+ }
492
558
  const INPUT = {
493
559
  power: .8,
494
560
  pitch: 0,
@@ -565,7 +631,14 @@ var AmbientAircraft = class {
565
631
  return;
566
632
  }
567
633
  if (this.disposed) return;
568
- const visual = createAircraftVisual(model, spec);
634
+ mergeStaticAircraftParts(model, spec);
635
+ const visual = createAircraftVisual(model, {
636
+ ...spec,
637
+ visual: {
638
+ ...spec.visual,
639
+ interior: void 0
640
+ }
641
+ });
569
642
  visual.object.traverse((object) => {
570
643
  object.userData.walkIgnore = true;
571
644
  object.castShadow = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/molen-ambient",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,14 +42,14 @@
42
42
  ],
43
43
  "dependencies": {
44
44
  "zod": "^4.6.5",
45
- "@bendyline/molen-figures": "0.0.7",
46
- "@bendyline/molen-kernel": "0.0.5",
47
- "@bendyline/molen-schema": "0.0.5",
48
- "@bendyline/molen-terrain": "0.0.8"
45
+ "@bendyline/molen-kernel": "0.0.6",
46
+ "@bendyline/molen-terrain": "0.0.9",
47
+ "@bendyline/molen-schema": "0.0.6",
48
+ "@bendyline/molen-figures": "0.0.8"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "three": ">=0.184.0 <0.187.0",
52
- "@bendyline/molen-client": "0.0.7"
52
+ "@bendyline/molen-client": "0.0.8"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@bendyline/molen-client": {
@@ -67,7 +67,7 @@
67
67
  "tsdown": "^0.22.2",
68
68
  "typescript": "^6.0.3",
69
69
  "vitest": "^5.0.1",
70
- "@bendyline/molen-client": "0.0.7"
70
+ "@bendyline/molen-client": "0.0.8"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",