@threlte/gltf 3.0.4 → 3.0.6
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 +15 -0
- package/cli.js +2 -1
- package/package.json +1 -1
- package/src/index.js +3 -2
- package/src/utils/Options.d.ts +10 -0
- package/src/utils/parser.js +8 -4
- package/src/utils/transform.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 3.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 766701b: Fixed -p flag collision between --printwidth and --precision
|
|
8
|
+
- 766701b: Fixed --printwidth flag being ignored
|
|
9
|
+
- 766701b: Fixed ReferenceError crash when using --degrade flag
|
|
10
|
+
|
|
11
|
+
## 3.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- bd24a8a: Fix prettier-plugin-svelte resolution error when running via npx
|
|
16
|
+
- 3c951cc: Auto-detect Draco compression from GLTF metadata and include useDraco() in generated components automatically
|
|
17
|
+
|
|
3
18
|
## 3.0.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/cli.js
CHANGED
|
@@ -47,7 +47,7 @@ const cli = meow(
|
|
|
47
47
|
keepnames: { type: 'boolean', shortFlag: 'k' },
|
|
48
48
|
keepgroups: { type: 'boolean', shortFlag: 'K' },
|
|
49
49
|
shadows: { type: 'boolean', shortFlag: 's' },
|
|
50
|
-
printwidth: { type: 'number', shortFlag: '
|
|
50
|
+
printwidth: { type: 'number', shortFlag: 'w', default: 120 },
|
|
51
51
|
meta: { type: 'boolean', shortFlag: 'm' },
|
|
52
52
|
precision: { type: 'number', shortFlag: 'p', default: 2 },
|
|
53
53
|
isolated: { type: 'boolean', shortFlag: 'i', default: false },
|
|
@@ -62,6 +62,7 @@ const cli = meow(
|
|
|
62
62
|
simplify: { type: 'boolean', shortFlag: 'S', default: false },
|
|
63
63
|
keepmeshes: { type: 'boolean', shortFlag: 'j', default: false },
|
|
64
64
|
keepmaterials: { type: 'boolean', shortFlag: 'M', default: false },
|
|
65
|
+
format: { type: 'string', shortFlag: 'f', default: 'webp' },
|
|
65
66
|
ratio: { type: 'number', default: 0.75 },
|
|
66
67
|
error: { type: 'number', default: 0.001 },
|
|
67
68
|
debug: { type: 'boolean', shortFlag: 'D' }
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import 'jsdom-global'
|
|
|
2
2
|
import fs from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import * as prettier from 'prettier'
|
|
5
|
+
import * as prettierPluginSvelte from 'prettier-plugin-svelte'
|
|
5
6
|
import { transform } from './utils/transform.js'
|
|
6
7
|
import { parse } from './utils/parser.js'
|
|
7
8
|
import { GLTFLoader } from './bin/GLTFLoader.js'
|
|
@@ -38,9 +39,9 @@ export default async function (file, output, options) {
|
|
|
38
39
|
singleQuote: true,
|
|
39
40
|
trailingComma: 'es5',
|
|
40
41
|
semi: false,
|
|
41
|
-
printWidth: 100,
|
|
42
|
+
printWidth: options.printwidth ?? 100,
|
|
42
43
|
parser: 'svelte',
|
|
43
|
-
plugins: [
|
|
44
|
+
plugins: [prettierPluginSvelte],
|
|
44
45
|
overrides: [
|
|
45
46
|
{
|
|
46
47
|
files: '*.svelte',
|
package/src/utils/Options.d.ts
CHANGED
|
@@ -19,4 +19,14 @@ export type Options = {
|
|
|
19
19
|
ratio?: number
|
|
20
20
|
error?: number
|
|
21
21
|
debug?: boolean
|
|
22
|
+
keepmeshes?: boolean
|
|
23
|
+
keepmaterials?: boolean
|
|
24
|
+
format?: string
|
|
25
|
+
degrade?: string
|
|
26
|
+
degraderesolution?: number
|
|
27
|
+
console?: boolean
|
|
28
|
+
header?: string
|
|
29
|
+
showLog?: (log: string) => void
|
|
30
|
+
timeout?: number
|
|
31
|
+
delay?: number
|
|
22
32
|
}
|
package/src/utils/parser.js
CHANGED
|
@@ -53,7 +53,7 @@ export function parse(fileName, gltf, options = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (child.geometry) {
|
|
56
|
-
const key = child.geometry.uuid + child.material?.name ?? ''
|
|
56
|
+
const key = child.geometry.uuid + (child.material?.name ?? '')
|
|
57
57
|
if (!duplicates.geometries[key]) {
|
|
58
58
|
let name = (child.name || 'Part').replace(/[^a-zA-Z]/g, '')
|
|
59
59
|
name = name.charAt(0).toUpperCase() + name.slice(1)
|
|
@@ -77,7 +77,7 @@ export function parse(fileName, gltf, options = {}) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function sanitizeName(name) {
|
|
80
|
-
return isVarName(name) ? `.${name}` : `['${name}']`
|
|
80
|
+
return isVarName(name) ? `.${name}` : `['${name.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}']`
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const rNbr = (number) => {
|
|
@@ -484,8 +484,12 @@ export function parse(fileName, gltf, options = {}) {
|
|
|
484
484
|
// 2nd pass to eliminate hard to swat left-overs
|
|
485
485
|
const scene = printThrelte(gltf.scene)
|
|
486
486
|
|
|
487
|
+
const hasDraco =
|
|
488
|
+
gltf.parser?.json?.extensionsUsed?.includes('KHR_draco_mesh_compression') ||
|
|
489
|
+
gltf.parser?.json?.extensionsRequired?.includes('KHR_draco_mesh_compression')
|
|
490
|
+
|
|
487
491
|
const useGltfOptions = {
|
|
488
|
-
draco: options.transform || options.draco
|
|
492
|
+
draco: options.transform || options.draco || hasDraco
|
|
489
493
|
}
|
|
490
494
|
|
|
491
495
|
const imports = `
|
|
@@ -524,7 +528,7 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
|
|
|
524
528
|
${
|
|
525
529
|
options.preload
|
|
526
530
|
? `
|
|
527
|
-
<script
|
|
531
|
+
<script module${options.types ? ' lang="ts"' : ''}>
|
|
528
532
|
${imports}
|
|
529
533
|
|
|
530
534
|
${options.types ? printThrelteTypes(objects, animations) : ''}
|
package/src/utils/transform.js
CHANGED
|
@@ -83,7 +83,7 @@ export async function transform(file, output, config = {}) {
|
|
|
83
83
|
encoder: sharp,
|
|
84
84
|
pattern: new RegExp(`^(?=${config.degrade}).*$`),
|
|
85
85
|
targetFormat: config.format,
|
|
86
|
-
resize: [
|
|
86
|
+
resize: [config.degraderesolution ?? 512, config.degraderesolution ?? 512]
|
|
87
87
|
}),
|
|
88
88
|
textureCompress({
|
|
89
89
|
encoder: sharp,
|