@linxai/3d-web 0.1.0 → 0.1.1
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/dist/chunk-WUKYLWAZ.mjs +0 -0
- package/dist/hls-UG2Y6VAT.mjs +33000 -0
- package/dist/index.d.mts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +4969 -0
- package/dist/index.mjs +4929 -0
- package/dist/vision_bundle-JCRSWKU6.mjs +4084 -0
- package/package.json +13 -7
- package/src/adapters/AnimationLoaderAdapter.ts +0 -34
- package/src/adapters/ModelLoaderAdapter.ts +0 -34
- package/src/builders/SceneBuilder.tsx +0 -91
- package/src/components/CharacterOverlay.tsx +0 -183
- package/src/components/CharacterView.tsx +0 -165
- package/src/components/ProgressBar.tsx +0 -69
- package/src/components/Scene3D.tsx +0 -89
- package/src/components/Subtitle.tsx +0 -89
- package/src/hooks/useModelLoader.ts +0 -12
- package/src/index.tsx +0 -44
- package/tsconfig.json +0 -23
- package/tsup.config.ts +0 -19
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4929 @@
|
|
|
1
|
+
import "./chunk-WUKYLWAZ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/components/CharacterView.tsx
|
|
4
|
+
import { Suspense, useRef, useEffect as useEffect3, useCallback, useState as useState2 } from "react";
|
|
5
|
+
import { useCharacterController } from "@linxai/3d-shared/internal";
|
|
6
|
+
|
|
7
|
+
// src/components/Scene3D.tsx
|
|
8
|
+
import { LoadingProvider, useLoading } from "@linxai/3d-shared/internal";
|
|
9
|
+
|
|
10
|
+
// src/components/ProgressBar.tsx
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
function ProgressBar({
|
|
13
|
+
progress,
|
|
14
|
+
style,
|
|
15
|
+
color = "#007AFF",
|
|
16
|
+
backgroundColor = "#E5E5E5",
|
|
17
|
+
height = 8
|
|
18
|
+
}) {
|
|
19
|
+
const percentage = Math.round(Math.max(0, Math.min(1, progress)) * 100);
|
|
20
|
+
return /* @__PURE__ */ jsxs(
|
|
21
|
+
"div",
|
|
22
|
+
{
|
|
23
|
+
style: {
|
|
24
|
+
width: "100%",
|
|
25
|
+
padding: 8,
|
|
26
|
+
backgroundColor: "#2a2a2a",
|
|
27
|
+
borderRadius: 8,
|
|
28
|
+
...style
|
|
29
|
+
},
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
style: {
|
|
35
|
+
width: "100%",
|
|
36
|
+
height,
|
|
37
|
+
backgroundColor,
|
|
38
|
+
borderRadius: 4,
|
|
39
|
+
overflow: "hidden"
|
|
40
|
+
},
|
|
41
|
+
children: /* @__PURE__ */ jsx(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
style: {
|
|
45
|
+
width: `${percentage}%`,
|
|
46
|
+
height: "100%",
|
|
47
|
+
backgroundColor: color,
|
|
48
|
+
transition: "width 0.3s ease"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ jsxs(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
style: {
|
|
58
|
+
marginTop: 8,
|
|
59
|
+
fontSize: 14,
|
|
60
|
+
fontWeight: "bold",
|
|
61
|
+
color: "#ffffff"
|
|
62
|
+
},
|
|
63
|
+
children: [
|
|
64
|
+
percentage,
|
|
65
|
+
"%"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/builders/SceneBuilder.tsx
|
|
75
|
+
import { Canvas } from "@react-three/fiber";
|
|
76
|
+
|
|
77
|
+
// ../../node_modules/@babel/runtime/helpers/esm/extends.js
|
|
78
|
+
function _extends() {
|
|
79
|
+
return _extends = Object.assign ? Object.assign.bind() : function(n) {
|
|
80
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
81
|
+
var t = arguments[e];
|
|
82
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
83
|
+
}
|
|
84
|
+
return n;
|
|
85
|
+
}, _extends.apply(null, arguments);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ../../node_modules/three-stdlib/_polyfill/constants.js
|
|
89
|
+
import { REVISION } from "three";
|
|
90
|
+
var version = /* @__PURE__ */ (() => parseInt(REVISION.replace(/\D+/g, "")))();
|
|
91
|
+
|
|
92
|
+
// ../../node_modules/three-stdlib/utils/BufferGeometryUtils.js
|
|
93
|
+
import { BufferGeometry, BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, TrianglesDrawMode, TriangleFanDrawMode, TriangleStripDrawMode, Vector3, Float32BufferAttribute } from "three";
|
|
94
|
+
function toTrianglesDrawMode(geometry, drawMode) {
|
|
95
|
+
if (drawMode === TrianglesDrawMode) {
|
|
96
|
+
console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.");
|
|
97
|
+
return geometry;
|
|
98
|
+
}
|
|
99
|
+
if (drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode) {
|
|
100
|
+
let index = geometry.getIndex();
|
|
101
|
+
if (index === null) {
|
|
102
|
+
const indices = [];
|
|
103
|
+
const position = geometry.getAttribute("position");
|
|
104
|
+
if (position !== void 0) {
|
|
105
|
+
for (let i = 0; i < position.count; i++) {
|
|
106
|
+
indices.push(i);
|
|
107
|
+
}
|
|
108
|
+
geometry.setIndex(indices);
|
|
109
|
+
index = geometry.getIndex();
|
|
110
|
+
} else {
|
|
111
|
+
console.error(
|
|
112
|
+
"THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."
|
|
113
|
+
);
|
|
114
|
+
return geometry;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const numberOfTriangles = index.count - 2;
|
|
118
|
+
const newIndices = [];
|
|
119
|
+
if (index) {
|
|
120
|
+
if (drawMode === TriangleFanDrawMode) {
|
|
121
|
+
for (let i = 1; i <= numberOfTriangles; i++) {
|
|
122
|
+
newIndices.push(index.getX(0));
|
|
123
|
+
newIndices.push(index.getX(i));
|
|
124
|
+
newIndices.push(index.getX(i + 1));
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
for (let i = 0; i < numberOfTriangles; i++) {
|
|
128
|
+
if (i % 2 === 0) {
|
|
129
|
+
newIndices.push(index.getX(i));
|
|
130
|
+
newIndices.push(index.getX(i + 1));
|
|
131
|
+
newIndices.push(index.getX(i + 2));
|
|
132
|
+
} else {
|
|
133
|
+
newIndices.push(index.getX(i + 2));
|
|
134
|
+
newIndices.push(index.getX(i + 1));
|
|
135
|
+
newIndices.push(index.getX(i));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (newIndices.length / 3 !== numberOfTriangles) {
|
|
141
|
+
console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
|
|
142
|
+
}
|
|
143
|
+
const newGeometry = geometry.clone();
|
|
144
|
+
newGeometry.setIndex(newIndices);
|
|
145
|
+
newGeometry.clearGroups();
|
|
146
|
+
return newGeometry;
|
|
147
|
+
} else {
|
|
148
|
+
console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", drawMode);
|
|
149
|
+
return geometry;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ../../node_modules/three-stdlib/controls/EventDispatcher.js
|
|
154
|
+
var __defProp = Object.defineProperty;
|
|
155
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
156
|
+
var __publicField = (obj, key, value) => {
|
|
157
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
158
|
+
return value;
|
|
159
|
+
};
|
|
160
|
+
var EventDispatcher = class {
|
|
161
|
+
constructor() {
|
|
162
|
+
__publicField(this, "_listeners");
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Adds a listener to an event type.
|
|
166
|
+
* @param type The type of event to listen to.
|
|
167
|
+
* @param listener The function that gets called when the event is fired.
|
|
168
|
+
*/
|
|
169
|
+
addEventListener(type, listener) {
|
|
170
|
+
if (this._listeners === void 0)
|
|
171
|
+
this._listeners = {};
|
|
172
|
+
const listeners = this._listeners;
|
|
173
|
+
if (listeners[type] === void 0) {
|
|
174
|
+
listeners[type] = [];
|
|
175
|
+
}
|
|
176
|
+
if (listeners[type].indexOf(listener) === -1) {
|
|
177
|
+
listeners[type].push(listener);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Checks if listener is added to an event type.
|
|
182
|
+
* @param type The type of event to listen to.
|
|
183
|
+
* @param listener The function that gets called when the event is fired.
|
|
184
|
+
*/
|
|
185
|
+
hasEventListener(type, listener) {
|
|
186
|
+
if (this._listeners === void 0)
|
|
187
|
+
return false;
|
|
188
|
+
const listeners = this._listeners;
|
|
189
|
+
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Removes a listener from an event type.
|
|
193
|
+
* @param type The type of the listener that gets removed.
|
|
194
|
+
* @param listener The listener function that gets removed.
|
|
195
|
+
*/
|
|
196
|
+
removeEventListener(type, listener) {
|
|
197
|
+
if (this._listeners === void 0)
|
|
198
|
+
return;
|
|
199
|
+
const listeners = this._listeners;
|
|
200
|
+
const listenerArray = listeners[type];
|
|
201
|
+
if (listenerArray !== void 0) {
|
|
202
|
+
const index = listenerArray.indexOf(listener);
|
|
203
|
+
if (index !== -1) {
|
|
204
|
+
listenerArray.splice(index, 1);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Fire an event type.
|
|
210
|
+
* @param event The event that gets fired.
|
|
211
|
+
*/
|
|
212
|
+
dispatchEvent(event) {
|
|
213
|
+
if (this._listeners === void 0)
|
|
214
|
+
return;
|
|
215
|
+
const listeners = this._listeners;
|
|
216
|
+
const listenerArray = listeners[event.type];
|
|
217
|
+
if (listenerArray !== void 0) {
|
|
218
|
+
event.target = this;
|
|
219
|
+
const array = listenerArray.slice(0);
|
|
220
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
221
|
+
array[i].call(this, event);
|
|
222
|
+
}
|
|
223
|
+
event.target = null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// ../../node_modules/three-stdlib/controls/OrbitControls.js
|
|
229
|
+
import { Vector3 as Vector32, MOUSE, TOUCH, Quaternion, PerspectiveCamera, OrthographicCamera, Spherical, Vector2, Ray, Plane } from "three";
|
|
230
|
+
var __defProp2 = Object.defineProperty;
|
|
231
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
232
|
+
var __publicField2 = (obj, key, value) => {
|
|
233
|
+
__defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
234
|
+
return value;
|
|
235
|
+
};
|
|
236
|
+
var _ray = /* @__PURE__ */ new Ray();
|
|
237
|
+
var _plane = /* @__PURE__ */ new Plane();
|
|
238
|
+
var TILT_LIMIT = Math.cos(70 * (Math.PI / 180));
|
|
239
|
+
var moduloWrapAround = (offset, capacity) => (offset % capacity + capacity) % capacity;
|
|
240
|
+
var OrbitControls = class extends EventDispatcher {
|
|
241
|
+
constructor(object, domElement) {
|
|
242
|
+
super();
|
|
243
|
+
__publicField2(this, "object");
|
|
244
|
+
__publicField2(this, "domElement");
|
|
245
|
+
__publicField2(this, "enabled", true);
|
|
246
|
+
__publicField2(this, "target", new Vector32());
|
|
247
|
+
__publicField2(this, "minDistance", 0);
|
|
248
|
+
__publicField2(this, "maxDistance", Infinity);
|
|
249
|
+
__publicField2(this, "minZoom", 0);
|
|
250
|
+
__publicField2(this, "maxZoom", Infinity);
|
|
251
|
+
__publicField2(this, "minPolarAngle", 0);
|
|
252
|
+
__publicField2(this, "maxPolarAngle", Math.PI);
|
|
253
|
+
__publicField2(this, "minAzimuthAngle", -Infinity);
|
|
254
|
+
__publicField2(this, "maxAzimuthAngle", Infinity);
|
|
255
|
+
__publicField2(this, "enableDamping", false);
|
|
256
|
+
__publicField2(this, "dampingFactor", 0.05);
|
|
257
|
+
__publicField2(this, "enableZoom", true);
|
|
258
|
+
__publicField2(this, "zoomSpeed", 1);
|
|
259
|
+
__publicField2(this, "enableRotate", true);
|
|
260
|
+
__publicField2(this, "rotateSpeed", 1);
|
|
261
|
+
__publicField2(this, "enablePan", true);
|
|
262
|
+
__publicField2(this, "panSpeed", 1);
|
|
263
|
+
__publicField2(this, "screenSpacePanning", true);
|
|
264
|
+
__publicField2(this, "keyPanSpeed", 7);
|
|
265
|
+
__publicField2(this, "zoomToCursor", false);
|
|
266
|
+
__publicField2(this, "autoRotate", false);
|
|
267
|
+
__publicField2(this, "autoRotateSpeed", 2);
|
|
268
|
+
__publicField2(this, "reverseOrbit", false);
|
|
269
|
+
__publicField2(this, "reverseHorizontalOrbit", false);
|
|
270
|
+
__publicField2(this, "reverseVerticalOrbit", false);
|
|
271
|
+
__publicField2(this, "keys", { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" });
|
|
272
|
+
__publicField2(this, "mouseButtons", {
|
|
273
|
+
LEFT: MOUSE.ROTATE,
|
|
274
|
+
MIDDLE: MOUSE.DOLLY,
|
|
275
|
+
RIGHT: MOUSE.PAN
|
|
276
|
+
});
|
|
277
|
+
__publicField2(this, "touches", { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN });
|
|
278
|
+
__publicField2(this, "target0");
|
|
279
|
+
__publicField2(this, "position0");
|
|
280
|
+
__publicField2(this, "zoom0");
|
|
281
|
+
__publicField2(this, "_domElementKeyEvents", null);
|
|
282
|
+
__publicField2(this, "getPolarAngle");
|
|
283
|
+
__publicField2(this, "getAzimuthalAngle");
|
|
284
|
+
__publicField2(this, "setPolarAngle");
|
|
285
|
+
__publicField2(this, "setAzimuthalAngle");
|
|
286
|
+
__publicField2(this, "getDistance");
|
|
287
|
+
__publicField2(this, "getZoomScale");
|
|
288
|
+
__publicField2(this, "listenToKeyEvents");
|
|
289
|
+
__publicField2(this, "stopListenToKeyEvents");
|
|
290
|
+
__publicField2(this, "saveState");
|
|
291
|
+
__publicField2(this, "reset");
|
|
292
|
+
__publicField2(this, "update");
|
|
293
|
+
__publicField2(this, "connect");
|
|
294
|
+
__publicField2(this, "dispose");
|
|
295
|
+
__publicField2(this, "dollyIn");
|
|
296
|
+
__publicField2(this, "dollyOut");
|
|
297
|
+
__publicField2(this, "getScale");
|
|
298
|
+
__publicField2(this, "setScale");
|
|
299
|
+
this.object = object;
|
|
300
|
+
this.domElement = domElement;
|
|
301
|
+
this.target0 = this.target.clone();
|
|
302
|
+
this.position0 = this.object.position.clone();
|
|
303
|
+
this.zoom0 = this.object.zoom;
|
|
304
|
+
this.getPolarAngle = () => spherical.phi;
|
|
305
|
+
this.getAzimuthalAngle = () => spherical.theta;
|
|
306
|
+
this.setPolarAngle = (value) => {
|
|
307
|
+
let phi = moduloWrapAround(value, 2 * Math.PI);
|
|
308
|
+
let currentPhi = spherical.phi;
|
|
309
|
+
if (currentPhi < 0)
|
|
310
|
+
currentPhi += 2 * Math.PI;
|
|
311
|
+
if (phi < 0)
|
|
312
|
+
phi += 2 * Math.PI;
|
|
313
|
+
let phiDist = Math.abs(phi - currentPhi);
|
|
314
|
+
if (2 * Math.PI - phiDist < phiDist) {
|
|
315
|
+
if (phi < currentPhi) {
|
|
316
|
+
phi += 2 * Math.PI;
|
|
317
|
+
} else {
|
|
318
|
+
currentPhi += 2 * Math.PI;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
sphericalDelta.phi = phi - currentPhi;
|
|
322
|
+
scope.update();
|
|
323
|
+
};
|
|
324
|
+
this.setAzimuthalAngle = (value) => {
|
|
325
|
+
let theta = moduloWrapAround(value, 2 * Math.PI);
|
|
326
|
+
let currentTheta = spherical.theta;
|
|
327
|
+
if (currentTheta < 0)
|
|
328
|
+
currentTheta += 2 * Math.PI;
|
|
329
|
+
if (theta < 0)
|
|
330
|
+
theta += 2 * Math.PI;
|
|
331
|
+
let thetaDist = Math.abs(theta - currentTheta);
|
|
332
|
+
if (2 * Math.PI - thetaDist < thetaDist) {
|
|
333
|
+
if (theta < currentTheta) {
|
|
334
|
+
theta += 2 * Math.PI;
|
|
335
|
+
} else {
|
|
336
|
+
currentTheta += 2 * Math.PI;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
sphericalDelta.theta = theta - currentTheta;
|
|
340
|
+
scope.update();
|
|
341
|
+
};
|
|
342
|
+
this.getDistance = () => scope.object.position.distanceTo(scope.target);
|
|
343
|
+
this.listenToKeyEvents = (domElement2) => {
|
|
344
|
+
domElement2.addEventListener("keydown", onKeyDown);
|
|
345
|
+
this._domElementKeyEvents = domElement2;
|
|
346
|
+
};
|
|
347
|
+
this.stopListenToKeyEvents = () => {
|
|
348
|
+
this._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
349
|
+
this._domElementKeyEvents = null;
|
|
350
|
+
};
|
|
351
|
+
this.saveState = () => {
|
|
352
|
+
scope.target0.copy(scope.target);
|
|
353
|
+
scope.position0.copy(scope.object.position);
|
|
354
|
+
scope.zoom0 = scope.object.zoom;
|
|
355
|
+
};
|
|
356
|
+
this.reset = () => {
|
|
357
|
+
scope.target.copy(scope.target0);
|
|
358
|
+
scope.object.position.copy(scope.position0);
|
|
359
|
+
scope.object.zoom = scope.zoom0;
|
|
360
|
+
scope.object.updateProjectionMatrix();
|
|
361
|
+
scope.dispatchEvent(changeEvent);
|
|
362
|
+
scope.update();
|
|
363
|
+
state = STATE.NONE;
|
|
364
|
+
};
|
|
365
|
+
this.update = (() => {
|
|
366
|
+
const offset = new Vector32();
|
|
367
|
+
const up = new Vector32(0, 1, 0);
|
|
368
|
+
const quat = new Quaternion().setFromUnitVectors(object.up, up);
|
|
369
|
+
const quatInverse = quat.clone().invert();
|
|
370
|
+
const lastPosition = new Vector32();
|
|
371
|
+
const lastQuaternion = new Quaternion();
|
|
372
|
+
const twoPI = 2 * Math.PI;
|
|
373
|
+
return function update() {
|
|
374
|
+
const position = scope.object.position;
|
|
375
|
+
quat.setFromUnitVectors(object.up, up);
|
|
376
|
+
quatInverse.copy(quat).invert();
|
|
377
|
+
offset.copy(position).sub(scope.target);
|
|
378
|
+
offset.applyQuaternion(quat);
|
|
379
|
+
spherical.setFromVector3(offset);
|
|
380
|
+
if (scope.autoRotate && state === STATE.NONE) {
|
|
381
|
+
rotateLeft(getAutoRotationAngle());
|
|
382
|
+
}
|
|
383
|
+
if (scope.enableDamping) {
|
|
384
|
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
385
|
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
386
|
+
} else {
|
|
387
|
+
spherical.theta += sphericalDelta.theta;
|
|
388
|
+
spherical.phi += sphericalDelta.phi;
|
|
389
|
+
}
|
|
390
|
+
let min = scope.minAzimuthAngle;
|
|
391
|
+
let max = scope.maxAzimuthAngle;
|
|
392
|
+
if (isFinite(min) && isFinite(max)) {
|
|
393
|
+
if (min < -Math.PI)
|
|
394
|
+
min += twoPI;
|
|
395
|
+
else if (min > Math.PI)
|
|
396
|
+
min -= twoPI;
|
|
397
|
+
if (max < -Math.PI)
|
|
398
|
+
max += twoPI;
|
|
399
|
+
else if (max > Math.PI)
|
|
400
|
+
max -= twoPI;
|
|
401
|
+
if (min <= max) {
|
|
402
|
+
spherical.theta = Math.max(min, Math.min(max, spherical.theta));
|
|
403
|
+
} else {
|
|
404
|
+
spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
|
|
408
|
+
spherical.makeSafe();
|
|
409
|
+
if (scope.enableDamping === true) {
|
|
410
|
+
scope.target.addScaledVector(panOffset, scope.dampingFactor);
|
|
411
|
+
} else {
|
|
412
|
+
scope.target.add(panOffset);
|
|
413
|
+
}
|
|
414
|
+
if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) {
|
|
415
|
+
spherical.radius = clampDistance(spherical.radius);
|
|
416
|
+
} else {
|
|
417
|
+
spherical.radius = clampDistance(spherical.radius * scale);
|
|
418
|
+
}
|
|
419
|
+
offset.setFromSpherical(spherical);
|
|
420
|
+
offset.applyQuaternion(quatInverse);
|
|
421
|
+
position.copy(scope.target).add(offset);
|
|
422
|
+
if (!scope.object.matrixAutoUpdate)
|
|
423
|
+
scope.object.updateMatrix();
|
|
424
|
+
scope.object.lookAt(scope.target);
|
|
425
|
+
if (scope.enableDamping === true) {
|
|
426
|
+
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
427
|
+
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
428
|
+
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
429
|
+
} else {
|
|
430
|
+
sphericalDelta.set(0, 0, 0);
|
|
431
|
+
panOffset.set(0, 0, 0);
|
|
432
|
+
}
|
|
433
|
+
let zoomChanged = false;
|
|
434
|
+
if (scope.zoomToCursor && performCursorZoom) {
|
|
435
|
+
let newRadius = null;
|
|
436
|
+
if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera) {
|
|
437
|
+
const prevRadius = offset.length();
|
|
438
|
+
newRadius = clampDistance(prevRadius * scale);
|
|
439
|
+
const radiusDelta = prevRadius - newRadius;
|
|
440
|
+
scope.object.position.addScaledVector(dollyDirection, radiusDelta);
|
|
441
|
+
scope.object.updateMatrixWorld();
|
|
442
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
443
|
+
const mouseBefore = new Vector32(mouse.x, mouse.y, 0);
|
|
444
|
+
mouseBefore.unproject(scope.object);
|
|
445
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
|
|
446
|
+
scope.object.updateProjectionMatrix();
|
|
447
|
+
zoomChanged = true;
|
|
448
|
+
const mouseAfter = new Vector32(mouse.x, mouse.y, 0);
|
|
449
|
+
mouseAfter.unproject(scope.object);
|
|
450
|
+
scope.object.position.sub(mouseAfter).add(mouseBefore);
|
|
451
|
+
scope.object.updateMatrixWorld();
|
|
452
|
+
newRadius = offset.length();
|
|
453
|
+
} else {
|
|
454
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
|
|
455
|
+
scope.zoomToCursor = false;
|
|
456
|
+
}
|
|
457
|
+
if (newRadius !== null) {
|
|
458
|
+
if (scope.screenSpacePanning) {
|
|
459
|
+
scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position);
|
|
460
|
+
} else {
|
|
461
|
+
_ray.origin.copy(scope.object.position);
|
|
462
|
+
_ray.direction.set(0, 0, -1).transformDirection(scope.object.matrix);
|
|
463
|
+
if (Math.abs(scope.object.up.dot(_ray.direction)) < TILT_LIMIT) {
|
|
464
|
+
object.lookAt(scope.target);
|
|
465
|
+
} else {
|
|
466
|
+
_plane.setFromNormalAndCoplanarPoint(scope.object.up, scope.target);
|
|
467
|
+
_ray.intersectPlane(_plane, scope.target);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
} else if (scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
|
|
472
|
+
zoomChanged = scale !== 1;
|
|
473
|
+
if (zoomChanged) {
|
|
474
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
|
|
475
|
+
scope.object.updateProjectionMatrix();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
scale = 1;
|
|
479
|
+
performCursorZoom = false;
|
|
480
|
+
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
481
|
+
scope.dispatchEvent(changeEvent);
|
|
482
|
+
lastPosition.copy(scope.object.position);
|
|
483
|
+
lastQuaternion.copy(scope.object.quaternion);
|
|
484
|
+
zoomChanged = false;
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
return false;
|
|
488
|
+
};
|
|
489
|
+
})();
|
|
490
|
+
this.connect = (domElement2) => {
|
|
491
|
+
scope.domElement = domElement2;
|
|
492
|
+
scope.domElement.style.touchAction = "none";
|
|
493
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu);
|
|
494
|
+
scope.domElement.addEventListener("pointerdown", onPointerDown);
|
|
495
|
+
scope.domElement.addEventListener("pointercancel", onPointerUp);
|
|
496
|
+
scope.domElement.addEventListener("wheel", onMouseWheel);
|
|
497
|
+
};
|
|
498
|
+
this.dispose = () => {
|
|
499
|
+
var _a, _b, _c, _d, _e, _f;
|
|
500
|
+
if (scope.domElement) {
|
|
501
|
+
scope.domElement.style.touchAction = "auto";
|
|
502
|
+
}
|
|
503
|
+
(_a = scope.domElement) == null ? void 0 : _a.removeEventListener("contextmenu", onContextMenu);
|
|
504
|
+
(_b = scope.domElement) == null ? void 0 : _b.removeEventListener("pointerdown", onPointerDown);
|
|
505
|
+
(_c = scope.domElement) == null ? void 0 : _c.removeEventListener("pointercancel", onPointerUp);
|
|
506
|
+
(_d = scope.domElement) == null ? void 0 : _d.removeEventListener("wheel", onMouseWheel);
|
|
507
|
+
(_e = scope.domElement) == null ? void 0 : _e.ownerDocument.removeEventListener("pointermove", onPointerMove);
|
|
508
|
+
(_f = scope.domElement) == null ? void 0 : _f.ownerDocument.removeEventListener("pointerup", onPointerUp);
|
|
509
|
+
if (scope._domElementKeyEvents !== null) {
|
|
510
|
+
scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
const scope = this;
|
|
514
|
+
const changeEvent = { type: "change" };
|
|
515
|
+
const startEvent = { type: "start" };
|
|
516
|
+
const endEvent = { type: "end" };
|
|
517
|
+
const STATE = {
|
|
518
|
+
NONE: -1,
|
|
519
|
+
ROTATE: 0,
|
|
520
|
+
DOLLY: 1,
|
|
521
|
+
PAN: 2,
|
|
522
|
+
TOUCH_ROTATE: 3,
|
|
523
|
+
TOUCH_PAN: 4,
|
|
524
|
+
TOUCH_DOLLY_PAN: 5,
|
|
525
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
526
|
+
};
|
|
527
|
+
let state = STATE.NONE;
|
|
528
|
+
const EPS = 1e-6;
|
|
529
|
+
const spherical = new Spherical();
|
|
530
|
+
const sphericalDelta = new Spherical();
|
|
531
|
+
let scale = 1;
|
|
532
|
+
const panOffset = new Vector32();
|
|
533
|
+
const rotateStart = new Vector2();
|
|
534
|
+
const rotateEnd = new Vector2();
|
|
535
|
+
const rotateDelta = new Vector2();
|
|
536
|
+
const panStart = new Vector2();
|
|
537
|
+
const panEnd = new Vector2();
|
|
538
|
+
const panDelta = new Vector2();
|
|
539
|
+
const dollyStart = new Vector2();
|
|
540
|
+
const dollyEnd = new Vector2();
|
|
541
|
+
const dollyDelta = new Vector2();
|
|
542
|
+
const dollyDirection = new Vector32();
|
|
543
|
+
const mouse = new Vector2();
|
|
544
|
+
let performCursorZoom = false;
|
|
545
|
+
const pointers = [];
|
|
546
|
+
const pointerPositions = {};
|
|
547
|
+
function getAutoRotationAngle() {
|
|
548
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
549
|
+
}
|
|
550
|
+
function getZoomScale() {
|
|
551
|
+
return Math.pow(0.95, scope.zoomSpeed);
|
|
552
|
+
}
|
|
553
|
+
function rotateLeft(angle) {
|
|
554
|
+
if (scope.reverseOrbit || scope.reverseHorizontalOrbit) {
|
|
555
|
+
sphericalDelta.theta += angle;
|
|
556
|
+
} else {
|
|
557
|
+
sphericalDelta.theta -= angle;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function rotateUp(angle) {
|
|
561
|
+
if (scope.reverseOrbit || scope.reverseVerticalOrbit) {
|
|
562
|
+
sphericalDelta.phi += angle;
|
|
563
|
+
} else {
|
|
564
|
+
sphericalDelta.phi -= angle;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const panLeft = (() => {
|
|
568
|
+
const v = new Vector32();
|
|
569
|
+
return function panLeft2(distance, objectMatrix) {
|
|
570
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
571
|
+
v.multiplyScalar(-distance);
|
|
572
|
+
panOffset.add(v);
|
|
573
|
+
};
|
|
574
|
+
})();
|
|
575
|
+
const panUp = (() => {
|
|
576
|
+
const v = new Vector32();
|
|
577
|
+
return function panUp2(distance, objectMatrix) {
|
|
578
|
+
if (scope.screenSpacePanning === true) {
|
|
579
|
+
v.setFromMatrixColumn(objectMatrix, 1);
|
|
580
|
+
} else {
|
|
581
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
582
|
+
v.crossVectors(scope.object.up, v);
|
|
583
|
+
}
|
|
584
|
+
v.multiplyScalar(distance);
|
|
585
|
+
panOffset.add(v);
|
|
586
|
+
};
|
|
587
|
+
})();
|
|
588
|
+
const pan = (() => {
|
|
589
|
+
const offset = new Vector32();
|
|
590
|
+
return function pan2(deltaX, deltaY) {
|
|
591
|
+
const element = scope.domElement;
|
|
592
|
+
if (element && scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera) {
|
|
593
|
+
const position = scope.object.position;
|
|
594
|
+
offset.copy(position).sub(scope.target);
|
|
595
|
+
let targetDistance = offset.length();
|
|
596
|
+
targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
|
|
597
|
+
panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
|
|
598
|
+
panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
|
|
599
|
+
} else if (element && scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
|
|
600
|
+
panLeft(
|
|
601
|
+
deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth,
|
|
602
|
+
scope.object.matrix
|
|
603
|
+
);
|
|
604
|
+
panUp(
|
|
605
|
+
deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight,
|
|
606
|
+
scope.object.matrix
|
|
607
|
+
);
|
|
608
|
+
} else {
|
|
609
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
|
|
610
|
+
scope.enablePan = false;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
})();
|
|
614
|
+
function setScale(newScale) {
|
|
615
|
+
if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera || scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
|
|
616
|
+
scale = newScale;
|
|
617
|
+
} else {
|
|
618
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
619
|
+
scope.enableZoom = false;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function dollyOut(dollyScale) {
|
|
623
|
+
setScale(scale / dollyScale);
|
|
624
|
+
}
|
|
625
|
+
function dollyIn(dollyScale) {
|
|
626
|
+
setScale(scale * dollyScale);
|
|
627
|
+
}
|
|
628
|
+
function updateMouseParameters(event) {
|
|
629
|
+
if (!scope.zoomToCursor || !scope.domElement) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
performCursorZoom = true;
|
|
633
|
+
const rect = scope.domElement.getBoundingClientRect();
|
|
634
|
+
const x = event.clientX - rect.left;
|
|
635
|
+
const y = event.clientY - rect.top;
|
|
636
|
+
const w = rect.width;
|
|
637
|
+
const h = rect.height;
|
|
638
|
+
mouse.x = x / w * 2 - 1;
|
|
639
|
+
mouse.y = -(y / h) * 2 + 1;
|
|
640
|
+
dollyDirection.set(mouse.x, mouse.y, 1).unproject(scope.object).sub(scope.object.position).normalize();
|
|
641
|
+
}
|
|
642
|
+
function clampDistance(dist) {
|
|
643
|
+
return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist));
|
|
644
|
+
}
|
|
645
|
+
function handleMouseDownRotate(event) {
|
|
646
|
+
rotateStart.set(event.clientX, event.clientY);
|
|
647
|
+
}
|
|
648
|
+
function handleMouseDownDolly(event) {
|
|
649
|
+
updateMouseParameters(event);
|
|
650
|
+
dollyStart.set(event.clientX, event.clientY);
|
|
651
|
+
}
|
|
652
|
+
function handleMouseDownPan(event) {
|
|
653
|
+
panStart.set(event.clientX, event.clientY);
|
|
654
|
+
}
|
|
655
|
+
function handleMouseMoveRotate(event) {
|
|
656
|
+
rotateEnd.set(event.clientX, event.clientY);
|
|
657
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
658
|
+
const element = scope.domElement;
|
|
659
|
+
if (element) {
|
|
660
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
661
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
662
|
+
}
|
|
663
|
+
rotateStart.copy(rotateEnd);
|
|
664
|
+
scope.update();
|
|
665
|
+
}
|
|
666
|
+
function handleMouseMoveDolly(event) {
|
|
667
|
+
dollyEnd.set(event.clientX, event.clientY);
|
|
668
|
+
dollyDelta.subVectors(dollyEnd, dollyStart);
|
|
669
|
+
if (dollyDelta.y > 0) {
|
|
670
|
+
dollyOut(getZoomScale());
|
|
671
|
+
} else if (dollyDelta.y < 0) {
|
|
672
|
+
dollyIn(getZoomScale());
|
|
673
|
+
}
|
|
674
|
+
dollyStart.copy(dollyEnd);
|
|
675
|
+
scope.update();
|
|
676
|
+
}
|
|
677
|
+
function handleMouseMovePan(event) {
|
|
678
|
+
panEnd.set(event.clientX, event.clientY);
|
|
679
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
680
|
+
pan(panDelta.x, panDelta.y);
|
|
681
|
+
panStart.copy(panEnd);
|
|
682
|
+
scope.update();
|
|
683
|
+
}
|
|
684
|
+
function handleMouseWheel(event) {
|
|
685
|
+
updateMouseParameters(event);
|
|
686
|
+
if (event.deltaY < 0) {
|
|
687
|
+
dollyIn(getZoomScale());
|
|
688
|
+
} else if (event.deltaY > 0) {
|
|
689
|
+
dollyOut(getZoomScale());
|
|
690
|
+
}
|
|
691
|
+
scope.update();
|
|
692
|
+
}
|
|
693
|
+
function handleKeyDown(event) {
|
|
694
|
+
let needsUpdate = false;
|
|
695
|
+
switch (event.code) {
|
|
696
|
+
case scope.keys.UP:
|
|
697
|
+
pan(0, scope.keyPanSpeed);
|
|
698
|
+
needsUpdate = true;
|
|
699
|
+
break;
|
|
700
|
+
case scope.keys.BOTTOM:
|
|
701
|
+
pan(0, -scope.keyPanSpeed);
|
|
702
|
+
needsUpdate = true;
|
|
703
|
+
break;
|
|
704
|
+
case scope.keys.LEFT:
|
|
705
|
+
pan(scope.keyPanSpeed, 0);
|
|
706
|
+
needsUpdate = true;
|
|
707
|
+
break;
|
|
708
|
+
case scope.keys.RIGHT:
|
|
709
|
+
pan(-scope.keyPanSpeed, 0);
|
|
710
|
+
needsUpdate = true;
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
if (needsUpdate) {
|
|
714
|
+
event.preventDefault();
|
|
715
|
+
scope.update();
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function handleTouchStartRotate() {
|
|
719
|
+
if (pointers.length == 1) {
|
|
720
|
+
rotateStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
721
|
+
} else {
|
|
722
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
723
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
724
|
+
rotateStart.set(x, y);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function handleTouchStartPan() {
|
|
728
|
+
if (pointers.length == 1) {
|
|
729
|
+
panStart.set(pointers[0].pageX, pointers[0].pageY);
|
|
730
|
+
} else {
|
|
731
|
+
const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
|
|
732
|
+
const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
|
|
733
|
+
panStart.set(x, y);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function handleTouchStartDolly() {
|
|
737
|
+
const dx = pointers[0].pageX - pointers[1].pageX;
|
|
738
|
+
const dy = pointers[0].pageY - pointers[1].pageY;
|
|
739
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
740
|
+
dollyStart.set(0, distance);
|
|
741
|
+
}
|
|
742
|
+
function handleTouchStartDollyPan() {
|
|
743
|
+
if (scope.enableZoom)
|
|
744
|
+
handleTouchStartDolly();
|
|
745
|
+
if (scope.enablePan)
|
|
746
|
+
handleTouchStartPan();
|
|
747
|
+
}
|
|
748
|
+
function handleTouchStartDollyRotate() {
|
|
749
|
+
if (scope.enableZoom)
|
|
750
|
+
handleTouchStartDolly();
|
|
751
|
+
if (scope.enableRotate)
|
|
752
|
+
handleTouchStartRotate();
|
|
753
|
+
}
|
|
754
|
+
function handleTouchMoveRotate(event) {
|
|
755
|
+
if (pointers.length == 1) {
|
|
756
|
+
rotateEnd.set(event.pageX, event.pageY);
|
|
757
|
+
} else {
|
|
758
|
+
const position = getSecondPointerPosition(event);
|
|
759
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
760
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
761
|
+
rotateEnd.set(x, y);
|
|
762
|
+
}
|
|
763
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
764
|
+
const element = scope.domElement;
|
|
765
|
+
if (element) {
|
|
766
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
|
|
767
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
768
|
+
}
|
|
769
|
+
rotateStart.copy(rotateEnd);
|
|
770
|
+
}
|
|
771
|
+
function handleTouchMovePan(event) {
|
|
772
|
+
if (pointers.length == 1) {
|
|
773
|
+
panEnd.set(event.pageX, event.pageY);
|
|
774
|
+
} else {
|
|
775
|
+
const position = getSecondPointerPosition(event);
|
|
776
|
+
const x = 0.5 * (event.pageX + position.x);
|
|
777
|
+
const y = 0.5 * (event.pageY + position.y);
|
|
778
|
+
panEnd.set(x, y);
|
|
779
|
+
}
|
|
780
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
781
|
+
pan(panDelta.x, panDelta.y);
|
|
782
|
+
panStart.copy(panEnd);
|
|
783
|
+
}
|
|
784
|
+
function handleTouchMoveDolly(event) {
|
|
785
|
+
const position = getSecondPointerPosition(event);
|
|
786
|
+
const dx = event.pageX - position.x;
|
|
787
|
+
const dy = event.pageY - position.y;
|
|
788
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
789
|
+
dollyEnd.set(0, distance);
|
|
790
|
+
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
791
|
+
dollyOut(dollyDelta.y);
|
|
792
|
+
dollyStart.copy(dollyEnd);
|
|
793
|
+
}
|
|
794
|
+
function handleTouchMoveDollyPan(event) {
|
|
795
|
+
if (scope.enableZoom)
|
|
796
|
+
handleTouchMoveDolly(event);
|
|
797
|
+
if (scope.enablePan)
|
|
798
|
+
handleTouchMovePan(event);
|
|
799
|
+
}
|
|
800
|
+
function handleTouchMoveDollyRotate(event) {
|
|
801
|
+
if (scope.enableZoom)
|
|
802
|
+
handleTouchMoveDolly(event);
|
|
803
|
+
if (scope.enableRotate)
|
|
804
|
+
handleTouchMoveRotate(event);
|
|
805
|
+
}
|
|
806
|
+
function onPointerDown(event) {
|
|
807
|
+
var _a, _b;
|
|
808
|
+
if (scope.enabled === false)
|
|
809
|
+
return;
|
|
810
|
+
if (pointers.length === 0) {
|
|
811
|
+
(_a = scope.domElement) == null ? void 0 : _a.ownerDocument.addEventListener("pointermove", onPointerMove);
|
|
812
|
+
(_b = scope.domElement) == null ? void 0 : _b.ownerDocument.addEventListener("pointerup", onPointerUp);
|
|
813
|
+
}
|
|
814
|
+
addPointer(event);
|
|
815
|
+
if (event.pointerType === "touch") {
|
|
816
|
+
onTouchStart(event);
|
|
817
|
+
} else {
|
|
818
|
+
onMouseDown(event);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function onPointerMove(event) {
|
|
822
|
+
if (scope.enabled === false)
|
|
823
|
+
return;
|
|
824
|
+
if (event.pointerType === "touch") {
|
|
825
|
+
onTouchMove(event);
|
|
826
|
+
} else {
|
|
827
|
+
onMouseMove(event);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function onPointerUp(event) {
|
|
831
|
+
var _a, _b, _c;
|
|
832
|
+
removePointer(event);
|
|
833
|
+
if (pointers.length === 0) {
|
|
834
|
+
(_a = scope.domElement) == null ? void 0 : _a.releasePointerCapture(event.pointerId);
|
|
835
|
+
(_b = scope.domElement) == null ? void 0 : _b.ownerDocument.removeEventListener("pointermove", onPointerMove);
|
|
836
|
+
(_c = scope.domElement) == null ? void 0 : _c.ownerDocument.removeEventListener("pointerup", onPointerUp);
|
|
837
|
+
}
|
|
838
|
+
scope.dispatchEvent(endEvent);
|
|
839
|
+
state = STATE.NONE;
|
|
840
|
+
}
|
|
841
|
+
function onMouseDown(event) {
|
|
842
|
+
let mouseAction;
|
|
843
|
+
switch (event.button) {
|
|
844
|
+
case 0:
|
|
845
|
+
mouseAction = scope.mouseButtons.LEFT;
|
|
846
|
+
break;
|
|
847
|
+
case 1:
|
|
848
|
+
mouseAction = scope.mouseButtons.MIDDLE;
|
|
849
|
+
break;
|
|
850
|
+
case 2:
|
|
851
|
+
mouseAction = scope.mouseButtons.RIGHT;
|
|
852
|
+
break;
|
|
853
|
+
default:
|
|
854
|
+
mouseAction = -1;
|
|
855
|
+
}
|
|
856
|
+
switch (mouseAction) {
|
|
857
|
+
case MOUSE.DOLLY:
|
|
858
|
+
if (scope.enableZoom === false)
|
|
859
|
+
return;
|
|
860
|
+
handleMouseDownDolly(event);
|
|
861
|
+
state = STATE.DOLLY;
|
|
862
|
+
break;
|
|
863
|
+
case MOUSE.ROTATE:
|
|
864
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
865
|
+
if (scope.enablePan === false)
|
|
866
|
+
return;
|
|
867
|
+
handleMouseDownPan(event);
|
|
868
|
+
state = STATE.PAN;
|
|
869
|
+
} else {
|
|
870
|
+
if (scope.enableRotate === false)
|
|
871
|
+
return;
|
|
872
|
+
handleMouseDownRotate(event);
|
|
873
|
+
state = STATE.ROTATE;
|
|
874
|
+
}
|
|
875
|
+
break;
|
|
876
|
+
case MOUSE.PAN:
|
|
877
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
878
|
+
if (scope.enableRotate === false)
|
|
879
|
+
return;
|
|
880
|
+
handleMouseDownRotate(event);
|
|
881
|
+
state = STATE.ROTATE;
|
|
882
|
+
} else {
|
|
883
|
+
if (scope.enablePan === false)
|
|
884
|
+
return;
|
|
885
|
+
handleMouseDownPan(event);
|
|
886
|
+
state = STATE.PAN;
|
|
887
|
+
}
|
|
888
|
+
break;
|
|
889
|
+
default:
|
|
890
|
+
state = STATE.NONE;
|
|
891
|
+
}
|
|
892
|
+
if (state !== STATE.NONE) {
|
|
893
|
+
scope.dispatchEvent(startEvent);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function onMouseMove(event) {
|
|
897
|
+
if (scope.enabled === false)
|
|
898
|
+
return;
|
|
899
|
+
switch (state) {
|
|
900
|
+
case STATE.ROTATE:
|
|
901
|
+
if (scope.enableRotate === false)
|
|
902
|
+
return;
|
|
903
|
+
handleMouseMoveRotate(event);
|
|
904
|
+
break;
|
|
905
|
+
case STATE.DOLLY:
|
|
906
|
+
if (scope.enableZoom === false)
|
|
907
|
+
return;
|
|
908
|
+
handleMouseMoveDolly(event);
|
|
909
|
+
break;
|
|
910
|
+
case STATE.PAN:
|
|
911
|
+
if (scope.enablePan === false)
|
|
912
|
+
return;
|
|
913
|
+
handleMouseMovePan(event);
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
function onMouseWheel(event) {
|
|
918
|
+
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE && state !== STATE.ROTATE) {
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
event.preventDefault();
|
|
922
|
+
scope.dispatchEvent(startEvent);
|
|
923
|
+
handleMouseWheel(event);
|
|
924
|
+
scope.dispatchEvent(endEvent);
|
|
925
|
+
}
|
|
926
|
+
function onKeyDown(event) {
|
|
927
|
+
if (scope.enabled === false || scope.enablePan === false)
|
|
928
|
+
return;
|
|
929
|
+
handleKeyDown(event);
|
|
930
|
+
}
|
|
931
|
+
function onTouchStart(event) {
|
|
932
|
+
trackPointer(event);
|
|
933
|
+
switch (pointers.length) {
|
|
934
|
+
case 1:
|
|
935
|
+
switch (scope.touches.ONE) {
|
|
936
|
+
case TOUCH.ROTATE:
|
|
937
|
+
if (scope.enableRotate === false)
|
|
938
|
+
return;
|
|
939
|
+
handleTouchStartRotate();
|
|
940
|
+
state = STATE.TOUCH_ROTATE;
|
|
941
|
+
break;
|
|
942
|
+
case TOUCH.PAN:
|
|
943
|
+
if (scope.enablePan === false)
|
|
944
|
+
return;
|
|
945
|
+
handleTouchStartPan();
|
|
946
|
+
state = STATE.TOUCH_PAN;
|
|
947
|
+
break;
|
|
948
|
+
default:
|
|
949
|
+
state = STATE.NONE;
|
|
950
|
+
}
|
|
951
|
+
break;
|
|
952
|
+
case 2:
|
|
953
|
+
switch (scope.touches.TWO) {
|
|
954
|
+
case TOUCH.DOLLY_PAN:
|
|
955
|
+
if (scope.enableZoom === false && scope.enablePan === false)
|
|
956
|
+
return;
|
|
957
|
+
handleTouchStartDollyPan();
|
|
958
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
|
959
|
+
break;
|
|
960
|
+
case TOUCH.DOLLY_ROTATE:
|
|
961
|
+
if (scope.enableZoom === false && scope.enableRotate === false)
|
|
962
|
+
return;
|
|
963
|
+
handleTouchStartDollyRotate();
|
|
964
|
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
965
|
+
break;
|
|
966
|
+
default:
|
|
967
|
+
state = STATE.NONE;
|
|
968
|
+
}
|
|
969
|
+
break;
|
|
970
|
+
default:
|
|
971
|
+
state = STATE.NONE;
|
|
972
|
+
}
|
|
973
|
+
if (state !== STATE.NONE) {
|
|
974
|
+
scope.dispatchEvent(startEvent);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function onTouchMove(event) {
|
|
978
|
+
trackPointer(event);
|
|
979
|
+
switch (state) {
|
|
980
|
+
case STATE.TOUCH_ROTATE:
|
|
981
|
+
if (scope.enableRotate === false)
|
|
982
|
+
return;
|
|
983
|
+
handleTouchMoveRotate(event);
|
|
984
|
+
scope.update();
|
|
985
|
+
break;
|
|
986
|
+
case STATE.TOUCH_PAN:
|
|
987
|
+
if (scope.enablePan === false)
|
|
988
|
+
return;
|
|
989
|
+
handleTouchMovePan(event);
|
|
990
|
+
scope.update();
|
|
991
|
+
break;
|
|
992
|
+
case STATE.TOUCH_DOLLY_PAN:
|
|
993
|
+
if (scope.enableZoom === false && scope.enablePan === false)
|
|
994
|
+
return;
|
|
995
|
+
handleTouchMoveDollyPan(event);
|
|
996
|
+
scope.update();
|
|
997
|
+
break;
|
|
998
|
+
case STATE.TOUCH_DOLLY_ROTATE:
|
|
999
|
+
if (scope.enableZoom === false && scope.enableRotate === false)
|
|
1000
|
+
return;
|
|
1001
|
+
handleTouchMoveDollyRotate(event);
|
|
1002
|
+
scope.update();
|
|
1003
|
+
break;
|
|
1004
|
+
default:
|
|
1005
|
+
state = STATE.NONE;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function onContextMenu(event) {
|
|
1009
|
+
if (scope.enabled === false)
|
|
1010
|
+
return;
|
|
1011
|
+
event.preventDefault();
|
|
1012
|
+
}
|
|
1013
|
+
function addPointer(event) {
|
|
1014
|
+
pointers.push(event);
|
|
1015
|
+
}
|
|
1016
|
+
function removePointer(event) {
|
|
1017
|
+
delete pointerPositions[event.pointerId];
|
|
1018
|
+
for (let i = 0; i < pointers.length; i++) {
|
|
1019
|
+
if (pointers[i].pointerId == event.pointerId) {
|
|
1020
|
+
pointers.splice(i, 1);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
function trackPointer(event) {
|
|
1026
|
+
let position = pointerPositions[event.pointerId];
|
|
1027
|
+
if (position === void 0) {
|
|
1028
|
+
position = new Vector2();
|
|
1029
|
+
pointerPositions[event.pointerId] = position;
|
|
1030
|
+
}
|
|
1031
|
+
position.set(event.pageX, event.pageY);
|
|
1032
|
+
}
|
|
1033
|
+
function getSecondPointerPosition(event) {
|
|
1034
|
+
const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
|
|
1035
|
+
return pointerPositions[pointer.pointerId];
|
|
1036
|
+
}
|
|
1037
|
+
this.dollyIn = (dollyScale = getZoomScale()) => {
|
|
1038
|
+
dollyIn(dollyScale);
|
|
1039
|
+
scope.update();
|
|
1040
|
+
};
|
|
1041
|
+
this.dollyOut = (dollyScale = getZoomScale()) => {
|
|
1042
|
+
dollyOut(dollyScale);
|
|
1043
|
+
scope.update();
|
|
1044
|
+
};
|
|
1045
|
+
this.getScale = () => {
|
|
1046
|
+
return scale;
|
|
1047
|
+
};
|
|
1048
|
+
this.setScale = (newScale) => {
|
|
1049
|
+
setScale(newScale);
|
|
1050
|
+
scope.update();
|
|
1051
|
+
};
|
|
1052
|
+
this.getZoomScale = () => {
|
|
1053
|
+
return getZoomScale();
|
|
1054
|
+
};
|
|
1055
|
+
if (domElement !== void 0)
|
|
1056
|
+
this.connect(domElement);
|
|
1057
|
+
this.update();
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
// ../../node_modules/three-stdlib/loaders/GLTFLoader.js
|
|
1062
|
+
import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2 as Vector22, Matrix4, Vector3 as Vector33, Quaternion as Quaternion2, InstancedMesh, InstancedBufferAttribute, Object3D, TextureLoader, ImageBitmapLoader, BufferAttribute as BufferAttribute2, InterleavedBuffer as InterleavedBuffer2, InterleavedBufferAttribute as InterleavedBufferAttribute2, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, PointsMaterial, Material, LineBasicMaterial, MeshStandardMaterial, DoubleSide, PropertyBinding, BufferGeometry as BufferGeometry2, SkinnedMesh, Mesh, TriangleStripDrawMode as TriangleStripDrawMode2, TriangleFanDrawMode as TriangleFanDrawMode2, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera as PerspectiveCamera2, MathUtils, OrthographicCamera as OrthographicCamera2, Skeleton, AnimationClip, Bone, InterpolateLinear, NearestFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, InterpolateDiscrete, FrontSide, Texture, VectorKeyframeTrack, NumberKeyframeTrack, QuaternionKeyframeTrack, Box3, Sphere, Interpolant } from "three";
|
|
1063
|
+
|
|
1064
|
+
// ../../node_modules/three-stdlib/_polyfill/LoaderUtils.js
|
|
1065
|
+
function decodeText(array) {
|
|
1066
|
+
if (typeof TextDecoder !== "undefined") {
|
|
1067
|
+
return new TextDecoder().decode(array);
|
|
1068
|
+
}
|
|
1069
|
+
let s = "";
|
|
1070
|
+
for (let i = 0, il = array.length; i < il; i++) {
|
|
1071
|
+
s += String.fromCharCode(array[i]);
|
|
1072
|
+
}
|
|
1073
|
+
try {
|
|
1074
|
+
return decodeURIComponent(escape(s));
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
return s;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// ../../node_modules/three-stdlib/loaders/GLTFLoader.js
|
|
1081
|
+
var SRGBColorSpace = "srgb";
|
|
1082
|
+
var LinearSRGBColorSpace = "srgb-linear";
|
|
1083
|
+
var sRGBEncoding = 3001;
|
|
1084
|
+
var LinearEncoding = 3e3;
|
|
1085
|
+
var GLTFLoader = class extends Loader {
|
|
1086
|
+
constructor(manager) {
|
|
1087
|
+
super(manager);
|
|
1088
|
+
this.dracoLoader = null;
|
|
1089
|
+
this.ktx2Loader = null;
|
|
1090
|
+
this.meshoptDecoder = null;
|
|
1091
|
+
this.pluginCallbacks = [];
|
|
1092
|
+
this.register(function(parser) {
|
|
1093
|
+
return new GLTFMaterialsClearcoatExtension(parser);
|
|
1094
|
+
});
|
|
1095
|
+
this.register(function(parser) {
|
|
1096
|
+
return new GLTFMaterialsDispersionExtension(parser);
|
|
1097
|
+
});
|
|
1098
|
+
this.register(function(parser) {
|
|
1099
|
+
return new GLTFTextureBasisUExtension(parser);
|
|
1100
|
+
});
|
|
1101
|
+
this.register(function(parser) {
|
|
1102
|
+
return new GLTFTextureWebPExtension(parser);
|
|
1103
|
+
});
|
|
1104
|
+
this.register(function(parser) {
|
|
1105
|
+
return new GLTFTextureAVIFExtension(parser);
|
|
1106
|
+
});
|
|
1107
|
+
this.register(function(parser) {
|
|
1108
|
+
return new GLTFMaterialsSheenExtension(parser);
|
|
1109
|
+
});
|
|
1110
|
+
this.register(function(parser) {
|
|
1111
|
+
return new GLTFMaterialsTransmissionExtension(parser);
|
|
1112
|
+
});
|
|
1113
|
+
this.register(function(parser) {
|
|
1114
|
+
return new GLTFMaterialsVolumeExtension(parser);
|
|
1115
|
+
});
|
|
1116
|
+
this.register(function(parser) {
|
|
1117
|
+
return new GLTFMaterialsIorExtension(parser);
|
|
1118
|
+
});
|
|
1119
|
+
this.register(function(parser) {
|
|
1120
|
+
return new GLTFMaterialsEmissiveStrengthExtension(parser);
|
|
1121
|
+
});
|
|
1122
|
+
this.register(function(parser) {
|
|
1123
|
+
return new GLTFMaterialsSpecularExtension(parser);
|
|
1124
|
+
});
|
|
1125
|
+
this.register(function(parser) {
|
|
1126
|
+
return new GLTFMaterialsIridescenceExtension(parser);
|
|
1127
|
+
});
|
|
1128
|
+
this.register(function(parser) {
|
|
1129
|
+
return new GLTFMaterialsAnisotropyExtension(parser);
|
|
1130
|
+
});
|
|
1131
|
+
this.register(function(parser) {
|
|
1132
|
+
return new GLTFMaterialsBumpExtension(parser);
|
|
1133
|
+
});
|
|
1134
|
+
this.register(function(parser) {
|
|
1135
|
+
return new GLTFLightsExtension(parser);
|
|
1136
|
+
});
|
|
1137
|
+
this.register(function(parser) {
|
|
1138
|
+
return new GLTFMeshoptCompression(parser);
|
|
1139
|
+
});
|
|
1140
|
+
this.register(function(parser) {
|
|
1141
|
+
return new GLTFMeshGpuInstancing(parser);
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
load(url, onLoad, onProgress, onError) {
|
|
1145
|
+
const scope = this;
|
|
1146
|
+
let resourcePath;
|
|
1147
|
+
if (this.resourcePath !== "") {
|
|
1148
|
+
resourcePath = this.resourcePath;
|
|
1149
|
+
} else if (this.path !== "") {
|
|
1150
|
+
const relativeUrl = LoaderUtils.extractUrlBase(url);
|
|
1151
|
+
resourcePath = LoaderUtils.resolveURL(relativeUrl, this.path);
|
|
1152
|
+
} else {
|
|
1153
|
+
resourcePath = LoaderUtils.extractUrlBase(url);
|
|
1154
|
+
}
|
|
1155
|
+
this.manager.itemStart(url);
|
|
1156
|
+
const _onError = function(e) {
|
|
1157
|
+
if (onError) {
|
|
1158
|
+
onError(e);
|
|
1159
|
+
} else {
|
|
1160
|
+
console.error(e);
|
|
1161
|
+
}
|
|
1162
|
+
scope.manager.itemError(url);
|
|
1163
|
+
scope.manager.itemEnd(url);
|
|
1164
|
+
};
|
|
1165
|
+
const loader = new FileLoader(this.manager);
|
|
1166
|
+
loader.setPath(this.path);
|
|
1167
|
+
loader.setResponseType("arraybuffer");
|
|
1168
|
+
loader.setRequestHeader(this.requestHeader);
|
|
1169
|
+
loader.setWithCredentials(this.withCredentials);
|
|
1170
|
+
loader.load(
|
|
1171
|
+
url,
|
|
1172
|
+
function(data) {
|
|
1173
|
+
try {
|
|
1174
|
+
scope.parse(
|
|
1175
|
+
data,
|
|
1176
|
+
resourcePath,
|
|
1177
|
+
function(gltf) {
|
|
1178
|
+
onLoad(gltf);
|
|
1179
|
+
scope.manager.itemEnd(url);
|
|
1180
|
+
},
|
|
1181
|
+
_onError
|
|
1182
|
+
);
|
|
1183
|
+
} catch (e) {
|
|
1184
|
+
_onError(e);
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
onProgress,
|
|
1188
|
+
_onError
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
setDRACOLoader(dracoLoader2) {
|
|
1192
|
+
this.dracoLoader = dracoLoader2;
|
|
1193
|
+
return this;
|
|
1194
|
+
}
|
|
1195
|
+
setDDSLoader() {
|
|
1196
|
+
throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
|
|
1197
|
+
}
|
|
1198
|
+
setKTX2Loader(ktx2Loader) {
|
|
1199
|
+
this.ktx2Loader = ktx2Loader;
|
|
1200
|
+
return this;
|
|
1201
|
+
}
|
|
1202
|
+
setMeshoptDecoder(meshoptDecoder) {
|
|
1203
|
+
this.meshoptDecoder = meshoptDecoder;
|
|
1204
|
+
return this;
|
|
1205
|
+
}
|
|
1206
|
+
register(callback) {
|
|
1207
|
+
if (this.pluginCallbacks.indexOf(callback) === -1) {
|
|
1208
|
+
this.pluginCallbacks.push(callback);
|
|
1209
|
+
}
|
|
1210
|
+
return this;
|
|
1211
|
+
}
|
|
1212
|
+
unregister(callback) {
|
|
1213
|
+
if (this.pluginCallbacks.indexOf(callback) !== -1) {
|
|
1214
|
+
this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
|
|
1215
|
+
}
|
|
1216
|
+
return this;
|
|
1217
|
+
}
|
|
1218
|
+
parse(data, path, onLoad, onError) {
|
|
1219
|
+
let json;
|
|
1220
|
+
const extensions2 = {};
|
|
1221
|
+
const plugins = {};
|
|
1222
|
+
if (typeof data === "string") {
|
|
1223
|
+
json = JSON.parse(data);
|
|
1224
|
+
} else if (data instanceof ArrayBuffer) {
|
|
1225
|
+
const magic = decodeText(new Uint8Array(data.slice(0, 4)));
|
|
1226
|
+
if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
|
|
1227
|
+
try {
|
|
1228
|
+
extensions2[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
if (onError)
|
|
1231
|
+
onError(error);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
json = JSON.parse(extensions2[EXTENSIONS.KHR_BINARY_GLTF].content);
|
|
1235
|
+
} else {
|
|
1236
|
+
json = JSON.parse(decodeText(new Uint8Array(data)));
|
|
1237
|
+
}
|
|
1238
|
+
} else {
|
|
1239
|
+
json = data;
|
|
1240
|
+
}
|
|
1241
|
+
if (json.asset === void 0 || json.asset.version[0] < 2) {
|
|
1242
|
+
if (onError)
|
|
1243
|
+
onError(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const parser = new GLTFParser(json, {
|
|
1247
|
+
path: path || this.resourcePath || "",
|
|
1248
|
+
crossOrigin: this.crossOrigin,
|
|
1249
|
+
requestHeader: this.requestHeader,
|
|
1250
|
+
manager: this.manager,
|
|
1251
|
+
ktx2Loader: this.ktx2Loader,
|
|
1252
|
+
meshoptDecoder: this.meshoptDecoder
|
|
1253
|
+
});
|
|
1254
|
+
parser.fileLoader.setRequestHeader(this.requestHeader);
|
|
1255
|
+
for (let i = 0; i < this.pluginCallbacks.length; i++) {
|
|
1256
|
+
const plugin = this.pluginCallbacks[i](parser);
|
|
1257
|
+
if (!plugin.name)
|
|
1258
|
+
console.error("THREE.GLTFLoader: Invalid plugin found: missing name");
|
|
1259
|
+
plugins[plugin.name] = plugin;
|
|
1260
|
+
extensions2[plugin.name] = true;
|
|
1261
|
+
}
|
|
1262
|
+
if (json.extensionsUsed) {
|
|
1263
|
+
for (let i = 0; i < json.extensionsUsed.length; ++i) {
|
|
1264
|
+
const extensionName = json.extensionsUsed[i];
|
|
1265
|
+
const extensionsRequired = json.extensionsRequired || [];
|
|
1266
|
+
switch (extensionName) {
|
|
1267
|
+
case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
|
1268
|
+
extensions2[extensionName] = new GLTFMaterialsUnlitExtension();
|
|
1269
|
+
break;
|
|
1270
|
+
case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
|
1271
|
+
extensions2[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
|
|
1272
|
+
break;
|
|
1273
|
+
case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
|
1274
|
+
extensions2[extensionName] = new GLTFTextureTransformExtension();
|
|
1275
|
+
break;
|
|
1276
|
+
case EXTENSIONS.KHR_MESH_QUANTIZATION:
|
|
1277
|
+
extensions2[extensionName] = new GLTFMeshQuantizationExtension();
|
|
1278
|
+
break;
|
|
1279
|
+
default:
|
|
1280
|
+
if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === void 0) {
|
|
1281
|
+
console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
parser.setExtensions(extensions2);
|
|
1287
|
+
parser.setPlugins(plugins);
|
|
1288
|
+
parser.parse(onLoad, onError);
|
|
1289
|
+
}
|
|
1290
|
+
parseAsync(data, path) {
|
|
1291
|
+
const scope = this;
|
|
1292
|
+
return new Promise(function(resolve, reject) {
|
|
1293
|
+
scope.parse(data, path, resolve, reject);
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
function GLTFRegistry() {
|
|
1298
|
+
let objects = {};
|
|
1299
|
+
return {
|
|
1300
|
+
get: function(key) {
|
|
1301
|
+
return objects[key];
|
|
1302
|
+
},
|
|
1303
|
+
add: function(key, object) {
|
|
1304
|
+
objects[key] = object;
|
|
1305
|
+
},
|
|
1306
|
+
remove: function(key) {
|
|
1307
|
+
delete objects[key];
|
|
1308
|
+
},
|
|
1309
|
+
removeAll: function() {
|
|
1310
|
+
objects = {};
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
var EXTENSIONS = {
|
|
1315
|
+
KHR_BINARY_GLTF: "KHR_binary_glTF",
|
|
1316
|
+
KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
|
|
1317
|
+
KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
|
|
1318
|
+
KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
|
|
1319
|
+
KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
|
|
1320
|
+
KHR_MATERIALS_IOR: "KHR_materials_ior",
|
|
1321
|
+
KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
|
|
1322
|
+
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
|
1323
|
+
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
|
1324
|
+
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
|
1325
|
+
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
|
1326
|
+
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
|
1327
|
+
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
|
1328
|
+
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
|
1329
|
+
KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
|
|
1330
|
+
KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
|
|
1331
|
+
KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
|
|
1332
|
+
EXT_MATERIALS_BUMP: "EXT_materials_bump",
|
|
1333
|
+
EXT_TEXTURE_WEBP: "EXT_texture_webp",
|
|
1334
|
+
EXT_TEXTURE_AVIF: "EXT_texture_avif",
|
|
1335
|
+
EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
|
|
1336
|
+
EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
|
|
1337
|
+
};
|
|
1338
|
+
var GLTFLightsExtension = class {
|
|
1339
|
+
constructor(parser) {
|
|
1340
|
+
this.parser = parser;
|
|
1341
|
+
this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
|
1342
|
+
this.cache = { refs: {}, uses: {} };
|
|
1343
|
+
}
|
|
1344
|
+
_markDefs() {
|
|
1345
|
+
const parser = this.parser;
|
|
1346
|
+
const nodeDefs = this.parser.json.nodes || [];
|
|
1347
|
+
for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
|
1348
|
+
const nodeDef = nodeDefs[nodeIndex];
|
|
1349
|
+
if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== void 0) {
|
|
1350
|
+
parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
_loadLight(lightIndex) {
|
|
1355
|
+
const parser = this.parser;
|
|
1356
|
+
const cacheKey = "light:" + lightIndex;
|
|
1357
|
+
let dependency = parser.cache.get(cacheKey);
|
|
1358
|
+
if (dependency)
|
|
1359
|
+
return dependency;
|
|
1360
|
+
const json = parser.json;
|
|
1361
|
+
const extensions2 = json.extensions && json.extensions[this.name] || {};
|
|
1362
|
+
const lightDefs = extensions2.lights || [];
|
|
1363
|
+
const lightDef = lightDefs[lightIndex];
|
|
1364
|
+
let lightNode;
|
|
1365
|
+
const color = new Color(16777215);
|
|
1366
|
+
if (lightDef.color !== void 0)
|
|
1367
|
+
color.setRGB(lightDef.color[0], lightDef.color[1], lightDef.color[2], LinearSRGBColorSpace);
|
|
1368
|
+
const range = lightDef.range !== void 0 ? lightDef.range : 0;
|
|
1369
|
+
switch (lightDef.type) {
|
|
1370
|
+
case "directional":
|
|
1371
|
+
lightNode = new DirectionalLight(color);
|
|
1372
|
+
lightNode.target.position.set(0, 0, -1);
|
|
1373
|
+
lightNode.add(lightNode.target);
|
|
1374
|
+
break;
|
|
1375
|
+
case "point":
|
|
1376
|
+
lightNode = new PointLight(color);
|
|
1377
|
+
lightNode.distance = range;
|
|
1378
|
+
break;
|
|
1379
|
+
case "spot":
|
|
1380
|
+
lightNode = new SpotLight(color);
|
|
1381
|
+
lightNode.distance = range;
|
|
1382
|
+
lightDef.spot = lightDef.spot || {};
|
|
1383
|
+
lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== void 0 ? lightDef.spot.innerConeAngle : 0;
|
|
1384
|
+
lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== void 0 ? lightDef.spot.outerConeAngle : Math.PI / 4;
|
|
1385
|
+
lightNode.angle = lightDef.spot.outerConeAngle;
|
|
1386
|
+
lightNode.penumbra = 1 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
|
1387
|
+
lightNode.target.position.set(0, 0, -1);
|
|
1388
|
+
lightNode.add(lightNode.target);
|
|
1389
|
+
break;
|
|
1390
|
+
default:
|
|
1391
|
+
throw new Error("THREE.GLTFLoader: Unexpected light type: " + lightDef.type);
|
|
1392
|
+
}
|
|
1393
|
+
lightNode.position.set(0, 0, 0);
|
|
1394
|
+
lightNode.decay = 2;
|
|
1395
|
+
assignExtrasToUserData(lightNode, lightDef);
|
|
1396
|
+
if (lightDef.intensity !== void 0)
|
|
1397
|
+
lightNode.intensity = lightDef.intensity;
|
|
1398
|
+
lightNode.name = parser.createUniqueName(lightDef.name || "light_" + lightIndex);
|
|
1399
|
+
dependency = Promise.resolve(lightNode);
|
|
1400
|
+
parser.cache.add(cacheKey, dependency);
|
|
1401
|
+
return dependency;
|
|
1402
|
+
}
|
|
1403
|
+
getDependency(type, index) {
|
|
1404
|
+
if (type !== "light")
|
|
1405
|
+
return;
|
|
1406
|
+
return this._loadLight(index);
|
|
1407
|
+
}
|
|
1408
|
+
createNodeAttachment(nodeIndex) {
|
|
1409
|
+
const self2 = this;
|
|
1410
|
+
const parser = this.parser;
|
|
1411
|
+
const json = parser.json;
|
|
1412
|
+
const nodeDef = json.nodes[nodeIndex];
|
|
1413
|
+
const lightDef = nodeDef.extensions && nodeDef.extensions[this.name] || {};
|
|
1414
|
+
const lightIndex = lightDef.light;
|
|
1415
|
+
if (lightIndex === void 0)
|
|
1416
|
+
return null;
|
|
1417
|
+
return this._loadLight(lightIndex).then(function(light) {
|
|
1418
|
+
return parser._getNodeRef(self2.cache, lightIndex, light);
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
var GLTFMaterialsUnlitExtension = class {
|
|
1423
|
+
constructor() {
|
|
1424
|
+
this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
|
1425
|
+
}
|
|
1426
|
+
getMaterialType() {
|
|
1427
|
+
return MeshBasicMaterial;
|
|
1428
|
+
}
|
|
1429
|
+
extendParams(materialParams, materialDef, parser) {
|
|
1430
|
+
const pending = [];
|
|
1431
|
+
materialParams.color = new Color(1, 1, 1);
|
|
1432
|
+
materialParams.opacity = 1;
|
|
1433
|
+
const metallicRoughness = materialDef.pbrMetallicRoughness;
|
|
1434
|
+
if (metallicRoughness) {
|
|
1435
|
+
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
1436
|
+
const array = metallicRoughness.baseColorFactor;
|
|
1437
|
+
materialParams.color.setRGB(array[0], array[1], array[2], LinearSRGBColorSpace);
|
|
1438
|
+
materialParams.opacity = array[3];
|
|
1439
|
+
}
|
|
1440
|
+
if (metallicRoughness.baseColorTexture !== void 0) {
|
|
1441
|
+
pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return Promise.all(pending);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
var GLTFMaterialsEmissiveStrengthExtension = class {
|
|
1448
|
+
constructor(parser) {
|
|
1449
|
+
this.parser = parser;
|
|
1450
|
+
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
1451
|
+
}
|
|
1452
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1453
|
+
const parser = this.parser;
|
|
1454
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1455
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1456
|
+
return Promise.resolve();
|
|
1457
|
+
}
|
|
1458
|
+
const emissiveStrength = materialDef.extensions[this.name].emissiveStrength;
|
|
1459
|
+
if (emissiveStrength !== void 0) {
|
|
1460
|
+
materialParams.emissiveIntensity = emissiveStrength;
|
|
1461
|
+
}
|
|
1462
|
+
return Promise.resolve();
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
var GLTFMaterialsClearcoatExtension = class {
|
|
1466
|
+
constructor(parser) {
|
|
1467
|
+
this.parser = parser;
|
|
1468
|
+
this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
|
|
1469
|
+
}
|
|
1470
|
+
getMaterialType(materialIndex) {
|
|
1471
|
+
const parser = this.parser;
|
|
1472
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1473
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1474
|
+
return null;
|
|
1475
|
+
return MeshPhysicalMaterial;
|
|
1476
|
+
}
|
|
1477
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1478
|
+
const parser = this.parser;
|
|
1479
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1480
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1481
|
+
return Promise.resolve();
|
|
1482
|
+
}
|
|
1483
|
+
const pending = [];
|
|
1484
|
+
const extension = materialDef.extensions[this.name];
|
|
1485
|
+
if (extension.clearcoatFactor !== void 0) {
|
|
1486
|
+
materialParams.clearcoat = extension.clearcoatFactor;
|
|
1487
|
+
}
|
|
1488
|
+
if (extension.clearcoatTexture !== void 0) {
|
|
1489
|
+
pending.push(parser.assignTexture(materialParams, "clearcoatMap", extension.clearcoatTexture));
|
|
1490
|
+
}
|
|
1491
|
+
if (extension.clearcoatRoughnessFactor !== void 0) {
|
|
1492
|
+
materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
|
|
1493
|
+
}
|
|
1494
|
+
if (extension.clearcoatRoughnessTexture !== void 0) {
|
|
1495
|
+
pending.push(parser.assignTexture(materialParams, "clearcoatRoughnessMap", extension.clearcoatRoughnessTexture));
|
|
1496
|
+
}
|
|
1497
|
+
if (extension.clearcoatNormalTexture !== void 0) {
|
|
1498
|
+
pending.push(parser.assignTexture(materialParams, "clearcoatNormalMap", extension.clearcoatNormalTexture));
|
|
1499
|
+
if (extension.clearcoatNormalTexture.scale !== void 0) {
|
|
1500
|
+
const scale = extension.clearcoatNormalTexture.scale;
|
|
1501
|
+
materialParams.clearcoatNormalScale = new Vector22(scale, scale);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
return Promise.all(pending);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
var GLTFMaterialsDispersionExtension = class {
|
|
1508
|
+
constructor(parser) {
|
|
1509
|
+
this.parser = parser;
|
|
1510
|
+
this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
|
|
1511
|
+
}
|
|
1512
|
+
getMaterialType(materialIndex) {
|
|
1513
|
+
const parser = this.parser;
|
|
1514
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1515
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1516
|
+
return null;
|
|
1517
|
+
return MeshPhysicalMaterial;
|
|
1518
|
+
}
|
|
1519
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1520
|
+
const parser = this.parser;
|
|
1521
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1522
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1523
|
+
return Promise.resolve();
|
|
1524
|
+
}
|
|
1525
|
+
const extension = materialDef.extensions[this.name];
|
|
1526
|
+
materialParams.dispersion = extension.dispersion !== void 0 ? extension.dispersion : 0;
|
|
1527
|
+
return Promise.resolve();
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
var GLTFMaterialsIridescenceExtension = class {
|
|
1531
|
+
constructor(parser) {
|
|
1532
|
+
this.parser = parser;
|
|
1533
|
+
this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
|
|
1534
|
+
}
|
|
1535
|
+
getMaterialType(materialIndex) {
|
|
1536
|
+
const parser = this.parser;
|
|
1537
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1538
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1539
|
+
return null;
|
|
1540
|
+
return MeshPhysicalMaterial;
|
|
1541
|
+
}
|
|
1542
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1543
|
+
const parser = this.parser;
|
|
1544
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1545
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1546
|
+
return Promise.resolve();
|
|
1547
|
+
}
|
|
1548
|
+
const pending = [];
|
|
1549
|
+
const extension = materialDef.extensions[this.name];
|
|
1550
|
+
if (extension.iridescenceFactor !== void 0) {
|
|
1551
|
+
materialParams.iridescence = extension.iridescenceFactor;
|
|
1552
|
+
}
|
|
1553
|
+
if (extension.iridescenceTexture !== void 0) {
|
|
1554
|
+
pending.push(parser.assignTexture(materialParams, "iridescenceMap", extension.iridescenceTexture));
|
|
1555
|
+
}
|
|
1556
|
+
if (extension.iridescenceIor !== void 0) {
|
|
1557
|
+
materialParams.iridescenceIOR = extension.iridescenceIor;
|
|
1558
|
+
}
|
|
1559
|
+
if (materialParams.iridescenceThicknessRange === void 0) {
|
|
1560
|
+
materialParams.iridescenceThicknessRange = [100, 400];
|
|
1561
|
+
}
|
|
1562
|
+
if (extension.iridescenceThicknessMinimum !== void 0) {
|
|
1563
|
+
materialParams.iridescenceThicknessRange[0] = extension.iridescenceThicknessMinimum;
|
|
1564
|
+
}
|
|
1565
|
+
if (extension.iridescenceThicknessMaximum !== void 0) {
|
|
1566
|
+
materialParams.iridescenceThicknessRange[1] = extension.iridescenceThicknessMaximum;
|
|
1567
|
+
}
|
|
1568
|
+
if (extension.iridescenceThicknessTexture !== void 0) {
|
|
1569
|
+
pending.push(
|
|
1570
|
+
parser.assignTexture(materialParams, "iridescenceThicknessMap", extension.iridescenceThicknessTexture)
|
|
1571
|
+
);
|
|
1572
|
+
}
|
|
1573
|
+
return Promise.all(pending);
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
var GLTFMaterialsSheenExtension = class {
|
|
1577
|
+
constructor(parser) {
|
|
1578
|
+
this.parser = parser;
|
|
1579
|
+
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
|
|
1580
|
+
}
|
|
1581
|
+
getMaterialType(materialIndex) {
|
|
1582
|
+
const parser = this.parser;
|
|
1583
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1584
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1585
|
+
return null;
|
|
1586
|
+
return MeshPhysicalMaterial;
|
|
1587
|
+
}
|
|
1588
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1589
|
+
const parser = this.parser;
|
|
1590
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1591
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1592
|
+
return Promise.resolve();
|
|
1593
|
+
}
|
|
1594
|
+
const pending = [];
|
|
1595
|
+
materialParams.sheenColor = new Color(0, 0, 0);
|
|
1596
|
+
materialParams.sheenRoughness = 0;
|
|
1597
|
+
materialParams.sheen = 1;
|
|
1598
|
+
const extension = materialDef.extensions[this.name];
|
|
1599
|
+
if (extension.sheenColorFactor !== void 0) {
|
|
1600
|
+
const colorFactor = extension.sheenColorFactor;
|
|
1601
|
+
materialParams.sheenColor.setRGB(colorFactor[0], colorFactor[1], colorFactor[2], LinearSRGBColorSpace);
|
|
1602
|
+
}
|
|
1603
|
+
if (extension.sheenRoughnessFactor !== void 0) {
|
|
1604
|
+
materialParams.sheenRoughness = extension.sheenRoughnessFactor;
|
|
1605
|
+
}
|
|
1606
|
+
if (extension.sheenColorTexture !== void 0) {
|
|
1607
|
+
pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, SRGBColorSpace));
|
|
1608
|
+
}
|
|
1609
|
+
if (extension.sheenRoughnessTexture !== void 0) {
|
|
1610
|
+
pending.push(parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
|
|
1611
|
+
}
|
|
1612
|
+
return Promise.all(pending);
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
var GLTFMaterialsTransmissionExtension = class {
|
|
1616
|
+
constructor(parser) {
|
|
1617
|
+
this.parser = parser;
|
|
1618
|
+
this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
|
|
1619
|
+
}
|
|
1620
|
+
getMaterialType(materialIndex) {
|
|
1621
|
+
const parser = this.parser;
|
|
1622
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1623
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1624
|
+
return null;
|
|
1625
|
+
return MeshPhysicalMaterial;
|
|
1626
|
+
}
|
|
1627
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1628
|
+
const parser = this.parser;
|
|
1629
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1630
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1631
|
+
return Promise.resolve();
|
|
1632
|
+
}
|
|
1633
|
+
const pending = [];
|
|
1634
|
+
const extension = materialDef.extensions[this.name];
|
|
1635
|
+
if (extension.transmissionFactor !== void 0) {
|
|
1636
|
+
materialParams.transmission = extension.transmissionFactor;
|
|
1637
|
+
}
|
|
1638
|
+
if (extension.transmissionTexture !== void 0) {
|
|
1639
|
+
pending.push(parser.assignTexture(materialParams, "transmissionMap", extension.transmissionTexture));
|
|
1640
|
+
}
|
|
1641
|
+
return Promise.all(pending);
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
var GLTFMaterialsVolumeExtension = class {
|
|
1645
|
+
constructor(parser) {
|
|
1646
|
+
this.parser = parser;
|
|
1647
|
+
this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
|
|
1648
|
+
}
|
|
1649
|
+
getMaterialType(materialIndex) {
|
|
1650
|
+
const parser = this.parser;
|
|
1651
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1652
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1653
|
+
return null;
|
|
1654
|
+
return MeshPhysicalMaterial;
|
|
1655
|
+
}
|
|
1656
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1657
|
+
const parser = this.parser;
|
|
1658
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1659
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1660
|
+
return Promise.resolve();
|
|
1661
|
+
}
|
|
1662
|
+
const pending = [];
|
|
1663
|
+
const extension = materialDef.extensions[this.name];
|
|
1664
|
+
materialParams.thickness = extension.thicknessFactor !== void 0 ? extension.thicknessFactor : 0;
|
|
1665
|
+
if (extension.thicknessTexture !== void 0) {
|
|
1666
|
+
pending.push(parser.assignTexture(materialParams, "thicknessMap", extension.thicknessTexture));
|
|
1667
|
+
}
|
|
1668
|
+
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
|
|
1669
|
+
const colorArray = extension.attenuationColor || [1, 1, 1];
|
|
1670
|
+
materialParams.attenuationColor = new Color().setRGB(
|
|
1671
|
+
colorArray[0],
|
|
1672
|
+
colorArray[1],
|
|
1673
|
+
colorArray[2],
|
|
1674
|
+
LinearSRGBColorSpace
|
|
1675
|
+
);
|
|
1676
|
+
return Promise.all(pending);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
var GLTFMaterialsIorExtension = class {
|
|
1680
|
+
constructor(parser) {
|
|
1681
|
+
this.parser = parser;
|
|
1682
|
+
this.name = EXTENSIONS.KHR_MATERIALS_IOR;
|
|
1683
|
+
}
|
|
1684
|
+
getMaterialType(materialIndex) {
|
|
1685
|
+
const parser = this.parser;
|
|
1686
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1687
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1688
|
+
return null;
|
|
1689
|
+
return MeshPhysicalMaterial;
|
|
1690
|
+
}
|
|
1691
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1692
|
+
const parser = this.parser;
|
|
1693
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1694
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1695
|
+
return Promise.resolve();
|
|
1696
|
+
}
|
|
1697
|
+
const extension = materialDef.extensions[this.name];
|
|
1698
|
+
materialParams.ior = extension.ior !== void 0 ? extension.ior : 1.5;
|
|
1699
|
+
return Promise.resolve();
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var GLTFMaterialsSpecularExtension = class {
|
|
1703
|
+
constructor(parser) {
|
|
1704
|
+
this.parser = parser;
|
|
1705
|
+
this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
|
|
1706
|
+
}
|
|
1707
|
+
getMaterialType(materialIndex) {
|
|
1708
|
+
const parser = this.parser;
|
|
1709
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1710
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1711
|
+
return null;
|
|
1712
|
+
return MeshPhysicalMaterial;
|
|
1713
|
+
}
|
|
1714
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1715
|
+
const parser = this.parser;
|
|
1716
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1717
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1718
|
+
return Promise.resolve();
|
|
1719
|
+
}
|
|
1720
|
+
const pending = [];
|
|
1721
|
+
const extension = materialDef.extensions[this.name];
|
|
1722
|
+
materialParams.specularIntensity = extension.specularFactor !== void 0 ? extension.specularFactor : 1;
|
|
1723
|
+
if (extension.specularTexture !== void 0) {
|
|
1724
|
+
pending.push(parser.assignTexture(materialParams, "specularIntensityMap", extension.specularTexture));
|
|
1725
|
+
}
|
|
1726
|
+
const colorArray = extension.specularColorFactor || [1, 1, 1];
|
|
1727
|
+
materialParams.specularColor = new Color().setRGB(colorArray[0], colorArray[1], colorArray[2], LinearSRGBColorSpace);
|
|
1728
|
+
if (extension.specularColorTexture !== void 0) {
|
|
1729
|
+
pending.push(
|
|
1730
|
+
parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, SRGBColorSpace)
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
return Promise.all(pending);
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
var GLTFMaterialsBumpExtension = class {
|
|
1737
|
+
constructor(parser) {
|
|
1738
|
+
this.parser = parser;
|
|
1739
|
+
this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
|
|
1740
|
+
}
|
|
1741
|
+
getMaterialType(materialIndex) {
|
|
1742
|
+
const parser = this.parser;
|
|
1743
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1744
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1745
|
+
return null;
|
|
1746
|
+
return MeshPhysicalMaterial;
|
|
1747
|
+
}
|
|
1748
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1749
|
+
const parser = this.parser;
|
|
1750
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1751
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1752
|
+
return Promise.resolve();
|
|
1753
|
+
}
|
|
1754
|
+
const pending = [];
|
|
1755
|
+
const extension = materialDef.extensions[this.name];
|
|
1756
|
+
materialParams.bumpScale = extension.bumpFactor !== void 0 ? extension.bumpFactor : 1;
|
|
1757
|
+
if (extension.bumpTexture !== void 0) {
|
|
1758
|
+
pending.push(parser.assignTexture(materialParams, "bumpMap", extension.bumpTexture));
|
|
1759
|
+
}
|
|
1760
|
+
return Promise.all(pending);
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
var GLTFMaterialsAnisotropyExtension = class {
|
|
1764
|
+
constructor(parser) {
|
|
1765
|
+
this.parser = parser;
|
|
1766
|
+
this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
|
|
1767
|
+
}
|
|
1768
|
+
getMaterialType(materialIndex) {
|
|
1769
|
+
const parser = this.parser;
|
|
1770
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1771
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name])
|
|
1772
|
+
return null;
|
|
1773
|
+
return MeshPhysicalMaterial;
|
|
1774
|
+
}
|
|
1775
|
+
extendMaterialParams(materialIndex, materialParams) {
|
|
1776
|
+
const parser = this.parser;
|
|
1777
|
+
const materialDef = parser.json.materials[materialIndex];
|
|
1778
|
+
if (!materialDef.extensions || !materialDef.extensions[this.name]) {
|
|
1779
|
+
return Promise.resolve();
|
|
1780
|
+
}
|
|
1781
|
+
const pending = [];
|
|
1782
|
+
const extension = materialDef.extensions[this.name];
|
|
1783
|
+
if (extension.anisotropyStrength !== void 0) {
|
|
1784
|
+
materialParams.anisotropy = extension.anisotropyStrength;
|
|
1785
|
+
}
|
|
1786
|
+
if (extension.anisotropyRotation !== void 0) {
|
|
1787
|
+
materialParams.anisotropyRotation = extension.anisotropyRotation;
|
|
1788
|
+
}
|
|
1789
|
+
if (extension.anisotropyTexture !== void 0) {
|
|
1790
|
+
pending.push(parser.assignTexture(materialParams, "anisotropyMap", extension.anisotropyTexture));
|
|
1791
|
+
}
|
|
1792
|
+
return Promise.all(pending);
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
var GLTFTextureBasisUExtension = class {
|
|
1796
|
+
constructor(parser) {
|
|
1797
|
+
this.parser = parser;
|
|
1798
|
+
this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
|
|
1799
|
+
}
|
|
1800
|
+
loadTexture(textureIndex) {
|
|
1801
|
+
const parser = this.parser;
|
|
1802
|
+
const json = parser.json;
|
|
1803
|
+
const textureDef = json.textures[textureIndex];
|
|
1804
|
+
if (!textureDef.extensions || !textureDef.extensions[this.name]) {
|
|
1805
|
+
return null;
|
|
1806
|
+
}
|
|
1807
|
+
const extension = textureDef.extensions[this.name];
|
|
1808
|
+
const loader = parser.options.ktx2Loader;
|
|
1809
|
+
if (!loader) {
|
|
1810
|
+
if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
|
|
1811
|
+
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
|
|
1812
|
+
} else {
|
|
1813
|
+
return null;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
var GLTFTextureWebPExtension = class {
|
|
1820
|
+
constructor(parser) {
|
|
1821
|
+
this.parser = parser;
|
|
1822
|
+
this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
|
|
1823
|
+
this.isSupported = null;
|
|
1824
|
+
}
|
|
1825
|
+
loadTexture(textureIndex) {
|
|
1826
|
+
const name = this.name;
|
|
1827
|
+
const parser = this.parser;
|
|
1828
|
+
const json = parser.json;
|
|
1829
|
+
const textureDef = json.textures[textureIndex];
|
|
1830
|
+
if (!textureDef.extensions || !textureDef.extensions[name]) {
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
const extension = textureDef.extensions[name];
|
|
1834
|
+
const source = json.images[extension.source];
|
|
1835
|
+
let loader = parser.textureLoader;
|
|
1836
|
+
if (source.uri) {
|
|
1837
|
+
const handler = parser.options.manager.getHandler(source.uri);
|
|
1838
|
+
if (handler !== null)
|
|
1839
|
+
loader = handler;
|
|
1840
|
+
}
|
|
1841
|
+
return this.detectSupport().then(function(isSupported) {
|
|
1842
|
+
if (isSupported)
|
|
1843
|
+
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
1844
|
+
if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
|
|
1845
|
+
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
|
|
1846
|
+
}
|
|
1847
|
+
return parser.loadTexture(textureIndex);
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
detectSupport() {
|
|
1851
|
+
if (!this.isSupported) {
|
|
1852
|
+
this.isSupported = new Promise(function(resolve) {
|
|
1853
|
+
const image = new Image();
|
|
1854
|
+
image.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA";
|
|
1855
|
+
image.onload = image.onerror = function() {
|
|
1856
|
+
resolve(image.height === 1);
|
|
1857
|
+
};
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
return this.isSupported;
|
|
1861
|
+
}
|
|
1862
|
+
};
|
|
1863
|
+
var GLTFTextureAVIFExtension = class {
|
|
1864
|
+
constructor(parser) {
|
|
1865
|
+
this.parser = parser;
|
|
1866
|
+
this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
|
|
1867
|
+
this.isSupported = null;
|
|
1868
|
+
}
|
|
1869
|
+
loadTexture(textureIndex) {
|
|
1870
|
+
const name = this.name;
|
|
1871
|
+
const parser = this.parser;
|
|
1872
|
+
const json = parser.json;
|
|
1873
|
+
const textureDef = json.textures[textureIndex];
|
|
1874
|
+
if (!textureDef.extensions || !textureDef.extensions[name]) {
|
|
1875
|
+
return null;
|
|
1876
|
+
}
|
|
1877
|
+
const extension = textureDef.extensions[name];
|
|
1878
|
+
const source = json.images[extension.source];
|
|
1879
|
+
let loader = parser.textureLoader;
|
|
1880
|
+
if (source.uri) {
|
|
1881
|
+
const handler = parser.options.manager.getHandler(source.uri);
|
|
1882
|
+
if (handler !== null)
|
|
1883
|
+
loader = handler;
|
|
1884
|
+
}
|
|
1885
|
+
return this.detectSupport().then(function(isSupported) {
|
|
1886
|
+
if (isSupported)
|
|
1887
|
+
return parser.loadTextureImage(textureIndex, extension.source, loader);
|
|
1888
|
+
if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
|
|
1889
|
+
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
|
|
1890
|
+
}
|
|
1891
|
+
return parser.loadTexture(textureIndex);
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
detectSupport() {
|
|
1895
|
+
if (!this.isSupported) {
|
|
1896
|
+
this.isSupported = new Promise(function(resolve) {
|
|
1897
|
+
const image = new Image();
|
|
1898
|
+
image.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=";
|
|
1899
|
+
image.onload = image.onerror = function() {
|
|
1900
|
+
resolve(image.height === 1);
|
|
1901
|
+
};
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
return this.isSupported;
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
var GLTFMeshoptCompression = class {
|
|
1908
|
+
constructor(parser) {
|
|
1909
|
+
this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
|
|
1910
|
+
this.parser = parser;
|
|
1911
|
+
}
|
|
1912
|
+
loadBufferView(index) {
|
|
1913
|
+
const json = this.parser.json;
|
|
1914
|
+
const bufferView = json.bufferViews[index];
|
|
1915
|
+
if (bufferView.extensions && bufferView.extensions[this.name]) {
|
|
1916
|
+
const extensionDef = bufferView.extensions[this.name];
|
|
1917
|
+
const buffer = this.parser.getDependency("buffer", extensionDef.buffer);
|
|
1918
|
+
const decoder = this.parser.options.meshoptDecoder;
|
|
1919
|
+
if (!decoder || !decoder.supported) {
|
|
1920
|
+
if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
|
|
1921
|
+
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
|
|
1922
|
+
} else {
|
|
1923
|
+
return null;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return buffer.then(function(res) {
|
|
1927
|
+
const byteOffset = extensionDef.byteOffset || 0;
|
|
1928
|
+
const byteLength = extensionDef.byteLength || 0;
|
|
1929
|
+
const count = extensionDef.count;
|
|
1930
|
+
const stride = extensionDef.byteStride;
|
|
1931
|
+
const source = new Uint8Array(res, byteOffset, byteLength);
|
|
1932
|
+
if (decoder.decodeGltfBufferAsync) {
|
|
1933
|
+
return decoder.decodeGltfBufferAsync(count, stride, source, extensionDef.mode, extensionDef.filter).then(function(res2) {
|
|
1934
|
+
return res2.buffer;
|
|
1935
|
+
});
|
|
1936
|
+
} else {
|
|
1937
|
+
return decoder.ready.then(function() {
|
|
1938
|
+
const result = new ArrayBuffer(count * stride);
|
|
1939
|
+
decoder.decodeGltfBuffer(
|
|
1940
|
+
new Uint8Array(result),
|
|
1941
|
+
count,
|
|
1942
|
+
stride,
|
|
1943
|
+
source,
|
|
1944
|
+
extensionDef.mode,
|
|
1945
|
+
extensionDef.filter
|
|
1946
|
+
);
|
|
1947
|
+
return result;
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
} else {
|
|
1952
|
+
return null;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
var GLTFMeshGpuInstancing = class {
|
|
1957
|
+
constructor(parser) {
|
|
1958
|
+
this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
|
|
1959
|
+
this.parser = parser;
|
|
1960
|
+
}
|
|
1961
|
+
createNodeMesh(nodeIndex) {
|
|
1962
|
+
const json = this.parser.json;
|
|
1963
|
+
const nodeDef = json.nodes[nodeIndex];
|
|
1964
|
+
if (!nodeDef.extensions || !nodeDef.extensions[this.name] || nodeDef.mesh === void 0) {
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
const meshDef = json.meshes[nodeDef.mesh];
|
|
1968
|
+
for (const primitive of meshDef.primitives) {
|
|
1969
|
+
if (primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && primitive.mode !== void 0) {
|
|
1970
|
+
return null;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
const extensionDef = nodeDef.extensions[this.name];
|
|
1974
|
+
const attributesDef = extensionDef.attributes;
|
|
1975
|
+
const pending = [];
|
|
1976
|
+
const attributes = {};
|
|
1977
|
+
for (const key in attributesDef) {
|
|
1978
|
+
pending.push(
|
|
1979
|
+
this.parser.getDependency("accessor", attributesDef[key]).then((accessor) => {
|
|
1980
|
+
attributes[key] = accessor;
|
|
1981
|
+
return attributes[key];
|
|
1982
|
+
})
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
if (pending.length < 1) {
|
|
1986
|
+
return null;
|
|
1987
|
+
}
|
|
1988
|
+
pending.push(this.parser.createNodeMesh(nodeIndex));
|
|
1989
|
+
return Promise.all(pending).then((results) => {
|
|
1990
|
+
const nodeObject = results.pop();
|
|
1991
|
+
const meshes = nodeObject.isGroup ? nodeObject.children : [nodeObject];
|
|
1992
|
+
const count = results[0].count;
|
|
1993
|
+
const instancedMeshes = [];
|
|
1994
|
+
for (const mesh of meshes) {
|
|
1995
|
+
const m = new Matrix4();
|
|
1996
|
+
const p = new Vector33();
|
|
1997
|
+
const q = new Quaternion2();
|
|
1998
|
+
const s = new Vector33(1, 1, 1);
|
|
1999
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, count);
|
|
2000
|
+
for (let i = 0; i < count; i++) {
|
|
2001
|
+
if (attributes.TRANSLATION) {
|
|
2002
|
+
p.fromBufferAttribute(attributes.TRANSLATION, i);
|
|
2003
|
+
}
|
|
2004
|
+
if (attributes.ROTATION) {
|
|
2005
|
+
q.fromBufferAttribute(attributes.ROTATION, i);
|
|
2006
|
+
}
|
|
2007
|
+
if (attributes.SCALE) {
|
|
2008
|
+
s.fromBufferAttribute(attributes.SCALE, i);
|
|
2009
|
+
}
|
|
2010
|
+
instancedMesh.setMatrixAt(i, m.compose(p, q, s));
|
|
2011
|
+
}
|
|
2012
|
+
for (const attributeName in attributes) {
|
|
2013
|
+
if (attributeName === "_COLOR_0") {
|
|
2014
|
+
const attr = attributes[attributeName];
|
|
2015
|
+
instancedMesh.instanceColor = new InstancedBufferAttribute(attr.array, attr.itemSize, attr.normalized);
|
|
2016
|
+
} else if (attributeName !== "TRANSLATION" && attributeName !== "ROTATION" && attributeName !== "SCALE") {
|
|
2017
|
+
mesh.geometry.setAttribute(attributeName, attributes[attributeName]);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
Object3D.prototype.copy.call(instancedMesh, mesh);
|
|
2021
|
+
this.parser.assignFinalMaterial(instancedMesh);
|
|
2022
|
+
instancedMeshes.push(instancedMesh);
|
|
2023
|
+
}
|
|
2024
|
+
if (nodeObject.isGroup) {
|
|
2025
|
+
nodeObject.clear();
|
|
2026
|
+
nodeObject.add(...instancedMeshes);
|
|
2027
|
+
return nodeObject;
|
|
2028
|
+
}
|
|
2029
|
+
return instancedMeshes[0];
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
var BINARY_EXTENSION_HEADER_MAGIC = "glTF";
|
|
2034
|
+
var BINARY_EXTENSION_HEADER_LENGTH = 12;
|
|
2035
|
+
var BINARY_EXTENSION_CHUNK_TYPES = { JSON: 1313821514, BIN: 5130562 };
|
|
2036
|
+
var GLTFBinaryExtension = class {
|
|
2037
|
+
constructor(data) {
|
|
2038
|
+
this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
|
2039
|
+
this.content = null;
|
|
2040
|
+
this.body = null;
|
|
2041
|
+
const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
|
|
2042
|
+
this.header = {
|
|
2043
|
+
magic: decodeText(new Uint8Array(data.slice(0, 4))),
|
|
2044
|
+
version: headerView.getUint32(4, true),
|
|
2045
|
+
length: headerView.getUint32(8, true)
|
|
2046
|
+
};
|
|
2047
|
+
if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
|
2048
|
+
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
|
|
2049
|
+
} else if (this.header.version < 2) {
|
|
2050
|
+
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
|
|
2051
|
+
}
|
|
2052
|
+
const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
|
|
2053
|
+
const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
|
2054
|
+
let chunkIndex = 0;
|
|
2055
|
+
while (chunkIndex < chunkContentsLength) {
|
|
2056
|
+
const chunkLength = chunkView.getUint32(chunkIndex, true);
|
|
2057
|
+
chunkIndex += 4;
|
|
2058
|
+
const chunkType = chunkView.getUint32(chunkIndex, true);
|
|
2059
|
+
chunkIndex += 4;
|
|
2060
|
+
if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
|
2061
|
+
const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
|
|
2062
|
+
this.content = decodeText(contentArray);
|
|
2063
|
+
} else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
|
2064
|
+
const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
|
2065
|
+
this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
|
2066
|
+
}
|
|
2067
|
+
chunkIndex += chunkLength;
|
|
2068
|
+
}
|
|
2069
|
+
if (this.content === null) {
|
|
2070
|
+
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
var GLTFDracoMeshCompressionExtension = class {
|
|
2075
|
+
constructor(json, dracoLoader2) {
|
|
2076
|
+
if (!dracoLoader2) {
|
|
2077
|
+
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
|
|
2078
|
+
}
|
|
2079
|
+
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
|
2080
|
+
this.json = json;
|
|
2081
|
+
this.dracoLoader = dracoLoader2;
|
|
2082
|
+
this.dracoLoader.preload();
|
|
2083
|
+
}
|
|
2084
|
+
decodePrimitive(primitive, parser) {
|
|
2085
|
+
const json = this.json;
|
|
2086
|
+
const dracoLoader2 = this.dracoLoader;
|
|
2087
|
+
const bufferViewIndex = primitive.extensions[this.name].bufferView;
|
|
2088
|
+
const gltfAttributeMap = primitive.extensions[this.name].attributes;
|
|
2089
|
+
const threeAttributeMap = {};
|
|
2090
|
+
const attributeNormalizedMap = {};
|
|
2091
|
+
const attributeTypeMap = {};
|
|
2092
|
+
for (const attributeName in gltfAttributeMap) {
|
|
2093
|
+
const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
|
2094
|
+
threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
|
|
2095
|
+
}
|
|
2096
|
+
for (const attributeName in primitive.attributes) {
|
|
2097
|
+
const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
|
2098
|
+
if (gltfAttributeMap[attributeName] !== void 0) {
|
|
2099
|
+
const accessorDef = json.accessors[primitive.attributes[attributeName]];
|
|
2100
|
+
const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
2101
|
+
attributeTypeMap[threeAttributeName] = componentType.name;
|
|
2102
|
+
attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
return parser.getDependency("bufferView", bufferViewIndex).then(function(bufferView) {
|
|
2106
|
+
return new Promise(function(resolve, reject) {
|
|
2107
|
+
dracoLoader2.decodeDracoFile(
|
|
2108
|
+
bufferView,
|
|
2109
|
+
function(geometry) {
|
|
2110
|
+
for (const attributeName in geometry.attributes) {
|
|
2111
|
+
const attribute = geometry.attributes[attributeName];
|
|
2112
|
+
const normalized = attributeNormalizedMap[attributeName];
|
|
2113
|
+
if (normalized !== void 0)
|
|
2114
|
+
attribute.normalized = normalized;
|
|
2115
|
+
}
|
|
2116
|
+
resolve(geometry);
|
|
2117
|
+
},
|
|
2118
|
+
threeAttributeMap,
|
|
2119
|
+
attributeTypeMap,
|
|
2120
|
+
LinearSRGBColorSpace,
|
|
2121
|
+
reject
|
|
2122
|
+
);
|
|
2123
|
+
});
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
};
|
|
2127
|
+
var GLTFTextureTransformExtension = class {
|
|
2128
|
+
constructor() {
|
|
2129
|
+
this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
|
2130
|
+
}
|
|
2131
|
+
extendTexture(texture, transform) {
|
|
2132
|
+
if ((transform.texCoord === void 0 || transform.texCoord === texture.channel) && transform.offset === void 0 && transform.rotation === void 0 && transform.scale === void 0) {
|
|
2133
|
+
return texture;
|
|
2134
|
+
}
|
|
2135
|
+
texture = texture.clone();
|
|
2136
|
+
if (transform.texCoord !== void 0) {
|
|
2137
|
+
texture.channel = transform.texCoord;
|
|
2138
|
+
}
|
|
2139
|
+
if (transform.offset !== void 0) {
|
|
2140
|
+
texture.offset.fromArray(transform.offset);
|
|
2141
|
+
}
|
|
2142
|
+
if (transform.rotation !== void 0) {
|
|
2143
|
+
texture.rotation = transform.rotation;
|
|
2144
|
+
}
|
|
2145
|
+
if (transform.scale !== void 0) {
|
|
2146
|
+
texture.repeat.fromArray(transform.scale);
|
|
2147
|
+
}
|
|
2148
|
+
texture.needsUpdate = true;
|
|
2149
|
+
return texture;
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
var GLTFMeshQuantizationExtension = class {
|
|
2153
|
+
constructor() {
|
|
2154
|
+
this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
var GLTFCubicSplineInterpolant = class extends Interpolant {
|
|
2158
|
+
constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
|
2159
|
+
super(parameterPositions, sampleValues, sampleSize, resultBuffer);
|
|
2160
|
+
}
|
|
2161
|
+
copySampleValue_(index) {
|
|
2162
|
+
const result = this.resultBuffer, values = this.sampleValues, valueSize = this.valueSize, offset = index * valueSize * 3 + valueSize;
|
|
2163
|
+
for (let i = 0; i !== valueSize; i++) {
|
|
2164
|
+
result[i] = values[offset + i];
|
|
2165
|
+
}
|
|
2166
|
+
return result;
|
|
2167
|
+
}
|
|
2168
|
+
interpolate_(i1, t0, t, t1) {
|
|
2169
|
+
const result = this.resultBuffer;
|
|
2170
|
+
const values = this.sampleValues;
|
|
2171
|
+
const stride = this.valueSize;
|
|
2172
|
+
const stride2 = stride * 2;
|
|
2173
|
+
const stride3 = stride * 3;
|
|
2174
|
+
const td = t1 - t0;
|
|
2175
|
+
const p = (t - t0) / td;
|
|
2176
|
+
const pp = p * p;
|
|
2177
|
+
const ppp = pp * p;
|
|
2178
|
+
const offset1 = i1 * stride3;
|
|
2179
|
+
const offset0 = offset1 - stride3;
|
|
2180
|
+
const s2 = -2 * ppp + 3 * pp;
|
|
2181
|
+
const s3 = ppp - pp;
|
|
2182
|
+
const s0 = 1 - s2;
|
|
2183
|
+
const s1 = s3 - pp + p;
|
|
2184
|
+
for (let i = 0; i !== stride; i++) {
|
|
2185
|
+
const p0 = values[offset0 + i + stride];
|
|
2186
|
+
const m0 = values[offset0 + i + stride2] * td;
|
|
2187
|
+
const p1 = values[offset1 + i + stride];
|
|
2188
|
+
const m1 = values[offset1 + i] * td;
|
|
2189
|
+
result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
|
2190
|
+
}
|
|
2191
|
+
return result;
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2194
|
+
var _q = /* @__PURE__ */ new Quaternion2();
|
|
2195
|
+
var GLTFCubicSplineQuaternionInterpolant = class extends GLTFCubicSplineInterpolant {
|
|
2196
|
+
interpolate_(i1, t0, t, t1) {
|
|
2197
|
+
const result = super.interpolate_(i1, t0, t, t1);
|
|
2198
|
+
_q.fromArray(result).normalize().toArray(result);
|
|
2199
|
+
return result;
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
var WEBGL_CONSTANTS = {
|
|
2203
|
+
FLOAT: 5126,
|
|
2204
|
+
//FLOAT_MAT2: 35674,
|
|
2205
|
+
FLOAT_MAT3: 35675,
|
|
2206
|
+
FLOAT_MAT4: 35676,
|
|
2207
|
+
FLOAT_VEC2: 35664,
|
|
2208
|
+
FLOAT_VEC3: 35665,
|
|
2209
|
+
FLOAT_VEC4: 35666,
|
|
2210
|
+
LINEAR: 9729,
|
|
2211
|
+
REPEAT: 10497,
|
|
2212
|
+
SAMPLER_2D: 35678,
|
|
2213
|
+
POINTS: 0,
|
|
2214
|
+
LINES: 1,
|
|
2215
|
+
LINE_LOOP: 2,
|
|
2216
|
+
LINE_STRIP: 3,
|
|
2217
|
+
TRIANGLES: 4,
|
|
2218
|
+
TRIANGLE_STRIP: 5,
|
|
2219
|
+
TRIANGLE_FAN: 6,
|
|
2220
|
+
UNSIGNED_BYTE: 5121,
|
|
2221
|
+
UNSIGNED_SHORT: 5123
|
|
2222
|
+
};
|
|
2223
|
+
var WEBGL_COMPONENT_TYPES = {
|
|
2224
|
+
5120: Int8Array,
|
|
2225
|
+
5121: Uint8Array,
|
|
2226
|
+
5122: Int16Array,
|
|
2227
|
+
5123: Uint16Array,
|
|
2228
|
+
5125: Uint32Array,
|
|
2229
|
+
5126: Float32Array
|
|
2230
|
+
};
|
|
2231
|
+
var WEBGL_FILTERS = {
|
|
2232
|
+
9728: NearestFilter,
|
|
2233
|
+
9729: LinearFilter,
|
|
2234
|
+
9984: NearestMipmapNearestFilter,
|
|
2235
|
+
9985: LinearMipmapNearestFilter,
|
|
2236
|
+
9986: NearestMipmapLinearFilter,
|
|
2237
|
+
9987: LinearMipmapLinearFilter
|
|
2238
|
+
};
|
|
2239
|
+
var WEBGL_WRAPPINGS = {
|
|
2240
|
+
33071: ClampToEdgeWrapping,
|
|
2241
|
+
33648: MirroredRepeatWrapping,
|
|
2242
|
+
10497: RepeatWrapping
|
|
2243
|
+
};
|
|
2244
|
+
var WEBGL_TYPE_SIZES = {
|
|
2245
|
+
SCALAR: 1,
|
|
2246
|
+
VEC2: 2,
|
|
2247
|
+
VEC3: 3,
|
|
2248
|
+
VEC4: 4,
|
|
2249
|
+
MAT2: 4,
|
|
2250
|
+
MAT3: 9,
|
|
2251
|
+
MAT4: 16
|
|
2252
|
+
};
|
|
2253
|
+
var ATTRIBUTES = {
|
|
2254
|
+
POSITION: "position",
|
|
2255
|
+
NORMAL: "normal",
|
|
2256
|
+
TANGENT: "tangent",
|
|
2257
|
+
// uv => uv1, 4 uv channels
|
|
2258
|
+
// https://github.com/mrdoob/three.js/pull/25943
|
|
2259
|
+
// https://github.com/mrdoob/three.js/pull/25788
|
|
2260
|
+
...version >= 152 ? {
|
|
2261
|
+
TEXCOORD_0: "uv",
|
|
2262
|
+
TEXCOORD_1: "uv1",
|
|
2263
|
+
TEXCOORD_2: "uv2",
|
|
2264
|
+
TEXCOORD_3: "uv3"
|
|
2265
|
+
} : {
|
|
2266
|
+
TEXCOORD_0: "uv",
|
|
2267
|
+
TEXCOORD_1: "uv2"
|
|
2268
|
+
},
|
|
2269
|
+
COLOR_0: "color",
|
|
2270
|
+
WEIGHTS_0: "skinWeight",
|
|
2271
|
+
JOINTS_0: "skinIndex"
|
|
2272
|
+
};
|
|
2273
|
+
var PATH_PROPERTIES = {
|
|
2274
|
+
scale: "scale",
|
|
2275
|
+
translation: "position",
|
|
2276
|
+
rotation: "quaternion",
|
|
2277
|
+
weights: "morphTargetInfluences"
|
|
2278
|
+
};
|
|
2279
|
+
var INTERPOLATION = {
|
|
2280
|
+
CUBICSPLINE: void 0,
|
|
2281
|
+
// We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
2282
|
+
// keyframe track will be initialized with a default interpolation type, then modified.
|
|
2283
|
+
LINEAR: InterpolateLinear,
|
|
2284
|
+
STEP: InterpolateDiscrete
|
|
2285
|
+
};
|
|
2286
|
+
var ALPHA_MODES = {
|
|
2287
|
+
OPAQUE: "OPAQUE",
|
|
2288
|
+
MASK: "MASK",
|
|
2289
|
+
BLEND: "BLEND"
|
|
2290
|
+
};
|
|
2291
|
+
function createDefaultMaterial(cache) {
|
|
2292
|
+
if (cache["DefaultMaterial"] === void 0) {
|
|
2293
|
+
cache["DefaultMaterial"] = new MeshStandardMaterial({
|
|
2294
|
+
color: 16777215,
|
|
2295
|
+
emissive: 0,
|
|
2296
|
+
metalness: 1,
|
|
2297
|
+
roughness: 1,
|
|
2298
|
+
transparent: false,
|
|
2299
|
+
depthTest: true,
|
|
2300
|
+
side: FrontSide
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
return cache["DefaultMaterial"];
|
|
2304
|
+
}
|
|
2305
|
+
function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
|
|
2306
|
+
for (const name in objectDef.extensions) {
|
|
2307
|
+
if (knownExtensions[name] === void 0) {
|
|
2308
|
+
object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
|
2309
|
+
object.userData.gltfExtensions[name] = objectDef.extensions[name];
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
function assignExtrasToUserData(object, gltfDef) {
|
|
2314
|
+
if (gltfDef.extras !== void 0) {
|
|
2315
|
+
if (typeof gltfDef.extras === "object") {
|
|
2316
|
+
Object.assign(object.userData, gltfDef.extras);
|
|
2317
|
+
} else {
|
|
2318
|
+
console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + gltfDef.extras);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
function addMorphTargets(geometry, targets, parser) {
|
|
2323
|
+
let hasMorphPosition = false;
|
|
2324
|
+
let hasMorphNormal = false;
|
|
2325
|
+
let hasMorphColor = false;
|
|
2326
|
+
for (let i = 0, il = targets.length; i < il; i++) {
|
|
2327
|
+
const target = targets[i];
|
|
2328
|
+
if (target.POSITION !== void 0)
|
|
2329
|
+
hasMorphPosition = true;
|
|
2330
|
+
if (target.NORMAL !== void 0)
|
|
2331
|
+
hasMorphNormal = true;
|
|
2332
|
+
if (target.COLOR_0 !== void 0)
|
|
2333
|
+
hasMorphColor = true;
|
|
2334
|
+
if (hasMorphPosition && hasMorphNormal && hasMorphColor)
|
|
2335
|
+
break;
|
|
2336
|
+
}
|
|
2337
|
+
if (!hasMorphPosition && !hasMorphNormal && !hasMorphColor)
|
|
2338
|
+
return Promise.resolve(geometry);
|
|
2339
|
+
const pendingPositionAccessors = [];
|
|
2340
|
+
const pendingNormalAccessors = [];
|
|
2341
|
+
const pendingColorAccessors = [];
|
|
2342
|
+
for (let i = 0, il = targets.length; i < il; i++) {
|
|
2343
|
+
const target = targets[i];
|
|
2344
|
+
if (hasMorphPosition) {
|
|
2345
|
+
const pendingAccessor = target.POSITION !== void 0 ? parser.getDependency("accessor", target.POSITION) : geometry.attributes.position;
|
|
2346
|
+
pendingPositionAccessors.push(pendingAccessor);
|
|
2347
|
+
}
|
|
2348
|
+
if (hasMorphNormal) {
|
|
2349
|
+
const pendingAccessor = target.NORMAL !== void 0 ? parser.getDependency("accessor", target.NORMAL) : geometry.attributes.normal;
|
|
2350
|
+
pendingNormalAccessors.push(pendingAccessor);
|
|
2351
|
+
}
|
|
2352
|
+
if (hasMorphColor) {
|
|
2353
|
+
const pendingAccessor = target.COLOR_0 !== void 0 ? parser.getDependency("accessor", target.COLOR_0) : geometry.attributes.color;
|
|
2354
|
+
pendingColorAccessors.push(pendingAccessor);
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
return Promise.all([
|
|
2358
|
+
Promise.all(pendingPositionAccessors),
|
|
2359
|
+
Promise.all(pendingNormalAccessors),
|
|
2360
|
+
Promise.all(pendingColorAccessors)
|
|
2361
|
+
]).then(function(accessors) {
|
|
2362
|
+
const morphPositions = accessors[0];
|
|
2363
|
+
const morphNormals = accessors[1];
|
|
2364
|
+
const morphColors = accessors[2];
|
|
2365
|
+
if (hasMorphPosition)
|
|
2366
|
+
geometry.morphAttributes.position = morphPositions;
|
|
2367
|
+
if (hasMorphNormal)
|
|
2368
|
+
geometry.morphAttributes.normal = morphNormals;
|
|
2369
|
+
if (hasMorphColor)
|
|
2370
|
+
geometry.morphAttributes.color = morphColors;
|
|
2371
|
+
geometry.morphTargetsRelative = true;
|
|
2372
|
+
return geometry;
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
function updateMorphTargets(mesh, meshDef) {
|
|
2376
|
+
mesh.updateMorphTargets();
|
|
2377
|
+
if (meshDef.weights !== void 0) {
|
|
2378
|
+
for (let i = 0, il = meshDef.weights.length; i < il; i++) {
|
|
2379
|
+
mesh.morphTargetInfluences[i] = meshDef.weights[i];
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
|
|
2383
|
+
const targetNames = meshDef.extras.targetNames;
|
|
2384
|
+
if (mesh.morphTargetInfluences.length === targetNames.length) {
|
|
2385
|
+
mesh.morphTargetDictionary = {};
|
|
2386
|
+
for (let i = 0, il = targetNames.length; i < il; i++) {
|
|
2387
|
+
mesh.morphTargetDictionary[targetNames[i]] = i;
|
|
2388
|
+
}
|
|
2389
|
+
} else {
|
|
2390
|
+
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
function createPrimitiveKey(primitiveDef) {
|
|
2395
|
+
let geometryKey;
|
|
2396
|
+
const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
|
2397
|
+
if (dracoExtension) {
|
|
2398
|
+
geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
|
|
2399
|
+
} else {
|
|
2400
|
+
geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
|
|
2401
|
+
}
|
|
2402
|
+
if (primitiveDef.targets !== void 0) {
|
|
2403
|
+
for (let i = 0, il = primitiveDef.targets.length; i < il; i++) {
|
|
2404
|
+
geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
return geometryKey;
|
|
2408
|
+
}
|
|
2409
|
+
function createAttributesKey(attributes) {
|
|
2410
|
+
let attributesKey = "";
|
|
2411
|
+
const keys = Object.keys(attributes).sort();
|
|
2412
|
+
for (let i = 0, il = keys.length; i < il; i++) {
|
|
2413
|
+
attributesKey += keys[i] + ":" + attributes[keys[i]] + ";";
|
|
2414
|
+
}
|
|
2415
|
+
return attributesKey;
|
|
2416
|
+
}
|
|
2417
|
+
function getNormalizedComponentScale(constructor) {
|
|
2418
|
+
switch (constructor) {
|
|
2419
|
+
case Int8Array:
|
|
2420
|
+
return 1 / 127;
|
|
2421
|
+
case Uint8Array:
|
|
2422
|
+
return 1 / 255;
|
|
2423
|
+
case Int16Array:
|
|
2424
|
+
return 1 / 32767;
|
|
2425
|
+
case Uint16Array:
|
|
2426
|
+
return 1 / 65535;
|
|
2427
|
+
default:
|
|
2428
|
+
throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
function getImageURIMimeType(uri) {
|
|
2432
|
+
if (uri.search(/\.jpe?g($|\?)/i) > 0 || uri.search(/^data\:image\/jpeg/) === 0)
|
|
2433
|
+
return "image/jpeg";
|
|
2434
|
+
if (uri.search(/\.webp($|\?)/i) > 0 || uri.search(/^data\:image\/webp/) === 0)
|
|
2435
|
+
return "image/webp";
|
|
2436
|
+
return "image/png";
|
|
2437
|
+
}
|
|
2438
|
+
var _identityMatrix = /* @__PURE__ */ new Matrix4();
|
|
2439
|
+
var GLTFParser = class {
|
|
2440
|
+
constructor(json = {}, options = {}) {
|
|
2441
|
+
this.json = json;
|
|
2442
|
+
this.extensions = {};
|
|
2443
|
+
this.plugins = {};
|
|
2444
|
+
this.options = options;
|
|
2445
|
+
this.cache = new GLTFRegistry();
|
|
2446
|
+
this.associations = /* @__PURE__ */ new Map();
|
|
2447
|
+
this.primitiveCache = {};
|
|
2448
|
+
this.nodeCache = {};
|
|
2449
|
+
this.meshCache = { refs: {}, uses: {} };
|
|
2450
|
+
this.cameraCache = { refs: {}, uses: {} };
|
|
2451
|
+
this.lightCache = { refs: {}, uses: {} };
|
|
2452
|
+
this.sourceCache = {};
|
|
2453
|
+
this.textureCache = {};
|
|
2454
|
+
this.nodeNamesUsed = {};
|
|
2455
|
+
let isSafari = false;
|
|
2456
|
+
let isFirefox = false;
|
|
2457
|
+
let firefoxVersion = -1;
|
|
2458
|
+
if (typeof navigator !== "undefined" && typeof navigator.userAgent !== "undefined") {
|
|
2459
|
+
isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === true;
|
|
2460
|
+
isFirefox = navigator.userAgent.indexOf("Firefox") > -1;
|
|
2461
|
+
firefoxVersion = isFirefox ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1;
|
|
2462
|
+
}
|
|
2463
|
+
if (typeof createImageBitmap === "undefined" || isSafari || isFirefox && firefoxVersion < 98) {
|
|
2464
|
+
this.textureLoader = new TextureLoader(this.options.manager);
|
|
2465
|
+
} else {
|
|
2466
|
+
this.textureLoader = new ImageBitmapLoader(this.options.manager);
|
|
2467
|
+
}
|
|
2468
|
+
this.textureLoader.setCrossOrigin(this.options.crossOrigin);
|
|
2469
|
+
this.textureLoader.setRequestHeader(this.options.requestHeader);
|
|
2470
|
+
this.fileLoader = new FileLoader(this.options.manager);
|
|
2471
|
+
this.fileLoader.setResponseType("arraybuffer");
|
|
2472
|
+
if (this.options.crossOrigin === "use-credentials") {
|
|
2473
|
+
this.fileLoader.setWithCredentials(true);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
setExtensions(extensions2) {
|
|
2477
|
+
this.extensions = extensions2;
|
|
2478
|
+
}
|
|
2479
|
+
setPlugins(plugins) {
|
|
2480
|
+
this.plugins = plugins;
|
|
2481
|
+
}
|
|
2482
|
+
parse(onLoad, onError) {
|
|
2483
|
+
const parser = this;
|
|
2484
|
+
const json = this.json;
|
|
2485
|
+
const extensions2 = this.extensions;
|
|
2486
|
+
this.cache.removeAll();
|
|
2487
|
+
this.nodeCache = {};
|
|
2488
|
+
this._invokeAll(function(ext) {
|
|
2489
|
+
return ext._markDefs && ext._markDefs();
|
|
2490
|
+
});
|
|
2491
|
+
Promise.all(
|
|
2492
|
+
this._invokeAll(function(ext) {
|
|
2493
|
+
return ext.beforeRoot && ext.beforeRoot();
|
|
2494
|
+
})
|
|
2495
|
+
).then(function() {
|
|
2496
|
+
return Promise.all([
|
|
2497
|
+
parser.getDependencies("scene"),
|
|
2498
|
+
parser.getDependencies("animation"),
|
|
2499
|
+
parser.getDependencies("camera")
|
|
2500
|
+
]);
|
|
2501
|
+
}).then(function(dependencies) {
|
|
2502
|
+
const result = {
|
|
2503
|
+
scene: dependencies[0][json.scene || 0],
|
|
2504
|
+
scenes: dependencies[0],
|
|
2505
|
+
animations: dependencies[1],
|
|
2506
|
+
cameras: dependencies[2],
|
|
2507
|
+
asset: json.asset,
|
|
2508
|
+
parser,
|
|
2509
|
+
userData: {}
|
|
2510
|
+
};
|
|
2511
|
+
addUnknownExtensionsToUserData(extensions2, result, json);
|
|
2512
|
+
assignExtrasToUserData(result, json);
|
|
2513
|
+
return Promise.all(
|
|
2514
|
+
parser._invokeAll(function(ext) {
|
|
2515
|
+
return ext.afterRoot && ext.afterRoot(result);
|
|
2516
|
+
})
|
|
2517
|
+
).then(function() {
|
|
2518
|
+
for (const scene of result.scenes) {
|
|
2519
|
+
scene.updateMatrixWorld();
|
|
2520
|
+
}
|
|
2521
|
+
onLoad(result);
|
|
2522
|
+
});
|
|
2523
|
+
}).catch(onError);
|
|
2524
|
+
}
|
|
2525
|
+
/**
|
|
2526
|
+
* Marks the special nodes/meshes in json for efficient parse.
|
|
2527
|
+
*/
|
|
2528
|
+
_markDefs() {
|
|
2529
|
+
const nodeDefs = this.json.nodes || [];
|
|
2530
|
+
const skinDefs = this.json.skins || [];
|
|
2531
|
+
const meshDefs = this.json.meshes || [];
|
|
2532
|
+
for (let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
|
|
2533
|
+
const joints = skinDefs[skinIndex].joints;
|
|
2534
|
+
for (let i = 0, il = joints.length; i < il; i++) {
|
|
2535
|
+
nodeDefs[joints[i]].isBone = true;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
|
2539
|
+
const nodeDef = nodeDefs[nodeIndex];
|
|
2540
|
+
if (nodeDef.mesh !== void 0) {
|
|
2541
|
+
this._addNodeRef(this.meshCache, nodeDef.mesh);
|
|
2542
|
+
if (nodeDef.skin !== void 0) {
|
|
2543
|
+
meshDefs[nodeDef.mesh].isSkinnedMesh = true;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
if (nodeDef.camera !== void 0) {
|
|
2547
|
+
this._addNodeRef(this.cameraCache, nodeDef.camera);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Counts references to shared node / Object3D resources. These resources
|
|
2553
|
+
* can be reused, or "instantiated", at multiple nodes in the scene
|
|
2554
|
+
* hierarchy. Mesh, Camera, and Light instances are instantiated and must
|
|
2555
|
+
* be marked. Non-scenegraph resources (like Materials, Geometries, and
|
|
2556
|
+
* Textures) can be reused directly and are not marked here.
|
|
2557
|
+
*
|
|
2558
|
+
* Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
|
2559
|
+
*/
|
|
2560
|
+
_addNodeRef(cache, index) {
|
|
2561
|
+
if (index === void 0)
|
|
2562
|
+
return;
|
|
2563
|
+
if (cache.refs[index] === void 0) {
|
|
2564
|
+
cache.refs[index] = cache.uses[index] = 0;
|
|
2565
|
+
}
|
|
2566
|
+
cache.refs[index]++;
|
|
2567
|
+
}
|
|
2568
|
+
/** Returns a reference to a shared resource, cloning it if necessary. */
|
|
2569
|
+
_getNodeRef(cache, index, object) {
|
|
2570
|
+
if (cache.refs[index] <= 1)
|
|
2571
|
+
return object;
|
|
2572
|
+
const ref = object.clone();
|
|
2573
|
+
const updateMappings = (original, clone) => {
|
|
2574
|
+
const mappings = this.associations.get(original);
|
|
2575
|
+
if (mappings != null) {
|
|
2576
|
+
this.associations.set(clone, mappings);
|
|
2577
|
+
}
|
|
2578
|
+
for (const [i, child] of original.children.entries()) {
|
|
2579
|
+
updateMappings(child, clone.children[i]);
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
updateMappings(object, ref);
|
|
2583
|
+
ref.name += "_instance_" + cache.uses[index]++;
|
|
2584
|
+
return ref;
|
|
2585
|
+
}
|
|
2586
|
+
_invokeOne(func) {
|
|
2587
|
+
const extensions2 = Object.values(this.plugins);
|
|
2588
|
+
extensions2.push(this);
|
|
2589
|
+
for (let i = 0; i < extensions2.length; i++) {
|
|
2590
|
+
const result = func(extensions2[i]);
|
|
2591
|
+
if (result)
|
|
2592
|
+
return result;
|
|
2593
|
+
}
|
|
2594
|
+
return null;
|
|
2595
|
+
}
|
|
2596
|
+
_invokeAll(func) {
|
|
2597
|
+
const extensions2 = Object.values(this.plugins);
|
|
2598
|
+
extensions2.unshift(this);
|
|
2599
|
+
const pending = [];
|
|
2600
|
+
for (let i = 0; i < extensions2.length; i++) {
|
|
2601
|
+
const result = func(extensions2[i]);
|
|
2602
|
+
if (result)
|
|
2603
|
+
pending.push(result);
|
|
2604
|
+
}
|
|
2605
|
+
return pending;
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Requests the specified dependency asynchronously, with caching.
|
|
2609
|
+
* @param {string} type
|
|
2610
|
+
* @param {number} index
|
|
2611
|
+
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
|
|
2612
|
+
*/
|
|
2613
|
+
getDependency(type, index) {
|
|
2614
|
+
const cacheKey = type + ":" + index;
|
|
2615
|
+
let dependency = this.cache.get(cacheKey);
|
|
2616
|
+
if (!dependency) {
|
|
2617
|
+
switch (type) {
|
|
2618
|
+
case "scene":
|
|
2619
|
+
dependency = this.loadScene(index);
|
|
2620
|
+
break;
|
|
2621
|
+
case "node":
|
|
2622
|
+
dependency = this._invokeOne(function(ext) {
|
|
2623
|
+
return ext.loadNode && ext.loadNode(index);
|
|
2624
|
+
});
|
|
2625
|
+
break;
|
|
2626
|
+
case "mesh":
|
|
2627
|
+
dependency = this._invokeOne(function(ext) {
|
|
2628
|
+
return ext.loadMesh && ext.loadMesh(index);
|
|
2629
|
+
});
|
|
2630
|
+
break;
|
|
2631
|
+
case "accessor":
|
|
2632
|
+
dependency = this.loadAccessor(index);
|
|
2633
|
+
break;
|
|
2634
|
+
case "bufferView":
|
|
2635
|
+
dependency = this._invokeOne(function(ext) {
|
|
2636
|
+
return ext.loadBufferView && ext.loadBufferView(index);
|
|
2637
|
+
});
|
|
2638
|
+
break;
|
|
2639
|
+
case "buffer":
|
|
2640
|
+
dependency = this.loadBuffer(index);
|
|
2641
|
+
break;
|
|
2642
|
+
case "material":
|
|
2643
|
+
dependency = this._invokeOne(function(ext) {
|
|
2644
|
+
return ext.loadMaterial && ext.loadMaterial(index);
|
|
2645
|
+
});
|
|
2646
|
+
break;
|
|
2647
|
+
case "texture":
|
|
2648
|
+
dependency = this._invokeOne(function(ext) {
|
|
2649
|
+
return ext.loadTexture && ext.loadTexture(index);
|
|
2650
|
+
});
|
|
2651
|
+
break;
|
|
2652
|
+
case "skin":
|
|
2653
|
+
dependency = this.loadSkin(index);
|
|
2654
|
+
break;
|
|
2655
|
+
case "animation":
|
|
2656
|
+
dependency = this._invokeOne(function(ext) {
|
|
2657
|
+
return ext.loadAnimation && ext.loadAnimation(index);
|
|
2658
|
+
});
|
|
2659
|
+
break;
|
|
2660
|
+
case "camera":
|
|
2661
|
+
dependency = this.loadCamera(index);
|
|
2662
|
+
break;
|
|
2663
|
+
default:
|
|
2664
|
+
dependency = this._invokeOne(function(ext) {
|
|
2665
|
+
return ext != this && ext.getDependency && ext.getDependency(type, index);
|
|
2666
|
+
});
|
|
2667
|
+
if (!dependency) {
|
|
2668
|
+
throw new Error("Unknown type: " + type);
|
|
2669
|
+
}
|
|
2670
|
+
break;
|
|
2671
|
+
}
|
|
2672
|
+
this.cache.add(cacheKey, dependency);
|
|
2673
|
+
}
|
|
2674
|
+
return dependency;
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Requests all dependencies of the specified type asynchronously, with caching.
|
|
2678
|
+
* @param {string} type
|
|
2679
|
+
* @return {Promise<Array<Object>>}
|
|
2680
|
+
*/
|
|
2681
|
+
getDependencies(type) {
|
|
2682
|
+
let dependencies = this.cache.get(type);
|
|
2683
|
+
if (!dependencies) {
|
|
2684
|
+
const parser = this;
|
|
2685
|
+
const defs = this.json[type + (type === "mesh" ? "es" : "s")] || [];
|
|
2686
|
+
dependencies = Promise.all(
|
|
2687
|
+
defs.map(function(def, index) {
|
|
2688
|
+
return parser.getDependency(type, index);
|
|
2689
|
+
})
|
|
2690
|
+
);
|
|
2691
|
+
this.cache.add(type, dependencies);
|
|
2692
|
+
}
|
|
2693
|
+
return dependencies;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
2697
|
+
* @param {number} bufferIndex
|
|
2698
|
+
* @return {Promise<ArrayBuffer>}
|
|
2699
|
+
*/
|
|
2700
|
+
loadBuffer(bufferIndex) {
|
|
2701
|
+
const bufferDef = this.json.buffers[bufferIndex];
|
|
2702
|
+
const loader = this.fileLoader;
|
|
2703
|
+
if (bufferDef.type && bufferDef.type !== "arraybuffer") {
|
|
2704
|
+
throw new Error("THREE.GLTFLoader: " + bufferDef.type + " buffer type is not supported.");
|
|
2705
|
+
}
|
|
2706
|
+
if (bufferDef.uri === void 0 && bufferIndex === 0) {
|
|
2707
|
+
return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
|
|
2708
|
+
}
|
|
2709
|
+
const options = this.options;
|
|
2710
|
+
return new Promise(function(resolve, reject) {
|
|
2711
|
+
loader.load(LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, void 0, function() {
|
|
2712
|
+
reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
|
|
2713
|
+
});
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
2718
|
+
* @param {number} bufferViewIndex
|
|
2719
|
+
* @return {Promise<ArrayBuffer>}
|
|
2720
|
+
*/
|
|
2721
|
+
loadBufferView(bufferViewIndex) {
|
|
2722
|
+
const bufferViewDef = this.json.bufferViews[bufferViewIndex];
|
|
2723
|
+
return this.getDependency("buffer", bufferViewDef.buffer).then(function(buffer) {
|
|
2724
|
+
const byteLength = bufferViewDef.byteLength || 0;
|
|
2725
|
+
const byteOffset = bufferViewDef.byteOffset || 0;
|
|
2726
|
+
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
|
2731
|
+
* @param {number} accessorIndex
|
|
2732
|
+
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
|
|
2733
|
+
*/
|
|
2734
|
+
loadAccessor(accessorIndex) {
|
|
2735
|
+
const parser = this;
|
|
2736
|
+
const json = this.json;
|
|
2737
|
+
const accessorDef = this.json.accessors[accessorIndex];
|
|
2738
|
+
if (accessorDef.bufferView === void 0 && accessorDef.sparse === void 0) {
|
|
2739
|
+
const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
|
2740
|
+
const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
2741
|
+
const normalized = accessorDef.normalized === true;
|
|
2742
|
+
const array = new TypedArray(accessorDef.count * itemSize);
|
|
2743
|
+
return Promise.resolve(new BufferAttribute2(array, itemSize, normalized));
|
|
2744
|
+
}
|
|
2745
|
+
const pendingBufferViews = [];
|
|
2746
|
+
if (accessorDef.bufferView !== void 0) {
|
|
2747
|
+
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.bufferView));
|
|
2748
|
+
} else {
|
|
2749
|
+
pendingBufferViews.push(null);
|
|
2750
|
+
}
|
|
2751
|
+
if (accessorDef.sparse !== void 0) {
|
|
2752
|
+
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.indices.bufferView));
|
|
2753
|
+
pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.values.bufferView));
|
|
2754
|
+
}
|
|
2755
|
+
return Promise.all(pendingBufferViews).then(function(bufferViews) {
|
|
2756
|
+
const bufferView = bufferViews[0];
|
|
2757
|
+
const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
|
2758
|
+
const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
|
2759
|
+
const elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
2760
|
+
const itemBytes = elementBytes * itemSize;
|
|
2761
|
+
const byteOffset = accessorDef.byteOffset || 0;
|
|
2762
|
+
const byteStride = accessorDef.bufferView !== void 0 ? json.bufferViews[accessorDef.bufferView].byteStride : void 0;
|
|
2763
|
+
const normalized = accessorDef.normalized === true;
|
|
2764
|
+
let array, bufferAttribute;
|
|
2765
|
+
if (byteStride && byteStride !== itemBytes) {
|
|
2766
|
+
const ibSlice = Math.floor(byteOffset / byteStride);
|
|
2767
|
+
const ibCacheKey = "InterleavedBuffer:" + accessorDef.bufferView + ":" + accessorDef.componentType + ":" + ibSlice + ":" + accessorDef.count;
|
|
2768
|
+
let ib = parser.cache.get(ibCacheKey);
|
|
2769
|
+
if (!ib) {
|
|
2770
|
+
array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
|
|
2771
|
+
ib = new InterleavedBuffer2(array, byteStride / elementBytes);
|
|
2772
|
+
parser.cache.add(ibCacheKey, ib);
|
|
2773
|
+
}
|
|
2774
|
+
bufferAttribute = new InterleavedBufferAttribute2(
|
|
2775
|
+
ib,
|
|
2776
|
+
itemSize,
|
|
2777
|
+
byteOffset % byteStride / elementBytes,
|
|
2778
|
+
normalized
|
|
2779
|
+
);
|
|
2780
|
+
} else {
|
|
2781
|
+
if (bufferView === null) {
|
|
2782
|
+
array = new TypedArray(accessorDef.count * itemSize);
|
|
2783
|
+
} else {
|
|
2784
|
+
array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
|
|
2785
|
+
}
|
|
2786
|
+
bufferAttribute = new BufferAttribute2(array, itemSize, normalized);
|
|
2787
|
+
}
|
|
2788
|
+
if (accessorDef.sparse !== void 0) {
|
|
2789
|
+
const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
|
2790
|
+
const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
|
|
2791
|
+
const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
|
2792
|
+
const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
|
2793
|
+
const sparseIndices = new TypedArrayIndices(
|
|
2794
|
+
bufferViews[1],
|
|
2795
|
+
byteOffsetIndices,
|
|
2796
|
+
accessorDef.sparse.count * itemSizeIndices
|
|
2797
|
+
);
|
|
2798
|
+
const sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
|
|
2799
|
+
if (bufferView !== null) {
|
|
2800
|
+
bufferAttribute = new BufferAttribute2(
|
|
2801
|
+
bufferAttribute.array.slice(),
|
|
2802
|
+
bufferAttribute.itemSize,
|
|
2803
|
+
bufferAttribute.normalized
|
|
2804
|
+
);
|
|
2805
|
+
}
|
|
2806
|
+
for (let i = 0, il = sparseIndices.length; i < il; i++) {
|
|
2807
|
+
const index = sparseIndices[i];
|
|
2808
|
+
bufferAttribute.setX(index, sparseValues[i * itemSize]);
|
|
2809
|
+
if (itemSize >= 2)
|
|
2810
|
+
bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
|
|
2811
|
+
if (itemSize >= 3)
|
|
2812
|
+
bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
|
|
2813
|
+
if (itemSize >= 4)
|
|
2814
|
+
bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
|
|
2815
|
+
if (itemSize >= 5)
|
|
2816
|
+
throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
return bufferAttribute;
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
/**
|
|
2823
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
|
2824
|
+
* @param {number} textureIndex
|
|
2825
|
+
* @return {Promise<THREE.Texture|null>}
|
|
2826
|
+
*/
|
|
2827
|
+
loadTexture(textureIndex) {
|
|
2828
|
+
const json = this.json;
|
|
2829
|
+
const options = this.options;
|
|
2830
|
+
const textureDef = json.textures[textureIndex];
|
|
2831
|
+
const sourceIndex = textureDef.source;
|
|
2832
|
+
const sourceDef = json.images[sourceIndex];
|
|
2833
|
+
let loader = this.textureLoader;
|
|
2834
|
+
if (sourceDef.uri) {
|
|
2835
|
+
const handler = options.manager.getHandler(sourceDef.uri);
|
|
2836
|
+
if (handler !== null)
|
|
2837
|
+
loader = handler;
|
|
2838
|
+
}
|
|
2839
|
+
return this.loadTextureImage(textureIndex, sourceIndex, loader);
|
|
2840
|
+
}
|
|
2841
|
+
loadTextureImage(textureIndex, sourceIndex, loader) {
|
|
2842
|
+
const parser = this;
|
|
2843
|
+
const json = this.json;
|
|
2844
|
+
const textureDef = json.textures[textureIndex];
|
|
2845
|
+
const sourceDef = json.images[sourceIndex];
|
|
2846
|
+
const cacheKey = (sourceDef.uri || sourceDef.bufferView) + ":" + textureDef.sampler;
|
|
2847
|
+
if (this.textureCache[cacheKey]) {
|
|
2848
|
+
return this.textureCache[cacheKey];
|
|
2849
|
+
}
|
|
2850
|
+
const promise = this.loadImageSource(sourceIndex, loader).then(function(texture) {
|
|
2851
|
+
texture.flipY = false;
|
|
2852
|
+
texture.name = textureDef.name || sourceDef.name || "";
|
|
2853
|
+
if (texture.name === "" && typeof sourceDef.uri === "string" && sourceDef.uri.startsWith("data:image/") === false) {
|
|
2854
|
+
texture.name = sourceDef.uri;
|
|
2855
|
+
}
|
|
2856
|
+
const samplers = json.samplers || {};
|
|
2857
|
+
const sampler = samplers[textureDef.sampler] || {};
|
|
2858
|
+
texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || LinearFilter;
|
|
2859
|
+
texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || LinearMipmapLinearFilter;
|
|
2860
|
+
texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || RepeatWrapping;
|
|
2861
|
+
texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || RepeatWrapping;
|
|
2862
|
+
parser.associations.set(texture, { textures: textureIndex });
|
|
2863
|
+
return texture;
|
|
2864
|
+
}).catch(function() {
|
|
2865
|
+
return null;
|
|
2866
|
+
});
|
|
2867
|
+
this.textureCache[cacheKey] = promise;
|
|
2868
|
+
return promise;
|
|
2869
|
+
}
|
|
2870
|
+
loadImageSource(sourceIndex, loader) {
|
|
2871
|
+
const parser = this;
|
|
2872
|
+
const json = this.json;
|
|
2873
|
+
const options = this.options;
|
|
2874
|
+
if (this.sourceCache[sourceIndex] !== void 0) {
|
|
2875
|
+
return this.sourceCache[sourceIndex].then((texture) => texture.clone());
|
|
2876
|
+
}
|
|
2877
|
+
const sourceDef = json.images[sourceIndex];
|
|
2878
|
+
const URL2 = self.URL || self.webkitURL;
|
|
2879
|
+
let sourceURI = sourceDef.uri || "";
|
|
2880
|
+
let isObjectURL = false;
|
|
2881
|
+
if (sourceDef.bufferView !== void 0) {
|
|
2882
|
+
sourceURI = parser.getDependency("bufferView", sourceDef.bufferView).then(function(bufferView) {
|
|
2883
|
+
isObjectURL = true;
|
|
2884
|
+
const blob = new Blob([bufferView], { type: sourceDef.mimeType });
|
|
2885
|
+
sourceURI = URL2.createObjectURL(blob);
|
|
2886
|
+
return sourceURI;
|
|
2887
|
+
});
|
|
2888
|
+
} else if (sourceDef.uri === void 0) {
|
|
2889
|
+
throw new Error("THREE.GLTFLoader: Image " + sourceIndex + " is missing URI and bufferView");
|
|
2890
|
+
}
|
|
2891
|
+
const promise = Promise.resolve(sourceURI).then(function(sourceURI2) {
|
|
2892
|
+
return new Promise(function(resolve, reject) {
|
|
2893
|
+
let onLoad = resolve;
|
|
2894
|
+
if (loader.isImageBitmapLoader === true) {
|
|
2895
|
+
onLoad = function(imageBitmap) {
|
|
2896
|
+
const texture = new Texture(imageBitmap);
|
|
2897
|
+
texture.needsUpdate = true;
|
|
2898
|
+
resolve(texture);
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
loader.load(LoaderUtils.resolveURL(sourceURI2, options.path), onLoad, void 0, reject);
|
|
2902
|
+
});
|
|
2903
|
+
}).then(function(texture) {
|
|
2904
|
+
if (isObjectURL === true) {
|
|
2905
|
+
URL2.revokeObjectURL(sourceURI);
|
|
2906
|
+
}
|
|
2907
|
+
assignExtrasToUserData(texture, sourceDef);
|
|
2908
|
+
texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType(sourceDef.uri);
|
|
2909
|
+
return texture;
|
|
2910
|
+
}).catch(function(error) {
|
|
2911
|
+
console.error("THREE.GLTFLoader: Couldn't load texture", sourceURI);
|
|
2912
|
+
throw error;
|
|
2913
|
+
});
|
|
2914
|
+
this.sourceCache[sourceIndex] = promise;
|
|
2915
|
+
return promise;
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* Asynchronously assigns a texture to the given material parameters.
|
|
2919
|
+
* @param {Object} materialParams
|
|
2920
|
+
* @param {string} mapName
|
|
2921
|
+
* @param {Object} mapDef
|
|
2922
|
+
* @return {Promise<Texture>}
|
|
2923
|
+
*/
|
|
2924
|
+
assignTexture(materialParams, mapName, mapDef, colorSpace) {
|
|
2925
|
+
const parser = this;
|
|
2926
|
+
return this.getDependency("texture", mapDef.index).then(function(texture) {
|
|
2927
|
+
if (!texture)
|
|
2928
|
+
return null;
|
|
2929
|
+
if (mapDef.texCoord !== void 0 && mapDef.texCoord > 0) {
|
|
2930
|
+
texture = texture.clone();
|
|
2931
|
+
texture.channel = mapDef.texCoord;
|
|
2932
|
+
}
|
|
2933
|
+
if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
|
|
2934
|
+
const transform = mapDef.extensions !== void 0 ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : void 0;
|
|
2935
|
+
if (transform) {
|
|
2936
|
+
const gltfReference = parser.associations.get(texture);
|
|
2937
|
+
texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
|
|
2938
|
+
parser.associations.set(texture, gltfReference);
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
if (colorSpace !== void 0) {
|
|
2942
|
+
if (typeof colorSpace === "number")
|
|
2943
|
+
colorSpace = colorSpace === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
|
|
2944
|
+
if ("colorSpace" in texture)
|
|
2945
|
+
texture.colorSpace = colorSpace;
|
|
2946
|
+
else
|
|
2947
|
+
texture.encoding = colorSpace === SRGBColorSpace ? sRGBEncoding : LinearEncoding;
|
|
2948
|
+
}
|
|
2949
|
+
materialParams[mapName] = texture;
|
|
2950
|
+
return texture;
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
/**
|
|
2954
|
+
* Assigns final material to a Mesh, Line, or Points instance. The instance
|
|
2955
|
+
* already has a material (generated from the glTF material options alone)
|
|
2956
|
+
* but reuse of the same glTF material may require multiple threejs materials
|
|
2957
|
+
* to accommodate different primitive types, defines, etc. New materials will
|
|
2958
|
+
* be created if necessary, and reused from a cache.
|
|
2959
|
+
* @param {Object3D} mesh Mesh, Line, or Points instance.
|
|
2960
|
+
*/
|
|
2961
|
+
assignFinalMaterial(mesh) {
|
|
2962
|
+
const geometry = mesh.geometry;
|
|
2963
|
+
let material = mesh.material;
|
|
2964
|
+
const useDerivativeTangents = geometry.attributes.tangent === void 0;
|
|
2965
|
+
const useVertexColors = geometry.attributes.color !== void 0;
|
|
2966
|
+
const useFlatShading = geometry.attributes.normal === void 0;
|
|
2967
|
+
if (mesh.isPoints) {
|
|
2968
|
+
const cacheKey = "PointsMaterial:" + material.uuid;
|
|
2969
|
+
let pointsMaterial = this.cache.get(cacheKey);
|
|
2970
|
+
if (!pointsMaterial) {
|
|
2971
|
+
pointsMaterial = new PointsMaterial();
|
|
2972
|
+
Material.prototype.copy.call(pointsMaterial, material);
|
|
2973
|
+
pointsMaterial.color.copy(material.color);
|
|
2974
|
+
pointsMaterial.map = material.map;
|
|
2975
|
+
pointsMaterial.sizeAttenuation = false;
|
|
2976
|
+
this.cache.add(cacheKey, pointsMaterial);
|
|
2977
|
+
}
|
|
2978
|
+
material = pointsMaterial;
|
|
2979
|
+
} else if (mesh.isLine) {
|
|
2980
|
+
const cacheKey = "LineBasicMaterial:" + material.uuid;
|
|
2981
|
+
let lineMaterial = this.cache.get(cacheKey);
|
|
2982
|
+
if (!lineMaterial) {
|
|
2983
|
+
lineMaterial = new LineBasicMaterial();
|
|
2984
|
+
Material.prototype.copy.call(lineMaterial, material);
|
|
2985
|
+
lineMaterial.color.copy(material.color);
|
|
2986
|
+
lineMaterial.map = material.map;
|
|
2987
|
+
this.cache.add(cacheKey, lineMaterial);
|
|
2988
|
+
}
|
|
2989
|
+
material = lineMaterial;
|
|
2990
|
+
}
|
|
2991
|
+
if (useDerivativeTangents || useVertexColors || useFlatShading) {
|
|
2992
|
+
let cacheKey = "ClonedMaterial:" + material.uuid + ":";
|
|
2993
|
+
if (useDerivativeTangents)
|
|
2994
|
+
cacheKey += "derivative-tangents:";
|
|
2995
|
+
if (useVertexColors)
|
|
2996
|
+
cacheKey += "vertex-colors:";
|
|
2997
|
+
if (useFlatShading)
|
|
2998
|
+
cacheKey += "flat-shading:";
|
|
2999
|
+
let cachedMaterial = this.cache.get(cacheKey);
|
|
3000
|
+
if (!cachedMaterial) {
|
|
3001
|
+
cachedMaterial = material.clone();
|
|
3002
|
+
if (useVertexColors)
|
|
3003
|
+
cachedMaterial.vertexColors = true;
|
|
3004
|
+
if (useFlatShading)
|
|
3005
|
+
cachedMaterial.flatShading = true;
|
|
3006
|
+
if (useDerivativeTangents) {
|
|
3007
|
+
if (cachedMaterial.normalScale)
|
|
3008
|
+
cachedMaterial.normalScale.y *= -1;
|
|
3009
|
+
if (cachedMaterial.clearcoatNormalScale)
|
|
3010
|
+
cachedMaterial.clearcoatNormalScale.y *= -1;
|
|
3011
|
+
}
|
|
3012
|
+
this.cache.add(cacheKey, cachedMaterial);
|
|
3013
|
+
this.associations.set(cachedMaterial, this.associations.get(material));
|
|
3014
|
+
}
|
|
3015
|
+
material = cachedMaterial;
|
|
3016
|
+
}
|
|
3017
|
+
mesh.material = material;
|
|
3018
|
+
}
|
|
3019
|
+
getMaterialType() {
|
|
3020
|
+
return MeshStandardMaterial;
|
|
3021
|
+
}
|
|
3022
|
+
/**
|
|
3023
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
|
3024
|
+
* @param {number} materialIndex
|
|
3025
|
+
* @return {Promise<Material>}
|
|
3026
|
+
*/
|
|
3027
|
+
loadMaterial(materialIndex) {
|
|
3028
|
+
const parser = this;
|
|
3029
|
+
const json = this.json;
|
|
3030
|
+
const extensions2 = this.extensions;
|
|
3031
|
+
const materialDef = json.materials[materialIndex];
|
|
3032
|
+
let materialType;
|
|
3033
|
+
const materialParams = {};
|
|
3034
|
+
const materialExtensions = materialDef.extensions || {};
|
|
3035
|
+
const pending = [];
|
|
3036
|
+
if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
|
|
3037
|
+
const kmuExtension = extensions2[EXTENSIONS.KHR_MATERIALS_UNLIT];
|
|
3038
|
+
materialType = kmuExtension.getMaterialType();
|
|
3039
|
+
pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
|
|
3040
|
+
} else {
|
|
3041
|
+
const metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
|
3042
|
+
materialParams.color = new Color(1, 1, 1);
|
|
3043
|
+
materialParams.opacity = 1;
|
|
3044
|
+
if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
|
3045
|
+
const array = metallicRoughness.baseColorFactor;
|
|
3046
|
+
materialParams.color.setRGB(array[0], array[1], array[2], LinearSRGBColorSpace);
|
|
3047
|
+
materialParams.opacity = array[3];
|
|
3048
|
+
}
|
|
3049
|
+
if (metallicRoughness.baseColorTexture !== void 0) {
|
|
3050
|
+
pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
|
|
3051
|
+
}
|
|
3052
|
+
materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
|
|
3053
|
+
materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
|
|
3054
|
+
if (metallicRoughness.metallicRoughnessTexture !== void 0) {
|
|
3055
|
+
pending.push(parser.assignTexture(materialParams, "metalnessMap", metallicRoughness.metallicRoughnessTexture));
|
|
3056
|
+
pending.push(parser.assignTexture(materialParams, "roughnessMap", metallicRoughness.metallicRoughnessTexture));
|
|
3057
|
+
}
|
|
3058
|
+
materialType = this._invokeOne(function(ext) {
|
|
3059
|
+
return ext.getMaterialType && ext.getMaterialType(materialIndex);
|
|
3060
|
+
});
|
|
3061
|
+
pending.push(
|
|
3062
|
+
Promise.all(
|
|
3063
|
+
this._invokeAll(function(ext) {
|
|
3064
|
+
return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
|
|
3065
|
+
})
|
|
3066
|
+
)
|
|
3067
|
+
);
|
|
3068
|
+
}
|
|
3069
|
+
if (materialDef.doubleSided === true) {
|
|
3070
|
+
materialParams.side = DoubleSide;
|
|
3071
|
+
}
|
|
3072
|
+
const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
|
3073
|
+
if (alphaMode === ALPHA_MODES.BLEND) {
|
|
3074
|
+
materialParams.transparent = true;
|
|
3075
|
+
materialParams.depthWrite = false;
|
|
3076
|
+
} else {
|
|
3077
|
+
materialParams.transparent = false;
|
|
3078
|
+
if (alphaMode === ALPHA_MODES.MASK) {
|
|
3079
|
+
materialParams.alphaTest = materialDef.alphaCutoff !== void 0 ? materialDef.alphaCutoff : 0.5;
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
if (materialDef.normalTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
3083
|
+
pending.push(parser.assignTexture(materialParams, "normalMap", materialDef.normalTexture));
|
|
3084
|
+
materialParams.normalScale = new Vector22(1, 1);
|
|
3085
|
+
if (materialDef.normalTexture.scale !== void 0) {
|
|
3086
|
+
const scale = materialDef.normalTexture.scale;
|
|
3087
|
+
materialParams.normalScale.set(scale, scale);
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
if (materialDef.occlusionTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
3091
|
+
pending.push(parser.assignTexture(materialParams, "aoMap", materialDef.occlusionTexture));
|
|
3092
|
+
if (materialDef.occlusionTexture.strength !== void 0) {
|
|
3093
|
+
materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
if (materialDef.emissiveFactor !== void 0 && materialType !== MeshBasicMaterial) {
|
|
3097
|
+
const emissiveFactor = materialDef.emissiveFactor;
|
|
3098
|
+
materialParams.emissive = new Color().setRGB(
|
|
3099
|
+
emissiveFactor[0],
|
|
3100
|
+
emissiveFactor[1],
|
|
3101
|
+
emissiveFactor[2],
|
|
3102
|
+
LinearSRGBColorSpace
|
|
3103
|
+
);
|
|
3104
|
+
}
|
|
3105
|
+
if (materialDef.emissiveTexture !== void 0 && materialType !== MeshBasicMaterial) {
|
|
3106
|
+
pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, SRGBColorSpace));
|
|
3107
|
+
}
|
|
3108
|
+
return Promise.all(pending).then(function() {
|
|
3109
|
+
const material = new materialType(materialParams);
|
|
3110
|
+
if (materialDef.name)
|
|
3111
|
+
material.name = materialDef.name;
|
|
3112
|
+
assignExtrasToUserData(material, materialDef);
|
|
3113
|
+
parser.associations.set(material, { materials: materialIndex });
|
|
3114
|
+
if (materialDef.extensions)
|
|
3115
|
+
addUnknownExtensionsToUserData(extensions2, material, materialDef);
|
|
3116
|
+
return material;
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
/** When Object3D instances are targeted by animation, they need unique names. */
|
|
3120
|
+
createUniqueName(originalName) {
|
|
3121
|
+
const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || "");
|
|
3122
|
+
if (sanitizedName in this.nodeNamesUsed) {
|
|
3123
|
+
return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
|
|
3124
|
+
} else {
|
|
3125
|
+
this.nodeNamesUsed[sanitizedName] = 0;
|
|
3126
|
+
return sanitizedName;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
/**
|
|
3130
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
|
3131
|
+
*
|
|
3132
|
+
* Creates BufferGeometries from primitives.
|
|
3133
|
+
*
|
|
3134
|
+
* @param {Array<GLTF.Primitive>} primitives
|
|
3135
|
+
* @return {Promise<Array<BufferGeometry>>}
|
|
3136
|
+
*/
|
|
3137
|
+
loadGeometries(primitives) {
|
|
3138
|
+
const parser = this;
|
|
3139
|
+
const extensions2 = this.extensions;
|
|
3140
|
+
const cache = this.primitiveCache;
|
|
3141
|
+
function createDracoPrimitive(primitive) {
|
|
3142
|
+
return extensions2[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function(geometry) {
|
|
3143
|
+
return addPrimitiveAttributes(geometry, primitive, parser);
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
const pending = [];
|
|
3147
|
+
for (let i = 0, il = primitives.length; i < il; i++) {
|
|
3148
|
+
const primitive = primitives[i];
|
|
3149
|
+
const cacheKey = createPrimitiveKey(primitive);
|
|
3150
|
+
const cached = cache[cacheKey];
|
|
3151
|
+
if (cached) {
|
|
3152
|
+
pending.push(cached.promise);
|
|
3153
|
+
} else {
|
|
3154
|
+
let geometryPromise;
|
|
3155
|
+
if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
|
|
3156
|
+
geometryPromise = createDracoPrimitive(primitive);
|
|
3157
|
+
} else {
|
|
3158
|
+
geometryPromise = addPrimitiveAttributes(new BufferGeometry2(), primitive, parser);
|
|
3159
|
+
}
|
|
3160
|
+
cache[cacheKey] = { primitive, promise: geometryPromise };
|
|
3161
|
+
pending.push(geometryPromise);
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
return Promise.all(pending);
|
|
3165
|
+
}
|
|
3166
|
+
/**
|
|
3167
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
|
3168
|
+
* @param {number} meshIndex
|
|
3169
|
+
* @return {Promise<Group|Mesh|SkinnedMesh>}
|
|
3170
|
+
*/
|
|
3171
|
+
loadMesh(meshIndex) {
|
|
3172
|
+
const parser = this;
|
|
3173
|
+
const json = this.json;
|
|
3174
|
+
const extensions2 = this.extensions;
|
|
3175
|
+
const meshDef = json.meshes[meshIndex];
|
|
3176
|
+
const primitives = meshDef.primitives;
|
|
3177
|
+
const pending = [];
|
|
3178
|
+
for (let i = 0, il = primitives.length; i < il; i++) {
|
|
3179
|
+
const material = primitives[i].material === void 0 ? createDefaultMaterial(this.cache) : this.getDependency("material", primitives[i].material);
|
|
3180
|
+
pending.push(material);
|
|
3181
|
+
}
|
|
3182
|
+
pending.push(parser.loadGeometries(primitives));
|
|
3183
|
+
return Promise.all(pending).then(function(results) {
|
|
3184
|
+
const materials = results.slice(0, results.length - 1);
|
|
3185
|
+
const geometries = results[results.length - 1];
|
|
3186
|
+
const meshes = [];
|
|
3187
|
+
for (let i = 0, il = geometries.length; i < il; i++) {
|
|
3188
|
+
const geometry = geometries[i];
|
|
3189
|
+
const primitive = primitives[i];
|
|
3190
|
+
let mesh;
|
|
3191
|
+
const material = materials[i];
|
|
3192
|
+
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === void 0) {
|
|
3193
|
+
mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, material) : new Mesh(geometry, material);
|
|
3194
|
+
if (mesh.isSkinnedMesh === true) {
|
|
3195
|
+
mesh.normalizeSkinWeights();
|
|
3196
|
+
}
|
|
3197
|
+
if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
|
|
3198
|
+
mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleStripDrawMode2);
|
|
3199
|
+
} else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
|
|
3200
|
+
mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleFanDrawMode2);
|
|
3201
|
+
}
|
|
3202
|
+
} else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
|
|
3203
|
+
mesh = new LineSegments(geometry, material);
|
|
3204
|
+
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
|
|
3205
|
+
mesh = new Line(geometry, material);
|
|
3206
|
+
} else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
|
|
3207
|
+
mesh = new LineLoop(geometry, material);
|
|
3208
|
+
} else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
|
|
3209
|
+
mesh = new Points(geometry, material);
|
|
3210
|
+
} else {
|
|
3211
|
+
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + primitive.mode);
|
|
3212
|
+
}
|
|
3213
|
+
if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
|
|
3214
|
+
updateMorphTargets(mesh, meshDef);
|
|
3215
|
+
}
|
|
3216
|
+
mesh.name = parser.createUniqueName(meshDef.name || "mesh_" + meshIndex);
|
|
3217
|
+
assignExtrasToUserData(mesh, meshDef);
|
|
3218
|
+
if (primitive.extensions)
|
|
3219
|
+
addUnknownExtensionsToUserData(extensions2, mesh, primitive);
|
|
3220
|
+
parser.assignFinalMaterial(mesh);
|
|
3221
|
+
meshes.push(mesh);
|
|
3222
|
+
}
|
|
3223
|
+
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
3224
|
+
parser.associations.set(meshes[i], {
|
|
3225
|
+
meshes: meshIndex,
|
|
3226
|
+
primitives: i
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
if (meshes.length === 1) {
|
|
3230
|
+
if (meshDef.extensions)
|
|
3231
|
+
addUnknownExtensionsToUserData(extensions2, meshes[0], meshDef);
|
|
3232
|
+
return meshes[0];
|
|
3233
|
+
}
|
|
3234
|
+
const group = new Group();
|
|
3235
|
+
if (meshDef.extensions)
|
|
3236
|
+
addUnknownExtensionsToUserData(extensions2, group, meshDef);
|
|
3237
|
+
parser.associations.set(group, { meshes: meshIndex });
|
|
3238
|
+
for (let i = 0, il = meshes.length; i < il; i++) {
|
|
3239
|
+
group.add(meshes[i]);
|
|
3240
|
+
}
|
|
3241
|
+
return group;
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
/**
|
|
3245
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
|
3246
|
+
* @param {number} cameraIndex
|
|
3247
|
+
* @return {Promise<THREE.Camera>}
|
|
3248
|
+
*/
|
|
3249
|
+
loadCamera(cameraIndex) {
|
|
3250
|
+
let camera;
|
|
3251
|
+
const cameraDef = this.json.cameras[cameraIndex];
|
|
3252
|
+
const params = cameraDef[cameraDef.type];
|
|
3253
|
+
if (!params) {
|
|
3254
|
+
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
3255
|
+
return;
|
|
3256
|
+
}
|
|
3257
|
+
if (cameraDef.type === "perspective") {
|
|
3258
|
+
camera = new PerspectiveCamera2(
|
|
3259
|
+
MathUtils.radToDeg(params.yfov),
|
|
3260
|
+
params.aspectRatio || 1,
|
|
3261
|
+
params.znear || 1,
|
|
3262
|
+
params.zfar || 2e6
|
|
3263
|
+
);
|
|
3264
|
+
} else if (cameraDef.type === "orthographic") {
|
|
3265
|
+
camera = new OrthographicCamera2(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
|
|
3266
|
+
}
|
|
3267
|
+
if (cameraDef.name)
|
|
3268
|
+
camera.name = this.createUniqueName(cameraDef.name);
|
|
3269
|
+
assignExtrasToUserData(camera, cameraDef);
|
|
3270
|
+
return Promise.resolve(camera);
|
|
3271
|
+
}
|
|
3272
|
+
/**
|
|
3273
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
|
3274
|
+
* @param {number} skinIndex
|
|
3275
|
+
* @return {Promise<Skeleton>}
|
|
3276
|
+
*/
|
|
3277
|
+
loadSkin(skinIndex) {
|
|
3278
|
+
const skinDef = this.json.skins[skinIndex];
|
|
3279
|
+
const pending = [];
|
|
3280
|
+
for (let i = 0, il = skinDef.joints.length; i < il; i++) {
|
|
3281
|
+
pending.push(this._loadNodeShallow(skinDef.joints[i]));
|
|
3282
|
+
}
|
|
3283
|
+
if (skinDef.inverseBindMatrices !== void 0) {
|
|
3284
|
+
pending.push(this.getDependency("accessor", skinDef.inverseBindMatrices));
|
|
3285
|
+
} else {
|
|
3286
|
+
pending.push(null);
|
|
3287
|
+
}
|
|
3288
|
+
return Promise.all(pending).then(function(results) {
|
|
3289
|
+
const inverseBindMatrices = results.pop();
|
|
3290
|
+
const jointNodes = results;
|
|
3291
|
+
const bones = [];
|
|
3292
|
+
const boneInverses = [];
|
|
3293
|
+
for (let i = 0, il = jointNodes.length; i < il; i++) {
|
|
3294
|
+
const jointNode = jointNodes[i];
|
|
3295
|
+
if (jointNode) {
|
|
3296
|
+
bones.push(jointNode);
|
|
3297
|
+
const mat = new Matrix4();
|
|
3298
|
+
if (inverseBindMatrices !== null) {
|
|
3299
|
+
mat.fromArray(inverseBindMatrices.array, i * 16);
|
|
3300
|
+
}
|
|
3301
|
+
boneInverses.push(mat);
|
|
3302
|
+
} else {
|
|
3303
|
+
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[i]);
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
return new Skeleton(bones, boneInverses);
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
/**
|
|
3310
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
3311
|
+
* @param {number} animationIndex
|
|
3312
|
+
* @return {Promise<AnimationClip>}
|
|
3313
|
+
*/
|
|
3314
|
+
loadAnimation(animationIndex) {
|
|
3315
|
+
const json = this.json;
|
|
3316
|
+
const parser = this;
|
|
3317
|
+
const animationDef = json.animations[animationIndex];
|
|
3318
|
+
const animationName = animationDef.name ? animationDef.name : "animation_" + animationIndex;
|
|
3319
|
+
const pendingNodes = [];
|
|
3320
|
+
const pendingInputAccessors = [];
|
|
3321
|
+
const pendingOutputAccessors = [];
|
|
3322
|
+
const pendingSamplers = [];
|
|
3323
|
+
const pendingTargets = [];
|
|
3324
|
+
for (let i = 0, il = animationDef.channels.length; i < il; i++) {
|
|
3325
|
+
const channel = animationDef.channels[i];
|
|
3326
|
+
const sampler = animationDef.samplers[channel.sampler];
|
|
3327
|
+
const target = channel.target;
|
|
3328
|
+
const name = target.node;
|
|
3329
|
+
const input = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.input] : sampler.input;
|
|
3330
|
+
const output = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.output] : sampler.output;
|
|
3331
|
+
if (target.node === void 0)
|
|
3332
|
+
continue;
|
|
3333
|
+
pendingNodes.push(this.getDependency("node", name));
|
|
3334
|
+
pendingInputAccessors.push(this.getDependency("accessor", input));
|
|
3335
|
+
pendingOutputAccessors.push(this.getDependency("accessor", output));
|
|
3336
|
+
pendingSamplers.push(sampler);
|
|
3337
|
+
pendingTargets.push(target);
|
|
3338
|
+
}
|
|
3339
|
+
return Promise.all([
|
|
3340
|
+
Promise.all(pendingNodes),
|
|
3341
|
+
Promise.all(pendingInputAccessors),
|
|
3342
|
+
Promise.all(pendingOutputAccessors),
|
|
3343
|
+
Promise.all(pendingSamplers),
|
|
3344
|
+
Promise.all(pendingTargets)
|
|
3345
|
+
]).then(function(dependencies) {
|
|
3346
|
+
const nodes = dependencies[0];
|
|
3347
|
+
const inputAccessors = dependencies[1];
|
|
3348
|
+
const outputAccessors = dependencies[2];
|
|
3349
|
+
const samplers = dependencies[3];
|
|
3350
|
+
const targets = dependencies[4];
|
|
3351
|
+
const tracks = [];
|
|
3352
|
+
for (let i = 0, il = nodes.length; i < il; i++) {
|
|
3353
|
+
const node = nodes[i];
|
|
3354
|
+
const inputAccessor = inputAccessors[i];
|
|
3355
|
+
const outputAccessor = outputAccessors[i];
|
|
3356
|
+
const sampler = samplers[i];
|
|
3357
|
+
const target = targets[i];
|
|
3358
|
+
if (node === void 0)
|
|
3359
|
+
continue;
|
|
3360
|
+
if (node.updateMatrix) {
|
|
3361
|
+
node.updateMatrix();
|
|
3362
|
+
}
|
|
3363
|
+
const createdTracks = parser._createAnimationTracks(node, inputAccessor, outputAccessor, sampler, target);
|
|
3364
|
+
if (createdTracks) {
|
|
3365
|
+
for (let k = 0; k < createdTracks.length; k++) {
|
|
3366
|
+
tracks.push(createdTracks[k]);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
return new AnimationClip(animationName, void 0, tracks);
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
createNodeMesh(nodeIndex) {
|
|
3374
|
+
const json = this.json;
|
|
3375
|
+
const parser = this;
|
|
3376
|
+
const nodeDef = json.nodes[nodeIndex];
|
|
3377
|
+
if (nodeDef.mesh === void 0)
|
|
3378
|
+
return null;
|
|
3379
|
+
return parser.getDependency("mesh", nodeDef.mesh).then(function(mesh) {
|
|
3380
|
+
const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh);
|
|
3381
|
+
if (nodeDef.weights !== void 0) {
|
|
3382
|
+
node.traverse(function(o) {
|
|
3383
|
+
if (!o.isMesh)
|
|
3384
|
+
return;
|
|
3385
|
+
for (let i = 0, il = nodeDef.weights.length; i < il; i++) {
|
|
3386
|
+
o.morphTargetInfluences[i] = nodeDef.weights[i];
|
|
3387
|
+
}
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
return node;
|
|
3391
|
+
});
|
|
3392
|
+
}
|
|
3393
|
+
/**
|
|
3394
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
|
3395
|
+
* @param {number} nodeIndex
|
|
3396
|
+
* @return {Promise<Object3D>}
|
|
3397
|
+
*/
|
|
3398
|
+
loadNode(nodeIndex) {
|
|
3399
|
+
const json = this.json;
|
|
3400
|
+
const parser = this;
|
|
3401
|
+
const nodeDef = json.nodes[nodeIndex];
|
|
3402
|
+
const nodePending = parser._loadNodeShallow(nodeIndex);
|
|
3403
|
+
const childPending = [];
|
|
3404
|
+
const childrenDef = nodeDef.children || [];
|
|
3405
|
+
for (let i = 0, il = childrenDef.length; i < il; i++) {
|
|
3406
|
+
childPending.push(parser.getDependency("node", childrenDef[i]));
|
|
3407
|
+
}
|
|
3408
|
+
const skeletonPending = nodeDef.skin === void 0 ? Promise.resolve(null) : parser.getDependency("skin", nodeDef.skin);
|
|
3409
|
+
return Promise.all([nodePending, Promise.all(childPending), skeletonPending]).then(function(results) {
|
|
3410
|
+
const node = results[0];
|
|
3411
|
+
const children = results[1];
|
|
3412
|
+
const skeleton = results[2];
|
|
3413
|
+
if (skeleton !== null) {
|
|
3414
|
+
node.traverse(function(mesh) {
|
|
3415
|
+
if (!mesh.isSkinnedMesh)
|
|
3416
|
+
return;
|
|
3417
|
+
mesh.bind(skeleton, _identityMatrix);
|
|
3418
|
+
});
|
|
3419
|
+
}
|
|
3420
|
+
for (let i = 0, il = children.length; i < il; i++) {
|
|
3421
|
+
node.add(children[i]);
|
|
3422
|
+
}
|
|
3423
|
+
return node;
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
// ._loadNodeShallow() parses a single node.
|
|
3427
|
+
// skin and child nodes are created and added in .loadNode() (no '_' prefix).
|
|
3428
|
+
_loadNodeShallow(nodeIndex) {
|
|
3429
|
+
const json = this.json;
|
|
3430
|
+
const extensions2 = this.extensions;
|
|
3431
|
+
const parser = this;
|
|
3432
|
+
if (this.nodeCache[nodeIndex] !== void 0) {
|
|
3433
|
+
return this.nodeCache[nodeIndex];
|
|
3434
|
+
}
|
|
3435
|
+
const nodeDef = json.nodes[nodeIndex];
|
|
3436
|
+
const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : "";
|
|
3437
|
+
const pending = [];
|
|
3438
|
+
const meshPromise = parser._invokeOne(function(ext) {
|
|
3439
|
+
return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
|
|
3440
|
+
});
|
|
3441
|
+
if (meshPromise) {
|
|
3442
|
+
pending.push(meshPromise);
|
|
3443
|
+
}
|
|
3444
|
+
if (nodeDef.camera !== void 0) {
|
|
3445
|
+
pending.push(
|
|
3446
|
+
parser.getDependency("camera", nodeDef.camera).then(function(camera) {
|
|
3447
|
+
return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
|
|
3448
|
+
})
|
|
3449
|
+
);
|
|
3450
|
+
}
|
|
3451
|
+
parser._invokeAll(function(ext) {
|
|
3452
|
+
return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
|
|
3453
|
+
}).forEach(function(promise) {
|
|
3454
|
+
pending.push(promise);
|
|
3455
|
+
});
|
|
3456
|
+
this.nodeCache[nodeIndex] = Promise.all(pending).then(function(objects) {
|
|
3457
|
+
let node;
|
|
3458
|
+
if (nodeDef.isBone === true) {
|
|
3459
|
+
node = new Bone();
|
|
3460
|
+
} else if (objects.length > 1) {
|
|
3461
|
+
node = new Group();
|
|
3462
|
+
} else if (objects.length === 1) {
|
|
3463
|
+
node = objects[0];
|
|
3464
|
+
} else {
|
|
3465
|
+
node = new Object3D();
|
|
3466
|
+
}
|
|
3467
|
+
if (node !== objects[0]) {
|
|
3468
|
+
for (let i = 0, il = objects.length; i < il; i++) {
|
|
3469
|
+
node.add(objects[i]);
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
if (nodeDef.name) {
|
|
3473
|
+
node.userData.name = nodeDef.name;
|
|
3474
|
+
node.name = nodeName;
|
|
3475
|
+
}
|
|
3476
|
+
assignExtrasToUserData(node, nodeDef);
|
|
3477
|
+
if (nodeDef.extensions)
|
|
3478
|
+
addUnknownExtensionsToUserData(extensions2, node, nodeDef);
|
|
3479
|
+
if (nodeDef.matrix !== void 0) {
|
|
3480
|
+
const matrix = new Matrix4();
|
|
3481
|
+
matrix.fromArray(nodeDef.matrix);
|
|
3482
|
+
node.applyMatrix4(matrix);
|
|
3483
|
+
} else {
|
|
3484
|
+
if (nodeDef.translation !== void 0) {
|
|
3485
|
+
node.position.fromArray(nodeDef.translation);
|
|
3486
|
+
}
|
|
3487
|
+
if (nodeDef.rotation !== void 0) {
|
|
3488
|
+
node.quaternion.fromArray(nodeDef.rotation);
|
|
3489
|
+
}
|
|
3490
|
+
if (nodeDef.scale !== void 0) {
|
|
3491
|
+
node.scale.fromArray(nodeDef.scale);
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
if (!parser.associations.has(node)) {
|
|
3495
|
+
parser.associations.set(node, {});
|
|
3496
|
+
}
|
|
3497
|
+
parser.associations.get(node).nodes = nodeIndex;
|
|
3498
|
+
return node;
|
|
3499
|
+
});
|
|
3500
|
+
return this.nodeCache[nodeIndex];
|
|
3501
|
+
}
|
|
3502
|
+
/**
|
|
3503
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
|
3504
|
+
* @param {number} sceneIndex
|
|
3505
|
+
* @return {Promise<Group>}
|
|
3506
|
+
*/
|
|
3507
|
+
loadScene(sceneIndex) {
|
|
3508
|
+
const extensions2 = this.extensions;
|
|
3509
|
+
const sceneDef = this.json.scenes[sceneIndex];
|
|
3510
|
+
const parser = this;
|
|
3511
|
+
const scene = new Group();
|
|
3512
|
+
if (sceneDef.name)
|
|
3513
|
+
scene.name = parser.createUniqueName(sceneDef.name);
|
|
3514
|
+
assignExtrasToUserData(scene, sceneDef);
|
|
3515
|
+
if (sceneDef.extensions)
|
|
3516
|
+
addUnknownExtensionsToUserData(extensions2, scene, sceneDef);
|
|
3517
|
+
const nodeIds = sceneDef.nodes || [];
|
|
3518
|
+
const pending = [];
|
|
3519
|
+
for (let i = 0, il = nodeIds.length; i < il; i++) {
|
|
3520
|
+
pending.push(parser.getDependency("node", nodeIds[i]));
|
|
3521
|
+
}
|
|
3522
|
+
return Promise.all(pending).then(function(nodes) {
|
|
3523
|
+
for (let i = 0, il = nodes.length; i < il; i++) {
|
|
3524
|
+
scene.add(nodes[i]);
|
|
3525
|
+
}
|
|
3526
|
+
const reduceAssociations = (node) => {
|
|
3527
|
+
const reducedAssociations = /* @__PURE__ */ new Map();
|
|
3528
|
+
for (const [key, value] of parser.associations) {
|
|
3529
|
+
if (key instanceof Material || key instanceof Texture) {
|
|
3530
|
+
reducedAssociations.set(key, value);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
node.traverse((node2) => {
|
|
3534
|
+
const mappings = parser.associations.get(node2);
|
|
3535
|
+
if (mappings != null) {
|
|
3536
|
+
reducedAssociations.set(node2, mappings);
|
|
3537
|
+
}
|
|
3538
|
+
});
|
|
3539
|
+
return reducedAssociations;
|
|
3540
|
+
};
|
|
3541
|
+
parser.associations = reduceAssociations(scene);
|
|
3542
|
+
return scene;
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
_createAnimationTracks(node, inputAccessor, outputAccessor, sampler, target) {
|
|
3546
|
+
const tracks = [];
|
|
3547
|
+
const targetName = node.name ? node.name : node.uuid;
|
|
3548
|
+
const targetNames = [];
|
|
3549
|
+
if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
|
|
3550
|
+
node.traverse(function(object) {
|
|
3551
|
+
if (object.morphTargetInfluences) {
|
|
3552
|
+
targetNames.push(object.name ? object.name : object.uuid);
|
|
3553
|
+
}
|
|
3554
|
+
});
|
|
3555
|
+
} else {
|
|
3556
|
+
targetNames.push(targetName);
|
|
3557
|
+
}
|
|
3558
|
+
let TypedKeyframeTrack;
|
|
3559
|
+
switch (PATH_PROPERTIES[target.path]) {
|
|
3560
|
+
case PATH_PROPERTIES.weights:
|
|
3561
|
+
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
3562
|
+
break;
|
|
3563
|
+
case PATH_PROPERTIES.rotation:
|
|
3564
|
+
TypedKeyframeTrack = QuaternionKeyframeTrack;
|
|
3565
|
+
break;
|
|
3566
|
+
case PATH_PROPERTIES.position:
|
|
3567
|
+
case PATH_PROPERTIES.scale:
|
|
3568
|
+
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
3569
|
+
break;
|
|
3570
|
+
default:
|
|
3571
|
+
switch (outputAccessor.itemSize) {
|
|
3572
|
+
case 1:
|
|
3573
|
+
TypedKeyframeTrack = NumberKeyframeTrack;
|
|
3574
|
+
break;
|
|
3575
|
+
case 2:
|
|
3576
|
+
case 3:
|
|
3577
|
+
default:
|
|
3578
|
+
TypedKeyframeTrack = VectorKeyframeTrack;
|
|
3579
|
+
break;
|
|
3580
|
+
}
|
|
3581
|
+
break;
|
|
3582
|
+
}
|
|
3583
|
+
const interpolation = sampler.interpolation !== void 0 ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
|
|
3584
|
+
const outputArray = this._getArrayFromAccessor(outputAccessor);
|
|
3585
|
+
for (let j = 0, jl = targetNames.length; j < jl; j++) {
|
|
3586
|
+
const track = new TypedKeyframeTrack(
|
|
3587
|
+
targetNames[j] + "." + PATH_PROPERTIES[target.path],
|
|
3588
|
+
inputAccessor.array,
|
|
3589
|
+
outputArray,
|
|
3590
|
+
interpolation
|
|
3591
|
+
);
|
|
3592
|
+
if (sampler.interpolation === "CUBICSPLINE") {
|
|
3593
|
+
this._createCubicSplineTrackInterpolant(track);
|
|
3594
|
+
}
|
|
3595
|
+
tracks.push(track);
|
|
3596
|
+
}
|
|
3597
|
+
return tracks;
|
|
3598
|
+
}
|
|
3599
|
+
_getArrayFromAccessor(accessor) {
|
|
3600
|
+
let outputArray = accessor.array;
|
|
3601
|
+
if (accessor.normalized) {
|
|
3602
|
+
const scale = getNormalizedComponentScale(outputArray.constructor);
|
|
3603
|
+
const scaled = new Float32Array(outputArray.length);
|
|
3604
|
+
for (let j = 0, jl = outputArray.length; j < jl; j++) {
|
|
3605
|
+
scaled[j] = outputArray[j] * scale;
|
|
3606
|
+
}
|
|
3607
|
+
outputArray = scaled;
|
|
3608
|
+
}
|
|
3609
|
+
return outputArray;
|
|
3610
|
+
}
|
|
3611
|
+
_createCubicSplineTrackInterpolant(track) {
|
|
3612
|
+
track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
|
|
3613
|
+
const interpolantType = this instanceof QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
|
|
3614
|
+
return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
|
|
3615
|
+
};
|
|
3616
|
+
track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
|
3617
|
+
}
|
|
3618
|
+
};
|
|
3619
|
+
function computeBounds(geometry, primitiveDef, parser) {
|
|
3620
|
+
const attributes = primitiveDef.attributes;
|
|
3621
|
+
const box = new Box3();
|
|
3622
|
+
if (attributes.POSITION !== void 0) {
|
|
3623
|
+
const accessor = parser.json.accessors[attributes.POSITION];
|
|
3624
|
+
const min = accessor.min;
|
|
3625
|
+
const max = accessor.max;
|
|
3626
|
+
if (min !== void 0 && max !== void 0) {
|
|
3627
|
+
box.set(new Vector33(min[0], min[1], min[2]), new Vector33(max[0], max[1], max[2]));
|
|
3628
|
+
if (accessor.normalized) {
|
|
3629
|
+
const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
|
|
3630
|
+
box.min.multiplyScalar(boxScale);
|
|
3631
|
+
box.max.multiplyScalar(boxScale);
|
|
3632
|
+
}
|
|
3633
|
+
} else {
|
|
3634
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
3635
|
+
return;
|
|
3636
|
+
}
|
|
3637
|
+
} else {
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
const targets = primitiveDef.targets;
|
|
3641
|
+
if (targets !== void 0) {
|
|
3642
|
+
const maxDisplacement = new Vector33();
|
|
3643
|
+
const vector = new Vector33();
|
|
3644
|
+
for (let i = 0, il = targets.length; i < il; i++) {
|
|
3645
|
+
const target = targets[i];
|
|
3646
|
+
if (target.POSITION !== void 0) {
|
|
3647
|
+
const accessor = parser.json.accessors[target.POSITION];
|
|
3648
|
+
const min = accessor.min;
|
|
3649
|
+
const max = accessor.max;
|
|
3650
|
+
if (min !== void 0 && max !== void 0) {
|
|
3651
|
+
vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
|
|
3652
|
+
vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
|
|
3653
|
+
vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2])));
|
|
3654
|
+
if (accessor.normalized) {
|
|
3655
|
+
const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
|
|
3656
|
+
vector.multiplyScalar(boxScale);
|
|
3657
|
+
}
|
|
3658
|
+
maxDisplacement.max(vector);
|
|
3659
|
+
} else {
|
|
3660
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
box.expandByVector(maxDisplacement);
|
|
3665
|
+
}
|
|
3666
|
+
geometry.boundingBox = box;
|
|
3667
|
+
const sphere = new Sphere();
|
|
3668
|
+
box.getCenter(sphere.center);
|
|
3669
|
+
sphere.radius = box.min.distanceTo(box.max) / 2;
|
|
3670
|
+
geometry.boundingSphere = sphere;
|
|
3671
|
+
}
|
|
3672
|
+
function addPrimitiveAttributes(geometry, primitiveDef, parser) {
|
|
3673
|
+
const attributes = primitiveDef.attributes;
|
|
3674
|
+
const pending = [];
|
|
3675
|
+
function assignAttributeAccessor(accessorIndex, attributeName) {
|
|
3676
|
+
return parser.getDependency("accessor", accessorIndex).then(function(accessor) {
|
|
3677
|
+
geometry.setAttribute(attributeName, accessor);
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
for (const gltfAttributeName in attributes) {
|
|
3681
|
+
const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
|
|
3682
|
+
if (threeAttributeName in geometry.attributes)
|
|
3683
|
+
continue;
|
|
3684
|
+
pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
|
|
3685
|
+
}
|
|
3686
|
+
if (primitiveDef.indices !== void 0 && !geometry.index) {
|
|
3687
|
+
const accessor = parser.getDependency("accessor", primitiveDef.indices).then(function(accessor2) {
|
|
3688
|
+
geometry.setIndex(accessor2);
|
|
3689
|
+
});
|
|
3690
|
+
pending.push(accessor);
|
|
3691
|
+
}
|
|
3692
|
+
assignExtrasToUserData(geometry, primitiveDef);
|
|
3693
|
+
computeBounds(geometry, primitiveDef, parser);
|
|
3694
|
+
return Promise.all(pending).then(function() {
|
|
3695
|
+
return primitiveDef.targets !== void 0 ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
|
|
3696
|
+
});
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
// ../../node_modules/three-stdlib/loaders/DRACOLoader.js
|
|
3700
|
+
import { Loader as Loader2, FileLoader as FileLoader2, BufferGeometry as BufferGeometry3, BufferAttribute as BufferAttribute3 } from "three";
|
|
3701
|
+
var _taskCache = /* @__PURE__ */ new WeakMap();
|
|
3702
|
+
var DRACOLoader = class extends Loader2 {
|
|
3703
|
+
constructor(manager) {
|
|
3704
|
+
super(manager);
|
|
3705
|
+
this.decoderPath = "";
|
|
3706
|
+
this.decoderConfig = {};
|
|
3707
|
+
this.decoderBinary = null;
|
|
3708
|
+
this.decoderPending = null;
|
|
3709
|
+
this.workerLimit = 4;
|
|
3710
|
+
this.workerPool = [];
|
|
3711
|
+
this.workerNextTaskID = 1;
|
|
3712
|
+
this.workerSourceURL = "";
|
|
3713
|
+
this.defaultAttributeIDs = {
|
|
3714
|
+
position: "POSITION",
|
|
3715
|
+
normal: "NORMAL",
|
|
3716
|
+
color: "COLOR",
|
|
3717
|
+
uv: "TEX_COORD"
|
|
3718
|
+
};
|
|
3719
|
+
this.defaultAttributeTypes = {
|
|
3720
|
+
position: "Float32Array",
|
|
3721
|
+
normal: "Float32Array",
|
|
3722
|
+
color: "Float32Array",
|
|
3723
|
+
uv: "Float32Array"
|
|
3724
|
+
};
|
|
3725
|
+
}
|
|
3726
|
+
setDecoderPath(path) {
|
|
3727
|
+
this.decoderPath = path;
|
|
3728
|
+
return this;
|
|
3729
|
+
}
|
|
3730
|
+
setDecoderConfig(config) {
|
|
3731
|
+
this.decoderConfig = config;
|
|
3732
|
+
return this;
|
|
3733
|
+
}
|
|
3734
|
+
setWorkerLimit(workerLimit) {
|
|
3735
|
+
this.workerLimit = workerLimit;
|
|
3736
|
+
return this;
|
|
3737
|
+
}
|
|
3738
|
+
load(url, onLoad, onProgress, onError) {
|
|
3739
|
+
const loader = new FileLoader2(this.manager);
|
|
3740
|
+
loader.setPath(this.path);
|
|
3741
|
+
loader.setResponseType("arraybuffer");
|
|
3742
|
+
loader.setRequestHeader(this.requestHeader);
|
|
3743
|
+
loader.setWithCredentials(this.withCredentials);
|
|
3744
|
+
loader.load(
|
|
3745
|
+
url,
|
|
3746
|
+
(buffer) => {
|
|
3747
|
+
const taskConfig = {
|
|
3748
|
+
attributeIDs: this.defaultAttributeIDs,
|
|
3749
|
+
attributeTypes: this.defaultAttributeTypes,
|
|
3750
|
+
useUniqueIDs: false
|
|
3751
|
+
};
|
|
3752
|
+
this.decodeGeometry(buffer, taskConfig).then(onLoad).catch(onError);
|
|
3753
|
+
},
|
|
3754
|
+
onProgress,
|
|
3755
|
+
onError
|
|
3756
|
+
);
|
|
3757
|
+
}
|
|
3758
|
+
/** @deprecated Kept for backward-compatibility with previous DRACOLoader versions. */
|
|
3759
|
+
decodeDracoFile(buffer, callback, attributeIDs, attributeTypes) {
|
|
3760
|
+
const taskConfig = {
|
|
3761
|
+
attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
|
3762
|
+
attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
|
3763
|
+
useUniqueIDs: !!attributeIDs
|
|
3764
|
+
};
|
|
3765
|
+
this.decodeGeometry(buffer, taskConfig).then(callback);
|
|
3766
|
+
}
|
|
3767
|
+
decodeGeometry(buffer, taskConfig) {
|
|
3768
|
+
for (const attribute in taskConfig.attributeTypes) {
|
|
3769
|
+
const type = taskConfig.attributeTypes[attribute];
|
|
3770
|
+
if (type.BYTES_PER_ELEMENT !== void 0) {
|
|
3771
|
+
taskConfig.attributeTypes[attribute] = type.name;
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
const taskKey = JSON.stringify(taskConfig);
|
|
3775
|
+
if (_taskCache.has(buffer)) {
|
|
3776
|
+
const cachedTask = _taskCache.get(buffer);
|
|
3777
|
+
if (cachedTask.key === taskKey) {
|
|
3778
|
+
return cachedTask.promise;
|
|
3779
|
+
} else if (buffer.byteLength === 0) {
|
|
3780
|
+
throw new Error(
|
|
3781
|
+
"THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred."
|
|
3782
|
+
);
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
let worker;
|
|
3786
|
+
const taskID = this.workerNextTaskID++;
|
|
3787
|
+
const taskCost = buffer.byteLength;
|
|
3788
|
+
const geometryPending = this._getWorker(taskID, taskCost).then((_worker) => {
|
|
3789
|
+
worker = _worker;
|
|
3790
|
+
return new Promise((resolve, reject) => {
|
|
3791
|
+
worker._callbacks[taskID] = { resolve, reject };
|
|
3792
|
+
worker.postMessage({ type: "decode", id: taskID, taskConfig, buffer }, [buffer]);
|
|
3793
|
+
});
|
|
3794
|
+
}).then((message) => this._createGeometry(message.geometry));
|
|
3795
|
+
geometryPending.catch(() => true).then(() => {
|
|
3796
|
+
if (worker && taskID) {
|
|
3797
|
+
this._releaseTask(worker, taskID);
|
|
3798
|
+
}
|
|
3799
|
+
});
|
|
3800
|
+
_taskCache.set(buffer, {
|
|
3801
|
+
key: taskKey,
|
|
3802
|
+
promise: geometryPending
|
|
3803
|
+
});
|
|
3804
|
+
return geometryPending;
|
|
3805
|
+
}
|
|
3806
|
+
_createGeometry(geometryData) {
|
|
3807
|
+
const geometry = new BufferGeometry3();
|
|
3808
|
+
if (geometryData.index) {
|
|
3809
|
+
geometry.setIndex(new BufferAttribute3(geometryData.index.array, 1));
|
|
3810
|
+
}
|
|
3811
|
+
for (let i = 0; i < geometryData.attributes.length; i++) {
|
|
3812
|
+
const attribute = geometryData.attributes[i];
|
|
3813
|
+
const name = attribute.name;
|
|
3814
|
+
const array = attribute.array;
|
|
3815
|
+
const itemSize = attribute.itemSize;
|
|
3816
|
+
geometry.setAttribute(name, new BufferAttribute3(array, itemSize));
|
|
3817
|
+
}
|
|
3818
|
+
return geometry;
|
|
3819
|
+
}
|
|
3820
|
+
_loadLibrary(url, responseType) {
|
|
3821
|
+
const loader = new FileLoader2(this.manager);
|
|
3822
|
+
loader.setPath(this.decoderPath);
|
|
3823
|
+
loader.setResponseType(responseType);
|
|
3824
|
+
loader.setWithCredentials(this.withCredentials);
|
|
3825
|
+
return new Promise((resolve, reject) => {
|
|
3826
|
+
loader.load(url, resolve, void 0, reject);
|
|
3827
|
+
});
|
|
3828
|
+
}
|
|
3829
|
+
preload() {
|
|
3830
|
+
this._initDecoder();
|
|
3831
|
+
return this;
|
|
3832
|
+
}
|
|
3833
|
+
_initDecoder() {
|
|
3834
|
+
if (this.decoderPending)
|
|
3835
|
+
return this.decoderPending;
|
|
3836
|
+
const useJS = typeof WebAssembly !== "object" || this.decoderConfig.type === "js";
|
|
3837
|
+
const librariesPending = [];
|
|
3838
|
+
if (useJS) {
|
|
3839
|
+
librariesPending.push(this._loadLibrary("draco_decoder.js", "text"));
|
|
3840
|
+
} else {
|
|
3841
|
+
librariesPending.push(this._loadLibrary("draco_wasm_wrapper.js", "text"));
|
|
3842
|
+
librariesPending.push(this._loadLibrary("draco_decoder.wasm", "arraybuffer"));
|
|
3843
|
+
}
|
|
3844
|
+
this.decoderPending = Promise.all(librariesPending).then((libraries) => {
|
|
3845
|
+
const jsContent = libraries[0];
|
|
3846
|
+
if (!useJS) {
|
|
3847
|
+
this.decoderConfig.wasmBinary = libraries[1];
|
|
3848
|
+
}
|
|
3849
|
+
const fn = DRACOWorker.toString();
|
|
3850
|
+
const body = [
|
|
3851
|
+
"/* draco decoder */",
|
|
3852
|
+
jsContent,
|
|
3853
|
+
"",
|
|
3854
|
+
"/* worker */",
|
|
3855
|
+
fn.substring(fn.indexOf("{") + 1, fn.lastIndexOf("}"))
|
|
3856
|
+
].join("\n");
|
|
3857
|
+
this.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
|
3858
|
+
});
|
|
3859
|
+
return this.decoderPending;
|
|
3860
|
+
}
|
|
3861
|
+
_getWorker(taskID, taskCost) {
|
|
3862
|
+
return this._initDecoder().then(() => {
|
|
3863
|
+
if (this.workerPool.length < this.workerLimit) {
|
|
3864
|
+
const worker2 = new Worker(this.workerSourceURL);
|
|
3865
|
+
worker2._callbacks = {};
|
|
3866
|
+
worker2._taskCosts = {};
|
|
3867
|
+
worker2._taskLoad = 0;
|
|
3868
|
+
worker2.postMessage({ type: "init", decoderConfig: this.decoderConfig });
|
|
3869
|
+
worker2.onmessage = function(e) {
|
|
3870
|
+
const message = e.data;
|
|
3871
|
+
switch (message.type) {
|
|
3872
|
+
case "decode":
|
|
3873
|
+
worker2._callbacks[message.id].resolve(message);
|
|
3874
|
+
break;
|
|
3875
|
+
case "error":
|
|
3876
|
+
worker2._callbacks[message.id].reject(message);
|
|
3877
|
+
break;
|
|
3878
|
+
default:
|
|
3879
|
+
console.error('THREE.DRACOLoader: Unexpected message, "' + message.type + '"');
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
this.workerPool.push(worker2);
|
|
3883
|
+
} else {
|
|
3884
|
+
this.workerPool.sort(function(a, b) {
|
|
3885
|
+
return a._taskLoad > b._taskLoad ? -1 : 1;
|
|
3886
|
+
});
|
|
3887
|
+
}
|
|
3888
|
+
const worker = this.workerPool[this.workerPool.length - 1];
|
|
3889
|
+
worker._taskCosts[taskID] = taskCost;
|
|
3890
|
+
worker._taskLoad += taskCost;
|
|
3891
|
+
return worker;
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
_releaseTask(worker, taskID) {
|
|
3895
|
+
worker._taskLoad -= worker._taskCosts[taskID];
|
|
3896
|
+
delete worker._callbacks[taskID];
|
|
3897
|
+
delete worker._taskCosts[taskID];
|
|
3898
|
+
}
|
|
3899
|
+
debug() {
|
|
3900
|
+
console.log(
|
|
3901
|
+
"Task load: ",
|
|
3902
|
+
this.workerPool.map((worker) => worker._taskLoad)
|
|
3903
|
+
);
|
|
3904
|
+
}
|
|
3905
|
+
dispose() {
|
|
3906
|
+
for (let i = 0; i < this.workerPool.length; ++i) {
|
|
3907
|
+
this.workerPool[i].terminate();
|
|
3908
|
+
}
|
|
3909
|
+
this.workerPool.length = 0;
|
|
3910
|
+
return this;
|
|
3911
|
+
}
|
|
3912
|
+
};
|
|
3913
|
+
function DRACOWorker() {
|
|
3914
|
+
let decoderConfig;
|
|
3915
|
+
let decoderPending;
|
|
3916
|
+
onmessage = function(e) {
|
|
3917
|
+
const message = e.data;
|
|
3918
|
+
switch (message.type) {
|
|
3919
|
+
case "init":
|
|
3920
|
+
decoderConfig = message.decoderConfig;
|
|
3921
|
+
decoderPending = new Promise(function(resolve) {
|
|
3922
|
+
decoderConfig.onModuleLoaded = function(draco) {
|
|
3923
|
+
resolve({ draco });
|
|
3924
|
+
};
|
|
3925
|
+
DracoDecoderModule(decoderConfig);
|
|
3926
|
+
});
|
|
3927
|
+
break;
|
|
3928
|
+
case "decode":
|
|
3929
|
+
const buffer = message.buffer;
|
|
3930
|
+
const taskConfig = message.taskConfig;
|
|
3931
|
+
decoderPending.then((module) => {
|
|
3932
|
+
const draco = module.draco;
|
|
3933
|
+
const decoder = new draco.Decoder();
|
|
3934
|
+
const decoderBuffer = new draco.DecoderBuffer();
|
|
3935
|
+
decoderBuffer.Init(new Int8Array(buffer), buffer.byteLength);
|
|
3936
|
+
try {
|
|
3937
|
+
const geometry = decodeGeometry(draco, decoder, decoderBuffer, taskConfig);
|
|
3938
|
+
const buffers = geometry.attributes.map((attr) => attr.array.buffer);
|
|
3939
|
+
if (geometry.index)
|
|
3940
|
+
buffers.push(geometry.index.array.buffer);
|
|
3941
|
+
self.postMessage({ type: "decode", id: message.id, geometry }, buffers);
|
|
3942
|
+
} catch (error) {
|
|
3943
|
+
console.error(error);
|
|
3944
|
+
self.postMessage({ type: "error", id: message.id, error: error.message });
|
|
3945
|
+
} finally {
|
|
3946
|
+
draco.destroy(decoderBuffer);
|
|
3947
|
+
draco.destroy(decoder);
|
|
3948
|
+
}
|
|
3949
|
+
});
|
|
3950
|
+
break;
|
|
3951
|
+
}
|
|
3952
|
+
};
|
|
3953
|
+
function decodeGeometry(draco, decoder, decoderBuffer, taskConfig) {
|
|
3954
|
+
const attributeIDs = taskConfig.attributeIDs;
|
|
3955
|
+
const attributeTypes = taskConfig.attributeTypes;
|
|
3956
|
+
let dracoGeometry;
|
|
3957
|
+
let decodingStatus;
|
|
3958
|
+
const geometryType = decoder.GetEncodedGeometryType(decoderBuffer);
|
|
3959
|
+
if (geometryType === draco.TRIANGULAR_MESH) {
|
|
3960
|
+
dracoGeometry = new draco.Mesh();
|
|
3961
|
+
decodingStatus = decoder.DecodeBufferToMesh(decoderBuffer, dracoGeometry);
|
|
3962
|
+
} else if (geometryType === draco.POINT_CLOUD) {
|
|
3963
|
+
dracoGeometry = new draco.PointCloud();
|
|
3964
|
+
decodingStatus = decoder.DecodeBufferToPointCloud(decoderBuffer, dracoGeometry);
|
|
3965
|
+
} else {
|
|
3966
|
+
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
|
3967
|
+
}
|
|
3968
|
+
if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
|
|
3969
|
+
throw new Error("THREE.DRACOLoader: Decoding failed: " + decodingStatus.error_msg());
|
|
3970
|
+
}
|
|
3971
|
+
const geometry = { index: null, attributes: [] };
|
|
3972
|
+
for (const attributeName in attributeIDs) {
|
|
3973
|
+
const attributeType = self[attributeTypes[attributeName]];
|
|
3974
|
+
let attribute;
|
|
3975
|
+
let attributeID;
|
|
3976
|
+
if (taskConfig.useUniqueIDs) {
|
|
3977
|
+
attributeID = attributeIDs[attributeName];
|
|
3978
|
+
attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
|
|
3979
|
+
} else {
|
|
3980
|
+
attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeIDs[attributeName]]);
|
|
3981
|
+
if (attributeID === -1)
|
|
3982
|
+
continue;
|
|
3983
|
+
attribute = decoder.GetAttribute(dracoGeometry, attributeID);
|
|
3984
|
+
}
|
|
3985
|
+
geometry.attributes.push(decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute));
|
|
3986
|
+
}
|
|
3987
|
+
if (geometryType === draco.TRIANGULAR_MESH) {
|
|
3988
|
+
geometry.index = decodeIndex(draco, decoder, dracoGeometry);
|
|
3989
|
+
}
|
|
3990
|
+
draco.destroy(dracoGeometry);
|
|
3991
|
+
return geometry;
|
|
3992
|
+
}
|
|
3993
|
+
function decodeIndex(draco, decoder, dracoGeometry) {
|
|
3994
|
+
const numFaces = dracoGeometry.num_faces();
|
|
3995
|
+
const numIndices = numFaces * 3;
|
|
3996
|
+
const byteLength = numIndices * 4;
|
|
3997
|
+
const ptr = draco._malloc(byteLength);
|
|
3998
|
+
decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
3999
|
+
const index = new Uint32Array(draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
4000
|
+
draco._free(ptr);
|
|
4001
|
+
return { array: index, itemSize: 1 };
|
|
4002
|
+
}
|
|
4003
|
+
function decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute) {
|
|
4004
|
+
const numComponents = attribute.num_components();
|
|
4005
|
+
const numPoints = dracoGeometry.num_points();
|
|
4006
|
+
const numValues = numPoints * numComponents;
|
|
4007
|
+
const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
|
|
4008
|
+
const dataType = getDracoDataType(draco, attributeType);
|
|
4009
|
+
const ptr = draco._malloc(byteLength);
|
|
4010
|
+
decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, attribute, dataType, byteLength, ptr);
|
|
4011
|
+
const array = new attributeType(draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
4012
|
+
draco._free(ptr);
|
|
4013
|
+
return {
|
|
4014
|
+
name: attributeName,
|
|
4015
|
+
array,
|
|
4016
|
+
itemSize: numComponents
|
|
4017
|
+
};
|
|
4018
|
+
}
|
|
4019
|
+
function getDracoDataType(draco, attributeType) {
|
|
4020
|
+
switch (attributeType) {
|
|
4021
|
+
case Float32Array:
|
|
4022
|
+
return draco.DT_FLOAT32;
|
|
4023
|
+
case Int8Array:
|
|
4024
|
+
return draco.DT_INT8;
|
|
4025
|
+
case Int16Array:
|
|
4026
|
+
return draco.DT_INT16;
|
|
4027
|
+
case Int32Array:
|
|
4028
|
+
return draco.DT_INT32;
|
|
4029
|
+
case Uint8Array:
|
|
4030
|
+
return draco.DT_UINT8;
|
|
4031
|
+
case Uint16Array:
|
|
4032
|
+
return draco.DT_UINT16;
|
|
4033
|
+
case Uint32Array:
|
|
4034
|
+
return draco.DT_UINT32;
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
// ../../node_modules/three-stdlib/libs/MeshoptDecoder.js
|
|
4040
|
+
var generated;
|
|
4041
|
+
var MeshoptDecoder = () => {
|
|
4042
|
+
if (generated)
|
|
4043
|
+
return generated;
|
|
4044
|
+
const wasm_base = "B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQB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
|
|
4053
|
+
0,
|
|
4054
|
+
0,
|
|
4055
|
+
1,
|
|
4056
|
+
4,
|
|
4057
|
+
1,
|
|
4058
|
+
96,
|
|
4059
|
+
0,
|
|
4060
|
+
0,
|
|
4061
|
+
3,
|
|
4062
|
+
3,
|
|
4063
|
+
2,
|
|
4064
|
+
0,
|
|
4065
|
+
0,
|
|
4066
|
+
5,
|
|
4067
|
+
3,
|
|
4068
|
+
1,
|
|
4069
|
+
0,
|
|
4070
|
+
1,
|
|
4071
|
+
12,
|
|
4072
|
+
1,
|
|
4073
|
+
0,
|
|
4074
|
+
10,
|
|
4075
|
+
22,
|
|
4076
|
+
2,
|
|
4077
|
+
12,
|
|
4078
|
+
0,
|
|
4079
|
+
65,
|
|
4080
|
+
0,
|
|
4081
|
+
65,
|
|
4082
|
+
0,
|
|
4083
|
+
65,
|
|
4084
|
+
0,
|
|
4085
|
+
252,
|
|
4086
|
+
10,
|
|
4087
|
+
0,
|
|
4088
|
+
0,
|
|
4089
|
+
11,
|
|
4090
|
+
7,
|
|
4091
|
+
0,
|
|
4092
|
+
65,
|
|
4093
|
+
0,
|
|
4094
|
+
253,
|
|
4095
|
+
15,
|
|
4096
|
+
26,
|
|
4097
|
+
11
|
|
4098
|
+
]);
|
|
4099
|
+
const wasmpack = new Uint8Array([
|
|
4100
|
+
32,
|
|
4101
|
+
0,
|
|
4102
|
+
65,
|
|
4103
|
+
253,
|
|
4104
|
+
3,
|
|
4105
|
+
1,
|
|
4106
|
+
2,
|
|
4107
|
+
34,
|
|
4108
|
+
4,
|
|
4109
|
+
106,
|
|
4110
|
+
6,
|
|
4111
|
+
5,
|
|
4112
|
+
11,
|
|
4113
|
+
8,
|
|
4114
|
+
7,
|
|
4115
|
+
20,
|
|
4116
|
+
13,
|
|
4117
|
+
33,
|
|
4118
|
+
12,
|
|
4119
|
+
16,
|
|
4120
|
+
128,
|
|
4121
|
+
9,
|
|
4122
|
+
116,
|
|
4123
|
+
64,
|
|
4124
|
+
19,
|
|
4125
|
+
113,
|
|
4126
|
+
127,
|
|
4127
|
+
15,
|
|
4128
|
+
10,
|
|
4129
|
+
21,
|
|
4130
|
+
22,
|
|
4131
|
+
14,
|
|
4132
|
+
255,
|
|
4133
|
+
66,
|
|
4134
|
+
24,
|
|
4135
|
+
54,
|
|
4136
|
+
136,
|
|
4137
|
+
107,
|
|
4138
|
+
18,
|
|
4139
|
+
23,
|
|
4140
|
+
192,
|
|
4141
|
+
26,
|
|
4142
|
+
114,
|
|
4143
|
+
118,
|
|
4144
|
+
132,
|
|
4145
|
+
17,
|
|
4146
|
+
77,
|
|
4147
|
+
101,
|
|
4148
|
+
130,
|
|
4149
|
+
144,
|
|
4150
|
+
27,
|
|
4151
|
+
87,
|
|
4152
|
+
131,
|
|
4153
|
+
44,
|
|
4154
|
+
45,
|
|
4155
|
+
74,
|
|
4156
|
+
156,
|
|
4157
|
+
154,
|
|
4158
|
+
70,
|
|
4159
|
+
167
|
|
4160
|
+
]);
|
|
4161
|
+
if (typeof WebAssembly !== "object") {
|
|
4162
|
+
return {
|
|
4163
|
+
supported: false
|
|
4164
|
+
};
|
|
4165
|
+
}
|
|
4166
|
+
let wasm = wasm_base;
|
|
4167
|
+
if (WebAssembly.validate(detector)) {
|
|
4168
|
+
wasm = wasm_simd;
|
|
4169
|
+
}
|
|
4170
|
+
let instance;
|
|
4171
|
+
const promise = WebAssembly.instantiate(unpack(wasm), {}).then((result) => {
|
|
4172
|
+
instance = result.instance;
|
|
4173
|
+
instance.exports.__wasm_call_ctors();
|
|
4174
|
+
});
|
|
4175
|
+
function unpack(data) {
|
|
4176
|
+
const result = new Uint8Array(data.length);
|
|
4177
|
+
for (let i = 0; i < data.length; ++i) {
|
|
4178
|
+
const ch = data.charCodeAt(i);
|
|
4179
|
+
result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62;
|
|
4180
|
+
}
|
|
4181
|
+
let write = 0;
|
|
4182
|
+
for (let i = 0; i < data.length; ++i) {
|
|
4183
|
+
result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];
|
|
4184
|
+
}
|
|
4185
|
+
return result.buffer.slice(0, write);
|
|
4186
|
+
}
|
|
4187
|
+
function decode(fun, target, count, size, source, filter) {
|
|
4188
|
+
const sbrk = instance.exports.sbrk;
|
|
4189
|
+
const count4 = count + 3 & ~3;
|
|
4190
|
+
const tp = sbrk(count4 * size);
|
|
4191
|
+
const sp = sbrk(source.length);
|
|
4192
|
+
const heap = new Uint8Array(instance.exports.memory.buffer);
|
|
4193
|
+
heap.set(source, sp);
|
|
4194
|
+
const res = fun(tp, count, size, sp, source.length);
|
|
4195
|
+
if (res === 0 && filter) {
|
|
4196
|
+
filter(tp, count4, size);
|
|
4197
|
+
}
|
|
4198
|
+
target.set(heap.subarray(tp, tp + count * size));
|
|
4199
|
+
sbrk(tp - sbrk(0));
|
|
4200
|
+
if (res !== 0) {
|
|
4201
|
+
throw new Error(`Malformed buffer data: ${res}`);
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
const filters = {
|
|
4205
|
+
// legacy index-based enums for glTF
|
|
4206
|
+
0: "",
|
|
4207
|
+
1: "meshopt_decodeFilterOct",
|
|
4208
|
+
2: "meshopt_decodeFilterQuat",
|
|
4209
|
+
3: "meshopt_decodeFilterExp",
|
|
4210
|
+
// string-based enums for glTF
|
|
4211
|
+
NONE: "",
|
|
4212
|
+
OCTAHEDRAL: "meshopt_decodeFilterOct",
|
|
4213
|
+
QUATERNION: "meshopt_decodeFilterQuat",
|
|
4214
|
+
EXPONENTIAL: "meshopt_decodeFilterExp"
|
|
4215
|
+
};
|
|
4216
|
+
const decoders = {
|
|
4217
|
+
// legacy index-based enums for glTF
|
|
4218
|
+
0: "meshopt_decodeVertexBuffer",
|
|
4219
|
+
1: "meshopt_decodeIndexBuffer",
|
|
4220
|
+
2: "meshopt_decodeIndexSequence",
|
|
4221
|
+
// string-based enums for glTF
|
|
4222
|
+
ATTRIBUTES: "meshopt_decodeVertexBuffer",
|
|
4223
|
+
TRIANGLES: "meshopt_decodeIndexBuffer",
|
|
4224
|
+
INDICES: "meshopt_decodeIndexSequence"
|
|
4225
|
+
};
|
|
4226
|
+
generated = {
|
|
4227
|
+
ready: promise,
|
|
4228
|
+
supported: true,
|
|
4229
|
+
decodeVertexBuffer(target, count, size, source, filter) {
|
|
4230
|
+
decode(
|
|
4231
|
+
instance.exports.meshopt_decodeVertexBuffer,
|
|
4232
|
+
target,
|
|
4233
|
+
count,
|
|
4234
|
+
size,
|
|
4235
|
+
source,
|
|
4236
|
+
instance.exports[filters[filter]]
|
|
4237
|
+
);
|
|
4238
|
+
},
|
|
4239
|
+
decodeIndexBuffer(target, count, size, source) {
|
|
4240
|
+
decode(instance.exports.meshopt_decodeIndexBuffer, target, count, size, source);
|
|
4241
|
+
},
|
|
4242
|
+
decodeIndexSequence(target, count, size, source) {
|
|
4243
|
+
decode(instance.exports.meshopt_decodeIndexSequence, target, count, size, source);
|
|
4244
|
+
},
|
|
4245
|
+
decodeGltfBuffer(target, count, size, source, mode, filter) {
|
|
4246
|
+
decode(
|
|
4247
|
+
instance.exports[decoders[mode]],
|
|
4248
|
+
target,
|
|
4249
|
+
count,
|
|
4250
|
+
size,
|
|
4251
|
+
source,
|
|
4252
|
+
instance.exports[filters[filter]]
|
|
4253
|
+
);
|
|
4254
|
+
}
|
|
4255
|
+
};
|
|
4256
|
+
return generated;
|
|
4257
|
+
};
|
|
4258
|
+
|
|
4259
|
+
// ../../node_modules/@react-three/drei/core/Gltf.js
|
|
4260
|
+
import * as React from "react";
|
|
4261
|
+
import { useLoader } from "@react-three/fiber";
|
|
4262
|
+
var dracoLoader = null;
|
|
4263
|
+
var decoderPath = "https://www.gstatic.com/draco/versioned/decoders/1.5.5/";
|
|
4264
|
+
function extensions(useDraco = true, useMeshopt = true, extendLoader) {
|
|
4265
|
+
return (loader) => {
|
|
4266
|
+
if (extendLoader) {
|
|
4267
|
+
extendLoader(loader);
|
|
4268
|
+
}
|
|
4269
|
+
if (useDraco) {
|
|
4270
|
+
if (!dracoLoader) {
|
|
4271
|
+
dracoLoader = new DRACOLoader();
|
|
4272
|
+
}
|
|
4273
|
+
dracoLoader.setDecoderPath(typeof useDraco === "string" ? useDraco : decoderPath);
|
|
4274
|
+
loader.setDRACOLoader(dracoLoader);
|
|
4275
|
+
}
|
|
4276
|
+
if (useMeshopt) {
|
|
4277
|
+
loader.setMeshoptDecoder(typeof MeshoptDecoder === "function" ? MeshoptDecoder() : MeshoptDecoder);
|
|
4278
|
+
}
|
|
4279
|
+
};
|
|
4280
|
+
}
|
|
4281
|
+
var useGLTF = (path, useDraco, useMeshopt, extendLoader) => useLoader(GLTFLoader, path, extensions(useDraco, useMeshopt, extendLoader));
|
|
4282
|
+
useGLTF.preload = (path, useDraco, useMeshopt, extendLoader) => useLoader.preload(GLTFLoader, path, extensions(useDraco, useMeshopt, extendLoader));
|
|
4283
|
+
useGLTF.clear = (path) => useLoader.clear(GLTFLoader, path);
|
|
4284
|
+
useGLTF.setDecoderPath = (path) => {
|
|
4285
|
+
decoderPath = path;
|
|
4286
|
+
};
|
|
4287
|
+
|
|
4288
|
+
// ../../node_modules/@react-three/drei/core/OrbitControls.js
|
|
4289
|
+
import { useThree, useFrame } from "@react-three/fiber";
|
|
4290
|
+
import * as React2 from "react";
|
|
4291
|
+
var OrbitControls2 = /* @__PURE__ */ React2.forwardRef(({
|
|
4292
|
+
makeDefault,
|
|
4293
|
+
camera,
|
|
4294
|
+
regress,
|
|
4295
|
+
domElement,
|
|
4296
|
+
enableDamping = true,
|
|
4297
|
+
keyEvents = false,
|
|
4298
|
+
onChange,
|
|
4299
|
+
onStart,
|
|
4300
|
+
onEnd,
|
|
4301
|
+
...restProps
|
|
4302
|
+
}, ref) => {
|
|
4303
|
+
const invalidate = useThree((state) => state.invalidate);
|
|
4304
|
+
const defaultCamera = useThree((state) => state.camera);
|
|
4305
|
+
const gl = useThree((state) => state.gl);
|
|
4306
|
+
const events = useThree((state) => state.events);
|
|
4307
|
+
const setEvents = useThree((state) => state.setEvents);
|
|
4308
|
+
const set = useThree((state) => state.set);
|
|
4309
|
+
const get = useThree((state) => state.get);
|
|
4310
|
+
const performance2 = useThree((state) => state.performance);
|
|
4311
|
+
const explCamera = camera || defaultCamera;
|
|
4312
|
+
const explDomElement = domElement || events.connected || gl.domElement;
|
|
4313
|
+
const controls = React2.useMemo(() => new OrbitControls(explCamera), [explCamera]);
|
|
4314
|
+
useFrame(() => {
|
|
4315
|
+
if (controls.enabled) controls.update();
|
|
4316
|
+
}, -1);
|
|
4317
|
+
React2.useEffect(() => {
|
|
4318
|
+
if (keyEvents) {
|
|
4319
|
+
controls.connect(keyEvents === true ? explDomElement : keyEvents);
|
|
4320
|
+
}
|
|
4321
|
+
controls.connect(explDomElement);
|
|
4322
|
+
return () => void controls.dispose();
|
|
4323
|
+
}, [keyEvents, explDomElement, regress, controls, invalidate]);
|
|
4324
|
+
React2.useEffect(() => {
|
|
4325
|
+
const callback = (e) => {
|
|
4326
|
+
invalidate();
|
|
4327
|
+
if (regress) performance2.regress();
|
|
4328
|
+
if (onChange) onChange(e);
|
|
4329
|
+
};
|
|
4330
|
+
const onStartCb = (e) => {
|
|
4331
|
+
if (onStart) onStart(e);
|
|
4332
|
+
};
|
|
4333
|
+
const onEndCb = (e) => {
|
|
4334
|
+
if (onEnd) onEnd(e);
|
|
4335
|
+
};
|
|
4336
|
+
controls.addEventListener("change", callback);
|
|
4337
|
+
controls.addEventListener("start", onStartCb);
|
|
4338
|
+
controls.addEventListener("end", onEndCb);
|
|
4339
|
+
return () => {
|
|
4340
|
+
controls.removeEventListener("start", onStartCb);
|
|
4341
|
+
controls.removeEventListener("end", onEndCb);
|
|
4342
|
+
controls.removeEventListener("change", callback);
|
|
4343
|
+
};
|
|
4344
|
+
}, [onChange, onStart, onEnd, controls, invalidate, setEvents]);
|
|
4345
|
+
React2.useEffect(() => {
|
|
4346
|
+
if (makeDefault) {
|
|
4347
|
+
const old = get().controls;
|
|
4348
|
+
set({
|
|
4349
|
+
controls
|
|
4350
|
+
});
|
|
4351
|
+
return () => set({
|
|
4352
|
+
controls: old
|
|
4353
|
+
});
|
|
4354
|
+
}
|
|
4355
|
+
}, [makeDefault, controls]);
|
|
4356
|
+
return /* @__PURE__ */ React2.createElement("primitive", _extends({
|
|
4357
|
+
ref,
|
|
4358
|
+
object: controls,
|
|
4359
|
+
enableDamping
|
|
4360
|
+
}, restProps));
|
|
4361
|
+
});
|
|
4362
|
+
|
|
4363
|
+
// ../../node_modules/camera-controls/dist/camera-controls.module.js
|
|
4364
|
+
var ACTION = Object.freeze({
|
|
4365
|
+
NONE: 0,
|
|
4366
|
+
ROTATE: 1,
|
|
4367
|
+
TRUCK: 2,
|
|
4368
|
+
SCREEN_PAN: 4,
|
|
4369
|
+
OFFSET: 8,
|
|
4370
|
+
DOLLY: 16,
|
|
4371
|
+
ZOOM: 32,
|
|
4372
|
+
TOUCH_ROTATE: 64,
|
|
4373
|
+
TOUCH_TRUCK: 128,
|
|
4374
|
+
TOUCH_SCREEN_PAN: 256,
|
|
4375
|
+
TOUCH_OFFSET: 512,
|
|
4376
|
+
TOUCH_DOLLY: 1024,
|
|
4377
|
+
TOUCH_ZOOM: 2048,
|
|
4378
|
+
TOUCH_DOLLY_TRUCK: 4096,
|
|
4379
|
+
TOUCH_DOLLY_SCREEN_PAN: 8192,
|
|
4380
|
+
TOUCH_DOLLY_OFFSET: 16384,
|
|
4381
|
+
TOUCH_DOLLY_ROTATE: 32768,
|
|
4382
|
+
TOUCH_ZOOM_TRUCK: 65536,
|
|
4383
|
+
TOUCH_ZOOM_OFFSET: 131072,
|
|
4384
|
+
TOUCH_ZOOM_SCREEN_PAN: 262144,
|
|
4385
|
+
TOUCH_ZOOM_ROTATE: 524288
|
|
4386
|
+
});
|
|
4387
|
+
var PI_2 = Math.PI * 2;
|
|
4388
|
+
var PI_HALF = Math.PI / 2;
|
|
4389
|
+
var DEG2RAD = Math.PI / 180;
|
|
4390
|
+
var TOUCH_DOLLY_FACTOR = 1 / 8;
|
|
4391
|
+
var isMac = /Mac/.test(globalThis?.navigator?.platform);
|
|
4392
|
+
|
|
4393
|
+
// src/builders/SceneBuilder.tsx
|
|
4394
|
+
import { SceneContent } from "@linxai/3d-shared";
|
|
4395
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
4396
|
+
var WebSceneBuilder = {
|
|
4397
|
+
/**
|
|
4398
|
+
* 构建 Web 平台的 Canvas
|
|
4399
|
+
*/
|
|
4400
|
+
buildCanvas: ({ children, config = {}, style, className }) => {
|
|
4401
|
+
const {
|
|
4402
|
+
cameraPosition = [0, 0, 5],
|
|
4403
|
+
fov = 75
|
|
4404
|
+
} = config;
|
|
4405
|
+
return /* @__PURE__ */ jsx2(
|
|
4406
|
+
Canvas,
|
|
4407
|
+
{
|
|
4408
|
+
camera: { position: cameraPosition, fov },
|
|
4409
|
+
style,
|
|
4410
|
+
className,
|
|
4411
|
+
children: /* @__PURE__ */ jsx2(SceneContent, { config, children })
|
|
4412
|
+
}
|
|
4413
|
+
);
|
|
4414
|
+
},
|
|
4415
|
+
/**
|
|
4416
|
+
* 构建 Web 平台的 OrbitControls
|
|
4417
|
+
*/
|
|
4418
|
+
buildOrbitControls: (config) => {
|
|
4419
|
+
const {
|
|
4420
|
+
enableDamping = true,
|
|
4421
|
+
dampingFactor = 0.05,
|
|
4422
|
+
enableRotate = true,
|
|
4423
|
+
enableZoom = true,
|
|
4424
|
+
enablePan = true,
|
|
4425
|
+
minDistance,
|
|
4426
|
+
maxDistance,
|
|
4427
|
+
minPolarAngle,
|
|
4428
|
+
maxPolarAngle,
|
|
4429
|
+
target
|
|
4430
|
+
} = config || {};
|
|
4431
|
+
return /* @__PURE__ */ jsx2(
|
|
4432
|
+
OrbitControls2,
|
|
4433
|
+
{
|
|
4434
|
+
enableDamping,
|
|
4435
|
+
dampingFactor,
|
|
4436
|
+
enableRotate,
|
|
4437
|
+
enableZoom,
|
|
4438
|
+
enablePan,
|
|
4439
|
+
minDistance,
|
|
4440
|
+
maxDistance,
|
|
4441
|
+
minPolarAngle,
|
|
4442
|
+
maxPolarAngle,
|
|
4443
|
+
target
|
|
4444
|
+
}
|
|
4445
|
+
);
|
|
4446
|
+
},
|
|
4447
|
+
/**
|
|
4448
|
+
* 构建 Web 平台的 GridHelper
|
|
4449
|
+
*/
|
|
4450
|
+
buildGridHelper: (config) => {
|
|
4451
|
+
if (!config || config?.visible === false) {
|
|
4452
|
+
return null;
|
|
4453
|
+
}
|
|
4454
|
+
const {
|
|
4455
|
+
size = 10,
|
|
4456
|
+
divisions = 10,
|
|
4457
|
+
centerLineColor = "#888888",
|
|
4458
|
+
gridColor = "#444444"
|
|
4459
|
+
} = config || {};
|
|
4460
|
+
return (
|
|
4461
|
+
// @ts-ignore - R3F JSX 元素
|
|
4462
|
+
/* @__PURE__ */ jsx2(
|
|
4463
|
+
"gridHelper",
|
|
4464
|
+
{
|
|
4465
|
+
args: [size, divisions, centerLineColor, gridColor]
|
|
4466
|
+
}
|
|
4467
|
+
)
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4470
|
+
};
|
|
4471
|
+
|
|
4472
|
+
// src/components/Scene3D.tsx
|
|
4473
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4474
|
+
function Scene3DContent({
|
|
4475
|
+
children,
|
|
4476
|
+
config = {},
|
|
4477
|
+
controlsConfig,
|
|
4478
|
+
style,
|
|
4479
|
+
className,
|
|
4480
|
+
showProgress = true
|
|
4481
|
+
}) {
|
|
4482
|
+
const { progress, isLoading } = useLoading();
|
|
4483
|
+
const canvas = WebSceneBuilder.buildCanvas({
|
|
4484
|
+
children: /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
4485
|
+
WebSceneBuilder.buildOrbitControls(controlsConfig),
|
|
4486
|
+
WebSceneBuilder.buildGridHelper(config.gridHelper),
|
|
4487
|
+
children
|
|
4488
|
+
] }),
|
|
4489
|
+
config,
|
|
4490
|
+
style,
|
|
4491
|
+
className
|
|
4492
|
+
});
|
|
4493
|
+
const shouldShowProgress = showProgress && isLoading && progress < 1;
|
|
4494
|
+
return /* @__PURE__ */ jsxs2("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
|
|
4495
|
+
canvas,
|
|
4496
|
+
shouldShowProgress && /* @__PURE__ */ jsx3(
|
|
4497
|
+
"div",
|
|
4498
|
+
{
|
|
4499
|
+
style: {
|
|
4500
|
+
position: "absolute",
|
|
4501
|
+
top: "50%",
|
|
4502
|
+
left: "50%",
|
|
4503
|
+
transform: "translate(-50%, -50%)",
|
|
4504
|
+
width: "80%",
|
|
4505
|
+
maxWidth: 400,
|
|
4506
|
+
zIndex: 1e3
|
|
4507
|
+
},
|
|
4508
|
+
children: /* @__PURE__ */ jsx3(ProgressBar, { progress })
|
|
4509
|
+
}
|
|
4510
|
+
)
|
|
4511
|
+
] });
|
|
4512
|
+
}
|
|
4513
|
+
function Scene3D(props) {
|
|
4514
|
+
return /* @__PURE__ */ jsx3(LoadingProvider, { children: /* @__PURE__ */ jsx3(Scene3DContent, { ...props }) });
|
|
4515
|
+
}
|
|
4516
|
+
|
|
4517
|
+
// src/components/Subtitle.tsx
|
|
4518
|
+
import { useState, useEffect as useEffect2 } from "react";
|
|
4519
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
4520
|
+
function Subtitle({
|
|
4521
|
+
text = "",
|
|
4522
|
+
visible = true,
|
|
4523
|
+
style,
|
|
4524
|
+
boxStyle,
|
|
4525
|
+
textStyle,
|
|
4526
|
+
bottomOffset = 80
|
|
4527
|
+
}) {
|
|
4528
|
+
const [fadeIn, setFadeIn] = useState(false);
|
|
4529
|
+
useEffect2(() => {
|
|
4530
|
+
if (text) {
|
|
4531
|
+
setFadeIn(true);
|
|
4532
|
+
} else {
|
|
4533
|
+
setFadeIn(false);
|
|
4534
|
+
}
|
|
4535
|
+
}, [text]);
|
|
4536
|
+
if (!visible || !text) return null;
|
|
4537
|
+
return /* @__PURE__ */ jsx4(
|
|
4538
|
+
"div",
|
|
4539
|
+
{
|
|
4540
|
+
style: {
|
|
4541
|
+
position: "absolute",
|
|
4542
|
+
left: 0,
|
|
4543
|
+
right: 0,
|
|
4544
|
+
bottom: `${bottomOffset}px`,
|
|
4545
|
+
display: "flex",
|
|
4546
|
+
justifyContent: "center",
|
|
4547
|
+
padding: "0 20px",
|
|
4548
|
+
pointerEvents: "none",
|
|
4549
|
+
zIndex: 100,
|
|
4550
|
+
opacity: fadeIn ? 1 : 0,
|
|
4551
|
+
transform: fadeIn ? "translateY(0)" : "translateY(10px)",
|
|
4552
|
+
transition: "all 0.3s ease-out",
|
|
4553
|
+
...style
|
|
4554
|
+
},
|
|
4555
|
+
children: /* @__PURE__ */ jsx4(
|
|
4556
|
+
"div",
|
|
4557
|
+
{
|
|
4558
|
+
style: {
|
|
4559
|
+
background: "rgba(0, 0, 0, 0.85)",
|
|
4560
|
+
backdropFilter: "blur(10px)",
|
|
4561
|
+
padding: "16px 24px",
|
|
4562
|
+
borderRadius: "12px",
|
|
4563
|
+
maxWidth: "80%",
|
|
4564
|
+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.3)",
|
|
4565
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
4566
|
+
...boxStyle
|
|
4567
|
+
},
|
|
4568
|
+
children: /* @__PURE__ */ jsx4(
|
|
4569
|
+
"p",
|
|
4570
|
+
{
|
|
4571
|
+
style: {
|
|
4572
|
+
margin: 0,
|
|
4573
|
+
color: "#fff",
|
|
4574
|
+
fontSize: "16px",
|
|
4575
|
+
lineHeight: "1.6",
|
|
4576
|
+
textAlign: "center",
|
|
4577
|
+
fontWeight: "500",
|
|
4578
|
+
...textStyle
|
|
4579
|
+
},
|
|
4580
|
+
children: text
|
|
4581
|
+
}
|
|
4582
|
+
)
|
|
4583
|
+
}
|
|
4584
|
+
)
|
|
4585
|
+
}
|
|
4586
|
+
);
|
|
4587
|
+
}
|
|
4588
|
+
|
|
4589
|
+
// src/components/CharacterOverlay.tsx
|
|
4590
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
4591
|
+
function CharacterOverlay({
|
|
4592
|
+
visible = true,
|
|
4593
|
+
subtitle = "",
|
|
4594
|
+
showSubtitle = true,
|
|
4595
|
+
showSpeakButton = true,
|
|
4596
|
+
isLoading = false,
|
|
4597
|
+
isConnected = false,
|
|
4598
|
+
onStartSpeak,
|
|
4599
|
+
onStopSpeak,
|
|
4600
|
+
onButtonClick,
|
|
4601
|
+
subtitleStyle,
|
|
4602
|
+
style
|
|
4603
|
+
}) {
|
|
4604
|
+
if (!visible) return null;
|
|
4605
|
+
const handleSpeakClick = () => {
|
|
4606
|
+
if (onButtonClick) {
|
|
4607
|
+
onButtonClick();
|
|
4608
|
+
} else {
|
|
4609
|
+
if (isConnected) {
|
|
4610
|
+
onStopSpeak?.();
|
|
4611
|
+
} else {
|
|
4612
|
+
onStartSpeak?.();
|
|
4613
|
+
}
|
|
4614
|
+
}
|
|
4615
|
+
};
|
|
4616
|
+
return /* @__PURE__ */ jsxs3(
|
|
4617
|
+
"div",
|
|
4618
|
+
{
|
|
4619
|
+
style: {
|
|
4620
|
+
position: "absolute",
|
|
4621
|
+
top: 0,
|
|
4622
|
+
left: 0,
|
|
4623
|
+
right: 0,
|
|
4624
|
+
bottom: 0,
|
|
4625
|
+
pointerEvents: "none",
|
|
4626
|
+
display: "flex",
|
|
4627
|
+
flexDirection: "column",
|
|
4628
|
+
justifyContent: "flex-end",
|
|
4629
|
+
padding: "20px",
|
|
4630
|
+
zIndex: 100,
|
|
4631
|
+
...style
|
|
4632
|
+
},
|
|
4633
|
+
children: [
|
|
4634
|
+
/* @__PURE__ */ jsx5(
|
|
4635
|
+
Subtitle,
|
|
4636
|
+
{
|
|
4637
|
+
text: subtitle,
|
|
4638
|
+
visible: showSubtitle,
|
|
4639
|
+
boxStyle: subtitleStyle,
|
|
4640
|
+
bottomOffset: 0,
|
|
4641
|
+
style: { position: "relative", bottom: "auto", marginBottom: "80px" }
|
|
4642
|
+
}
|
|
4643
|
+
),
|
|
4644
|
+
showSpeakButton && /* @__PURE__ */ jsx5(
|
|
4645
|
+
"div",
|
|
4646
|
+
{
|
|
4647
|
+
style: {
|
|
4648
|
+
display: "flex",
|
|
4649
|
+
justifyContent: "center"
|
|
4650
|
+
},
|
|
4651
|
+
children: /* @__PURE__ */ jsxs3(
|
|
4652
|
+
"button",
|
|
4653
|
+
{
|
|
4654
|
+
onClick: handleSpeakClick,
|
|
4655
|
+
disabled: isLoading,
|
|
4656
|
+
style: {
|
|
4657
|
+
pointerEvents: "auto",
|
|
4658
|
+
padding: "14px 28px",
|
|
4659
|
+
background: isConnected ? "linear-gradient(135deg, #ef4444 0%, #dc2626 100%)" : "linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)",
|
|
4660
|
+
color: "#fff",
|
|
4661
|
+
border: "none",
|
|
4662
|
+
borderRadius: "50px",
|
|
4663
|
+
cursor: isLoading ? "wait" : "pointer",
|
|
4664
|
+
fontSize: "15px",
|
|
4665
|
+
fontWeight: "600",
|
|
4666
|
+
display: "flex",
|
|
4667
|
+
alignItems: "center",
|
|
4668
|
+
gap: "8px",
|
|
4669
|
+
boxShadow: isConnected || isLoading ? "0 4px 20px rgba(239, 68, 68, 0.4)" : "0 4px 20px rgba(139, 92, 246, 0.4)",
|
|
4670
|
+
transition: "all 0.3s ease",
|
|
4671
|
+
transform: "scale(1)",
|
|
4672
|
+
opacity: isLoading ? 0.7 : 1
|
|
4673
|
+
},
|
|
4674
|
+
onMouseEnter: (e) => {
|
|
4675
|
+
if (!isLoading) {
|
|
4676
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
4677
|
+
e.currentTarget.style.boxShadow = isConnected ? "0 6px 25px rgba(239, 68, 68, 0.5)" : "0 6px 25px rgba(139, 92, 246, 0.5)";
|
|
4678
|
+
}
|
|
4679
|
+
},
|
|
4680
|
+
onMouseLeave: (e) => {
|
|
4681
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
4682
|
+
e.currentTarget.style.boxShadow = isConnected || isLoading ? "0 4px 20px rgba(239, 68, 68, 0.4)" : "0 4px 20px rgba(139, 92, 246, 0.4)";
|
|
4683
|
+
},
|
|
4684
|
+
onMouseDown: (e) => {
|
|
4685
|
+
if (!isLoading) {
|
|
4686
|
+
e.currentTarget.style.transform = "scale(0.95)";
|
|
4687
|
+
}
|
|
4688
|
+
},
|
|
4689
|
+
onMouseUp: (e) => {
|
|
4690
|
+
if (!isLoading) {
|
|
4691
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
4692
|
+
}
|
|
4693
|
+
},
|
|
4694
|
+
children: [
|
|
4695
|
+
/* @__PURE__ */ jsx5("span", { style: { fontSize: "18px" }, children: isLoading ? "\u23F3" : isConnected ? "\u{1F534}" : "\u{1F4AC}" }),
|
|
4696
|
+
/* @__PURE__ */ jsx5("span", { children: isLoading ? "\u8FDE\u63A5\u4E2D..." : isConnected ? "\u7ED3\u675F\u5BF9\u8BDD" : "\u5F00\u59CB\u8BF4\u8BDD" }),
|
|
4697
|
+
(isConnected || isLoading) && /* @__PURE__ */ jsx5(
|
|
4698
|
+
"span",
|
|
4699
|
+
{
|
|
4700
|
+
style: {
|
|
4701
|
+
width: "8px",
|
|
4702
|
+
height: "8px",
|
|
4703
|
+
borderRadius: "50%",
|
|
4704
|
+
background: "#fff",
|
|
4705
|
+
animation: "pulse 1.5s ease-in-out infinite"
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
)
|
|
4709
|
+
]
|
|
4710
|
+
}
|
|
4711
|
+
)
|
|
4712
|
+
}
|
|
4713
|
+
),
|
|
4714
|
+
/* @__PURE__ */ jsx5("style", { children: `
|
|
4715
|
+
@keyframes pulse {
|
|
4716
|
+
0%, 100% {
|
|
4717
|
+
opacity: 1;
|
|
4718
|
+
transform: scale(1);
|
|
4719
|
+
}
|
|
4720
|
+
50% {
|
|
4721
|
+
opacity: 0.5;
|
|
4722
|
+
transform: scale(0.8);
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
` })
|
|
4726
|
+
]
|
|
4727
|
+
}
|
|
4728
|
+
);
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4731
|
+
// src/adapters/ModelLoaderAdapter.ts
|
|
4732
|
+
import { GLTFLoader as GLTFLoader2 } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4733
|
+
var WebModelLoaderAdapter = {
|
|
4734
|
+
load: async (path, onProgress) => {
|
|
4735
|
+
if (typeof path !== "string") {
|
|
4736
|
+
throw new Error("Web \u7AEF\u6A21\u578B\u52A0\u8F7D: path \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 URL");
|
|
4737
|
+
}
|
|
4738
|
+
return new Promise((resolve, reject) => {
|
|
4739
|
+
const loader = new GLTFLoader2();
|
|
4740
|
+
loader.load(
|
|
4741
|
+
path,
|
|
4742
|
+
(gltf) => {
|
|
4743
|
+
resolve(gltf);
|
|
4744
|
+
},
|
|
4745
|
+
(event) => {
|
|
4746
|
+
if (event.lengthComputable && onProgress) {
|
|
4747
|
+
onProgress(event.loaded / event.total);
|
|
4748
|
+
}
|
|
4749
|
+
},
|
|
4750
|
+
(error) => {
|
|
4751
|
+
reject(error);
|
|
4752
|
+
}
|
|
4753
|
+
);
|
|
4754
|
+
});
|
|
4755
|
+
}
|
|
4756
|
+
};
|
|
4757
|
+
|
|
4758
|
+
// src/adapters/AnimationLoaderAdapter.ts
|
|
4759
|
+
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
|
|
4760
|
+
var WebAnimationLoaderAdapter = {
|
|
4761
|
+
load: async (path, onProgress) => {
|
|
4762
|
+
if (typeof path !== "string") {
|
|
4763
|
+
throw new Error("Web \u7AEF\u52A8\u753B\u52A0\u8F7D: path \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 URL");
|
|
4764
|
+
}
|
|
4765
|
+
return new Promise((resolve, reject) => {
|
|
4766
|
+
const loader = new FBXLoader();
|
|
4767
|
+
loader.load(
|
|
4768
|
+
path,
|
|
4769
|
+
(fbx) => {
|
|
4770
|
+
resolve(fbx);
|
|
4771
|
+
},
|
|
4772
|
+
(event) => {
|
|
4773
|
+
if (event.lengthComputable && onProgress) {
|
|
4774
|
+
onProgress(event.loaded / event.total);
|
|
4775
|
+
}
|
|
4776
|
+
},
|
|
4777
|
+
(error) => {
|
|
4778
|
+
reject(error);
|
|
4779
|
+
}
|
|
4780
|
+
);
|
|
4781
|
+
});
|
|
4782
|
+
}
|
|
4783
|
+
};
|
|
4784
|
+
|
|
4785
|
+
// src/components/CharacterView.tsx
|
|
4786
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4787
|
+
function CharacterContent({
|
|
4788
|
+
model,
|
|
4789
|
+
animationStates,
|
|
4790
|
+
initialState,
|
|
4791
|
+
initialMood,
|
|
4792
|
+
enableWelcome,
|
|
4793
|
+
onError,
|
|
4794
|
+
onReady,
|
|
4795
|
+
onStateChange,
|
|
4796
|
+
children
|
|
4797
|
+
}) {
|
|
4798
|
+
const { loadedModel, character, isReady } = useCharacterController({
|
|
4799
|
+
model,
|
|
4800
|
+
modelAdapter: WebModelLoaderAdapter,
|
|
4801
|
+
animationAdapter: WebAnimationLoaderAdapter,
|
|
4802
|
+
animationStates,
|
|
4803
|
+
initialState,
|
|
4804
|
+
initialMood,
|
|
4805
|
+
enableWelcome,
|
|
4806
|
+
onError,
|
|
4807
|
+
onStateChange
|
|
4808
|
+
});
|
|
4809
|
+
const onReadyRef = useRef(onReady);
|
|
4810
|
+
useEffect3(() => {
|
|
4811
|
+
onReadyRef.current = onReady;
|
|
4812
|
+
}, [onReady]);
|
|
4813
|
+
useEffect3(() => {
|
|
4814
|
+
if (character) {
|
|
4815
|
+
onReadyRef.current?.(character);
|
|
4816
|
+
}
|
|
4817
|
+
}, [character]);
|
|
4818
|
+
useEffect3(() => {
|
|
4819
|
+
if (loadedModel?.scene) {
|
|
4820
|
+
loadedModel.scene.visible = isReady;
|
|
4821
|
+
}
|
|
4822
|
+
}, [loadedModel, isReady]);
|
|
4823
|
+
if (!loadedModel) return null;
|
|
4824
|
+
return /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
4825
|
+
/* @__PURE__ */ jsx6("primitive", { object: loadedModel.scene }),
|
|
4826
|
+
children
|
|
4827
|
+
] });
|
|
4828
|
+
}
|
|
4829
|
+
function CharacterView(props) {
|
|
4830
|
+
const {
|
|
4831
|
+
model,
|
|
4832
|
+
animationStates,
|
|
4833
|
+
initialState,
|
|
4834
|
+
initialMood,
|
|
4835
|
+
enableWelcome,
|
|
4836
|
+
sceneConfig,
|
|
4837
|
+
controlsConfig,
|
|
4838
|
+
overlay,
|
|
4839
|
+
style,
|
|
4840
|
+
className,
|
|
4841
|
+
children,
|
|
4842
|
+
onError,
|
|
4843
|
+
onReady,
|
|
4844
|
+
onStateChange
|
|
4845
|
+
} = props;
|
|
4846
|
+
const [subtitle, setSubtitle] = useState2("");
|
|
4847
|
+
const characterRef = useRef(null);
|
|
4848
|
+
const appendSubtitle = useCallback((text) => {
|
|
4849
|
+
setSubtitle((prev) => prev + text);
|
|
4850
|
+
}, []);
|
|
4851
|
+
const replaceSubtitle = useCallback((text) => {
|
|
4852
|
+
setSubtitle(text);
|
|
4853
|
+
}, []);
|
|
4854
|
+
const clearSubtitle = useCallback(() => {
|
|
4855
|
+
setSubtitle("");
|
|
4856
|
+
}, []);
|
|
4857
|
+
const handleReady = useCallback((character) => {
|
|
4858
|
+
character.appendSubtitle = appendSubtitle;
|
|
4859
|
+
character.setSubtitle = replaceSubtitle;
|
|
4860
|
+
character.clearSubtitle = clearSubtitle;
|
|
4861
|
+
characterRef.current = character;
|
|
4862
|
+
onReady?.(character);
|
|
4863
|
+
}, [onReady, appendSubtitle, replaceSubtitle, clearSubtitle]);
|
|
4864
|
+
const handleStartSpeak = useCallback(() => {
|
|
4865
|
+
characterRef.current?.startSpeak();
|
|
4866
|
+
}, []);
|
|
4867
|
+
const handleStopSpeak = useCallback(() => {
|
|
4868
|
+
characterRef.current?.stopSpeak();
|
|
4869
|
+
}, []);
|
|
4870
|
+
return /* @__PURE__ */ jsxs4("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
|
|
4871
|
+
/* @__PURE__ */ jsx6(
|
|
4872
|
+
Scene3D,
|
|
4873
|
+
{
|
|
4874
|
+
config: sceneConfig,
|
|
4875
|
+
controlsConfig,
|
|
4876
|
+
style,
|
|
4877
|
+
className,
|
|
4878
|
+
showProgress: false,
|
|
4879
|
+
children: /* @__PURE__ */ jsx6(Suspense, { fallback: null, children: /* @__PURE__ */ jsx6(
|
|
4880
|
+
CharacterContent,
|
|
4881
|
+
{
|
|
4882
|
+
model,
|
|
4883
|
+
animationStates,
|
|
4884
|
+
initialState,
|
|
4885
|
+
initialMood,
|
|
4886
|
+
enableWelcome,
|
|
4887
|
+
onError,
|
|
4888
|
+
onReady: handleReady,
|
|
4889
|
+
onStateChange,
|
|
4890
|
+
children
|
|
4891
|
+
}
|
|
4892
|
+
) })
|
|
4893
|
+
}
|
|
4894
|
+
),
|
|
4895
|
+
overlay?.show && /* @__PURE__ */ jsx6(
|
|
4896
|
+
CharacterOverlay,
|
|
4897
|
+
{
|
|
4898
|
+
visible: true,
|
|
4899
|
+
subtitle,
|
|
4900
|
+
showSpeakButton: overlay.showSpeakButton ?? true,
|
|
4901
|
+
isLoading: overlay.isLoading,
|
|
4902
|
+
isConnected: overlay.isConnected,
|
|
4903
|
+
onStartSpeak: handleStartSpeak,
|
|
4904
|
+
onStopSpeak: handleStopSpeak,
|
|
4905
|
+
onButtonClick: overlay.onButtonClick,
|
|
4906
|
+
subtitleStyle: overlay.subtitleStyle,
|
|
4907
|
+
style: overlay.style
|
|
4908
|
+
}
|
|
4909
|
+
)
|
|
4910
|
+
] });
|
|
4911
|
+
}
|
|
4912
|
+
export {
|
|
4913
|
+
CharacterOverlay,
|
|
4914
|
+
CharacterView,
|
|
4915
|
+
Scene3D,
|
|
4916
|
+
Subtitle,
|
|
4917
|
+
WebSceneBuilder,
|
|
4918
|
+
useGLTF as useModelLoader
|
|
4919
|
+
};
|
|
4920
|
+
/*! Bundled license information:
|
|
4921
|
+
|
|
4922
|
+
camera-controls/dist/camera-controls.module.js:
|
|
4923
|
+
(*!
|
|
4924
|
+
* camera-controls
|
|
4925
|
+
* https://github.com/yomotsu/camera-controls
|
|
4926
|
+
* (c) 2017 @yomotsu
|
|
4927
|
+
* Released under the MIT License.
|
|
4928
|
+
*)
|
|
4929
|
+
*/
|