@ridp/threejs 1.5.0 → 1.5.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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useBatchGLTFLoader-DHJyQcpJ.cjs"),r=require("./PredictiveLoader-Xy5S4HBr.cjs");exports.intersectColor=e.intersectColor;exports.obbObjects=e.obbObjects;exports.useBatchGLTFLoader=e.useBatchGLTFLoader;exports.useObb=e.useObb;exports.useRaycaster=e.useRaycaster;exports.useThreeJs=e.useThreeJs;exports.useGLTFLoader=r.useGLTFLoader;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useBatchGLTFLoader-wNkKD723.cjs"),r=require("./PredictiveLoader-c5o_CMyI.cjs");exports.intersectColor=e.intersectColor;exports.obbObjects=e.obbObjects;exports.useBatchGLTFLoader=e.useBatchGLTFLoader;exports.useObb=e.useObb;exports.useRaycaster=e.useRaycaster;exports.useThreeJs=e.useThreeJs;exports.useGLTFLoader=r.useGLTFLoader;
package/dist/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
- import { i as a, o, c as r, b as t, a as u, u as b } from "./useBatchGLTFLoader-C1C8R5Ss.js";
2
- import { u as L } from "./PredictiveLoader-C9zJlZEQ.js";
1
+ import { i as a, o, c as r, b as t, a as u, u as b } from "./useBatchGLTFLoader-BtuzDyHn.js";
2
+ import { u as L } from "./PredictiveLoader-Ce8DXwbW.js";
3
3
  export {
4
4
  a as intersectColor,
5
5
  o as obbObjects,
@@ -10,29 +10,33 @@ class f {
10
10
  * @returns {THREE.BufferGeometry} 简化后的几何体
11
11
  */
12
12
  simplifyGeometry(o, r = this.simplifyRatio) {
13
- const e = o.geometry;
14
- if (!e.isBufferGeometry)
15
- return console.warn("[ ModelOptimizer ] 非BufferGeometry,跳过简化"), e;
16
- const t = e.index ? e.index.count / 3 : e.attributes.position.count / 3, i = Math.floor(t * r);
13
+ const t = o.geometry;
14
+ if (!t.isBufferGeometry)
15
+ return console.warn("[ ModelOptimizer ] 非BufferGeometry,跳过简化"), t;
16
+ const e = t.index ? t.index.count / 3 : t.attributes.position.count / 3, i = Math.floor(e * r);
17
17
  if (i < 4)
18
- return console.warn("[ ModelOptimizer ] 简化后面数太少,跳过"), e;
18
+ return console.warn("[ ModelOptimizer ] 简化后面数太少,跳过"), t;
19
19
  try {
20
- const n = this.modifierModify(e, i);
21
- return console.log(`[ ModelOptimizer ] 简化完成: ${t} -> ${i} 面`), n;
20
+ const n = this.modifierModify(t, i);
21
+ return console.log(`[ ModelOptimizer ] 简化完成: ${e} -> ${i} 面`), n;
22
22
  } catch (n) {
23
- return console.warn("[ ModelOptimizer ] 简化失败,使用原几何体", n), e;
23
+ return console.warn("[ ModelOptimizer ] 简化失败,使用原几何体", n), t;
24
24
  }
25
25
  }
26
26
  /**
27
- * 使用修饰器修改几何体(简化实现)
28
- * 注意: 完整实现需要 three/addons/modifiers/SimplifyModifier.js
29
- * 这里提供一个基础实现
27
+ * 使用修饰器修改几何体
28
+ * 注意: 此方法需要 three/addons/modifiers/SimplifyModifier.js 才能正常工作
29
+ * 如果 SimplifyModifier 不可用,将返回原几何体(不做简化)
30
+ *
31
+ * @param {THREE.BufferGeometry} geometry - 几何体
32
+ * @param {number} targetFaceCount - 目标面数
33
+ * @returns {THREE.BufferGeometry} 简化后的几何体
30
34
  */
31
35
  modifierModify(o, r) {
32
- if (typeof a.SimplifyModifier < "u")
33
- return new a.SimplifyModifier().modify(o, r);
34
- const e = o.clone();
35
- return e.attributes.normal && e.deleteAttribute("normal"), e.attributes.uv && this.simplifyRatio < 0.3 && e.deleteAttribute("uv"), e;
36
+ return typeof a.SimplifyModifier < "u" ? new a.SimplifyModifier().modify(o, r) : (console.warn(
37
+ `[ ModelOptimizer ] SimplifyModifier 不可用,跳过几何体简化。
38
+ 建议安装: import { SimplifyModifier } from "three/addons/modifiers/SimplifyModifier.js"`
39
+ ), o);
36
40
  }
37
41
  /**
38
42
  * 优化材质 - 合并相同材质
@@ -40,26 +44,26 @@ class f {
40
44
  */
41
45
  optimizeMaterials(o) {
42
46
  const r = /* @__PURE__ */ new Map();
43
- let e = 0;
44
- return o.traverse((t) => {
45
- if (t.isMesh && t.material) {
46
- const i = this.getMaterialKey(t.material);
47
+ let t = 0;
48
+ return o.traverse((e) => {
49
+ if (e.isMesh && e.material) {
50
+ const i = this.getMaterialKey(e.material);
47
51
  if (r.has(i)) {
48
- const n = t.material;
49
- t.material = r.get(i), e++, n.dispose && n.dispose();
52
+ const n = e.material;
53
+ e.material = r.get(i), t++, n.dispose && n.dispose();
50
54
  } else
51
- r.set(i, t.material);
55
+ r.set(i, e.material);
52
56
  }
53
- }), console.log(`[ ModelOptimizer ] 材质合并: 合并了 ${e} 个重复材质`), o;
57
+ }), console.log(`[ ModelOptimizer ] 材质合并: 合并了 ${t} 个重复材质`), o;
54
58
  }
55
59
  /**
56
60
  * 获取材质的唯一标识
57
61
  */
58
62
  getMaterialKey(o) {
59
- var e;
63
+ var t;
60
64
  return [
61
65
  o.type,
62
- (e = o.color) == null ? void 0 : e.getHex(),
66
+ (t = o.color) == null ? void 0 : t.getHex(),
63
67
  o.roughness,
64
68
  o.metalness,
65
69
  o.opacity,
@@ -73,17 +77,17 @@ class f {
73
77
  */
74
78
  mergeMeshes(o) {
75
79
  if (o.length === 0) return null;
76
- const r = [], e = [];
77
- if (o.forEach((t) => {
78
- t.geometry && r.push(t.geometry), t.material && e.push(t.material);
80
+ const r = [], t = [];
81
+ if (o.forEach((e) => {
82
+ e.geometry && r.push(e.geometry), e.material && t.push(e.material);
79
83
  }), r.length === 0) return null;
80
84
  try {
81
85
  if (typeof a.BufferGeometryUtils < "u" && a.BufferGeometryUtils.mergeGeometries) {
82
- const t = a.BufferGeometryUtils.mergeGeometries(r), i = new a.Mesh(t, e[0]);
86
+ const e = a.BufferGeometryUtils.mergeGeometries(r), i = new a.Mesh(e, t[0]);
83
87
  return console.log(`[ ModelOptimizer ] 合并了 ${o.length} 个网格`), i;
84
88
  }
85
- } catch (t) {
86
- console.warn("[ ModelOptimizer ] 合并网格失败", t);
89
+ } catch (e) {
90
+ console.warn("[ ModelOptimizer ] 合并网格失败", e);
87
91
  }
88
92
  return null;
89
93
  }
@@ -94,14 +98,14 @@ class f {
94
98
  * @param {Array<number>} ratios - 简化比例数组
95
99
  * @returns {THREE.LOD} LOD 对象
96
100
  */
97
- createLOD(o, r = [0, 50, 100], e = [1, 0.5, 0.25]) {
98
- const t = new a.LOD();
99
- t.addLevel(o, r[0]);
101
+ createLOD(o, r = [0, 50, 100], t = [1, 0.5, 0.25]) {
102
+ const e = new a.LOD();
103
+ e.addLevel(o, r[0]);
100
104
  for (let i = 1; i < r.length; i++) {
101
105
  const n = o.clone();
102
- n.geometry = this.simplifyGeometry(o, e[i]), t.addLevel(n, r[i]);
106
+ n.geometry = this.simplifyGeometry(o, t[i]), e.addLevel(n, r[i]);
103
107
  }
104
- return console.log(`[ ModelOptimizer ] 创建 LOD: ${r.length} 个细节级别`), t;
108
+ return console.log(`[ ModelOptimizer ] 创建 LOD: ${r.length} 个细节级别`), e;
105
109
  }
106
110
  /**
107
111
  * 计算模型统计信息
@@ -109,17 +113,17 @@ class f {
109
113
  * @returns {Object} 统计信息
110
114
  */
111
115
  getModelStats(o) {
112
- let r = 0, e = 0, t = 0, i = /* @__PURE__ */ new Set();
116
+ let r = 0, t = 0, e = 0, i = /* @__PURE__ */ new Set();
113
117
  return o.traverse((n) => {
114
118
  if (n.isMesh) {
115
119
  r++;
116
120
  const s = n.geometry;
117
- s.index ? e += s.index.count / 3 : s.attributes.position && (e += s.attributes.position.count / 3), s.attributes.position && (t += s.attributes.position.count), n.material && (Array.isArray(n.material) ? n.material.forEach((l) => i.add(l.uuid)) : i.add(n.material.uuid));
121
+ s.index ? t += s.index.count / 3 : s.attributes.position && (t += s.attributes.position.count / 3), s.attributes.position && (e += s.attributes.position.count), n.material && (Array.isArray(n.material) ? n.material.forEach((l) => i.add(l.uuid)) : i.add(n.material.uuid));
118
122
  }
119
123
  }), {
120
124
  meshCount: r,
121
- triangleCount: e,
122
- vertexCount: t,
125
+ triangleCount: t,
126
+ vertexCount: e,
123
127
  materialCount: i.size
124
128
  };
125
129
  }
@@ -129,13 +133,13 @@ class f {
129
133
  * @param {THREE.Object3D} optimized - 优化后对象
130
134
  */
131
135
  generateReport(o, r) {
132
- const e = this.getModelStats(o), t = this.getModelStats(r);
133
- return console.group("📊 模型优化报告"), console.log("网格数量:", `${e.meshCount} -> ${t.meshCount}`), console.log("三角形数量:", `${e.triangleCount} -> ${t.triangleCount} (${((1 - t.triangleCount / e.triangleCount) * 100).toFixed(1)}% 减少)`), console.log("顶点数量:", `${e.vertexCount} -> ${t.vertexCount} (${((1 - t.vertexCount / e.vertexCount) * 100).toFixed(1)}% 减少)`), console.log("材质数量:", `${e.materialCount} -> ${t.materialCount}`), console.groupEnd(), {
134
- original: e,
135
- optimized: t,
136
+ const t = this.getModelStats(o), e = this.getModelStats(r);
137
+ return console.group("📊 模型优化报告"), console.log("网格数量:", `${t.meshCount} -> ${e.meshCount}`), console.log("三角形数量:", `${t.triangleCount} -> ${e.triangleCount} (${((1 - e.triangleCount / t.triangleCount) * 100).toFixed(1)}% 减少)`), console.log("顶点数量:", `${t.vertexCount} -> ${e.vertexCount} (${((1 - e.vertexCount / t.vertexCount) * 100).toFixed(1)}% 减少)`), console.log("材质数量:", `${t.materialCount} -> ${e.materialCount}`), console.groupEnd(), {
138
+ original: t,
139
+ optimized: e,
136
140
  reduction: {
137
- triangles: 1 - t.triangleCount / e.triangleCount,
138
- vertices: 1 - t.vertexCount / e.vertexCount
141
+ triangles: 1 - e.triangleCount / t.triangleCount,
142
+ vertices: 1 - e.vertexCount / t.vertexCount
139
143
  }
140
144
  };
141
145
  }
@@ -148,8 +152,8 @@ class f {
148
152
  * @param {boolean} options.preserveUVs - 是否保留 UV 坐标(默认 true)
149
153
  * @returns {THREE.Object3D} 简化后的对象
150
154
  */
151
- simplifyModel(o, r = 0.5, e = {}) {
152
- const { minFaceCount: t = 100, preserveUVs: i = !0 } = e;
155
+ simplifyModel(o, r = 0.5, t = {}) {
156
+ const { minFaceCount: e = 100, preserveUVs: i = !0 } = t;
153
157
  let n = 0, s = 0;
154
158
  return o.traverse((l) => {
155
159
  if (l.isMesh) {
@@ -158,7 +162,7 @@ class f {
158
162
  s++;
159
163
  return;
160
164
  }
161
- if ((m.index ? m.index.count / 3 : m.attributes.position.count / 3) < t) {
165
+ if ((m.index ? m.index.count / 3 : m.attributes.position.count / 3) < e) {
162
166
  s++;
163
167
  return;
164
168
  }
@@ -172,8 +176,8 @@ class f {
172
176
  }), console.log(`[ ModelOptimizer ] 模型简化完成: 成功 ${n} 个, 跳过 ${s} 个`), o;
173
177
  }
174
178
  }
175
- const c = new f();
179
+ const g = new f();
176
180
  export {
177
181
  f as ModelOptimizer,
178
- c as modelOptimizer
182
+ g as modelOptimizer
179
183
  };
@@ -1 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("three");function g(u){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const r in u)if(r!=="default"){const e=Object.getOwnPropertyDescriptor(u,r);Object.defineProperty(o,r,e.get?e:{enumerable:!0,get:()=>u[r]})}}return o.default=u,Object.freeze(o)}const a=g(p);class c{constructor(){this.simplifyRatio=.5}simplifyGeometry(o,r=this.simplifyRatio){const e=o.geometry;if(!e.isBufferGeometry)return console.warn("[ ModelOptimizer ] 非BufferGeometry,跳过简化"),e;const t=e.index?e.index.count/3:e.attributes.position.count/3,i=Math.floor(t*r);if(i<4)return console.warn("[ ModelOptimizer ] 简化后面数太少,跳过"),e;try{const n=this.modifierModify(e,i);return console.log(`[ ModelOptimizer ] 简化完成: ${t} -> ${i} 面`),n}catch(n){return console.warn("[ ModelOptimizer ] 简化失败,使用原几何体",n),e}}modifierModify(o,r){if(typeof a.SimplifyModifier<"u")return new a.SimplifyModifier().modify(o,r);const e=o.clone();return e.attributes.normal&&e.deleteAttribute("normal"),e.attributes.uv&&this.simplifyRatio<.3&&e.deleteAttribute("uv"),e}optimizeMaterials(o){const r=new Map;let e=0;return o.traverse(t=>{if(t.isMesh&&t.material){const i=this.getMaterialKey(t.material);if(r.has(i)){const n=t.material;t.material=r.get(i),e++,n.dispose&&n.dispose()}else r.set(i,t.material)}}),console.log(`[ ModelOptimizer ] 材质合并: 合并了 ${e} 个重复材质`),o}getMaterialKey(o){var e;return[o.type,(e=o.color)==null?void 0:e.getHex(),o.roughness,o.metalness,o.opacity,o.transparent].join("|")}mergeMeshes(o){if(o.length===0)return null;const r=[],e=[];if(o.forEach(t=>{t.geometry&&r.push(t.geometry),t.material&&e.push(t.material)}),r.length===0)return null;try{if(typeof a.BufferGeometryUtils<"u"&&a.BufferGeometryUtils.mergeGeometries){const t=a.BufferGeometryUtils.mergeGeometries(r),i=new a.Mesh(t,e[0]);return console.log(`[ ModelOptimizer ] 合并了 ${o.length} 个网格`),i}}catch(t){console.warn("[ ModelOptimizer ] 合并网格失败",t)}return null}createLOD(o,r=[0,50,100],e=[1,.5,.25]){const t=new a.LOD;t.addLevel(o,r[0]);for(let i=1;i<r.length;i++){const n=o.clone();n.geometry=this.simplifyGeometry(o,e[i]),t.addLevel(n,r[i])}return console.log(`[ ModelOptimizer ] 创建 LOD: ${r.length} 个细节级别`),t}getModelStats(o){let r=0,e=0,t=0,i=new Set;return o.traverse(n=>{if(n.isMesh){r++;const s=n.geometry;s.index?e+=s.index.count/3:s.attributes.position&&(e+=s.attributes.position.count/3),s.attributes.position&&(t+=s.attributes.position.count),n.material&&(Array.isArray(n.material)?n.material.forEach(l=>i.add(l.uuid)):i.add(n.material.uuid))}}),{meshCount:r,triangleCount:e,vertexCount:t,materialCount:i.size}}generateReport(o,r){const e=this.getModelStats(o),t=this.getModelStats(r);return console.group("📊 模型优化报告"),console.log("网格数量:",`${e.meshCount} -> ${t.meshCount}`),console.log("三角形数量:",`${e.triangleCount} -> ${t.triangleCount} (${((1-t.triangleCount/e.triangleCount)*100).toFixed(1)}% 减少)`),console.log("顶点数量:",`${e.vertexCount} -> ${t.vertexCount} (${((1-t.vertexCount/e.vertexCount)*100).toFixed(1)}% 减少)`),console.log("材质数量:",`${e.materialCount} -> ${t.materialCount}`),console.groupEnd(),{original:e,optimized:t,reduction:{triangles:1-t.triangleCount/e.triangleCount,vertices:1-t.vertexCount/e.vertexCount}}}simplifyModel(o,r=.5,e={}){const{minFaceCount:t=100,preserveUVs:i=!0}=e;let n=0,s=0;return o.traverse(l=>{if(l.isMesh){const f=l.geometry;if(!f.isBufferGeometry){s++;return}if((f.index?f.index.count/3:f.attributes.position.count/3)<t){s++;return}try{const m=this.simplifyGeometry(l,r);l.geometry=m,n++,!i&&m.attributes.uv&&m.deleteAttribute("uv")}catch(m){console.warn("[ ModelOptimizer ] 简化网格失败:",l.name||l.uuid,m),s++}}}),console.log(`[ ModelOptimizer ] 模型简化完成: 成功 ${n} 个, 跳过 ${s} 个`),o}}const d=new c;exports.ModelOptimizer=c;exports.modelOptimizer=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("three");function d(u){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const r in u)if(r!=="default"){const e=Object.getOwnPropertyDescriptor(u,r);Object.defineProperty(o,r,e.get?e:{enumerable:!0,get:()=>u[r]})}}return o.default=u,Object.freeze(o)}const a=d(c);class p{constructor(){this.simplifyRatio=.5}simplifyGeometry(o,r=this.simplifyRatio){const e=o.geometry;if(!e.isBufferGeometry)return console.warn("[ ModelOptimizer ] 非BufferGeometry,跳过简化"),e;const t=e.index?e.index.count/3:e.attributes.position.count/3,i=Math.floor(t*r);if(i<4)return console.warn("[ ModelOptimizer ] 简化后面数太少,跳过"),e;try{const n=this.modifierModify(e,i);return console.log(`[ ModelOptimizer ] 简化完成: ${t} -> ${i} 面`),n}catch(n){return console.warn("[ ModelOptimizer ] 简化失败,使用原几何体",n),e}}modifierModify(o,r){return typeof a.SimplifyModifier<"u"?new a.SimplifyModifier().modify(o,r):(console.warn(`[ ModelOptimizer ] SimplifyModifier 不可用,跳过几何体简化。
2
+ 建议安装: import { SimplifyModifier } from "three/addons/modifiers/SimplifyModifier.js"`),o)}optimizeMaterials(o){const r=new Map;let e=0;return o.traverse(t=>{if(t.isMesh&&t.material){const i=this.getMaterialKey(t.material);if(r.has(i)){const n=t.material;t.material=r.get(i),e++,n.dispose&&n.dispose()}else r.set(i,t.material)}}),console.log(`[ ModelOptimizer ] 材质合并: 合并了 ${e} 个重复材质`),o}getMaterialKey(o){var e;return[o.type,(e=o.color)==null?void 0:e.getHex(),o.roughness,o.metalness,o.opacity,o.transparent].join("|")}mergeMeshes(o){if(o.length===0)return null;const r=[],e=[];if(o.forEach(t=>{t.geometry&&r.push(t.geometry),t.material&&e.push(t.material)}),r.length===0)return null;try{if(typeof a.BufferGeometryUtils<"u"&&a.BufferGeometryUtils.mergeGeometries){const t=a.BufferGeometryUtils.mergeGeometries(r),i=new a.Mesh(t,e[0]);return console.log(`[ ModelOptimizer ] 合并了 ${o.length} 个网格`),i}}catch(t){console.warn("[ ModelOptimizer ] 合并网格失败",t)}return null}createLOD(o,r=[0,50,100],e=[1,.5,.25]){const t=new a.LOD;t.addLevel(o,r[0]);for(let i=1;i<r.length;i++){const n=o.clone();n.geometry=this.simplifyGeometry(o,e[i]),t.addLevel(n,r[i])}return console.log(`[ ModelOptimizer ] 创建 LOD: ${r.length} 个细节级别`),t}getModelStats(o){let r=0,e=0,t=0,i=new Set;return o.traverse(n=>{if(n.isMesh){r++;const s=n.geometry;s.index?e+=s.index.count/3:s.attributes.position&&(e+=s.attributes.position.count/3),s.attributes.position&&(t+=s.attributes.position.count),n.material&&(Array.isArray(n.material)?n.material.forEach(l=>i.add(l.uuid)):i.add(n.material.uuid))}}),{meshCount:r,triangleCount:e,vertexCount:t,materialCount:i.size}}generateReport(o,r){const e=this.getModelStats(o),t=this.getModelStats(r);return console.group("📊 模型优化报告"),console.log("网格数量:",`${e.meshCount} -> ${t.meshCount}`),console.log("三角形数量:",`${e.triangleCount} -> ${t.triangleCount} (${((1-t.triangleCount/e.triangleCount)*100).toFixed(1)}% 减少)`),console.log("顶点数量:",`${e.vertexCount} -> ${t.vertexCount} (${((1-t.vertexCount/e.vertexCount)*100).toFixed(1)}% 减少)`),console.log("材质数量:",`${e.materialCount} -> ${t.materialCount}`),console.groupEnd(),{original:e,optimized:t,reduction:{triangles:1-t.triangleCount/e.triangleCount,vertices:1-t.vertexCount/e.vertexCount}}}simplifyModel(o,r=.5,e={}){const{minFaceCount:t=100,preserveUVs:i=!0}=e;let n=0,s=0;return o.traverse(l=>{if(l.isMesh){const f=l.geometry;if(!f.isBufferGeometry){s++;return}if((f.index?f.index.count/3:f.attributes.position.count/3)<t){s++;return}try{const m=this.simplifyGeometry(l,r);l.geometry=m,n++,!i&&m.attributes.uv&&m.deleteAttribute("uv")}catch(m){console.warn("[ ModelOptimizer ] 简化网格失败:",l.name||l.uuid,m),s++}}}),console.log(`[ ModelOptimizer ] 模型简化完成: 成功 ${n} 个, 跳过 ${s} 个`),o}}const g=new p;exports.ModelOptimizer=p;exports.modelOptimizer=g;