@threlte/gltf 0.0.4 → 1.0.0-next.0

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 ADDED
@@ -0,0 +1,13 @@
1
+ # @threlte/gltf
2
+
3
+ ## 1.0.0-next.0
4
+
5
+ ### Major Changes
6
+
7
+ - 3a5376e2: Adapted gltf package to Threlte 6 T syntax
8
+
9
+ ## 0.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 8520f65: useDraco bugfix
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@threlte/gltf",
3
- "version": "0.0.4",
3
+ "version": "1.0.0-next.0",
4
4
  "description": "GLTF to Threlte converter",
5
- "scripts": {
6
- "cleanup": "rm -rf node_modules"
7
- },
8
5
  "type": "module",
9
6
  "keywords": [
10
7
  "gltf",
@@ -65,5 +62,8 @@
65
62
  "*.{js,jsx,ts,tsx}": [
66
63
  "prettier --write"
67
64
  ]
65
+ },
66
+ "scripts": {
67
+ "cleanup": "rm -rf node_modules"
68
68
  }
69
- }
69
+ }
package/readme.md CHANGED
@@ -58,20 +58,20 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb
58
58
  -->
59
59
  <script>
60
60
  import { Group } from 'three'
61
- import { T, Three } from '@threlte/core'
61
+ import { T } from '@threlte/core'
62
62
  import { useGltf, useGltfAnimations } from '@threlte/extras'
63
63
 
64
64
  export const ref = new Group()
65
65
 
66
- const { gltf } = useGltf('/stacy.glb')
66
+ const gltf = useGltf('/stacy.glb')
67
67
  export const { actions, mixer } = useGltfAnimations(gltf, ref)
68
68
  </script>
69
69
 
70
70
  {#if $gltf}
71
- <Three type={ref} {...$$restProps}>
71
+ <T is={ref} {...$$restProps}>
72
72
  <T.Group name="Scene">
73
73
  <T.Group name="Stacy" rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
74
- <Three type={$gltf.nodes.mixamorigHips} />
74
+ <T is={$gltf.nodes.mixamorigHips} />
75
75
  <T.SkinnedMesh
76
76
  name="stacy"
77
77
  geometry={$gltf.nodes.stacy.geometry}
@@ -84,7 +84,7 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb
84
84
  </T.Group>
85
85
 
86
86
  <slot {ref} />
87
- </Three>
87
+ </T>
88
88
  {/if}
89
89
  ```
90
90
 
@@ -161,7 +161,7 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
161
161
  <script lang="ts">
162
162
  import type * as THREE from 'three'
163
163
  import { Group } from 'three'
164
- import { T, Three, type Props, type Events, type Slots } from '@threlte/core'
164
+ import { T, type Props, type Events, type Slots } from '@threlte/core'
165
165
  import { useGltf, useGltfAnimations } from '@threlte/extras'
166
166
 
167
167
  type $$Props = Props<THREE.Group>
@@ -179,15 +179,15 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
179
179
  materials: {}
180
180
  }
181
181
 
182
- const { gltf } = useGltf<GLTFResult>('/stacy.glb')
182
+ const gltf = useGltf<GLTFResult>('/stacy.glb')
183
183
  export const { actions, mixer } = useGltfAnimations<ActionName>(gltf, ref)
184
184
  </script>
185
185
 
186
186
  {#if $gltf}
187
- <Three type={ref} {...$$restProps}>
187
+ <T is={ref} {...$$restProps}>
188
188
  <T.Group name="Scene">
189
189
  <T.Group name="Stacy" rotation={[Math.PI / 2, 0, 0]} scale={0.01}>
190
- <Three type={$gltf.nodes.mixamorigHips} />
190
+ <T is={$gltf.nodes.mixamorigHips} />
191
191
  <T.SkinnedMesh
192
192
  name="stacy"
193
193
  geometry={$gltf.nodes.stacy.geometry}
@@ -200,7 +200,7 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
200
200
  </T.Group>
201
201
 
202
202
  <slot {ref} />
203
- </Three>
203
+ </T>
204
204
  {/if}
205
205
  ```
206
206
 
@@ -209,7 +209,7 @@ Command: npx gltfjsx@0.0.1 ./stacy.glb -t
209
209
  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:
210
210
 
211
211
  ```svelte
212
- const { gltf } = useGltf('/stacy.glb')
212
+ const gltf = useGltf('/stacy.glb')
213
213
  export const { actions, mixer } = useGltfAnimations(gltf, ref)
214
214
  ```
215
215
 
@@ -244,3 +244,7 @@ gltfLoader.load(url, (gltf) => {
244
244
  - [three](https://github.com/mrdoob/three.js/) (>= 122.x)
245
245
  - @threlte/core > 5.0.0
246
246
  - @threlte/core > 4.9.3
247
+
248
+ ## Credits
249
+
250
+ This tool started off as a fork of [gltfjsx](https://github.com/pmndrs/gltfjsx) by [pmndrs](https://pmnd.rs/).
@@ -374,7 +374,7 @@ function parse(fileName, gltf, options = {}) {
374
374
 
375
375
  // Bail out on lights and bones
376
376
  if (type === 'bone') {
377
- return `<Three type={$gltf.${node}} />\n`
377
+ return `<T is={$gltf.${node}} />\n`
378
378
  }
379
379
 
380
380
  // Collect children
@@ -456,6 +456,17 @@ function parse(fileName, gltf, options = {}) {
456
456
  // 2nd pass to eliminate hard to swat left-overs
457
457
  const scene = printThrelte(gltf.scene)
458
458
 
459
+ const useGltfOptions =
460
+ options.transform && options.draco
461
+ ? {
462
+ useDraco: options.draco
463
+ }
464
+ : options.transform
465
+ ? {
466
+ useDraco: true
467
+ }
468
+ : undefined
469
+
459
470
  // Output
460
471
  return `
461
472
  <!--
@@ -471,7 +482,7 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
471
482
 
472
483
  ${options.types ? `\nimport type * as THREE from 'three'` : ''}
473
484
  import { Group } from 'three'
474
- import { ${['T', 'Three', options.types ? 'type Props, type Events, type Slots' : ''].join(
485
+ import { ${['T', options.types ? 'type Props, type Events, type Slots' : ''].join(
475
486
  ', '
476
487
  )} } from '@threlte/core'
477
488
  import { ${['useGltf', hasAnimations ? 'useGltfAnimations' : ''].join(
@@ -486,12 +497,8 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
486
497
 
487
498
  ${options.types ? printThrelteTypes(objects, animations) : ''}
488
499
 
489
- const { gltf } = useGltf${options.types ? '<GLTFResult>' : ''}('${url}'${
490
- options.draco
491
- ? `, {
492
- useDraco: ${JSON.stringify(options.draco)},
493
- }`
494
- : ''
500
+ const gltf = useGltf${options.types ? '<GLTFResult>' : ''}('${url}'${
501
+ useGltfOptions ? `, ${JSON.stringify(useGltfOptions)}` : ''
495
502
  })
496
503
  ${
497
504
  hasAnimations
@@ -504,13 +511,13 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
504
511
  </script>
505
512
 
506
513
  {#if $gltf}
507
- <Three type={ref} {...$$restProps}>
514
+ <T is={ref} {...$$restProps}>
508
515
  ${scene}
509
516
 
510
517
  <slot {ref} />
511
- </Three>
512
- {/if}
513
- `
518
+ </T>
519
+ {/if}
520
+ `
514
521
  }
515
522
 
516
523
  export default parse
package/Arcade.glb DELETED
Binary file
package/Arcade.svelte DELETED
@@ -1,86 +0,0 @@
1
- <!--
2
- Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
3
- Command: npx @threlte/gltf@0.0.3 Arcade.glb
4
- -->
5
- <script>
6
- import { Group } from 'three'
7
- import { T, Three } from '@threlte/core'
8
- import { useGltf } from '@threlte/extras'
9
-
10
- export const ref = new Group()
11
-
12
- const { gltf } = useGltf('/Arcade.glb')
13
- </script>
14
-
15
- {#if $gltf}
16
- <Three type={ref} {...$$restProps}>
17
- <T.Mesh
18
- geometry={$gltf.nodes.Screen.geometry}
19
- material={$gltf.materials.Screen}
20
- position={[0, 1.38, 0.14]}
21
- scale={1.01}
22
- />
23
- <T.Mesh
24
- geometry={$gltf.nodes.BodyMesh.geometry}
25
- material={$gltf.materials['machine body main']}
26
- position={[0.28, 0, 0]}
27
- />
28
- <T.Mesh
29
- geometry={$gltf.nodes.LeftCover.geometry}
30
- material={$gltf.materials['machine body outer']}
31
- position={[0.3, 1.21, -0.13]}
32
- />
33
- <T.Mesh
34
- geometry={$gltf.nodes.RightCover.geometry}
35
- material={$gltf.materials['machine body outer']}
36
- position={[-0.3, 1.21, -0.13]}
37
- scale={[-1, 1, 1]}
38
- />
39
- <T.Mesh
40
- geometry={$gltf.nodes.ScreenFrame.geometry}
41
- material={$gltf.materials['screen frame']}
42
- position={[0.28, 0.06, 0.03]}
43
- />
44
- <T.Mesh
45
- geometry={$gltf.nodes.joystick_base.geometry}
46
- material={$gltf.materials['joystick base']}
47
- position={[0.13, 0.96, -0.2]}
48
- rotation={[-0.19, 0, 0]}
49
- />
50
- <T.Mesh
51
- geometry={$gltf.nodes.Main_Button_Enclosure.geometry}
52
- material={$gltf.materials['joystick base']}
53
- position={[-0.11, 0.98, -0.09]}
54
- rotation={[-0.18, 0, 0]}
55
- scale={0.94}
56
- >
57
- <T.Mesh
58
- geometry={$gltf.nodes.Main_Button.geometry}
59
- material={$gltf.materials['joystick cap']}
60
- position={[0, 0.01, 0]}
61
- rotation={[0.19, 0, 0]}
62
- scale={0.72}
63
- />
64
- </T.Mesh>
65
- <T.Mesh
66
- geometry={$gltf.nodes.joystick_stick_application.geometry}
67
- material={$gltf.materials['joystick base']}
68
- position={[0.13, 0.97, -0.2]}
69
- rotation={[-0.19, 0, 0]}
70
- >
71
- <T.Mesh
72
- geometry={$gltf.nodes.joystick_stick.geometry}
73
- material={$gltf.materials['joystick stick']}
74
- position={[0, -0.01, 0]}
75
- >
76
- <T.Mesh
77
- geometry={$gltf.nodes.joystick_cap.geometry}
78
- material={$gltf.materials['joystick cap']}
79
- position={[0, 0.11, 0]}
80
- />
81
- </T.Mesh>
82
- </T.Mesh>
83
-
84
- <slot {ref} />
85
- </Three>
86
- {/if}