@threlte/gltf 1.0.0-next.7 → 1.0.0-next.9
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 +2 -2
- package/src/bin/DRACOLoader.js +222 -0
- package/src/bin/GLTFLoader.js +2842 -0
- package/src/index.js +10 -6
- package/src/utils/parser.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 1.0.0-next.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 89710f3e: Removed logs
|
|
8
|
+
|
|
9
|
+
## 1.0.0-next.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 119a04d1: Downgrading three and reusing own GLTFLoader and DRACOLoader implementations
|
|
14
|
+
|
|
3
15
|
## 1.0.0-next.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
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.9",
|
|
4
4
|
"description": "GLTF to Threlte converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"prettier-plugin-svelte": "^2.9.0",
|
|
44
44
|
"sharp": "^0.31.3",
|
|
45
45
|
"svelte": "^3.55.1",
|
|
46
|
-
"three": "0.
|
|
46
|
+
"three": "0.122.0",
|
|
47
47
|
"three-stdlib": "^2.21.8"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import THREE from 'three'
|
|
3
|
+
import draco from 'draco3dgltf'
|
|
4
|
+
const decoder = draco.createDecoderModule()
|
|
5
|
+
const DRACOLoader = (THREE.DRACOLoader = function (t) {
|
|
6
|
+
;(this.timeLoaded = 0),
|
|
7
|
+
(this.manager = t || THREE.DefaultLoadingManager),
|
|
8
|
+
(this.materials = null),
|
|
9
|
+
(this.verbosity = 0),
|
|
10
|
+
(this.attributeOptions = {}),
|
|
11
|
+
(this.drawMode = THREE.TrianglesDrawMode),
|
|
12
|
+
(this.nativeAttributeMap = {
|
|
13
|
+
position: 'POSITION',
|
|
14
|
+
normal: 'NORMAL',
|
|
15
|
+
color: 'COLOR',
|
|
16
|
+
uv: 'TEX_COORD'
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export default DRACOLoader
|
|
21
|
+
|
|
22
|
+
THREE.DRACOLoader.prototype = {
|
|
23
|
+
constructor: THREE.DRACOLoader,
|
|
24
|
+
load: function (t, e, r, o) {
|
|
25
|
+
var i = this,
|
|
26
|
+
n = new THREE.FileLoader(i.manager)
|
|
27
|
+
n.setPath(this.path),
|
|
28
|
+
n.setResponseType('arraybuffer'),
|
|
29
|
+
n.load(
|
|
30
|
+
t,
|
|
31
|
+
function (t) {
|
|
32
|
+
i.decodeDracoFile(t, e)
|
|
33
|
+
},
|
|
34
|
+
r,
|
|
35
|
+
o
|
|
36
|
+
)
|
|
37
|
+
},
|
|
38
|
+
setPath: function (t) {
|
|
39
|
+
return (this.path = t), this
|
|
40
|
+
},
|
|
41
|
+
setVerbosity: function (t) {
|
|
42
|
+
return (this.verbosity = t), this
|
|
43
|
+
},
|
|
44
|
+
setDrawMode: function (t) {
|
|
45
|
+
return (this.drawMode = t), this
|
|
46
|
+
},
|
|
47
|
+
setSkipDequantization: function (t, e) {
|
|
48
|
+
var r = !0
|
|
49
|
+
return void 0 !== e && (r = e), (this.getAttributeOptions(t).skipDequantization = r), this
|
|
50
|
+
},
|
|
51
|
+
decodeDracoFile: function (t, e, r, o) {
|
|
52
|
+
decoder.then((decoder) => this.decodeDracoFileInternal(t, decoder, e, r, o))
|
|
53
|
+
},
|
|
54
|
+
decodeDracoFileInternal: function (t, e, r, o, i) {
|
|
55
|
+
var n = new e.DecoderBuffer()
|
|
56
|
+
n.Init(new Int8Array(t), t.byteLength)
|
|
57
|
+
var a = new e.Decoder(),
|
|
58
|
+
s = a.GetEncodedGeometryType(n)
|
|
59
|
+
if (s == e.TRIANGULAR_MESH) this.verbosity > 0 && console.log('Loaded a mesh.')
|
|
60
|
+
else {
|
|
61
|
+
if (s != e.POINT_CLOUD) {
|
|
62
|
+
var u = 'THREE.DRACOLoader: Unknown geometry type.'
|
|
63
|
+
//throw (console.error(u), new Error(u))
|
|
64
|
+
}
|
|
65
|
+
this.verbosity > 0 && console.log('Loaded a point cloud.')
|
|
66
|
+
}
|
|
67
|
+
r(this.convertDracoGeometryTo3JS(e, a, s, n, o, i))
|
|
68
|
+
},
|
|
69
|
+
addAttributeToGeometry: function (t, e, r, o, i, n, a, s) {
|
|
70
|
+
if (0 === n.ptr) {
|
|
71
|
+
var u = 'THREE.DRACOLoader: No attribute ' + o
|
|
72
|
+
throw (console.error(u), new Error(u))
|
|
73
|
+
}
|
|
74
|
+
var d,
|
|
75
|
+
A,
|
|
76
|
+
c = n.num_components(),
|
|
77
|
+
l = r.num_points() * c
|
|
78
|
+
switch (i) {
|
|
79
|
+
case Float32Array:
|
|
80
|
+
;(d = new t.DracoFloat32Array()),
|
|
81
|
+
e.GetAttributeFloatForAllPoints(r, n, d),
|
|
82
|
+
(s[o] = new Float32Array(l)),
|
|
83
|
+
(A = THREE.Float32BufferAttribute)
|
|
84
|
+
break
|
|
85
|
+
case Int8Array:
|
|
86
|
+
;(d = new t.DracoInt8Array()),
|
|
87
|
+
e.GetAttributeInt8ForAllPoints(r, n, d),
|
|
88
|
+
(s[o] = new Int8Array(l)),
|
|
89
|
+
(A = THREE.Int8BufferAttribute)
|
|
90
|
+
break
|
|
91
|
+
case Int16Array:
|
|
92
|
+
;(d = new t.DracoInt16Array()),
|
|
93
|
+
e.GetAttributeInt16ForAllPoints(r, n, d),
|
|
94
|
+
(s[o] = new Int16Array(l)),
|
|
95
|
+
(A = THREE.Int16BufferAttribute)
|
|
96
|
+
break
|
|
97
|
+
case Int32Array:
|
|
98
|
+
;(d = new t.DracoInt32Array()),
|
|
99
|
+
e.GetAttributeInt32ForAllPoints(r, n, d),
|
|
100
|
+
(s[o] = new Int32Array(l)),
|
|
101
|
+
(A = THREE.Int32BufferAttribute)
|
|
102
|
+
break
|
|
103
|
+
case Uint8Array:
|
|
104
|
+
;(d = new t.DracoUInt8Array()),
|
|
105
|
+
e.GetAttributeUInt8ForAllPoints(r, n, d),
|
|
106
|
+
(s[o] = new Uint8Array(l)),
|
|
107
|
+
(A = THREE.Uint8BufferAttribute)
|
|
108
|
+
break
|
|
109
|
+
case Uint16Array:
|
|
110
|
+
;(d = new t.DracoUInt16Array()),
|
|
111
|
+
e.GetAttributeUInt16ForAllPoints(r, n, d),
|
|
112
|
+
(s[o] = new Uint16Array(l)),
|
|
113
|
+
(A = THREE.Uint16BufferAttribute)
|
|
114
|
+
break
|
|
115
|
+
case Uint32Array:
|
|
116
|
+
;(d = new t.DracoUInt32Array()),
|
|
117
|
+
e.GetAttributeUInt32ForAllPoints(r, n, d),
|
|
118
|
+
(s[o] = new Uint32Array(l)),
|
|
119
|
+
(A = THREE.Uint32BufferAttribute)
|
|
120
|
+
break
|
|
121
|
+
default:
|
|
122
|
+
u = 'THREE.DRACOLoader: Unexpected attribute type.'
|
|
123
|
+
throw (console.error(u), new Error(u))
|
|
124
|
+
}
|
|
125
|
+
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
|
+
},
|
|
128
|
+
convertDracoGeometryTo3JS: function (t, e, r, o, i, n) {
|
|
129
|
+
var a, s, u
|
|
130
|
+
if (
|
|
131
|
+
(!0 === this.getAttributeOptions('position').skipDequantization &&
|
|
132
|
+
e.SkipAttributeTransform(t.POSITION),
|
|
133
|
+
r === t.TRIANGULAR_MESH
|
|
134
|
+
? ((a = new t.Mesh()), (s = e.DecodeBufferToMesh(o, a)))
|
|
135
|
+
: ((a = new t.PointCloud()), (s = e.DecodeBufferToPointCloud(o, a))),
|
|
136
|
+
!s.ok() || 0 == a.ptr)
|
|
137
|
+
) {
|
|
138
|
+
return new THREE.BufferGeometry()
|
|
139
|
+
var d = 'THREE.DRACOLoader: Decoding failed: '
|
|
140
|
+
throw ((d += s.error_msg()), console.error(d), t.destroy(e), t.destroy(a), new Error(d))
|
|
141
|
+
}
|
|
142
|
+
t.destroy(o),
|
|
143
|
+
r == t.TRIANGULAR_MESH
|
|
144
|
+
? ((u = a.num_faces()),
|
|
145
|
+
this.verbosity > 0 && console.log('Number of faces loaded: ' + u.toString()))
|
|
146
|
+
: (u = 0)
|
|
147
|
+
var A = a.num_points(),
|
|
148
|
+
c = a.num_attributes()
|
|
149
|
+
this.verbosity > 0 &&
|
|
150
|
+
(console.log('Number of points loaded: ' + A.toString()),
|
|
151
|
+
console.log('Number of attributes loaded: ' + c.toString()))
|
|
152
|
+
var l = e.GetAttributeId(a, t.POSITION)
|
|
153
|
+
if (-1 == l) {
|
|
154
|
+
d = 'THREE.DRACOLoader: No position attribute found.'
|
|
155
|
+
throw (console.error(d), t.destroy(e), t.destroy(a), new Error(d))
|
|
156
|
+
}
|
|
157
|
+
var b = e.GetAttribute(a, l),
|
|
158
|
+
f = {},
|
|
159
|
+
y = new THREE.BufferGeometry()
|
|
160
|
+
if (i)
|
|
161
|
+
for (var E in i) {
|
|
162
|
+
var h = n[E],
|
|
163
|
+
w = i[E],
|
|
164
|
+
p = e.GetAttributeByUniqueId(a, w)
|
|
165
|
+
//this.addAttributeToGeometry(t, e, a, E, h, p, y, f)
|
|
166
|
+
}
|
|
167
|
+
else
|
|
168
|
+
for (var E in this.nativeAttributeMap) {
|
|
169
|
+
var T = e.GetAttributeId(a, t[this.nativeAttributeMap[E]])
|
|
170
|
+
if (-1 !== T) {
|
|
171
|
+
this.verbosity > 0 && console.log('Loaded ' + E + ' attribute.')
|
|
172
|
+
p = e.GetAttribute(a, T)
|
|
173
|
+
//this.addAttributeToGeometry(t, e, a, E, Float32Array, p, y, f)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (r == t.TRIANGULAR_MESH)
|
|
177
|
+
if (this.drawMode === THREE.TriangleStripDrawMode) {
|
|
178
|
+
var R = new t.DracoInt32Array()
|
|
179
|
+
e.GetTriangleStripsFromMesh(a, R)
|
|
180
|
+
f.indices = new Uint32Array(R.size())
|
|
181
|
+
for (var I = 0; I < R.size(); ++I) f.indices[I] = R.GetValue(I)
|
|
182
|
+
t.destroy(R)
|
|
183
|
+
} else {
|
|
184
|
+
var v = 3 * u
|
|
185
|
+
f.indices = new Uint32Array(v)
|
|
186
|
+
var D = new t.DracoInt32Array()
|
|
187
|
+
for (I = 0; I < u; ++I) {
|
|
188
|
+
e.GetFaceFromMesh(a, I, D)
|
|
189
|
+
var m = 3 * I
|
|
190
|
+
;(f.indices[m] = D.GetValue(0)),
|
|
191
|
+
(f.indices[m + 1] = D.GetValue(1)),
|
|
192
|
+
(f.indices[m + 2] = D.GetValue(2))
|
|
193
|
+
}
|
|
194
|
+
t.destroy(D)
|
|
195
|
+
}
|
|
196
|
+
;(y.drawMode = this.drawMode),
|
|
197
|
+
r == t.TRIANGULAR_MESH &&
|
|
198
|
+
y.setIndex(
|
|
199
|
+
new (f.indices.length > 65535
|
|
200
|
+
? THREE.Uint32BufferAttribute
|
|
201
|
+
: THREE.Uint16BufferAttribute)(f.indices, 1)
|
|
202
|
+
)
|
|
203
|
+
var G = new t.AttributeQuantizationTransform()
|
|
204
|
+
if (G.InitFromAttribute(b)) {
|
|
205
|
+
;(y.attributes.position.isQuantized = !0),
|
|
206
|
+
(y.attributes.position.maxRange = G.range()),
|
|
207
|
+
(y.attributes.position.numQuantizationBits = G.quantization_bits()),
|
|
208
|
+
(y.attributes.position.minValues = new Float32Array(3))
|
|
209
|
+
for (I = 0; I < 3; ++I) y.attributes.position.minValues[I] = G.min_value(I)
|
|
210
|
+
}
|
|
211
|
+
return t.destroy(G), t.destroy(e), t.destroy(a), y
|
|
212
|
+
},
|
|
213
|
+
isVersionSupported: function (t, e) {
|
|
214
|
+
e(decoder.isVersionSupported(t))
|
|
215
|
+
},
|
|
216
|
+
getAttributeOptions: function (t) {
|
|
217
|
+
return (
|
|
218
|
+
void 0 === this.attributeOptions[t] && (this.attributeOptions[t] = {}),
|
|
219
|
+
this.attributeOptions[t]
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
}
|