@threlte/gltf 3.0.1 → 3.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @threlte/gltf
2
2
 
3
+ ## 3.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - da99fff: Run `knip` and prune unused dependencies and exports
8
+
9
+ ## 3.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - b1bc980: Update dependencies
14
+
3
15
  ## 3.0.1
4
16
 
5
17
  ### Patch Changes
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 threejs objects can only be mounted once
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
- [![Powered by Vercel](./assets/vercel/powered-by-vercel.svg)](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 (No $$restProps usage)
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
- --simplify, -S Transform simplification (default: false) (experimental!)
34
- --weld Weld tolerance (default: 0.0001)
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', alias: 'o' },
43
- types: { type: 'boolean', alias: 't' },
44
- keepnames: { type: 'boolean', alias: 'k' },
45
- keepgroups: { type: 'boolean', alias: 'K' },
46
- shadows: { type: 'boolean', alias: 's' },
47
- printwidth: { type: 'number', alias: 'p', default: 120 },
48
- meta: { type: 'boolean', alias: 'm' },
49
- precision: { type: 'number', alias: 'p', default: 2 },
50
- isolated: { type: 'boolean', alias: 'i', default: false },
51
- preload: { type: 'boolean', alias: 'P', default: false },
52
- suspense: { type: 'boolean', alias: 'u', default: false },
53
- draco: { type: 'string', alias: 'd' },
54
- root: { type: 'string', alias: 'r' },
55
- transform: { type: 'boolean', alias: 'T' },
56
- resolution: { type: 'number', alias: 'R', default: 1024 },
57
- simplify: { type: 'boolean', alias: 'S', default: false },
58
- weld: { type: 'number', default: 0.0001 },
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', alias: 'D' }
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
- let nameExt = file.match(/[-_\w]+[.][\w]+$/i)[0]
78
- let name = nameExt.split('.').slice(0, -1).join('.')
79
- const output = name + '.svelte'
80
- const showLog = (log) => {
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
- ...config,
86
- showLog,
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.1",
3
+ "version": "3.0.3",
4
4
  "description": "GLTF to Threlte converter",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,42 +18,36 @@
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/threlte/threlte.git"
21
+ "url": "https://github.com/threlte/threlte",
22
+ "directory": "packages/gltf"
22
23
  },
23
24
  "bugs": {
24
- "url": "https://github.com/threlte/threlte.git/issues"
25
+ "url": "https://github.com/threlte/threlte/issues"
25
26
  },
26
- "homepage": "https://github.com/threlte/threlte.git#readme",
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": "^3.2.1",
34
- "@gltf-transform/extensions": "^3.2.1",
35
- "@gltf-transform/functions": "^3.2.1",
36
- "@node-loader/babel": "^2.0.1",
37
- "draco3dgltf": "^1.5.6",
38
- "jsdom": "^20.0.3",
31
+ "@gltf-transform/core": "^4.2.1",
32
+ "@gltf-transform/extensions": "^4.2.1",
33
+ "@gltf-transform/functions": "^4.2.1",
34
+ "draco3dgltf": "^1.5.7",
35
+ "jsdom": "^27.1.0",
39
36
  "jsdom-global": "^3.0.2",
40
- "meow": "^11.0.0",
41
- "meshoptimizer": "^0.18.1",
42
- "prettier": "^3.2.5",
43
- "prettier-plugin-svelte": "^3.2.2",
44
- "sharp": "^0.32.0",
45
- "svelte": "^5.26.2",
46
- "three": "0.122.0",
47
- "three-stdlib": "^2.21.8"
37
+ "keyframe-resample": "^0.1.0",
38
+ "meow": "^14.0.0",
39
+ "meshoptimizer": "^0.25.0",
40
+ "prettier": "^3.6.2",
41
+ "prettier-plugin-svelte": "^3.4.0",
42
+ "read-pkg-up": "^11.0.0",
43
+ "sharp": "^0.34.5",
44
+ "svelte": "5.53.6",
45
+ "three": "0.159.0"
48
46
  },
49
47
  "devDependencies": {
50
- "chalk": "^4.1.1",
51
- "fast-glob": "^3.2.7",
52
- "fs-extra": "^9.0.1",
53
- "husky": "^4.3.0",
54
- "lint-staged": "^10.4.0",
55
- "read-pkg-up": "^9.1.0",
56
- "rimraf": "^5.0.1"
48
+ "husky": "^9.1.7",
49
+ "lint-staged": "^16.2.6",
50
+ "rimraf": "^6.1.0"
57
51
  },
58
52
  "husky": {
59
53
  "hooks": {
@@ -1,9 +1,9 @@
1
- 'use strict'
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 = (THREE.DRACOLoader = function (t) {
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
- THREE.DRACOLoader.prototype = {
23
- constructor: THREE.DRACOLoader,
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 }