@preference-sl/pref-gltf-transform 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/README.md CHANGED
@@ -1,81 +1,102 @@
1
- # pref-gltf-transform
1
+ # @preference-sl/pref-gltf-transform
2
2
 
3
- Browser helper utilities built on top of **glTF Transform** that allow you to:
3
+ Helper utilities built on top of [glTF Transform](https://gltf-transform.dev/) to process glTF assets in the browser.
4
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
5
+ Features:
6
+ - **Download External References**: Fetch `.bin` buffers referenced by a `.gltf` file from a configurable backend.
7
+ - **Convert to GLB**: Pack a `.gltf` and its buffers into a single `.glb` file.
8
+ - **Caching**: Uses IndexedDB to cache large binary assets to avoid re-downloading.
8
9
 
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)
10
+ ## Installation
23
11
 
24
12
  ```bash
25
- npm install @gltf-transform/core @gltf-transform/extensions @gltf-transform/functions
26
-
27
- npm run build
13
+ npm install @preference-sl/pref-gltf-transform
28
14
  ```
29
15
 
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.
16
+ ## Usage
35
17
 
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.
18
+ ### 1. Import in Modern Bundlers (Vite, Webpack, etc.)
37
19
 
38
- - index.html defines a simple UI (inputs + buttons) and loads main.js as an ES module.
20
+ ```javascript
21
+ import {
22
+ downloadBinsReferencedByGltf,
23
+ generateGlbFromGltfAndBins
24
+ } from '@preference-sl/pref-gltf-transform';
39
25
 
40
- - main.js demonstrates how to call the library functions:
26
+ // ... usage
27
+ ```
41
28
 
42
- downloadBinsReferencedByGltf() � downloads external .bin buffers referenced by a .gltf
29
+ ### 2. Import in Browser (without bundler)
30
+
31
+ Browsers require an **Import Map** to resolve the package name if you are not using a build tool.
32
+
33
+ **index.html**:
34
+ ```html
35
+ <script type="importmap">
36
+ {
37
+ "imports": {
38
+ "@preference-sl/pref-gltf-transform": "./node_modules/@preference-sl/pref-gltf-transform/www/pref-gltf-transform.js"
39
+ }
40
+ }
41
+ </script>
42
+ <script type="module">
43
+ import { downloadBinsReferencedByGltf } from '@preference-sl/pref-gltf-transform';
44
+ </script>
45
+ ```
43
46
 
44
- generateGlbFromGltfAndBins() � generates a single .glb file from .gltf + downloaded buffers
47
+ ## API
45
48
 
46
- ---
49
+ ### `downloadBinsReferencedByGltf(gltfUrl, options)`
50
+ Crawls a `.gltf` file, finds referenced `.bin` files (via `KB_Key` extras), and downloads/caches them.
47
51
 
48
- ## Configuration
52
+ - **gltfUrl**: `string` - URL to the .gltf file.
53
+ - **options**: `{ myserverHost: string, useHttps?: boolean }`
54
+ - **Returns**: `Promise<{ results: Array }>`
49
55
 
50
- The module builds `.bin` download URLs in the form:
56
+ ### `generateGlbFromGltfAndBins(gltfUrl, options)`
57
+ Loads the `.gltf` and all cached `.bin` files, then packs them into a `.glb` blob.
51
58
 
52
- ```
53
- {protocol}://{myserverHost}/Files/{Maker}/{Type}/{uri}
54
- ```
59
+ - **Returns**: `Promise<string>` (The Blob URL of the generated .glb).
55
60
 
56
61
  ---
57
62
 
58
- ## Initialization
63
+ ## Development
64
+
65
+ If you want to contribute or modify this package:
59
66
 
60
- ```js
61
- await initPrefGltfTransform("./config.json");
67
+ ### Build
68
+ Compiles TypeScript to JavaScript (`www/pref-gltf-transform.js`) and generates types (`www/pref-gltf-transform.d.ts`).
62
69
 
63
- ./config.json - is in-memory configuration,
70
+ ```bash
71
+ npm run build
72
+ ```
64
73
 
74
+ ### Test
75
+ Runs the verification script in the `playground/` directory.
65
76
 
77
+ ```bash
78
+ npm test
66
79
  ```
67
80
 
68
- ---
81
+ ### Playground
82
+ A local test environment is available in `playground/`.
83
+ 1. Build the project: `npm run build`
84
+ 2. Pack it: `npm pack`
85
+ 3. Go to playground: `cd playground`
86
+ 4. Install tarball: `npm install ../preference-sl-pref-gltf-transform-1.0.0.tgz`
87
+ 5. Run server: `npx serve .`
69
88
 
70
- ## Quick Start
89
+ ## Publishing
71
90
 
72
- ```js
73
- await downloadBinsReferencedByGltf(gltfUrl);
74
- const blobUrl = await generateGlbFromGltfAndBins(gltfUrl);
75
- ```
91
+ 1. Increment version in `package.json`.
92
+ 2. Run the release script:
93
+ ```bash
94
+ npm run release
95
+ ```
76
96
 
77
- ---
97
+ The script will automatically:
98
+ - Run `npm run build`
99
+ - Publish to npm with public access
100
+ - Handle errors gracefully
78
101
 
79
- ## References
80
102
 
81
- - https://gltf-transform.dev
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preference-sl/pref-gltf-transform",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Web component to convert GLTF into GLB",
5
5
  "type": "module",
6
6
  "main": "./www/pref-gltf-transform.js",
@@ -19,7 +19,9 @@
19
19
  "scripts": {
20
20
  "build": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js",
21
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"
22
+ "build:watch": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js --watch",
23
+ "test": "cd playground && npm test",
24
+ "release": "node scripts/publish.js"
23
25
  },
24
26
  "devDependencies": {
25
27
  "@gltf-transform/core": "^4.3.0",
@@ -10251,7 +10251,7 @@ async function loadGltfJsonFromStorage(gltfUrl) {
10251
10251
  }
10252
10252
  function buildKbFileUrl(options, key) {
10253
10253
  const protocol = options.useHttps ? "https" : "http";
10254
- return `${protocol}://${options.myserverHost}/Files/${encodeURIComponent(key.maker)}/${encodeURIComponent(key.type)}/${encodeURIComponent(key.uri)}`;
10254
+ return `${protocol}://${options.myserverHost}/KB/${encodeURIComponent(key.maker)}/${encodeURIComponent(key.type)}/${encodeURIComponent(key.uri)}`;
10255
10255
  }
10256
10256
  async function ensureBinExists(options, key) {
10257
10257
  const storageKey = `${key.maker}::${key.type}::${key.uri}`;