You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-14Lines changed: 30 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,8 +27,8 @@ With this plugin you get:
27
27
- ✅ Only the used models are bundled in the final product, not all included in your dev project.
28
28
- ⚠️ Detects and handles [Draco Compression](https://github.com/google/draco) during type generation automatically,
29
29
see [Draco Compression handling](#draco-compression-handling) below for more information.
30
-
- ✅ Works with glTF Seperate (`.gltf` + `.bin` + textures) and glTF Embedded (only `.gltf`) files,
31
-
see [glTF Versions and Representations](#gltf-versions-and-representations) below for more information.
30
+
- ✅ Works with glTF Seperate (`.gltf` + `.bin` + textures), glTF Embedded (only `.gltf`) and glTF Binary (`.glb`)
31
+
files, see [glTF Versions and Representations](#gltf-versions-and-representations) below for more information.
32
32
- ✅ ESM ready.
33
33
- ⚠️ Build tool & bundler agnostic thanks to [Unplugin](https://github.com/unjs/unplugin), so use it with your
34
34
favorite one, but see chapter
@@ -119,14 +119,16 @@ to different folders, changing paths, or adjusting how the model is handled afte
119
119
3. Start your dev to generate all files. With our example model we get:
120
120
121
121
```diff
122
-
@/assets/models/MyModel.gltf
123
-
@/assets/models/MyModel.bin
124
-
@/assets/models/MyModel-texture1.png
125
-
@/assets/models/MyModel-texture2.png
122
+
@/assets/models/MyModel.gltf
123
+
@/assets/models/MyModel.bin
124
+
@/assets/models/MyModel-texture1.png
125
+
@/assets/models/MyModel-texture2.png
126
126
+@/assets/models/MyModel.gltf.d.ts <- the typing
127
-
+@/assets/models/MyModel.gltf.js <- actual code with node get helper function and scene/ model graph representation
127
+
+@/assets/models/MyModel.gltf.js <- actual code with node get helper function and model graph representation
128
128
```
129
129
130
+
> Alternatively, you can run the script `gltf-codegen` supplied by the package to manually create those files. More details at [Binary scripts](#binary-scripts).
131
+
130
132
4. Import the type safe model in your code and use it, e.g.:
131
133
132
134
```ts
@@ -165,14 +167,14 @@ resulting in the following compatibility in our project:
165
167
166
168
## glTF Versions and Representations
167
169
168
-
(Legend: 🟢 Tested & Supported | 🟡 Not Yet Tested | 🔴 Not Supported)
| glTF 1.0 | Any | 🔴 | glTF 2.0 was introduced in 2017 with major improvements. Avoid using the outdated glTF 1.0 standard in your projects. |
173
-
| glTF 2.0 | Separate (`.gltf` + `.bin` + textures) | 🟢 | Recommended! Offers better performance, version control, caching, transferability, and debugging. |
174
-
| glTF 2.0 | Embedded (only `.gltf`) | 🟢 | Assets are embedded directly into the `.gltf` file as base64 encoded `data:` sources within the `uri` fields, making single-file management simpler. |
175
-
| glTF 2.0 | Binary (`.glb`) |🔴| Currently not supported because we scan JSON-encoded `.gltf`files for type generation and cannot yet process binary representations. Contributions welcome! ❤️ |
172
+
| glTF Version | File Representation | Status | Note |
| glTF 1.0 | Any | 🔴 | glTF 2.0 was introduced in 2017 with major improvements. Avoid using the outdated glTF 1.0 standard in your projects. |
175
+
| glTF 2.0 | Separate (`.gltf` + `.bin` + textures) | 🟢 | Recommended! Offers better performance, version control, caching, transferability, and debugging. |
176
+
| glTF 2.0 | Embedded (only `.gltf`) | 🟢 | Assets are embedded directly into the `.gltf` file as base64 encoded `data:` sources within the `uri` fields, making single-file management simpler. |
177
+
| glTF 2.0 | Binary (`.glb`) |🟡| Currently, only works with models that contain all referenced files in the binary chunk without external file references. Contributions welcome! ❤️|
176
178
177
179
## Draco Compression handling
178
180
@@ -210,6 +212,20 @@ const gltfLoader = new GLTFLoader().setDRACOLoader(dracoLoader)
210
212
exportdefaultgltfLoader
211
213
```
212
214
215
+
## Binary scripts
216
+
217
+
In addition to the commands in the `scripts` section of the `package.json`, this plugin also provides binary scripts.
218
+
219
+
Run them by adding this plugin to your project, be sure to have the dependencies installed and then
220
+
add `npx` or `pnpx` before the commands.
221
+
222
+
### `gltf-codegen [DIR]`
223
+
224
+
This script generates types and runtime code for all models found in `DIR` and sub-directories. `DIR` defaults to
225
+
the current directory.
226
+
227
+
Run `gltf-codegen --help` for more options and details.
228
+
213
229
## idea behind the scenes
214
230
215
231
On runtime it runs `useGLTF` under the hood. So no extra layer and therefore correct objects that
0 commit comments