@preference-sl/pref-gltf-transform 1.0.0 → 1.0.2
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 +72 -51
- package/package.json +4 -3
- package/www/pref-gltf-transform.js +1 -1
- package/www/pref-gltf-transform.d.ts +0 -37
package/README.md
CHANGED
|
@@ -1,81 +1,102 @@
|
|
|
1
|
-
# pref-gltf-transform
|
|
1
|
+
# @preference-sl/pref-gltf-transform
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Helper utilities built on top of [glTF Transform](https://gltf-transform.dev/) to process glTF assets in the browser.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
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 @
|
|
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
|
-
|
|
18
|
+
### 1. Import in Modern Bundlers (Vite, Webpack, etc.)
|
|
37
19
|
|
|
38
|
-
|
|
20
|
+
```javascript
|
|
21
|
+
import {
|
|
22
|
+
downloadBinsReferencedByGltf,
|
|
23
|
+
generateGlbFromGltfAndBins
|
|
24
|
+
} from '@preference-sl/pref-gltf-transform';
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
// ... usage
|
|
27
|
+
```
|
|
41
28
|
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
+
- **gltfUrl**: `string` - URL to the .gltf file.
|
|
53
|
+
- **options**: `{ myserverHost: string, useHttps?: boolean }`
|
|
54
|
+
- **Returns**: `Promise<{ results: Array }>`
|
|
49
55
|
|
|
50
|
-
|
|
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
|
-
##
|
|
63
|
+
## Development
|
|
64
|
+
|
|
65
|
+
If you want to contribute or modify this package:
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
### Build
|
|
68
|
+
Compiles TypeScript to JavaScript (`www/pref-gltf-transform.js`) and generates types (`www/pref-gltf-transform.d.ts`).
|
|
62
69
|
|
|
63
|
-
|
|
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
|
-
##
|
|
89
|
+
## Publishing
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Web component to convert GLTF into GLB",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./www/pref-gltf-transform.js",
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"build:watch": "esbuild src/pref-gltf-transform.ts --bundle --format=esm --target=es2022 --outfile=www/pref-gltf-transform.js --watch",
|
|
22
|
+
"test": "cd playground && npm test",
|
|
23
|
+
"release": "node scripts/publish.js"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@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}/
|
|
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}`;
|
|
@@ -1,37 +0,0 @@
|
|
|
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 {};
|