@ridp/threejs 1.4.1 → 1.4.2
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/hooks.cjs +1 -1
- package/dist/hooks.js +12 -9
- package/dist/packages/threejs/package.json.cjs +1 -0
- package/dist/packages/threejs/package.json.js +4 -0
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +83 -0
- package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useGLTFLoader.js +292 -0
- package/dist/packages/threejs/src/hooks/useObb.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useObb.js +41 -0
- package/dist/packages/threejs/src/hooks/useRaycaster.cjs +1 -0
- package/dist/packages/threejs/src/hooks/useRaycaster.js +35 -0
- package/dist/packages/threejs/src/hooks/useThreeJs.cjs +5 -0
- package/dist/packages/threejs/src/hooks/useThreeJs.js +153 -0
- package/dist/packages/threejs/src/instance/IDBCache.cjs +1 -0
- package/dist/packages/threejs/src/instance/IDBCache.js +142 -0
- package/dist/packages/threejs/src/instance/threeIns.cjs +3 -0
- package/dist/packages/threejs/src/instance/threeIns.js +369 -0
- package/dist/packages/threejs/src/utils/CacheMonitor.cjs +1 -0
- package/dist/packages/threejs/src/utils/CacheMonitor.js +125 -0
- package/dist/packages/threejs/src/utils/ImageLoader.cjs +1 -0
- package/dist/packages/threejs/src/utils/ImageLoader.js +33 -0
- package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +1 -0
- package/dist/packages/threejs/src/utils/PredictiveLoader.js +155 -0
- package/dist/packages/threejs/src/utils/RetryHelper.cjs +1 -0
- package/dist/packages/threejs/src/utils/RetryHelper.js +108 -0
- package/dist/packages/threejs/src/utils/common.cjs +1 -0
- package/dist/packages/threejs/src/utils/common.js +15 -0
- package/dist/packages/threejs/src/utils/css3dHelper.cjs +15 -0
- package/dist/packages/threejs/src/utils/css3dHelper.js +42 -0
- package/dist/packages/threejs/src/utils/disposeObject.cjs +1 -0
- package/dist/packages/threejs/src/utils/disposeObject.js +13 -0
- package/dist/packages/threejs/src/utils/helper.cjs +1 -0
- package/dist/packages/threejs/src/utils/helper.js +47 -0
- package/dist/packages/threejs/src/utils/modelSerialize.cjs +1 -0
- package/dist/packages/threejs/src/utils/modelSerialize.js +225 -0
- package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +1 -0
- package/dist/packages/threejs/src/utils/sceneRebuilder.js +138 -0
- package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +1 -0
- package/dist/packages/threejs/src/workers/gltfParser.worker.js +11 -0
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +1 -0
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +11 -0
- package/dist/threejs.cjs +1 -3
- package/dist/threejs.js +58 -404
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +40 -32
- package/package.json +1 -1
- package/dist/ImageLoader-Br_nvMOg.js +0 -1444
- package/dist/ImageLoader-DL32KyTh.cjs +0 -24
- package/dist/PredictiveLoader-CZfMSjv-.js +0 -3731
- package/dist/PredictiveLoader-DDxh7dDg.cjs +0 -2
- package/dist/useBatchGLTFLoader-B5EUagWI.js +0 -493
- package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +0 -5
- /package/dist/{modelOptimizer-A0Cs6f9e.cjs → packages/threejs/src/utils/modelOptimizer.cjs} +0 -0
- /package/dist/{modelOptimizer-BRPnM2RH.js → packages/threejs/src/utils/modelOptimizer.js} +0 -0
package/dist/hooks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./packages/threejs/src/hooks/useThreeJs.cjs"),r=require("./packages/threejs/src/hooks/useRaycaster.cjs"),e=require("./packages/threejs/src/hooks/useObb.cjs"),t=require("./packages/threejs/src/hooks/useGLTFLoader.cjs"),u=require("./packages/threejs/src/hooks/useBatchGLTFLoader.cjs");exports.useThreeJs=s.useThreeJs;exports.useRaycaster=r.useRaycaster;exports.intersectColor=e.intersectColor;exports.obbObjects=e.obbObjects;exports.useObb=e.useObb;exports.useGLTFLoader=t.useGLTFLoader;exports.useBatchGLTFLoader=u.useBatchGLTFLoader;
|
package/dist/hooks.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useThreeJs as o } from "./packages/threejs/src/hooks/useThreeJs.js";
|
|
2
|
+
import { useRaycaster as s } from "./packages/threejs/src/hooks/useRaycaster.js";
|
|
3
|
+
import { intersectColor as b, obbObjects as f, useObb as m } from "./packages/threejs/src/hooks/useObb.js";
|
|
4
|
+
import { useGLTFLoader as u } from "./packages/threejs/src/hooks/useGLTFLoader.js";
|
|
5
|
+
import { useBatchGLTFLoader as c } from "./packages/threejs/src/hooks/useBatchGLTFLoader.js";
|
|
3
6
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
b as intersectColor,
|
|
8
|
+
f as obbObjects,
|
|
9
|
+
c as useBatchGLTFLoader,
|
|
10
|
+
u as useGLTFLoader,
|
|
11
|
+
m as useObb,
|
|
12
|
+
s as useRaycaster,
|
|
13
|
+
o as useThreeJs
|
|
11
14
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="1.4.2";exports.version=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./useGLTFLoader.cjs");function P(){const{asyncFetch:d}=C.useGLTFLoader();async function i(e,t={}){const{maxConcurrent:r=3,maxRetries:c=3,onProgress:s,onModelLoad:o,onModelError:a}=t,u=new Map,g=new Map,y=[...e];let h=0,f=0;return new Promise((F,R)=>{const G=async w=>{const{path:l,version:T}=w;f++;try{const n=await d(l,T,b=>{const x=h/e.length*100+b/e.length;s==null||s(Math.round(x))},{maxRetries:c});if(n)u.set(l,n),o==null||o(l,n);else throw new Error(`模型加载返回空结果: ${l}`)}catch(n){console.error(`[ 批量加载 ] 加载失败: ${l}`,n),g.set(l,n),a==null||a(l,n)}finally{f--,h++;const n=h/e.length*100;s==null||s(Math.round(n)),L()}},L=()=>{if(h>=e.length){g.size>0&&console.warn(`[ 批量加载 ] 完成,但有 ${g.size} 个模型加载失败`),F(u);return}for(;y.length>0&&f<r;){const w=y.shift();G(w)}};L()})}async function $(e,t={}){console.log(`[ 批量预加载 ] 开始预加载 ${e.length} 个模型`);const r=await i(e,{...t,maxConcurrent:t.maxConcurrent||2});return console.log(`[ 批量预加载 ] 完成,成功加载 ${r.size} 个模型`),r}async function M(e,t={}){const r=new Map;for(let c=0;c<e.length;c++)console.log(`[ 分组批量加载 ] 加载第 ${c+1}/${e.length} 组`),(await i(e[c],{...t,onProgress:o=>{var u;const a=c/e.length*100+o/e.length;(u=t.onProgress)==null||u.call(t,Math.round(a))}})).forEach((o,a)=>{r.set(a,o)});return r}return{batchLoad:i,preload:$,batchLoadGroups:M}}exports.useBatchGLTFLoader=P;
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -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;
|