@threlte/gltf 3.0.0-next.2 → 3.0.0-next.4
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/package.json +4 -4
- package/src/index.js +9 -8
- package/src/utils/Options.d.ts +22 -0
- package/src/utils/parser.js +22 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 3.0.0-next.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 54bdef9: Fix gltf parser template for isolated components
|
|
8
|
+
|
|
9
|
+
## 3.0.0-next.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bb726da: fix prettier formatting
|
|
14
|
+
|
|
3
15
|
## 3.0.0-next.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/gltf",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.4",
|
|
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.
|
|
43
|
-
"prettier-plugin-svelte": "^2.
|
|
42
|
+
"prettier": "^3.2.5",
|
|
43
|
+
"prettier-plugin-svelte": "^3.2.2",
|
|
44
44
|
"sharp": "^0.32.0",
|
|
45
|
-
"svelte": "
|
|
45
|
+
"svelte": "5.0.0-next.133",
|
|
46
46
|
"three": "0.122.0",
|
|
47
47
|
"three-stdlib": "^2.21.8"
|
|
48
48
|
},
|
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
|
-
|
|
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
|
+
}
|
package/src/utils/parser.js
CHANGED
|
@@ -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,14 +472,14 @@ function parse(fileName, gltf, options = {}) {
|
|
|
466
472
|
useDraco: options.draco
|
|
467
473
|
}
|
|
468
474
|
: options.transform
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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.
|
|
482
|
+
${options.types ? `import type { Snippet } from 'svelte'` : ''}
|
|
477
483
|
import { ${['T', options.types && !options.isolated ? 'type Props' : '']
|
|
478
484
|
.filter(Boolean)
|
|
479
485
|
.join(', ')} } from '@threlte/core'
|
|
@@ -528,16 +534,16 @@ ${
|
|
|
528
534
|
${!options.preload ? imports : ''}
|
|
529
535
|
|
|
530
536
|
let {
|
|
531
|
-
|
|
532
|
-
fallback,
|
|
537
|
+
fallback,
|
|
533
538
|
error,
|
|
534
539
|
children,
|
|
535
|
-
|
|
540
|
+
${options.isolated ? '' : 'ref = $bindable(),'}
|
|
541
|
+
${options.isolated ? '' : '...props'}
|
|
536
542
|
}${
|
|
537
|
-
options.types
|
|
538
|
-
? `: Props<THREE.Group> & {
|
|
539
|
-
ref?: THREE.Group
|
|
540
|
-
children?: Snippet<[{ ref: THREE.Group }]>
|
|
543
|
+
options.types
|
|
544
|
+
? `: ${options.isolated ? '' : 'Props<THREE.Group> & '} {
|
|
545
|
+
${options.isolated ? '' : 'ref?: THREE.Group'}
|
|
546
|
+
children?: ${options.isolated ? 'Snippet' : 'Snippet<[{ ref: THREE.Group }]>'}
|
|
541
547
|
fallback?: Snippet
|
|
542
548
|
error?: Snippet<[{ error: Error }]>
|
|
543
549
|
}`
|
|
@@ -558,16 +564,16 @@ ${
|
|
|
558
564
|
}
|
|
559
565
|
</script>
|
|
560
566
|
|
|
561
|
-
<T.Group bind:ref dispose={false} ${!options.isolated ? '{...props}' : ''}>
|
|
567
|
+
<T.Group ${options.isolated ? '' : 'bind:ref'} dispose={false} ${!options.isolated ? '{...props}' : ''}>
|
|
562
568
|
{#await gltf}
|
|
563
569
|
{@render fallback?.()}
|
|
564
570
|
{:then gltf}
|
|
565
571
|
${scene}
|
|
566
|
-
{:catch
|
|
567
|
-
{@render error?.({ error })}
|
|
572
|
+
{:catch err}
|
|
573
|
+
{@render error?.({ error: err })}
|
|
568
574
|
{/await}
|
|
569
575
|
|
|
570
|
-
{@render children?.({ ref })}
|
|
576
|
+
{@render children?.(${options.isolated ? '' : '{ ref }'})}
|
|
571
577
|
</T.Group>
|
|
572
578
|
`
|
|
573
579
|
}
|