@plasius/gpu-shared 1.0.0 → 1.0.1

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/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  gpuSharedTranslationKeys,
12
12
  gpuSharedTranslations,
13
13
  translateGpuSharedText
14
- } from "./chunk-CH3ZS5TQ.js";
14
+ } from "./chunk-Z6SOXBHL.js";
15
15
  import {
16
16
  resolveShowcaseAssetUrl
17
17
  } from "./chunk-KGKLNL4X.js";
@@ -70,7 +70,7 @@ async function mountGpuShowcase(options = {}) {
70
70
  delete productOptions.__featureFlags;
71
71
  return productModule.mountGpuProductStudio(productOptions, options.__featureFlags);
72
72
  }
73
- const runtimeLoader = typeof options.__runtimeLoader === "function" ? options.__runtimeLoader : () => import("./showcase-runtime-INRAPCXW.js");
73
+ const runtimeLoader = typeof options.__runtimeLoader === "function" ? options.__runtimeLoader : () => import("./showcase-runtime-B544T6AM.js");
74
74
  const module = await runtimeLoader();
75
75
  if (typeof module.mountGpuShowcase !== "function") {
76
76
  throw new Error("showcase runtime loader must provide mountGpuShowcase.");
@@ -2,7 +2,7 @@ import {
2
2
  GPU_SHOWCASE_REALISTIC_MODELS_FEATURE,
3
3
  createGpuSharedTranslator,
4
4
  gpuSharedTranslationKeys
5
- } from "./chunk-CH3ZS5TQ.js";
5
+ } from "./chunk-Z6SOXBHL.js";
6
6
  import {
7
7
  loadGltfModel,
8
8
  resolveShowcaseAssetUrl
@@ -1471,42 +1471,74 @@ function buildTrianglesFromMesh(mesh, transform, colorOverride, camera, viewport
1471
1471
  }
1472
1472
  }
1473
1473
  }
1474
- async function loadShowcaseAssetCatalog() {
1475
- const [brigantine, cutter, lighthouse, harborDock, shoreline] = await Promise.all([
1474
+ function createShowcaseAssetCatalog({
1475
+ mode,
1476
+ ships,
1477
+ environment,
1478
+ primaryShipKey = "brigantine",
1479
+ fallbackReason = null
1480
+ }) {
1481
+ return Object.freeze({
1482
+ mode,
1483
+ primaryShipKey,
1484
+ ships: Object.freeze(ships),
1485
+ environment: Object.freeze(environment),
1486
+ fallbackReason
1487
+ });
1488
+ }
1489
+ function normalizeAssetCatalogFailureReason(error) {
1490
+ if (typeof error?.message === "string" && error.message.trim().length > 0) {
1491
+ return error.message;
1492
+ }
1493
+ return "showcase asset loading failed";
1494
+ }
1495
+ async function loadShowcaseAssetCatalog({ includeSecondaryShip = true } = {}) {
1496
+ const [brigantine, lighthouse, harborDock, shoreline] = await Promise.all([
1476
1497
  loadGltfModel(resolveShowcaseAssetUrl("brigantine")),
1477
- loadGltfModel(resolveShowcaseAssetUrl("cutter")),
1478
1498
  loadGltfModel(resolveShowcaseAssetUrl("lighthouse")),
1479
1499
  loadGltfModel(resolveShowcaseAssetUrl("harbor-dock")),
1480
1500
  loadGltfModel(resolveShowcaseAssetUrl("shoreline"))
1481
1501
  ]);
1482
- return Object.freeze({
1483
- primaryShipKey: "brigantine",
1484
- ships: Object.freeze({
1485
- brigantine,
1486
- cutter
1487
- }),
1488
- environment: Object.freeze({
1502
+ const ships = {
1503
+ brigantine
1504
+ };
1505
+ if (includeSecondaryShip) {
1506
+ ships.cutter = await loadGltfModel(resolveShowcaseAssetUrl("cutter"));
1507
+ }
1508
+ return createShowcaseAssetCatalog({
1509
+ mode: includeSecondaryShip ? "modeled-rich" : "modeled-baseline",
1510
+ ships,
1511
+ environment: {
1489
1512
  lighthouse,
1490
1513
  "harbor-dock": harborDock,
1491
1514
  shoreline
1492
- })
1515
+ }
1493
1516
  });
1494
1517
  }
1495
- function createLegacyShowcaseAssetCatalog() {
1496
- const brigantine = loadGltfModel(resolveShowcaseAssetUrl("brigantine"));
1497
- return Promise.resolve(brigantine).then(
1498
- (primary) => Object.freeze({
1499
- primaryShipKey: "brigantine",
1500
- ships: Object.freeze({
1501
- brigantine: primary
1502
- }),
1503
- environment: Object.freeze({})
1504
- })
1505
- );
1518
+ async function createLegacyShowcaseAssetCatalog(error = null) {
1519
+ const brigantine = await loadGltfModel(resolveShowcaseAssetUrl("brigantine"));
1520
+ return createShowcaseAssetCatalog({
1521
+ mode: "legacy-fallback",
1522
+ ships: {
1523
+ brigantine
1524
+ },
1525
+ environment: {},
1526
+ fallbackReason: normalizeAssetCatalogFailureReason(error)
1527
+ });
1528
+ }
1529
+ async function loadShowcaseAssetCatalogWithFallback({ includeSecondaryShip = true } = {}) {
1530
+ try {
1531
+ return await loadShowcaseAssetCatalog({ includeSecondaryShip });
1532
+ } catch (error) {
1533
+ return createLegacyShowcaseAssetCatalog(error);
1534
+ }
1506
1535
  }
1507
1536
  function resolveShipModel(state, ship, fallbackModel = null) {
1508
1537
  return state.assetCatalog?.ships?.[ship.modelKey ?? state.assetCatalog?.primaryShipKey ?? "brigantine"] ?? fallbackModel ?? state.shipModel;
1509
1538
  }
1539
+ function hasModeledHarborEnvironment(state) {
1540
+ return Object.keys(state.assetCatalog?.environment ?? {}).length > 0;
1541
+ }
1510
1542
  function createPerformanceGovernor(performanceFeatures) {
1511
1543
  const createQualityLadderAdapter = assertRequiredFunction(
1512
1544
  performanceFeatures,
@@ -2659,7 +2691,7 @@ function renderProjectedShadow(ctx, worldPoints, camera, viewport, lightDir, opt
2659
2691
  ctx.restore();
2660
2692
  }
2661
2693
  function pushHarborGeometry(camera, viewport, triangles, state) {
2662
- if (!state.showcaseRealisticModelsEnabled) {
2694
+ if (!hasModeledHarborEnvironment(state)) {
2663
2695
  for (const object of LEGACY_HARBOR_LAYOUT) {
2664
2696
  buildTrianglesFromMesh(
2665
2697
  { positions: [object], indices: [0], normals: null, colors: null, material: createLegacyMeshPrimitive({})?.material, bounds: null, name: "legacy-structure" },
@@ -3415,7 +3447,7 @@ function renderLighthouseBeam(ctx, state, camera, viewport, visuals) {
3415
3447
  const lighthousePlacement = SHOWCASE_ENVIRONMENT_LAYOUT.find(
3416
3448
  (placement) => placement.assetKey === "lighthouse"
3417
3449
  );
3418
- if (!lighthousePlacement || !state.showcaseRealisticModelsEnabled) {
3450
+ if (!lighthousePlacement || !state.showcaseRealisticModelsEnabled || !hasModeledHarborEnvironment(state)) {
3419
3451
  return;
3420
3452
  }
3421
3453
  const source = transformPoint(
@@ -3751,7 +3783,7 @@ function renderScene(ctx, canvas, state, shipModel, dom, lightingFeatures, fluid
3751
3783
  };
3752
3784
  const sceneMetrics = [
3753
3785
  `focus: ${state.focus}`,
3754
- `ships: ${state.ships.length} active GLTF hulls across ${new Set(state.ships.map((ship) => ship.modelKey)).size} model families`,
3786
+ `ships: ${state.ships.length} active GLTF hulls across ${new Set(state.ships.map((ship) => resolveShipModel(state, ship, shipModel)?.name ?? ship.modelKey)).size} model families`,
3755
3787
  `moonlight: cold overhead key + ${HARBOR_TORCHES.length + state.ships.reduce((total, ship) => total + (Array.isArray(ship.lanterns) ? ship.lanterns.length : 0), 0)} warm deck and harbor lights`,
3756
3788
  `physics snapshot: ${state.physics.snapshot.stage} (${state.physics.snapshot.stability})`,
3757
3789
  `physics contacts: ${state.contactCount}`,
@@ -3829,17 +3861,28 @@ function syncTextState(state, shipModel, featureAdapters) {
3829
3861
  coordinateSystem: "right-handed world; +x right, +y up, +z forward from the shore",
3830
3862
  focus: state.focus,
3831
3863
  stress: state.stress,
3832
- ships: state.ships.map((ship) => ({
3833
- id: ship.id,
3834
- modelKey: ship.modelKey ?? "brigantine",
3835
- x: Number(ship.position.x.toFixed(2)),
3836
- y: Number(ship.position.y.toFixed(2)),
3837
- z: Number(ship.position.z.toFixed(2)),
3838
- vx: Number(ship.velocity.x.toFixed(2)),
3839
- vz: Number(ship.velocity.z.toFixed(2)),
3840
- massKg: Math.round(getShipMass(ship, resolveShipModel(state, ship, shipModel))),
3841
- lanterns: Array.isArray(ship.lanterns) ? ship.lanterns.length : 0
3842
- })),
3864
+ ships: state.ships.map((ship) => {
3865
+ const resolvedShipModel = resolveShipModel(state, ship, shipModel);
3866
+ return {
3867
+ id: ship.id,
3868
+ modelKey: ship.modelKey ?? "brigantine",
3869
+ resolvedModelKey: resolvedShipModel?.name ?? ship.modelKey ?? "brigantine",
3870
+ x: Number(ship.position.x.toFixed(2)),
3871
+ y: Number(ship.position.y.toFixed(2)),
3872
+ z: Number(ship.position.z.toFixed(2)),
3873
+ vx: Number(ship.velocity.x.toFixed(2)),
3874
+ vz: Number(ship.velocity.z.toFixed(2)),
3875
+ massKg: Math.round(getShipMass(ship, resolvedShipModel)),
3876
+ lanterns: Array.isArray(ship.lanterns) ? ship.lanterns.length : 0
3877
+ };
3878
+ }),
3879
+ assetCatalog: {
3880
+ mode: state.assetCatalog?.mode ?? "unknown",
3881
+ shipKeys: Object.keys(state.assetCatalog?.ships ?? {}).sort(),
3882
+ environmentKeys: Object.keys(state.assetCatalog?.environment ?? {}).sort(),
3883
+ fallbackReason: state.assetCatalog?.fallbackReason ?? null,
3884
+ requestedRealisticModels: state.showcaseRealisticModelsEnabled
3885
+ },
3843
3886
  shipPhysics: Object.fromEntries(
3844
3887
  state.ships.map((ship) => [ship.id, resolveShipModel(state, ship, shipModel)?.physics ?? null])
3845
3888
  ),
@@ -3896,7 +3939,9 @@ async function mountGpuShowcase(options = {}, featureFlags = null) {
3896
3939
  },
3897
3940
  featureAdapters
3898
3941
  );
3899
- const assetCatalog = await (state.showcaseRealisticModelsEnabled ? loadShowcaseAssetCatalog() : createLegacyShowcaseAssetCatalog());
3942
+ const assetCatalog = await loadShowcaseAssetCatalogWithFallback({
3943
+ includeSecondaryShip: state.showcaseRealisticModelsEnabled
3944
+ });
3900
3945
  const shipModel = assetCatalog.ships[assetCatalog.primaryShipKey];
3901
3946
  state.assetCatalog = assetCatalog;
3902
3947
  state.shipModel = shipModel;
@@ -4045,4 +4090,4 @@ export {
4045
4090
  mountGpuShowcase,
4046
4091
  showcaseFocusModes
4047
4092
  };
4048
- //# sourceMappingURL=showcase-runtime-INRAPCXW.js.map
4093
+ //# sourceMappingURL=showcase-runtime-B544T6AM.js.map