@tonybfox/threejs-tools 1.0.5 → 1.0.6
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/asset-loader/index.cjs +3 -417
- package/dist/asset-loader/index.mjs +1 -6
- package/dist/camera/index.cjs +1 -393
- package/dist/camera/index.mjs +1 -6
- package/dist/chunk-4O4ENFL7.mjs +83 -0
- package/dist/chunk-55YVGK52.mjs +1 -0
- package/dist/chunk-B75TYEOO.mjs +44 -0
- package/dist/chunk-EQRUOKFV.mjs +1 -0
- package/dist/chunk-JRJBW66X.mjs +1 -0
- package/dist/chunk-OJFYE56U.mjs +1 -0
- package/dist/chunk-UJF4S4J3.mjs +1 -0
- package/dist/chunk-WZ4X7GQ2.mjs +1 -0
- package/dist/chunk-Z5VL3O6M.mjs +43 -0
- package/dist/compass/index.cjs +3 -304
- package/dist/compass/index.mjs +1 -6
- package/dist/grid/index.cjs +3 -159
- package/dist/grid/index.mjs +1 -6
- package/dist/index.cjs +7 -5406
- package/dist/index.mjs +1 -384
- package/dist/measurements/index.cjs +1 -1197
- package/dist/measurements/index.mjs +1 -8
- package/dist/sunlight/index.cjs +1 -440
- package/dist/sunlight/index.d.mts +19 -0
- package/dist/sunlight/index.d.ts +19 -0
- package/dist/sunlight/index.mjs +1 -6
- package/dist/terrain/index.cjs +1 -422
- package/dist/terrain/index.mjs +1 -6
- package/dist/transform-controls/index.cjs +1 -1586
- package/dist/transform-controls/index.mjs +1 -12
- package/dist/view-helper/index.cjs +1 -435
- package/dist/view-helper/index.mjs +1 -6
- package/package.json +1 -1
- package/dist/chunk-2CDI7ORN.mjs +0 -163
- package/dist/chunk-FBTT6MU6.mjs +0 -386
- package/dist/chunk-IAZH4OHC.mjs +0 -399
- package/dist/chunk-LUE7VHLK.mjs +0 -422
- package/dist/chunk-OZKJ3GAD.mjs +0 -1160
- package/dist/chunk-W4DAAAW6.mjs +0 -404
- package/dist/chunk-XA7OKYSM.mjs +0 -357
- package/dist/chunk-YMMLYGHV.mjs +0 -1578
- package/dist/chunk-ZNGFST7K.mjs +0 -348
|
@@ -1,95 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/asset-loader/src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
AssetLoader: () => AssetLoader
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
|
|
37
|
-
// packages/asset-loader/src/AssetLoader.ts
|
|
38
|
-
var THREE = __toESM(require("three"));
|
|
39
|
-
var import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader.js");
|
|
40
|
-
var import_FBXLoader = require("three/examples/jsm/loaders/FBXLoader.js");
|
|
41
|
-
var import_OBJLoader = require("three/examples/jsm/loaders/OBJLoader.js");
|
|
42
|
-
var import_USDLoader = require("three/examples/jsm/loaders/USDLoader.js");
|
|
43
|
-
var import_ColladaLoader = require("three/examples/jsm/loaders/ColladaLoader.js");
|
|
44
|
-
var import_STLLoader = require("three/examples/jsm/loaders/STLLoader.js");
|
|
45
|
-
var import_PLYLoader = require("three/examples/jsm/loaders/PLYLoader.js");
|
|
46
|
-
var import_MFLoader = require("three/examples/jsm/loaders/3MFLoader.js");
|
|
47
|
-
var AssetLoader = class extends THREE.EventDispatcher {
|
|
48
|
-
constructor() {
|
|
49
|
-
super();
|
|
50
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
51
|
-
this.placeholder = null;
|
|
52
|
-
this.loadedAsset = null;
|
|
53
|
-
this.lowResAsset = null;
|
|
54
|
-
this.errorColor = 16729156;
|
|
55
|
-
this.errorOpacity = 0.5;
|
|
56
|
-
this.gltfLoader = new import_GLTFLoader.GLTFLoader();
|
|
57
|
-
this.fbxLoader = new import_FBXLoader.FBXLoader();
|
|
58
|
-
this.objLoader = new import_OBJLoader.OBJLoader();
|
|
59
|
-
this.usdLoader = new import_USDLoader.USDLoader();
|
|
60
|
-
this.colladaLoader = new import_ColladaLoader.ColladaLoader();
|
|
61
|
-
this.stlLoader = new import_STLLoader.STLLoader();
|
|
62
|
-
this.plyLoader = new import_PLYLoader.PLYLoader();
|
|
63
|
-
this.threeMFLoader = new import_MFLoader.ThreeMFLoader();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Create a placeholder cube with shader effect
|
|
67
|
-
*/
|
|
68
|
-
createPlaceholder(size, color = 5227511, opacity = 0.3) {
|
|
69
|
-
const [width, height, depth] = size;
|
|
70
|
-
const geometry = new THREE.BoxGeometry(width, height, depth);
|
|
71
|
-
const material = new THREE.ShaderMaterial({
|
|
72
|
-
side: THREE.DoubleSide,
|
|
73
|
-
depthWrite: false,
|
|
74
|
-
blending: THREE.AdditiveBlending,
|
|
75
|
-
transparent: true,
|
|
76
|
-
uniforms: {
|
|
77
|
-
color: { value: new THREE.Color(color) },
|
|
78
|
-
opacity: { value: opacity },
|
|
79
|
-
fillProgress: { value: 0 },
|
|
80
|
-
time: { value: 0 },
|
|
81
|
-
isError: { value: 0 },
|
|
82
|
-
yMin: { value: -height / 2 },
|
|
83
|
-
yMax: { value: height / 2 }
|
|
84
|
-
},
|
|
85
|
-
vertexShader: `
|
|
1
|
+
"use strict";var H=Object.create;var u=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var D=(n,c)=>{for(var e in c)u(n,e,{get:c[e],enumerable:!0})},b=(n,c,e,t)=>{if(c&&typeof c=="object"||typeof c=="function")for(let a of O(c))!x.call(n,a)&&a!==e&&u(n,a,{get:()=>c[a],enumerable:!(t=M(c,a))||t.enumerable});return n};var B=(n,c,e)=>(e=n!=null?H(P(n)):{},b(c||!n||!n.__esModule?u(e,"default",{value:n,enumerable:!0}):e,n)),z=n=>b(u({},"__esModule",{value:!0}),n);var j={};D(j,{AssetLoader:()=>E});module.exports=z(j);var o=B(require("three")),y=require("three/examples/jsm/loaders/GLTFLoader.js"),v=require("three/examples/jsm/loaders/FBXLoader.js"),R=require("three/examples/jsm/loaders/OBJLoader.js"),L=require("three/examples/jsm/loaders/USDLoader.js"),T=require("three/examples/jsm/loaders/ColladaLoader.js"),g=require("three/examples/jsm/loaders/STLLoader.js"),C=require("three/examples/jsm/loaders/PLYLoader.js"),w=require("three/examples/jsm/loaders/3MFLoader.js"),E=class extends o.EventDispatcher{constructor(){super();this.cache=new Map;this.placeholder=null;this.loadedAsset=null;this.lowResAsset=null;this.errorColor=16729156;this.errorOpacity=.5;this.gltfLoader=new y.GLTFLoader,this.fbxLoader=new v.FBXLoader,this.objLoader=new R.OBJLoader,this.usdLoader=new L.USDLoader,this.colladaLoader=new T.ColladaLoader,this.stlLoader=new g.STLLoader,this.plyLoader=new C.PLYLoader,this.threeMFLoader=new w.ThreeMFLoader}createPlaceholder(e,t=5227511,a=.3){let[s,p,l]=e,h=new o.BoxGeometry(s,p,l),r=new o.ShaderMaterial({side:o.DoubleSide,depthWrite:!1,blending:o.AdditiveBlending,transparent:!0,uniforms:{color:{value:new o.Color(t)},opacity:{value:a},fillProgress:{value:0},time:{value:0},isError:{value:0},yMin:{value:-p/2},yMax:{value:p/2}},vertexShader:`
|
|
86
2
|
varying vec3 vPosition;
|
|
87
3
|
void main() {
|
|
88
4
|
vPosition = position;
|
|
89
5
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
90
6
|
}
|
|
91
|
-
`,
|
|
92
|
-
fragmentShader: `
|
|
7
|
+
`,fragmentShader:`
|
|
93
8
|
uniform vec3 color;
|
|
94
9
|
uniform float opacity;
|
|
95
10
|
uniform float fillProgress;
|
|
@@ -126,333 +41,4 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
126
41
|
vec3 finalColor = color + edgeIntensity * 0.5;
|
|
127
42
|
gl_FragColor = vec4(finalColor, alpha);
|
|
128
43
|
}
|
|
129
|
-
`
|
|
130
|
-
});
|
|
131
|
-
const mesh = new THREE.Mesh(geometry, material);
|
|
132
|
-
this.positionAssetAtBottomCenter(mesh);
|
|
133
|
-
return mesh;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Update placeholder fill progress based on loading progress
|
|
137
|
-
*/
|
|
138
|
-
updatePlaceholder(progress) {
|
|
139
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
140
|
-
const material = this.placeholder.material;
|
|
141
|
-
if (material.uniforms && material.uniforms.fillProgress) {
|
|
142
|
-
material.uniforms.fillProgress.value = progress;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Set placeholder to error state with configurable color and opacity
|
|
148
|
-
*/
|
|
149
|
-
setPlaceholderError() {
|
|
150
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
151
|
-
const material = this.placeholder.material;
|
|
152
|
-
if (material.uniforms) {
|
|
153
|
-
if (material.uniforms.color) {
|
|
154
|
-
material.uniforms.color.value = new THREE.Color(this.errorColor);
|
|
155
|
-
}
|
|
156
|
-
if (material.uniforms.opacity) {
|
|
157
|
-
material.uniforms.opacity.value = this.errorOpacity;
|
|
158
|
-
}
|
|
159
|
-
if (material.uniforms.fillProgress) {
|
|
160
|
-
material.uniforms.fillProgress.value = 0;
|
|
161
|
-
}
|
|
162
|
-
if (material.uniforms.isError) {
|
|
163
|
-
material.uniforms.isError.value = 1;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Update placeholder animation time (call this in your render loop)
|
|
170
|
-
*/
|
|
171
|
-
updatePlaceholderAnimation(deltaTime) {
|
|
172
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
173
|
-
const material = this.placeholder.material;
|
|
174
|
-
if (material.uniforms && material.uniforms.time) {
|
|
175
|
-
material.uniforms.time.value += deltaTime;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Reposition an asset so that its bottom-center sits at the local origin.
|
|
181
|
-
*/
|
|
182
|
-
positionAssetAtBottomCenter(object) {
|
|
183
|
-
object.updateMatrixWorld(true);
|
|
184
|
-
const boundingBox = new THREE.Box3().setFromObject(object);
|
|
185
|
-
if (boundingBox.isEmpty()) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const center = boundingBox.getCenter(new THREE.Vector3());
|
|
189
|
-
const bottomCenter = new THREE.Vector3(
|
|
190
|
-
center.x,
|
|
191
|
-
boundingBox.min.y - 0.01,
|
|
192
|
-
center.z
|
|
193
|
-
);
|
|
194
|
-
if (!Number.isFinite(bottomCenter.x) || !Number.isFinite(bottomCenter.y) || !Number.isFinite(bottomCenter.z)) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
object.position.sub(bottomCenter);
|
|
198
|
-
object.userData.bottomCenterOffset = bottomCenter;
|
|
199
|
-
object.updateMatrixWorld(true);
|
|
200
|
-
}
|
|
201
|
-
ensureBottomCenterOffset(object) {
|
|
202
|
-
const offset = object.userData.bottomCenterOffset;
|
|
203
|
-
if (offset instanceof THREE.Vector3) {
|
|
204
|
-
return offset;
|
|
205
|
-
}
|
|
206
|
-
if (offset && typeof offset === "object") {
|
|
207
|
-
const {
|
|
208
|
-
x = 0,
|
|
209
|
-
y = 0,
|
|
210
|
-
z = 0
|
|
211
|
-
} = offset;
|
|
212
|
-
const normalized = new THREE.Vector3(x ?? 0, y ?? 0, z ?? 0);
|
|
213
|
-
object.userData.bottomCenterOffset = normalized;
|
|
214
|
-
return normalized;
|
|
215
|
-
}
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
normalizeBottomCenterData(object) {
|
|
219
|
-
const hasOffset = this.ensureBottomCenterOffset(object) !== null;
|
|
220
|
-
object.children.forEach((child) => this.normalizeBottomCenterData(child));
|
|
221
|
-
return hasOffset;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Load an asset with the specified options
|
|
225
|
-
*/
|
|
226
|
-
async load(options) {
|
|
227
|
-
const {
|
|
228
|
-
type,
|
|
229
|
-
url,
|
|
230
|
-
size,
|
|
231
|
-
lowResUrl,
|
|
232
|
-
enableCaching = true,
|
|
233
|
-
disablePlaceholder = false,
|
|
234
|
-
placeholderColor = 5227511,
|
|
235
|
-
placeholderOpacity = 0.4,
|
|
236
|
-
errorColor = 16729156,
|
|
237
|
-
errorOpacity = 0.5
|
|
238
|
-
} = options;
|
|
239
|
-
if (enableCaching && this.cache.has(url)) {
|
|
240
|
-
const cachedClone = this.cache.get(url).clone(true);
|
|
241
|
-
const hasOffset = this.normalizeBottomCenterData(cachedClone);
|
|
242
|
-
if (!hasOffset) {
|
|
243
|
-
this.positionAssetAtBottomCenter(cachedClone);
|
|
244
|
-
} else {
|
|
245
|
-
cachedClone.updateMatrixWorld(true);
|
|
246
|
-
}
|
|
247
|
-
this.loadedAsset = cachedClone;
|
|
248
|
-
this.dispatchEvent({ type: "loaded", asset: cachedClone });
|
|
249
|
-
return cachedClone;
|
|
250
|
-
}
|
|
251
|
-
this.errorColor = errorColor;
|
|
252
|
-
this.errorOpacity = errorOpacity;
|
|
253
|
-
if (size && !disablePlaceholder) {
|
|
254
|
-
this.placeholder = this.createPlaceholder(
|
|
255
|
-
size,
|
|
256
|
-
placeholderColor,
|
|
257
|
-
placeholderOpacity
|
|
258
|
-
);
|
|
259
|
-
this.dispatchEvent({
|
|
260
|
-
type: "placeholderCreated",
|
|
261
|
-
placeholder: this.placeholder
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
if (lowResUrl) {
|
|
266
|
-
const lowRes = await this.loadModel(type, lowResUrl, true);
|
|
267
|
-
this.lowResAsset = lowRes;
|
|
268
|
-
this.dispatchEvent({ type: "lowResLoaded", lowRes });
|
|
269
|
-
}
|
|
270
|
-
const asset = await this.loadModel(type, url, false);
|
|
271
|
-
this.loadedAsset = asset;
|
|
272
|
-
if (enableCaching) {
|
|
273
|
-
const cacheEntry = asset.clone(true);
|
|
274
|
-
const hasOffset = this.normalizeBottomCenterData(cacheEntry);
|
|
275
|
-
if (!hasOffset) {
|
|
276
|
-
this.positionAssetAtBottomCenter(cacheEntry);
|
|
277
|
-
} else {
|
|
278
|
-
cacheEntry.updateMatrixWorld(true);
|
|
279
|
-
}
|
|
280
|
-
this.cache.set(url, cacheEntry);
|
|
281
|
-
}
|
|
282
|
-
this.dispatchEvent({ type: "loaded", asset });
|
|
283
|
-
return asset;
|
|
284
|
-
} catch (error) {
|
|
285
|
-
this.setPlaceholderError();
|
|
286
|
-
this.dispatchEvent({ type: "error", error });
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Load a model based on type
|
|
292
|
-
*/
|
|
293
|
-
loadModel(type, url, isLowRes) {
|
|
294
|
-
return new Promise((resolve, reject) => {
|
|
295
|
-
const onProgress = (event) => {
|
|
296
|
-
let percentage = -1;
|
|
297
|
-
if (event.lengthComputable && event.total > 0 && event.loaded <= event.total) {
|
|
298
|
-
percentage = event.loaded / event.total * 100;
|
|
299
|
-
}
|
|
300
|
-
this.dispatchEvent({
|
|
301
|
-
type: "progress",
|
|
302
|
-
loaded: event.loaded,
|
|
303
|
-
total: event.total,
|
|
304
|
-
percentage
|
|
305
|
-
});
|
|
306
|
-
if (!isLowRes && percentage >= 0) {
|
|
307
|
-
this.updatePlaceholder(percentage / 100);
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
const onError = (error) => {
|
|
311
|
-
reject(error);
|
|
312
|
-
};
|
|
313
|
-
switch (type) {
|
|
314
|
-
case "gltf":
|
|
315
|
-
this.gltfLoader.load(
|
|
316
|
-
url,
|
|
317
|
-
(gltf) => {
|
|
318
|
-
const scene = gltf.scene;
|
|
319
|
-
this.positionAssetAtBottomCenter(scene);
|
|
320
|
-
resolve(scene);
|
|
321
|
-
},
|
|
322
|
-
onProgress,
|
|
323
|
-
onError
|
|
324
|
-
);
|
|
325
|
-
break;
|
|
326
|
-
case "fbx":
|
|
327
|
-
this.fbxLoader.load(
|
|
328
|
-
url,
|
|
329
|
-
(fbx) => {
|
|
330
|
-
this.positionAssetAtBottomCenter(fbx);
|
|
331
|
-
resolve(fbx);
|
|
332
|
-
},
|
|
333
|
-
onProgress,
|
|
334
|
-
onError
|
|
335
|
-
);
|
|
336
|
-
break;
|
|
337
|
-
case "obj":
|
|
338
|
-
this.objLoader.load(
|
|
339
|
-
url,
|
|
340
|
-
(obj) => {
|
|
341
|
-
this.positionAssetAtBottomCenter(obj);
|
|
342
|
-
resolve(obj);
|
|
343
|
-
},
|
|
344
|
-
onProgress,
|
|
345
|
-
onError
|
|
346
|
-
);
|
|
347
|
-
break;
|
|
348
|
-
case "usd":
|
|
349
|
-
case "usdz":
|
|
350
|
-
this.usdLoader.load(
|
|
351
|
-
url,
|
|
352
|
-
(usd) => {
|
|
353
|
-
this.positionAssetAtBottomCenter(usd);
|
|
354
|
-
resolve(usd);
|
|
355
|
-
},
|
|
356
|
-
onProgress,
|
|
357
|
-
onError
|
|
358
|
-
);
|
|
359
|
-
break;
|
|
360
|
-
case "dae":
|
|
361
|
-
this.colladaLoader.load(
|
|
362
|
-
url,
|
|
363
|
-
(collada) => {
|
|
364
|
-
const scene = collada.scene;
|
|
365
|
-
this.positionAssetAtBottomCenter(scene);
|
|
366
|
-
resolve(scene);
|
|
367
|
-
},
|
|
368
|
-
onProgress,
|
|
369
|
-
onError
|
|
370
|
-
);
|
|
371
|
-
break;
|
|
372
|
-
case "stl":
|
|
373
|
-
this.stlLoader.load(
|
|
374
|
-
url,
|
|
375
|
-
(geometry) => {
|
|
376
|
-
const material = new THREE.MeshStandardMaterial({
|
|
377
|
-
color: 8947848
|
|
378
|
-
});
|
|
379
|
-
const mesh = new THREE.Mesh(geometry, material);
|
|
380
|
-
this.positionAssetAtBottomCenter(mesh);
|
|
381
|
-
resolve(mesh);
|
|
382
|
-
},
|
|
383
|
-
onProgress,
|
|
384
|
-
onError
|
|
385
|
-
);
|
|
386
|
-
break;
|
|
387
|
-
case "ply":
|
|
388
|
-
this.plyLoader.load(
|
|
389
|
-
url,
|
|
390
|
-
(geometry) => {
|
|
391
|
-
const material = new THREE.MeshStandardMaterial({
|
|
392
|
-
vertexColors: true
|
|
393
|
-
});
|
|
394
|
-
const mesh = new THREE.Mesh(geometry, material);
|
|
395
|
-
this.positionAssetAtBottomCenter(mesh);
|
|
396
|
-
resolve(mesh);
|
|
397
|
-
},
|
|
398
|
-
onProgress,
|
|
399
|
-
onError
|
|
400
|
-
);
|
|
401
|
-
break;
|
|
402
|
-
case "3mf":
|
|
403
|
-
this.threeMFLoader.load(
|
|
404
|
-
url,
|
|
405
|
-
(object) => {
|
|
406
|
-
this.positionAssetAtBottomCenter(object);
|
|
407
|
-
resolve(object);
|
|
408
|
-
},
|
|
409
|
-
onProgress,
|
|
410
|
-
onError
|
|
411
|
-
);
|
|
412
|
-
break;
|
|
413
|
-
default:
|
|
414
|
-
reject(new Error(`Unsupported asset type: ${type}`));
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Get the placeholder object
|
|
420
|
-
*/
|
|
421
|
-
getPlaceholder() {
|
|
422
|
-
return this.placeholder;
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Get the loaded asset
|
|
426
|
-
*/
|
|
427
|
-
getAsset() {
|
|
428
|
-
return this.loadedAsset;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Get the low-res asset
|
|
432
|
-
*/
|
|
433
|
-
getLowResAsset() {
|
|
434
|
-
return this.lowResAsset;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Clear the cache
|
|
438
|
-
*/
|
|
439
|
-
clearCache() {
|
|
440
|
-
this.cache.clear();
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Remove an item from cache
|
|
444
|
-
*/
|
|
445
|
-
removeFromCache(url) {
|
|
446
|
-
this.cache.delete(url);
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Get cache size
|
|
450
|
-
*/
|
|
451
|
-
getCacheSize() {
|
|
452
|
-
return this.cache.size;
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
456
|
-
0 && (module.exports = {
|
|
457
|
-
AssetLoader
|
|
458
|
-
});
|
|
44
|
+
`}),i=new o.Mesh(h,r);return this.positionAssetAtBottomCenter(i),i}updatePlaceholder(e){if(this.placeholder&&this.placeholder instanceof o.Mesh){let t=this.placeholder.material;t.uniforms&&t.uniforms.fillProgress&&(t.uniforms.fillProgress.value=e)}}setPlaceholderError(){if(this.placeholder&&this.placeholder instanceof o.Mesh){let e=this.placeholder.material;e.uniforms&&(e.uniforms.color&&(e.uniforms.color.value=new o.Color(this.errorColor)),e.uniforms.opacity&&(e.uniforms.opacity.value=this.errorOpacity),e.uniforms.fillProgress&&(e.uniforms.fillProgress.value=0),e.uniforms.isError&&(e.uniforms.isError.value=1))}}updatePlaceholderAnimation(e){if(this.placeholder&&this.placeholder instanceof o.Mesh){let t=this.placeholder.material;t.uniforms&&t.uniforms.time&&(t.uniforms.time.value+=e)}}positionAssetAtBottomCenter(e){e.updateMatrixWorld(!0);let t=new o.Box3().setFromObject(e);if(t.isEmpty())return;let a=t.getCenter(new o.Vector3),s=new o.Vector3(a.x,t.min.y-.01,a.z);!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.z)||(e.position.sub(s),e.userData.bottomCenterOffset=s,e.updateMatrixWorld(!0))}ensureBottomCenterOffset(e){let t=e.userData.bottomCenterOffset;if(t instanceof o.Vector3)return t;if(t&&typeof t=="object"){let{x:a=0,y:s=0,z:p=0}=t,l=new o.Vector3(a??0,s??0,p??0);return e.userData.bottomCenterOffset=l,l}return null}normalizeBottomCenterData(e){let t=this.ensureBottomCenterOffset(e)!==null;return e.children.forEach(a=>this.normalizeBottomCenterData(a)),t}async load(e){let{type:t,url:a,size:s,lowResUrl:p,enableCaching:l=!0,disablePlaceholder:h=!1,placeholderColor:r=5227511,placeholderOpacity:i=.4,errorColor:m=16729156,errorOpacity:A=.5}=e;if(l&&this.cache.has(a)){let d=this.cache.get(a).clone(!0);return this.normalizeBottomCenterData(d)?d.updateMatrixWorld(!0):this.positionAssetAtBottomCenter(d),this.loadedAsset=d,this.dispatchEvent({type:"loaded",asset:d}),d}this.errorColor=m,this.errorOpacity=A,s&&!h&&(this.placeholder=this.createPlaceholder(s,r,i),this.dispatchEvent({type:"placeholderCreated",placeholder:this.placeholder}));try{if(p){let f=await this.loadModel(t,p,!0);this.lowResAsset=f,this.dispatchEvent({type:"lowResLoaded",lowRes:f})}let d=await this.loadModel(t,a,!1);if(this.loadedAsset=d,l){let f=d.clone(!0);this.normalizeBottomCenterData(f)?f.updateMatrixWorld(!0):this.positionAssetAtBottomCenter(f),this.cache.set(a,f)}return this.dispatchEvent({type:"loaded",asset:d}),d}catch(d){throw this.setPlaceholderError(),this.dispatchEvent({type:"error",error:d}),d}}loadModel(e,t,a){return new Promise((s,p)=>{let l=r=>{let i=-1;r.lengthComputable&&r.total>0&&r.loaded<=r.total&&(i=r.loaded/r.total*100),this.dispatchEvent({type:"progress",loaded:r.loaded,total:r.total,percentage:i}),!a&&i>=0&&this.updatePlaceholder(i/100)},h=r=>{p(r)};switch(e){case"gltf":this.gltfLoader.load(t,r=>{let i=r.scene;this.positionAssetAtBottomCenter(i),s(i)},l,h);break;case"fbx":this.fbxLoader.load(t,r=>{this.positionAssetAtBottomCenter(r),s(r)},l,h);break;case"obj":this.objLoader.load(t,r=>{this.positionAssetAtBottomCenter(r),s(r)},l,h);break;case"usd":case"usdz":this.usdLoader.load(t,r=>{this.positionAssetAtBottomCenter(r),s(r)},l,h);break;case"dae":this.colladaLoader.load(t,r=>{let i=r.scene;this.positionAssetAtBottomCenter(i),s(i)},l,h);break;case"stl":this.stlLoader.load(t,r=>{let i=new o.MeshStandardMaterial({color:8947848}),m=new o.Mesh(r,i);this.positionAssetAtBottomCenter(m),s(m)},l,h);break;case"ply":this.plyLoader.load(t,r=>{let i=new o.MeshStandardMaterial({vertexColors:!0}),m=new o.Mesh(r,i);this.positionAssetAtBottomCenter(m),s(m)},l,h);break;case"3mf":this.threeMFLoader.load(t,r=>{this.positionAssetAtBottomCenter(r),s(r)},l,h);break;default:p(new Error(`Unsupported asset type: ${e}`))}})}getPlaceholder(){return this.placeholder}getAsset(){return this.loadedAsset}getLowResAsset(){return this.lowResAsset}clearCache(){this.cache.clear()}removeFromCache(e){this.cache.delete(e)}getCacheSize(){return this.cache.size}};0&&(module.exports={AssetLoader});
|