@threlte/gltf 1.0.0-next.0 → 1.0.0-next.10
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 +60 -0
- package/cli.js +40 -11
- package/package.json +7 -6
- package/readme.md +7 -4
- package/src/bin/DRACOLoader.js +21 -7
- package/src/bin/GLTFLoader.js +186 -78
- package/src/index.js +4 -1
- package/src/utils/parser.js +67 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 1.0.0-next.10
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 05d91701: Added forwarding event handlers
|
|
8
|
+
|
|
9
|
+
## 1.0.0-next.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 89710f3e: Removed logs
|
|
14
|
+
|
|
15
|
+
## 1.0.0-next.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 119a04d1: Downgrading three and reusing own GLTFLoader and DRACOLoader implementations
|
|
20
|
+
|
|
21
|
+
## 1.0.0-next.7
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 89e0c7a9: Updated dependencies
|
|
26
|
+
|
|
27
|
+
## 1.0.0-next.6
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 81834dd4: Refactored the pascal case function
|
|
32
|
+
|
|
33
|
+
## 1.0.0-next.5
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- da70d570: typo
|
|
38
|
+
|
|
39
|
+
## 1.0.0-next.4
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- 16e75c31: Fixed a bug where the suspense was created in the wrong place when preloading was activated.
|
|
44
|
+
|
|
45
|
+
## 1.0.0-next.3
|
|
46
|
+
|
|
47
|
+
### Major Changes
|
|
48
|
+
|
|
49
|
+
- a07850e4: Removed the name from the exported preload function (seems silly and might collide anyway), updated deps and included three-stdlib instead of rolling an own implementation of GLTFLoader and DRACOLoader. Added option to make the component suspense-ready, updated README.
|
|
50
|
+
|
|
51
|
+
## 1.0.0-next.2
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- 124eabab: Fixed preload method to return a Promise
|
|
56
|
+
|
|
57
|
+
## 1.0.0-next.1
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- 72c71414: Added option to add a preload method that makes preloading an asset easy. Also, added the option to make an isolated component (so no \$\$restProps usage)
|
|
62
|
+
|
|
3
63
|
## 1.0.0-next.0
|
|
4
64
|
|
|
5
65
|
### Major Changes
|
package/cli.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
3
|
import meow from 'meow'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import { fileURLToPath } from 'url'
|
|
6
4
|
import { dirname } from 'path'
|
|
7
|
-
import gltf from './src/index.js'
|
|
8
5
|
import { readPackageUpSync } from 'read-pkg-up'
|
|
6
|
+
import { fileURLToPath } from 'url'
|
|
7
|
+
import gltf from './src/index.js'
|
|
9
8
|
|
|
10
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
11
10
|
const __dirname = dirname(__filename)
|
|
12
11
|
|
|
13
12
|
const cli = meow(
|
|
14
13
|
`
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Usage
|
|
15
|
+
$ npx @threlte/gltf [Model.glb] [options]
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
Options
|
|
19
18
|
--output, -o Output file name/path
|
|
20
19
|
--types, -t Add Typescript definitions
|
|
21
20
|
--keepnames, -k Keep original names
|
|
22
21
|
--keepgroups, -K Keep (empty) groups, disable pruning
|
|
23
22
|
--meta, -m Include metadata (as userData)
|
|
24
|
-
--shadows, s
|
|
25
|
-
--printwidth, w
|
|
23
|
+
--shadows, -s Let meshes cast and receive shadows
|
|
24
|
+
--printwidth, -w Prettier printWidth (default: 120)
|
|
26
25
|
--precision, -p Number of fractional digits (default: 2)
|
|
27
26
|
--draco, -d Draco binary path
|
|
27
|
+
--preload -P Add preload method to module script
|
|
28
|
+
--suspense -u Make the component suspense-ready
|
|
29
|
+
--isolated, -i Output as isolated module (No $$restProps usage)
|
|
28
30
|
--root, -r Sets directory from which .gltf file is served
|
|
29
31
|
--transform, -T Transform the asset for the web (draco, prune, resize)
|
|
30
32
|
--resolution, -R Transform resolution for texture resizing (default: 1024)
|
|
@@ -45,6 +47,9 @@ const cli = meow(
|
|
|
45
47
|
printwidth: { type: 'number', alias: 'p', default: 120 },
|
|
46
48
|
meta: { type: 'boolean', alias: 'm' },
|
|
47
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 },
|
|
48
53
|
draco: { type: 'string', alias: 'd' },
|
|
49
54
|
root: { type: 'string', alias: 'r' },
|
|
50
55
|
transform: { type: 'boolean', alias: 'T' },
|
|
@@ -60,6 +65,26 @@ const cli = meow(
|
|
|
60
65
|
|
|
61
66
|
const { packageJson } = readPackageUpSync({ cwd: __dirname, normalize: false })
|
|
62
67
|
|
|
68
|
+
function toPascalCase(str) {
|
|
69
|
+
return (
|
|
70
|
+
str
|
|
71
|
+
.replace(/(\w)(\w*)/g, function (g0, g1, g2) {
|
|
72
|
+
// capitalize first letter of g1, leave the reset as-is and return the result
|
|
73
|
+
return g1.toUpperCase() + g2
|
|
74
|
+
})
|
|
75
|
+
// replace every non-word character with an empty string and capitalize the first following letter
|
|
76
|
+
.replace(/\W+(.)/g, function (g0, g1) {
|
|
77
|
+
return g1.toUpperCase()
|
|
78
|
+
})
|
|
79
|
+
// replace every non-word character with an empty string
|
|
80
|
+
.replace(/\s+/g, '')
|
|
81
|
+
// make first letter uppercase
|
|
82
|
+
.replace(/^\w/, function (g0) {
|
|
83
|
+
return g0.toUpperCase()
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
63
88
|
if (cli.input.length === 0) {
|
|
64
89
|
console.log(cli.help)
|
|
65
90
|
} else {
|
|
@@ -69,16 +94,20 @@ if (cli.input.length === 0) {
|
|
|
69
94
|
Command: npx @threlte/gltf@${packageJson.version} ${process.argv.slice(2).join(' ')}`
|
|
70
95
|
}
|
|
71
96
|
const file = cli.input[0]
|
|
72
|
-
const filePath = path.resolve(__dirname, file)
|
|
73
97
|
let nameExt = file.match(/[-_\w]+[.][\w]+$/i)[0]
|
|
74
98
|
let name = nameExt.split('.').slice(0, -1).join('.')
|
|
75
|
-
const baseName = name.charAt(0).toUpperCase() + name.slice(1)
|
|
99
|
+
const baseName = toPascalCase(name.charAt(0).toUpperCase() + name.slice(1))
|
|
76
100
|
const output = baseName + '.svelte'
|
|
77
101
|
const showLog = (log) => {
|
|
78
102
|
console.info('log:', log)
|
|
79
103
|
}
|
|
80
104
|
try {
|
|
81
|
-
const response = await gltf(file, output, {
|
|
105
|
+
const response = await gltf(file, output, {
|
|
106
|
+
...config,
|
|
107
|
+
showLog,
|
|
108
|
+
timeout: 0,
|
|
109
|
+
delay: 1
|
|
110
|
+
})
|
|
82
111
|
} catch (e) {
|
|
83
112
|
console.error(e)
|
|
84
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/gltf",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.10",
|
|
4
4
|
"description": "GLTF to Threlte converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"node": ">=16"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@gltf-transform/core": "3.
|
|
34
|
-
"@gltf-transform/extensions": "3.
|
|
35
|
-
"@gltf-transform/functions": "3.
|
|
33
|
+
"@gltf-transform/core": "^3.2.1",
|
|
34
|
+
"@gltf-transform/extensions": "^3.2.1",
|
|
35
|
+
"@gltf-transform/functions": "^3.2.1",
|
|
36
36
|
"@node-loader/babel": "^2.0.1",
|
|
37
|
-
"draco3dgltf": "^1.5.
|
|
37
|
+
"draco3dgltf": "^1.5.6",
|
|
38
38
|
"jsdom": "^20.0.3",
|
|
39
39
|
"jsdom-global": "^3.0.2",
|
|
40
40
|
"meow": "^11.0.0",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"prettier-plugin-svelte": "^2.9.0",
|
|
44
44
|
"sharp": "^0.31.3",
|
|
45
45
|
"svelte": "^3.55.1",
|
|
46
|
-
"three": "0.122.0"
|
|
46
|
+
"three": "0.122.0",
|
|
47
|
+
"three-stdlib": "^2.21.8"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"chalk": "^4.1.1",
|
package/readme.md
CHANGED
|
@@ -27,16 +27,19 @@ Options
|
|
|
27
27
|
--keepnames, -k Keep original names
|
|
28
28
|
--keepgroups, -K Keep (empty) groups, disable pruning
|
|
29
29
|
--meta, -m Include metadata (as userData)
|
|
30
|
-
--shadows, s
|
|
31
|
-
--printwidth, w
|
|
30
|
+
--shadows, -s Let meshes cast and receive shadows
|
|
31
|
+
--printwidth, -w Prettier printWidth (default: 120)
|
|
32
32
|
--precision, -p Number of fractional digits (default: 2)
|
|
33
33
|
--draco, -d Draco binary path
|
|
34
|
+
--preload -P Add preload method to module script
|
|
35
|
+
--suspense -u Make the component suspense-ready
|
|
36
|
+
--isolated, -i Output as isolated module (No $$restProps usage)
|
|
34
37
|
--root, -r Sets directory from which .gltf file is served
|
|
35
38
|
--transform, -T Transform the asset for the web (draco, prune, resize)
|
|
36
39
|
--resolution, -R Transform resolution for texture resizing (default: 1024)
|
|
37
40
|
--simplify, -S Transform simplification (default: false) (experimental!)
|
|
38
41
|
--weld Weld tolerance (default: 0.0001)
|
|
39
|
-
--ratio Simplifier ratio (default: 0.
|
|
42
|
+
--ratio Simplifier ratio (default: 0.75)
|
|
40
43
|
--error Simplifier error threshold (default: 0.001)
|
|
41
44
|
--debug, -D Debug output
|
|
42
45
|
```
|
|
@@ -217,7 +220,7 @@ If you want to play an animation you can do so at any time:
|
|
|
217
220
|
|
|
218
221
|
```ts
|
|
219
222
|
const onEvent = () => {
|
|
220
|
-
|
|
223
|
+
$actions.jump.play()
|
|
221
224
|
}
|
|
222
225
|
```
|
|
223
226
|
|
package/src/bin/DRACOLoader.js
CHANGED
|
@@ -9,7 +9,12 @@ const DRACOLoader = (THREE.DRACOLoader = function (t) {
|
|
|
9
9
|
(this.verbosity = 0),
|
|
10
10
|
(this.attributeOptions = {}),
|
|
11
11
|
(this.drawMode = THREE.TrianglesDrawMode),
|
|
12
|
-
(this.nativeAttributeMap = {
|
|
12
|
+
(this.nativeAttributeMap = {
|
|
13
|
+
position: 'POSITION',
|
|
14
|
+
normal: 'NORMAL',
|
|
15
|
+
color: 'COLOR',
|
|
16
|
+
uv: 'TEX_COORD'
|
|
17
|
+
})
|
|
13
18
|
})
|
|
14
19
|
|
|
15
20
|
export default DRACOLoader
|
|
@@ -123,7 +128,8 @@ THREE.DRACOLoader.prototype = {
|
|
|
123
128
|
convertDracoGeometryTo3JS: function (t, e, r, o, i, n) {
|
|
124
129
|
var a, s, u
|
|
125
130
|
if (
|
|
126
|
-
(!0 === this.getAttributeOptions('position').skipDequantization &&
|
|
131
|
+
(!0 === this.getAttributeOptions('position').skipDequantization &&
|
|
132
|
+
e.SkipAttributeTransform(t.POSITION),
|
|
127
133
|
r === t.TRIANGULAR_MESH
|
|
128
134
|
? ((a = new t.Mesh()), (s = e.DecodeBufferToMesh(o, a)))
|
|
129
135
|
: ((a = new t.PointCloud()), (s = e.DecodeBufferToPointCloud(o, a))),
|
|
@@ -135,7 +141,8 @@ THREE.DRACOLoader.prototype = {
|
|
|
135
141
|
}
|
|
136
142
|
t.destroy(o),
|
|
137
143
|
r == t.TRIANGULAR_MESH
|
|
138
|
-
? ((u = a.num_faces()),
|
|
144
|
+
? ((u = a.num_faces()),
|
|
145
|
+
this.verbosity > 0 && console.log('Number of faces loaded: ' + u.toString()))
|
|
139
146
|
: (u = 0)
|
|
140
147
|
var A = a.num_points(),
|
|
141
148
|
c = a.num_attributes()
|
|
@@ -180,14 +187,18 @@ THREE.DRACOLoader.prototype = {
|
|
|
180
187
|
for (I = 0; I < u; ++I) {
|
|
181
188
|
e.GetFaceFromMesh(a, I, D)
|
|
182
189
|
var m = 3 * I
|
|
183
|
-
;(f.indices[m] = D.GetValue(0)),
|
|
190
|
+
;(f.indices[m] = D.GetValue(0)),
|
|
191
|
+
(f.indices[m + 1] = D.GetValue(1)),
|
|
192
|
+
(f.indices[m + 2] = D.GetValue(2))
|
|
184
193
|
}
|
|
185
194
|
t.destroy(D)
|
|
186
195
|
}
|
|
187
196
|
;(y.drawMode = this.drawMode),
|
|
188
197
|
r == t.TRIANGULAR_MESH &&
|
|
189
198
|
y.setIndex(
|
|
190
|
-
new (f.indices.length > 65535
|
|
199
|
+
new (f.indices.length > 65535
|
|
200
|
+
? THREE.Uint32BufferAttribute
|
|
201
|
+
: THREE.Uint16BufferAttribute)(f.indices, 1)
|
|
191
202
|
)
|
|
192
203
|
var G = new t.AttributeQuantizationTransform()
|
|
193
204
|
if (G.InitFromAttribute(b)) {
|
|
@@ -203,6 +214,9 @@ THREE.DRACOLoader.prototype = {
|
|
|
203
214
|
e(decoder.isVersionSupported(t))
|
|
204
215
|
},
|
|
205
216
|
getAttributeOptions: function (t) {
|
|
206
|
-
return
|
|
207
|
-
|
|
217
|
+
return (
|
|
218
|
+
void 0 === this.attributeOptions[t] && (this.attributeOptions[t] = {}),
|
|
219
|
+
this.attributeOptions[t]
|
|
220
|
+
)
|
|
221
|
+
}
|
|
208
222
|
}
|
package/src/bin/GLTFLoader.js
CHANGED
|
@@ -147,7 +147,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
147
147
|
var json = JSON.parse(content)
|
|
148
148
|
|
|
149
149
|
if (json.asset === undefined || json.asset.version[0] < 2) {
|
|
150
|
-
if (onError)
|
|
150
|
+
if (onError)
|
|
151
|
+
onError(
|
|
152
|
+
new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.')
|
|
153
|
+
)
|
|
151
154
|
return
|
|
152
155
|
}
|
|
153
156
|
|
|
@@ -155,7 +158,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
155
158
|
path: path || this.resourcePath || '',
|
|
156
159
|
crossOrigin: this.crossOrigin,
|
|
157
160
|
manager: this.manager,
|
|
158
|
-
ktx2Loader: this.ktx2Loader
|
|
161
|
+
ktx2Loader: this.ktx2Loader
|
|
159
162
|
})
|
|
160
163
|
|
|
161
164
|
parser.fileLoader.setRequestHeader(this.requestHeader)
|
|
@@ -186,7 +189,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
186
189
|
break
|
|
187
190
|
|
|
188
191
|
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
189
|
-
extensions[extensionName] = new GLTFDracoMeshCompressionExtension(
|
|
192
|
+
extensions[extensionName] = new GLTFDracoMeshCompressionExtension(
|
|
193
|
+
json,
|
|
194
|
+
this.dracoLoader
|
|
195
|
+
)
|
|
190
196
|
break
|
|
191
197
|
|
|
192
198
|
case EXTENSIONS.MSFT_TEXTURE_DDS:
|
|
@@ -202,7 +208,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
202
208
|
break
|
|
203
209
|
|
|
204
210
|
default:
|
|
205
|
-
if (
|
|
211
|
+
if (
|
|
212
|
+
extensionsRequired.indexOf(extensionName) >= 0 &&
|
|
213
|
+
plugins[extensionName] === undefined
|
|
214
|
+
) {
|
|
206
215
|
// console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".')
|
|
207
216
|
}
|
|
208
217
|
}
|
|
@@ -212,7 +221,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
212
221
|
parser.setExtensions(extensions)
|
|
213
222
|
parser.setPlugins(plugins)
|
|
214
223
|
parser.parse(onLoad, onError)
|
|
215
|
-
}
|
|
224
|
+
}
|
|
216
225
|
})
|
|
217
226
|
|
|
218
227
|
/* GLTFREGISTRY */
|
|
@@ -235,7 +244,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
235
244
|
|
|
236
245
|
removeAll: function () {
|
|
237
246
|
objects = {}
|
|
238
|
-
}
|
|
247
|
+
}
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
250
|
|
|
@@ -254,7 +263,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
254
263
|
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
|
|
255
264
|
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
|
256
265
|
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
|
257
|
-
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
|
266
|
+
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
/**
|
|
@@ -265,7 +274,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
265
274
|
*/
|
|
266
275
|
function GLTFTextureDDSExtension(ddsLoader) {
|
|
267
276
|
if (!ddsLoader) {
|
|
268
|
-
throw new Error(
|
|
277
|
+
throw new Error(
|
|
278
|
+
'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader'
|
|
279
|
+
)
|
|
269
280
|
}
|
|
270
281
|
|
|
271
282
|
this.name = EXTENSIONS.MSFT_TEXTURE_DDS
|
|
@@ -292,7 +303,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
292
303
|
for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
|
293
304
|
var nodeDef = nodeDefs[nodeIndex]
|
|
294
305
|
|
|
295
|
-
if (
|
|
306
|
+
if (
|
|
307
|
+
nodeDef.extensions &&
|
|
308
|
+
nodeDef.extensions[this.name] &&
|
|
309
|
+
nodeDef.extensions[this.name].light !== undefined
|
|
310
|
+
) {
|
|
296
311
|
parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light)
|
|
297
312
|
}
|
|
298
313
|
}
|
|
@@ -334,7 +349,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
334
349
|
lightNode.distance = range
|
|
335
350
|
// Handle spotlight properties.
|
|
336
351
|
lightDef.spot = lightDef.spot || {}
|
|
337
|
-
lightDef.spot.innerConeAngle =
|
|
352
|
+
lightDef.spot.innerConeAngle =
|
|
353
|
+
lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0
|
|
338
354
|
lightDef.spot.outerConeAngle =
|
|
339
355
|
lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0
|
|
340
356
|
lightNode.angle = lightDef.spot.outerConeAngle
|
|
@@ -392,7 +408,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
392
408
|
return THREE.MeshBasicMaterial
|
|
393
409
|
}
|
|
394
410
|
|
|
395
|
-
GLTFMaterialsUnlitExtension.prototype.extendParams = function (
|
|
411
|
+
GLTFMaterialsUnlitExtension.prototype.extendParams = function (
|
|
412
|
+
materialParams,
|
|
413
|
+
materialDef,
|
|
414
|
+
parser
|
|
415
|
+
) {
|
|
396
416
|
var pending = []
|
|
397
417
|
|
|
398
418
|
materialParams.color = new THREE.Color(1.0, 1.0, 1.0)
|
|
@@ -431,7 +451,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
431
451
|
return THREE.MeshPhysicalMaterial
|
|
432
452
|
}
|
|
433
453
|
|
|
434
|
-
GLTFMaterialsClearcoatExtension.prototype.extendMaterialParams = function (
|
|
454
|
+
GLTFMaterialsClearcoatExtension.prototype.extendMaterialParams = function (
|
|
455
|
+
materialIndex,
|
|
456
|
+
materialParams
|
|
457
|
+
) {
|
|
435
458
|
var parser = this.parser
|
|
436
459
|
var materialDef = parser.json.materials[materialIndex]
|
|
437
460
|
|
|
@@ -481,7 +504,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
481
504
|
return THREE.MeshPhysicalMaterial
|
|
482
505
|
}
|
|
483
506
|
|
|
484
|
-
GLTFMaterialsTransmissionExtension.prototype.extendMaterialParams = function (
|
|
507
|
+
GLTFMaterialsTransmissionExtension.prototype.extendMaterialParams = function (
|
|
508
|
+
materialIndex,
|
|
509
|
+
materialParams
|
|
510
|
+
) {
|
|
485
511
|
var parser = this.parser
|
|
486
512
|
var materialDef = parser.json.materials[materialIndex]
|
|
487
513
|
|
|
@@ -530,7 +556,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
530
556
|
this.header = {
|
|
531
557
|
magic: THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
|
|
532
558
|
version: headerView.getUint32(4, true),
|
|
533
|
-
length: headerView.getUint32(8, true)
|
|
559
|
+
length: headerView.getUint32(8, true)
|
|
534
560
|
}
|
|
535
561
|
|
|
536
562
|
if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
@@ -550,7 +576,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
550
576
|
chunkIndex += 4
|
|
551
577
|
|
|
552
578
|
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
553
|
-
var contentArray = new Uint8Array(
|
|
579
|
+
var contentArray = new Uint8Array(
|
|
580
|
+
data,
|
|
581
|
+
BINARY_EXTENSION_HEADER_LENGTH + chunkIndex,
|
|
582
|
+
chunkLength
|
|
583
|
+
)
|
|
554
584
|
this.content = THREE.LoaderUtils.decodeText(contentArray)
|
|
555
585
|
} else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
556
586
|
var byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex
|
|
@@ -655,7 +685,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
655
685
|
}
|
|
656
686
|
|
|
657
687
|
if (transform.texCoord !== undefined) {
|
|
658
|
-
console.warn(
|
|
688
|
+
console.warn(
|
|
689
|
+
'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.'
|
|
690
|
+
)
|
|
659
691
|
}
|
|
660
692
|
|
|
661
693
|
texture.needsUpdate = true
|
|
@@ -681,12 +713,16 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
681
713
|
this.isGLTFSpecularGlossinessMaterial = true
|
|
682
714
|
|
|
683
715
|
//various chunks that need replacing
|
|
684
|
-
var specularMapParsFragmentChunk = [
|
|
716
|
+
var specularMapParsFragmentChunk = [
|
|
717
|
+
'#ifdef USE_SPECULARMAP',
|
|
718
|
+
' uniform sampler2D specularMap;',
|
|
719
|
+
'#endif'
|
|
720
|
+
].join('\n')
|
|
685
721
|
|
|
686
722
|
var glossinessMapParsFragmentChunk = [
|
|
687
723
|
'#ifdef USE_GLOSSINESSMAP',
|
|
688
724
|
' uniform sampler2D glossinessMap;',
|
|
689
|
-
'#endif'
|
|
725
|
+
'#endif'
|
|
690
726
|
].join('\n')
|
|
691
727
|
|
|
692
728
|
var specularMapFragmentChunk = [
|
|
@@ -696,7 +732,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
696
732
|
' texelSpecular = sRGBToLinear( texelSpecular );',
|
|
697
733
|
' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture',
|
|
698
734
|
' specularFactor *= texelSpecular.rgb;',
|
|
699
|
-
'#endif'
|
|
735
|
+
'#endif'
|
|
700
736
|
].join('\n')
|
|
701
737
|
|
|
702
738
|
var glossinessMapFragmentChunk = [
|
|
@@ -705,7 +741,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
705
741
|
' vec4 texelGlossiness = texture2D( glossinessMap, vUv );',
|
|
706
742
|
' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture',
|
|
707
743
|
' glossinessFactor *= texelGlossiness.a;',
|
|
708
|
-
'#endif'
|
|
744
|
+
'#endif'
|
|
709
745
|
].join('\n')
|
|
710
746
|
|
|
711
747
|
var lightPhysicalFragmentChunk = [
|
|
@@ -716,14 +752,14 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
716
752
|
'material.specularRoughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.',
|
|
717
753
|
'material.specularRoughness += geometryRoughness;',
|
|
718
754
|
'material.specularRoughness = min( material.specularRoughness, 1.0 );',
|
|
719
|
-
'material.specularColor = specularFactor;'
|
|
755
|
+
'material.specularColor = specularFactor;'
|
|
720
756
|
].join('\n')
|
|
721
757
|
|
|
722
758
|
var uniforms = {
|
|
723
759
|
specular: { value: new THREE.Color().setHex(0xffffff) },
|
|
724
760
|
glossiness: { value: 1 },
|
|
725
761
|
specularMap: { value: null },
|
|
726
|
-
glossinessMap: { value: null }
|
|
762
|
+
glossinessMap: { value: null }
|
|
727
763
|
}
|
|
728
764
|
|
|
729
765
|
this._extraUniforms = uniforms
|
|
@@ -750,7 +786,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
750
786
|
},
|
|
751
787
|
set: function (v) {
|
|
752
788
|
uniforms.specular.value = v
|
|
753
|
-
}
|
|
789
|
+
}
|
|
754
790
|
},
|
|
755
791
|
|
|
756
792
|
specularMap: {
|
|
@@ -765,7 +801,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
765
801
|
} else {
|
|
766
802
|
delete this.defines.USE_SPECULARMAP
|
|
767
803
|
}
|
|
768
|
-
}
|
|
804
|
+
}
|
|
769
805
|
},
|
|
770
806
|
|
|
771
807
|
glossiness: {
|
|
@@ -774,7 +810,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
774
810
|
},
|
|
775
811
|
set: function (v) {
|
|
776
812
|
uniforms.glossiness.value = v
|
|
777
|
-
}
|
|
813
|
+
}
|
|
778
814
|
},
|
|
779
815
|
|
|
780
816
|
glossinessMap: {
|
|
@@ -791,8 +827,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
791
827
|
delete this.defines.USE_GLOSSINESSMAP
|
|
792
828
|
delete this.defines.USE_UV
|
|
793
829
|
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
796
832
|
})
|
|
797
833
|
|
|
798
834
|
delete this.metalness
|
|
@@ -847,7 +883,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
847
883
|
'alphaMap',
|
|
848
884
|
'envMap',
|
|
849
885
|
'envMapIntensity',
|
|
850
|
-
'refractionRatio'
|
|
886
|
+
'refractionRatio'
|
|
851
887
|
],
|
|
852
888
|
|
|
853
889
|
getMaterialType: function () {
|
|
@@ -871,7 +907,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
871
907
|
|
|
872
908
|
materialParams.emissive = new THREE.Color(0.0, 0.0, 0.0)
|
|
873
909
|
materialParams.glossiness =
|
|
874
|
-
pbrSpecularGlossiness.glossinessFactor !== undefined
|
|
910
|
+
pbrSpecularGlossiness.glossinessFactor !== undefined
|
|
911
|
+
? pbrSpecularGlossiness.glossinessFactor
|
|
912
|
+
: 1.0
|
|
875
913
|
materialParams.specular = new THREE.Color(1.0, 1.0, 1.0)
|
|
876
914
|
|
|
877
915
|
if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
|
|
@@ -897,12 +935,14 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
897
935
|
|
|
898
936
|
material.emissive = materialParams.emissive
|
|
899
937
|
material.emissiveIntensity = 1.0
|
|
900
|
-
material.emissiveMap =
|
|
938
|
+
material.emissiveMap =
|
|
939
|
+
materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap
|
|
901
940
|
|
|
902
941
|
material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap
|
|
903
942
|
material.bumpScale = 1
|
|
904
943
|
|
|
905
|
-
material.normalMap =
|
|
944
|
+
material.normalMap =
|
|
945
|
+
materialParams.normalMap === undefined ? null : materialParams.normalMap
|
|
906
946
|
material.normalMapType = THREE.TangentSpaceNormalMap
|
|
907
947
|
|
|
908
948
|
if (materialParams.normalScale) material.normalScale = materialParams.normalScale
|
|
@@ -911,10 +951,12 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
911
951
|
material.displacementScale = 1
|
|
912
952
|
material.displacementBias = 0
|
|
913
953
|
|
|
914
|
-
material.specularMap =
|
|
954
|
+
material.specularMap =
|
|
955
|
+
materialParams.specularMap === undefined ? null : materialParams.specularMap
|
|
915
956
|
material.specular = materialParams.specular
|
|
916
957
|
|
|
917
|
-
material.glossinessMap =
|
|
958
|
+
material.glossinessMap =
|
|
959
|
+
materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap
|
|
918
960
|
material.glossiness = materialParams.glossiness
|
|
919
961
|
|
|
920
962
|
material.alphaMap = null
|
|
@@ -925,7 +967,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
925
967
|
material.refractionRatio = 0.98
|
|
926
968
|
|
|
927
969
|
return material
|
|
928
|
-
}
|
|
970
|
+
}
|
|
929
971
|
}
|
|
930
972
|
}
|
|
931
973
|
|
|
@@ -967,9 +1009,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
967
1009
|
return result
|
|
968
1010
|
}
|
|
969
1011
|
|
|
970
|
-
GLTFCubicSplineInterpolant.prototype.beforeStart_ =
|
|
1012
|
+
GLTFCubicSplineInterpolant.prototype.beforeStart_ =
|
|
1013
|
+
GLTFCubicSplineInterpolant.prototype.copySampleValue_
|
|
971
1014
|
|
|
972
|
-
GLTFCubicSplineInterpolant.prototype.afterEnd_ =
|
|
1015
|
+
GLTFCubicSplineInterpolant.prototype.afterEnd_ =
|
|
1016
|
+
GLTFCubicSplineInterpolant.prototype.copySampleValue_
|
|
973
1017
|
|
|
974
1018
|
GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
|
|
975
1019
|
var result = this.resultBuffer
|
|
@@ -1032,7 +1076,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1032
1076
|
TRIANGLE_STRIP: 5,
|
|
1033
1077
|
TRIANGLE_FAN: 6,
|
|
1034
1078
|
UNSIGNED_BYTE: 5121,
|
|
1035
|
-
UNSIGNED_SHORT: 5123
|
|
1079
|
+
UNSIGNED_SHORT: 5123
|
|
1036
1080
|
}
|
|
1037
1081
|
|
|
1038
1082
|
var WEBGL_COMPONENT_TYPES = {
|
|
@@ -1041,7 +1085,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1041
1085
|
5122: Int16Array,
|
|
1042
1086
|
5123: Uint16Array,
|
|
1043
1087
|
5125: Uint32Array,
|
|
1044
|
-
5126: Float32Array
|
|
1088
|
+
5126: Float32Array
|
|
1045
1089
|
}
|
|
1046
1090
|
|
|
1047
1091
|
var WEBGL_FILTERS = {
|
|
@@ -1050,13 +1094,13 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1050
1094
|
9984: THREE.NearestMipmapNearestFilter,
|
|
1051
1095
|
9985: THREE.LinearMipmapNearestFilter,
|
|
1052
1096
|
9986: THREE.NearestMipmapLinearFilter,
|
|
1053
|
-
9987: THREE.LinearMipmapLinearFilter
|
|
1097
|
+
9987: THREE.LinearMipmapLinearFilter
|
|
1054
1098
|
}
|
|
1055
1099
|
|
|
1056
1100
|
var WEBGL_WRAPPINGS = {
|
|
1057
1101
|
33071: THREE.ClampToEdgeWrapping,
|
|
1058
1102
|
33648: THREE.MirroredRepeatWrapping,
|
|
1059
|
-
10497: THREE.RepeatWrapping
|
|
1103
|
+
10497: THREE.RepeatWrapping
|
|
1060
1104
|
}
|
|
1061
1105
|
|
|
1062
1106
|
var WEBGL_TYPE_SIZES = {
|
|
@@ -1066,7 +1110,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1066
1110
|
VEC4: 4,
|
|
1067
1111
|
MAT2: 4,
|
|
1068
1112
|
MAT3: 9,
|
|
1069
|
-
MAT4: 16
|
|
1113
|
+
MAT4: 16
|
|
1070
1114
|
}
|
|
1071
1115
|
|
|
1072
1116
|
var ATTRIBUTES = {
|
|
@@ -1077,27 +1121,27 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1077
1121
|
TEXCOORD_1: 'uv2',
|
|
1078
1122
|
COLOR_0: 'color',
|
|
1079
1123
|
WEIGHTS_0: 'skinWeight',
|
|
1080
|
-
JOINTS_0: 'skinIndex'
|
|
1124
|
+
JOINTS_0: 'skinIndex'
|
|
1081
1125
|
}
|
|
1082
1126
|
|
|
1083
1127
|
var PATH_PROPERTIES = {
|
|
1084
1128
|
scale: 'scale',
|
|
1085
1129
|
translation: 'position',
|
|
1086
1130
|
rotation: 'quaternion',
|
|
1087
|
-
weights: 'morphTargetInfluences'
|
|
1131
|
+
weights: 'morphTargetInfluences'
|
|
1088
1132
|
}
|
|
1089
1133
|
|
|
1090
1134
|
var INTERPOLATION = {
|
|
1091
1135
|
CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
1092
1136
|
// keyframe track will be initialized with a default interpolation type, then modified.
|
|
1093
1137
|
LINEAR: THREE.InterpolateLinear,
|
|
1094
|
-
STEP: THREE.InterpolateDiscrete
|
|
1138
|
+
STEP: THREE.InterpolateDiscrete
|
|
1095
1139
|
}
|
|
1096
1140
|
|
|
1097
1141
|
var ALPHA_MODES = {
|
|
1098
1142
|
OPAQUE: 'OPAQUE',
|
|
1099
1143
|
MASK: 'MASK',
|
|
1100
|
-
BLEND: 'BLEND'
|
|
1144
|
+
BLEND: 'BLEND'
|
|
1101
1145
|
}
|
|
1102
1146
|
|
|
1103
1147
|
/* UTILITY FUNCTIONS */
|
|
@@ -1136,7 +1180,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1136
1180
|
roughness: 1,
|
|
1137
1181
|
transparent: false,
|
|
1138
1182
|
depthTest: true,
|
|
1139
|
-
side: THREE.FrontSide
|
|
1183
|
+
side: THREE.FrontSide
|
|
1140
1184
|
})
|
|
1141
1185
|
}
|
|
1142
1186
|
|
|
@@ -1208,15 +1252,18 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1208
1252
|
|
|
1209
1253
|
if (hasMorphNormal) {
|
|
1210
1254
|
var pendingAccessor =
|
|
1211
|
-
target.NORMAL !== undefined
|
|
1255
|
+
target.NORMAL !== undefined
|
|
1256
|
+
? parser.getDependency('accessor', target.NORMAL)
|
|
1257
|
+
: geometry.attributes.normal
|
|
1212
1258
|
|
|
1213
1259
|
pendingNormalAccessors.push(pendingAccessor)
|
|
1214
1260
|
}
|
|
1215
1261
|
}
|
|
1216
1262
|
|
|
1217
|
-
return Promise.all([
|
|
1218
|
-
|
|
1219
|
-
|
|
1263
|
+
return Promise.all([
|
|
1264
|
+
Promise.all(pendingPositionAccessors),
|
|
1265
|
+
Promise.all(pendingNormalAccessors)
|
|
1266
|
+
]).then(function (accessors) {
|
|
1220
1267
|
var morphPositions = accessors[0]
|
|
1221
1268
|
var morphNormals = accessors[1]
|
|
1222
1269
|
|
|
@@ -1258,7 +1305,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1258
1305
|
}
|
|
1259
1306
|
|
|
1260
1307
|
function createPrimitiveKey(primitiveDef) {
|
|
1261
|
-
var dracoExtension =
|
|
1308
|
+
var dracoExtension =
|
|
1309
|
+
primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]
|
|
1262
1310
|
var geometryKey
|
|
1263
1311
|
|
|
1264
1312
|
if (dracoExtension) {
|
|
@@ -1270,7 +1318,12 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1270
1318
|
':' +
|
|
1271
1319
|
createAttributesKey(dracoExtension.attributes)
|
|
1272
1320
|
} else {
|
|
1273
|
-
geometryKey =
|
|
1321
|
+
geometryKey =
|
|
1322
|
+
primitiveDef.indices +
|
|
1323
|
+
':' +
|
|
1324
|
+
createAttributesKey(primitiveDef.attributes) +
|
|
1325
|
+
':' +
|
|
1326
|
+
primitiveDef.mode
|
|
1274
1327
|
}
|
|
1275
1328
|
|
|
1276
1329
|
return geometryKey
|
|
@@ -1352,7 +1405,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1352
1405
|
return ext._markDefs && ext._markDefs()
|
|
1353
1406
|
})
|
|
1354
1407
|
|
|
1355
|
-
Promise.all([
|
|
1408
|
+
Promise.all([
|
|
1409
|
+
this.getDependencies('scene'),
|
|
1410
|
+
this.getDependencies('animation'),
|
|
1411
|
+
this.getDependencies('camera')
|
|
1412
|
+
])
|
|
1356
1413
|
.then(function (dependencies) {
|
|
1357
1414
|
var result = {
|
|
1358
1415
|
scene: dependencies[0][json.scene || 0],
|
|
@@ -1361,7 +1418,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1361
1418
|
cameras: dependencies[2],
|
|
1362
1419
|
asset: json.asset,
|
|
1363
1420
|
parser: parser,
|
|
1364
|
-
userData: {}
|
|
1421
|
+
userData: {}
|
|
1365
1422
|
}
|
|
1366
1423
|
|
|
1367
1424
|
addUnknownExtensionsToUserData(extensions, result, json)
|
|
@@ -1628,8 +1685,12 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1628
1685
|
}
|
|
1629
1686
|
|
|
1630
1687
|
if (accessorDef.sparse !== undefined) {
|
|
1631
|
-
pendingBufferViews.push(
|
|
1632
|
-
|
|
1688
|
+
pendingBufferViews.push(
|
|
1689
|
+
this.getDependency('bufferView', accessorDef.sparse.indices.bufferView)
|
|
1690
|
+
)
|
|
1691
|
+
pendingBufferViews.push(
|
|
1692
|
+
this.getDependency('bufferView', accessorDef.sparse.values.bufferView)
|
|
1693
|
+
)
|
|
1633
1694
|
}
|
|
1634
1695
|
|
|
1635
1696
|
return Promise.all(pendingBufferViews).then(function (bufferViews) {
|
|
@@ -1643,7 +1704,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1643
1704
|
var itemBytes = elementBytes * itemSize
|
|
1644
1705
|
var byteOffset = accessorDef.byteOffset || 0
|
|
1645
1706
|
var byteStride =
|
|
1646
|
-
accessorDef.bufferView !== undefined
|
|
1707
|
+
accessorDef.bufferView !== undefined
|
|
1708
|
+
? json.bufferViews[accessorDef.bufferView].byteStride
|
|
1709
|
+
: undefined
|
|
1647
1710
|
var normalized = accessorDef.normalized === true
|
|
1648
1711
|
var array, bufferAttribute
|
|
1649
1712
|
|
|
@@ -1664,7 +1727,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1664
1727
|
var ib = parser.cache.get(ibCacheKey)
|
|
1665
1728
|
|
|
1666
1729
|
if (!ib) {
|
|
1667
|
-
array = new TypedArray(
|
|
1730
|
+
array = new TypedArray(
|
|
1731
|
+
bufferView,
|
|
1732
|
+
ibSlice * byteStride,
|
|
1733
|
+
(accessorDef.count * byteStride) / elementBytes
|
|
1734
|
+
)
|
|
1668
1735
|
|
|
1669
1736
|
// Integer parameters to IB/IBA are in array elements, not bytes.
|
|
1670
1737
|
ib = new THREE.InterleavedBuffer(array, byteStride / elementBytes)
|
|
@@ -1701,7 +1768,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1701
1768
|
byteOffsetIndices,
|
|
1702
1769
|
accessorDef.sparse.count * itemSizeIndices
|
|
1703
1770
|
)
|
|
1704
|
-
var sparseValues = new TypedArray(
|
|
1771
|
+
var sparseValues = new TypedArray(
|
|
1772
|
+
bufferViews[2],
|
|
1773
|
+
byteOffsetValues,
|
|
1774
|
+
accessorDef.sparse.count * itemSize
|
|
1775
|
+
)
|
|
1705
1776
|
|
|
1706
1777
|
if (bufferView !== null) {
|
|
1707
1778
|
// Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
|
|
@@ -1719,7 +1790,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1719
1790
|
if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1])
|
|
1720
1791
|
if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2])
|
|
1721
1792
|
if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3])
|
|
1722
|
-
if (itemSize >= 5)
|
|
1793
|
+
if (itemSize >= 5)
|
|
1794
|
+
throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.')
|
|
1723
1795
|
}
|
|
1724
1796
|
}
|
|
1725
1797
|
|
|
@@ -1821,7 +1893,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1821
1893
|
|
|
1822
1894
|
// workarounds for mesh and geometry
|
|
1823
1895
|
|
|
1824
|
-
if (
|
|
1896
|
+
if (
|
|
1897
|
+
material.aoMap &&
|
|
1898
|
+
geometry.attributes.uv2 === undefined &&
|
|
1899
|
+
geometry.attributes.uv !== undefined
|
|
1900
|
+
) {
|
|
1825
1901
|
geometry.setAttribute('uv2', geometry.attributes.uv)
|
|
1826
1902
|
}
|
|
1827
1903
|
|
|
@@ -1882,7 +1958,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1882
1958
|
materialParams.opacity = array[3]
|
|
1883
1959
|
}
|
|
1884
1960
|
|
|
1885
|
-
materialParams.metalness =
|
|
1961
|
+
materialParams.metalness =
|
|
1962
|
+
metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0
|
|
1886
1963
|
materialParams.roughness =
|
|
1887
1964
|
metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0
|
|
1888
1965
|
|
|
@@ -1893,7 +1970,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1893
1970
|
pending.push(
|
|
1894
1971
|
Promise.all(
|
|
1895
1972
|
this._invokeAll(function (ext) {
|
|
1896
|
-
return
|
|
1973
|
+
return (
|
|
1974
|
+
ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams)
|
|
1975
|
+
)
|
|
1897
1976
|
})
|
|
1898
1977
|
)
|
|
1899
1978
|
)
|
|
@@ -1914,7 +1993,8 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1914
1993
|
materialParams.transparent = false
|
|
1915
1994
|
|
|
1916
1995
|
if (alphaMode === ALPHA_MODES.MASK) {
|
|
1917
|
-
materialParams.alphaTest =
|
|
1996
|
+
materialParams.alphaTest =
|
|
1997
|
+
materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5
|
|
1918
1998
|
}
|
|
1919
1999
|
}
|
|
1920
2000
|
|
|
@@ -1922,7 +2002,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1922
2002
|
materialParams.normalScale = new THREE.Vector2(1, 1)
|
|
1923
2003
|
|
|
1924
2004
|
if (materialDef.normalTexture.scale !== undefined) {
|
|
1925
|
-
materialParams.normalScale.set(
|
|
2005
|
+
materialParams.normalScale.set(
|
|
2006
|
+
materialDef.normalTexture.scale,
|
|
2007
|
+
materialDef.normalTexture.scale
|
|
2008
|
+
)
|
|
1926
2009
|
}
|
|
1927
2010
|
}
|
|
1928
2011
|
|
|
@@ -1940,7 +2023,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1940
2023
|
var material
|
|
1941
2024
|
|
|
1942
2025
|
if (materialType === GLTFMeshStandardSGMaterial) {
|
|
1943
|
-
material =
|
|
2026
|
+
material =
|
|
2027
|
+
extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(
|
|
2028
|
+
materialParams
|
|
2029
|
+
)
|
|
1944
2030
|
} else {
|
|
1945
2031
|
material = new materialType(materialParams)
|
|
1946
2032
|
}
|
|
@@ -1995,7 +2081,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
1995
2081
|
// glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
|
|
1996
2082
|
|
|
1997
2083
|
if (min !== undefined && max !== undefined) {
|
|
1998
|
-
box.set(
|
|
2084
|
+
box.set(
|
|
2085
|
+
new THREE.Vector3(min[0], min[1], min[2]),
|
|
2086
|
+
new THREE.Vector3(max[0], max[1], max[2])
|
|
2087
|
+
)
|
|
1999
2088
|
} else {
|
|
2000
2089
|
console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.')
|
|
2001
2090
|
|
|
@@ -2079,9 +2168,11 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2079
2168
|
}
|
|
2080
2169
|
|
|
2081
2170
|
if (primitiveDef.indices !== undefined && !geometry.index) {
|
|
2082
|
-
var accessor = parser
|
|
2083
|
-
|
|
2084
|
-
|
|
2171
|
+
var accessor = parser
|
|
2172
|
+
.getDependency('accessor', primitiveDef.indices)
|
|
2173
|
+
.then(function (accessor) {
|
|
2174
|
+
geometry.setIndex(accessor)
|
|
2175
|
+
})
|
|
2085
2176
|
|
|
2086
2177
|
pending.push(accessor)
|
|
2087
2178
|
}
|
|
@@ -2091,7 +2182,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2091
2182
|
computeBounds(geometry, primitiveDef, parser)
|
|
2092
2183
|
|
|
2093
2184
|
return Promise.all(pending).then(function () {
|
|
2094
|
-
return primitiveDef.targets !== undefined
|
|
2185
|
+
return primitiveDef.targets !== undefined
|
|
2186
|
+
? addMorphTargets(geometry, primitiveDef.targets, parser)
|
|
2187
|
+
: geometry
|
|
2095
2188
|
})
|
|
2096
2189
|
}
|
|
2097
2190
|
|
|
@@ -2118,7 +2211,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2118
2211
|
geometry.setIndex(indices)
|
|
2119
2212
|
index = geometry.getIndex()
|
|
2120
2213
|
} else {
|
|
2121
|
-
console.error(
|
|
2214
|
+
console.error(
|
|
2215
|
+
'THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.'
|
|
2216
|
+
)
|
|
2122
2217
|
return geometry
|
|
2123
2218
|
}
|
|
2124
2219
|
}
|
|
@@ -2153,7 +2248,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2153
2248
|
}
|
|
2154
2249
|
|
|
2155
2250
|
if (newIndices.length / 3 !== numberOfTriangles) {
|
|
2156
|
-
console.error(
|
|
2251
|
+
console.error(
|
|
2252
|
+
'THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.'
|
|
2253
|
+
)
|
|
2157
2254
|
}
|
|
2158
2255
|
|
|
2159
2256
|
// build final geometry
|
|
@@ -2399,8 +2496,14 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2399
2496
|
var sampler = animationDef.samplers[channel.sampler]
|
|
2400
2497
|
var target = channel.target
|
|
2401
2498
|
var name = target.node !== undefined ? target.node : target.id // NOTE: target.id is deprecated.
|
|
2402
|
-
var input =
|
|
2403
|
-
|
|
2499
|
+
var input =
|
|
2500
|
+
animationDef.parameters !== undefined
|
|
2501
|
+
? animationDef.parameters[sampler.input]
|
|
2502
|
+
: sampler.input
|
|
2503
|
+
var output =
|
|
2504
|
+
animationDef.parameters !== undefined
|
|
2505
|
+
? animationDef.parameters[sampler.output]
|
|
2506
|
+
: sampler.output
|
|
2404
2507
|
|
|
2405
2508
|
pendingNodes.push(this.getDependency('node', name))
|
|
2406
2509
|
pendingInputAccessors.push(this.getDependency('accessor', input))
|
|
@@ -2414,7 +2517,7 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2414
2517
|
Promise.all(pendingInputAccessors),
|
|
2415
2518
|
Promise.all(pendingOutputAccessors),
|
|
2416
2519
|
Promise.all(pendingSamplers),
|
|
2417
|
-
Promise.all(pendingTargets)
|
|
2520
|
+
Promise.all(pendingTargets)
|
|
2418
2521
|
]).then(function (dependencies) {
|
|
2419
2522
|
var nodes = dependencies[0]
|
|
2420
2523
|
var inputAccessors = dependencies[1]
|
|
@@ -2457,7 +2560,9 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2457
2560
|
var targetName = node.name ? node.name : node.uuid
|
|
2458
2561
|
|
|
2459
2562
|
var interpolation =
|
|
2460
|
-
sampler.interpolation !== undefined
|
|
2563
|
+
sampler.interpolation !== undefined
|
|
2564
|
+
? INTERPOLATION[sampler.interpolation]
|
|
2565
|
+
: THREE.InterpolateLinear
|
|
2461
2566
|
|
|
2462
2567
|
var targetNames = []
|
|
2463
2568
|
|
|
@@ -2669,7 +2774,10 @@ const GLTFLoader = (THREE.GLTFLoader = (function () {
|
|
|
2669
2774
|
|
|
2670
2775
|
boneInverses.push(mat)
|
|
2671
2776
|
} else {
|
|
2672
|
-
console.warn(
|
|
2777
|
+
console.warn(
|
|
2778
|
+
'THREE.GLTFLoader: Joint "%s" could not be found.',
|
|
2779
|
+
skinEntry.joints[j]
|
|
2780
|
+
)
|
|
2673
2781
|
}
|
|
2674
2782
|
}
|
|
2675
2783
|
|
package/src/index.js
CHANGED
|
@@ -2,14 +2,16 @@ import 'jsdom-global'
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import transform from './utils/transform.js'
|
|
5
|
-
|
|
5
|
+
// import { GLTFLoader, DRACOLoader } from 'three-stdlib'
|
|
6
6
|
import * as prettier from 'prettier'
|
|
7
7
|
import THREE from 'three'
|
|
8
|
+
|
|
8
9
|
global.THREE = THREE
|
|
9
10
|
|
|
10
11
|
import './bin/GLTFLoader.js'
|
|
11
12
|
import DracoLoader from './bin/DRACOLoader.js'
|
|
12
13
|
THREE.DRACOLoader.getDecoderModule = () => {}
|
|
14
|
+
|
|
13
15
|
import parse from './utils/parser.js'
|
|
14
16
|
|
|
15
17
|
const gltfLoader = new THREE.GLTFLoader()
|
|
@@ -49,6 +51,7 @@ export default function (file, output, options) {
|
|
|
49
51
|
const filePath = getRelativeFilePath(file)
|
|
50
52
|
const data = fs.readFileSync(file)
|
|
51
53
|
const arrayBuffer = toArrayBuffer(data)
|
|
54
|
+
|
|
52
55
|
gltfLoader.parse(
|
|
53
56
|
arrayBuffer,
|
|
54
57
|
'',
|
package/src/utils/parser.js
CHANGED
|
@@ -183,7 +183,11 @@ function parse(fileName, gltf, options = {}) {
|
|
|
183
183
|
result += `position={[${rNbr(obj.position.x)}, ${rNbr(obj.position.y)}, ${rNbr(
|
|
184
184
|
obj.position.z
|
|
185
185
|
)},]} `
|
|
186
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
obj.rotation &&
|
|
188
|
+
obj.rotation.isEuler &&
|
|
189
|
+
rNbr(new THREE.Vector3(...obj.rotation.toArray()).length())
|
|
190
|
+
)
|
|
187
191
|
result += `rotation={[${rDeg(obj.rotation.x)}, ${rDeg(obj.rotation.y)}, ${rDeg(
|
|
188
192
|
obj.rotation.z
|
|
189
193
|
)},]} `
|
|
@@ -467,6 +471,31 @@ function parse(fileName, gltf, options = {}) {
|
|
|
467
471
|
}
|
|
468
472
|
: undefined
|
|
469
473
|
|
|
474
|
+
const imports = `
|
|
475
|
+
${options.types ? `\nimport type * as THREE from 'three'` : ''}
|
|
476
|
+
import { Group } from 'three'
|
|
477
|
+
import { ${[
|
|
478
|
+
'T',
|
|
479
|
+
options.types && !options.isolated ? 'type Props, type Events, type Slots' : '',
|
|
480
|
+
!options.isolated && 'forwardEventHandlers'
|
|
481
|
+
]
|
|
482
|
+
.filter(Boolean)
|
|
483
|
+
.join(', ')} } from '@threlte/core'
|
|
484
|
+
import { ${[
|
|
485
|
+
'useGltf',
|
|
486
|
+
hasAnimations ? 'useGltfAnimations' : '',
|
|
487
|
+
options.suspense ? 'useSuspense' : ''
|
|
488
|
+
]
|
|
489
|
+
.filter(Boolean)
|
|
490
|
+
.join(', ')} } from '@threlte/extras'
|
|
491
|
+
`
|
|
492
|
+
|
|
493
|
+
const useGltf = `${options.suspense ? 'suspend(' : ''}useGltf${
|
|
494
|
+
options.types ? '<GLTFResult>' : ''
|
|
495
|
+
}('${url}'${useGltfOptions ? `, ${JSON.stringify(useGltfOptions)}` : ''})${
|
|
496
|
+
options.suspense ? ')' : ''
|
|
497
|
+
}`
|
|
498
|
+
|
|
470
499
|
// Output
|
|
471
500
|
return `
|
|
472
501
|
<!--
|
|
@@ -477,29 +506,44 @@ ${
|
|
|
477
506
|
}
|
|
478
507
|
${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
|
|
479
508
|
|
|
480
|
-
|
|
509
|
+
${
|
|
510
|
+
options.preload
|
|
511
|
+
? `
|
|
481
512
|
|
|
513
|
+
<script context="module"${options.types ? ' lang="ts"' : ''}>
|
|
514
|
+
${imports}
|
|
482
515
|
|
|
483
|
-
|
|
484
|
-
import { Group } from 'three'
|
|
485
|
-
import { ${['T', options.types ? 'type Props, type Events, type Slots' : ''].join(
|
|
486
|
-
', '
|
|
487
|
-
)} } from '@threlte/core'
|
|
488
|
-
import { ${['useGltf', hasAnimations ? 'useGltfAnimations' : ''].join(
|
|
489
|
-
', '
|
|
490
|
-
)} } from '@threlte/extras'
|
|
516
|
+
${options.types ? printThrelteTypes(objects, animations) : ''}
|
|
491
517
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
518
|
+
const load = () => {
|
|
519
|
+
${options.suspense ? 'const suspend = useSuspense()' : ''}
|
|
520
|
+
return ${useGltf}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export const preload = async () => {
|
|
524
|
+
await load()
|
|
525
|
+
}
|
|
526
|
+
</script>
|
|
527
|
+
`
|
|
528
|
+
: ''
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
<script${options.types ? ' lang="ts"' : ''}>
|
|
533
|
+
|
|
534
|
+
${!options.preload ? imports : ''}
|
|
535
|
+
|
|
536
|
+
${options.types && !options.isolated ? 'type $$Props = Props<THREE.Group>' : ''}
|
|
537
|
+
${options.types && !options.isolated ? 'type $$Events = Events<THREE.Group>' : ''}
|
|
538
|
+
${options.types && !options.isolated ? 'type $$Slots = Slots<THREE.Group>' : ''}
|
|
495
539
|
|
|
496
540
|
export const ref = new Group()
|
|
497
541
|
|
|
498
|
-
|
|
542
|
+
${!options.preload && options.suspense ? 'const suspend = useSuspense()' : ''}
|
|
499
543
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
544
|
+
${options.types && !options.preload ? printThrelteTypes(objects, animations) : ''}
|
|
545
|
+
|
|
546
|
+
${!options.preload ? `const gltf = ${useGltf}` : 'const gltf = load()'}
|
|
503
547
|
${
|
|
504
548
|
hasAnimations
|
|
505
549
|
? `export const { actions, mixer } = useGltfAnimations${
|
|
@@ -508,15 +552,16 @@ ${parseExtras(gltf.parser.json.asset && gltf.parser.json.asset.extras)}-->
|
|
|
508
552
|
: ''
|
|
509
553
|
}
|
|
510
554
|
|
|
555
|
+
${!options.isolated ? 'const component = forwardEventHandlers()' : ''}
|
|
511
556
|
</script>
|
|
512
557
|
|
|
513
|
-
|
|
514
|
-
|
|
558
|
+
<T is={ref} dispose={false} ${!options.isolated ? '{...$$restProps} bind:this={$component}' : ''}>
|
|
559
|
+
{#if $gltf}
|
|
515
560
|
${scene}
|
|
561
|
+
{/if}
|
|
516
562
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
{/if}
|
|
563
|
+
<slot {ref} />
|
|
564
|
+
</T>
|
|
520
565
|
`
|
|
521
566
|
}
|
|
522
567
|
|