@threlte/gltf 3.0.0 → 3.0.2
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 +1 -5
- package/cli.js +37 -36
- package/package.json +26 -28
- package/src/bin/DRACOLoader.js +43 -40
- package/src/bin/GLTFLoader.js +2212 -2287
- package/src/index.js +46 -74
- package/src/utils/exports.js +1 -1
- package/src/utils/isVarName.js +1 -3
- package/src/utils/parser.js +56 -40
- package/src/utils/transform.js +78 -17
- package/tsconfig.json +30 -0
- package/src/utils/glftLoader.js +0 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ This helps with performance optimization for asset-heavy Threlte apps. It also a
|
|
|
35
35
|
|
|
36
36
|
#### The GLTF workflow on the web is not ideal ...
|
|
37
37
|
|
|
38
|
-
- GLTF is thrown wholesale into the scene which prevents re-use, in
|
|
38
|
+
- GLTF is thrown wholesale into the scene which prevents re-use, in Three.js objects can only be mounted once
|
|
39
39
|
- Contents can only be found by traversal which is cumbersome and slow
|
|
40
40
|
- Changes to queried nodes are made by mutation, which alters the source data and prevents re-use
|
|
41
41
|
- Re-structuring content, making nodes conditional or adding/removing is cumbersome
|
|
@@ -323,10 +323,6 @@ Contributions are what make the open source community such an amazing place to l
|
|
|
323
323
|
- **Filing Issues** - if you have feature requestions or you think you spotted a bug, [submit an issue](https://github.com/threlte/threlte/issues/new).
|
|
324
324
|
- **Contributing Code** - if you would like to drop us a PR, read the [contribution guide](https://github.com/threlte/threlte/blob/main/CONTRIBUTING.md) first.
|
|
325
325
|
|
|
326
|
-
## Sponsors
|
|
327
|
-
|
|
328
|
-
[](https://vercel.com/?utm_source=threlte&utm_campaign=oss)
|
|
329
|
-
|
|
330
326
|
---
|
|
331
327
|
|
|
332
328
|
### License
|
package/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
|
+
|
|
4
|
+
import { dirname } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
3
6
|
import meow from 'meow'
|
|
4
|
-
import { dirname } from 'path'
|
|
5
7
|
import { readPackageUpSync } from 'read-pkg-up'
|
|
6
|
-
import { fileURLToPath } from 'url'
|
|
7
8
|
import gltf from './src/index.js'
|
|
8
9
|
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url)
|
|
@@ -26,12 +27,14 @@ const cli = meow(
|
|
|
26
27
|
--draco, -d Draco binary path
|
|
27
28
|
--preload -P Add preload method to module script
|
|
28
29
|
--suspense -u Make the component suspense-ready
|
|
29
|
-
--isolated, -i Output as isolated module
|
|
30
|
+
--isolated, -i Output as isolated module
|
|
30
31
|
--root, -r Sets directory from which .gltf file is served
|
|
31
32
|
--transform, -T Transform the asset for the web (draco, prune, resize)
|
|
32
33
|
--resolution, -R Transform resolution for texture resizing (default: 1024)
|
|
33
|
-
--
|
|
34
|
-
|
|
34
|
+
--keepmeshes, -j Do not join compatible meshes
|
|
35
|
+
--keepmaterials, -M Do not palette join materials
|
|
36
|
+
--format, -f Texture format (default: "webp")
|
|
37
|
+
--simplify, -S Transform simplification (default: false)
|
|
35
38
|
--ratio Simplifier ratio (default: 0.75)
|
|
36
39
|
--error Simplifier error threshold (default: 0.001)
|
|
37
40
|
--debug, -D Debug output
|
|
@@ -39,26 +42,29 @@ const cli = meow(
|
|
|
39
42
|
{
|
|
40
43
|
importMeta: import.meta,
|
|
41
44
|
flags: {
|
|
42
|
-
output: { type: 'string',
|
|
43
|
-
types: { type: 'boolean',
|
|
44
|
-
keepnames: { type: 'boolean',
|
|
45
|
-
keepgroups: { type: 'boolean',
|
|
46
|
-
shadows: { type: 'boolean',
|
|
47
|
-
printwidth: { type: 'number',
|
|
48
|
-
meta: { type: 'boolean',
|
|
49
|
-
precision: { type: 'number',
|
|
50
|
-
isolated: { type: 'boolean',
|
|
51
|
-
preload: { type: 'boolean',
|
|
52
|
-
suspense: { type: 'boolean',
|
|
53
|
-
draco: { type: 'string',
|
|
54
|
-
root: { type: 'string',
|
|
55
|
-
transform: { type: 'boolean',
|
|
56
|
-
resolution: { type: 'number',
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
output: { type: 'string', shortFlag: 'o' },
|
|
46
|
+
types: { type: 'boolean', shortFlag: 't' },
|
|
47
|
+
keepnames: { type: 'boolean', shortFlag: 'k' },
|
|
48
|
+
keepgroups: { type: 'boolean', shortFlag: 'K' },
|
|
49
|
+
shadows: { type: 'boolean', shortFlag: 's' },
|
|
50
|
+
printwidth: { type: 'number', shortFlag: 'p', default: 120 },
|
|
51
|
+
meta: { type: 'boolean', shortFlag: 'm' },
|
|
52
|
+
precision: { type: 'number', shortFlag: 'p', default: 2 },
|
|
53
|
+
isolated: { type: 'boolean', shortFlag: 'i', default: false },
|
|
54
|
+
preload: { type: 'boolean', shortFlag: 'P', default: false },
|
|
55
|
+
suspense: { type: 'boolean', shortFlag: 'u', default: false },
|
|
56
|
+
draco: { type: 'string', shortFlag: 'd' },
|
|
57
|
+
root: { type: 'string', shortFlag: 'r' },
|
|
58
|
+
transform: { type: 'boolean', shortFlag: 'T' },
|
|
59
|
+
resolution: { type: 'number', shortFlag: 'R', default: 1024 },
|
|
60
|
+
degrade: { type: 'string', shortFlag: 'q', default: '' },
|
|
61
|
+
degraderesolution: { type: 'number', shortFlag: 'Q', default: 512 },
|
|
62
|
+
simplify: { type: 'boolean', shortFlag: 'S', default: false },
|
|
63
|
+
keepmeshes: { type: 'boolean', shortFlag: 'j', default: false },
|
|
64
|
+
keepmaterials: { type: 'boolean', shortFlag: 'M', default: false },
|
|
59
65
|
ratio: { type: 'number', default: 0.75 },
|
|
60
66
|
error: { type: 'number', default: 0.001 },
|
|
61
|
-
debug: { type: 'boolean',
|
|
67
|
+
debug: { type: 'boolean', shortFlag: 'D' }
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
)
|
|
@@ -68,22 +74,17 @@ const { packageJson } = readPackageUpSync({ cwd: __dirname, normalize: false })
|
|
|
68
74
|
if (cli.input.length === 0) {
|
|
69
75
|
console.log(cli.help)
|
|
70
76
|
} else {
|
|
71
|
-
const config = {
|
|
72
|
-
...cli.flags,
|
|
73
|
-
header: `Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
|
|
74
|
-
Command: npx @threlte/gltf@${packageJson.version} ${process.argv.slice(2).join(' ')}`
|
|
75
|
-
}
|
|
76
77
|
const file = cli.input[0]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const output = name
|
|
80
|
-
|
|
81
|
-
console.info('log:', log)
|
|
82
|
-
}
|
|
78
|
+
const nameExt = file.match(/[-_\w]+[.][\w]+$/i)[0]
|
|
79
|
+
const name = nameExt.split('.').slice(0, -1).join('.')
|
|
80
|
+
const output = `${name}.svelte`
|
|
81
|
+
|
|
83
82
|
try {
|
|
84
83
|
await gltf(file, output, {
|
|
85
|
-
...
|
|
86
|
-
|
|
84
|
+
...cli.flags,
|
|
85
|
+
header: `Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
|
|
86
|
+
Command: npx @threlte/gltf@${packageJson.version} ${process.argv.slice(2).join(' ')}`,
|
|
87
|
+
showLog: (log) => console.info('log:', log),
|
|
87
88
|
timeout: 0,
|
|
88
89
|
delay: 1
|
|
89
90
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/gltf",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "GLTF to Threlte converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,42 +18,40 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "
|
|
21
|
+
"url": "https://github.com/threlte/threlte",
|
|
22
|
+
"directory": "packages/gltf"
|
|
22
23
|
},
|
|
23
24
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/threlte/threlte
|
|
25
|
+
"url": "https://github.com/threlte/threlte/issues"
|
|
25
26
|
},
|
|
26
|
-
"homepage": "https://
|
|
27
|
+
"homepage": "https://threlte.xyz",
|
|
27
28
|
"bin": "./cli.js",
|
|
28
29
|
"main": "./src/utils/exports.js",
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=16"
|
|
31
|
-
},
|
|
32
30
|
"dependencies": {
|
|
33
|
-
"@gltf-transform/core": "^
|
|
34
|
-
"@gltf-transform/extensions": "^
|
|
35
|
-
"@gltf-transform/functions": "^
|
|
36
|
-
"@node-loader/babel": "^2.0
|
|
37
|
-
"draco3dgltf": "^1.5.
|
|
38
|
-
"jsdom": "^
|
|
31
|
+
"@gltf-transform/core": "^4.2.1",
|
|
32
|
+
"@gltf-transform/extensions": "^4.2.1",
|
|
33
|
+
"@gltf-transform/functions": "^4.2.1",
|
|
34
|
+
"@node-loader/babel": "^2.1.0",
|
|
35
|
+
"draco3dgltf": "^1.5.7",
|
|
36
|
+
"jsdom": "^27.1.0",
|
|
39
37
|
"jsdom-global": "^3.0.2",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"prettier
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
38
|
+
"keyframe-resample": "^0.1.0",
|
|
39
|
+
"meow": "^14.0.0",
|
|
40
|
+
"meshoptimizer": "^0.25.0",
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"prettier-plugin-svelte": "^3.4.0",
|
|
43
|
+
"read-pkg-up": "^11.0.0",
|
|
44
|
+
"sharp": "^0.34.5",
|
|
45
|
+
"svelte": "5.53.6",
|
|
46
|
+
"three": "0.159.0"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"chalk": "^
|
|
51
|
-
"fast-glob": "^3.
|
|
52
|
-
"fs-extra": "^
|
|
53
|
-
"husky": "^
|
|
54
|
-
"lint-staged": "^
|
|
55
|
-
"
|
|
56
|
-
"rimraf": "^5.0.1"
|
|
49
|
+
"chalk": "^5.6.2",
|
|
50
|
+
"fast-glob": "^3.3.3",
|
|
51
|
+
"fs-extra": "^11.3.2",
|
|
52
|
+
"husky": "^9.1.7",
|
|
53
|
+
"lint-staged": "^16.2.6",
|
|
54
|
+
"rimraf": "^6.1.0"
|
|
57
55
|
},
|
|
58
56
|
"husky": {
|
|
59
57
|
"hooks": {
|
package/src/bin/DRACOLoader.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import THREE from 'three'
|
|
1
|
+
import * as THREE from 'three'
|
|
3
2
|
import draco from 'draco3dgltf'
|
|
3
|
+
|
|
4
4
|
const decoder = draco.createDecoderModule()
|
|
5
|
-
const DRACOLoader =
|
|
6
|
-
;(this.timeLoaded = 0),
|
|
5
|
+
const DRACOLoader = function (t) {
|
|
6
|
+
;((this.timeLoaded = 0),
|
|
7
7
|
(this.manager = t || THREE.DefaultLoadingManager),
|
|
8
8
|
(this.materials = null),
|
|
9
9
|
(this.verbosity = 0),
|
|
@@ -14,17 +14,18 @@ const DRACOLoader = (THREE.DRACOLoader = function (t) {
|
|
|
14
14
|
normal: 'NORMAL',
|
|
15
15
|
color: 'COLOR',
|
|
16
16
|
uv: 'TEX_COORD'
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default DRACOLoader
|
|
17
|
+
}))
|
|
18
|
+
}
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
constructor:
|
|
20
|
+
DRACOLoader.prototype = {
|
|
21
|
+
constructor: DRACOLoader,
|
|
22
|
+
preload: function () {
|
|
23
|
+
return this
|
|
24
|
+
},
|
|
24
25
|
load: function (t, e, r, o) {
|
|
25
26
|
var i = this,
|
|
26
27
|
n = new THREE.FileLoader(i.manager)
|
|
27
|
-
n.setPath(this.path),
|
|
28
|
+
;(n.setPath(this.path),
|
|
28
29
|
n.setResponseType('arraybuffer'),
|
|
29
30
|
n.load(
|
|
30
31
|
t,
|
|
@@ -33,20 +34,20 @@ THREE.DRACOLoader.prototype = {
|
|
|
33
34
|
},
|
|
34
35
|
r,
|
|
35
36
|
o
|
|
36
|
-
)
|
|
37
|
+
))
|
|
37
38
|
},
|
|
38
39
|
setPath: function (t) {
|
|
39
|
-
return (this.path = t), this
|
|
40
|
+
return ((this.path = t), this)
|
|
40
41
|
},
|
|
41
42
|
setVerbosity: function (t) {
|
|
42
|
-
return (this.verbosity = t), this
|
|
43
|
+
return ((this.verbosity = t), this)
|
|
43
44
|
},
|
|
44
45
|
setDrawMode: function (t) {
|
|
45
|
-
return (this.drawMode = t), this
|
|
46
|
+
return ((this.drawMode = t), this)
|
|
46
47
|
},
|
|
47
48
|
setSkipDequantization: function (t, e) {
|
|
48
49
|
var r = !0
|
|
49
|
-
return void 0 !== e && (r = e), (this.getAttributeOptions(t).skipDequantization = r), this
|
|
50
|
+
return (void 0 !== e && (r = e), (this.getAttributeOptions(t).skipDequantization = r), this)
|
|
50
51
|
},
|
|
51
52
|
decodeDracoFile: function (t, e, r, o) {
|
|
52
53
|
decoder.then((decoder) => this.decodeDracoFileInternal(t, decoder, e, r, o))
|
|
@@ -77,53 +78,53 @@ THREE.DRACOLoader.prototype = {
|
|
|
77
78
|
l = r.num_points() * c
|
|
78
79
|
switch (i) {
|
|
79
80
|
case Float32Array:
|
|
80
|
-
;(d = new t.DracoFloat32Array()),
|
|
81
|
+
;((d = new t.DracoFloat32Array()),
|
|
81
82
|
e.GetAttributeFloatForAllPoints(r, n, d),
|
|
82
83
|
(s[o] = new Float32Array(l)),
|
|
83
|
-
(A = THREE.Float32BufferAttribute)
|
|
84
|
+
(A = THREE.Float32BufferAttribute))
|
|
84
85
|
break
|
|
85
86
|
case Int8Array:
|
|
86
|
-
;(d = new t.DracoInt8Array()),
|
|
87
|
+
;((d = new t.DracoInt8Array()),
|
|
87
88
|
e.GetAttributeInt8ForAllPoints(r, n, d),
|
|
88
89
|
(s[o] = new Int8Array(l)),
|
|
89
|
-
(A = THREE.Int8BufferAttribute)
|
|
90
|
+
(A = THREE.Int8BufferAttribute))
|
|
90
91
|
break
|
|
91
92
|
case Int16Array:
|
|
92
|
-
;(d = new t.DracoInt16Array()),
|
|
93
|
+
;((d = new t.DracoInt16Array()),
|
|
93
94
|
e.GetAttributeInt16ForAllPoints(r, n, d),
|
|
94
95
|
(s[o] = new Int16Array(l)),
|
|
95
|
-
(A = THREE.Int16BufferAttribute)
|
|
96
|
+
(A = THREE.Int16BufferAttribute))
|
|
96
97
|
break
|
|
97
98
|
case Int32Array:
|
|
98
|
-
;(d = new t.DracoInt32Array()),
|
|
99
|
+
;((d = new t.DracoInt32Array()),
|
|
99
100
|
e.GetAttributeInt32ForAllPoints(r, n, d),
|
|
100
101
|
(s[o] = new Int32Array(l)),
|
|
101
|
-
(A = THREE.Int32BufferAttribute)
|
|
102
|
+
(A = THREE.Int32BufferAttribute))
|
|
102
103
|
break
|
|
103
104
|
case Uint8Array:
|
|
104
|
-
;(d = new t.DracoUInt8Array()),
|
|
105
|
+
;((d = new t.DracoUInt8Array()),
|
|
105
106
|
e.GetAttributeUInt8ForAllPoints(r, n, d),
|
|
106
107
|
(s[o] = new Uint8Array(l)),
|
|
107
|
-
(A = THREE.Uint8BufferAttribute)
|
|
108
|
+
(A = THREE.Uint8BufferAttribute))
|
|
108
109
|
break
|
|
109
110
|
case Uint16Array:
|
|
110
|
-
;(d = new t.DracoUInt16Array()),
|
|
111
|
+
;((d = new t.DracoUInt16Array()),
|
|
111
112
|
e.GetAttributeUInt16ForAllPoints(r, n, d),
|
|
112
113
|
(s[o] = new Uint16Array(l)),
|
|
113
|
-
(A = THREE.Uint16BufferAttribute)
|
|
114
|
+
(A = THREE.Uint16BufferAttribute))
|
|
114
115
|
break
|
|
115
116
|
case Uint32Array:
|
|
116
|
-
;(d = new t.DracoUInt32Array()),
|
|
117
|
+
;((d = new t.DracoUInt32Array()),
|
|
117
118
|
e.GetAttributeUInt32ForAllPoints(r, n, d),
|
|
118
119
|
(s[o] = new Uint32Array(l)),
|
|
119
|
-
(A = THREE.Uint32BufferAttribute)
|
|
120
|
+
(A = THREE.Uint32BufferAttribute))
|
|
120
121
|
break
|
|
121
122
|
default:
|
|
122
123
|
u = 'THREE.DRACOLoader: Unexpected attribute type.'
|
|
123
124
|
throw (console.error(u), new Error(u))
|
|
124
125
|
}
|
|
125
126
|
for (var b = 0; b < l; b++) s[o][b] = d.GetValue(b)
|
|
126
|
-
a.setAttribute(o, new A(s[o], c)), t.destroy(d)
|
|
127
|
+
;(a.setAttribute(o, new A(s[o], c)), t.destroy(d))
|
|
127
128
|
},
|
|
128
129
|
convertDracoGeometryTo3JS: function (t, e, r, o, i, n) {
|
|
129
130
|
var a, s, u
|
|
@@ -139,11 +140,11 @@ THREE.DRACOLoader.prototype = {
|
|
|
139
140
|
var d = 'THREE.DRACOLoader: Decoding failed: '
|
|
140
141
|
throw ((d += s.error_msg()), console.error(d), t.destroy(e), t.destroy(a), new Error(d))
|
|
141
142
|
}
|
|
142
|
-
t.destroy(o),
|
|
143
|
+
;(t.destroy(o),
|
|
143
144
|
r == t.TRIANGULAR_MESH
|
|
144
145
|
? ((u = a.num_faces()),
|
|
145
146
|
this.verbosity > 0 && console.log('Number of faces loaded: ' + u.toString()))
|
|
146
|
-
: (u = 0)
|
|
147
|
+
: (u = 0))
|
|
147
148
|
var A = a.num_points(),
|
|
148
149
|
c = a.num_attributes()
|
|
149
150
|
this.verbosity > 0 &&
|
|
@@ -187,28 +188,28 @@ THREE.DRACOLoader.prototype = {
|
|
|
187
188
|
for (I = 0; I < u; ++I) {
|
|
188
189
|
e.GetFaceFromMesh(a, I, D)
|
|
189
190
|
var m = 3 * I
|
|
190
|
-
;(f.indices[m] = D.GetValue(0)),
|
|
191
|
+
;((f.indices[m] = D.GetValue(0)),
|
|
191
192
|
(f.indices[m + 1] = D.GetValue(1)),
|
|
192
|
-
(f.indices[m + 2] = D.GetValue(2))
|
|
193
|
+
(f.indices[m + 2] = D.GetValue(2)))
|
|
193
194
|
}
|
|
194
195
|
t.destroy(D)
|
|
195
196
|
}
|
|
196
|
-
;(y.drawMode = this.drawMode),
|
|
197
|
+
;((y.drawMode = this.drawMode),
|
|
197
198
|
r == t.TRIANGULAR_MESH &&
|
|
198
199
|
y.setIndex(
|
|
199
200
|
new (f.indices.length > 65535
|
|
200
201
|
? THREE.Uint32BufferAttribute
|
|
201
202
|
: THREE.Uint16BufferAttribute)(f.indices, 1)
|
|
202
|
-
)
|
|
203
|
+
))
|
|
203
204
|
var G = new t.AttributeQuantizationTransform()
|
|
204
205
|
if (G.InitFromAttribute(b)) {
|
|
205
|
-
;(y.attributes.position.isQuantized = !0),
|
|
206
|
+
;((y.attributes.position.isQuantized = !0),
|
|
206
207
|
(y.attributes.position.maxRange = G.range()),
|
|
207
208
|
(y.attributes.position.numQuantizationBits = G.quantization_bits()),
|
|
208
|
-
(y.attributes.position.minValues = new Float32Array(3))
|
|
209
|
+
(y.attributes.position.minValues = new Float32Array(3)))
|
|
209
210
|
for (I = 0; I < 3; ++I) y.attributes.position.minValues[I] = G.min_value(I)
|
|
210
211
|
}
|
|
211
|
-
return t.destroy(G), t.destroy(e), t.destroy(a), y
|
|
212
|
+
return (t.destroy(G), t.destroy(e), t.destroy(a), y)
|
|
212
213
|
},
|
|
213
214
|
isVersionSupported: function (t, e) {
|
|
214
215
|
e(decoder.isVersionSupported(t))
|
|
@@ -220,3 +221,5 @@ THREE.DRACOLoader.prototype = {
|
|
|
220
221
|
)
|
|
221
222
|
}
|
|
222
223
|
}
|
|
224
|
+
|
|
225
|
+
export { DRACOLoader }
|