@threlte/gltf 3.0.0-next.0 → 3.0.0-next.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/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "useTabs": false,
3
+ "singleQuote": true,
4
+ "trailingComma": "none",
5
+ "semi": false,
6
+ "printWidth": 100,
7
+ "plugins": ["prettier-plugin-svelte"],
8
+ "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
9
+ "singleAttributePerLine": true
10
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @threlte/gltf
2
2
 
3
+ ## 3.0.0-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 958c375: Fix T.Group parser error
8
+
9
+ ## 3.0.0-next.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 36128d5: Replace events with callback props and slots with snippets
14
+
3
15
  ## 3.0.0-next.0
4
16
 
5
17
  ### Major Changes
package/README.md CHANGED
@@ -116,9 +116,16 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb
116
116
  </script>
117
117
 
118
118
  {#if $gltf}
119
- <T is={ref} {...$$restProps}>
119
+ <T
120
+ is={ref}
121
+ {...$$restProps}
122
+ >
120
123
  <T.Group name="Scene">
121
- <T.Group name="Stacy" rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
124
+ <T.Group
125
+ name="Stacy"
126
+ rotation={[Math.PI / 2, 0, 0]}
127
+ scale={0.01}
128
+ >
122
129
  <T is={$gltf.nodes.mixamorigHips} />
123
130
  <T.SkinnedMesh
124
131
  name="stacy"
@@ -166,7 +173,11 @@ You can re-use it, it will re-use geometries and materials out of the box:
166
173
  Or make the model dynamic. Change its colors for example:
167
174
 
168
175
  ```svelte
169
- <T.Mesh geometry={$gltf.nodes.robot.geometry} material={$gltf.materials.metal} material.color="green" />
176
+ <T.Mesh
177
+ geometry={$gltf.nodes.robot.geometry}
178
+ material={$gltf.materials.metal}
179
+ material.color="green"
180
+ />
170
181
  ```
171
182
 
172
183
  Or exchange materials:
@@ -181,7 +192,10 @@ Make contents conditional:
181
192
 
182
193
  ```svelte
183
194
  {#if condition}
184
- <T.Mesh geometry={$gltf.nodes.robot.geometry} material={$gltf.materials.metal} />}
195
+ <T.Mesh
196
+ geometry={$gltf.nodes.robot.geometry}
197
+ material={$gltf.materials.metal}
198
+ />}
185
199
  {/if}
186
200
  ```
187
201
 
@@ -193,7 +207,7 @@ You don't need to do anything if your models are draco compressed, since `useGlt
193
207
 
194
208
  #### ⚡️ Auto-transform (compression, resize)
195
209
 
196
- With the `--transform` flag it creates a binary-packed, draco-compressed, texture-resized (1024x1024), webp compressed, deduped, instanced and pruned *.glb ready to be consumed on a web site. It uses [glTF-Transform](https://github.com/donmccurdy/glTF-Transform). This can reduce the size of an asset by 70%-90%.
210
+ With the `--transform` flag it creates a binary-packed, draco-compressed, texture-resized (1024x1024), webp compressed, deduped, instanced and pruned \*.glb ready to be consumed on a web site. It uses [glTF-Transform](https://github.com/donmccurdy/glTF-Transform). This can reduce the size of an asset by 70%-90%.
197
211
 
198
212
  It will not alter the original but create a copy and append `[modelname]-transformed.glb`.
199
213
 
@@ -218,7 +232,16 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
218
232
 
219
233
  export const ref = new Group()
220
234
 
221
- type ActionName = 'pockets' | 'rope' | 'swingdance' | 'jump' | 'react' | 'shrug' | 'wave' | 'golf' | 'idle'
235
+ type ActionName =
236
+ | 'pockets'
237
+ | 'rope'
238
+ | 'swingdance'
239
+ | 'jump'
240
+ | 'react'
241
+ | 'shrug'
242
+ | 'wave'
243
+ | 'golf'
244
+ | 'idle'
222
245
  type GLTFResult = {
223
246
  nodes: {
224
247
  stacy: THREE.SkinnedMesh
@@ -232,9 +255,16 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
232
255
  </script>
233
256
 
234
257
  {#if $gltf}
235
- <T is={ref} {...$$restProps}>
258
+ <T
259
+ is={ref}
260
+ {...$$restProps}
261
+ >
236
262
  <T.Group name="Scene">
237
- <T.Group name="Stacy" rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
263
+ <T.Group
264
+ name="Stacy"
265
+ rotation={[Math.PI / 2, 0, 0]}
266
+ scale={0.01}
267
+ >
238
268
  <T is={$gltf.nodes.mixamorigHips} />
239
269
  <T.SkinnedMesh
240
270
  name="stacy"
@@ -257,8 +287,7 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
257
287
  If your GLTF contains animations it will add [@threlte/extras's `useGltfAnimations`](https://threlte.xyz/extras/use-gltf-animations) hook, which extracts all clips and prepares them as actions:
258
288
 
259
289
  ```svelte
260
- const gltf = useGltf('/stacy.glb')
261
- export const { actions, mixer } = useGltfAnimations(gltf, ref)
290
+ const gltf = useGltf('/stacy.glb') export const {(actions, mixer)} = useGltfAnimations(gltf, ref)
262
291
  ```
263
292
 
264
293
  If you want to play an animation you can do so at any time:
@@ -285,7 +314,6 @@ gltfLoader.load(url, (gltf) => {
285
314
  })
286
315
  ```
287
316
 
288
-
289
317
  ## Contributing
290
318
 
291
319
  Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/gltf",
3
- "version": "3.0.0-next.0",
3
+ "version": "3.0.0-next.2",
4
4
  "description": "GLTF to Threlte converter",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -66,6 +66,8 @@
66
66
  ]
67
67
  },
68
68
  "scripts": {
69
- "cleanup": "rimraf node_modules"
69
+ "cleanup": "rimraf node_modules",
70
+ "lint": "prettier --check .",
71
+ "format": "prettier --write ."
70
72
  }
71
73
  }
@@ -1,4 +1,4 @@
1
1
  const THREE = (global.THREE = require('three'))
2
2
  require('../bin/GLTFLoader')
3
3
 
4
- module.exports = THREE.GLTFLoader
4
+ module.exports = THREE.GLTFLoader
@@ -473,10 +473,8 @@ function parse(fileName, gltf, options = {}) {
473
473
 
474
474
  const imports = `
475
475
  ${options.types ? `\nimport type * as THREE from 'three'` : ''}
476
- import { ${[
477
- 'T',
478
- options.types && !options.isolated ? 'type Props, type Events, type Slots' : ''
479
- ]
476
+ ${options.stype && !options.isolated ? `import type { Snippet } from 'svelte'` : ''}
477
+ import { ${['T', options.types && !options.isolated ? 'type Props' : '']
480
478
  .filter(Boolean)
481
479
  .join(', ')} } from '@threlte/core'
482
480
  import { ${[
@@ -507,7 +505,6 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
507
505
  ${
508
506
  options.preload
509
507
  ? `
510
-
511
508
  <script context="module"${options.types ? ' lang="ts"' : ''}>
512
509
  ${imports}
513
510
 
@@ -530,17 +527,22 @@ ${
530
527
  <script${options.types ? ' lang="ts"' : ''}>
531
528
  ${!options.preload ? imports : ''}
532
529
 
533
- ${options.types && !options.isolated ? 'type $$Events = Events<THREE.Group>' : ''}
534
- ${
535
- options.types && !options.isolated
536
- ? 'type $$Slots = Slots<THREE.Group> & { fallback: {}; error: { error: any } }'
537
- : ''
538
- }
539
-
540
530
  let {
541
531
  ref = $bindable(),
532
+ fallback,
533
+ error,
534
+ children,
542
535
  ...props
543
- }${options.types && !options.isolated ? ': Props<THREE.Group>' : ''} = $props()
536
+ }${
537
+ options.types && !options.isolated
538
+ ? `: Props<THREE.Group> & {
539
+ ref?: THREE.Group
540
+ children?: Snippet<[{ ref: THREE.Group }]>
541
+ fallback?: Snippet
542
+ error?: Snippet<[{ error: Error }]>
543
+ }`
544
+ : ''
545
+ } = $props()
544
546
 
545
547
  ${!options.preload && options.suspense ? 'const suspend = useSuspense()' : ''}
546
548
 
@@ -558,15 +560,15 @@ ${
558
560
 
559
561
  <T.Group bind:ref dispose={false} ${!options.isolated ? '{...props}' : ''}>
560
562
  {#await gltf}
561
- <slot name="fallback" />
563
+ {@render fallback?.()}
562
564
  {:then gltf}
563
565
  ${scene}
564
566
  {:catch error}
565
- <slot name="error" {error} />
567
+ {@render error?.({ error })}
566
568
  {/await}
567
569
 
568
- <slot {ref} />
569
- </T>
570
+ {@render children?.({ ref })}
571
+ </T.Group>
570
572
  `
571
573
  }
572
574
 
@@ -1,5 +1,13 @@
1
1
  import { NodeIO } from '@gltf-transform/core'
2
- import { simplify, weld, dedup, resample, prune, textureCompress, draco } from '@gltf-transform/functions'
2
+ import {
3
+ simplify,
4
+ weld,
5
+ dedup,
6
+ resample,
7
+ prune,
8
+ textureCompress,
9
+ draco
10
+ } from '@gltf-transform/functions'
3
11
  import { ALL_EXTENSIONS } from '@gltf-transform/extensions'
4
12
  import { MeshoptDecoder, MeshoptEncoder, MeshoptSimplifier } from 'meshoptimizer'
5
13
  import draco3d from 'draco3dgltf'
@@ -12,7 +20,7 @@ async function transform(file, output, config = {}) {
12
20
  'draco3d.decoder': await draco3d.createDecoderModule(),
13
21
  'draco3d.encoder': await draco3d.createEncoderModule(),
14
22
  'meshopt.decoder': MeshoptDecoder,
15
- 'meshopt.encoder': MeshoptEncoder,
23
+ 'meshopt.encoder': MeshoptEncoder
16
24
  })
17
25
 
18
26
  const document = await io.read(file)
@@ -28,7 +36,7 @@ async function transform(file, output, config = {}) {
28
36
  // Resize and convert textures (using webp and sharp)
29
37
  textureCompress({ targetFormat: 'webp', encoder: sharp, resize: [resolution, resolution] }),
30
38
  // Add Draco compression.
31
- draco(),
39
+ draco()
32
40
  ]
33
41
 
34
42
  if (config.simplify) {
@@ -36,7 +44,11 @@ async function transform(file, output, config = {}) {
36
44
  // Weld vertices
37
45
  weld({ tolerance: config.weld ?? 0.0001 }),
38
46
  // Simplify meshes
39
- simplify({ simplifier: MeshoptSimplifier, ratio: config.ratio ?? 0.75, error: config.error ?? 0.001 })
47
+ simplify({
48
+ simplifier: MeshoptSimplifier,
49
+ ratio: config.ratio ?? 0.75,
50
+ error: config.error ?? 0.001
51
+ })
40
52
  )
41
53
  }
42
54