@maqiuyao/dxf-viewer 0.2.15 → 0.2.16

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.
@@ -5103,6 +5103,22 @@ const Ih = new p.Vector3(0, 1, 0), Ze = class Ze {
5103
5103
  static isObjectSelectable(t) {
5104
5104
  return t.layers.isEnabled(li);
5105
5105
  }
5106
+ /**
5107
+ * 递归释放对象的 GPU 资源(geometry/material)。
5108
+ * 用于从场景移除模型后释放显存,避免切换图纸时内存泄漏。
5109
+ * 覆盖 Mesh/Line/Points 等所有携带 geometry 的可渲染对象。
5110
+ * 注意:释放后对象不可再用于渲染。
5111
+ */
5112
+ static disposeObject(t) {
5113
+ t.traverse((e) => {
5114
+ const i = e;
5115
+ if (i.geometry) {
5116
+ i.geometry.dispose(), (Array.isArray(i.material) ? i.material : [i.material]).forEach((r) => r?.dispose());
5117
+ const n = e.userData?.originalMaterial;
5118
+ n && (Array.isArray(n) ? n : [n]).forEach((r) => r?.dispose());
5119
+ }
5120
+ });
5121
+ }
5106
5122
  };
5107
5123
  /**
5108
5124
  * Outline default material
@@ -5118,7 +5134,7 @@ g(Ze, "OUTLINE_MATERIAL", new p.LineBasicMaterial({
5118
5134
  opacity: 0.3,
5119
5135
  side: p.FrontSide
5120
5136
  }));
5121
- let Q = Ze;
5137
+ let J = Ze;
5122
5138
  const Vs = new p.Matrix4(), Bh = new p.Matrix4(), us = class us {
5123
5139
  static resetMergeInfo() {
5124
5140
  this.MergeInfo.removedObjects = 0, this.MergeInfo.mergedMeshes = 0, this.MergeInfo.mergedLines = 0, this.MergeInfo.mergedPoints = 0, this.MergeInfo.mergedUnknownTypeObjects = 0, this.MergeInfo.elapsedTime = 0;
@@ -5304,7 +5320,7 @@ const Vs = new p.Matrix4(), Bh = new p.Matrix4(), us = class us {
5304
5320
  const b = r.added;
5305
5321
  return [...h, ...d, ...u].forEach((y) => {
5306
5322
  b.push(y), i && e && (e.add(y), y.updateWorldMatrix(!1, !1));
5307
- }), this.MergeInfo.removedObjects += f.length, this.MergeInfo.mergedMeshes += h.length, this.MergeInfo.mergedLines += d.length, this.MergeInfo.mergedPoints += u.length, s && e && Q.removeEmptyObjects(e), r;
5323
+ }), this.MergeInfo.removedObjects += f.length, this.MergeInfo.mergedMeshes += h.length, this.MergeInfo.mergedLines += d.length, this.MergeInfo.mergedPoints += u.length, s && e && J.removeEmptyObjects(e), r;
5308
5324
  }
5309
5325
  /**
5310
5326
  * since we'll move geometry to another merged mesh under a group, below is the structure:
@@ -5560,7 +5576,7 @@ class zt {
5560
5576
  static getVisibleObjectBoundingBox(t) {
5561
5577
  const e = new p.Box3();
5562
5578
  return t.traverse((i) => {
5563
- i.visible && (i instanceof p.Mesh || i instanceof p.Line) && Q.isObjectSelectable(i) && e.expandByObject(i);
5579
+ i.visible && (i instanceof p.Mesh || i instanceof p.Line) && J.isObjectSelectable(i) && e.expandByObject(i);
5564
5580
  }), e;
5565
5581
  }
5566
5582
  static getObjectsBoundingBox(t, e, i) {
@@ -15665,7 +15681,7 @@ class Dt {
15665
15681
  const b = r.added;
15666
15682
  return [...h, ...d, ...u].forEach((y) => {
15667
15683
  b.push(y), i && e && e.add(y);
15668
- }), this.MergeInfo.removedObjects += f.length, this.MergeInfo.mergedMeshes += h.length, this.MergeInfo.mergedLines += d.length, this.MergeInfo.mergedPoints += u.length, s && e && Q.removeEmptyObjects(e), r;
15684
+ }), this.MergeInfo.removedObjects += f.length, this.MergeInfo.mergedMeshes += h.length, this.MergeInfo.mergedLines += d.length, this.MergeInfo.mergedPoints += u.length, s && e && J.removeEmptyObjects(e), r;
15669
15685
  }
15670
15686
  /**
15671
15687
  * since we'll move geometry to another merged mesh under a group, below is the structure:
@@ -20758,7 +20774,7 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
20758
20774
  !M && (M = [], y[E] = M), M.push(x);
20759
20775
  };
20760
20776
  m.children.forEach((x) => {
20761
- if (Q.setSharedVariablesOfObject(x), !x.userData.isLayoutLevelObject) return;
20777
+ if (J.setSharedVariablesOfObject(x), !x.userData.isLayoutLevelObject) return;
20762
20778
  const E = x.name;
20763
20779
  let M;
20764
20780
  if (E !== j.MODEL_LAYOUT_NAME) {
@@ -20766,7 +20782,7 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
20766
20782
  !O.directAssociatedLeafObjectSet && (O.directAssociatedLeafObjectSet = /* @__PURE__ */ new Set()), M = O.directAssociatedLeafObjectSet;
20767
20783
  }
20768
20784
  x.traverse((O) => {
20769
- if (Q.setSharedVariablesOfObject(O), O.userData.isSnapGroup && (O.visible = j.SHOW_SNAP_OBJECT), O.geometry) {
20785
+ if (J.setSharedVariablesOfObject(O), O.userData.isSnapGroup && (O.visible = j.SHOW_SNAP_OBJECT), O.geometry) {
20770
20786
  const T = O.userData.layerName;
20771
20787
  this.getLayerVisible(e, T) === !1 && (O.visible = !1, O.userData.layerVisible = !1), S(O), M && M.add(O);
20772
20788
  }
@@ -20914,8 +20930,8 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
20914
20930
  !_ && (_ = [], M[C] = _), _.push(v);
20915
20931
  };
20916
20932
  E.children.forEach((v) => {
20917
- Q.setSharedVariablesOfObject(v), v.userData.isLayoutLevelObject && v.traverse((C) => {
20918
- if (Q.setSharedVariablesOfObject(C), C.userData.isSnapGroup && (C.visible = j.SHOW_SNAP_OBJECT), C.geometry) {
20933
+ J.setSharedVariablesOfObject(v), v.userData.isLayoutLevelObject && v.traverse((C) => {
20934
+ if (J.setSharedVariablesOfObject(C), C.userData.isSnapGroup && (C.visible = j.SHOW_SNAP_OBJECT), C.geometry) {
20919
20935
  const _ = C.userData.layerName;
20920
20936
  this.getLayerVisible(f, _) === !1 && (C.visible = !1, C.userData.layerVisible = !1), O(C);
20921
20937
  }
@@ -21819,7 +21835,7 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
21819
21835
  else {
21820
21836
  const E = new z(H.Mesh);
21821
21837
  E.geometry = y, E.material = wi, E.layers.enableAll(), E.layers.disable(qe), a.add(E);
21822
- const M = Q.createOutline(y, pe, E.matrix), O = new z(H.LineSegment);
21838
+ const M = J.createOutline(y, pe, E.matrix), O = new z(H.LineSegment);
21823
21839
  O.geometry = M.geometry, O.material = M.material, O.matrix = M.matrix, O.layers.enableAll(), O.layers.disable(qe), a.add(O);
21824
21840
  }
21825
21841
  }
@@ -23816,7 +23832,7 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
23816
23832
  }
23817
23833
  for (let k = 0; k < A.length; k++) {
23818
23834
  const D = A[k];
23819
- Q.setSharedVariablesOfObject(D), E.push(D), o[T].children.push(D), v && v.add(D);
23835
+ J.setSharedVariablesOfObject(D), E.push(D), o[T].children.push(D), v && v.add(D);
23820
23836
  }
23821
23837
  h > l && u(), await s((m + ++O / M) / f * 100);
23822
23838
  }
@@ -23889,7 +23905,7 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
23889
23905
  s(e), this.removeEmptyObjectsFromMark(i);
23890
23906
  }
23891
23907
  static removeEmptyObjectsFromMark(e) {
23892
- if (e.userData.validCount === 0 || Q.isEmptyObject(e)) return e.removeFromParent(), !0;
23908
+ if (e.userData.validCount === 0 || J.isEmptyObject(e)) return e.removeFromParent(), !0;
23893
23909
  for (let i = 0; i < e.children.length; )
23894
23910
  !this.removeEmptyObjectsFromMark(e.children[i]) && ++i;
23895
23911
  return !1;
@@ -24323,7 +24339,7 @@ class ys extends Or {
24323
24339
  }), S && S.size === 0) return;
24324
24340
  const E = s.getModelObject();
24325
24341
  let M = s.getLayoutLevelObject(e);
24326
- !M && (M = new p.Group(), Q.setSharedVariablesOfObject(M), M.name = e, E?.add(M)), M.add(w), w.applyMatrix4(r.msToPsMatrix), w.updateMatrixWorld(!0);
24342
+ !M && (M = new p.Group(), J.setSharedVariablesOfObject(M), M.name = e, E?.add(M)), M.add(w), w.applyMatrix4(r.msToPsMatrix), w.updateMatrixWorld(!0);
24327
24343
  let O = M.children.find((C) => C.name === X.SNAP_GROUP_NAME);
24328
24344
  !O && (O = new p.Group(), O.visible = X.SHOW_SNAP_OBJECT, O.name = X.SNAP_GROUP_NAME, M.add(O));
24329
24345
  const T = s.getLayoutLevelObject(X.MODEL_LAYOUT_NAME), v = T?.children.find((C) => C.name === X.SNAP_GROUP_NAME);
@@ -24332,7 +24348,7 @@ class ys extends Or {
24332
24348
  const _ = C.userData.layerName;
24333
24349
  if (this.isLayerFrozenForViewport(_, y) || (Kn.makeEmpty(), Kn.expandByObject(C), !a.intersectsBox(Kn))) return;
24334
24350
  const A = C.clone();
24335
- Q.setSharedVariablesOfObject(A);
24351
+ J.setSharedVariablesOfObject(A);
24336
24352
  let I = A.parent;
24337
24353
  const B = vi.identity();
24338
24354
  for (; I && I.userData.isLayoutLevelObject !== !0; )
@@ -24340,8 +24356,8 @@ class ys extends Or {
24340
24356
  B.premultiply(r.msToPsMatrix), A.applyMatrix4(B), O?.add(A), S?.add(A);
24341
24357
  const k = s.getObjectsByLayer(_);
24342
24358
  k && k.push(A);
24343
- }), x.length > 0 && Q.removeEmptyObjectsFromRemovingObjects(x, w), w.traverse((C) => {
24344
- Q.setSharedVariablesOfObject(C), this.addSpatialFilterSection(C, s.dxfData, !0);
24359
+ }), x.length > 0 && J.removeEmptyObjectsFromRemovingObjects(x, w), w.traverse((C) => {
24360
+ J.setSharedVariablesOfObject(C), this.addSpatialFilterSection(C, s.dxfData, !0);
24345
24361
  });
24346
24362
  }
24347
24363
  setMaterialUniforms(e, i) {
@@ -24507,12 +24523,12 @@ class Lo extends Or {
24507
24523
  */
24508
24524
  setDoubleSidedMaterials() {
24509
24525
  this.getModelObject().traverse((e) => {
24510
- e instanceof p.Mesh && Q.setDoubleSidedMaterialToObject(e);
24526
+ e instanceof p.Mesh && J.setDoubleSidedMaterialToObject(e);
24511
24527
  });
24512
24528
  }
24513
24529
  revertDoubleSidedMaterials() {
24514
24530
  this.getModelObject().traverse((e) => {
24515
- e instanceof p.Mesh && Q.revertDoubleSidedMaterialToObject(e);
24531
+ e instanceof p.Mesh && J.revertDoubleSidedMaterialToObject(e);
24516
24532
  });
24517
24533
  }
24518
24534
  getModelObject() {
@@ -24528,7 +24544,7 @@ class Lo extends Or {
24528
24544
  * Enables/disables edges.
24529
24545
  */
24530
24546
  async enableOutline(e, i) {
24531
- e && !this.edges && (this.edges = await Q.createOutlines(this.getModelObject(), void 0, i)), this.edges && this.edges.forEach((s) => s.visible = e);
24547
+ e && !this.edges && (this.edges = await J.createOutlines(this.getModelObject(), void 0, i)), this.edges && this.edges.forEach((s) => s.visible = e);
24532
24548
  }
24533
24549
  /**
24534
24550
  * Sets object's color.
@@ -26862,6 +26878,7 @@ class N1 {
26862
26878
  });
26863
26879
  }
26864
26880
  init() {
26881
+ this.destroy();
26865
26882
  const t = document.createElement("div");
26866
26883
  t.classList.add("model-layout-switch-bar");
26867
26884
  const e = document.createElement("div");
@@ -29086,7 +29103,7 @@ function Qa(c, t, e, i, s) {
29086
29103
  path: r
29087
29104
  };
29088
29105
  }
29089
- class J {
29106
+ class Q {
29090
29107
  static GetBytes(t) {
29091
29108
  switch (typeof t) {
29092
29109
  case "string": {
@@ -29111,7 +29128,7 @@ class J {
29111
29128
  if (t instanceof Array) {
29112
29129
  const e = [];
29113
29130
  for (let r = 0; r < t.length; r++)
29114
- e.push(J.GetBytes(t[r]));
29131
+ e.push(Q.GetBytes(t[r]));
29115
29132
  let i = 0;
29116
29133
  for (let r = 0; r < e.length; r++)
29117
29134
  i += e[r].length;
@@ -29341,7 +29358,7 @@ const yt = class yt {
29341
29358
  */
29342
29359
  static getCode(t) {
29343
29360
  const e = J1(t);
29344
- return e.length < 2 ? e[0] : e.length < 4 ? J.ToUInt16(e, 0) : J.ToUInt32(e, 0);
29361
+ return e.length < 2 ? e[0] : e.length < 4 ? Q.ToUInt16(e, 0) : Q.ToUInt32(e, 0);
29345
29362
  }
29346
29363
  /**
29347
29364
  * Parses code data and generates TextShape.
@@ -29386,10 +29403,10 @@ const yt = class yt {
29386
29403
  l++, d = e[l];
29387
29404
  break;
29388
29405
  case je.Bigfont:
29389
- l++, d = e[l], d == 0 && (l++, d = J.ToUInt16(new Uint8Array([e[l++], e[l++]]), 0), m.x = e[l++] * i, m.y = e[l++] * i, f = e[l] * i);
29406
+ l++, d = e[l], d == 0 && (l++, d = Q.ToUInt16(new Uint8Array([e[l++], e[l++]]), 0), m.x = e[l++] * i, m.y = e[l++] * i, f = e[l] * i);
29390
29407
  break;
29391
29408
  case je.Unifont:
29392
- l += 2, d = J.ToUInt16(new Uint8Array([e[l - 1], e[l]]), 0);
29409
+ l += 2, d = Q.ToUInt16(new Uint8Array([e[l - 1], e[l]]), 0);
29393
29410
  break;
29394
29411
  }
29395
29412
  d !== 0 && (u = t.getGraphicDataByCodeWithOffset(d, f, m), u && (n.push(...u.polylines.slice()), s = u.lastPoint.clone()));
@@ -29398,19 +29415,19 @@ const yt = class yt {
29398
29415
  case 8:
29399
29416
  {
29400
29417
  const d = new p.Vector2();
29401
- d.x = J.byteTosbyte(e[++l]), d.y = J.byteTosbyte(e[++l]), s.add(d.multiplyScalar(i)), o && r.push(s.clone());
29418
+ d.x = Q.byteTosbyte(e[++l]), d.y = Q.byteTosbyte(e[++l]), s.add(d.multiplyScalar(i)), o && r.push(s.clone());
29402
29419
  }
29403
29420
  break;
29404
29421
  case 9:
29405
29422
  for (; ; ) {
29406
29423
  const u = new p.Vector2();
29407
- if (u.x = J.byteTosbyte(e[++l]), u.y = J.byteTosbyte(e[++l]), !Number.isFinite(u.x) || !Number.isFinite(u.y) || u.x == 0 && u.y == 0) break;
29424
+ if (u.x = Q.byteTosbyte(e[++l]), u.y = Q.byteTosbyte(e[++l]), !Number.isFinite(u.x) || !Number.isFinite(u.y) || u.x == 0 && u.y == 0) break;
29408
29425
  s.add(u.multiplyScalar(i)), o && r.push(s.clone());
29409
29426
  }
29410
29427
  break;
29411
29428
  case 10:
29412
29429
  {
29413
- const d = e[++l] * i, u = J.byteTosbyte(e[++l]), f = (u & 112) >> 4;
29430
+ const d = e[++l] * i, u = Q.byteTosbyte(e[++l]), f = (u & 112) >> 4;
29414
29431
  let m = u & 7;
29415
29432
  m == 0 && (m = 8);
29416
29433
  const b = Math.PI / 4;
@@ -29429,7 +29446,7 @@ const yt = class yt {
29429
29446
  break;
29430
29447
  case 11:
29431
29448
  {
29432
- const d = e[++l], u = e[++l], f = e[++l], m = e[++l], b = (f * 255 + m) * i, y = J.byteTosbyte(e[++l]), S = (y & 112) >> 4;
29449
+ const d = e[++l], u = e[++l], f = e[++l], m = e[++l], b = (f * 255 + m) * i, y = Q.byteTosbyte(e[++l]), S = (y & 112) >> 4;
29433
29450
  let w = y & 7;
29434
29451
  w == 0 && (w = 8), u != 0 && w--;
29435
29452
  const x = Math.PI / 4;
@@ -29451,16 +29468,16 @@ const yt = class yt {
29451
29468
  case 12:
29452
29469
  {
29453
29470
  const d = new p.Vector2();
29454
- d.x = J.byteTosbyte(e[++l]) * i, d.y = J.byteTosbyte(e[++l]) * i;
29455
- let u = J.byteTosbyte(e[++l]);
29471
+ d.x = Q.byteTosbyte(e[++l]) * i, d.y = Q.byteTosbyte(e[++l]) * i;
29472
+ let u = Q.byteTosbyte(e[++l]);
29456
29473
  u < -127 && (u = -127), o && (u == 0 ? r.push(s.clone().add(d)) : r.push(yt.generateArcPoints(s, d, u / 127))), s.add(d);
29457
29474
  }
29458
29475
  break;
29459
29476
  case 13:
29460
29477
  for (; ; ) {
29461
29478
  const u = new p.Vector2();
29462
- if (u.x = J.byteTosbyte(e[++l]) * i, u.y = J.byteTosbyte(e[++l]) * i, !Number.isFinite(u.x) || !Number.isFinite(u.y) || u.x == 0 && u.y == 0) break;
29463
- let f = J.byteTosbyte(e[++l]);
29479
+ if (u.x = Q.byteTosbyte(e[++l]) * i, u.y = Q.byteTosbyte(e[++l]) * i, !Number.isFinite(u.x) || !Number.isFinite(u.y) || u.x == 0 && u.y == 0) break;
29480
+ let f = Q.byteTosbyte(e[++l]);
29464
29481
  f < -127 && (f = -127), o && (f == 0 ? r.push(s.clone().add(u)) : r.push(yt.generateArcPoints(s.clone(), u, f / 127))), s.add(u);
29465
29482
  }
29466
29483
  break;
@@ -30390,13 +30407,13 @@ const rr = {
30390
30407
  return this.getGraphicDataByCode(e, i)?.offset(s);
30391
30408
  }
30392
30409
  parseBigFont(e) {
30393
- J.ToInt16(e.readBytes(2), 0);
30394
- const i = J.ToInt16(e.readBytes(2), 0), s = J.ToInt16(e.readBytes(2), 0);
30410
+ Q.ToInt16(e.readBytes(2), 0);
30411
+ const i = Q.ToInt16(e.readBytes(2), 0), s = Q.ToInt16(e.readBytes(2), 0);
30395
30412
  for (let l = 0; l < s; l++)
30396
30413
  e.readBytes(2), e.readBytes(2);
30397
30414
  const n = [];
30398
30415
  for (let l = 0; l < i; l++) {
30399
- const h = e.readBytes(8), d = J.ToUInt16(new Uint8Array([h[1], h[0]]), 0), u = J.ToUInt16(h, 2), f = J.ToUInt32(h, 4);
30416
+ const h = e.readBytes(8), d = Q.ToUInt16(new Uint8Array([h[1], h[0]]), 0), u = Q.ToUInt16(h, 2), f = Q.ToUInt32(h, 4);
30400
30417
  d === 0 && u === 0 && f === 0 || n.push({
30401
30418
  code: d,
30402
30419
  length: u,
@@ -30412,22 +30429,22 @@ const rr = {
30412
30429
  a.length - o === 4 ? (this.baseUp = a[o++], this.baseDown = a[o++], this.orientation = a[o++]) : (this.baseUp = a[o++], o++, this.orientation = a[o++], this.baseDown = a[o++], this.isExtend = !0), this.data = r;
30413
30430
  }
30414
30431
  parseUniFont(e) {
30415
- const i = J.ToInt32(e.readBytes(4), 0), s = J.ToInt16(e.readBytes(2), 0), n = e.readBytes(s);
30432
+ const i = Q.ToInt32(e.readBytes(4), 0), s = Q.ToInt16(e.readBytes(2), 0), n = e.readBytes(s);
30416
30433
  this.info = new TextDecoder().decode(n);
30417
30434
  let r = this.info.indexOf("\0");
30418
30435
  this.baseUp = n[++r], this.baseDown = n[++r], this.orientation = n[++r], this.isUniCode = n[++r] == 0, this.isEmbedded = n[++r] == 0;
30419
30436
  const a = {};
30420
30437
  for (let o = 0; o < i - 1; o++) {
30421
- const l = J.ToUInt16(e.readBytes(2), 0), h = J.ToUInt16(e.readBytes(2), 0);
30438
+ const l = Q.ToUInt16(e.readBytes(2), 0), h = Q.ToUInt16(e.readBytes(2), 0);
30422
30439
  a[l] = e.readBytes(h);
30423
30440
  }
30424
30441
  this.data = a;
30425
30442
  }
30426
30443
  parseShapeFont(e) {
30427
30444
  e.readBytes(2), e.readBytes(2);
30428
- const i = J.ToInt16(e.readBytes(2), 0), s = [];
30445
+ const i = Q.ToInt16(e.readBytes(2), 0), s = [];
30429
30446
  for (let o = 0; o < i; o++) {
30430
- const l = J.ToUInt16(e.readBytes(2), 0), h = J.ToUInt16(e.readBytes(2), 0);
30447
+ const l = Q.ToUInt16(e.readBytes(2), 0), h = Q.ToUInt16(e.readBytes(2), 0);
30431
30448
  s.push({
30432
30449
  code: l,
30433
30450
  length: h
@@ -32104,8 +32121,8 @@ class N0 {
32104
32121
  const i = t.slice(), s = [];
32105
32122
  for (let r = 0; r < t.length && r < this.intersectionLimit; r++) {
32106
32123
  const a = t[r].object;
32107
- if (a.updateWorldMatrix(!0, !1), a instanceof p.Mesh && !Q.hasOutline(a, !1)) {
32108
- const o = Q.createOutline(a.geometry);
32124
+ if (a.updateWorldMatrix(!0, !1), a instanceof p.Mesh && !J.hasOutline(a, !1)) {
32125
+ const o = J.createOutline(a.geometry);
32109
32126
  o.visible = !1, a.add(o), o.updateWorldMatrix(!0, !1), s.push(o);
32110
32127
  }
32111
32128
  }
@@ -32398,6 +32415,12 @@ class no {
32398
32415
  getMasterModel() {
32399
32416
  return this.viewer.loadedModels.find((t) => this.viewer.masterModelId === t.modelId);
32400
32417
  }
32418
+ /**
32419
+ * 失效已建立的文本搜索索引(模型被移除后调用),释放对旧模型对象的引用。
32420
+ */
32421
+ invalidateIndex() {
32422
+ this.index = [], this.indexedModelObject = void 0;
32423
+ }
32401
32424
  /**
32402
32425
  * 遍历主模型场景图,收集所有带 userData.textContent 的文本对象。
32403
32426
  */
@@ -33446,7 +33469,9 @@ class Pr extends hi {
33446
33469
  };
33447
33470
  }
33448
33471
  /**
33449
- * 从场景中移除指定模型(不销毁 viewer,用于切换图纸等场景)。
33472
+ * 从场景中移除指定模型(不销毁 viewer,用于切换图纸等场景),
33473
+ * 并释放模型的 GPU 资源(geometry/material)避免内存泄漏。
33474
+ * 注意:移除后该模型对象不可再用于渲染。
33450
33475
  * @param modelId 加载时指定的 modelId
33451
33476
  * @returns 被移除的模型,未找到时返回 undefined
33452
33477
  */
@@ -33454,7 +33479,7 @@ class Pr extends hi {
33454
33479
  const i = this.loadedModels.findIndex((n) => n.modelId === e);
33455
33480
  if (i === -1) return;
33456
33481
  const s = this.loadedModels.splice(i, 1)[0];
33457
- return this.sceneManager.removeModel(s), this.enableRender(), s;
33482
+ return this.sceneManager.removeModel(s), J.disposeObject(s.getModelObject()), this.enableRender(), s;
33458
33483
  }
33459
33484
  destroy() {
33460
33485
  this.requestAnimationFrameHandle && cancelAnimationFrame(this.requestAnimationFrameHandle), this.loaderHelper.abortDxfLoading(), this.css2dRenderer.domElement.remove(), this.container.destroy(), this.sceneManager.destroy(), this.cameraManager.destroy(), this.overlayRender.destroy(), this.spinner.destroy(), this.progressBar?.destroy(), this.undoManager.destroy();
@@ -33771,7 +33796,7 @@ class $o extends Pr {
33771
33796
  */
33772
33797
  removeModel(e) {
33773
33798
  const i = super.removeModel(e);
33774
- return i && this.loadedModels.length === 0 && (this.masterModelId = "", this.activeLayoutName = "", this.layoutInfos = {}, this.units = void 0), i;
33799
+ return i && this.textSearchHelper?.invalidateIndex(), i && this.loadedModels.length === 0 && (this.masterModelId = "", this.activeLayoutName = "", this.layoutInfos = {}, this.units = void 0), i;
33775
33800
  }
33776
33801
  addModel(e) {
33777
33802
  super.addModel(e);
@@ -33850,7 +33875,7 @@ class $o extends Pr {
33850
33875
  color: "#888",
33851
33876
  side: p.DoubleSide
33852
33877
  });
33853
- this.groundPlane = new p.Mesh(o, l), this.groundPlane.visible = !1, this.groundPlane.position.set(a.x, a.y, -r.z), this.groundPlane.scale.set(1e5, 1e5, 1), this.groundPlane.name = "groundPlane", this.groundPlane.renderOrder = vu, this.groundPlane.layers.enableAll(), Q.disableLayerChannels(this.groundPlane, [li]), this.scene.add(this.groundPlane);
33878
+ this.groundPlane = new p.Mesh(o, l), this.groundPlane.visible = !1, this.groundPlane.position.set(a.x, a.y, -r.z), this.groundPlane.scale.set(1e5, 1e5, 1), this.groundPlane.name = "groundPlane", this.groundPlane.renderOrder = vu, this.groundPlane.layers.enableAll(), J.disableLayerChannels(this.groundPlane, [li]), this.scene.add(this.groundPlane);
33854
33879
  }
33855
33880
  this.groundPlane.updateMatrix(), this.groundPlane.updateMatrixWorld(!0);
33856
33881
  }
@@ -33870,7 +33895,7 @@ class $o extends Pr {
33870
33895
  for (const s of this.loadedModels) {
33871
33896
  const n = s.getModelObject(), r = n.children.find((a) => a.name === this.activeLayoutName);
33872
33897
  r && r.children.find((o) => o.name === X.SNAP_GROUP_NAME)?.traverse((o) => {
33873
- if (Q.isLeafObject(o)) {
33898
+ if (J.isLeafObject(o)) {
33874
33899
  if (ar.makeEmpty(), ar.expandByObject(o), !oo.intersectsBox(ar)) return;
33875
33900
  e.push(o);
33876
33901
  }
@@ -34439,7 +34464,7 @@ class $o extends Pr {
34439
34464
  this.lastCameraZoom = a;
34440
34465
  let o = 1;
34441
34466
  e.traverse((h) => {
34442
- if (h.userData.isSnapObject || !Q.isLeafObject(h)) return;
34467
+ if (h.userData.isSnapObject || !J.isLeafObject(h)) return;
34443
34468
  const d = h.geometry;
34444
34469
  d.boundingBox || d.computeBoundingBox();
34445
34470
  const u = d.boundingBox.clone();
@@ -35967,7 +35992,7 @@ class K0 {
35967
35992
  u.geometry && u.layers.enableAll(), u instanceof p.Light && (u.visible = !1);
35968
35993
  });
35969
35994
  let o;
35970
- r.edges && (o = await Q.createOutlines(n, void 0, a));
35995
+ r.edges && (o = await J.createOutlines(n, void 0, a));
35971
35996
  let l = r.modelId || r.src;
35972
35997
  const h = (u) => !!this.loadedModels.find((f) => f.modelId === u);
35973
35998
  if (h(l)) {
@@ -36139,10 +36164,10 @@ class K0 {
36139
36164
  this.loadedModels.forEach((a) => {
36140
36165
  const o = a.object.id;
36141
36166
  if (t) {
36142
- this.savedMaterialsForOpacity && this.savedMaterialsForOpacity.length > 0 && Q.revertObjectOpacityById(n, o, this.savedMaterialsForOpacity);
36143
- const l = Q.setObjectOpacityById(n, o, e, i, s);
36167
+ this.savedMaterialsForOpacity && this.savedMaterialsForOpacity.length > 0 && J.revertObjectOpacityById(n, o, this.savedMaterialsForOpacity);
36168
+ const l = J.setObjectOpacityById(n, o, e, i, s);
36144
36169
  r.push(...l);
36145
- } else this.savedMaterialsForOpacity && Q.revertObjectOpacityById(n, o, this.savedMaterialsForOpacity);
36170
+ } else this.savedMaterialsForOpacity && J.revertObjectOpacityById(n, o, this.savedMaterialsForOpacity);
36146
36171
  }), t ? this.savedMaterialsForOpacity = r : this.savedMaterialsForOpacity = [];
36147
36172
  }
36148
36173
  hasTransparentObject() {
@@ -36274,7 +36299,7 @@ class K0 {
36274
36299
  });
36275
36300
  this.loadedModels.forEach((r) => {
36276
36301
  const a = r.object.id;
36277
- Q.applyMaterialToObjectById(this.scene, a, s, i, e);
36302
+ J.applyMaterialToObjectById(this.scene, a, s, i, e);
36278
36303
  }), this.outlineRoot.clear();
36279
36304
  let n = [];
36280
36305
  if (t.forEach((r) => {
@@ -36288,13 +36313,13 @@ class K0 {
36288
36313
  });
36289
36314
  }), n.length > 0) {
36290
36315
  n.forEach((a) => {
36291
- const o = Q.createOutline(a.geometry, this.outlineMaterial);
36316
+ const o = J.createOutline(a.geometry, this.outlineMaterial);
36292
36317
  o.applyMatrix4(a.matrixWorld), this.outlineRoot.add(o), o.updateWorldMatrix(!0, !1);
36293
36318
  });
36294
36319
  const r = n.map((a) => a.id);
36295
36320
  this.loadedModels.forEach((a) => {
36296
36321
  const o = a.object.id;
36297
- Q.revertAppliedMaterialToObjectById(this.scene, o, r);
36322
+ J.revertAppliedMaterialToObjectById(this.scene, o, r);
36298
36323
  }), this.transparentObjectIds = r, this.flyToObjects(n);
36299
36324
  } else
36300
36325
  P.warn("[Viewer] No object found with uniqueIds: " + t.map((r) => r.id));
@@ -36413,7 +36438,7 @@ export {
36413
36438
  Rt as OSnapMarkerType,
36414
36439
  cu as OSnapType,
36415
36440
  j0 as ObjectPixelSizeHelper,
36416
- Q as ObjectUtils,
36441
+ J as ObjectUtils,
36417
36442
  q0 as Offset,
36418
36443
  X1 as OrbitControls,
36419
36444
  Rn as OutlineColorRgba,
@@ -41,6 +41,10 @@ export declare class TextSearchHelper {
41
41
  private index;
42
42
  constructor(viewer: Viewer2d);
43
43
  private getMasterModel;
44
+ /**
45
+ * 失效已建立的文本搜索索引(模型被移除后调用),释放对旧模型对象的引用。
46
+ */
47
+ invalidateIndex(): void;
44
48
  /**
45
49
  * 遍历主模型场景图,收集所有带 userData.textContent 的文本对象。
46
50
  */
@@ -212,4 +212,11 @@ export declare class ObjectUtils {
212
212
  static isObjectHittable(obj: THREE.Object3D): boolean;
213
213
  static isObjectSnapable(obj: THREE.Object3D): boolean;
214
214
  static isObjectSelectable(obj: THREE.Object3D): boolean;
215
+ /**
216
+ * 递归释放对象的 GPU 资源(geometry/material)。
217
+ * 用于从场景移除模型后释放显存,避免切换图纸时内存泄漏。
218
+ * 覆盖 Mesh/Line/Points 等所有携带 geometry 的可渲染对象。
219
+ * 注意:释放后对象不可再用于渲染。
220
+ */
221
+ static disposeObject(object: THREE.Object3D): void;
215
222
  }
@@ -224,7 +224,9 @@ export declare abstract class BaseViewer extends Event<ViewerEvents> {
224
224
  materials: number;
225
225
  };
226
226
  /**
227
- * 从场景中移除指定模型(不销毁 viewer,用于切换图纸等场景)。
227
+ * 从场景中移除指定模型(不销毁 viewer,用于切换图纸等场景),
228
+ * 并释放模型的 GPU 资源(geometry/material)避免内存泄漏。
229
+ * 注意:移除后该模型对象不可再用于渲染。
228
230
  * @param modelId 加载时指定的 modelId
229
231
  * @returns 被移除的模型,未找到时返回 undefined
230
232
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maqiuyao/dxf-viewer",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "基于 three.js 的 DXF 图纸 2D/3D 查看与对比库(Viewer2d / DxfCompareHelper)",
5
5
  "type": "module",
6
6
  "main": "./dist/dxf-viewer.cjs",