@preference-sl/pref-gltf-transform 1.0.0

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/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # pref-gltf-transform
2
+
3
+ Browser helper utilities built on top of **glTF Transform** that allow you to:
4
+
5
+ - Download all external `.bin` buffers referenced by a `.gltf`
6
+ - Pack a `.gltf` + its `.bin` buffers into a single `.glb`
7
+ - Return a **Blob URL** that can be downloaded in the browser
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - Browser-compatible (`fetch`, `Blob`, `URL.createObjectURL`)
14
+ - Uses glTF Transform `WebIO`
15
+ - Supports embedded `data:` buffer URIs
16
+ - Downloads external buffers via configurable backend endpoint
17
+ - In-memory caching for glTF JSON and buffers
18
+ - Applies `unpartition()` before GLB generation
19
+
20
+ ---
21
+
22
+ ## Installation (in case of pref-gltf-transform.ts)
23
+
24
+ ```bash
25
+ npm install @gltf-transform/core @gltf-transform/extensions @gltf-transform/functions
26
+
27
+ npm run build
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Integration (in case of pref-gltf-transform.js)
33
+
34
+ Make sure the compiled file pref-gltf-transform.js is available in your hosted folder.
35
+
36
+ The files index.html and main.js are provided as a working example of how to integrate pref-gltf-transform.js in a browser environment.
37
+
38
+ - index.html defines a simple UI (inputs + buttons) and loads main.js as an ES module.
39
+
40
+ - main.js demonstrates how to call the library functions:
41
+
42
+ downloadBinsReferencedByGltf() � downloads external .bin buffers referenced by a .gltf
43
+
44
+ generateGlbFromGltfAndBins() � generates a single .glb file from .gltf + downloaded buffers
45
+
46
+ ---
47
+
48
+ ## Configuration
49
+
50
+ The module builds `.bin` download URLs in the form:
51
+
52
+ ```
53
+ {protocol}://{myserverHost}/Files/{Maker}/{Type}/{uri}
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Initialization
59
+
60
+ ```js
61
+ await initPrefGltfTransform("./config.json");
62
+
63
+ ./config.json - is in-memory configuration,
64
+
65
+
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Quick Start
71
+
72
+ ```js
73
+ await downloadBinsReferencedByGltf(gltfUrl);
74
+ const blobUrl = await generateGlbFromGltfAndBins(gltfUrl);
75
+ ```
76
+
77
+ ---
78
+
79
+ ## References
80
+
81
+ - https://gltf-transform.dev
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@preference-sl/pref-gltf-transform",
3
+ "version": "1.0.0",
4
+ "description": "Web component to convert GLTF into GLB",
5
+ "type": "module",
6
+ "main": "./www/pref-gltf-transform.js",
7
+ "module": "./www/pref-gltf-transform.js",
8
+ "types": "./www/pref-gltf-transform.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./www/pref-gltf-transform.d.ts",
12
+ "import": "./www/pref-gltf-transform.js",
13
+ "require": "./www/pref-gltf-transform.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "www"
18
+ ],
19
+ "scripts": {
20
+ "build": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js",
21
+ "prebuild": "tsc --emitDeclarationOnly",
22
+ "build:watch": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js --watch"
23
+ },
24
+ "devDependencies": {
25
+ "@gltf-transform/core": "^4.3.0",
26
+ "@gltf-transform/extensions": "^4.3.0",
27
+ "@gltf-transform/functions": "^4.3.0",
28
+ "esbuild": "^0.27.3",
29
+ "marked": "^17.0.1",
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }
@@ -0,0 +1,37 @@
1
+ export type PrefGltfTransformConfig = {
2
+ myserverHost: string;
3
+ useHttps?: boolean;
4
+ protocol?: "http" | "https";
5
+ };
6
+ type Options = {
7
+ myserverHost: string;
8
+ useHttps: boolean;
9
+ };
10
+ /**
11
+ * Provide config directly (called by main.js on page load).
12
+ */
13
+ export declare function setPrefGltfTransformConfig(cfg: PrefGltfTransformConfig): void;
14
+ /**
15
+ * Load config from a JSON URL (called by main.js on page load).
16
+ * Example config.json:
17
+ * {
18
+ * "protocol": "https",
19
+ * "myserverHost": "example.com:8443"
20
+ * }
21
+ */
22
+ export declare function initPrefGltfTransform(configJsonUrl: string): Promise<void>;
23
+ /**
24
+ * Same logic as your main.ts, but:
25
+ * - no UI refs
26
+ * - options optional if config was initialized via initPrefGltfTransform()/setPrefGltfTransformConfig()
27
+ */
28
+ export declare function downloadBinsReferencedByGltf(gltfUrl: string, options?: Options): Promise<{
29
+ results: Array<Record<string, unknown>>;
30
+ }>;
31
+ /**
32
+ * Same logic as your main.ts, but returns blobUrl:
33
+ * const blob = new Blob([glbBytes], { type: "model/gltf-binary" });
34
+ * return URL.createObjectURL(blob);
35
+ */
36
+ export declare function generateGlbFromGltfAndBins(gltfUrl: string, options?: Options): Promise<string>;
37
+ export {};