@ridp/threejs 1.4.1 → 1.4.3

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.
Files changed (56) hide show
  1. package/{readme.md → README.md} +228 -26
  2. package/dist/hooks.cjs +1 -1
  3. package/dist/hooks.js +12 -9
  4. package/dist/packages/threejs/package.json.cjs +1 -0
  5. package/dist/packages/threejs/package.json.js +4 -0
  6. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +1 -0
  7. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +83 -0
  8. package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +1 -0
  9. package/dist/packages/threejs/src/hooks/useGLTFLoader.js +292 -0
  10. package/dist/packages/threejs/src/hooks/useObb.cjs +1 -0
  11. package/dist/packages/threejs/src/hooks/useObb.js +41 -0
  12. package/dist/packages/threejs/src/hooks/useRaycaster.cjs +1 -0
  13. package/dist/packages/threejs/src/hooks/useRaycaster.js +35 -0
  14. package/dist/packages/threejs/src/hooks/useThreeJs.cjs +5 -0
  15. package/dist/packages/threejs/src/hooks/useThreeJs.js +153 -0
  16. package/dist/packages/threejs/src/instance/IDBCache.cjs +1 -0
  17. package/dist/packages/threejs/src/instance/IDBCache.js +142 -0
  18. package/dist/packages/threejs/src/instance/threeIns.cjs +3 -0
  19. package/dist/packages/threejs/src/instance/threeIns.js +393 -0
  20. package/dist/packages/threejs/src/utils/CacheMonitor.cjs +1 -0
  21. package/dist/packages/threejs/src/utils/CacheMonitor.js +125 -0
  22. package/dist/packages/threejs/src/utils/ImageLoader.cjs +1 -0
  23. package/dist/packages/threejs/src/utils/ImageLoader.js +33 -0
  24. package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +1 -0
  25. package/dist/packages/threejs/src/utils/PredictiveLoader.js +155 -0
  26. package/dist/packages/threejs/src/utils/RetryHelper.cjs +1 -0
  27. package/dist/packages/threejs/src/utils/RetryHelper.js +108 -0
  28. package/dist/packages/threejs/src/utils/common.cjs +1 -0
  29. package/dist/packages/threejs/src/utils/common.js +15 -0
  30. package/dist/packages/threejs/src/utils/css3dHelper.cjs +15 -0
  31. package/dist/packages/threejs/src/utils/css3dHelper.js +42 -0
  32. package/dist/packages/threejs/src/utils/disposeObject.cjs +1 -0
  33. package/dist/packages/threejs/src/utils/disposeObject.js +13 -0
  34. package/dist/packages/threejs/src/utils/helper.cjs +1 -0
  35. package/dist/packages/threejs/src/utils/helper.js +47 -0
  36. package/dist/packages/threejs/src/utils/modelSerialize.cjs +1 -0
  37. package/dist/packages/threejs/src/utils/modelSerialize.js +225 -0
  38. package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +1 -0
  39. package/dist/packages/threejs/src/utils/sceneRebuilder.js +138 -0
  40. package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +1 -0
  41. package/dist/packages/threejs/src/workers/gltfParser.worker.js +11 -0
  42. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +1 -0
  43. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +11 -0
  44. package/dist/threejs.cjs +1 -3
  45. package/dist/threejs.js +58 -404
  46. package/dist/utils.cjs +1 -1
  47. package/dist/utils.js +40 -32
  48. package/package.json +1 -1
  49. package/dist/ImageLoader-Br_nvMOg.js +0 -1444
  50. package/dist/ImageLoader-DL32KyTh.cjs +0 -24
  51. package/dist/PredictiveLoader-CZfMSjv-.js +0 -3731
  52. package/dist/PredictiveLoader-DDxh7dDg.cjs +0 -2
  53. package/dist/useBatchGLTFLoader-B5EUagWI.js +0 -493
  54. package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +0 -5
  55. /package/dist/{modelOptimizer-A0Cs6f9e.cjs → packages/threejs/src/utils/modelOptimizer.cjs} +0 -0
  56. /package/dist/{modelOptimizer-BRPnM2RH.js → packages/threejs/src/utils/modelOptimizer.js} +0 -0
@@ -0,0 +1,292 @@
1
+ import { GLTFLoader as U } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/loaders/GLTFLoader.js";
2
+ import { DRACOLoader as _ } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/loaders/DRACOLoader.js";
3
+ import { IDBCache as $ } from "../instance/IDBCache.js";
4
+ import "three";
5
+ import { dataToObject3D as V } from "../utils/modelSerialize.js";
6
+ import { cacheMonitor as m } from "../utils/CacheMonitor.js";
7
+ import { RetryHelper as q, ModelLoadError as J } from "../utils/RetryHelper.js";
8
+ import { rebuildScene as K } from "../utils/sceneRebuilder.js";
9
+ import N from "../workers/gltfParser.worker.js";
10
+ import Q from "../workers/gltfParserOptimized.worker.js";
11
+ let y;
12
+ const O = "/draco/";
13
+ let w, k, R = 0;
14
+ const u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), ce = (b = {}) => {
15
+ const { debug: T = !1 } = b, M = new U(), P = new _();
16
+ P.setDecoderPath(O), M.setDRACOLoader(P);
17
+ const n = {
18
+ info: (...e) => T && console.log(...e),
19
+ warn: (...e) => T && console.warn(...e),
20
+ error: (...e) => console.error(...e),
21
+ // 错误总是输出
22
+ time: (e) => T && console.time(e),
23
+ timeEnd: (e) => T && console.timeEnd(e)
24
+ };
25
+ function A(e, r, o, s) {
26
+ return M.load(e, r, o, s);
27
+ }
28
+ function G(e, r) {
29
+ return new Promise((o, s) => {
30
+ M.load(e, o, r, s);
31
+ });
32
+ }
33
+ async function z(e, r, o, s = {}) {
34
+ const t = performance.now();
35
+ let i = !1;
36
+ const {
37
+ maxRetries: c = 3,
38
+ optimizeMaterials: h = !1,
39
+ simplifyGeometry: g = !1,
40
+ simplifyRatio: W = 0.5,
41
+ simplifyOptions: C = {},
42
+ useMemoryCache: L = !0
43
+ // 是否使用内存缓存(默认 true)
44
+ } = s;
45
+ if (L) {
46
+ const a = d.get(e);
47
+ if (a && a.has(r)) {
48
+ const f = a.get(r);
49
+ n.info(`[ 内存缓存命中 ] ${e} (version: ${r})`), n.time("[ 内存缓存克隆耗时 ]");
50
+ const p = f.clone(!0);
51
+ return n.timeEnd("[ 内存缓存克隆耗时 ]"), m.recordHit(performance.now() - t), p;
52
+ }
53
+ }
54
+ try {
55
+ let a = await S(e, r);
56
+ if (a)
57
+ n.info(`[ asyncFetch ] ====> IndexedDB 缓存命中: ${e}`), i = !0;
58
+ else {
59
+ n.info(`[ asyncFetch ] ====> 缓存未命中: ${e}`), n.time("[ fetchArrayBuffer ] 加载模型耗时"), a = await q.retry(
60
+ () => D(e, o),
61
+ {
62
+ maxRetries: c,
63
+ shouldRetry: (F) => !!(F.name === "TypeError" || F.message.includes("HTTP error! status: 5"))
64
+ }
65
+ ), n.timeEnd("[ fetchArrayBuffer ] 加载模型耗时");
66
+ const l = performance.now();
67
+ await y.saveModel(e, r, a);
68
+ const E = performance.now() - l;
69
+ m.recordCacheSave(E), i = !1;
70
+ }
71
+ n.time("[ 解析模型耗时 ]");
72
+ let f = await v(a);
73
+ if (n.timeEnd("[ 解析模型耗时 ]"), n.time("[ 模型优化耗时 ]"), h) {
74
+ n.info("🔧 [ 材质优化 ] 开始合并相同材质...");
75
+ const { modelOptimizer: l } = await import("../utils/modelOptimizer.js");
76
+ f = l.optimizeMaterials(f);
77
+ }
78
+ if (g) {
79
+ n.info(`🔧 [ 几何体简化 ] 开始简化模型 (比例: ${W})...`);
80
+ const { modelOptimizer: l } = await import("../utils/modelOptimizer.js"), E = {
81
+ minFaceCount: 100,
82
+ preserveUVs: !0,
83
+ ...C
84
+ };
85
+ f = l.simplifyModel(f, W, E);
86
+ }
87
+ if (n.timeEnd("[ 模型优化耗时 ]"), L) {
88
+ d.has(e) || d.set(e, /* @__PURE__ */ new Map());
89
+ const l = d.get(e);
90
+ l.has(r) || (n.info(`[ 内存缓存 ] 存储模型 ${e} (version: ${r})`), l.set(r, f.clone(!0)));
91
+ }
92
+ const p = performance.now() - t;
93
+ return i ? m.recordHit(p) : m.recordMiss(p), f;
94
+ } catch (a) {
95
+ throw n.error(`加载模型 ${e} 失败:`, a), m.recordError(e, a), a.name === "TypeError" && a.message.includes("fetch") ? J.networkError(e, a) : a;
96
+ }
97
+ }
98
+ async function D(e, r) {
99
+ return new Promise((o, s) => {
100
+ fetch(e).then((t) => {
101
+ if (!t.ok)
102
+ throw new Error(`HTTP error! status: ${t.status}`);
103
+ return t;
104
+ }).then((t) => {
105
+ const i = t.headers.get("content-length"), c = i ? parseInt(i, 10) : 0;
106
+ if (r && c > 0) {
107
+ const h = t.body.getReader();
108
+ let g = 0;
109
+ const W = [], C = () => {
110
+ h.read().then(({ done: L, value: a }) => {
111
+ if (L) {
112
+ const f = new Uint8Array(g);
113
+ let p = 0;
114
+ for (const l of W)
115
+ f.set(l, p), p += l.length;
116
+ o(f.buffer);
117
+ return;
118
+ }
119
+ W.push(a), g += a.length, r(Math.round(g / c * 100)), C();
120
+ }).catch(s);
121
+ };
122
+ C();
123
+ } else
124
+ return t.arrayBuffer();
125
+ }).then((t) => o(t)).catch((t) => {
126
+ s(t);
127
+ });
128
+ });
129
+ }
130
+ async function S(e, r) {
131
+ return y || (y = new $()), y.getModel(e, r);
132
+ }
133
+ async function v(e, r = {}) {
134
+ if (!e) return null;
135
+ const { useOptimizedParser: o = !0, useProgressive: s = !1 } = r;
136
+ if (o) {
137
+ const c = B();
138
+ if (c)
139
+ try {
140
+ n.time("[ 优化解析 ] 使用 Transferable Objects 解析");
141
+ const h = await H(c, e, s);
142
+ return n.timeEnd("[ 优化解析 ] 使用 Transferable Objects 解析"), K(h);
143
+ } catch (h) {
144
+ n.warn("[ 优化解析 ] 失败,回退到标准解析", h);
145
+ }
146
+ }
147
+ const t = I();
148
+ if (t)
149
+ try {
150
+ const c = await j(t, e);
151
+ return V(c);
152
+ } catch (c) {
153
+ n.warn("[ GLTF Worker ] ====> 解析失败,回退到主线程解析", c);
154
+ }
155
+ return (await x(e)).scene;
156
+ }
157
+ const I = () => {
158
+ if (typeof window > "u" || typeof Worker > "u")
159
+ return null;
160
+ if (!w)
161
+ try {
162
+ n.info("[GLTF Worker] 使用 ?worker 工厂函数创建 Worker..."), w = N(), n.info("[GLTF Worker] Worker 创建成功:", w), w.onmessage = (e) => {
163
+ const { id: r, data: o, error: s } = e.data || {};
164
+ if (!r || !u.has(r)) return;
165
+ const { resolve: t, reject: i } = u.get(r);
166
+ u.delete(r), s ? i(new Error(s)) : t(o);
167
+ }, w.onmessageerror = (e) => {
168
+ console.error("[ GLTF Worker ] ====> 消息解析失败", e);
169
+ }, w.onerror = (e) => {
170
+ console.error("[ GLTF Worker ] ====> 运行错误", e);
171
+ };
172
+ } catch (e) {
173
+ console.error("[GLTF Worker] 创建 Worker 失败:", e), console.error("[GLTF Worker] 错误堆栈:", e.stack);
174
+ }
175
+ return w;
176
+ }, B = () => {
177
+ if (typeof window > "u" || typeof Worker > "u")
178
+ return null;
179
+ if (!k)
180
+ try {
181
+ n.info("[Optimized Worker] 使用 ?worker 工厂函数创建 Worker..."), k = Q(), n.info("[Optimized Worker] Worker 创建成功:", k), k.onmessage = (e) => {
182
+ const { id: r, data: o, error: s, type: t } = e.data || {};
183
+ if (!r || !u.has(r) || t === "progress")
184
+ return;
185
+ const { resolve: i, reject: c } = u.get(r);
186
+ u.delete(r), s ? c(new Error(s)) : i(o);
187
+ }, k.onmessageerror = (e) => {
188
+ console.error("[ 优化 Worker ] ====> 消息解析失败", e);
189
+ }, k.onerror = (e) => {
190
+ console.error("[ 优化 Worker ] ====> 运行错误", e);
191
+ };
192
+ } catch (e) {
193
+ return n.warn("[ 优化 Worker ] ====> 创建失败,可能不支持模块化 Worker", e), null;
194
+ }
195
+ return k;
196
+ }, H = (e, r, o = !1) => new Promise((s, t) => {
197
+ const i = ++R;
198
+ u.set(i, { resolve: s, reject: t });
199
+ const c = {
200
+ id: i,
201
+ arrayBuffer: r,
202
+ dracoPath: O,
203
+ mode: o ? "progressive" : "standard"
204
+ };
205
+ e.postMessage(c, [r]);
206
+ }), j = (e, r) => new Promise((o, s) => {
207
+ const t = ++R;
208
+ u.set(t, { resolve: o, reject: s }), e.postMessage({ id: t, arrayBuffer: r, dracoPath: O });
209
+ }), x = (e) => new Promise((r, o) => {
210
+ M.parse(e, "", r, o);
211
+ });
212
+ return {
213
+ load: A,
214
+ asyncLoad: G,
215
+ asyncCacheLoad: z,
216
+ asyncFetch: z,
217
+ /**
218
+ * 获取缓存统计信息
219
+ * @returns {Object} 统计数据
220
+ */
221
+ getCacheStats: () => m.getStats(),
222
+ /**
223
+ * 获取缓存实例
224
+ * @returns {IDBCache} 缓存实例
225
+ */
226
+ getCache: () => y || (y = new $()),
227
+ /**
228
+ * 打印缓存性能报告
229
+ */
230
+ logCacheReport: () => m.logReport(),
231
+ /**
232
+ * 重置缓存统计
233
+ */
234
+ resetCacheStats: () => m.reset(),
235
+ /**
236
+ * 清空内存缓存
237
+ * 释放已缓存的 3D 模型对象内存
238
+ * @returns {number} 释放的模型数量
239
+ */
240
+ clearMemoryCache: () => {
241
+ let e = 0;
242
+ for (const [r, o] of d.entries())
243
+ e += o.size, o.clear();
244
+ return d.clear(), n.info(`[ 内存缓存 ] 已清空,释放了 ${e} 个模型`), e;
245
+ },
246
+ /**
247
+ * 获取内存缓存信息
248
+ * @returns {Object} 内存缓存统计
249
+ * @returns {number} returns.totalPaths - 缓存的不同模型路径数量
250
+ * @returns {number} returns.totalModels - 缓存的总模型数量
251
+ * @returns {Array} returns.details - 每个路径的详细信息
252
+ */
253
+ getMemoryCacheInfo: () => {
254
+ const e = [];
255
+ let r = 0;
256
+ for (const [o, s] of d.entries()) {
257
+ const t = Array.from(s.keys());
258
+ r += t.length, e.push({
259
+ path: o,
260
+ versions: t,
261
+ count: t.length
262
+ });
263
+ }
264
+ return {
265
+ totalPaths: d.size,
266
+ totalModels: r,
267
+ details: e
268
+ };
269
+ },
270
+ /**
271
+ * 删除指定模型的内存缓存
272
+ * @param {string} path - 模型路径
273
+ * @param {string} [version] - 可选的版本号,如果不指定则删除该路径的所有版本
274
+ * @returns {boolean} 是否删除成功
275
+ */
276
+ deleteMemoryCache: (e, r) => {
277
+ const o = d.get(e);
278
+ if (!o)
279
+ return !1;
280
+ if (r) {
281
+ const s = o.delete(r);
282
+ return o.size === 0 && d.delete(e), n.info(`[ 内存缓存 ] 删除模型 ${e} (version: ${r})`), s;
283
+ } else {
284
+ const s = o.size;
285
+ return d.delete(e), n.info(`[ 内存缓存 ] 删除模型 ${e} 及其所有版本 (共 ${s} 个)`), s > 0;
286
+ }
287
+ }
288
+ };
289
+ };
290
+ export {
291
+ ce as useGLTFLoader
292
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("three"),n=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/math/OBB.cjs"),b=[],u=new o.Color(16711680),O=()=>{const s=()=>{b.splice(0)},a=(t,e)=>{e.traverse(r=>{r&&i(t,r)})},i=(t,e)=>{if(e.userData.needCheck&&(e.autoUpdateMatrix=!1,e.updateMatrix(),e.updateMatrixWorld(),e.isMesh)){const r=new o.Box3(new o.Vector3).setFromObject(e);e.geometry.userData.obb=new n.OBB,e.geometry.userData.obb.halfSize.copy(r.getSize(new o.Vector3)).multiplyScalar(.5).multiplyScalar(.88),e.userData.obb=new n.OBB,e.userData.originColor=e.material.color.clone(),e.userData.parentUid=t,b.push({object:e,parentUid:t})}};return{resetObbs:s,initObb:a,getObbObjectByParentUid:t=>b.filter(e=>e.parentUid===t),addObbFromArray:(t,e)=>{for(let r=0,c=e.length;r<c;r++)i(t,e[r])},removeObbFromArray:t=>{const e=b.filter(r=>!t.includes(r.object));b.splice(0,b.length,...e)},removeUidObb:t=>{for(let e=b.length-1;e>=0;e--)b[e].parentUid===t&&b.splice(e,1)}}};exports.intersectColor=u;exports.obbObjects=b;exports.useObb=O;
@@ -0,0 +1,41 @@
1
+ import { Color as O, Box3 as l, Vector3 as a } from "three";
2
+ import { OBB as i } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/math/OBB.js";
3
+ const o = [], m = new O(16711680), x = () => {
4
+ const n = () => {
5
+ o.splice(0);
6
+ }, s = (e, t) => {
7
+ t.traverse((r) => {
8
+ r && b(e, r);
9
+ });
10
+ }, b = (e, t) => {
11
+ if (t.userData.needCheck && (t.autoUpdateMatrix = !1, t.updateMatrix(), t.updateMatrixWorld(), t.isMesh)) {
12
+ const r = new l(new a()).setFromObject(t);
13
+ t.geometry.userData.obb = new i(), t.geometry.userData.obb.halfSize.copy(r.getSize(new a())).multiplyScalar(0.5).multiplyScalar(0.88), t.userData.obb = new i(), t.userData.originColor = t.material.color.clone(), t.userData.parentUid = e, o.push({
14
+ object: t,
15
+ parentUid: e
16
+ });
17
+ }
18
+ };
19
+ return {
20
+ resetObbs: n,
21
+ initObb: s,
22
+ getObbObjectByParentUid: (e) => o.filter((t) => t.parentUid === e),
23
+ addObbFromArray: (e, t) => {
24
+ for (let r = 0, c = t.length; r < c; r++)
25
+ b(e, t[r]);
26
+ },
27
+ removeObbFromArray: (e) => {
28
+ const t = o.filter((r) => !e.includes(r.object));
29
+ o.splice(0, o.length, ...t);
30
+ },
31
+ removeUidObb: (e) => {
32
+ for (let t = o.length - 1; t >= 0; t--)
33
+ o[t].parentUid === e && o.splice(t, 1);
34
+ }
35
+ };
36
+ };
37
+ export {
38
+ m as intersectColor,
39
+ o as obbObjects,
40
+ x as useObb
41
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("three"),x=(f="app")=>{const a=new p.Raycaster;a.params.Line.threshold=8;const i=new p.Vector2,y=document.getElementById(f);function l(t,e){const{scaleX:s,scaleY:o}=u(y),{clientWidth:c,clientHeight:r}=e,n=e.getBoundingClientRect(),m=c*s,d=r*o,h=t.clientX-n.left,w=t.clientY-n.top;return i.x=(t.clientX-n.left)/m*2-1,i.y=-((t.clientY-n.top)/d)*2+1,{pointer:i,x:h,y:w}}function g(t,e,s,o){const{pointer:c,x:r,y:n}=l(t,e);return a.setFromCamera(c,s),{intersects:a.intersectObjects(o),pointer:c,x:r,y:n}}function u(t){const e=window.getComputedStyle(t),s=e.transform||e.webkitTransform||e.mozTransform;if(s&&s!=="none"){const o=s.match(/^matrix\((.+)\)$/);if(o){const c=o[1].split(", "),r=parseFloat(c[0]),n=parseFloat(c[3]);return{scaleX:r,scaleY:n}}}return{scaleX:1,scaleY:1}}return{raycaster:a,pointer:i,getPointer:l,getScale:u,getIntersects:g}};exports.useRaycaster=x;
@@ -0,0 +1,35 @@
1
+ import { Raycaster as x, Vector2 as w } from "three";
2
+ const Y = (u = "app") => {
3
+ const a = new x();
4
+ a.params.Line.threshold = 8;
5
+ const i = new w(), f = document.getElementById(u);
6
+ function l(t, e) {
7
+ const { scaleX: s, scaleY: o } = m(f), { clientWidth: c, clientHeight: r } = e, n = e.getBoundingClientRect(), p = c * s, y = r * o, d = t.clientX - n.left, h = t.clientY - n.top;
8
+ return i.x = (t.clientX - n.left) / p * 2 - 1, i.y = -((t.clientY - n.top) / y) * 2 + 1, { pointer: i, x: d, y: h };
9
+ }
10
+ function g(t, e, s, o) {
11
+ const { pointer: c, x: r, y: n } = l(t, e);
12
+ return a.setFromCamera(c, s), { intersects: a.intersectObjects(o), pointer: c, x: r, y: n };
13
+ }
14
+ function m(t) {
15
+ const e = window.getComputedStyle(t), s = e.transform || e.webkitTransform || e.mozTransform;
16
+ if (s && s !== "none") {
17
+ const o = s.match(/^matrix\((.+)\)$/);
18
+ if (o) {
19
+ const c = o[1].split(", "), r = parseFloat(c[0]), n = parseFloat(c[3]);
20
+ return { scaleX: r, scaleY: n };
21
+ }
22
+ }
23
+ return { scaleX: 1, scaleY: 1 };
24
+ }
25
+ return {
26
+ raycaster: a,
27
+ pointer: i,
28
+ getPointer: l,
29
+ getScale: m,
30
+ getIntersects: g
31
+ };
32
+ };
33
+ export {
34
+ Y as useRaycaster
35
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three"),u=require("vue"),W=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/libs/stats.module.cjs"),B=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/renderers/CSS3DRenderer.cjs"),G=require("../utils/helper.cjs"),N=require("../utils/disposeObject.cjs");require("../utils/PredictiveLoader.cjs");const Y={enableDamping:!0,dampingFactor:.25,screenSpacePanning:!1,minDistance:.1,maxDistance:1e3,maxPolarAngle:i.MathUtils.degToRad(60)};function K(k,F){typeof console<"u"&&console.warn&&console.warn(`[ThreeIns] useThreeJs() Hook 已弃用,建议使用 ThreeIns 类代替。
2
+ 旧用法: const { scene, camera } = useThreeJs(selector, options)
3
+ 新用法: const threeIns = new ThreeIns(selector, options)
4
+
5
+ ThreeIns 类提供更完整的 API 和更好的性能。`);const a=Object.assign({css3d:!1,stats:!1,renderType:"change",control:{init:!0,options:{}}},F||{});let d,v,n,y=[];const T=u.ref(!1),p=u.shallowRef(),s=u.ref(0),r=u.ref(0),o=new i.WebGLRenderer({antialias:!0,alpha:!0,precision:"mediump",logarithmicDepthBuffer:!0}),h=new i.Scene({}),e=new i.PerspectiveCamera(50,1,.1,2e3),w=Math.tan(Math.PI/180*e.fov/2);let b=!1;o.setPixelRatio(window.devicePixelRatio);function S(){T.value=!1;const t=q();s.value=t[0],r.value=t[1],e.aspect=s.value/r.value,e.position.set(47,39,100),e.fov=360/Math.PI*Math.atan(w*(r.value/s.value)),e.lookAt(0,0,0),e.updateProjectionMatrix(),o.setSize(s.value,r.value),d.appendChild(o.domElement),a.stats&&L(),a.css3d&&_();let l;if(a.control&&a.control.init){l=G.createOrbitControl(e,o.domElement);const c=Object.assign(Y,a.control.options||{});Object.keys(c).forEach(x=>{l[x]=c[x]})}return u.nextTick(()=>T.value=!0),l}function A(t){t.preventDefault(),cancelAnimationFrame(g)}function R(t){t.preventDefault(),S(),g()}function j(t){y.push(t)}function g(t){y&&y.length&&y.forEach(l=>{typeof l=="function"&&l()}),a.renderType==="loop"&&E(),requestAnimationFrame(g)}function E(){b=!1,v&&v.update(),p.value&&p.value.update(),o.render(h,e),n&&n.render(h,e)}function I(){b||(b=!0,requestAnimationFrame(E))}function O(){u.nextTick(()=>{const t=q();s.value=t[0],r.value=t[1],e.aspect=s.value/r.value,e.fov=360/Math.PI*Math.atan(w*(r.value/s.value)),e.updateProjectionMatrix(),e.lookAt(h.position),o.setSize(s.value,r.value),n&&n.setSize(s.value,r.value),E()})}function q(){return d=document.querySelector(k),d?[d.clientWidth,d.clientHeight]:[0,0]}function L(){v=new W,v.dom.style.cssText="position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",d.appendChild(v.dom)}function D(t,l,c,x,C){const M=new i.Box3().setFromObject(t),P=M.getSize(new i.Vector3).length(),m=M.getCenter(new i.Vector3);C&&m.add(C);const H=P*l*.5,J=i.MathUtils.degToRad(c.fov*.5),U=H/Math.tan(J),z=new i.Vector3().subVectors(c.position,m).multiply(new i.Vector3(1,1,1)).normalize().multiplyScalar(U).add(m),f={x:z.x,y:z.y,z:z.z,lookAt_x:m.x,lookAt_y:m.y,lookAt_z:m.z};return c.position.set(f.x,f.y,f.z),c.lookAt(f.lookAt_x,f.lookAt_y,f.lookAt_z),c.updateProjectionMatrix(),x.target.copy(m),x.update(),P}function _(){n=new B.CSS3DRenderer,n.setSize(s.value,r.value),n.domElement.style.position="absolute",n.domElement.style.top=0,n.domElement.style.left=0,n.domElement.style.pointerEvents="none",d.appendChild(n.domElement)}function V(){N.disposeThreeObject(h)}return u.onMounted(()=>{p.value=S(),window.addEventListener("resize",O,!1),o.domElement.addEventListener("webglcontextlost",A,!1),o.domElement.addEventListener("webglcontextrestored",R,!1),a.renderType==="loop"?requestAnimationFrame(g):a.renderType==="change"&&p.value&&p.value.addEventListener("change",I)}),u.onUnmounted(()=>{cancelAnimationFrame(g),o.domElement.removeEventListener("resize",O,!1),o.domElement.removeEventListener("webglcontextlost",A,!1),o.domElement.removeEventListener("webglcontextrestored",R,!1),V()}),{addAnimate:j,frameArea:D,onRender:E,css3dRenderer:n,scene:h,camera:e,control:p,renderer:o,domWidth:s,domHeight:r,isReady:T}}exports.useThreeJs=K;
@@ -0,0 +1,153 @@
1
+ import { MathUtils as I, WebGLRenderer as G, Scene as N, PerspectiveCamera as Y, Box3 as K, Vector3 as y } from "three";
2
+ import { ref as b, shallowRef as Q, onMounted as X, onUnmounted as Z, nextTick as k } from "vue";
3
+ import $ from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/libs/stats.module.js";
4
+ import { CSS3DRenderer as ee } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/renderers/CSS3DRenderer.js";
5
+ import { createOrbitControl as te } from "../utils/helper.js";
6
+ import { disposeThreeObject as ne } from "../utils/disposeObject.js";
7
+ import "../utils/PredictiveLoader.js";
8
+ const oe = {
9
+ enableDamping: !0,
10
+ dampingFactor: 0.25,
11
+ screenSpacePanning: !1,
12
+ minDistance: 0.1,
13
+ maxDistance: 1e3,
14
+ maxPolarAngle: I.degToRad(60)
15
+ };
16
+ function pe(L, j) {
17
+ typeof console < "u" && console.warn && console.warn(
18
+ `[ThreeIns] useThreeJs() Hook 已弃用,建议使用 ThreeIns 类代替。
19
+ 旧用法: const { scene, camera } = useThreeJs(selector, options)
20
+ 新用法: const threeIns = new ThreeIns(selector, options)
21
+
22
+ ThreeIns 类提供更完整的 API 和更好的性能。`
23
+ );
24
+ const r = Object.assign(
25
+ {
26
+ css3d: !1,
27
+ stats: !1,
28
+ renderType: "change",
29
+ control: {
30
+ init: !0,
31
+ options: {}
32
+ }
33
+ },
34
+ j || {}
35
+ );
36
+ let c, p, n, x = [];
37
+ const z = b(!1), u = Q(), s = b(0), i = b(0), o = new G({
38
+ antialias: !0,
39
+ alpha: !0,
40
+ precision: "mediump",
41
+ logarithmicDepthBuffer: !0
42
+ }), f = new N({}), e = new Y(50, 1, 0.1, 2e3), T = Math.tan(Math.PI / 180 * e.fov / 2);
43
+ let w = !1;
44
+ o.setPixelRatio(window.devicePixelRatio);
45
+ function S() {
46
+ z.value = !1;
47
+ const t = O();
48
+ s.value = t[0], i.value = t[1], e.aspect = s.value / i.value, e.position.set(47, 39, 100), e.fov = 360 / Math.PI * Math.atan(T * (i.value / s.value)), e.lookAt(0, 0, 0), e.updateProjectionMatrix(), o.setSize(s.value, i.value), c.appendChild(o.domElement), r.stats && _(), r.css3d && J();
49
+ let a;
50
+ if (r.control && r.control.init) {
51
+ a = te(e, o.domElement);
52
+ const l = Object.assign(
53
+ oe,
54
+ r.control.options || {}
55
+ );
56
+ Object.keys(l).forEach((h) => {
57
+ a[h] = l[h];
58
+ });
59
+ }
60
+ return k(() => z.value = !0), a;
61
+ }
62
+ function A(t) {
63
+ t.preventDefault(), cancelAnimationFrame(v);
64
+ }
65
+ function R(t) {
66
+ t.preventDefault(), S(), v();
67
+ }
68
+ function q(t) {
69
+ x.push(t);
70
+ }
71
+ function v(t) {
72
+ x && x.length && x.forEach((a) => {
73
+ typeof a == "function" && a();
74
+ }), r.renderType === "loop" && g(), requestAnimationFrame(v);
75
+ }
76
+ function g() {
77
+ w = !1, p && p.update(), u.value && u.value.update(), o.render(f, e), n && n.render(f, e);
78
+ }
79
+ function D() {
80
+ w || (w = !0, requestAnimationFrame(g));
81
+ }
82
+ function C() {
83
+ k(() => {
84
+ const t = O();
85
+ s.value = t[0], i.value = t[1], e.aspect = s.value / i.value, e.fov = 360 / Math.PI * Math.atan(T * (i.value / s.value)), e.updateProjectionMatrix(), e.lookAt(f.position), o.setSize(s.value, i.value), n && n.setSize(s.value, i.value), g();
86
+ });
87
+ }
88
+ function O() {
89
+ return c = document.querySelector(L), c ? [c.clientWidth, c.clientHeight] : [0, 0];
90
+ }
91
+ function _() {
92
+ p = new $(), p.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", c.appendChild(p.dom);
93
+ }
94
+ function H(t, a, l, h, P) {
95
+ const F = new K().setFromObject(t), M = F.getSize(new y()).length(), d = F.getCenter(new y());
96
+ P && d.add(P);
97
+ const W = M * a * 0.5, B = I.degToRad(l.fov * 0.5), U = W / Math.tan(B), E = new y().subVectors(l.position, d).multiply(new y(1, 1, 1)).normalize().multiplyScalar(U).add(d), m = {
98
+ x: E.x,
99
+ y: E.y,
100
+ z: E.z,
101
+ lookAt_x: d.x,
102
+ lookAt_y: d.y,
103
+ lookAt_z: d.z
104
+ };
105
+ return l.position.set(m.x, m.y, m.z), l.lookAt(
106
+ m.lookAt_x,
107
+ m.lookAt_y,
108
+ m.lookAt_z
109
+ ), l.updateProjectionMatrix(), h.target.copy(d), h.update(), M;
110
+ }
111
+ function J() {
112
+ n = new ee(), n.setSize(s.value, i.value), n.domElement.style.position = "absolute", n.domElement.style.top = 0, n.domElement.style.left = 0, n.domElement.style.pointerEvents = "none", c.appendChild(n.domElement);
113
+ }
114
+ function V() {
115
+ ne(f);
116
+ }
117
+ return X(() => {
118
+ u.value = S(), window.addEventListener("resize", C, !1), o.domElement.addEventListener(
119
+ "webglcontextlost",
120
+ A,
121
+ !1
122
+ ), o.domElement.addEventListener(
123
+ "webglcontextrestored",
124
+ R,
125
+ !1
126
+ ), r.renderType === "loop" ? requestAnimationFrame(v) : r.renderType === "change" && u.value && u.value.addEventListener("change", D);
127
+ }), Z(() => {
128
+ cancelAnimationFrame(v), o.domElement.removeEventListener("resize", C, !1), o.domElement.removeEventListener(
129
+ "webglcontextlost",
130
+ A,
131
+ !1
132
+ ), o.domElement.removeEventListener(
133
+ "webglcontextrestored",
134
+ R,
135
+ !1
136
+ ), V();
137
+ }), {
138
+ addAnimate: q,
139
+ frameArea: H,
140
+ onRender: g,
141
+ css3dRenderer: n,
142
+ scene: f,
143
+ camera: e,
144
+ control: u,
145
+ renderer: o,
146
+ domWidth: s,
147
+ domHeight: i,
148
+ isReady: z
149
+ };
150
+ }
151
+ export {
152
+ pe as useThreeJs
153
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("three");const d=require("dexie"),c=4;class r{constructor(e="threeJsIDBCache",t={}){this.version=c,this.dbName=e,this.options={maxSize:t.maxSize||500*1024*1024,maxEntries:t.maxEntries||50,evictRatio:t.evictRatio||.2},this.dbInit()}dbInit(){this.db=new d(this.dbName),this.db.version(this.version).stores({models:"&path, version, timestamp, accessCount, size"}).upgrade(async e=>{console.log("[ IDBCache 版本更新 ] ====> version",c);const t=e.table("models"),s=await t.toArray();for(const o of s)o.data instanceof ArrayBuffer||await t.delete(o.path)})}getDatabase(){return this.db}async saveModel(e,t,s){await this.ensureCapacity(s.byteLength),await this.db.table("models").put({path:e,version:t,data:s,size:s.byteLength,timestamp:Date.now(),accessCount:0})}async ensureCapacity(e){const t=await this.db.table("models").toArray(),s=t.reduce((a,i)=>a+(i.size||0),0),o=t.length,n=s+e>this.options.maxSize,l=o>=this.options.maxEntries;(n||l)&&(console.log(`[ IDBCache ] ====> 容量不足,开始 LRU 淘汰. 总大小: ${(s/1024/1024).toFixed(2)}MB, 条目数: ${o}`),await this.evictLRU(t))}async evictLRU(e){const t=e.sort((a,i)=>(a.accessCount||0)!==(i.accessCount||0)?(a.accessCount||0)-(i.accessCount||0):(a.timestamp||0)-(i.timestamp||0)),s=Math.max(1,Math.floor(t.length*this.options.evictRatio)),o=t.slice(0,s),n=o.map(a=>a.path);await this.db.table("models").bulkDelete(n);const l=o.reduce((a,i)=>a+(i.size||0),0);console.log(`[ IDBCache ] ====> LRU 淘汰完成. 删除 ${s} 个条目,释放 ${(l/1024/1024).toFixed(2)}MB`)}async getModel(e,t){const s=await this.db.table("models").get(e);return s?s.version!==t?(console.log("模型版本不一致, 清除当前记录"),await this.db.table("models").delete(e),null):(await this.db.table("models").update(e,{accessCount:(s.accessCount||0)+1,timestamp:Date.now()}),s.data):(console.warn(`Model "${e}" not found in table models`),null)}async cacheModel(e,t,s){console.log("[ ] ====> path, modelData, version",e,t,s);try{this.db.table("models").put({version:s,path:e,data:t}).then(()=>{console.log(`Model "${e}" cached successfully in table models`)})}catch{console.log(" 缓存模型失败 =====> ")}return t}async loadCachedModel(e,t){let s=null;try{if(s=await this.db.table("models").get(e),!s)return console.warn(`Model "${t}" not found in table models`),null;if(s.version!==t)return console.log(" =====> 模型版本不一致, 清除当前记录"),await this.db.table("models").delete(e),null}catch{return console.log(" =====> 查询表中模型失败"),this.db.delete().then(()=>{this.init()}),null}return s.data}async getStats(){const e=await this.db.table("models").toArray(),t=e.reduce((o,n)=>o+(n.size||0),0),s=e.reduce((o,n)=>o+(n.accessCount||0),0);return{count:e.length,totalSize:t,totalSizeMB:(t/1024/1024).toFixed(2),maxEntries:this.options.maxEntries,maxSizeMB:(this.options.maxSize/1024/1024).toFixed(2),usagePercentage:(t/this.options.maxSize*100).toFixed(2),totalAccessCount:s,avgAccessCount:e.length>0?(s/e.length).toFixed(2):0}}async clear(){await this.db.table("models").clear(),console.log("[ IDBCache ] ====> 缓存已清空")}async deleteModel(e){await this.db.table("models").delete(e)}}exports.IDBCache=r;