@threlte/gltf 3.0.0-next.1 → 3.0.0-next.3

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.3
4
+
5
+ ### Patch Changes
6
+
7
+ - bb726da: fix prettier formatting
8
+
9
+ ## 3.0.0-next.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 958c375: Fix T.Group parser error
14
+
3
15
  ## 3.0.0-next.1
4
16
 
5
17
  ### Patch 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.1",
3
+ "version": "3.0.0-next.3",
4
4
  "description": "GLTF to Threlte converter",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -39,10 +39,10 @@
39
39
  "jsdom-global": "^3.0.2",
40
40
  "meow": "^11.0.0",
41
41
  "meshoptimizer": "^0.18.1",
42
- "prettier": "^2.8.3",
43
- "prettier-plugin-svelte": "^2.9.0",
42
+ "prettier": "^3.2.5",
43
+ "prettier-plugin-svelte": "^3.2.2",
44
44
  "sharp": "^0.32.0",
45
- "svelte": "^3.55.1",
45
+ "svelte": "5.0.0-next.133",
46
46
  "three": "0.122.0",
47
47
  "three-stdlib": "^2.21.8"
48
48
  },
@@ -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
  }
package/src/index.js CHANGED
@@ -51,17 +51,18 @@ export default function (file, output, options) {
51
51
  gltfLoader.parse(
52
52
  arrayBuffer,
53
53
  '',
54
- (gltf) => {
54
+ async (gltf) => {
55
55
  const raw = parse(filePath, gltf, options)
56
56
  try {
57
- const prettiered = prettier.format(raw, {
58
- semi: false,
59
- bracketSameLine: true,
60
- svelteBracketNewLine: false,
61
- printWidth: options.printwidth || 120,
62
- svelteBracketNewLine: true,
57
+ const prettiered = await prettier.format(raw, {
63
58
  singleQuote: true,
64
- parser: 'svelte'
59
+ trailingComma: 'none',
60
+ semi: false,
61
+ printWidth: 100,
62
+ parser: 'svelte',
63
+ plugins: ['prettier-plugin-svelte'],
64
+ overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }],
65
+ singleAttributePerLine: true
65
66
  })
66
67
  stream.write(prettiered)
67
68
  stream.end()
@@ -0,0 +1,22 @@
1
+ export type Options = {
2
+ output?: string
3
+ types?: boolean
4
+ keepnames?: boolean
5
+ keepgroups?: boolean
6
+ shadows?: boolean
7
+ printwidth?: number
8
+ meta?: boolean
9
+ precision?: number
10
+ isolated?: boolean
11
+ preload?: boolean
12
+ suspense?: boolean
13
+ draco?: string
14
+ root?: string
15
+ transform?: boolean
16
+ resolution?: number
17
+ simplify?: boolean
18
+ weld?: number
19
+ ratio?: number
20
+ error?: number
21
+ debug?: boolean
22
+ }
@@ -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
@@ -1,6 +1,12 @@
1
1
  import THREE from 'three'
2
2
  import isVarName from './isVarName.js'
3
3
 
4
+ /**
5
+ * @param {string} fileName
6
+ * @param {import('three/examples/jsm/loaders/GLTFLoader').GLTF} gltf
7
+ * @param {import('./Options.d.ts').Options} options
8
+ * @returns {string}
9
+ */
4
10
  function parse(fileName, gltf, options = {}) {
5
11
  const url = fileName
6
12
  const animations = gltf.animations
@@ -466,18 +472,15 @@ function parse(fileName, gltf, options = {}) {
466
472
  useDraco: options.draco
467
473
  }
468
474
  : options.transform
469
- ? {
470
- useDraco: true
471
- }
472
- : undefined
475
+ ? {
476
+ useDraco: true
477
+ }
478
+ : undefined
473
479
 
474
480
  const imports = `
475
481
  ${options.types ? `\nimport type * as THREE from 'three'` : ''}
476
- ${options.stype && !options.isolated ? `import type { Snippet } from 'svelte'` : ''}
477
- import { ${[
478
- 'T',
479
- options.types && !options.isolated ? 'type Props' : ''
480
- ]
482
+ ${options.types ? `import type { Snippet } from 'svelte'` : ''}
483
+ import { ${['T', options.types && !options.isolated ? 'type Props' : '']
481
484
  .filter(Boolean)
482
485
  .join(', ')} } from '@threlte/core'
483
486
  import { ${[
@@ -531,17 +534,21 @@ ${
531
534
  ${!options.preload ? imports : ''}
532
535
 
533
536
  let {
534
- ref = $bindable(),
535
- fallback,
537
+ fallback,
536
538
  error,
537
539
  children,
538
- ...props
539
- }${options.types && !options.isolated ? `: Props<THREE.Group> & {
540
- ref?: THREE.Group
540
+ ${options.isolated ? '' : 'ref = $bindable(),'}
541
+ ${options.isolated ? '' : '...props'}
542
+ }${
543
+ options.types
544
+ ? `: Props<THREE.Group> & {
545
+ ${options.isolated ? '' : 'ref?: THREE.Group'}
541
546
  children?: Snippet<[{ ref: THREE.Group }]>
542
547
  fallback?: Snippet
543
548
  error?: Snippet<[{ error: Error }]>
544
- }` : ''} = $props()
549
+ }`
550
+ : ''
551
+ } = $props()
545
552
 
546
553
  ${!options.preload && options.suspense ? 'const suspend = useSuspense()' : ''}
547
554
 
@@ -557,7 +564,7 @@ ${
557
564
  }
558
565
  </script>
559
566
 
560
- <T.Group bind:ref dispose={false} ${!options.isolated ? '{...props}' : ''}>
567
+ <T.Group ${options.isolated ? '' : 'bind:ref'} dispose={false} ${!options.isolated ? '{...props}' : ''}>
561
568
  {#await gltf}
562
569
  {@render fallback?.()}
563
570
  {:then gltf}
@@ -567,7 +574,7 @@ ${
567
574
  {/await}
568
575
 
569
576
  {@render children?.({ ref })}
570
- </T>
577
+ </T.Group>
571
578
  `
572
579
  }
573
580
 
@@ -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