@tonybfox/threejs-tools 1.0.4 → 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 -355
- package/dist/asset-loader/index.d.mts +6 -1
- package/dist/asset-loader/index.d.ts +6 -1
- 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 -5005
- package/dist/index.d.mts +169 -1
- package/dist/index.d.ts +169 -1
- package/dist/index.mjs +1 -46
- 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-27WUVRGX.mjs +0 -360
- package/dist/chunk-2CDI7ORN.mjs +0 -163
- package/dist/chunk-FBTT6MU6.mjs +0 -386
- package/dist/chunk-IAZH4OHC.mjs +0 -399
- 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,87 +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 AssetLoader = class extends THREE.EventDispatcher {
|
|
44
|
-
constructor() {
|
|
45
|
-
super();
|
|
46
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
47
|
-
this.placeholder = null;
|
|
48
|
-
this.loadedAsset = null;
|
|
49
|
-
this.lowResAsset = null;
|
|
50
|
-
this.errorColor = 16729156;
|
|
51
|
-
this.errorOpacity = 0.5;
|
|
52
|
-
this.gltfLoader = new import_GLTFLoader.GLTFLoader();
|
|
53
|
-
this.fbxLoader = new import_FBXLoader.FBXLoader();
|
|
54
|
-
this.objLoader = new import_OBJLoader.OBJLoader();
|
|
55
|
-
this.usdLoader = new import_USDLoader.USDLoader();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Create a placeholder cube with shader effect
|
|
59
|
-
*/
|
|
60
|
-
createPlaceholder(size, color = 5227511, opacity = 0.3) {
|
|
61
|
-
const [width, height, depth] = size;
|
|
62
|
-
const geometry = new THREE.BoxGeometry(width, height, depth);
|
|
63
|
-
const material = new THREE.ShaderMaterial({
|
|
64
|
-
side: THREE.DoubleSide,
|
|
65
|
-
depthWrite: false,
|
|
66
|
-
blending: THREE.AdditiveBlending,
|
|
67
|
-
transparent: true,
|
|
68
|
-
uniforms: {
|
|
69
|
-
color: { value: new THREE.Color(color) },
|
|
70
|
-
opacity: { value: opacity },
|
|
71
|
-
fillProgress: { value: 0 },
|
|
72
|
-
time: { value: 0 },
|
|
73
|
-
isError: { value: 0 },
|
|
74
|
-
yMin: { value: -height / 2 },
|
|
75
|
-
yMax: { value: height / 2 }
|
|
76
|
-
},
|
|
77
|
-
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:`
|
|
78
2
|
varying vec3 vPosition;
|
|
79
3
|
void main() {
|
|
80
4
|
vPosition = position;
|
|
81
5
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
82
6
|
}
|
|
83
|
-
`,
|
|
84
|
-
fragmentShader: `
|
|
7
|
+
`,fragmentShader:`
|
|
85
8
|
uniform vec3 color;
|
|
86
9
|
uniform float opacity;
|
|
87
10
|
uniform float fillProgress;
|
|
@@ -118,279 +41,4 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
118
41
|
vec3 finalColor = color + edgeIntensity * 0.5;
|
|
119
42
|
gl_FragColor = vec4(finalColor, alpha);
|
|
120
43
|
}
|
|
121
|
-
`
|
|
122
|
-
});
|
|
123
|
-
const mesh = new THREE.Mesh(geometry, material);
|
|
124
|
-
this.positionAssetAtBottomCenter(mesh);
|
|
125
|
-
return mesh;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Update placeholder fill progress based on loading progress
|
|
129
|
-
*/
|
|
130
|
-
updatePlaceholder(progress) {
|
|
131
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
132
|
-
const material = this.placeholder.material;
|
|
133
|
-
if (material.uniforms && material.uniforms.fillProgress) {
|
|
134
|
-
material.uniforms.fillProgress.value = progress;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Set placeholder to error state with configurable color and opacity
|
|
140
|
-
*/
|
|
141
|
-
setPlaceholderError() {
|
|
142
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
143
|
-
const material = this.placeholder.material;
|
|
144
|
-
if (material.uniforms) {
|
|
145
|
-
if (material.uniforms.color) {
|
|
146
|
-
material.uniforms.color.value = new THREE.Color(this.errorColor);
|
|
147
|
-
}
|
|
148
|
-
if (material.uniforms.opacity) {
|
|
149
|
-
material.uniforms.opacity.value = this.errorOpacity;
|
|
150
|
-
}
|
|
151
|
-
if (material.uniforms.fillProgress) {
|
|
152
|
-
material.uniforms.fillProgress.value = 0;
|
|
153
|
-
}
|
|
154
|
-
if (material.uniforms.isError) {
|
|
155
|
-
material.uniforms.isError.value = 1;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Update placeholder animation time (call this in your render loop)
|
|
162
|
-
*/
|
|
163
|
-
updatePlaceholderAnimation(deltaTime) {
|
|
164
|
-
if (this.placeholder && this.placeholder instanceof THREE.Mesh) {
|
|
165
|
-
const material = this.placeholder.material;
|
|
166
|
-
if (material.uniforms && material.uniforms.time) {
|
|
167
|
-
material.uniforms.time.value += deltaTime;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Reposition an asset so that its bottom-center sits at the local origin.
|
|
173
|
-
*/
|
|
174
|
-
positionAssetAtBottomCenter(object) {
|
|
175
|
-
object.updateMatrixWorld(true);
|
|
176
|
-
const boundingBox = new THREE.Box3().setFromObject(object);
|
|
177
|
-
if (boundingBox.isEmpty()) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const center = boundingBox.getCenter(new THREE.Vector3());
|
|
181
|
-
const bottomCenter = new THREE.Vector3(
|
|
182
|
-
center.x,
|
|
183
|
-
boundingBox.min.y + 0.01,
|
|
184
|
-
center.z
|
|
185
|
-
);
|
|
186
|
-
if (!Number.isFinite(bottomCenter.x) || !Number.isFinite(bottomCenter.y) || !Number.isFinite(bottomCenter.z)) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
object.position.sub(bottomCenter);
|
|
190
|
-
object.userData.bottomCenterOffset = bottomCenter;
|
|
191
|
-
object.updateMatrixWorld(true);
|
|
192
|
-
}
|
|
193
|
-
ensureBottomCenterOffset(object) {
|
|
194
|
-
const offset = object.userData.bottomCenterOffset;
|
|
195
|
-
if (offset instanceof THREE.Vector3) {
|
|
196
|
-
return offset;
|
|
197
|
-
}
|
|
198
|
-
if (offset && typeof offset === "object") {
|
|
199
|
-
const {
|
|
200
|
-
x = 0,
|
|
201
|
-
y = 0,
|
|
202
|
-
z = 0
|
|
203
|
-
} = offset;
|
|
204
|
-
const normalized = new THREE.Vector3(x ?? 0, y ?? 0, z ?? 0);
|
|
205
|
-
object.userData.bottomCenterOffset = normalized;
|
|
206
|
-
return normalized;
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
normalizeBottomCenterData(object) {
|
|
211
|
-
const hasOffset = this.ensureBottomCenterOffset(object) !== null;
|
|
212
|
-
object.children.forEach((child) => this.normalizeBottomCenterData(child));
|
|
213
|
-
return hasOffset;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Load an asset with the specified options
|
|
217
|
-
*/
|
|
218
|
-
async load(options) {
|
|
219
|
-
const {
|
|
220
|
-
type,
|
|
221
|
-
url,
|
|
222
|
-
size,
|
|
223
|
-
lowResUrl,
|
|
224
|
-
enableCaching = true,
|
|
225
|
-
placeholderColor = 5227511,
|
|
226
|
-
placeholderOpacity = 0.4,
|
|
227
|
-
errorColor = 16729156,
|
|
228
|
-
errorOpacity = 0.5
|
|
229
|
-
} = options;
|
|
230
|
-
if (enableCaching && this.cache.has(url)) {
|
|
231
|
-
const cachedClone = this.cache.get(url).clone(true);
|
|
232
|
-
const hasOffset = this.normalizeBottomCenterData(cachedClone);
|
|
233
|
-
if (!hasOffset) {
|
|
234
|
-
this.positionAssetAtBottomCenter(cachedClone);
|
|
235
|
-
} else {
|
|
236
|
-
cachedClone.updateMatrixWorld(true);
|
|
237
|
-
}
|
|
238
|
-
this.loadedAsset = cachedClone;
|
|
239
|
-
this.dispatchEvent({ type: "loaded", asset: cachedClone });
|
|
240
|
-
return cachedClone;
|
|
241
|
-
}
|
|
242
|
-
this.errorColor = errorColor;
|
|
243
|
-
this.errorOpacity = errorOpacity;
|
|
244
|
-
if (size) {
|
|
245
|
-
this.placeholder = this.createPlaceholder(
|
|
246
|
-
size,
|
|
247
|
-
placeholderColor,
|
|
248
|
-
placeholderOpacity
|
|
249
|
-
);
|
|
250
|
-
this.dispatchEvent({
|
|
251
|
-
type: "placeholderCreated",
|
|
252
|
-
placeholder: this.placeholder
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
if (lowResUrl) {
|
|
257
|
-
const lowRes = await this.loadModel(type, lowResUrl, true);
|
|
258
|
-
this.lowResAsset = lowRes;
|
|
259
|
-
this.dispatchEvent({ type: "lowResLoaded", lowRes });
|
|
260
|
-
}
|
|
261
|
-
const asset = await this.loadModel(type, url, false);
|
|
262
|
-
this.loadedAsset = asset;
|
|
263
|
-
if (enableCaching) {
|
|
264
|
-
const cacheEntry = asset.clone(true);
|
|
265
|
-
const hasOffset = this.normalizeBottomCenterData(cacheEntry);
|
|
266
|
-
if (!hasOffset) {
|
|
267
|
-
this.positionAssetAtBottomCenter(cacheEntry);
|
|
268
|
-
} else {
|
|
269
|
-
cacheEntry.updateMatrixWorld(true);
|
|
270
|
-
}
|
|
271
|
-
this.cache.set(url, cacheEntry);
|
|
272
|
-
}
|
|
273
|
-
this.dispatchEvent({ type: "loaded", asset });
|
|
274
|
-
return asset;
|
|
275
|
-
} catch (error) {
|
|
276
|
-
this.setPlaceholderError();
|
|
277
|
-
this.dispatchEvent({ type: "error", error });
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Load a model based on type
|
|
283
|
-
*/
|
|
284
|
-
loadModel(type, url, isLowRes) {
|
|
285
|
-
return new Promise((resolve, reject) => {
|
|
286
|
-
const onProgress = (event) => {
|
|
287
|
-
let percentage = -1;
|
|
288
|
-
if (event.lengthComputable && event.total > 0 && event.loaded <= event.total) {
|
|
289
|
-
percentage = event.loaded / event.total * 100;
|
|
290
|
-
}
|
|
291
|
-
this.dispatchEvent({
|
|
292
|
-
type: "progress",
|
|
293
|
-
loaded: event.loaded,
|
|
294
|
-
total: event.total,
|
|
295
|
-
percentage
|
|
296
|
-
});
|
|
297
|
-
if (!isLowRes && percentage >= 0) {
|
|
298
|
-
this.updatePlaceholder(percentage / 100);
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
const onError = (error) => {
|
|
302
|
-
reject(error);
|
|
303
|
-
};
|
|
304
|
-
switch (type) {
|
|
305
|
-
case "gltf":
|
|
306
|
-
this.gltfLoader.load(
|
|
307
|
-
url,
|
|
308
|
-
(gltf) => {
|
|
309
|
-
const scene = gltf.scene;
|
|
310
|
-
this.positionAssetAtBottomCenter(scene);
|
|
311
|
-
resolve(scene);
|
|
312
|
-
},
|
|
313
|
-
onProgress,
|
|
314
|
-
onError
|
|
315
|
-
);
|
|
316
|
-
break;
|
|
317
|
-
case "fbx":
|
|
318
|
-
this.fbxLoader.load(
|
|
319
|
-
url,
|
|
320
|
-
(fbx) => {
|
|
321
|
-
this.positionAssetAtBottomCenter(fbx);
|
|
322
|
-
resolve(fbx);
|
|
323
|
-
},
|
|
324
|
-
onProgress,
|
|
325
|
-
onError
|
|
326
|
-
);
|
|
327
|
-
break;
|
|
328
|
-
case "obj":
|
|
329
|
-
this.objLoader.load(
|
|
330
|
-
url,
|
|
331
|
-
(obj) => {
|
|
332
|
-
this.positionAssetAtBottomCenter(obj);
|
|
333
|
-
resolve(obj);
|
|
334
|
-
},
|
|
335
|
-
onProgress,
|
|
336
|
-
onError
|
|
337
|
-
);
|
|
338
|
-
break;
|
|
339
|
-
case "usd":
|
|
340
|
-
case "usdz":
|
|
341
|
-
this.usdLoader.load(
|
|
342
|
-
url,
|
|
343
|
-
(usd) => {
|
|
344
|
-
this.positionAssetAtBottomCenter(usd);
|
|
345
|
-
resolve(usd);
|
|
346
|
-
},
|
|
347
|
-
onProgress,
|
|
348
|
-
onError
|
|
349
|
-
);
|
|
350
|
-
break;
|
|
351
|
-
default:
|
|
352
|
-
reject(new Error(`Unsupported asset type: ${type}`));
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Get the placeholder object
|
|
358
|
-
*/
|
|
359
|
-
getPlaceholder() {
|
|
360
|
-
return this.placeholder;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Get the loaded asset
|
|
364
|
-
*/
|
|
365
|
-
getAsset() {
|
|
366
|
-
return this.loadedAsset;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Get the low-res asset
|
|
370
|
-
*/
|
|
371
|
-
getLowResAsset() {
|
|
372
|
-
return this.lowResAsset;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Clear the cache
|
|
376
|
-
*/
|
|
377
|
-
clearCache() {
|
|
378
|
-
this.cache.clear();
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Remove an item from cache
|
|
382
|
-
*/
|
|
383
|
-
removeFromCache(url) {
|
|
384
|
-
this.cache.delete(url);
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Get cache size
|
|
388
|
-
*/
|
|
389
|
-
getCacheSize() {
|
|
390
|
-
return this.cache.size;
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
394
|
-
0 && (module.exports = {
|
|
395
|
-
AssetLoader
|
|
396
|
-
});
|
|
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});
|
|
@@ -19,13 +19,14 @@ interface AssetLoaderEventMap {
|
|
|
19
19
|
lowRes: THREE.Object3D;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz';
|
|
22
|
+
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz' | 'dae' | 'stl' | 'ply' | '3mf';
|
|
23
23
|
interface AssetLoaderOptions {
|
|
24
24
|
type: AssetType;
|
|
25
25
|
url: string;
|
|
26
26
|
size?: [number, number, number];
|
|
27
27
|
lowResUrl?: string;
|
|
28
28
|
enableCaching?: boolean;
|
|
29
|
+
disablePlaceholder?: boolean;
|
|
29
30
|
placeholderColor?: number;
|
|
30
31
|
placeholderOpacity?: number;
|
|
31
32
|
errorColor?: number;
|
|
@@ -37,6 +38,10 @@ declare class AssetLoader extends THREE.EventDispatcher<AssetLoaderEventMap> {
|
|
|
37
38
|
private fbxLoader;
|
|
38
39
|
private objLoader;
|
|
39
40
|
private usdLoader;
|
|
41
|
+
private colladaLoader;
|
|
42
|
+
private stlLoader;
|
|
43
|
+
private plyLoader;
|
|
44
|
+
private threeMFLoader;
|
|
40
45
|
private placeholder;
|
|
41
46
|
private loadedAsset;
|
|
42
47
|
private lowResAsset;
|
|
@@ -19,13 +19,14 @@ interface AssetLoaderEventMap {
|
|
|
19
19
|
lowRes: THREE.Object3D;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz';
|
|
22
|
+
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz' | 'dae' | 'stl' | 'ply' | '3mf';
|
|
23
23
|
interface AssetLoaderOptions {
|
|
24
24
|
type: AssetType;
|
|
25
25
|
url: string;
|
|
26
26
|
size?: [number, number, number];
|
|
27
27
|
lowResUrl?: string;
|
|
28
28
|
enableCaching?: boolean;
|
|
29
|
+
disablePlaceholder?: boolean;
|
|
29
30
|
placeholderColor?: number;
|
|
30
31
|
placeholderOpacity?: number;
|
|
31
32
|
errorColor?: number;
|
|
@@ -37,6 +38,10 @@ declare class AssetLoader extends THREE.EventDispatcher<AssetLoaderEventMap> {
|
|
|
37
38
|
private fbxLoader;
|
|
38
39
|
private objLoader;
|
|
39
40
|
private usdLoader;
|
|
41
|
+
private colladaLoader;
|
|
42
|
+
private stlLoader;
|
|
43
|
+
private plyLoader;
|
|
44
|
+
private threeMFLoader;
|
|
40
45
|
private placeholder;
|
|
41
46
|
private loadedAsset;
|
|
42
47
|
private lowResAsset;
|