@ridp/threejs 1.4.0 → 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-DXx88iwh.js +0 -1444
- package/dist/ImageLoader-DzG6sgbB.cjs +0 -24
- package/dist/PredictiveLoader--_3bEnce.js +0 -3738
- package/dist/PredictiveLoader-CpRi-ULa.cjs +0 -2
- package/dist/useBatchGLTFLoader-CDNvTMtt.cjs +0 -5
- package/dist/useBatchGLTFLoader-Dg-xau9i.js +0 -493
- /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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useGLTFLoader as l } from "../hooks/useGLTFLoader.js";
|
|
2
|
+
class d {
|
|
3
|
+
constructor(e = {}) {
|
|
4
|
+
this.options = {
|
|
5
|
+
maxPreloadCount: e.maxPreloadCount || 5,
|
|
6
|
+
preloadDelay: e.preloadDelay || 1e3,
|
|
7
|
+
enableLearning: e.enableLearning !== !1
|
|
8
|
+
}, this.loadHistory = /* @__PURE__ */ new Map(), this.loadSequence = [], this.associations = /* @__PURE__ */ new Map(), this.preloadQueue = /* @__PURE__ */ new Set(), this.isPreloading = !1, this.loader = null, this.getLoader = () => (this.loader || (this.loader = l()), this.loader);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 记录模型加载
|
|
12
|
+
* @param {string} path - 模型路径
|
|
13
|
+
* @param {string} version - 模型版本
|
|
14
|
+
*/
|
|
15
|
+
recordLoad(e, s) {
|
|
16
|
+
const t = Date.now(), o = this.loadHistory.get(e) || {
|
|
17
|
+
count: 0,
|
|
18
|
+
lastLoadTime: 0,
|
|
19
|
+
versions: /* @__PURE__ */ new Set()
|
|
20
|
+
};
|
|
21
|
+
o.count++, o.lastLoadTime = t, o.versions.add(s), this.loadHistory.set(e, o), this.loadSequence.push({ path: e, timestamp: t }), this.loadSequence.length > 100 && this.loadSequence.shift(), this.options.enableLearning && this.loadSequence.length >= 2 && this._learnAssociations(e), this._triggerPredictivePreload(e, s);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 学习模型关联规则
|
|
25
|
+
* @private
|
|
26
|
+
* @param {string} currentPath - 当前加载的模型
|
|
27
|
+
*/
|
|
28
|
+
_learnAssociations(e) {
|
|
29
|
+
const t = this.loadSequence.length - 1;
|
|
30
|
+
for (let o = Math.max(0, t - 10); o < t; o++) {
|
|
31
|
+
const { path: a } = this.loadSequence[o];
|
|
32
|
+
if (this.loadSequence[t].timestamp - this.loadSequence[o].timestamp < 5 * 60 * 1e3 && a !== e) {
|
|
33
|
+
this.associations.has(a) || this.associations.set(a, /* @__PURE__ */ new Map());
|
|
34
|
+
const i = this.associations.get(a), n = i.get(e) || 0;
|
|
35
|
+
i.set(e, n + 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 触发预测性预加载
|
|
41
|
+
* @private
|
|
42
|
+
* @param {string} currentPath - 当前加载的模型
|
|
43
|
+
* @param {string} version - 模型版本
|
|
44
|
+
*/
|
|
45
|
+
_triggerPredictivePreload(e, s) {
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
const t = this.predictNext(e);
|
|
48
|
+
this.preload(t, s);
|
|
49
|
+
}, this.options.preloadDelay);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 预测下一个可能加载的模型
|
|
53
|
+
* @param {string} currentPath - 当前模型路径
|
|
54
|
+
* @returns {Array<string>} 预测的模型路径列表
|
|
55
|
+
*/
|
|
56
|
+
predictNext(e) {
|
|
57
|
+
const s = /* @__PURE__ */ new Map(), t = this.associations.get(e);
|
|
58
|
+
t && t.forEach((i, n) => {
|
|
59
|
+
s.set(n, (s.get(n) || 0) + i * 2);
|
|
60
|
+
});
|
|
61
|
+
const o = Array.from(this.loadHistory.values()).reduce((i, n) => i + n.count, 0) / (this.loadHistory.size || 1);
|
|
62
|
+
this.loadHistory.forEach((i, n) => {
|
|
63
|
+
if (n !== e) {
|
|
64
|
+
const c = i.count / o;
|
|
65
|
+
s.set(n, (s.get(n) || 0) + c);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const a = this.loadSequence.slice(-10);
|
|
69
|
+
return new Set(a.map((i) => i.path)).forEach((i) => {
|
|
70
|
+
i !== e && s.set(i, (s.get(i) || 0) + 0.5);
|
|
71
|
+
}), Array.from(s.entries()).sort((i, n) => n[1] - i[1]).slice(0, this.options.maxPreloadCount).map(([i]) => i);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 预加载模型列表
|
|
75
|
+
* @param {Array<string>} paths - 模型路径列表
|
|
76
|
+
* @param {string} version - 模型版本
|
|
77
|
+
*/
|
|
78
|
+
async preload(e, s = "latest") {
|
|
79
|
+
if (this.isPreloading)
|
|
80
|
+
return;
|
|
81
|
+
this.isPreloading = !0;
|
|
82
|
+
const { asyncFetch: t } = this.getLoader(), o = e.filter((a) => !this.preloadQueue.has(a)).slice(0, this.options.maxPreloadCount).map(async (a) => {
|
|
83
|
+
this.preloadQueue.add(a);
|
|
84
|
+
try {
|
|
85
|
+
console.log(`[ 智能预加载 ] 开始预加载: ${a}`), await t(a, s), console.log(`[ 智能预加载 ] 完成: ${a}`);
|
|
86
|
+
} catch (r) {
|
|
87
|
+
console.warn(`[ 智能预加载 ] 失败: ${a}`, r);
|
|
88
|
+
} finally {
|
|
89
|
+
this.preloadQueue.delete(a);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
await Promise.all(o), this.isPreloading = !1;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 手动添加关联规则
|
|
96
|
+
* @param {string} fromPath - 源模型路径
|
|
97
|
+
* @param {Array<string>} toPaths - 关联的模型路径列表
|
|
98
|
+
*/
|
|
99
|
+
addAssociation(e, s) {
|
|
100
|
+
this.associations.has(e) || this.associations.set(e, /* @__PURE__ */ new Map());
|
|
101
|
+
const t = this.associations.get(e);
|
|
102
|
+
s.forEach((o) => {
|
|
103
|
+
const a = t.get(o) || 0;
|
|
104
|
+
t.set(o, a + 10);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 获取加载统计信息
|
|
109
|
+
* @returns {Object} 统计数据
|
|
110
|
+
*/
|
|
111
|
+
getStats() {
|
|
112
|
+
const e = Array.from(this.loadHistory.entries()).sort((s, t) => t[1].count - s[1].count).slice(0, 10).map(([s, t]) => ({
|
|
113
|
+
path: s,
|
|
114
|
+
loadCount: t.count,
|
|
115
|
+
lastLoadTime: new Date(t.lastLoadTime).toLocaleString()
|
|
116
|
+
}));
|
|
117
|
+
return {
|
|
118
|
+
totalModelsLoaded: this.loadHistory.size,
|
|
119
|
+
totalAssociations: this.associations.size,
|
|
120
|
+
topModels: e,
|
|
121
|
+
preloadQueueSize: this.preloadQueue.size
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 清空历史记录
|
|
126
|
+
*/
|
|
127
|
+
clearHistory() {
|
|
128
|
+
this.loadHistory.clear(), this.loadSequence = [], this.associations.clear();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 导出关联规则(可持久化)
|
|
132
|
+
* @returns {Object} 关联规则数据
|
|
133
|
+
*/
|
|
134
|
+
exportAssociations() {
|
|
135
|
+
const e = {};
|
|
136
|
+
return this.associations.forEach((s, t) => {
|
|
137
|
+
e[t] = Array.from(s.entries());
|
|
138
|
+
}), e;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 导入关联规则
|
|
142
|
+
* @param {Object} data - 关联规则数据
|
|
143
|
+
*/
|
|
144
|
+
importAssociations(e) {
|
|
145
|
+
Object.entries(e).forEach(([s, t]) => {
|
|
146
|
+
const o = new Map(t);
|
|
147
|
+
this.associations.set(s, o);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const g = new d();
|
|
152
|
+
export {
|
|
153
|
+
d as PredictiveLoader,
|
|
154
|
+
g as predictiveLoader
|
|
155
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class l{static async retry(t,e={}){const{maxRetries:r=3,initialDelay:s=1e3,maxDelay:m=1e4,backoffFactor:y=2,shouldRetry:E=l.defaultShouldRetry}=e;let u,i=s;for(let a=0;a<=r;a++)try{return await t()}catch(n){if(u=n,a===r||!E(n,a))throw n;console.warn(`[ RetryHelper ] 操作失败,第 ${a+1} 次尝试失败,${i}ms 后进行第 ${a+2} 次尝试...`,n),await l.delay(i),i=Math.min(i*y,m)}throw u}static defaultShouldRetry(t,e){if(t.name==="TypeError"&&t.message.includes("fetch"))return!0;if(t.message.includes("HTTP error")){const r=t.message.match(/status:\s*(\d+)/);if(r){const s=parseInt(r[1],10);return s>=500||s===429||s===408}}return!1}static delay(t){return new Promise(e=>setTimeout(e,t))}}const c={NETWORK:"NETWORK",PARSE:"PARSE",VERSION_MISMATCH:"VERSION",UNKNOWN:"UNKNOWN"};class o extends Error{constructor(t,e,r,s){super(t),this.name="ModelLoadError",this.type=e,this.path=r,this.originalError=s,this.timestamp=Date.now()}static networkError(t,e){return new o(`网络加载失败: ${t}`,c.NETWORK,t,e)}static parseError(t,e){return new o(`模型解析失败: ${t}`,c.PARSE,t,e)}static versionMismatchError(t,e,r){return new o(`版本不匹配: ${t} (期望: ${e}, 实际: ${r})`,c.VERSION_MISMATCH,t)}}exports.ErrorType=c;exports.ModelLoadError=o;exports.RetryHelper=l;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
class u {
|
|
2
|
+
/**
|
|
3
|
+
* 异步操作并支持重试
|
|
4
|
+
* @param {Function} operation - 要执行的异步操作
|
|
5
|
+
* @param {RetryOptions} options - 重试配置
|
|
6
|
+
* @returns {Promise} 操作结果
|
|
7
|
+
*/
|
|
8
|
+
static async retry(t, e = {}) {
|
|
9
|
+
const {
|
|
10
|
+
maxRetries: r = 3,
|
|
11
|
+
initialDelay: s = 1e3,
|
|
12
|
+
maxDelay: m = 1e4,
|
|
13
|
+
backoffFactor: E = 2,
|
|
14
|
+
shouldRetry: h = u.defaultShouldRetry
|
|
15
|
+
} = e;
|
|
16
|
+
let l, i = s;
|
|
17
|
+
for (let a = 0; a <= r; a++)
|
|
18
|
+
try {
|
|
19
|
+
return await t();
|
|
20
|
+
} catch (n) {
|
|
21
|
+
if (l = n, a === r || !h(n, a))
|
|
22
|
+
throw n;
|
|
23
|
+
console.warn(
|
|
24
|
+
`[ RetryHelper ] 操作失败,第 ${a + 1} 次尝试失败,${i}ms 后进行第 ${a + 2} 次尝试...`,
|
|
25
|
+
n
|
|
26
|
+
), await u.delay(i), i = Math.min(i * E, m);
|
|
27
|
+
}
|
|
28
|
+
throw l;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 默认的重试判断逻辑
|
|
32
|
+
* @param {Error} error - 错误对象
|
|
33
|
+
* @param {number} attempt - 当前尝试次数
|
|
34
|
+
* @returns {boolean} 是否应该重试
|
|
35
|
+
*/
|
|
36
|
+
static defaultShouldRetry(t, e) {
|
|
37
|
+
if (t.name === "TypeError" && t.message.includes("fetch"))
|
|
38
|
+
return !0;
|
|
39
|
+
if (t.message.includes("HTTP error")) {
|
|
40
|
+
const r = t.message.match(/status:\s*(\d+)/);
|
|
41
|
+
if (r) {
|
|
42
|
+
const s = parseInt(r[1], 10);
|
|
43
|
+
return s >= 500 || s === 429 || s === 408;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return !1;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 延迟指定时间
|
|
50
|
+
* @param {number} ms - 延迟毫秒数
|
|
51
|
+
* @returns {Promise}
|
|
52
|
+
*/
|
|
53
|
+
static delay(t) {
|
|
54
|
+
return new Promise((e) => setTimeout(e, t));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const c = {
|
|
58
|
+
NETWORK: "NETWORK",
|
|
59
|
+
// 网络错误
|
|
60
|
+
PARSE: "PARSE",
|
|
61
|
+
// 解析错误
|
|
62
|
+
VERSION_MISMATCH: "VERSION",
|
|
63
|
+
// 版本不匹配
|
|
64
|
+
UNKNOWN: "UNKNOWN"
|
|
65
|
+
// 未知错误
|
|
66
|
+
};
|
|
67
|
+
class o extends Error {
|
|
68
|
+
constructor(t, e, r, s) {
|
|
69
|
+
super(t), this.name = "ModelLoadError", this.type = e, this.path = r, this.originalError = s, this.timestamp = Date.now();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 创建网络错误
|
|
73
|
+
*/
|
|
74
|
+
static networkError(t, e) {
|
|
75
|
+
return new o(
|
|
76
|
+
`网络加载失败: ${t}`,
|
|
77
|
+
c.NETWORK,
|
|
78
|
+
t,
|
|
79
|
+
e
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 创建解析错误
|
|
84
|
+
*/
|
|
85
|
+
static parseError(t, e) {
|
|
86
|
+
return new o(
|
|
87
|
+
`模型解析失败: ${t}`,
|
|
88
|
+
c.PARSE,
|
|
89
|
+
t,
|
|
90
|
+
e
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 创建版本不匹配错误
|
|
95
|
+
*/
|
|
96
|
+
static versionMismatchError(t, e, r) {
|
|
97
|
+
return new o(
|
|
98
|
+
`版本不匹配: ${t} (期望: ${e}, 实际: ${r})`,
|
|
99
|
+
c.VERSION_MISMATCH,
|
|
100
|
+
t
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
c as ErrorType,
|
|
106
|
+
o as ModelLoadError,
|
|
107
|
+
u as RetryHelper
|
|
108
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(u,i)=>{const t={};u.forEach(n=>{let e=n.parent;for(;e;)t[e.uuid]?t[e.uuid]++:t[e.uuid]=1,e=e.parent});let o=null,r=0;for(const n in t)t[n]>r&&(r=t[n],o=i.getObjectByProperty("uuid",n));return o};exports.getCommonParent=a;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const a = (r, i) => {
|
|
2
|
+
const t = {};
|
|
3
|
+
r.forEach((n) => {
|
|
4
|
+
let e = n.parent;
|
|
5
|
+
for (; e; )
|
|
6
|
+
t[e.uuid] ? t[e.uuid]++ : t[e.uuid] = 1, e = e.parent;
|
|
7
|
+
});
|
|
8
|
+
let u = null, o = 0;
|
|
9
|
+
for (const n in t)
|
|
10
|
+
t[n] > o && (o = t[n], u = i.getObjectByProperty("uuid", n));
|
|
11
|
+
return u;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
a as getCommonParent
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/renderers/CSS3DRenderer.cjs");function s(n,e=[.3,.3,.3]){const t=document.querySelector(`#${n}`);if(!t){console.log(" 获取 infoPlane 元素失败 (id) =====> :",n);return}const r=t.cloneNode(!0);r.style.display="block";const o=new l.CSS3DSprite(r);return o.visible=!1,o.scale.set(...e),o}function c(n,e){const t=a(n);t.style.display="block";const r=new l.CSS3DSprite(t);return r.visible=!1,r.scale.set(e,e,e),r}const a=n=>{const e=document.createElement("div");e.style.cssText=`
|
|
2
|
+
border-radius: 50px;
|
|
3
|
+
border: 2px solid rgba(255, 255, 255, 0.5);
|
|
4
|
+
background-color: rgba(15, 20, 22, 0.562);
|
|
5
|
+
justify-content: flex-start;
|
|
6
|
+
align-items: center;
|
|
7
|
+
padding: 20px 30px;
|
|
8
|
+
display: flex;
|
|
9
|
+
transform-origin: center 0;`;const t=document.createElement("span");return t.style.cssText=`
|
|
10
|
+
font-size: 40px;
|
|
11
|
+
line-height: 1;
|
|
12
|
+
white-space: nowrap;
|
|
13
|
+
color: #fff;
|
|
14
|
+
font-weight: 700;
|
|
15
|
+
`,t.innerText=n,e.appendChild(t),e};exports.createInfoPlane=s;exports.createTagPlane=c;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CSS3DSprite as r } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/renderers/CSS3DRenderer.js";
|
|
2
|
+
function a(n, e = [0.3, 0.3, 0.3]) {
|
|
3
|
+
const t = document.querySelector(`#${n}`);
|
|
4
|
+
if (!t) {
|
|
5
|
+
console.log(" 获取 infoPlane 元素失败 (id) =====> :", n);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const o = t.cloneNode(!0);
|
|
9
|
+
o.style.display = "block";
|
|
10
|
+
const l = new r(o);
|
|
11
|
+
return l.visible = !1, l.scale.set(...e), l;
|
|
12
|
+
}
|
|
13
|
+
function i(n, e) {
|
|
14
|
+
const t = s(n);
|
|
15
|
+
t.style.display = "block";
|
|
16
|
+
const o = new r(t);
|
|
17
|
+
return o.visible = !1, o.scale.set(e, e, e), o;
|
|
18
|
+
}
|
|
19
|
+
const s = (n) => {
|
|
20
|
+
const e = document.createElement("div");
|
|
21
|
+
e.style.cssText = `
|
|
22
|
+
border-radius: 50px;
|
|
23
|
+
border: 2px solid rgba(255, 255, 255, 0.5);
|
|
24
|
+
background-color: rgba(15, 20, 22, 0.562);
|
|
25
|
+
justify-content: flex-start;
|
|
26
|
+
align-items: center;
|
|
27
|
+
padding: 20px 30px;
|
|
28
|
+
display: flex;
|
|
29
|
+
transform-origin: center 0;`;
|
|
30
|
+
const t = document.createElement("span");
|
|
31
|
+
return t.style.cssText = `
|
|
32
|
+
font-size: 40px;
|
|
33
|
+
line-height: 1;
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
color: #fff;
|
|
36
|
+
font-weight: 700;
|
|
37
|
+
`, t.innerText = n, e.appendChild(t), e;
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
a as createInfoPlane,
|
|
41
|
+
i as createTagPlane
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=e=>{e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{r(i)}):r(e.material)),e.children&&e.children.forEach(i=>s(i))};function r(e){for(const i in e)e[i]&&e[i].isTexture&&e[i].dispose();e.dispose()}exports.disposeThreeObject=s;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const e = (i) => {
|
|
2
|
+
i.geometry && i.geometry.dispose(), i.material && (Array.isArray(i.material) ? i.material.forEach((r) => {
|
|
3
|
+
s(r);
|
|
4
|
+
}) : s(i.material)), i.children && i.children.forEach((r) => e(r));
|
|
5
|
+
};
|
|
6
|
+
function s(i) {
|
|
7
|
+
for (const r in i)
|
|
8
|
+
i[r] && i[r].isTexture && i[r].dispose();
|
|
9
|
+
i.dispose();
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
e as disposeThreeObject
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("three"),c=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/controls/OrbitControls.cjs"),a=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/controls/MapControls.cjs"),s=require("../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/libs/stats.module.cjs");function l(e){return new t.CameraHelper(e)}function i(e=150,...r){return new t.GridHelper(e,e/10,...r)}function u(e){return new t.BoxHelper(e,16776960)}function p(e,r){return new c.OrbitControls(e,r)}function f(e,r){return new a.MapControls(e,r)}function H(){const e=new t.Raycaster,r=new t.Vector2(0,0);return{raycaster:e,pointer:r}}function w(e=10){return new t.AxesHelper(e)}function C(e=new t.Vector3(1,1,1),r=new t.Vector3(10,10,10),n=5,o=16776960){return e.normalize(),new t.ArrowHelper(e,r,n,o)}function x(){const e=new s;return e.dom.style.cssText="position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e}exports.createArrowHelper=C;exports.createAxesHelper=w;exports.createBox3Helper=u;exports.createCameraHelper=l;exports.createGridHelper=i;exports.createMapControls=f;exports.createOrbitControl=p;exports.createRaycaster=H;exports.createStats=x;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Vector3 as t, CameraHelper as c, GridHelper as a, BoxHelper as f, Raycaster as i, Vector2 as p, AxesHelper as s, ArrowHelper as u } from "three";
|
|
2
|
+
import { OrbitControls as l } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/controls/OrbitControls.js";
|
|
3
|
+
import { MapControls as w } from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/controls/MapControls.js";
|
|
4
|
+
import m from "../../../../node_modules/.pnpm/three@0.178.0/node_modules/three/examples/jsm/libs/stats.module.js";
|
|
5
|
+
function A(e) {
|
|
6
|
+
return new c(e);
|
|
7
|
+
}
|
|
8
|
+
function b(e = 150, ...r) {
|
|
9
|
+
return new a(e, e / 10, ...r);
|
|
10
|
+
}
|
|
11
|
+
function d(e) {
|
|
12
|
+
return new f(e, 16776960);
|
|
13
|
+
}
|
|
14
|
+
function B(e, r) {
|
|
15
|
+
return new l(e, r);
|
|
16
|
+
}
|
|
17
|
+
function G(e, r) {
|
|
18
|
+
return new w(e, r);
|
|
19
|
+
}
|
|
20
|
+
function M() {
|
|
21
|
+
const e = new i(), r = new p(0, 0);
|
|
22
|
+
return {
|
|
23
|
+
raycaster: e,
|
|
24
|
+
pointer: r
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function O(e = 10) {
|
|
28
|
+
return new s(e);
|
|
29
|
+
}
|
|
30
|
+
function R(e = new t(1, 1, 1), r = new t(10, 10, 10), n = 5, o = 16776960) {
|
|
31
|
+
return e.normalize(), new u(e, r, n, o);
|
|
32
|
+
}
|
|
33
|
+
function S() {
|
|
34
|
+
const e = new m();
|
|
35
|
+
return e.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
R as createArrowHelper,
|
|
39
|
+
O as createAxesHelper,
|
|
40
|
+
d as createBox3Helper,
|
|
41
|
+
A as createCameraHelper,
|
|
42
|
+
b as createGridHelper,
|
|
43
|
+
G as createMapControls,
|
|
44
|
+
B as createOrbitControl,
|
|
45
|
+
M as createRaycaster,
|
|
46
|
+
S as createStats
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("three");function d(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,a.get?a:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const l=d(D),h={};async function A(e,n=50){const t={type:e.type,name:e.name,position:e.position.toArray(),rotation:e.rotation.toArray(),scale:e.scale.toArray(),visible:e.visible,children:[],geometry:null,material:null,userData:e.userData};e.isMesh&&(t.geometry=y(e.geometry),t.material=m(e.material));const a=[{object:e,parentData:t}];let s=0;for(;a.length>0;){const{object:r,parentData:i}=a.pop();for(const o of r.children){const c={type:o.type,name:o.name,position:o.position.toArray(),rotation:o.rotation.toArray(),scale:o.scale.toArray(),visible:o.visible,children:[],geometry:null,material:null,userData:o.userData};o.isMesh&&(c.geometry=y(o.geometry),c.material=m(o.material)),i.children.push(c),a.push({object:o,parentData:c}),s++,s%n===0&&await new Promise(p=>requestAnimationFrame(p))}}return t}function g(e){const n={type:e.type,name:e.name,position:e.position.toArray(),rotation:e.rotation.toArray(),scale:e.scale.toArray(),visible:e.visible,children:[],geometry:null,material:null,userData:e.userData};e.isMesh&&(n.geometry=y(e.geometry),n.material=m(e.material));const t=[{object:e,parentData:n}];for(;t.length>0;){const{object:a,parentData:s}=t.pop();for(const r of a.children){const i={type:r.type,name:r.name,position:r.position.toArray(),rotation:r.rotation.toArray(),scale:r.scale.toArray(),visible:r.visible,children:[],geometry:null,material:null,userData:r.userData};r.isMesh&&(i.geometry=y(r.geometry),i.material=m(r.material)),s.children.push(i),t.push({object:r,parentData:i})}}return n}async function w(e,n=50){const t=[];let a;switch(e.type){case"Mesh":const r=u(e.geometry),i=f(e.material);a=new l.Mesh(r,i);break;case"Group":a=new l.Group;break;case"Object3D":a=new l.Object3D;break;default:return console.warn(`Unsupported object type: ${e.type}`),null}a.name=e.name,a.position.fromArray(e.position),a.rotation.fromArray(e.rotation),a.scale.fromArray(e.scale),a.visible=e.visible,a.userData=e.userData,t.push({data:e,object:a});let s=0;for(;t.length>0;){const{data:r,object:i}=t.pop();for(const o of[...r.children].reverse()){let c;switch(o.type){case"Mesh":const p=u(o.geometry),b=f(o.material);c=new l.Mesh(p,b);break;case"Group":c=new l.Group;break;case"Object3D":c=new l.Object3D;break;default:console.warn(`Unsupported object type: ${o.type}`);continue}c&&(c.name=o.name,c.position.fromArray(o.position),c.rotation.fromArray(o.rotation),c.scale.fromArray(o.scale),c.visible=o.visible,c.userData=o.userData,i.add(c),t.push({data:o,object:c}),s++,s%n===0&&await new Promise(p=>requestAnimationFrame(p)))}}return a}function O(e){const n=[];let t;switch(e.type){case"Mesh":const a=u(e.geometry),s=f(e.material);t=new l.Mesh(a,s);break;case"Group":t=new l.Group;break;case"Object3D":t=new l.Object3D;break;default:return console.warn(`Unsupported object type: ${e.type}`),null}for(t.name=e.name,t.position.fromArray(e.position),t.rotation.fromArray(e.rotation),t.scale.fromArray(e.scale),t.visible=e.visible,t.userData=e.userData,n.push({data:e,object:t});n.length>0;){const{data:a,object:s}=n.pop();for(const r of[...a.children].reverse()){let i;switch(r.type){case"Mesh":const o=u(r.geometry),c=f(r.material);i=new l.Mesh(o,c);break;case"Group":i=new l.Group;break;case"Object3D":i=new l.Object3D;break;default:console.warn(`Unsupported object type: ${r.type}`);continue}i&&(i.name=r.name,i.position.fromArray(r.position),i.rotation.fromArray(r.rotation),i.scale.fromArray(r.scale),i.visible=r.visible,i.userData=r.userData,s.add(i),n.push({data:r,object:i}))}}return t}function y(e){const n={},{attributes:t,index:a,type:s}=e;t.position&&(n.position={type:"Float32Array",array:Array.from(t.position.array),itemSize:3}),t.normal&&(n.normal={type:"Float32Array",array:Array.from(t.normal.array),itemSize:3}),t.uv&&(n.uv={type:"Float32Array",array:Array.from(t.uv.array),itemSize:2});const r={type:s,attributes:n};return a&&a.array&&(r.index={type:"Uint32Array",array:Array.from(a.array),itemSize:1}),r}function u(e){const{type:n,attributes:t,index:a}=e,s=new l.BufferGeometry;for(const r in t)if(t.hasOwnProperty(r)){const{type:i,array:o,itemSize:c}=t[r];s.setAttribute(r,new l.BufferAttribute(new Float32Array(o),c))}return a&&s.setIndex(a.array),s}function m(e){return{type:e.type,color:e.color.getHex(),map:e.map?e.map.image.src:null,opacity:e.opacity,name:e.name,depthTest:e.depthTest,depthWrite:e.depthWrite,transparent:e.transparent,side:e.side,roughness:e.roughness,metalness:e.metalness,emissive:e.emissive.getHex()}}function f(e){if(h[e.name])return h[e.name];const{type:n,...t}=e,a=n||"MeshStandardMaterial",s=new l[a]({...t});if(e.map){const r=new l.TextureLoader().load(e.map);s.map=r}return s.needsUpdate=!0,h[e.name]=s,s}exports.dataToObject3D=w;exports.dataToObject3DSync=O;exports.object3DToData=A;exports.object3DToDataSync=g;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import * as l from "three";
|
|
2
|
+
const f = {};
|
|
3
|
+
async function D(e, s = 50) {
|
|
4
|
+
const t = {
|
|
5
|
+
type: e.type,
|
|
6
|
+
name: e.name,
|
|
7
|
+
position: e.position.toArray(),
|
|
8
|
+
rotation: e.rotation.toArray(),
|
|
9
|
+
scale: e.scale.toArray(),
|
|
10
|
+
visible: e.visible,
|
|
11
|
+
children: [],
|
|
12
|
+
geometry: null,
|
|
13
|
+
material: null,
|
|
14
|
+
userData: e.userData
|
|
15
|
+
};
|
|
16
|
+
e.isMesh && (t.geometry = y(e.geometry), t.material = u(e.material));
|
|
17
|
+
const a = [{ object: e, parentData: t }];
|
|
18
|
+
let i = 0;
|
|
19
|
+
for (; a.length > 0; ) {
|
|
20
|
+
const { object: r, parentData: n } = a.pop();
|
|
21
|
+
for (const o of r.children) {
|
|
22
|
+
const c = {
|
|
23
|
+
type: o.type,
|
|
24
|
+
name: o.name,
|
|
25
|
+
position: o.position.toArray(),
|
|
26
|
+
rotation: o.rotation.toArray(),
|
|
27
|
+
scale: o.scale.toArray(),
|
|
28
|
+
visible: o.visible,
|
|
29
|
+
children: [],
|
|
30
|
+
geometry: null,
|
|
31
|
+
material: null,
|
|
32
|
+
userData: o.userData
|
|
33
|
+
};
|
|
34
|
+
o.isMesh && (c.geometry = y(o.geometry), c.material = u(o.material)), n.children.push(c), a.push({ object: o, parentData: c }), i++, i % s === 0 && await new Promise((p) => requestAnimationFrame(p));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
}
|
|
39
|
+
function A(e) {
|
|
40
|
+
const s = {
|
|
41
|
+
type: e.type,
|
|
42
|
+
name: e.name,
|
|
43
|
+
position: e.position.toArray(),
|
|
44
|
+
rotation: e.rotation.toArray(),
|
|
45
|
+
scale: e.scale.toArray(),
|
|
46
|
+
visible: e.visible,
|
|
47
|
+
children: [],
|
|
48
|
+
geometry: null,
|
|
49
|
+
material: null,
|
|
50
|
+
userData: e.userData
|
|
51
|
+
};
|
|
52
|
+
e.isMesh && (s.geometry = y(e.geometry), s.material = u(e.material));
|
|
53
|
+
const t = [{ object: e, parentData: s }];
|
|
54
|
+
for (; t.length > 0; ) {
|
|
55
|
+
const { object: a, parentData: i } = t.pop();
|
|
56
|
+
for (const r of a.children) {
|
|
57
|
+
const n = {
|
|
58
|
+
type: r.type,
|
|
59
|
+
name: r.name,
|
|
60
|
+
position: r.position.toArray(),
|
|
61
|
+
rotation: r.rotation.toArray(),
|
|
62
|
+
scale: r.scale.toArray(),
|
|
63
|
+
visible: r.visible,
|
|
64
|
+
children: [],
|
|
65
|
+
geometry: null,
|
|
66
|
+
material: null,
|
|
67
|
+
userData: r.userData
|
|
68
|
+
};
|
|
69
|
+
r.isMesh && (n.geometry = y(r.geometry), n.material = u(r.material)), i.children.push(n), t.push({ object: r, parentData: n });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return s;
|
|
73
|
+
}
|
|
74
|
+
async function w(e, s = 50) {
|
|
75
|
+
const t = [];
|
|
76
|
+
let a;
|
|
77
|
+
switch (e.type) {
|
|
78
|
+
case "Mesh":
|
|
79
|
+
const r = m(e.geometry), n = h(e.material);
|
|
80
|
+
a = new l.Mesh(r, n);
|
|
81
|
+
break;
|
|
82
|
+
case "Group":
|
|
83
|
+
a = new l.Group();
|
|
84
|
+
break;
|
|
85
|
+
case "Object3D":
|
|
86
|
+
a = new l.Object3D();
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
return console.warn(`Unsupported object type: ${e.type}`), null;
|
|
90
|
+
}
|
|
91
|
+
a.name = e.name, a.position.fromArray(e.position), a.rotation.fromArray(e.rotation), a.scale.fromArray(e.scale), a.visible = e.visible, a.userData = e.userData, t.push({ data: e, object: a });
|
|
92
|
+
let i = 0;
|
|
93
|
+
for (; t.length > 0; ) {
|
|
94
|
+
const { data: r, object: n } = t.pop();
|
|
95
|
+
for (const o of [...r.children].reverse()) {
|
|
96
|
+
let c;
|
|
97
|
+
switch (o.type) {
|
|
98
|
+
case "Mesh":
|
|
99
|
+
const p = m(o.geometry), b = h(o.material);
|
|
100
|
+
c = new l.Mesh(p, b);
|
|
101
|
+
break;
|
|
102
|
+
case "Group":
|
|
103
|
+
c = new l.Group();
|
|
104
|
+
break;
|
|
105
|
+
case "Object3D":
|
|
106
|
+
c = new l.Object3D();
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
console.warn(`Unsupported object type: ${o.type}`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
c && (c.name = o.name, c.position.fromArray(o.position), c.rotation.fromArray(o.rotation), c.scale.fromArray(o.scale), c.visible = o.visible, c.userData = o.userData, n.add(c), t.push({ data: o, object: c }), i++, i % s === 0 && await new Promise((p) => requestAnimationFrame(p)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return a;
|
|
116
|
+
}
|
|
117
|
+
function d(e) {
|
|
118
|
+
const s = [];
|
|
119
|
+
let t;
|
|
120
|
+
switch (e.type) {
|
|
121
|
+
case "Mesh":
|
|
122
|
+
const a = m(e.geometry), i = h(e.material);
|
|
123
|
+
t = new l.Mesh(a, i);
|
|
124
|
+
break;
|
|
125
|
+
case "Group":
|
|
126
|
+
t = new l.Group();
|
|
127
|
+
break;
|
|
128
|
+
case "Object3D":
|
|
129
|
+
t = new l.Object3D();
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
return console.warn(`Unsupported object type: ${e.type}`), null;
|
|
133
|
+
}
|
|
134
|
+
for (t.name = e.name, t.position.fromArray(e.position), t.rotation.fromArray(e.rotation), t.scale.fromArray(e.scale), t.visible = e.visible, t.userData = e.userData, s.push({ data: e, object: t }); s.length > 0; ) {
|
|
135
|
+
const { data: a, object: i } = s.pop();
|
|
136
|
+
for (const r of [...a.children].reverse()) {
|
|
137
|
+
let n;
|
|
138
|
+
switch (r.type) {
|
|
139
|
+
case "Mesh":
|
|
140
|
+
const o = m(r.geometry), c = h(r.material);
|
|
141
|
+
n = new l.Mesh(o, c);
|
|
142
|
+
break;
|
|
143
|
+
case "Group":
|
|
144
|
+
n = new l.Group();
|
|
145
|
+
break;
|
|
146
|
+
case "Object3D":
|
|
147
|
+
n = new l.Object3D();
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
console.warn(`Unsupported object type: ${r.type}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
n && (n.name = r.name, n.position.fromArray(r.position), n.rotation.fromArray(r.rotation), n.scale.fromArray(r.scale), n.visible = r.visible, n.userData = r.userData, i.add(n), s.push({ data: r, object: n }));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return t;
|
|
157
|
+
}
|
|
158
|
+
function y(e) {
|
|
159
|
+
const s = {}, { attributes: t, index: a, type: i } = e;
|
|
160
|
+
t.position && (s.position = {
|
|
161
|
+
type: "Float32Array",
|
|
162
|
+
array: Array.from(t.position.array),
|
|
163
|
+
itemSize: 3
|
|
164
|
+
}), t.normal && (s.normal = {
|
|
165
|
+
type: "Float32Array",
|
|
166
|
+
array: Array.from(t.normal.array),
|
|
167
|
+
itemSize: 3
|
|
168
|
+
}), t.uv && (s.uv = {
|
|
169
|
+
type: "Float32Array",
|
|
170
|
+
array: Array.from(t.uv.array),
|
|
171
|
+
itemSize: 2
|
|
172
|
+
});
|
|
173
|
+
const r = {
|
|
174
|
+
type: i,
|
|
175
|
+
attributes: s
|
|
176
|
+
};
|
|
177
|
+
return a && a.array && (r.index = {
|
|
178
|
+
type: "Uint32Array",
|
|
179
|
+
array: Array.from(a.array),
|
|
180
|
+
itemSize: 1
|
|
181
|
+
}), r;
|
|
182
|
+
}
|
|
183
|
+
function m(e) {
|
|
184
|
+
const { type: s, attributes: t, index: a } = e, i = new l.BufferGeometry();
|
|
185
|
+
for (const r in t)
|
|
186
|
+
if (t.hasOwnProperty(r)) {
|
|
187
|
+
const { type: n, array: o, itemSize: c } = t[r];
|
|
188
|
+
i.setAttribute(
|
|
189
|
+
r,
|
|
190
|
+
new l.BufferAttribute(new Float32Array(o), c)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return a && i.setIndex(a.array), i;
|
|
194
|
+
}
|
|
195
|
+
function u(e) {
|
|
196
|
+
return {
|
|
197
|
+
type: e.type,
|
|
198
|
+
color: e.color.getHex(),
|
|
199
|
+
map: e.map ? e.map.image.src : null,
|
|
200
|
+
opacity: e.opacity,
|
|
201
|
+
name: e.name,
|
|
202
|
+
depthTest: e.depthTest,
|
|
203
|
+
depthWrite: e.depthWrite,
|
|
204
|
+
transparent: e.transparent,
|
|
205
|
+
side: e.side,
|
|
206
|
+
roughness: e.roughness,
|
|
207
|
+
metalness: e.metalness,
|
|
208
|
+
emissive: e.emissive.getHex()
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function h(e) {
|
|
212
|
+
if (f[e.name]) return f[e.name];
|
|
213
|
+
const { type: s, ...t } = e, a = s || "MeshStandardMaterial", i = new l[a]({ ...t });
|
|
214
|
+
if (e.map) {
|
|
215
|
+
const r = new l.TextureLoader().load(e.map);
|
|
216
|
+
i.map = r;
|
|
217
|
+
}
|
|
218
|
+
return i.needsUpdate = !0, f[e.name] = i, i;
|
|
219
|
+
}
|
|
220
|
+
export {
|
|
221
|
+
w as dataToObject3D,
|
|
222
|
+
d as dataToObject3DSync,
|
|
223
|
+
D as object3DToData,
|
|
224
|
+
A as object3DToDataSync
|
|
225
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("three");function y(e){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(i,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return i.default=e,Object.freeze(i)}const o=y(a);function h(e){const{geometries:i,materials:r,hierarchy:n}=e,c=new Map;i.forEach((s,t)=>{const u=b(s);c.set(t,u)});const f=new Map;r.forEach((s,t)=>{const u=g(s);f.set(t,u)});const l=new o.Group;l.name="Scene";const d=new Map;return n.forEach(s=>{let t;if(s.type==="Mesh"){const u=s.geometryIndex>=0?c.get(s.geometryIndex):null,p=s.materialIndex>=0?f.get(s.materialIndex):null;t=new o.Mesh(u,p)}else s.type==="Group"?t=new o.Group:s.type==="Object3D"?t=new o.Object3D:t=new o.Object3D;t.name=s.name,t.position.fromArray(s.position),t.rotation.fromArray(s.rotation),t.scale.fromArray(s.scale),t.visible=s.visible,d.set(s.id,t)}),n.forEach(s=>{const t=d.get(s.id);if(s.parentId!==null){const u=d.get(s.parentId);u&&u.add(t)}else l.add(t)}),l}function b(e){const i=new o.BufferGeometry;for(const r in e.attributes){const n=e.attributes[r],c=n.array;let f;if(c.byteLength===0){console.warn(`[ sceneRebuilder ] 属性 ${r} 的数组为空`);continue}if(c.buffer&&c.buffer.byteLength===0){console.warn(`[ sceneRebuilder ] 属性 ${r} 的 buffer 已被转移,尝试重建`);continue}f=c;const l=new o.BufferAttribute(f,n.itemSize);l.normalized=n.normalized,i.setAttribute(r,l)}if(e.index){const r=e.index,n=r.array;if(n&&n.byteLength>0){const c=new o.BufferAttribute(n,r.itemSize);i.setIndex(c)}}return i}function g(e){let i;const r={color:e.color!==void 0?e.color:16777215,opacity:e.opacity!==void 0?e.opacity:1,transparent:e.transparent!==void 0?e.transparent:!1,alphaTest:e.alphaTest!==void 0?e.alphaTest:0,side:e.side!==void 0?e.side:o.FrontSide,depthTest:e.depthTest!==void 0?e.depthTest:!0,depthWrite:e.depthWrite!==void 0?e.depthWrite:!0,wireframe:e.wireframe!==void 0?e.wireframe:!1,vertexColors:e.vertexColors!==void 0?e.vertexColors:!1};switch(e.type){case"MeshStandardMaterial":i=new o.MeshStandardMaterial({...r,roughness:e.roughness!==void 0?e.roughness:.5,metalness:e.metalness!==void 0?e.metalness:.5,emissive:e.emissive!==void 0?e.emissive:0,emissiveIntensity:e.emissiveIntensity!==void 0?e.emissiveIntensity:1});break;case"MeshBasicMaterial":i=new o.MeshBasicMaterial({...r});break;case"MeshPhongMaterial":i=new o.MeshPhongMaterial({...r,shininess:e.shininess!==void 0?e.shininess:30,specular:e.specular!==void 0?e.specular:1118481,emissive:e.emissive!==void 0?e.emissive:0,emissiveIntensity:e.emissiveIntensity!==void 0?e.emissiveIntensity:1});break;default:i=new o.MeshStandardMaterial(r)}return i.uuid=e.uuid,i}class m{constructor(){this.geometries=[],this.materials=[],this.hierarchy=[],this.geometryMap=new Map,this.materialMap=new Map}addChunk(i){i.geometries&&i.geometries.forEach(r=>{const n=this.geometries.length;this.geometries.push(r),this.geometryMap.set(r.uuid,n)}),i.materials&&i.materials.forEach(r=>{const n=this.materials.length;this.materials.push(r),this.materialMap.set(r.uuid,n)}),i.hierarchy&&this.hierarchy.push(...i.hierarchy)}buildCurrent(){const i={geometries:this.geometries,materials:this.materials,hierarchy:this.hierarchy};return h(i)}finalize(){return this.buildCurrent()}}exports.ProgressiveSceneBuilder=m;exports.rebuildScene=h;
|