@threlte/gltf 3.0.0-next.5 → 3.0.0-next.7
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/CHANGELOG.md +12 -0
- package/README.md +4 -2
- package/package.json +1 -1
- package/src/utils/parser.js +12 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 3.0.0-next.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 946e7a8: fix parser for animated assets
|
|
8
|
+
|
|
9
|
+
## 3.0.0-next.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 7a3281c: Split out gltf-related loaders into hooks for better tree shaking
|
|
14
|
+
|
|
3
15
|
## 3.0.0-next.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -286,8 +286,10 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
|
|
|
286
286
|
|
|
287
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:
|
|
288
288
|
|
|
289
|
-
```
|
|
290
|
-
const gltf = useGltf('/stacy.glb')
|
|
289
|
+
```ts
|
|
290
|
+
const gltf = useGltf('/stacy.glb')
|
|
291
|
+
|
|
292
|
+
export const {(actions, mixer)} = useGltfAnimations(gltf, ref)
|
|
291
293
|
```
|
|
292
294
|
|
|
293
295
|
If you want to play an animation you can do so at any time:
|
package/package.json
CHANGED
package/src/utils/parser.js
CHANGED
|
@@ -466,19 +466,13 @@ function parse(fileName, gltf, options = {}) {
|
|
|
466
466
|
// 2nd pass to eliminate hard to swat left-overs
|
|
467
467
|
const scene = printThrelte(gltf.scene)
|
|
468
468
|
|
|
469
|
-
const useGltfOptions =
|
|
470
|
-
options.transform && options.draco
|
|
471
|
-
|
|
472
|
-
useDraco: options.draco
|
|
473
|
-
}
|
|
474
|
-
: options.transform
|
|
475
|
-
? {
|
|
476
|
-
useDraco: true
|
|
477
|
-
}
|
|
478
|
-
: undefined
|
|
469
|
+
const useGltfOptions = {
|
|
470
|
+
draco: options.transform && options.draco ? (options.draco ? options.transform : true) : false
|
|
471
|
+
}
|
|
479
472
|
|
|
480
473
|
const imports = `
|
|
481
474
|
${options.types ? `\nimport type * as THREE from 'three'` : ''}
|
|
475
|
+
${hasAnimations ? `import { Group } from 'three'` : ''}
|
|
482
476
|
${options.types ? `import type { Snippet } from 'svelte'` : ''}
|
|
483
477
|
import { ${['T', options.types && !options.isolated ? 'type Props' : '']
|
|
484
478
|
.filter(Boolean)
|
|
@@ -486,7 +480,8 @@ function parse(fileName, gltf, options = {}) {
|
|
|
486
480
|
import { ${[
|
|
487
481
|
'useGltf',
|
|
488
482
|
hasAnimations ? 'useGltfAnimations' : '',
|
|
489
|
-
options.suspense ? 'useSuspense' : ''
|
|
483
|
+
options.suspense ? 'useSuspense' : '',
|
|
484
|
+
useGltfOptions.draco ? 'useDraco' : ''
|
|
490
485
|
]
|
|
491
486
|
.filter(Boolean)
|
|
492
487
|
.join(', ')} } from '@threlte/extras'
|
|
@@ -494,7 +489,7 @@ function parse(fileName, gltf, options = {}) {
|
|
|
494
489
|
|
|
495
490
|
const useGltf = `${options.suspense ? 'suspend(' : ''}useGltf${
|
|
496
491
|
options.types ? '<GLTFResult>' : ''
|
|
497
|
-
}('${url}'${useGltfOptions ? `, ${
|
|
492
|
+
}('${url}'${useGltfOptions.draco ? `, { dracoLoader: useDraco(${typeof useGltfOptions.draco === 'string' ? `'${useGltfOptions.draco}'` : ''}) }` : ''})${
|
|
498
493
|
options.suspense ? ')' : ''
|
|
499
494
|
}`
|
|
500
495
|
|
|
@@ -552,9 +547,12 @@ ${
|
|
|
552
547
|
|
|
553
548
|
${!options.preload && options.suspense ? 'const suspend = useSuspense()' : ''}
|
|
554
549
|
|
|
550
|
+
${hasAnimations && options.isolated ? 'const ref = new Group()' : hasAnimations ? 'ref = new Group()' : ''}
|
|
551
|
+
|
|
555
552
|
${options.types && !options.preload ? printThrelteTypes(objects, animations) : ''}
|
|
556
553
|
|
|
557
554
|
${!options.preload ? `const gltf = ${useGltf}` : 'const gltf = load()'}
|
|
555
|
+
|
|
558
556
|
${
|
|
559
557
|
hasAnimations
|
|
560
558
|
? `export const { actions, mixer } = useGltfAnimations${
|
|
@@ -564,7 +562,7 @@ ${
|
|
|
564
562
|
}
|
|
565
563
|
</script>
|
|
566
564
|
|
|
567
|
-
|
|
565
|
+
<${hasAnimations ? 'T is={ref}' : 'T.Group'} ${!hasAnimations && !options.isolated ? 'bind:ref' : ''} dispose={false} ${!options.isolated ? '{...props}' : ''}>
|
|
568
566
|
{#await gltf}
|
|
569
567
|
{@render fallback?.()}
|
|
570
568
|
{:then gltf}
|
|
@@ -574,7 +572,7 @@ ${
|
|
|
574
572
|
{/await}
|
|
575
573
|
|
|
576
574
|
{@render children?.(${options.isolated ? '' : '{ ref }'})}
|
|
577
|
-
|
|
575
|
+
</${hasAnimations ? 'T' : 'T.Group'}>
|
|
578
576
|
`
|
|
579
577
|
}
|
|
580
578
|
|