@plasius/gpu-shared 0.1.13 → 0.1.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +70 -3
  3. package/dist/{chunk-NCPJWLX3.js → chunk-2GM64LB6.js} +1 -9
  4. package/dist/{chunk-NCPJWLX3.js.map → chunk-2GM64LB6.js.map} +1 -1
  5. package/dist/chunk-6SOHFUOE.js +403 -0
  6. package/dist/chunk-6SOHFUOE.js.map +1 -0
  7. package/dist/{chunk-DABW627O.js → chunk-CH3ZS5TQ.js} +7 -1
  8. package/dist/chunk-CH3ZS5TQ.js.map +1 -0
  9. package/dist/chunk-DGUM43GV.js +11 -0
  10. package/dist/{chunk-DQX4DXBR.js → chunk-QVNRTWHB.js} +82 -6
  11. package/dist/chunk-QVNRTWHB.js.map +1 -0
  12. package/dist/dist-B5R2GZQR.js +1433 -0
  13. package/dist/dist-B5R2GZQR.js.map +1 -0
  14. package/dist/gltf-loader-B6VOWGBV.js +9 -0
  15. package/dist/index.cjs +2408 -5913
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +55 -5
  18. package/dist/index.js.map +1 -1
  19. package/dist/product-studio-runtime-BYVBUWIN.js +12 -0
  20. package/dist/product-studio-runtime-BYVBUWIN.js.map +1 -0
  21. package/dist/showcase-inline-assets-QRQKXGVX.js +8 -0
  22. package/dist/showcase-inline-assets-QRQKXGVX.js.map +1 -0
  23. package/dist/showcase-runtime-M6TEUYOG.js +3786 -0
  24. package/dist/showcase-runtime-M6TEUYOG.js.map +1 -0
  25. package/package.json +7 -10
  26. package/src/feature-flags.js +1 -0
  27. package/src/gltf-loader.js +14 -2
  28. package/src/index.d.ts +73 -1
  29. package/src/index.js +67 -0
  30. package/src/product-studio-runtime.js +466 -0
  31. package/src/showcase-runtime.js +875 -72
  32. package/dist/chunk-2FIFSBB4.js +0 -74
  33. package/dist/chunk-2FIFSBB4.js.map +0 -1
  34. package/dist/chunk-DABW627O.js.map +0 -1
  35. package/dist/chunk-DQX4DXBR.js.map +0 -1
  36. package/dist/gltf-loader-WAM23F37.js +0 -9
  37. package/dist/showcase-inline-assets-B7U7VX5H.js +0 -7
  38. package/dist/showcase-runtime-PN7N3FZY.js +0 -9164
  39. package/dist/showcase-runtime-PN7N3FZY.js.map +0 -1
  40. /package/dist/{gltf-loader-WAM23F37.js.map → chunk-DGUM43GV.js.map} +0 -0
  41. /package/dist/{showcase-inline-assets-B7U7VX5H.js.map → gltf-loader-B6VOWGBV.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasius/gpu-shared",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Shared browser-safe demo runtime and asset helpers for the Plasius gpu-* package family.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -33,7 +33,7 @@
33
33
  "demo": "python3 -m http.server --directory ..",
34
34
  "demo:example": "node demo/example.js",
35
35
  "generate:assets": "node scripts/generate-showcase-assets.mjs",
36
- "typecheck": "node --check src/index.js && node --check src/showcase-runtime.js && node --check src/gltf-loader.js && node --check demo/main.js",
36
+ "typecheck": "node --check src/index.js && node --check src/showcase-runtime.js && node --check src/gltf-loader.js && node --check src/product-studio-runtime.js && node --check demo/main.js",
37
37
  "audit:eslint": "eslint . --max-warnings=0",
38
38
  "audit:deps": "npm ls --all --omit=optional --omit=peer > /dev/null 2>&1 || true",
39
39
  "audit:npm": "npm audit --audit-level=high --omit=dev",
@@ -56,24 +56,21 @@
56
56
  ],
57
57
  "author": "Plasius LTD <development@plasius.co.uk>",
58
58
  "license": "Apache-2.0",
59
- "dependencies": {
60
- "@plasius/gpu-cloth": "^0.1.4",
61
- "@plasius/gpu-debug": "^0.1.5",
62
- "@plasius/gpu-fluid": "^0.1.4",
63
- "@plasius/gpu-lighting": "^0.1.16",
64
- "@plasius/gpu-performance": "^0.1.6",
65
- "@plasius/gpu-physics": "^0.1.13"
66
- },
67
59
  "peerDependencies": {
60
+ "@plasius/gpu-renderer": "^0.1.15",
68
61
  "@plasius/translations": "^1.0.17"
69
62
  },
70
63
  "peerDependenciesMeta": {
64
+ "@plasius/gpu-renderer": {
65
+ "optional": true
66
+ },
71
67
  "@plasius/translations": {
72
68
  "optional": true
73
69
  }
74
70
  },
75
71
  "devDependencies": {
76
72
  "@eslint/js": "^10.0.1",
73
+ "@plasius/gpu-lighting": "^0.1.19",
77
74
  "@plasius/translations": "^1.0.17",
78
75
  "c8": "^11.0.0",
79
76
  "eslint": "^10.3.0",
@@ -1 +1,2 @@
1
1
  export const GPU_SHOWCASE_REALISTIC_MODELS_FEATURE = "gpu_showcase_realistic_models_v1";
2
+ export const GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE = "gpu_showcase_product_studio_wavefront_v1";
@@ -139,6 +139,18 @@ function computeBounds(positions) {
139
139
  });
140
140
  }
141
141
 
142
+ function appendValues(target, values) {
143
+ for (let index = 0; index < values.length; index += 1) {
144
+ target.push(values[index]);
145
+ }
146
+ }
147
+
148
+ function appendIndicesWithOffset(target, values, vertexOffset) {
149
+ for (let index = 0; index < values.length; index += 1) {
150
+ target.push(values[index] + vertexOffset);
151
+ }
152
+ }
153
+
142
154
  function resolveBrowserRequestBaseUrl() {
143
155
  if (
144
156
  typeof document !== "undefined" &&
@@ -406,8 +418,8 @@ async function buildGltfModel(document, baseUrl) {
406
418
 
407
419
  for (const primitive of scene.primitives) {
408
420
  const vertexOffset = aggregatePositions.length / 3;
409
- aggregatePositions.push(...primitive.positions);
410
- aggregateIndices.push(...primitive.indices.map((index) => index + vertexOffset));
421
+ appendValues(aggregatePositions, primitive.positions);
422
+ appendIndicesWithOffset(aggregateIndices, primitive.indices, vertexOffset);
411
423
  }
412
424
 
413
425
  const color = scene.primitives[0]?.material?.color ?? { r: 0.56, g: 0.33, b: 0.22, a: 1 };
package/src/index.d.ts CHANGED
@@ -57,6 +57,23 @@ export type ShowcaseFocusMode =
57
57
  | "performance"
58
58
  | "debug";
59
59
 
60
+ export type ShowcaseDemoMode = "harbor" | "product-studio" | "product" | "studio" | "eames";
61
+
62
+ export interface ProductStudioMesh {
63
+ readonly id: number;
64
+ readonly positions: readonly number[];
65
+ readonly indices: readonly number[];
66
+ readonly normals?: readonly number[] | null;
67
+ readonly uvs?: readonly number[] | null;
68
+ readonly color: readonly number[];
69
+ readonly emission?: readonly number[];
70
+ readonly materialKind: string | number;
71
+ readonly materialRefId?: number;
72
+ readonly roughness?: number;
73
+ readonly metallic?: number;
74
+ readonly opacity?: number;
75
+ }
76
+
60
77
  export type GpuSharedTranslationValue =
61
78
  | string
62
79
  | number
@@ -137,7 +154,17 @@ export function createGpuSharedTranslator(
137
154
  ): (key: GpuSharedTranslationKey, args?: GpuSharedTranslationArgs) => string;
138
155
 
139
156
  export interface MountGpuShowcaseOptions {
157
+ __showcaseFeatureLoaders?: {
158
+ cloth?: () => Promise<unknown>;
159
+ fluid?: () => Promise<unknown>;
160
+ lighting?: () => Promise<unknown>;
161
+ performance?: () => Promise<unknown>;
162
+ debug?: () => Promise<unknown>;
163
+ physics?: () => Promise<unknown>;
164
+ };
140
165
  root?: HTMLElement;
166
+ demoMode?: ShowcaseDemoMode;
167
+ mode?: ShowcaseDemoMode;
141
168
  focus?: ShowcaseFocusMode | string;
142
169
  packageName?: string;
143
170
  title?: string;
@@ -145,6 +172,16 @@ export interface MountGpuShowcaseOptions {
145
172
  translate?: GpuSharedTranslate;
146
173
  captureMode?: boolean;
147
174
  renderScale?: number;
175
+ productAssetUrl?: string | URL;
176
+ assetUrl?: string | URL;
177
+ width?: number;
178
+ height?: number;
179
+ maxDepth?: number;
180
+ tileSize?: number;
181
+ samplesPerPixel?: number;
182
+ denoise?: boolean;
183
+ lightingPreset?: string;
184
+ lightingIntensity?: number;
148
185
  createState?: () => unknown;
149
186
  updateState?: (state: unknown, scene: Record<string, unknown>, dt: number) => unknown;
150
187
  describeState?: (state: unknown, scene: Record<string, unknown>) => Record<string, unknown> | null;
@@ -158,7 +195,30 @@ export interface MountGpuShowcaseResult {
158
195
  destroy(): void;
159
196
  }
160
197
 
198
+ export interface MountGpuProductStudioResult {
199
+ readonly state: Readonly<{
200
+ featureFlags: unknown;
201
+ modelName: string;
202
+ sourceTriangleCount: number;
203
+ meshCount: number;
204
+ geometryMode: string;
205
+ requiresTriangleMeshRenderer: boolean;
206
+ displayQuality: boolean;
207
+ requiresMeshBvhForDisplayQuality: boolean;
208
+ rendererStats: Record<string, unknown>;
209
+ }>;
210
+ readonly model: GltfModel;
211
+ readonly productModel: GltfModel;
212
+ readonly canvas: HTMLCanvasElement;
213
+ readonly renderer: unknown;
214
+ readonly meshes: readonly ProductStudioMesh[];
215
+ destroy(): void;
216
+ }
217
+
161
218
  export const showcaseFocusModes: readonly ShowcaseFocusMode[];
219
+ export const showcaseDemoModes: readonly ShowcaseDemoMode[];
220
+ export const GPU_SHOWCASE_REALISTIC_MODELS_FEATURE: "gpu_showcase_realistic_models_v1";
221
+ export const GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE: "gpu_showcase_product_studio_wavefront_v1";
162
222
 
163
223
  export function resolveShowcaseAssetUrl(
164
224
  baseUrlOrAssetName?: string | URL | ShowcaseAssetName,
@@ -167,6 +227,18 @@ export function resolveShowcaseAssetUrl(
167
227
 
168
228
  export function loadGltfModel(url: string | URL): Promise<GltfModel>;
169
229
 
230
+ export function createProductStudioMeshes(
231
+ model: GltfModel,
232
+ options?: {
233
+ targetCenter?: readonly number[];
234
+ targetSize?: number;
235
+ }
236
+ ): readonly ProductStudioMesh[];
237
+
238
+ export function mountGpuProductStudio(
239
+ options?: MountGpuShowcaseOptions
240
+ ): Promise<MountGpuProductStudioResult>;
241
+
170
242
  export function mountGpuShowcase(
171
243
  options?: MountGpuShowcaseOptions
172
- ): Promise<MountGpuShowcaseResult>;
244
+ ): Promise<MountGpuShowcaseResult | MountGpuProductStudioResult>;
package/src/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE,
3
+ GPU_SHOWCASE_REALISTIC_MODELS_FEATURE,
4
+ } from "./feature-flags.js";
5
+
1
6
  export { resolveShowcaseAssetUrl } from "./asset-url.js";
2
7
  export {
3
8
  createGpuSharedTranslator,
@@ -6,6 +11,14 @@ export {
6
11
  translateGpuSharedText,
7
12
  } from "./i18n.js";
8
13
  export { gpuSharedEnGbTranslations } from "./translations/en-GB.js";
14
+ export {
15
+ GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE,
16
+ GPU_SHOWCASE_REALISTIC_MODELS_FEATURE,
17
+ };
18
+ export {
19
+ createProductStudioMeshes,
20
+ mountGpuProductStudio,
21
+ } from "./product-studio-runtime.js";
9
22
 
10
23
  export const showcaseFocusModes = Object.freeze([
11
24
  "integrated",
@@ -16,13 +29,66 @@ export const showcaseFocusModes = Object.freeze([
16
29
  "performance",
17
30
  "debug",
18
31
  ]);
32
+ export const showcaseDemoModes = Object.freeze(["harbor", "product-studio"]);
19
33
 
20
34
  export async function loadGltfModel(url) {
21
35
  const module = await import("./gltf-loader.js");
22
36
  return module.loadGltfModel(url);
23
37
  }
24
38
 
39
+ function isProductStudioFeatureEnabled(featureFlags) {
40
+ if (typeof featureFlags?.get === "function") {
41
+ return featureFlags.get(GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE) === true;
42
+ }
43
+
44
+ const direct = featureFlags?.[GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE];
45
+ if (typeof direct === "boolean") {
46
+ return direct;
47
+ }
48
+
49
+ const flagsValue = featureFlags?.flags?.[GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE];
50
+ if (typeof flagsValue === "boolean") {
51
+ return flagsValue;
52
+ }
53
+
54
+ const enabledValue = featureFlags?.enabled?.[GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE];
55
+ if (typeof enabledValue === "boolean") {
56
+ return enabledValue;
57
+ }
58
+
59
+ return false;
60
+ }
61
+
25
62
  export async function mountGpuShowcase(options = {}) {
63
+ const demoMode = options.demoMode ?? options.mode;
64
+ if (
65
+ demoMode === "product-studio" ||
66
+ demoMode === "product" ||
67
+ demoMode === "studio" ||
68
+ demoMode === "eames"
69
+ ) {
70
+ if (!isProductStudioFeatureEnabled(options.__featureFlags)) {
71
+ throw new Error(
72
+ `${GPU_SHOWCASE_PRODUCT_STUDIO_FEATURE} must be enabled before Product Studio can mount.`
73
+ );
74
+ }
75
+
76
+ const productRuntimeLoader =
77
+ typeof options.__productRuntimeLoader === "function"
78
+ ? options.__productRuntimeLoader
79
+ : () => import("./product-studio-runtime.js");
80
+ const productModule = await productRuntimeLoader();
81
+ if (typeof productModule.mountGpuProductStudio !== "function") {
82
+ throw new Error("product runtime loader must provide mountGpuProductStudio.");
83
+ }
84
+
85
+ const productOptions = { ...options, demoMode };
86
+ delete productOptions.__runtimeLoader;
87
+ delete productOptions.__productRuntimeLoader;
88
+ delete productOptions.__featureFlags;
89
+ return productModule.mountGpuProductStudio(productOptions, options.__featureFlags);
90
+ }
91
+
26
92
  const runtimeLoader =
27
93
  typeof options.__runtimeLoader === "function"
28
94
  ? options.__runtimeLoader
@@ -34,6 +100,7 @@ export async function mountGpuShowcase(options = {}) {
34
100
 
35
101
  const publicOptions = { ...options };
36
102
  delete publicOptions.__runtimeLoader;
103
+ delete publicOptions.__productRuntimeLoader;
37
104
  delete publicOptions.__featureFlags;
38
105
  return module.mountGpuShowcase(publicOptions, options.__featureFlags);
39
106
  }