@shopware-ag/dive 1.19.1-beta.2 → 1.19.1-beta.4
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/README.md +295 -362
- package/build/chunks/PerspectiveCamera-ACx6umAu.mjs +38 -0
- package/build/chunks/PerspectiveCamera-ACx6umAu.mjs.map +1 -0
- package/build/chunks/PerspectiveCamera-BXPNOM71.cjs +2 -0
- package/build/chunks/PerspectiveCamera-BXPNOM71.cjs.map +1 -0
- package/build/chunks/fflate.module-DHdJvhNh.cjs +7 -0
- package/build/chunks/fflate.module-DHdJvhNh.cjs.map +1 -0
- package/build/chunks/fflate.module-DkZg07PZ.mjs +603 -0
- package/build/chunks/fflate.module-DkZg07PZ.mjs.map +1 -0
- package/build/chunks/file-type-error-D6aWGgyc.mjs +15 -0
- package/build/chunks/file-type-error-D6aWGgyc.mjs.map +1 -0
- package/build/chunks/file-type-error-DtvBgs64.cjs +2 -0
- package/build/chunks/file-type-error-DtvBgs64.cjs.map +1 -0
- package/build/chunks/index-C7Wx_9uY.mjs +34 -0
- package/build/chunks/index-C7Wx_9uY.mjs.map +1 -0
- package/build/chunks/index-MNP0K5dt.cjs +2 -0
- package/build/chunks/index-MNP0K5dt.cjs.map +1 -0
- package/build/chunks/network-error-C2ZDC8qS.cjs +2 -0
- package/build/chunks/network-error-C2ZDC8qS.cjs.map +1 -0
- package/build/chunks/network-error-DgecatEk.mjs +27 -0
- package/build/chunks/network-error-DgecatEk.mjs.map +1 -0
- package/build/index.cjs +57 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.mjs +6884 -0
- package/build/index.mjs.map +1 -0
- package/build/src/animation/AnimationSystem.d.ts +1 -1
- package/build/src/axiscamera/AxisCamera.d.ts +2 -2
- package/build/src/com/Communication.d.ts +5 -8
- package/build/src/com/actions/scene/exportscene.d.ts +1 -1
- package/build/src/com/actions/scene/launchar.d.ts +1 -1
- package/build/src/controls/OrbitControls.d.ts +2 -2
- package/build/src/dive.d.ts +12 -29
- package/build/src/engine/Engine.d.ts +32 -0
- package/build/src/{camera → engine/camera}/PerspectiveCamera.d.ts +1 -1
- package/build/src/{scene → engine/scene}/Scene.d.ts +4 -4
- package/build/src/{scene → engine/scene}/root/Root.d.ts +2 -3
- package/build/src/error/ar-compatibility/ar-compatibility-error.d.ts +12 -0
- package/build/src/error/file-type/file-type-error.d.ts +4 -0
- package/build/src/error/index.d.ts +4 -0
- package/build/src/error/network/network-error.d.ts +5 -0
- package/build/src/error/parse/parse-error.d.ts +4 -0
- package/build/src/helper/findSceneRecursive/findSceneRecursive.d.ts +1 -1
- package/build/src/helper/getFileTypeFromUri/getFileTypeFromUri.d.ts +6 -0
- package/build/src/helper/index.d.ts +7 -0
- package/build/src/helper/isFileTypeSupported/isFileTypeSupported.d.ts +7 -0
- package/build/src/index.d.ts +2 -0
- package/build/src/math/index.d.ts +1 -1
- package/build/src/modules/_system/Module.d.ts +13 -0
- package/build/src/modules/_system/ModuleRegistry.d.ts +29 -0
- package/build/src/modules/ar/ARSystem.cjs +2 -0
- package/build/src/modules/ar/ARSystem.cjs.map +1 -0
- package/build/src/{ar/AR.d.ts → modules/ar/ARSystem.d.ts} +26 -0
- package/build/src/modules/ar/ARSystem.mjs +164 -0
- package/build/src/modules/ar/ARSystem.mjs.map +1 -0
- package/build/src/{ar → modules/ar}/arquicklook/ARQuickLook.d.ts +2 -1
- package/build/src/{ar → modules/ar}/sceneviewer/SceneViewer.d.ts +1 -1
- package/build/src/{ar → modules/ar}/webxr/WebXR.d.ts +3 -3
- package/build/src/{ar → modules/ar}/webxr/controller/WebXRController.d.ts +2 -2
- package/build/src/{ar → modules/ar}/webxr/origin/WebXROrigin.d.ts +1 -1
- package/build/src/{ar → modules/ar}/webxr/raycaster/WebXRRaycaster.d.ts +3 -3
- package/build/src/{ar → modules/ar}/webxr/raycaster/ar/WebXRRaycasterAR.d.ts +1 -1
- package/build/src/{ar → modules/ar}/webxr/raycaster/three/WebXRRaycasterTHREE.d.ts +2 -2
- package/build/src/{ar → modules/ar}/webxr/touchscreencontrols/WebXRTouchscreenControls.d.ts +1 -1
- package/build/src/modules/asset/converter/AssetConverter.cjs +2 -0
- package/build/src/modules/asset/converter/AssetConverter.cjs.map +1 -0
- package/build/src/modules/asset/converter/AssetConverter.d.ts +29 -0
- package/build/src/modules/asset/converter/AssetConverter.mjs +22 -0
- package/build/src/modules/asset/converter/AssetConverter.mjs.map +1 -0
- package/build/src/modules/asset/exporter/AssetExporter.cjs +165 -0
- package/build/src/modules/asset/exporter/AssetExporter.cjs.map +1 -0
- package/build/src/{exporter/Exporter.d.ts → modules/asset/exporter/AssetExporter.d.ts} +7 -2
- package/build/src/modules/asset/exporter/AssetExporter.mjs +1622 -0
- package/build/src/modules/asset/exporter/AssetExporter.mjs.map +1 -0
- package/build/src/modules/asset/loader/AssetLoader.cjs +3 -0
- package/build/src/modules/asset/loader/AssetLoader.cjs.map +1 -0
- package/build/src/modules/asset/loader/AssetLoader.d.ts +33 -0
- package/build/src/modules/asset/loader/AssetLoader.mjs +1924 -0
- package/build/src/modules/asset/loader/AssetLoader.mjs.map +1 -0
- package/build/src/modules/index.d.ts +10 -0
- package/build/src/modules/mediacreator/MediaCreator.cjs +2 -0
- package/build/src/modules/mediacreator/MediaCreator.cjs.map +1 -0
- package/build/src/modules/mediacreator/MediaCreator.d.ts +40 -0
- package/build/src/modules/mediacreator/MediaCreator.mjs +28 -0
- package/build/src/modules/mediacreator/MediaCreator.mjs.map +1 -0
- package/build/src/modules/systeminfo/SystemInfo.cjs +2 -0
- package/build/src/modules/systeminfo/SystemInfo.cjs.map +1 -0
- package/build/src/{info/Info.d.ts → modules/systeminfo/SystemInfo.d.ts} +40 -7
- package/build/src/modules/systeminfo/SystemInfo.mjs +115 -0
- package/build/src/modules/systeminfo/SystemInfo.mjs.map +1 -0
- package/build/src/toolbox/BaseTool.d.ts +1 -1
- package/build/src/toolbox/Toolbox.d.ts +1 -1
- package/build/src/toolbox/select/SelectTool.d.ts +1 -1
- package/build/src/toolbox/transform/TransformTool.d.ts +1 -1
- package/build/src/types/file/FileTypes.d.ts +1 -2
- package/build/src/types/index.d.ts +1 -0
- package/package.json +17 -21
- package/build/dive.cjs +0 -4025
- package/build/dive.cjs.map +0 -1
- package/build/dive.d.ts +0 -6
- package/build/dive.js +0 -4025
- package/build/dive.js.map +0 -1
- package/build/dive.mjs +0 -28200
- package/build/dive.mjs.map +0 -1
- package/build/src/converter/Converter.d.ts +0 -12
- package/build/src/io/IO.d.ts +0 -10
- package/build/src/io/gltf/GLTFIO.d.ts +0 -12
- package/build/src/loader/Loader.d.ts +0 -7
- package/build/src/mediacreator/MediaCreator.d.ts +0 -17
- package/build/src/module/Module.d.ts +0 -8
- package/build/src/types/error/index.d.ts +0 -12
- /package/build/src/{renderer → engine/renderer}/Renderer.d.ts +0 -0
- /package/build/src/{scene → engine/scene}/xrroot/XRRoot.d.ts +0 -0
- /package/build/src/{scene → engine/scene}/xrroot/xrlightroot/XRLightRoot.d.ts +0 -0
- /package/build/src/{ar → modules/ar}/webxr/crosshair/WebXRCrosshair.d.ts +0 -0
- /package/build/src/{ar → modules/ar}/webxr/overlay/Overlay.d.ts +0 -0
|
@@ -0,0 +1,1622 @@
|
|
|
1
|
+
var Te = Object.defineProperty;
|
|
2
|
+
var Me = (n, e, s) => e in n ? Te(n, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[e] = s;
|
|
3
|
+
var Y = (n, e, s) => Me(n, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { PlaneGeometry as ye, ShaderMaterial as we, Uniform as Ee, SRGBColorSpace as ue, Mesh as be, PerspectiveCamera as Ae, Scene as Z, WebGLRenderer as Ie, CanvasTexture as Re, Color as _e, Matrix4 as le, Vector3 as B, Quaternion as Se, BufferAttribute as L, CompressedTexture as j, Source as Ne, NoColorSpace as fe, MathUtils as q, RGBAFormat as Le, DoubleSide as pe, PropertyBinding as H, InterpolateDiscrete as ve, NearestFilter as Ce, NearestMipmapNearestFilter as Ue, NearestMipmapLinearFilter as Fe, LinearFilter as $e, LinearMipmapNearestFilter as Oe, LinearMipmapLinearFilter as Pe, ClampToEdgeWrapping as De, RepeatWrapping as Ge, MirroredRepeatWrapping as ke, InterpolateLinear as ze } from "three";
|
|
5
|
+
import { a as he, z as Be } from "../../../../chunks/fflate.module-DkZg07PZ.mjs";
|
|
6
|
+
import { F as He, P as N } from "../../../../chunks/file-type-error-D6aWGgyc.mjs";
|
|
7
|
+
let O, K, C, G;
|
|
8
|
+
function z(n, e = 1 / 0, s = null) {
|
|
9
|
+
K || (K = new ye(2, 2, 1, 1)), C || (C = new we({
|
|
10
|
+
uniforms: { blitTexture: new Ee(n) },
|
|
11
|
+
vertexShader: `
|
|
12
|
+
varying vec2 vUv;
|
|
13
|
+
void main(){
|
|
14
|
+
vUv = uv;
|
|
15
|
+
gl_Position = vec4(position.xy * 1.0,0.,.999999);
|
|
16
|
+
}`,
|
|
17
|
+
fragmentShader: `
|
|
18
|
+
uniform sampler2D blitTexture;
|
|
19
|
+
varying vec2 vUv;
|
|
20
|
+
|
|
21
|
+
void main(){
|
|
22
|
+
gl_FragColor = vec4(vUv.xy, 0, 1);
|
|
23
|
+
|
|
24
|
+
#ifdef IS_SRGB
|
|
25
|
+
gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
|
|
26
|
+
#else
|
|
27
|
+
gl_FragColor = texture2D( blitTexture, vUv);
|
|
28
|
+
#endif
|
|
29
|
+
}`
|
|
30
|
+
})), C.uniforms.blitTexture.value = n, C.defines.IS_SRGB = n.colorSpace == ue, C.needsUpdate = !0, G || (G = new be(K, C), G.frustumCulled = !1);
|
|
31
|
+
const t = new Ae(), i = new Z();
|
|
32
|
+
i.add(G), s === null && (s = O = new Ie({ antialias: !1 }));
|
|
33
|
+
const r = Math.min(n.image.width, e), o = Math.min(n.image.height, e);
|
|
34
|
+
s.setSize(r, o), s.clear(), s.render(i, t);
|
|
35
|
+
const a = document.createElement("canvas"), c = a.getContext("2d");
|
|
36
|
+
a.width = r, a.height = o, c.drawImage(s.domElement, 0, 0, r, o);
|
|
37
|
+
const u = new Re(a);
|
|
38
|
+
return u.minFilter = n.minFilter, u.magFilter = n.magFilter, u.wrapS = n.wrapS, u.wrapT = n.wrapT, u.name = n.name, O && (O.forceContextLoss(), O.dispose(), O = null), u;
|
|
39
|
+
}
|
|
40
|
+
const te = {
|
|
41
|
+
POSITION: [
|
|
42
|
+
"byte",
|
|
43
|
+
"byte normalized",
|
|
44
|
+
"unsigned byte",
|
|
45
|
+
"unsigned byte normalized",
|
|
46
|
+
"short",
|
|
47
|
+
"short normalized",
|
|
48
|
+
"unsigned short",
|
|
49
|
+
"unsigned short normalized"
|
|
50
|
+
],
|
|
51
|
+
NORMAL: [
|
|
52
|
+
"byte normalized",
|
|
53
|
+
"short normalized"
|
|
54
|
+
],
|
|
55
|
+
TANGENT: [
|
|
56
|
+
"byte normalized",
|
|
57
|
+
"short normalized"
|
|
58
|
+
],
|
|
59
|
+
TEXCOORD: [
|
|
60
|
+
"byte",
|
|
61
|
+
"byte normalized",
|
|
62
|
+
"unsigned byte",
|
|
63
|
+
"short",
|
|
64
|
+
"short normalized",
|
|
65
|
+
"unsigned short"
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
class Q {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.pluginCallbacks = [], this.register(function(e) {
|
|
71
|
+
return new Qe(e);
|
|
72
|
+
}), this.register(function(e) {
|
|
73
|
+
return new et(e);
|
|
74
|
+
}), this.register(function(e) {
|
|
75
|
+
return new nt(e);
|
|
76
|
+
}), this.register(function(e) {
|
|
77
|
+
return new it(e);
|
|
78
|
+
}), this.register(function(e) {
|
|
79
|
+
return new rt(e);
|
|
80
|
+
}), this.register(function(e) {
|
|
81
|
+
return new ot(e);
|
|
82
|
+
}), this.register(function(e) {
|
|
83
|
+
return new tt(e);
|
|
84
|
+
}), this.register(function(e) {
|
|
85
|
+
return new st(e);
|
|
86
|
+
}), this.register(function(e) {
|
|
87
|
+
return new at(e);
|
|
88
|
+
}), this.register(function(e) {
|
|
89
|
+
return new ct(e);
|
|
90
|
+
}), this.register(function(e) {
|
|
91
|
+
return new ut(e);
|
|
92
|
+
}), this.register(function(e) {
|
|
93
|
+
return new lt(e);
|
|
94
|
+
}), this.register(function(e) {
|
|
95
|
+
return new ft(e);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
register(e) {
|
|
99
|
+
return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
|
|
100
|
+
}
|
|
101
|
+
unregister(e) {
|
|
102
|
+
return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parse scenes and generate GLTF output
|
|
106
|
+
* @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
|
|
107
|
+
* @param {Function} onDone Callback on completed
|
|
108
|
+
* @param {Function} onError Callback on errors
|
|
109
|
+
* @param {Object} options options
|
|
110
|
+
*/
|
|
111
|
+
parse(e, s, t, i) {
|
|
112
|
+
const r = new Je(), o = [];
|
|
113
|
+
for (let a = 0, c = this.pluginCallbacks.length; a < c; a++)
|
|
114
|
+
o.push(this.pluginCallbacks[a](r));
|
|
115
|
+
r.setPlugins(o), r.write(e, s, i).catch(t);
|
|
116
|
+
}
|
|
117
|
+
parseAsync(e, s) {
|
|
118
|
+
const t = this;
|
|
119
|
+
return new Promise(function(i, r) {
|
|
120
|
+
t.parse(e, i, r, s);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const T = {
|
|
125
|
+
POINTS: 0,
|
|
126
|
+
LINES: 1,
|
|
127
|
+
LINE_LOOP: 2,
|
|
128
|
+
LINE_STRIP: 3,
|
|
129
|
+
TRIANGLES: 4,
|
|
130
|
+
BYTE: 5120,
|
|
131
|
+
UNSIGNED_BYTE: 5121,
|
|
132
|
+
SHORT: 5122,
|
|
133
|
+
UNSIGNED_SHORT: 5123,
|
|
134
|
+
INT: 5124,
|
|
135
|
+
UNSIGNED_INT: 5125,
|
|
136
|
+
FLOAT: 5126,
|
|
137
|
+
ARRAY_BUFFER: 34962,
|
|
138
|
+
ELEMENT_ARRAY_BUFFER: 34963,
|
|
139
|
+
NEAREST: 9728,
|
|
140
|
+
LINEAR: 9729,
|
|
141
|
+
NEAREST_MIPMAP_NEAREST: 9984,
|
|
142
|
+
LINEAR_MIPMAP_NEAREST: 9985,
|
|
143
|
+
NEAREST_MIPMAP_LINEAR: 9986,
|
|
144
|
+
LINEAR_MIPMAP_LINEAR: 9987,
|
|
145
|
+
CLAMP_TO_EDGE: 33071,
|
|
146
|
+
MIRRORED_REPEAT: 33648,
|
|
147
|
+
REPEAT: 10497
|
|
148
|
+
}, W = "KHR_mesh_quantization", R = {};
|
|
149
|
+
R[Ce] = T.NEAREST;
|
|
150
|
+
R[Ue] = T.NEAREST_MIPMAP_NEAREST;
|
|
151
|
+
R[Fe] = T.NEAREST_MIPMAP_LINEAR;
|
|
152
|
+
R[$e] = T.LINEAR;
|
|
153
|
+
R[Oe] = T.LINEAR_MIPMAP_NEAREST;
|
|
154
|
+
R[Pe] = T.LINEAR_MIPMAP_LINEAR;
|
|
155
|
+
R[De] = T.CLAMP_TO_EDGE;
|
|
156
|
+
R[Ge] = T.REPEAT;
|
|
157
|
+
R[ke] = T.MIRRORED_REPEAT;
|
|
158
|
+
const se = {
|
|
159
|
+
scale: "scale",
|
|
160
|
+
position: "translation",
|
|
161
|
+
quaternion: "rotation",
|
|
162
|
+
morphTargetInfluences: "weights"
|
|
163
|
+
}, Ve = new _e(), ne = 12, Ye = 1179937895, je = 2, ie = 8, Ke = 1313821514, We = 5130562;
|
|
164
|
+
function P(n, e) {
|
|
165
|
+
return n.length === e.length && n.every(function(s, t) {
|
|
166
|
+
return s === e[t];
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function Xe(n) {
|
|
170
|
+
return new TextEncoder().encode(n).buffer;
|
|
171
|
+
}
|
|
172
|
+
function Ze(n) {
|
|
173
|
+
return P(n.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
174
|
+
}
|
|
175
|
+
function qe(n, e, s) {
|
|
176
|
+
const t = {
|
|
177
|
+
min: new Array(n.itemSize).fill(Number.POSITIVE_INFINITY),
|
|
178
|
+
max: new Array(n.itemSize).fill(Number.NEGATIVE_INFINITY)
|
|
179
|
+
};
|
|
180
|
+
for (let i = e; i < e + s; i++)
|
|
181
|
+
for (let r = 0; r < n.itemSize; r++) {
|
|
182
|
+
let o;
|
|
183
|
+
n.itemSize > 4 ? o = n.array[i * n.itemSize + r] : (r === 0 ? o = n.getX(i) : r === 1 ? o = n.getY(i) : r === 2 ? o = n.getZ(i) : r === 3 && (o = n.getW(i)), n.normalized === !0 && (o = q.normalize(o, n.array))), t.min[r] = Math.min(t.min[r], o), t.max[r] = Math.max(t.max[r], o);
|
|
184
|
+
}
|
|
185
|
+
return t;
|
|
186
|
+
}
|
|
187
|
+
function de(n) {
|
|
188
|
+
return Math.ceil(n / 4) * 4;
|
|
189
|
+
}
|
|
190
|
+
function X(n, e = 0) {
|
|
191
|
+
const s = de(n.byteLength);
|
|
192
|
+
if (s !== n.byteLength) {
|
|
193
|
+
const t = new Uint8Array(s);
|
|
194
|
+
if (t.set(new Uint8Array(n)), e !== 0)
|
|
195
|
+
for (let i = n.byteLength; i < s; i++)
|
|
196
|
+
t[i] = e;
|
|
197
|
+
return t.buffer;
|
|
198
|
+
}
|
|
199
|
+
return n;
|
|
200
|
+
}
|
|
201
|
+
function re() {
|
|
202
|
+
return typeof document > "u" && typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1) : document.createElement("canvas");
|
|
203
|
+
}
|
|
204
|
+
function oe(n, e) {
|
|
205
|
+
if (n.toBlob !== void 0)
|
|
206
|
+
return new Promise((t) => n.toBlob(t, e));
|
|
207
|
+
let s;
|
|
208
|
+
return e === "image/jpeg" ? s = 0.92 : e === "image/webp" && (s = 0.8), n.convertToBlob({
|
|
209
|
+
type: e,
|
|
210
|
+
quality: s
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
class Je {
|
|
214
|
+
constructor() {
|
|
215
|
+
this.plugins = [], this.options = {}, this.pending = [], this.buffers = [], this.byteOffset = 0, this.buffers = [], this.nodeMap = /* @__PURE__ */ new Map(), this.skins = [], this.extensionsUsed = {}, this.extensionsRequired = {}, this.uids = /* @__PURE__ */ new Map(), this.uid = 0, this.json = {
|
|
216
|
+
asset: {
|
|
217
|
+
version: "2.0",
|
|
218
|
+
generator: "THREE.GLTFExporter"
|
|
219
|
+
}
|
|
220
|
+
}, this.cache = {
|
|
221
|
+
meshes: /* @__PURE__ */ new Map(),
|
|
222
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
223
|
+
attributesNormalized: /* @__PURE__ */ new Map(),
|
|
224
|
+
materials: /* @__PURE__ */ new Map(),
|
|
225
|
+
textures: /* @__PURE__ */ new Map(),
|
|
226
|
+
images: /* @__PURE__ */ new Map()
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
setPlugins(e) {
|
|
230
|
+
this.plugins = e;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Parse scenes and generate GLTF output
|
|
234
|
+
* @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
|
|
235
|
+
* @param {Function} onDone Callback on completed
|
|
236
|
+
* @param {Object} options options
|
|
237
|
+
*/
|
|
238
|
+
async write(e, s, t = {}) {
|
|
239
|
+
this.options = Object.assign({
|
|
240
|
+
// default options
|
|
241
|
+
binary: !1,
|
|
242
|
+
trs: !1,
|
|
243
|
+
onlyVisible: !0,
|
|
244
|
+
maxTextureSize: 1 / 0,
|
|
245
|
+
animations: [],
|
|
246
|
+
includeCustomExtensions: !1
|
|
247
|
+
}, t), this.options.animations.length > 0 && (this.options.trs = !0), this.processInput(e), await Promise.all(this.pending);
|
|
248
|
+
const i = this, r = i.buffers, o = i.json;
|
|
249
|
+
t = i.options;
|
|
250
|
+
const a = i.extensionsUsed, c = i.extensionsRequired, u = new Blob(r, { type: "application/octet-stream" }), p = Object.keys(a), l = Object.keys(c);
|
|
251
|
+
if (p.length > 0 && (o.extensionsUsed = p), l.length > 0 && (o.extensionsRequired = l), o.buffers && o.buffers.length > 0 && (o.buffers[0].byteLength = u.size), t.binary === !0) {
|
|
252
|
+
const x = new FileReader();
|
|
253
|
+
x.readAsArrayBuffer(u), x.onloadend = function() {
|
|
254
|
+
const f = X(x.result), h = new DataView(new ArrayBuffer(ie));
|
|
255
|
+
h.setUint32(0, f.byteLength, !0), h.setUint32(4, We, !0);
|
|
256
|
+
const d = X(Xe(JSON.stringify(o)), 32), g = new DataView(new ArrayBuffer(ie));
|
|
257
|
+
g.setUint32(0, d.byteLength, !0), g.setUint32(4, Ke, !0);
|
|
258
|
+
const y = new ArrayBuffer(ne), _ = new DataView(y);
|
|
259
|
+
_.setUint32(0, Ye, !0), _.setUint32(4, je, !0);
|
|
260
|
+
const D = ne + g.byteLength + d.byteLength + h.byteLength + f.byteLength;
|
|
261
|
+
_.setUint32(8, D, !0);
|
|
262
|
+
const m = new Blob([
|
|
263
|
+
y,
|
|
264
|
+
g,
|
|
265
|
+
d,
|
|
266
|
+
h,
|
|
267
|
+
f
|
|
268
|
+
], { type: "application/octet-stream" }), M = new FileReader();
|
|
269
|
+
M.readAsArrayBuffer(m), M.onloadend = function() {
|
|
270
|
+
s(M.result);
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
} else if (o.buffers && o.buffers.length > 0) {
|
|
274
|
+
const x = new FileReader();
|
|
275
|
+
x.readAsDataURL(u), x.onloadend = function() {
|
|
276
|
+
const f = x.result;
|
|
277
|
+
o.buffers[0].uri = f, s(o);
|
|
278
|
+
};
|
|
279
|
+
} else
|
|
280
|
+
s(o);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Serializes a userData.
|
|
284
|
+
*
|
|
285
|
+
* @param {THREE.Object3D|THREE.Material} object
|
|
286
|
+
* @param {Object} objectDef
|
|
287
|
+
*/
|
|
288
|
+
serializeUserData(e, s) {
|
|
289
|
+
if (Object.keys(e.userData).length === 0) return;
|
|
290
|
+
const t = this.options, i = this.extensionsUsed;
|
|
291
|
+
try {
|
|
292
|
+
const r = JSON.parse(JSON.stringify(e.userData));
|
|
293
|
+
if (t.includeCustomExtensions && r.gltfExtensions) {
|
|
294
|
+
s.extensions === void 0 && (s.extensions = {});
|
|
295
|
+
for (const o in r.gltfExtensions)
|
|
296
|
+
s.extensions[o] = r.gltfExtensions[o], i[o] = !0;
|
|
297
|
+
delete r.gltfExtensions;
|
|
298
|
+
}
|
|
299
|
+
Object.keys(r).length > 0 && (s.extras = r);
|
|
300
|
+
} catch (r) {
|
|
301
|
+
console.warn("THREE.GLTFExporter: userData of '" + e.name + "' won't be serialized because of JSON.stringify error - " + r.message);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Returns ids for buffer attributes.
|
|
306
|
+
* @param {Object} object
|
|
307
|
+
* @return {Integer}
|
|
308
|
+
*/
|
|
309
|
+
getUID(e, s = !1) {
|
|
310
|
+
if (this.uids.has(e) === !1) {
|
|
311
|
+
const i = /* @__PURE__ */ new Map();
|
|
312
|
+
i.set(!0, this.uid++), i.set(!1, this.uid++), this.uids.set(e, i);
|
|
313
|
+
}
|
|
314
|
+
return this.uids.get(e).get(s);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Checks if normal attribute values are normalized.
|
|
318
|
+
*
|
|
319
|
+
* @param {BufferAttribute} normal
|
|
320
|
+
* @returns {Boolean}
|
|
321
|
+
*/
|
|
322
|
+
isNormalizedNormalAttribute(e) {
|
|
323
|
+
if (this.cache.attributesNormalized.has(e)) return !1;
|
|
324
|
+
const t = new B();
|
|
325
|
+
for (let i = 0, r = e.count; i < r; i++)
|
|
326
|
+
if (Math.abs(t.fromBufferAttribute(e, i).length() - 1) > 5e-4) return !1;
|
|
327
|
+
return !0;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Creates normalized normal buffer attribute.
|
|
331
|
+
*
|
|
332
|
+
* @param {BufferAttribute} normal
|
|
333
|
+
* @returns {BufferAttribute}
|
|
334
|
+
*
|
|
335
|
+
*/
|
|
336
|
+
createNormalizedNormalAttribute(e) {
|
|
337
|
+
const s = this.cache;
|
|
338
|
+
if (s.attributesNormalized.has(e)) return s.attributesNormalized.get(e);
|
|
339
|
+
const t = e.clone(), i = new B();
|
|
340
|
+
for (let r = 0, o = t.count; r < o; r++)
|
|
341
|
+
i.fromBufferAttribute(t, r), i.x === 0 && i.y === 0 && i.z === 0 ? i.setX(1) : i.normalize(), t.setXYZ(r, i.x, i.y, i.z);
|
|
342
|
+
return s.attributesNormalized.set(e, t), t;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Applies a texture transform, if present, to the map definition. Requires
|
|
346
|
+
* the KHR_texture_transform extension.
|
|
347
|
+
*
|
|
348
|
+
* @param {Object} mapDef
|
|
349
|
+
* @param {THREE.Texture} texture
|
|
350
|
+
*/
|
|
351
|
+
applyTextureTransform(e, s) {
|
|
352
|
+
let t = !1;
|
|
353
|
+
const i = {};
|
|
354
|
+
(s.offset.x !== 0 || s.offset.y !== 0) && (i.offset = s.offset.toArray(), t = !0), s.rotation !== 0 && (i.rotation = s.rotation, t = !0), (s.repeat.x !== 1 || s.repeat.y !== 1) && (i.scale = s.repeat.toArray(), t = !0), t && (e.extensions = e.extensions || {}, e.extensions.KHR_texture_transform = i, this.extensionsUsed.KHR_texture_transform = !0);
|
|
355
|
+
}
|
|
356
|
+
buildMetalRoughTexture(e, s) {
|
|
357
|
+
if (e === s) return e;
|
|
358
|
+
function t(f) {
|
|
359
|
+
return f.colorSpace === ue ? function(d) {
|
|
360
|
+
return d < 0.04045 ? d * 0.0773993808 : Math.pow(d * 0.9478672986 + 0.0521327014, 2.4);
|
|
361
|
+
} : function(d) {
|
|
362
|
+
return d;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."), e instanceof j && (e = z(e)), s instanceof j && (s = z(s));
|
|
366
|
+
const i = e ? e.image : null, r = s ? s.image : null, o = Math.max(i ? i.width : 0, r ? r.width : 0), a = Math.max(i ? i.height : 0, r ? r.height : 0), c = re();
|
|
367
|
+
c.width = o, c.height = a;
|
|
368
|
+
const u = c.getContext("2d");
|
|
369
|
+
u.fillStyle = "#00ffff", u.fillRect(0, 0, o, a);
|
|
370
|
+
const p = u.getImageData(0, 0, o, a);
|
|
371
|
+
if (i) {
|
|
372
|
+
u.drawImage(i, 0, 0, o, a);
|
|
373
|
+
const f = t(e), h = u.getImageData(0, 0, o, a).data;
|
|
374
|
+
for (let d = 2; d < h.length; d += 4)
|
|
375
|
+
p.data[d] = f(h[d] / 256) * 256;
|
|
376
|
+
}
|
|
377
|
+
if (r) {
|
|
378
|
+
u.drawImage(r, 0, 0, o, a);
|
|
379
|
+
const f = t(s), h = u.getImageData(0, 0, o, a).data;
|
|
380
|
+
for (let d = 1; d < h.length; d += 4)
|
|
381
|
+
p.data[d] = f(h[d] / 256) * 256;
|
|
382
|
+
}
|
|
383
|
+
u.putImageData(p, 0, 0);
|
|
384
|
+
const x = (e || s).clone();
|
|
385
|
+
return x.source = new Ne(c), x.colorSpace = fe, x.channel = (e || s).channel, e && s && e.channel !== s.channel && console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."), x;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Process a buffer to append to the default one.
|
|
389
|
+
* @param {ArrayBuffer} buffer
|
|
390
|
+
* @return {Integer}
|
|
391
|
+
*/
|
|
392
|
+
processBuffer(e) {
|
|
393
|
+
const s = this.json, t = this.buffers;
|
|
394
|
+
return s.buffers || (s.buffers = [{ byteLength: 0 }]), t.push(e), 0;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Process and generate a BufferView
|
|
398
|
+
* @param {BufferAttribute} attribute
|
|
399
|
+
* @param {number} componentType
|
|
400
|
+
* @param {number} start
|
|
401
|
+
* @param {number} count
|
|
402
|
+
* @param {number} target (Optional) Target usage of the BufferView
|
|
403
|
+
* @return {Object}
|
|
404
|
+
*/
|
|
405
|
+
processBufferView(e, s, t, i, r) {
|
|
406
|
+
const o = this.json;
|
|
407
|
+
o.bufferViews || (o.bufferViews = []);
|
|
408
|
+
let a;
|
|
409
|
+
switch (s) {
|
|
410
|
+
case T.BYTE:
|
|
411
|
+
case T.UNSIGNED_BYTE:
|
|
412
|
+
a = 1;
|
|
413
|
+
break;
|
|
414
|
+
case T.SHORT:
|
|
415
|
+
case T.UNSIGNED_SHORT:
|
|
416
|
+
a = 2;
|
|
417
|
+
break;
|
|
418
|
+
default:
|
|
419
|
+
a = 4;
|
|
420
|
+
}
|
|
421
|
+
let c = e.itemSize * a;
|
|
422
|
+
r === T.ARRAY_BUFFER && (c = Math.ceil(c / 4) * 4);
|
|
423
|
+
const u = de(i * c), p = new DataView(new ArrayBuffer(u));
|
|
424
|
+
let l = 0;
|
|
425
|
+
for (let h = t; h < t + i; h++) {
|
|
426
|
+
for (let d = 0; d < e.itemSize; d++) {
|
|
427
|
+
let g;
|
|
428
|
+
e.itemSize > 4 ? g = e.array[h * e.itemSize + d] : (d === 0 ? g = e.getX(h) : d === 1 ? g = e.getY(h) : d === 2 ? g = e.getZ(h) : d === 3 && (g = e.getW(h)), e.normalized === !0 && (g = q.normalize(g, e.array))), s === T.FLOAT ? p.setFloat32(l, g, !0) : s === T.INT ? p.setInt32(l, g, !0) : s === T.UNSIGNED_INT ? p.setUint32(l, g, !0) : s === T.SHORT ? p.setInt16(l, g, !0) : s === T.UNSIGNED_SHORT ? p.setUint16(l, g, !0) : s === T.BYTE ? p.setInt8(l, g) : s === T.UNSIGNED_BYTE && p.setUint8(l, g), l += a;
|
|
429
|
+
}
|
|
430
|
+
l % c !== 0 && (l += c - l % c);
|
|
431
|
+
}
|
|
432
|
+
const x = {
|
|
433
|
+
buffer: this.processBuffer(p.buffer),
|
|
434
|
+
byteOffset: this.byteOffset,
|
|
435
|
+
byteLength: u
|
|
436
|
+
};
|
|
437
|
+
return r !== void 0 && (x.target = r), r === T.ARRAY_BUFFER && (x.byteStride = c), this.byteOffset += u, o.bufferViews.push(x), {
|
|
438
|
+
id: o.bufferViews.length - 1,
|
|
439
|
+
byteLength: 0
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Process and generate a BufferView from an image Blob.
|
|
444
|
+
* @param {Blob} blob
|
|
445
|
+
* @return {Promise<Integer>}
|
|
446
|
+
*/
|
|
447
|
+
processBufferViewImage(e) {
|
|
448
|
+
const s = this, t = s.json;
|
|
449
|
+
return t.bufferViews || (t.bufferViews = []), new Promise(function(i) {
|
|
450
|
+
const r = new FileReader();
|
|
451
|
+
r.readAsArrayBuffer(e), r.onloadend = function() {
|
|
452
|
+
const o = X(r.result), a = {
|
|
453
|
+
buffer: s.processBuffer(o),
|
|
454
|
+
byteOffset: s.byteOffset,
|
|
455
|
+
byteLength: o.byteLength
|
|
456
|
+
};
|
|
457
|
+
s.byteOffset += o.byteLength, i(t.bufferViews.push(a) - 1);
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Process attribute to generate an accessor
|
|
463
|
+
* @param {BufferAttribute} attribute Attribute to process
|
|
464
|
+
* @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
|
|
465
|
+
* @param {Integer} start (Optional)
|
|
466
|
+
* @param {Integer} count (Optional)
|
|
467
|
+
* @return {Integer|null} Index of the processed accessor on the "accessors" array
|
|
468
|
+
*/
|
|
469
|
+
processAccessor(e, s, t, i) {
|
|
470
|
+
const r = this.json, o = {
|
|
471
|
+
1: "SCALAR",
|
|
472
|
+
2: "VEC2",
|
|
473
|
+
3: "VEC3",
|
|
474
|
+
4: "VEC4",
|
|
475
|
+
9: "MAT3",
|
|
476
|
+
16: "MAT4"
|
|
477
|
+
};
|
|
478
|
+
let a;
|
|
479
|
+
if (e.array.constructor === Float32Array)
|
|
480
|
+
a = T.FLOAT;
|
|
481
|
+
else if (e.array.constructor === Int32Array)
|
|
482
|
+
a = T.INT;
|
|
483
|
+
else if (e.array.constructor === Uint32Array)
|
|
484
|
+
a = T.UNSIGNED_INT;
|
|
485
|
+
else if (e.array.constructor === Int16Array)
|
|
486
|
+
a = T.SHORT;
|
|
487
|
+
else if (e.array.constructor === Uint16Array)
|
|
488
|
+
a = T.UNSIGNED_SHORT;
|
|
489
|
+
else if (e.array.constructor === Int8Array)
|
|
490
|
+
a = T.BYTE;
|
|
491
|
+
else if (e.array.constructor === Uint8Array)
|
|
492
|
+
a = T.UNSIGNED_BYTE;
|
|
493
|
+
else
|
|
494
|
+
throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: " + e.array.constructor.name);
|
|
495
|
+
if (t === void 0 && (t = 0), (i === void 0 || i === 1 / 0) && (i = e.count), i === 0) return null;
|
|
496
|
+
const c = qe(e, t, i);
|
|
497
|
+
let u;
|
|
498
|
+
s !== void 0 && (u = e === s.index ? T.ELEMENT_ARRAY_BUFFER : T.ARRAY_BUFFER);
|
|
499
|
+
const p = this.processBufferView(e, a, t, i, u), l = {
|
|
500
|
+
bufferView: p.id,
|
|
501
|
+
byteOffset: p.byteOffset,
|
|
502
|
+
componentType: a,
|
|
503
|
+
count: i,
|
|
504
|
+
max: c.max,
|
|
505
|
+
min: c.min,
|
|
506
|
+
type: o[e.itemSize]
|
|
507
|
+
};
|
|
508
|
+
return e.normalized === !0 && (l.normalized = !0), r.accessors || (r.accessors = []), r.accessors.push(l) - 1;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Process image
|
|
512
|
+
* @param {Image} image to process
|
|
513
|
+
* @param {Integer} format of the image (RGBAFormat)
|
|
514
|
+
* @param {Boolean} flipY before writing out the image
|
|
515
|
+
* @param {String} mimeType export format
|
|
516
|
+
* @return {Integer} Index of the processed texture in the "images" array
|
|
517
|
+
*/
|
|
518
|
+
processImage(e, s, t, i = "image/png") {
|
|
519
|
+
if (e !== null) {
|
|
520
|
+
const r = this, o = r.cache, a = r.json, c = r.options, u = r.pending;
|
|
521
|
+
o.images.has(e) || o.images.set(e, {});
|
|
522
|
+
const p = o.images.get(e), l = i + ":flipY/" + t.toString();
|
|
523
|
+
if (p[l] !== void 0) return p[l];
|
|
524
|
+
a.images || (a.images = []);
|
|
525
|
+
const x = { mimeType: i }, f = re();
|
|
526
|
+
f.width = Math.min(e.width, c.maxTextureSize), f.height = Math.min(e.height, c.maxTextureSize);
|
|
527
|
+
const h = f.getContext("2d");
|
|
528
|
+
if (t === !0 && (h.translate(0, f.height), h.scale(1, -1)), e.data !== void 0) {
|
|
529
|
+
s !== Le && console.error("GLTFExporter: Only RGBAFormat is supported.", s), (e.width > c.maxTextureSize || e.height > c.maxTextureSize) && console.warn("GLTFExporter: Image size is bigger than maxTextureSize", e);
|
|
530
|
+
const g = new Uint8ClampedArray(e.height * e.width * 4);
|
|
531
|
+
for (let y = 0; y < g.length; y += 4)
|
|
532
|
+
g[y + 0] = e.data[y + 0], g[y + 1] = e.data[y + 1], g[y + 2] = e.data[y + 2], g[y + 3] = e.data[y + 3];
|
|
533
|
+
h.putImageData(new ImageData(g, e.width, e.height), 0, 0);
|
|
534
|
+
} else if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && e instanceof ImageBitmap || typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas)
|
|
535
|
+
h.drawImage(e, 0, 0, f.width, f.height);
|
|
536
|
+
else
|
|
537
|
+
throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
|
|
538
|
+
c.binary === !0 ? u.push(
|
|
539
|
+
oe(f, i).then((g) => r.processBufferViewImage(g)).then((g) => {
|
|
540
|
+
x.bufferView = g;
|
|
541
|
+
})
|
|
542
|
+
) : f.toDataURL !== void 0 ? x.uri = f.toDataURL(i) : u.push(
|
|
543
|
+
oe(f, i).then((g) => new FileReader().readAsDataURL(g)).then((g) => {
|
|
544
|
+
x.uri = g;
|
|
545
|
+
})
|
|
546
|
+
);
|
|
547
|
+
const d = a.images.push(x) - 1;
|
|
548
|
+
return p[l] = d, d;
|
|
549
|
+
} else
|
|
550
|
+
throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Process sampler
|
|
554
|
+
* @param {Texture} map Texture to process
|
|
555
|
+
* @return {Integer} Index of the processed texture in the "samplers" array
|
|
556
|
+
*/
|
|
557
|
+
processSampler(e) {
|
|
558
|
+
const s = this.json;
|
|
559
|
+
s.samplers || (s.samplers = []);
|
|
560
|
+
const t = {
|
|
561
|
+
magFilter: R[e.magFilter],
|
|
562
|
+
minFilter: R[e.minFilter],
|
|
563
|
+
wrapS: R[e.wrapS],
|
|
564
|
+
wrapT: R[e.wrapT]
|
|
565
|
+
};
|
|
566
|
+
return s.samplers.push(t) - 1;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Process texture
|
|
570
|
+
* @param {Texture} map Map to process
|
|
571
|
+
* @return {Integer} Index of the processed texture in the "textures" array
|
|
572
|
+
*/
|
|
573
|
+
processTexture(e) {
|
|
574
|
+
const t = this.options, i = this.cache, r = this.json;
|
|
575
|
+
if (i.textures.has(e)) return i.textures.get(e);
|
|
576
|
+
r.textures || (r.textures = []), e instanceof j && (e = z(e, t.maxTextureSize));
|
|
577
|
+
let o = e.userData.mimeType;
|
|
578
|
+
o === "image/webp" && (o = "image/png");
|
|
579
|
+
const a = {
|
|
580
|
+
sampler: this.processSampler(e),
|
|
581
|
+
source: this.processImage(e.image, e.format, e.flipY, o)
|
|
582
|
+
};
|
|
583
|
+
e.name && (a.name = e.name), this._invokeAll(function(u) {
|
|
584
|
+
u.writeTexture && u.writeTexture(e, a);
|
|
585
|
+
});
|
|
586
|
+
const c = r.textures.push(a) - 1;
|
|
587
|
+
return i.textures.set(e, c), c;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Process material
|
|
591
|
+
* @param {THREE.Material} material Material to process
|
|
592
|
+
* @return {Integer|null} Index of the processed material in the "materials" array
|
|
593
|
+
*/
|
|
594
|
+
processMaterial(e) {
|
|
595
|
+
const s = this.cache, t = this.json;
|
|
596
|
+
if (s.materials.has(e)) return s.materials.get(e);
|
|
597
|
+
if (e.isShaderMaterial)
|
|
598
|
+
return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."), null;
|
|
599
|
+
t.materials || (t.materials = []);
|
|
600
|
+
const i = { pbrMetallicRoughness: {} };
|
|
601
|
+
e.isMeshStandardMaterial !== !0 && e.isMeshBasicMaterial !== !0 && console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
|
|
602
|
+
const r = e.color.toArray().concat([e.opacity]);
|
|
603
|
+
if (P(r, [1, 1, 1, 1]) || (i.pbrMetallicRoughness.baseColorFactor = r), e.isMeshStandardMaterial ? (i.pbrMetallicRoughness.metallicFactor = e.metalness, i.pbrMetallicRoughness.roughnessFactor = e.roughness) : (i.pbrMetallicRoughness.metallicFactor = 0.5, i.pbrMetallicRoughness.roughnessFactor = 0.5), e.metalnessMap || e.roughnessMap) {
|
|
604
|
+
const a = this.buildMetalRoughTexture(e.metalnessMap, e.roughnessMap), c = {
|
|
605
|
+
index: this.processTexture(a),
|
|
606
|
+
channel: a.channel
|
|
607
|
+
};
|
|
608
|
+
this.applyTextureTransform(c, a), i.pbrMetallicRoughness.metallicRoughnessTexture = c;
|
|
609
|
+
}
|
|
610
|
+
if (e.map) {
|
|
611
|
+
const a = {
|
|
612
|
+
index: this.processTexture(e.map),
|
|
613
|
+
texCoord: e.map.channel
|
|
614
|
+
};
|
|
615
|
+
this.applyTextureTransform(a, e.map), i.pbrMetallicRoughness.baseColorTexture = a;
|
|
616
|
+
}
|
|
617
|
+
if (e.emissive) {
|
|
618
|
+
const a = e.emissive;
|
|
619
|
+
if (Math.max(a.r, a.g, a.b) > 0 && (i.emissiveFactor = e.emissive.toArray()), e.emissiveMap) {
|
|
620
|
+
const u = {
|
|
621
|
+
index: this.processTexture(e.emissiveMap),
|
|
622
|
+
texCoord: e.emissiveMap.channel
|
|
623
|
+
};
|
|
624
|
+
this.applyTextureTransform(u, e.emissiveMap), i.emissiveTexture = u;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (e.normalMap) {
|
|
628
|
+
const a = {
|
|
629
|
+
index: this.processTexture(e.normalMap),
|
|
630
|
+
texCoord: e.normalMap.channel
|
|
631
|
+
};
|
|
632
|
+
e.normalScale && e.normalScale.x !== 1 && (a.scale = e.normalScale.x), this.applyTextureTransform(a, e.normalMap), i.normalTexture = a;
|
|
633
|
+
}
|
|
634
|
+
if (e.aoMap) {
|
|
635
|
+
const a = {
|
|
636
|
+
index: this.processTexture(e.aoMap),
|
|
637
|
+
texCoord: e.aoMap.channel
|
|
638
|
+
};
|
|
639
|
+
e.aoMapIntensity !== 1 && (a.strength = e.aoMapIntensity), this.applyTextureTransform(a, e.aoMap), i.occlusionTexture = a;
|
|
640
|
+
}
|
|
641
|
+
e.transparent ? i.alphaMode = "BLEND" : e.alphaTest > 0 && (i.alphaMode = "MASK", i.alphaCutoff = e.alphaTest), e.side === pe && (i.doubleSided = !0), e.name !== "" && (i.name = e.name), this.serializeUserData(e, i), this._invokeAll(function(a) {
|
|
642
|
+
a.writeMaterial && a.writeMaterial(e, i);
|
|
643
|
+
});
|
|
644
|
+
const o = t.materials.push(i) - 1;
|
|
645
|
+
return s.materials.set(e, o), o;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Process mesh
|
|
649
|
+
* @param {THREE.Mesh} mesh Mesh to process
|
|
650
|
+
* @return {Integer|null} Index of the processed mesh in the "meshes" array
|
|
651
|
+
*/
|
|
652
|
+
processMesh(e) {
|
|
653
|
+
const s = this.cache, t = this.json, i = [e.geometry.uuid];
|
|
654
|
+
if (Array.isArray(e.material))
|
|
655
|
+
for (let m = 0, M = e.material.length; m < M; m++)
|
|
656
|
+
i.push(e.material[m].uuid);
|
|
657
|
+
else
|
|
658
|
+
i.push(e.material.uuid);
|
|
659
|
+
const r = i.join(":");
|
|
660
|
+
if (s.meshes.has(r)) return s.meshes.get(r);
|
|
661
|
+
const o = e.geometry;
|
|
662
|
+
let a;
|
|
663
|
+
e.isLineSegments ? a = T.LINES : e.isLineLoop ? a = T.LINE_LOOP : e.isLine ? a = T.LINE_STRIP : e.isPoints ? a = T.POINTS : a = e.material.wireframe ? T.LINES : T.TRIANGLES;
|
|
664
|
+
const c = {}, u = {}, p = [], l = [], x = {
|
|
665
|
+
uv: "TEXCOORD_0",
|
|
666
|
+
uv1: "TEXCOORD_1",
|
|
667
|
+
uv2: "TEXCOORD_2",
|
|
668
|
+
uv3: "TEXCOORD_3",
|
|
669
|
+
color: "COLOR_0",
|
|
670
|
+
skinWeight: "WEIGHTS_0",
|
|
671
|
+
skinIndex: "JOINTS_0"
|
|
672
|
+
}, f = o.getAttribute("normal");
|
|
673
|
+
f !== void 0 && !this.isNormalizedNormalAttribute(f) && (console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."), o.setAttribute("normal", this.createNormalizedNormalAttribute(f)));
|
|
674
|
+
let h = null;
|
|
675
|
+
for (let m in o.attributes) {
|
|
676
|
+
if (m.slice(0, 5) === "morph") continue;
|
|
677
|
+
const M = o.attributes[m];
|
|
678
|
+
if (m = x[m] || m.toUpperCase(), /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(m) || (m = "_" + m), s.attributes.has(this.getUID(M))) {
|
|
679
|
+
u[m] = s.attributes.get(this.getUID(M));
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
h = null;
|
|
683
|
+
const b = M.array;
|
|
684
|
+
m === "JOINTS_0" && !(b instanceof Uint16Array) && !(b instanceof Uint8Array) && (console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'), h = new L(new Uint16Array(b), M.itemSize, M.normalized));
|
|
685
|
+
const I = this.processAccessor(h || M, o);
|
|
686
|
+
I !== null && (m.startsWith("_") || this.detectMeshQuantization(m, M), u[m] = I, s.attributes.set(this.getUID(M), I));
|
|
687
|
+
}
|
|
688
|
+
if (f !== void 0 && o.setAttribute("normal", f), Object.keys(u).length === 0) return null;
|
|
689
|
+
if (e.morphTargetInfluences !== void 0 && e.morphTargetInfluences.length > 0) {
|
|
690
|
+
const m = [], M = [], E = {};
|
|
691
|
+
if (e.morphTargetDictionary !== void 0)
|
|
692
|
+
for (const b in e.morphTargetDictionary)
|
|
693
|
+
E[e.morphTargetDictionary[b]] = b;
|
|
694
|
+
for (let b = 0; b < e.morphTargetInfluences.length; ++b) {
|
|
695
|
+
const I = {};
|
|
696
|
+
let ee = !1;
|
|
697
|
+
for (const U in o.morphAttributes) {
|
|
698
|
+
if (U !== "position" && U !== "normal") {
|
|
699
|
+
ee || (console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."), ee = !0);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const S = o.morphAttributes[U][b], V = U.toUpperCase(), F = o.attributes[U];
|
|
703
|
+
if (s.attributes.has(this.getUID(S, !0))) {
|
|
704
|
+
I[V] = s.attributes.get(this.getUID(S, !0));
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const $ = S.clone();
|
|
708
|
+
if (!o.morphTargetsRelative)
|
|
709
|
+
for (let A = 0, me = S.count; A < me; A++)
|
|
710
|
+
for (let v = 0; v < S.itemSize; v++)
|
|
711
|
+
v === 0 && $.setX(A, S.getX(A) - F.getX(A)), v === 1 && $.setY(A, S.getY(A) - F.getY(A)), v === 2 && $.setZ(A, S.getZ(A) - F.getZ(A)), v === 3 && $.setW(A, S.getW(A) - F.getW(A));
|
|
712
|
+
I[V] = this.processAccessor($, o), s.attributes.set(this.getUID(F, !0), I[V]);
|
|
713
|
+
}
|
|
714
|
+
l.push(I), m.push(e.morphTargetInfluences[b]), e.morphTargetDictionary !== void 0 && M.push(E[b]);
|
|
715
|
+
}
|
|
716
|
+
c.weights = m, M.length > 0 && (c.extras = {}, c.extras.targetNames = M);
|
|
717
|
+
}
|
|
718
|
+
const d = Array.isArray(e.material);
|
|
719
|
+
if (d && o.groups.length === 0) return null;
|
|
720
|
+
let g = !1;
|
|
721
|
+
if (d && o.index === null) {
|
|
722
|
+
const m = [];
|
|
723
|
+
for (let M = 0, E = o.attributes.position.count; M < E; M++)
|
|
724
|
+
m[M] = M;
|
|
725
|
+
o.setIndex(m), g = !0;
|
|
726
|
+
}
|
|
727
|
+
const y = d ? e.material : [e.material], _ = d ? o.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
|
|
728
|
+
for (let m = 0, M = _.length; m < M; m++) {
|
|
729
|
+
const E = {
|
|
730
|
+
mode: a,
|
|
731
|
+
attributes: u
|
|
732
|
+
};
|
|
733
|
+
if (this.serializeUserData(o, E), l.length > 0 && (E.targets = l), o.index !== null) {
|
|
734
|
+
let I = this.getUID(o.index);
|
|
735
|
+
(_[m].start !== void 0 || _[m].count !== void 0) && (I += ":" + _[m].start + ":" + _[m].count), s.attributes.has(I) ? E.indices = s.attributes.get(I) : (E.indices = this.processAccessor(o.index, o, _[m].start, _[m].count), s.attributes.set(I, E.indices)), E.indices === null && delete E.indices;
|
|
736
|
+
}
|
|
737
|
+
const b = this.processMaterial(y[_[m].materialIndex]);
|
|
738
|
+
b !== null && (E.material = b), p.push(E);
|
|
739
|
+
}
|
|
740
|
+
g === !0 && o.setIndex(null), c.primitives = p, t.meshes || (t.meshes = []), this._invokeAll(function(m) {
|
|
741
|
+
m.writeMesh && m.writeMesh(e, c);
|
|
742
|
+
});
|
|
743
|
+
const D = t.meshes.push(c) - 1;
|
|
744
|
+
return s.meshes.set(r, D), D;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* If a vertex attribute with a
|
|
748
|
+
* [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
|
|
749
|
+
* is used, it is checked whether it is a valid data type according to the
|
|
750
|
+
* [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
|
751
|
+
* extension.
|
|
752
|
+
* In this case the extension is automatically added to the list of used extensions.
|
|
753
|
+
*
|
|
754
|
+
* @param {string} attributeName
|
|
755
|
+
* @param {THREE.BufferAttribute} attribute
|
|
756
|
+
*/
|
|
757
|
+
detectMeshQuantization(e, s) {
|
|
758
|
+
if (this.extensionsUsed[W]) return;
|
|
759
|
+
let t;
|
|
760
|
+
switch (s.array.constructor) {
|
|
761
|
+
case Int8Array:
|
|
762
|
+
t = "byte";
|
|
763
|
+
break;
|
|
764
|
+
case Uint8Array:
|
|
765
|
+
t = "unsigned byte";
|
|
766
|
+
break;
|
|
767
|
+
case Int16Array:
|
|
768
|
+
t = "short";
|
|
769
|
+
break;
|
|
770
|
+
case Uint16Array:
|
|
771
|
+
t = "unsigned short";
|
|
772
|
+
break;
|
|
773
|
+
default:
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
s.normalized && (t += " normalized");
|
|
777
|
+
const i = e.split("_", 1)[0];
|
|
778
|
+
te[i] && te[i].includes(t) && (this.extensionsUsed[W] = !0, this.extensionsRequired[W] = !0);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Process camera
|
|
782
|
+
* @param {THREE.Camera} camera Camera to process
|
|
783
|
+
* @return {Integer} Index of the processed mesh in the "camera" array
|
|
784
|
+
*/
|
|
785
|
+
processCamera(e) {
|
|
786
|
+
const s = this.json;
|
|
787
|
+
s.cameras || (s.cameras = []);
|
|
788
|
+
const t = e.isOrthographicCamera, i = {
|
|
789
|
+
type: t ? "orthographic" : "perspective"
|
|
790
|
+
};
|
|
791
|
+
return t ? i.orthographic = {
|
|
792
|
+
xmag: e.right * 2,
|
|
793
|
+
ymag: e.top * 2,
|
|
794
|
+
zfar: e.far <= 0 ? 1e-3 : e.far,
|
|
795
|
+
znear: e.near < 0 ? 0 : e.near
|
|
796
|
+
} : i.perspective = {
|
|
797
|
+
aspectRatio: e.aspect,
|
|
798
|
+
yfov: q.degToRad(e.fov),
|
|
799
|
+
zfar: e.far <= 0 ? 1e-3 : e.far,
|
|
800
|
+
znear: e.near < 0 ? 0 : e.near
|
|
801
|
+
}, e.name !== "" && (i.name = e.type), s.cameras.push(i) - 1;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Creates glTF animation entry from AnimationClip object.
|
|
805
|
+
*
|
|
806
|
+
* Status:
|
|
807
|
+
* - Only properties listed in PATH_PROPERTIES may be animated.
|
|
808
|
+
*
|
|
809
|
+
* @param {THREE.AnimationClip} clip
|
|
810
|
+
* @param {THREE.Object3D} root
|
|
811
|
+
* @return {number|null}
|
|
812
|
+
*/
|
|
813
|
+
processAnimation(e, s) {
|
|
814
|
+
const t = this.json, i = this.nodeMap;
|
|
815
|
+
t.animations || (t.animations = []), e = Q.Utils.mergeMorphTargetTracks(e.clone(), s);
|
|
816
|
+
const r = e.tracks, o = [], a = [];
|
|
817
|
+
for (let c = 0; c < r.length; ++c) {
|
|
818
|
+
const u = r[c], p = H.parseTrackName(u.name);
|
|
819
|
+
let l = H.findNode(s, p.nodeName);
|
|
820
|
+
const x = se[p.propertyName];
|
|
821
|
+
if (p.objectName === "bones" && (l.isSkinnedMesh === !0 ? l = l.skeleton.getBoneByName(p.objectIndex) : l = void 0), !l || !x)
|
|
822
|
+
return console.warn('THREE.GLTFExporter: Could not export animation track "%s".', u.name), null;
|
|
823
|
+
const f = 1;
|
|
824
|
+
let h = u.values.length / u.times.length;
|
|
825
|
+
x === se.morphTargetInfluences && (h /= l.morphTargetInfluences.length);
|
|
826
|
+
let d;
|
|
827
|
+
u.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === !0 ? (d = "CUBICSPLINE", h /= 3) : u.getInterpolation() === ve ? d = "STEP" : d = "LINEAR", a.push({
|
|
828
|
+
input: this.processAccessor(new L(u.times, f)),
|
|
829
|
+
output: this.processAccessor(new L(u.values, h)),
|
|
830
|
+
interpolation: d
|
|
831
|
+
}), o.push({
|
|
832
|
+
sampler: a.length - 1,
|
|
833
|
+
target: {
|
|
834
|
+
node: i.get(l),
|
|
835
|
+
path: x
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
return t.animations.push({
|
|
840
|
+
name: e.name || "clip_" + t.animations.length,
|
|
841
|
+
samplers: a,
|
|
842
|
+
channels: o
|
|
843
|
+
}), t.animations.length - 1;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* @param {THREE.Object3D} object
|
|
847
|
+
* @return {number|null}
|
|
848
|
+
*/
|
|
849
|
+
processSkin(e) {
|
|
850
|
+
const s = this.json, t = this.nodeMap, i = s.nodes[t.get(e)], r = e.skeleton;
|
|
851
|
+
if (r === void 0) return null;
|
|
852
|
+
const o = e.skeleton.bones[0];
|
|
853
|
+
if (o === void 0) return null;
|
|
854
|
+
const a = [], c = new Float32Array(r.bones.length * 16), u = new le();
|
|
855
|
+
for (let l = 0; l < r.bones.length; ++l)
|
|
856
|
+
a.push(t.get(r.bones[l])), u.copy(r.boneInverses[l]), u.multiply(e.bindMatrix).toArray(c, l * 16);
|
|
857
|
+
return s.skins === void 0 && (s.skins = []), s.skins.push({
|
|
858
|
+
inverseBindMatrices: this.processAccessor(new L(c, 16)),
|
|
859
|
+
joints: a,
|
|
860
|
+
skeleton: t.get(o)
|
|
861
|
+
}), i.skin = s.skins.length - 1;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Process Object3D node
|
|
865
|
+
* @param {THREE.Object3D} node Object3D to processNode
|
|
866
|
+
* @return {Integer} Index of the node in the nodes list
|
|
867
|
+
*/
|
|
868
|
+
processNode(e) {
|
|
869
|
+
const s = this.json, t = this.options, i = this.nodeMap;
|
|
870
|
+
s.nodes || (s.nodes = []);
|
|
871
|
+
const r = {};
|
|
872
|
+
if (t.trs) {
|
|
873
|
+
const a = e.quaternion.toArray(), c = e.position.toArray(), u = e.scale.toArray();
|
|
874
|
+
P(a, [0, 0, 0, 1]) || (r.rotation = a), P(c, [0, 0, 0]) || (r.translation = c), P(u, [1, 1, 1]) || (r.scale = u);
|
|
875
|
+
} else
|
|
876
|
+
e.matrixAutoUpdate && e.updateMatrix(), Ze(e.matrix) === !1 && (r.matrix = e.matrix.elements);
|
|
877
|
+
if (e.name !== "" && (r.name = String(e.name)), this.serializeUserData(e, r), e.isMesh || e.isLine || e.isPoints) {
|
|
878
|
+
const a = this.processMesh(e);
|
|
879
|
+
a !== null && (r.mesh = a);
|
|
880
|
+
} else e.isCamera && (r.camera = this.processCamera(e));
|
|
881
|
+
if (e.isSkinnedMesh && this.skins.push(e), e.children.length > 0) {
|
|
882
|
+
const a = [];
|
|
883
|
+
for (let c = 0, u = e.children.length; c < u; c++) {
|
|
884
|
+
const p = e.children[c];
|
|
885
|
+
if (p.visible || t.onlyVisible === !1) {
|
|
886
|
+
const l = this.processNode(p);
|
|
887
|
+
l !== null && a.push(l);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
a.length > 0 && (r.children = a);
|
|
891
|
+
}
|
|
892
|
+
this._invokeAll(function(a) {
|
|
893
|
+
a.writeNode && a.writeNode(e, r);
|
|
894
|
+
});
|
|
895
|
+
const o = s.nodes.push(r) - 1;
|
|
896
|
+
return i.set(e, o), o;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Process Scene
|
|
900
|
+
* @param {Scene} node Scene to process
|
|
901
|
+
*/
|
|
902
|
+
processScene(e) {
|
|
903
|
+
const s = this.json, t = this.options;
|
|
904
|
+
s.scenes || (s.scenes = [], s.scene = 0);
|
|
905
|
+
const i = {};
|
|
906
|
+
e.name !== "" && (i.name = e.name), s.scenes.push(i);
|
|
907
|
+
const r = [];
|
|
908
|
+
for (let o = 0, a = e.children.length; o < a; o++) {
|
|
909
|
+
const c = e.children[o];
|
|
910
|
+
if (c.visible || t.onlyVisible === !1) {
|
|
911
|
+
const u = this.processNode(c);
|
|
912
|
+
u !== null && r.push(u);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
r.length > 0 && (i.nodes = r), this.serializeUserData(e, i);
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Creates a Scene to hold a list of objects and parse it
|
|
919
|
+
* @param {Array} objects List of objects to process
|
|
920
|
+
*/
|
|
921
|
+
processObjects(e) {
|
|
922
|
+
const s = new Z();
|
|
923
|
+
s.name = "AuxScene";
|
|
924
|
+
for (let t = 0; t < e.length; t++)
|
|
925
|
+
s.children.push(e[t]);
|
|
926
|
+
this.processScene(s);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* @param {THREE.Object3D|Array<THREE.Object3D>} input
|
|
930
|
+
*/
|
|
931
|
+
processInput(e) {
|
|
932
|
+
const s = this.options;
|
|
933
|
+
e = e instanceof Array ? e : [e], this._invokeAll(function(i) {
|
|
934
|
+
i.beforeParse && i.beforeParse(e);
|
|
935
|
+
});
|
|
936
|
+
const t = [];
|
|
937
|
+
for (let i = 0; i < e.length; i++)
|
|
938
|
+
e[i] instanceof Z ? this.processScene(e[i]) : t.push(e[i]);
|
|
939
|
+
t.length > 0 && this.processObjects(t);
|
|
940
|
+
for (let i = 0; i < this.skins.length; ++i)
|
|
941
|
+
this.processSkin(this.skins[i]);
|
|
942
|
+
for (let i = 0; i < s.animations.length; ++i)
|
|
943
|
+
this.processAnimation(s.animations[i], e[0]);
|
|
944
|
+
this._invokeAll(function(i) {
|
|
945
|
+
i.afterParse && i.afterParse(e);
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
_invokeAll(e) {
|
|
949
|
+
for (let s = 0, t = this.plugins.length; s < t; s++)
|
|
950
|
+
e(this.plugins[s]);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
class Qe {
|
|
954
|
+
constructor(e) {
|
|
955
|
+
this.writer = e, this.name = "KHR_lights_punctual";
|
|
956
|
+
}
|
|
957
|
+
writeNode(e, s) {
|
|
958
|
+
if (!e.isLight) return;
|
|
959
|
+
if (!e.isDirectionalLight && !e.isPointLight && !e.isSpotLight) {
|
|
960
|
+
console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", e);
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const t = this.writer, i = t.json, r = t.extensionsUsed, o = {};
|
|
964
|
+
e.name && (o.name = e.name), o.color = e.color.toArray(), o.intensity = e.intensity, e.isDirectionalLight ? o.type = "directional" : e.isPointLight ? (o.type = "point", e.distance > 0 && (o.range = e.distance)) : e.isSpotLight && (o.type = "spot", e.distance > 0 && (o.range = e.distance), o.spot = {}, o.spot.innerConeAngle = (1 - e.penumbra) * e.angle, o.spot.outerConeAngle = e.angle), e.decay !== void 0 && e.decay !== 2 && console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."), e.target && (e.target.parent !== e || e.target.position.x !== 0 || e.target.position.y !== 0 || e.target.position.z !== -1) && console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."), r[this.name] || (i.extensions = i.extensions || {}, i.extensions[this.name] = { lights: [] }, r[this.name] = !0);
|
|
965
|
+
const a = i.extensions[this.name].lights;
|
|
966
|
+
a.push(o), s.extensions = s.extensions || {}, s.extensions[this.name] = { light: a.length - 1 };
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
class et {
|
|
970
|
+
constructor(e) {
|
|
971
|
+
this.writer = e, this.name = "KHR_materials_unlit";
|
|
972
|
+
}
|
|
973
|
+
writeMaterial(e, s) {
|
|
974
|
+
if (!e.isMeshBasicMaterial) return;
|
|
975
|
+
const i = this.writer.extensionsUsed;
|
|
976
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = {}, i[this.name] = !0, s.pbrMetallicRoughness.metallicFactor = 0, s.pbrMetallicRoughness.roughnessFactor = 0.9;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
class tt {
|
|
980
|
+
constructor(e) {
|
|
981
|
+
this.writer = e, this.name = "KHR_materials_clearcoat";
|
|
982
|
+
}
|
|
983
|
+
writeMaterial(e, s) {
|
|
984
|
+
if (!e.isMeshPhysicalMaterial || e.clearcoat === 0) return;
|
|
985
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
986
|
+
if (r.clearcoatFactor = e.clearcoat, e.clearcoatMap) {
|
|
987
|
+
const o = {
|
|
988
|
+
index: t.processTexture(e.clearcoatMap),
|
|
989
|
+
texCoord: e.clearcoatMap.channel
|
|
990
|
+
};
|
|
991
|
+
t.applyTextureTransform(o, e.clearcoatMap), r.clearcoatTexture = o;
|
|
992
|
+
}
|
|
993
|
+
if (r.clearcoatRoughnessFactor = e.clearcoatRoughness, e.clearcoatRoughnessMap) {
|
|
994
|
+
const o = {
|
|
995
|
+
index: t.processTexture(e.clearcoatRoughnessMap),
|
|
996
|
+
texCoord: e.clearcoatRoughnessMap.channel
|
|
997
|
+
};
|
|
998
|
+
t.applyTextureTransform(o, e.clearcoatRoughnessMap), r.clearcoatRoughnessTexture = o;
|
|
999
|
+
}
|
|
1000
|
+
if (e.clearcoatNormalMap) {
|
|
1001
|
+
const o = {
|
|
1002
|
+
index: t.processTexture(e.clearcoatNormalMap),
|
|
1003
|
+
texCoord: e.clearcoatNormalMap.channel
|
|
1004
|
+
};
|
|
1005
|
+
t.applyTextureTransform(o, e.clearcoatNormalMap), r.clearcoatNormalTexture = o;
|
|
1006
|
+
}
|
|
1007
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
class st {
|
|
1011
|
+
constructor(e) {
|
|
1012
|
+
this.writer = e, this.name = "KHR_materials_iridescence";
|
|
1013
|
+
}
|
|
1014
|
+
writeMaterial(e, s) {
|
|
1015
|
+
if (!e.isMeshPhysicalMaterial || e.iridescence === 0) return;
|
|
1016
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1017
|
+
if (r.iridescenceFactor = e.iridescence, e.iridescenceMap) {
|
|
1018
|
+
const o = {
|
|
1019
|
+
index: t.processTexture(e.iridescenceMap),
|
|
1020
|
+
texCoord: e.iridescenceMap.channel
|
|
1021
|
+
};
|
|
1022
|
+
t.applyTextureTransform(o, e.iridescenceMap), r.iridescenceTexture = o;
|
|
1023
|
+
}
|
|
1024
|
+
if (r.iridescenceIor = e.iridescenceIOR, r.iridescenceThicknessMinimum = e.iridescenceThicknessRange[0], r.iridescenceThicknessMaximum = e.iridescenceThicknessRange[1], e.iridescenceThicknessMap) {
|
|
1025
|
+
const o = {
|
|
1026
|
+
index: t.processTexture(e.iridescenceThicknessMap),
|
|
1027
|
+
texCoord: e.iridescenceThicknessMap.channel
|
|
1028
|
+
};
|
|
1029
|
+
t.applyTextureTransform(o, e.iridescenceThicknessMap), r.iridescenceThicknessTexture = o;
|
|
1030
|
+
}
|
|
1031
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
class nt {
|
|
1035
|
+
constructor(e) {
|
|
1036
|
+
this.writer = e, this.name = "KHR_materials_transmission";
|
|
1037
|
+
}
|
|
1038
|
+
writeMaterial(e, s) {
|
|
1039
|
+
if (!e.isMeshPhysicalMaterial || e.transmission === 0) return;
|
|
1040
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1041
|
+
if (r.transmissionFactor = e.transmission, e.transmissionMap) {
|
|
1042
|
+
const o = {
|
|
1043
|
+
index: t.processTexture(e.transmissionMap),
|
|
1044
|
+
texCoord: e.transmissionMap.channel
|
|
1045
|
+
};
|
|
1046
|
+
t.applyTextureTransform(o, e.transmissionMap), r.transmissionTexture = o;
|
|
1047
|
+
}
|
|
1048
|
+
s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
class it {
|
|
1052
|
+
constructor(e) {
|
|
1053
|
+
this.writer = e, this.name = "KHR_materials_volume";
|
|
1054
|
+
}
|
|
1055
|
+
writeMaterial(e, s) {
|
|
1056
|
+
if (!e.isMeshPhysicalMaterial || e.transmission === 0) return;
|
|
1057
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1058
|
+
if (r.thicknessFactor = e.thickness, e.thicknessMap) {
|
|
1059
|
+
const o = {
|
|
1060
|
+
index: t.processTexture(e.thicknessMap),
|
|
1061
|
+
texCoord: e.thicknessMap.channel
|
|
1062
|
+
};
|
|
1063
|
+
t.applyTextureTransform(o, e.thicknessMap), r.thicknessTexture = o;
|
|
1064
|
+
}
|
|
1065
|
+
r.attenuationDistance = e.attenuationDistance, r.attenuationColor = e.attenuationColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
class rt {
|
|
1069
|
+
constructor(e) {
|
|
1070
|
+
this.writer = e, this.name = "KHR_materials_ior";
|
|
1071
|
+
}
|
|
1072
|
+
writeMaterial(e, s) {
|
|
1073
|
+
if (!e.isMeshPhysicalMaterial || e.ior === 1.5) return;
|
|
1074
|
+
const i = this.writer.extensionsUsed, r = {};
|
|
1075
|
+
r.ior = e.ior, s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
class ot {
|
|
1079
|
+
constructor(e) {
|
|
1080
|
+
this.writer = e, this.name = "KHR_materials_specular";
|
|
1081
|
+
}
|
|
1082
|
+
writeMaterial(e, s) {
|
|
1083
|
+
if (!e.isMeshPhysicalMaterial || e.specularIntensity === 1 && e.specularColor.equals(Ve) && !e.specularIntensityMap && !e.specularColorMap) return;
|
|
1084
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1085
|
+
if (e.specularIntensityMap) {
|
|
1086
|
+
const o = {
|
|
1087
|
+
index: t.processTexture(e.specularIntensityMap),
|
|
1088
|
+
texCoord: e.specularIntensityMap.channel
|
|
1089
|
+
};
|
|
1090
|
+
t.applyTextureTransform(o, e.specularIntensityMap), r.specularTexture = o;
|
|
1091
|
+
}
|
|
1092
|
+
if (e.specularColorMap) {
|
|
1093
|
+
const o = {
|
|
1094
|
+
index: t.processTexture(e.specularColorMap),
|
|
1095
|
+
texCoord: e.specularColorMap.channel
|
|
1096
|
+
};
|
|
1097
|
+
t.applyTextureTransform(o, e.specularColorMap), r.specularColorTexture = o;
|
|
1098
|
+
}
|
|
1099
|
+
r.specularFactor = e.specularIntensity, r.specularColorFactor = e.specularColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
class at {
|
|
1103
|
+
constructor(e) {
|
|
1104
|
+
this.writer = e, this.name = "KHR_materials_sheen";
|
|
1105
|
+
}
|
|
1106
|
+
writeMaterial(e, s) {
|
|
1107
|
+
if (!e.isMeshPhysicalMaterial || e.sheen == 0) return;
|
|
1108
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1109
|
+
if (e.sheenRoughnessMap) {
|
|
1110
|
+
const o = {
|
|
1111
|
+
index: t.processTexture(e.sheenRoughnessMap),
|
|
1112
|
+
texCoord: e.sheenRoughnessMap.channel
|
|
1113
|
+
};
|
|
1114
|
+
t.applyTextureTransform(o, e.sheenRoughnessMap), r.sheenRoughnessTexture = o;
|
|
1115
|
+
}
|
|
1116
|
+
if (e.sheenColorMap) {
|
|
1117
|
+
const o = {
|
|
1118
|
+
index: t.processTexture(e.sheenColorMap),
|
|
1119
|
+
texCoord: e.sheenColorMap.channel
|
|
1120
|
+
};
|
|
1121
|
+
t.applyTextureTransform(o, e.sheenColorMap), r.sheenColorTexture = o;
|
|
1122
|
+
}
|
|
1123
|
+
r.sheenRoughnessFactor = e.sheenRoughness, r.sheenColorFactor = e.sheenColor.toArray(), s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
class ct {
|
|
1127
|
+
constructor(e) {
|
|
1128
|
+
this.writer = e, this.name = "KHR_materials_anisotropy";
|
|
1129
|
+
}
|
|
1130
|
+
writeMaterial(e, s) {
|
|
1131
|
+
if (!e.isMeshPhysicalMaterial || e.anisotropy == 0) return;
|
|
1132
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1133
|
+
if (e.anisotropyMap) {
|
|
1134
|
+
const o = { index: t.processTexture(e.anisotropyMap) };
|
|
1135
|
+
t.applyTextureTransform(o, e.anisotropyMap), r.anisotropyTexture = o;
|
|
1136
|
+
}
|
|
1137
|
+
r.anisotropyStrength = e.anisotropy, r.anisotropyRotation = e.anisotropyRotation, s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
class ut {
|
|
1141
|
+
constructor(e) {
|
|
1142
|
+
this.writer = e, this.name = "KHR_materials_emissive_strength";
|
|
1143
|
+
}
|
|
1144
|
+
writeMaterial(e, s) {
|
|
1145
|
+
if (!e.isMeshStandardMaterial || e.emissiveIntensity === 1) return;
|
|
1146
|
+
const i = this.writer.extensionsUsed, r = {};
|
|
1147
|
+
r.emissiveStrength = e.emissiveIntensity, s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
class lt {
|
|
1151
|
+
constructor(e) {
|
|
1152
|
+
this.writer = e, this.name = "EXT_materials_bump";
|
|
1153
|
+
}
|
|
1154
|
+
writeMaterial(e, s) {
|
|
1155
|
+
if (!e.isMeshStandardMaterial || e.bumpScale === 1 && !e.bumpMap) return;
|
|
1156
|
+
const t = this.writer, i = t.extensionsUsed, r = {};
|
|
1157
|
+
if (e.bumpMap) {
|
|
1158
|
+
const o = {
|
|
1159
|
+
index: t.processTexture(e.bumpMap),
|
|
1160
|
+
texCoord: e.bumpMap.channel
|
|
1161
|
+
};
|
|
1162
|
+
t.applyTextureTransform(o, e.bumpMap), r.bumpTexture = o;
|
|
1163
|
+
}
|
|
1164
|
+
r.bumpFactor = e.bumpScale, s.extensions = s.extensions || {}, s.extensions[this.name] = r, i[this.name] = !0;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
class ft {
|
|
1168
|
+
constructor(e) {
|
|
1169
|
+
this.writer = e, this.name = "EXT_mesh_gpu_instancing";
|
|
1170
|
+
}
|
|
1171
|
+
writeNode(e, s) {
|
|
1172
|
+
if (!e.isInstancedMesh) return;
|
|
1173
|
+
const t = this.writer, i = e, r = new Float32Array(i.count * 3), o = new Float32Array(i.count * 4), a = new Float32Array(i.count * 3), c = new le(), u = new B(), p = new Se(), l = new B();
|
|
1174
|
+
for (let f = 0; f < i.count; f++)
|
|
1175
|
+
i.getMatrixAt(f, c), c.decompose(u, p, l), u.toArray(r, f * 3), p.toArray(o, f * 4), l.toArray(a, f * 3);
|
|
1176
|
+
const x = {
|
|
1177
|
+
TRANSLATION: t.processAccessor(new L(r, 3)),
|
|
1178
|
+
ROTATION: t.processAccessor(new L(o, 4)),
|
|
1179
|
+
SCALE: t.processAccessor(new L(a, 3))
|
|
1180
|
+
};
|
|
1181
|
+
i.instanceColor && (x._COLOR_0 = t.processAccessor(i.instanceColor)), s.extensions = s.extensions || {}, s.extensions[this.name] = { attributes: x }, t.extensionsUsed[this.name] = !0, t.extensionsRequired[this.name] = !0;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
Q.Utils = {
|
|
1185
|
+
insertKeyframe: function(n, e) {
|
|
1186
|
+
const t = n.getValueSize(), i = new n.TimeBufferType(n.times.length + 1), r = new n.ValueBufferType(n.values.length + t), o = n.createInterpolant(new n.ValueBufferType(t));
|
|
1187
|
+
let a;
|
|
1188
|
+
if (n.times.length === 0) {
|
|
1189
|
+
i[0] = e;
|
|
1190
|
+
for (let c = 0; c < t; c++)
|
|
1191
|
+
r[c] = 0;
|
|
1192
|
+
a = 0;
|
|
1193
|
+
} else if (e < n.times[0]) {
|
|
1194
|
+
if (Math.abs(n.times[0] - e) < 1e-3) return 0;
|
|
1195
|
+
i[0] = e, i.set(n.times, 1), r.set(o.evaluate(e), 0), r.set(n.values, t), a = 0;
|
|
1196
|
+
} else if (e > n.times[n.times.length - 1]) {
|
|
1197
|
+
if (Math.abs(n.times[n.times.length - 1] - e) < 1e-3)
|
|
1198
|
+
return n.times.length - 1;
|
|
1199
|
+
i[i.length - 1] = e, i.set(n.times, 0), r.set(n.values, 0), r.set(o.evaluate(e), n.values.length), a = i.length - 1;
|
|
1200
|
+
} else
|
|
1201
|
+
for (let c = 0; c < n.times.length; c++) {
|
|
1202
|
+
if (Math.abs(n.times[c] - e) < 1e-3) return c;
|
|
1203
|
+
if (n.times[c] < e && n.times[c + 1] > e) {
|
|
1204
|
+
i.set(n.times.slice(0, c + 1), 0), i[c + 1] = e, i.set(n.times.slice(c + 1), c + 2), r.set(n.values.slice(0, (c + 1) * t), 0), r.set(o.evaluate(e), (c + 1) * t), r.set(n.values.slice((c + 1) * t), (c + 2) * t), a = c + 1;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return n.times = i, n.values = r, a;
|
|
1209
|
+
},
|
|
1210
|
+
mergeMorphTargetTracks: function(n, e) {
|
|
1211
|
+
const s = [], t = {}, i = n.tracks;
|
|
1212
|
+
for (let r = 0; r < i.length; ++r) {
|
|
1213
|
+
let o = i[r];
|
|
1214
|
+
const a = H.parseTrackName(o.name), c = H.findNode(e, a.nodeName);
|
|
1215
|
+
if (a.propertyName !== "morphTargetInfluences" || a.propertyIndex === void 0) {
|
|
1216
|
+
s.push(o);
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
if (o.createInterpolant !== o.InterpolantFactoryMethodDiscrete && o.createInterpolant !== o.InterpolantFactoryMethodLinear) {
|
|
1220
|
+
if (o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)
|
|
1221
|
+
throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
|
|
1222
|
+
console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."), o = o.clone(), o.setInterpolation(ze);
|
|
1223
|
+
}
|
|
1224
|
+
const u = c.morphTargetInfluences.length, p = c.morphTargetDictionary[a.propertyIndex];
|
|
1225
|
+
if (p === void 0)
|
|
1226
|
+
throw new Error("THREE.GLTFExporter: Morph target name not found: " + a.propertyIndex);
|
|
1227
|
+
let l;
|
|
1228
|
+
if (t[c.uuid] === void 0) {
|
|
1229
|
+
l = o.clone();
|
|
1230
|
+
const f = new l.ValueBufferType(u * l.times.length);
|
|
1231
|
+
for (let h = 0; h < l.times.length; h++)
|
|
1232
|
+
f[h * u + p] = l.values[h];
|
|
1233
|
+
l.name = (a.nodeName || "") + ".morphTargetInfluences", l.values = f, t[c.uuid] = l, s.push(l);
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
const x = o.createInterpolant(new o.ValueBufferType(1));
|
|
1237
|
+
l = t[c.uuid];
|
|
1238
|
+
for (let f = 0; f < l.times.length; f++)
|
|
1239
|
+
l.values[f * u + p] = x.evaluate(l.times[f]);
|
|
1240
|
+
for (let f = 0; f < o.times.length; f++) {
|
|
1241
|
+
const h = this.insertKeyframe(l, o.times[f]);
|
|
1242
|
+
l.values[h * u + p] = o.values[f];
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
return n.tracks = s, n;
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
class pt {
|
|
1249
|
+
async parse(e, s = {}) {
|
|
1250
|
+
s = Object.assign({
|
|
1251
|
+
ar: {
|
|
1252
|
+
anchoring: { type: "plane" },
|
|
1253
|
+
planeAnchoring: { alignment: "horizontal" }
|
|
1254
|
+
},
|
|
1255
|
+
quickLookCompatible: !1,
|
|
1256
|
+
maxTextureSize: 1024
|
|
1257
|
+
}, s);
|
|
1258
|
+
const t = {}, i = "model.usda";
|
|
1259
|
+
t[i] = null;
|
|
1260
|
+
let r = xe();
|
|
1261
|
+
r += dt(s);
|
|
1262
|
+
const o = {}, a = {};
|
|
1263
|
+
e.traverseVisible((u) => {
|
|
1264
|
+
if (u.isMesh) {
|
|
1265
|
+
const p = u.geometry, l = u.material;
|
|
1266
|
+
if (l.isMeshStandardMaterial) {
|
|
1267
|
+
const x = "geometries/Geometry_" + p.id + ".usda";
|
|
1268
|
+
if (!(x in t)) {
|
|
1269
|
+
const f = Tt(p);
|
|
1270
|
+
t[x] = gt(f);
|
|
1271
|
+
}
|
|
1272
|
+
l.uuid in o || (o[l.uuid] = l), r += mt(u, p, l);
|
|
1273
|
+
} else
|
|
1274
|
+
console.warn("THREE.USDZExporter: Unsupported material type (USDZ only supports MeshStandardMaterial)", u);
|
|
1275
|
+
} else u.isCamera && (r += _t(u));
|
|
1276
|
+
}), r += xt(), r += At(o, a, s.quickLookCompatible), t[i] = he(r), r = null;
|
|
1277
|
+
for (const u in a) {
|
|
1278
|
+
let p = a[u];
|
|
1279
|
+
p.isCompressedTexture === !0 && (p = z(p));
|
|
1280
|
+
const l = ht(p.image, p.flipY, s.maxTextureSize), x = await new Promise((f) => l.toBlob(f, "image/png", 1));
|
|
1281
|
+
t[`textures/Texture_${u}.png`] = new Uint8Array(await x.arrayBuffer());
|
|
1282
|
+
}
|
|
1283
|
+
let c = 0;
|
|
1284
|
+
for (const u in t) {
|
|
1285
|
+
const p = t[u], l = 34 + u.length;
|
|
1286
|
+
c += l;
|
|
1287
|
+
const x = c & 63;
|
|
1288
|
+
if (x !== 4) {
|
|
1289
|
+
const f = 64 - x, h = new Uint8Array(f);
|
|
1290
|
+
t[u] = [p, { extra: { 12345: h } }];
|
|
1291
|
+
}
|
|
1292
|
+
c = p.length;
|
|
1293
|
+
}
|
|
1294
|
+
return Be(t, { level: 0 });
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function ht(n, e, s) {
|
|
1298
|
+
if (typeof HTMLImageElement < "u" && n instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && n instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && n instanceof OffscreenCanvas || typeof ImageBitmap < "u" && n instanceof ImageBitmap) {
|
|
1299
|
+
const t = s / Math.max(n.width, n.height), i = document.createElement("canvas");
|
|
1300
|
+
i.width = n.width * Math.min(1, t), i.height = n.height * Math.min(1, t);
|
|
1301
|
+
const r = i.getContext("2d");
|
|
1302
|
+
return e === !0 && (r.translate(0, i.height), r.scale(1, -1)), r.drawImage(n, 0, 0, i.width, i.height), i;
|
|
1303
|
+
} else
|
|
1304
|
+
throw new Error("THREE.USDZExporter: No valid image data found. Unable to process texture.");
|
|
1305
|
+
}
|
|
1306
|
+
const w = 7;
|
|
1307
|
+
function xe() {
|
|
1308
|
+
return `#usda 1.0
|
|
1309
|
+
(
|
|
1310
|
+
customLayerData = {
|
|
1311
|
+
string creator = "Three.js USDZExporter"
|
|
1312
|
+
}
|
|
1313
|
+
defaultPrim = "Root"
|
|
1314
|
+
metersPerUnit = 1
|
|
1315
|
+
upAxis = "Y"
|
|
1316
|
+
)
|
|
1317
|
+
|
|
1318
|
+
`;
|
|
1319
|
+
}
|
|
1320
|
+
function dt(n) {
|
|
1321
|
+
return `def Xform "Root"
|
|
1322
|
+
{
|
|
1323
|
+
def Scope "Scenes" (
|
|
1324
|
+
kind = "sceneLibrary"
|
|
1325
|
+
)
|
|
1326
|
+
{
|
|
1327
|
+
def Xform "Scene" (
|
|
1328
|
+
customData = {
|
|
1329
|
+
bool preliminary_collidesWithEnvironment = 0
|
|
1330
|
+
string sceneName = "Scene"
|
|
1331
|
+
}
|
|
1332
|
+
sceneName = "Scene"
|
|
1333
|
+
)
|
|
1334
|
+
{
|
|
1335
|
+
token preliminary:anchoring:type = "${n.ar.anchoring.type}"
|
|
1336
|
+
token preliminary:planeAnchoring:alignment = "${n.ar.planeAnchoring.alignment}"
|
|
1337
|
+
|
|
1338
|
+
`;
|
|
1339
|
+
}
|
|
1340
|
+
function xt() {
|
|
1341
|
+
return `
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
`;
|
|
1347
|
+
}
|
|
1348
|
+
function gt(n) {
|
|
1349
|
+
let e = xe();
|
|
1350
|
+
return e += n, he(e);
|
|
1351
|
+
}
|
|
1352
|
+
function mt(n, e, s) {
|
|
1353
|
+
const t = "Object_" + n.id, i = ge(n.matrixWorld);
|
|
1354
|
+
return n.matrixWorld.determinant() < 0 && console.warn("THREE.USDZExporter: USDZ does not support negative scales", n), `def Xform "${t}" (
|
|
1355
|
+
prepend references = @./geometries/Geometry_${e.id}.usda@</Geometry>
|
|
1356
|
+
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
1357
|
+
)
|
|
1358
|
+
{
|
|
1359
|
+
matrix4d xformOp:transform = ${i}
|
|
1360
|
+
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
1361
|
+
|
|
1362
|
+
rel material:binding = </Materials/Material_${s.id}>
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
`;
|
|
1366
|
+
}
|
|
1367
|
+
function ge(n) {
|
|
1368
|
+
const e = n.elements;
|
|
1369
|
+
return `( ${k(e, 0)}, ${k(e, 4)}, ${k(e, 8)}, ${k(e, 12)} )`;
|
|
1370
|
+
}
|
|
1371
|
+
function k(n, e) {
|
|
1372
|
+
return `(${n[e + 0]}, ${n[e + 1]}, ${n[e + 2]}, ${n[e + 3]})`;
|
|
1373
|
+
}
|
|
1374
|
+
function Tt(n) {
|
|
1375
|
+
return `
|
|
1376
|
+
def "Geometry"
|
|
1377
|
+
{
|
|
1378
|
+
${Mt(n)}
|
|
1379
|
+
}
|
|
1380
|
+
`;
|
|
1381
|
+
}
|
|
1382
|
+
function Mt(n) {
|
|
1383
|
+
const e = "Geometry", s = n.attributes, t = s.position.count;
|
|
1384
|
+
return `
|
|
1385
|
+
def Mesh "${e}"
|
|
1386
|
+
{
|
|
1387
|
+
int[] faceVertexCounts = [${yt(n)}]
|
|
1388
|
+
int[] faceVertexIndices = [${wt(n)}]
|
|
1389
|
+
normal3f[] normals = [${J(s.normal, t)}] (
|
|
1390
|
+
interpolation = "vertex"
|
|
1391
|
+
)
|
|
1392
|
+
point3f[] points = [${J(s.position, t)}]
|
|
1393
|
+
${bt(s)}
|
|
1394
|
+
uniform token subdivisionScheme = "none"
|
|
1395
|
+
}
|
|
1396
|
+
`;
|
|
1397
|
+
}
|
|
1398
|
+
function yt(n) {
|
|
1399
|
+
const e = n.index !== null ? n.index.count : n.attributes.position.count;
|
|
1400
|
+
return Array(e / 3).fill(3).join(", ");
|
|
1401
|
+
}
|
|
1402
|
+
function wt(n) {
|
|
1403
|
+
const e = n.index, s = [];
|
|
1404
|
+
if (e !== null)
|
|
1405
|
+
for (let t = 0; t < e.count; t++)
|
|
1406
|
+
s.push(e.getX(t));
|
|
1407
|
+
else {
|
|
1408
|
+
const t = n.attributes.position.count;
|
|
1409
|
+
for (let i = 0; i < t; i++)
|
|
1410
|
+
s.push(i);
|
|
1411
|
+
}
|
|
1412
|
+
return s.join(", ");
|
|
1413
|
+
}
|
|
1414
|
+
function J(n, e) {
|
|
1415
|
+
if (n === void 0)
|
|
1416
|
+
return console.warn("USDZExporter: Normals missing."), Array(e).fill("(0, 0, 0)").join(", ");
|
|
1417
|
+
const s = [];
|
|
1418
|
+
for (let t = 0; t < n.count; t++) {
|
|
1419
|
+
const i = n.getX(t), r = n.getY(t), o = n.getZ(t);
|
|
1420
|
+
s.push(`(${i.toPrecision(w)}, ${r.toPrecision(w)}, ${o.toPrecision(w)})`);
|
|
1421
|
+
}
|
|
1422
|
+
return s.join(", ");
|
|
1423
|
+
}
|
|
1424
|
+
function Et(n) {
|
|
1425
|
+
const e = [];
|
|
1426
|
+
for (let s = 0; s < n.count; s++) {
|
|
1427
|
+
const t = n.getX(s), i = n.getY(s);
|
|
1428
|
+
e.push(`(${t.toPrecision(w)}, ${1 - i.toPrecision(w)})`);
|
|
1429
|
+
}
|
|
1430
|
+
return e.join(", ");
|
|
1431
|
+
}
|
|
1432
|
+
function bt(n) {
|
|
1433
|
+
let e = "";
|
|
1434
|
+
for (let t = 0; t < 4; t++) {
|
|
1435
|
+
const i = t > 0 ? t : "", r = n["uv" + i];
|
|
1436
|
+
r !== void 0 && (e += `
|
|
1437
|
+
texCoord2f[] primvars:st${i} = [${Et(r)}] (
|
|
1438
|
+
interpolation = "vertex"
|
|
1439
|
+
)`);
|
|
1440
|
+
}
|
|
1441
|
+
const s = n.color;
|
|
1442
|
+
if (s !== void 0) {
|
|
1443
|
+
const t = s.count;
|
|
1444
|
+
e += `
|
|
1445
|
+
color3f[] primvars:displayColor = [${J(s, t)}] (
|
|
1446
|
+
interpolation = "vertex"
|
|
1447
|
+
)`;
|
|
1448
|
+
}
|
|
1449
|
+
return e;
|
|
1450
|
+
}
|
|
1451
|
+
function At(n, e, s = !1) {
|
|
1452
|
+
const t = [];
|
|
1453
|
+
for (const i in n) {
|
|
1454
|
+
const r = n[i];
|
|
1455
|
+
t.push(It(r, e, s));
|
|
1456
|
+
}
|
|
1457
|
+
return `def "Materials"
|
|
1458
|
+
{
|
|
1459
|
+
${t.join("")}
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
`;
|
|
1463
|
+
}
|
|
1464
|
+
function It(n, e, s = !1) {
|
|
1465
|
+
const t = " ", i = [], r = [];
|
|
1466
|
+
function o(a, c, u) {
|
|
1467
|
+
const p = a.source.id + "_" + a.flipY;
|
|
1468
|
+
e[p] = a;
|
|
1469
|
+
const l = a.channel > 0 ? "st" + a.channel : "st", x = {
|
|
1470
|
+
1e3: "repeat",
|
|
1471
|
+
// RepeatWrapping
|
|
1472
|
+
1001: "clamp",
|
|
1473
|
+
// ClampToEdgeWrapping
|
|
1474
|
+
1002: "mirror"
|
|
1475
|
+
// MirroredRepeatWrapping
|
|
1476
|
+
}, f = a.repeat.clone(), h = a.offset.clone(), d = a.rotation, g = Math.sin(d), y = Math.cos(d);
|
|
1477
|
+
return h.y = 1 - h.y - f.y, s ? (h.x = h.x / f.x, h.y = h.y / f.y, h.x += g / f.x, h.y += y - 1) : (h.x += g * f.x, h.y += (1 - y) * f.y), `
|
|
1478
|
+
def Shader "PrimvarReader_${c}"
|
|
1479
|
+
{
|
|
1480
|
+
uniform token info:id = "UsdPrimvarReader_float2"
|
|
1481
|
+
float2 inputs:fallback = (0.0, 0.0)
|
|
1482
|
+
token inputs:varname = "${l}"
|
|
1483
|
+
float2 outputs:result
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
def Shader "Transform2d_${c}"
|
|
1487
|
+
{
|
|
1488
|
+
uniform token info:id = "UsdTransform2d"
|
|
1489
|
+
token inputs:in.connect = </Materials/Material_${n.id}/PrimvarReader_${c}.outputs:result>
|
|
1490
|
+
float inputs:rotation = ${(d * (180 / Math.PI)).toFixed(w)}
|
|
1491
|
+
float2 inputs:scale = ${ce(f)}
|
|
1492
|
+
float2 inputs:translation = ${ce(h)}
|
|
1493
|
+
float2 outputs:result
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
def Shader "Texture_${a.id}_${c}"
|
|
1497
|
+
{
|
|
1498
|
+
uniform token info:id = "UsdUVTexture"
|
|
1499
|
+
asset inputs:file = @textures/Texture_${p}.png@
|
|
1500
|
+
float2 inputs:st.connect = </Materials/Material_${n.id}/Transform2d_${c}.outputs:result>
|
|
1501
|
+
${u !== void 0 ? "float4 inputs:scale = " + Rt(u) : ""}
|
|
1502
|
+
token inputs:sourceColorSpace = "${a.colorSpace === fe ? "raw" : "sRGB"}"
|
|
1503
|
+
token inputs:wrapS = "${x[a.wrapS]}"
|
|
1504
|
+
token inputs:wrapT = "${x[a.wrapT]}"
|
|
1505
|
+
float outputs:r
|
|
1506
|
+
float outputs:g
|
|
1507
|
+
float outputs:b
|
|
1508
|
+
float3 outputs:rgb
|
|
1509
|
+
${n.transparent || n.alphaTest > 0 ? "float outputs:a" : ""}
|
|
1510
|
+
}`;
|
|
1511
|
+
}
|
|
1512
|
+
return n.side === pe && console.warn("THREE.USDZExporter: USDZ does not support double sided materials", n), n.map !== null ? (i.push(`${t}color3f inputs:diffuseColor.connect = </Materials/Material_${n.id}/Texture_${n.map.id}_diffuse.outputs:rgb>`), n.transparent ? i.push(`${t}float inputs:opacity.connect = </Materials/Material_${n.id}/Texture_${n.map.id}_diffuse.outputs:a>`) : n.alphaTest > 0 && (i.push(`${t}float inputs:opacity.connect = </Materials/Material_${n.id}/Texture_${n.map.id}_diffuse.outputs:a>`), i.push(`${t}float inputs:opacityThreshold = ${n.alphaTest}`)), r.push(o(n.map, "diffuse", n.color))) : i.push(`${t}color3f inputs:diffuseColor = ${ae(n.color)}`), n.emissiveMap !== null ? (i.push(`${t}color3f inputs:emissiveColor.connect = </Materials/Material_${n.id}/Texture_${n.emissiveMap.id}_emissive.outputs:rgb>`), r.push(o(n.emissiveMap, "emissive"))) : n.emissive.getHex() > 0 && i.push(`${t}color3f inputs:emissiveColor = ${ae(n.emissive)}`), n.normalMap !== null && (i.push(`${t}normal3f inputs:normal.connect = </Materials/Material_${n.id}/Texture_${n.normalMap.id}_normal.outputs:rgb>`), r.push(o(n.normalMap, "normal"))), n.aoMap !== null && (i.push(`${t}float inputs:occlusion.connect = </Materials/Material_${n.id}/Texture_${n.aoMap.id}_occlusion.outputs:r>`), r.push(o(n.aoMap, "occlusion"))), n.roughnessMap !== null && n.roughness === 1 ? (i.push(`${t}float inputs:roughness.connect = </Materials/Material_${n.id}/Texture_${n.roughnessMap.id}_roughness.outputs:g>`), r.push(o(n.roughnessMap, "roughness"))) : i.push(`${t}float inputs:roughness = ${n.roughness}`), n.metalnessMap !== null && n.metalness === 1 ? (i.push(`${t}float inputs:metallic.connect = </Materials/Material_${n.id}/Texture_${n.metalnessMap.id}_metallic.outputs:b>`), r.push(o(n.metalnessMap, "metallic"))) : i.push(`${t}float inputs:metallic = ${n.metalness}`), n.alphaMap !== null ? (i.push(`${t}float inputs:opacity.connect = </Materials/Material_${n.id}/Texture_${n.alphaMap.id}_opacity.outputs:r>`), i.push(`${t}float inputs:opacityThreshold = 0.0001`), r.push(o(n.alphaMap, "opacity"))) : i.push(`${t}float inputs:opacity = ${n.opacity}`), n.isMeshPhysicalMaterial && (i.push(`${t}float inputs:clearcoat = ${n.clearcoat}`), i.push(`${t}float inputs:clearcoatRoughness = ${n.clearcoatRoughness}`), i.push(`${t}float inputs:ior = ${n.ior}`)), `
|
|
1513
|
+
def Material "Material_${n.id}"
|
|
1514
|
+
{
|
|
1515
|
+
def Shader "PreviewSurface"
|
|
1516
|
+
{
|
|
1517
|
+
uniform token info:id = "UsdPreviewSurface"
|
|
1518
|
+
${i.join(`
|
|
1519
|
+
`)}
|
|
1520
|
+
int inputs:useSpecularWorkflow = 0
|
|
1521
|
+
token outputs:surface
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
token outputs:surface.connect = </Materials/Material_${n.id}/PreviewSurface.outputs:surface>
|
|
1525
|
+
|
|
1526
|
+
${r.join(`
|
|
1527
|
+
`)}
|
|
1528
|
+
|
|
1529
|
+
}
|
|
1530
|
+
`;
|
|
1531
|
+
}
|
|
1532
|
+
function ae(n) {
|
|
1533
|
+
return `(${n.r}, ${n.g}, ${n.b})`;
|
|
1534
|
+
}
|
|
1535
|
+
function Rt(n) {
|
|
1536
|
+
return `(${n.r}, ${n.g}, ${n.b}, 1.0)`;
|
|
1537
|
+
}
|
|
1538
|
+
function ce(n) {
|
|
1539
|
+
return `(${n.x}, ${n.y})`;
|
|
1540
|
+
}
|
|
1541
|
+
function _t(n) {
|
|
1542
|
+
const e = n.name ? n.name : "Camera_" + n.id, s = ge(n.matrixWorld);
|
|
1543
|
+
return n.matrixWorld.determinant() < 0 && console.warn("THREE.USDZExporter: USDZ does not support negative scales", n), n.isOrthographicCamera ? `def Camera "${e}"
|
|
1544
|
+
{
|
|
1545
|
+
matrix4d xformOp:transform = ${s}
|
|
1546
|
+
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
1547
|
+
|
|
1548
|
+
float2 clippingRange = (${n.near.toPrecision(w)}, ${n.far.toPrecision(w)})
|
|
1549
|
+
float horizontalAperture = ${((Math.abs(n.left) + Math.abs(n.right)) * 10).toPrecision(w)}
|
|
1550
|
+
float verticalAperture = ${((Math.abs(n.top) + Math.abs(n.bottom)) * 10).toPrecision(w)}
|
|
1551
|
+
token projection = "orthographic"
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
` : `def Camera "${e}"
|
|
1555
|
+
{
|
|
1556
|
+
matrix4d xformOp:transform = ${s}
|
|
1557
|
+
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
1558
|
+
|
|
1559
|
+
float2 clippingRange = (${n.near.toPrecision(w)}, ${n.far.toPrecision(w)})
|
|
1560
|
+
float focalLength = ${n.getFocalLength().toPrecision(w)}
|
|
1561
|
+
float focusDistance = ${n.focus.toPrecision(w)}
|
|
1562
|
+
float horizontalAperture = ${n.getFilmWidth().toPrecision(w)}
|
|
1563
|
+
token projection = "perspective"
|
|
1564
|
+
float verticalAperture = ${n.getFilmHeight().toPrecision(w)}
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
`;
|
|
1568
|
+
}
|
|
1569
|
+
class Ct {
|
|
1570
|
+
constructor() {
|
|
1571
|
+
Y(this, "_gltfExporter");
|
|
1572
|
+
Y(this, "_usdzExporter");
|
|
1573
|
+
this._gltfExporter = new Q(), this._usdzExporter = new pt();
|
|
1574
|
+
}
|
|
1575
|
+
async export(e, s, t) {
|
|
1576
|
+
switch (s) {
|
|
1577
|
+
case "glb":
|
|
1578
|
+
return this._exportGlb(e, t);
|
|
1579
|
+
case "gltf":
|
|
1580
|
+
return this._exportGltf(e, t);
|
|
1581
|
+
case "usdz":
|
|
1582
|
+
return this._exportUsdz(e, t);
|
|
1583
|
+
default:
|
|
1584
|
+
throw new He(`Unsupported file type: ${s}`, s);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
async _exportGlb(e, s) {
|
|
1588
|
+
try {
|
|
1589
|
+
const t = await this._gltfExporter.parseAsync(e, {
|
|
1590
|
+
...s,
|
|
1591
|
+
binary: !0
|
|
1592
|
+
});
|
|
1593
|
+
if (t instanceof ArrayBuffer)
|
|
1594
|
+
return t;
|
|
1595
|
+
throw new N("Failed to export GLB: expected ArrayBuffer");
|
|
1596
|
+
} catch (t) {
|
|
1597
|
+
throw t instanceof N ? t : new N("Failed to export GLB", t);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
async _exportGltf(e, s) {
|
|
1601
|
+
try {
|
|
1602
|
+
const t = await this._gltfExporter.parseAsync(e, {
|
|
1603
|
+
...s,
|
|
1604
|
+
binary: !1
|
|
1605
|
+
}), i = JSON.stringify(t);
|
|
1606
|
+
return new TextEncoder().encode(i).buffer;
|
|
1607
|
+
} catch (t) {
|
|
1608
|
+
throw t instanceof N ? t : new N("Failed to export GLTF", t);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
async _exportUsdz(e, s) {
|
|
1612
|
+
try {
|
|
1613
|
+
return (await this._usdzExporter.parse(e, s)).buffer;
|
|
1614
|
+
} catch (t) {
|
|
1615
|
+
throw t instanceof N ? t : new N("Failed to export USDZ", t);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
export {
|
|
1620
|
+
Ct as AssetExporter
|
|
1621
|
+
};
|
|
1622
|
+
//# sourceMappingURL=AssetExporter.mjs.map
|