@ridp/threejs 1.4.3 → 1.4.5
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/ImageLoader-6mmE7g5P.cjs +24 -0
- package/dist/ImageLoader-CnBqJLru.js +1444 -0
- package/dist/PredictiveLoader-DTN7SDRI.js +3842 -0
- package/dist/PredictiveLoader-KOCZXzGy.cjs +2 -0
- package/dist/assets/{gltfParser.worker-Bqz8BBJx.js → gltfParser.worker-D2lwod50.js} +2 -2
- package/dist/assets/{gltfParserOptimized.worker-DfipxPjm.js → gltfParserOptimized.worker-yo8WMPFM.js} +2 -2
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +9 -12
- package/dist/{packages/threejs/src/utils/modelOptimizer.js → modelOptimizer-D6fRg-DF.js} +1 -1
- package/dist/threejs.cjs +3 -1
- package/dist/threejs.js +428 -58
- package/dist/useBatchGLTFLoader-19GZ1dxv.cjs +5 -0
- package/dist/useBatchGLTFLoader-DPT0_95u.js +493 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +32 -40
- package/package.json +1 -1
- package/dist/packages/threejs/package.json.cjs +0 -1
- package/dist/packages/threejs/package.json.js +0 -4
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +0 -83
- package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useGLTFLoader.js +0 -292
- package/dist/packages/threejs/src/hooks/useObb.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useObb.js +0 -41
- package/dist/packages/threejs/src/hooks/useRaycaster.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useRaycaster.js +0 -35
- package/dist/packages/threejs/src/hooks/useThreeJs.cjs +0 -5
- package/dist/packages/threejs/src/hooks/useThreeJs.js +0 -153
- package/dist/packages/threejs/src/instance/IDBCache.cjs +0 -1
- package/dist/packages/threejs/src/instance/IDBCache.js +0 -142
- package/dist/packages/threejs/src/instance/threeIns.cjs +0 -3
- package/dist/packages/threejs/src/instance/threeIns.js +0 -393
- package/dist/packages/threejs/src/utils/CacheMonitor.cjs +0 -1
- package/dist/packages/threejs/src/utils/CacheMonitor.js +0 -125
- package/dist/packages/threejs/src/utils/ImageLoader.cjs +0 -1
- package/dist/packages/threejs/src/utils/ImageLoader.js +0 -33
- package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +0 -1
- package/dist/packages/threejs/src/utils/PredictiveLoader.js +0 -155
- package/dist/packages/threejs/src/utils/RetryHelper.cjs +0 -1
- package/dist/packages/threejs/src/utils/RetryHelper.js +0 -108
- package/dist/packages/threejs/src/utils/common.cjs +0 -1
- package/dist/packages/threejs/src/utils/common.js +0 -15
- package/dist/packages/threejs/src/utils/css3dHelper.cjs +0 -15
- package/dist/packages/threejs/src/utils/css3dHelper.js +0 -42
- package/dist/packages/threejs/src/utils/disposeObject.cjs +0 -1
- package/dist/packages/threejs/src/utils/disposeObject.js +0 -13
- package/dist/packages/threejs/src/utils/helper.cjs +0 -1
- package/dist/packages/threejs/src/utils/helper.js +0 -47
- package/dist/packages/threejs/src/utils/modelSerialize.cjs +0 -1
- package/dist/packages/threejs/src/utils/modelSerialize.js +0 -225
- package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +0 -1
- package/dist/packages/threejs/src/utils/sceneRebuilder.js +0 -138
- package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +0 -1
- package/dist/packages/threejs/src/workers/gltfParser.worker.js +0 -11
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +0 -1
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +0 -11
- /package/dist/{packages/threejs/src/utils/modelOptimizer.cjs → modelOptimizer-A0Cs6f9e.cjs} +0 -0
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useGLTFLoader as z } from "./useGLTFLoader.js";
|
|
2
|
-
function P() {
|
|
3
|
-
const { asyncFetch: x } = z();
|
|
4
|
-
async function i(t, e = {}) {
|
|
5
|
-
const {
|
|
6
|
-
maxConcurrent: r = 3,
|
|
7
|
-
maxRetries: c = 3,
|
|
8
|
-
onProgress: s,
|
|
9
|
-
onModelLoad: o,
|
|
10
|
-
onModelError: a
|
|
11
|
-
} = e, u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), y = [...t];
|
|
12
|
-
let h = 0, f = 0;
|
|
13
|
-
return new Promise((m, F) => {
|
|
14
|
-
const C = async (w) => {
|
|
15
|
-
const { path: l, version: R } = w;
|
|
16
|
-
f++;
|
|
17
|
-
try {
|
|
18
|
-
const n = await x(
|
|
19
|
-
l,
|
|
20
|
-
R,
|
|
21
|
-
(d) => {
|
|
22
|
-
const p = h / t.length * 100 + d / t.length;
|
|
23
|
-
s == null || s(Math.round(p));
|
|
24
|
-
},
|
|
25
|
-
{ maxRetries: c }
|
|
26
|
-
);
|
|
27
|
-
if (n)
|
|
28
|
-
u.set(l, n), o == null || o(l, n);
|
|
29
|
-
else
|
|
30
|
-
throw new Error(`模型加载返回空结果: ${l}`);
|
|
31
|
-
} catch (n) {
|
|
32
|
-
console.error(`[ 批量加载 ] 加载失败: ${l}`, n), g.set(l, n), a == null || a(l, n);
|
|
33
|
-
} finally {
|
|
34
|
-
f--, h++;
|
|
35
|
-
const n = h / t.length * 100;
|
|
36
|
-
s == null || s(Math.round(n)), $();
|
|
37
|
-
}
|
|
38
|
-
}, $ = () => {
|
|
39
|
-
if (h >= t.length) {
|
|
40
|
-
g.size > 0 && console.warn(`[ 批量加载 ] 完成,但有 ${g.size} 个模型加载失败`), m(u);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
for (; y.length > 0 && f < r; ) {
|
|
44
|
-
const w = y.shift();
|
|
45
|
-
C(w);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
$();
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async function L(t, e = {}) {
|
|
52
|
-
console.log(`[ 批量预加载 ] 开始预加载 ${t.length} 个模型`);
|
|
53
|
-
const r = await i(t, {
|
|
54
|
-
...e,
|
|
55
|
-
maxConcurrent: e.maxConcurrent || 2
|
|
56
|
-
// 预加载使用较低的并发数
|
|
57
|
-
});
|
|
58
|
-
return console.log(`[ 批量预加载 ] 完成,成功加载 ${r.size} 个模型`), r;
|
|
59
|
-
}
|
|
60
|
-
async function M(t, e = {}) {
|
|
61
|
-
const r = /* @__PURE__ */ new Map();
|
|
62
|
-
for (let c = 0; c < t.length; c++)
|
|
63
|
-
console.log(`[ 分组批量加载 ] 加载第 ${c + 1}/${t.length} 组`), (await i(t[c], {
|
|
64
|
-
...e,
|
|
65
|
-
onProgress: (o) => {
|
|
66
|
-
var u;
|
|
67
|
-
const a = c / t.length * 100 + o / t.length;
|
|
68
|
-
(u = e.onProgress) == null || u.call(e, Math.round(a));
|
|
69
|
-
}
|
|
70
|
-
})).forEach((o, a) => {
|
|
71
|
-
r.set(a, o);
|
|
72
|
-
});
|
|
73
|
-
return r;
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
batchLoad: i,
|
|
77
|
-
preload: L,
|
|
78
|
-
batchLoadGroups: M
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export {
|
|
82
|
-
P as useBatchGLTFLoader
|
|
83
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/loaders/GLTFLoader.cjs"),U=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/loaders/DRACOLoader.cjs"),R=require("../instance/IDBCache.cjs");require("three");const V=require("../utils/modelSerialize.cjs"),u=require("../utils/CacheMonitor.cjs"),b=require("../utils/RetryHelper.cjs"),J=require("../utils/sceneRebuilder.cjs"),K=require("../workers/gltfParser.worker.cjs"),N=require("../workers/gltfParserOptimized.worker.cjs");let k;const O="/draco/";let y,g,$=0;const m=new Map,d=new Map,Q=(D={})=>{const{debug:T=!1}=D,C=new x.GLTFLoader,z=new U.DRACOLoader;z.setDecoderPath(O),C.setDRACOLoader(z);const n={info:(...e)=>T&&console.log(...e),warn:(...e)=>T&&console.warn(...e),error:(...e)=>console.error(...e),time:e=>T&&console.time(e),timeEnd:e=>T&&console.timeEnd(e)};function G(e,r,t,s){return C.load(e,r,t,s)}function S(e,r){return new Promise((t,s)=>{C.load(e,t,r,s)})}async function E(e,r,t,s={}){const o=performance.now();let i=!1;const{maxRetries:a=3,optimizeMaterials:h=!1,simplifyGeometry:p=!1,simplifyRatio:M=.5,simplifyOptions:L={},useMemoryCache:W=!0}=s;if(W){const c=d.get(e);if(c&&c.has(r)){const l=c.get(r);n.info(`[ 内存缓存命中 ] ${e} (version: ${r})`),n.time("[ 内存缓存克隆耗时 ]");const w=l.clone(!0);return n.timeEnd("[ 内存缓存克隆耗时 ]"),u.cacheMonitor.recordHit(performance.now()-o),w}}try{let c=await v(e,r);if(c)n.info(`[ asyncFetch ] ====> IndexedDB 缓存命中: ${e}`),i=!0;else{n.info(`[ asyncFetch ] ====> 缓存未命中: ${e}`),n.time("[ fetchArrayBuffer ] 加载模型耗时"),c=await b.RetryHelper.retry(()=>q(e,t),{maxRetries:a,shouldRetry:F=>!!(F.name==="TypeError"||F.message.includes("HTTP error! status: 5"))}),n.timeEnd("[ fetchArrayBuffer ] 加载模型耗时");const f=performance.now();await k.saveModel(e,r,c);const P=performance.now()-f;u.cacheMonitor.recordCacheSave(P),i=!1}n.time("[ 解析模型耗时 ]");let l=await A(c);if(n.timeEnd("[ 解析模型耗时 ]"),n.time("[ 模型优化耗时 ]"),h){n.info("🔧 [ 材质优化 ] 开始合并相同材质...");const{modelOptimizer:f}=await Promise.resolve().then(()=>require("../utils/modelOptimizer.cjs"));l=f.optimizeMaterials(l)}if(p){n.info(`🔧 [ 几何体简化 ] 开始简化模型 (比例: ${M})...`);const{modelOptimizer:f}=await Promise.resolve().then(()=>require("../utils/modelOptimizer.cjs")),P={minFaceCount:100,preserveUVs:!0,...L};l=f.simplifyModel(l,M,P)}if(n.timeEnd("[ 模型优化耗时 ]"),W){d.has(e)||d.set(e,new Map);const f=d.get(e);f.has(r)||(n.info(`[ 内存缓存 ] 存储模型 ${e} (version: ${r})`),f.set(r,l.clone(!0)))}const w=performance.now()-o;return i?u.cacheMonitor.recordHit(w):u.cacheMonitor.recordMiss(w),l}catch(c){throw n.error(`加载模型 ${e} 失败:`,c),u.cacheMonitor.recordError(e,c),c.name==="TypeError"&&c.message.includes("fetch")?b.ModelLoadError.networkError(e,c):c}}async function q(e,r){return new Promise((t,s)=>{fetch(e).then(o=>{if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return o}).then(o=>{const i=o.headers.get("content-length"),a=i?parseInt(i,10):0;if(r&&a>0){const h=o.body.getReader();let p=0;const M=[],L=()=>{h.read().then(({done:W,value:c})=>{if(W){const l=new Uint8Array(p);let w=0;for(const f of M)l.set(f,w),w+=f.length;t(l.buffer);return}M.push(c),p+=c.length,r(Math.round(p/a*100)),L()}).catch(s)};L()}else return o.arrayBuffer()}).then(o=>t(o)).catch(o=>{s(o)})})}async function v(e,r){return k||(k=new R.IDBCache),k.getModel(e,r)}async function A(e,r={}){if(!e)return null;const{useOptimizedParser:t=!0,useProgressive:s=!1}=r;if(t){const a=B();if(a)try{n.time("[ 优化解析 ] 使用 Transferable Objects 解析");const h=await H(a,e,s);return n.timeEnd("[ 优化解析 ] 使用 Transferable Objects 解析"),J.rebuildScene(h)}catch(h){n.warn("[ 优化解析 ] 失败,回退到标准解析",h)}}const o=I();if(o)try{const a=await j(o,e);return V.dataToObject3D(a)}catch(a){n.warn("[ GLTF Worker ] ====> 解析失败,回退到主线程解析",a)}return(await _(e)).scene}const I=()=>{if(typeof window>"u"||typeof Worker>"u")return null;if(!y)try{n.info("[GLTF Worker] 使用 ?worker 工厂函数创建 Worker..."),y=K(),n.info("[GLTF Worker] Worker 创建成功:",y),y.onmessage=e=>{const{id:r,data:t,error:s}=e.data||{};if(!r||!m.has(r))return;const{resolve:o,reject:i}=m.get(r);m.delete(r),s?i(new Error(s)):o(t)},y.onmessageerror=e=>{console.error("[ GLTF Worker ] ====> 消息解析失败",e)},y.onerror=e=>{console.error("[ GLTF Worker ] ====> 运行错误",e)}}catch(e){console.error("[GLTF Worker] 创建 Worker 失败:",e),console.error("[GLTF Worker] 错误堆栈:",e.stack)}return y},B=()=>{if(typeof window>"u"||typeof Worker>"u")return null;if(!g)try{n.info("[Optimized Worker] 使用 ?worker 工厂函数创建 Worker..."),g=N(),n.info("[Optimized Worker] Worker 创建成功:",g),g.onmessage=e=>{const{id:r,data:t,error:s,type:o}=e.data||{};if(!r||!m.has(r)||o==="progress")return;const{resolve:i,reject:a}=m.get(r);m.delete(r),s?a(new Error(s)):i(t)},g.onmessageerror=e=>{console.error("[ 优化 Worker ] ====> 消息解析失败",e)},g.onerror=e=>{console.error("[ 优化 Worker ] ====> 运行错误",e)}}catch(e){return n.warn("[ 优化 Worker ] ====> 创建失败,可能不支持模块化 Worker",e),null}return g},H=(e,r,t=!1)=>new Promise((s,o)=>{const i=++$;m.set(i,{resolve:s,reject:o});const a={id:i,arrayBuffer:r,dracoPath:O,mode:t?"progressive":"standard"};e.postMessage(a,[r])}),j=(e,r)=>new Promise((t,s)=>{const o=++$;m.set(o,{resolve:t,reject:s}),e.postMessage({id:o,arrayBuffer:r,dracoPath:O})}),_=e=>new Promise((r,t)=>{C.parse(e,"",r,t)});return{load:G,asyncLoad:S,asyncCacheLoad:E,asyncFetch:E,getCacheStats:()=>u.cacheMonitor.getStats(),getCache:()=>k||(k=new R.IDBCache),logCacheReport:()=>u.cacheMonitor.logReport(),resetCacheStats:()=>u.cacheMonitor.reset(),clearMemoryCache:()=>{let e=0;for(const[r,t]of d.entries())e+=t.size,t.clear();return d.clear(),n.info(`[ 内存缓存 ] 已清空,释放了 ${e} 个模型`),e},getMemoryCacheInfo:()=>{const e=[];let r=0;for(const[t,s]of d.entries()){const o=Array.from(s.keys());r+=o.length,e.push({path:t,versions:o,count:o.length})}return{totalPaths:d.size,totalModels:r,details:e}},deleteMemoryCache:(e,r)=>{const t=d.get(e);if(!t)return!1;if(r){const s=t.delete(r);return t.size===0&&d.delete(e),n.info(`[ 内存缓存 ] 删除模型 ${e} (version: ${r})`),s}else{const s=t.size;return d.delete(e),n.info(`[ 内存缓存 ] 删除模型 ${e} 及其所有版本 (共 ${s} 个)`),s>0}}}};exports.useGLTFLoader=Q;
|
|
@@ -1,292 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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;
|