gltf-parser-plugin 1.1.6 → 1.1.7

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.
@@ -1512,7 +1512,7 @@ var GLTFWorkerLoader = class extends Loader {
1512
1512
  };
1513
1513
  //#endregion
1514
1514
  //#region src/plugin/PartColorHelper.ts
1515
- function ensureColor$1(color) {
1515
+ function ensureColor$2(color) {
1516
1516
  if (color instanceof Color) return color;
1517
1517
  return new Color(color);
1518
1518
  }
@@ -1533,7 +1533,7 @@ function getMaterialForColor(color) {
1533
1533
  }
1534
1534
  var materialCache = /* @__PURE__ */ new Map();
1535
1535
  /**
1536
- * 构件着色/透明度辅助器,参考 example 逻辑:hideByOids -> 修改材质 -> scene.add -> mesh-change 监听
1536
+ * 构件着色/透明度辅助器,参考 example 逻辑:hidePartsByOids -> 修改材质 -> scene.add -> mesh-change 监听
1537
1537
  * 由 GLTFParserPlugin 内部使用,scene 通过 tiles.group 获取
1538
1538
  */
1539
1539
  var PartColorHelper = class {
@@ -1573,7 +1573,7 @@ var PartColorHelper = class {
1573
1573
  setPartColorByOids(oids, color) {
1574
1574
  const scene = this.context.getScene();
1575
1575
  if (!scene) return;
1576
- const material = getMaterialForColor(ensureColor$1(color));
1576
+ const material = getMaterialForColor(ensureColor$2(color));
1577
1577
  for (const oid of oids) {
1578
1578
  this.coloredOids.add(oid);
1579
1579
  this.materialByOid.set(oid, material);
@@ -1589,7 +1589,7 @@ var PartColorHelper = class {
1589
1589
  collector.addEventListener("mesh-change", handler);
1590
1590
  }
1591
1591
  }
1592
- this.context.hideByOids(this.getAllModifiedOids());
1592
+ this.context.hidePartsByOids(this.getAllModifiedOids());
1593
1593
  }
1594
1594
  /**
1595
1595
  * 恢复指定构件的颜色
@@ -1624,7 +1624,7 @@ var PartColorHelper = class {
1624
1624
  }
1625
1625
  }
1626
1626
  }
1627
- this.context.unhideByOids(oids);
1627
+ this.context.showPartsByOids(oids);
1628
1628
  }
1629
1629
  /**
1630
1630
  * 根据 oid 数组设置构件透明度
@@ -1662,7 +1662,7 @@ var PartColorHelper = class {
1662
1662
  collector.addEventListener("mesh-change", handler);
1663
1663
  }
1664
1664
  }
1665
- this.context.hideByOids(this.getAllModifiedOids());
1665
+ this.context.hidePartsByOids(this.getAllModifiedOids());
1666
1666
  }
1667
1667
  /**
1668
1668
  * 恢复指定构件的透明度
@@ -1694,18 +1694,18 @@ var PartColorHelper = class {
1694
1694
  }
1695
1695
  }
1696
1696
  }
1697
- this.context.unhideByOids(oids);
1697
+ this.context.showPartsByOids(oids);
1698
1698
  }
1699
1699
  };
1700
1700
  //#endregion
1701
1701
  //#region src/plugin/PartBlinkHelper.ts
1702
- function ensureColor(color) {
1702
+ function ensureColor$1(color) {
1703
1703
  if (color instanceof Color) return color;
1704
1704
  return new Color(color);
1705
1705
  }
1706
1706
  /**
1707
1707
  * 构件闪烁强调辅助器
1708
- * 通过 hideByOids + split mesh + emissive 动画实现闪烁效果
1708
+ * 通过 hidePartsByOids + split mesh + emissive 动画实现闪烁效果
1709
1709
  */
1710
1710
  var PartBlinkHelper = class {
1711
1711
  blinkOids = /* @__PURE__ */ new Set();
@@ -1778,7 +1778,7 @@ var PartBlinkHelper = class {
1778
1778
  this.meshChangeHandlers.set(oid, handler);
1779
1779
  collector.addEventListener("mesh-change", handler);
1780
1780
  }
1781
- this.context.hideByOids(Array.from(this.blinkOids));
1781
+ this.context.hidePartsByOids(Array.from(this.blinkOids));
1782
1782
  if (this.blinkOids.size > 0) this.startAnimation();
1783
1783
  }
1784
1784
  /**
@@ -1786,7 +1786,7 @@ var PartBlinkHelper = class {
1786
1786
  * @param color 颜色值,支持 hex 数字、颜色字符串(如 "#ff0000")、THREE.Color 对象
1787
1787
  */
1788
1788
  setBlinkColor(color) {
1789
- const c = ensureColor(color);
1789
+ const c = ensureColor$1(color);
1790
1790
  this.blinkColor.copy(c);
1791
1791
  this.blinkMaterial.color.copy(c);
1792
1792
  this.blinkMaterial.emissive.copy(c);
@@ -1823,7 +1823,7 @@ var PartBlinkHelper = class {
1823
1823
  }
1824
1824
  }
1825
1825
  this.blinkOids.clear();
1826
- this.context.unhideByOids(oidsToUnhide);
1826
+ this.context.showPartsByOids(oidsToUnhide);
1827
1827
  }
1828
1828
  dispose() {
1829
1829
  this.clearAllBlinkParts();
@@ -1831,43 +1831,60 @@ var PartBlinkHelper = class {
1831
1831
  };
1832
1832
  //#endregion
1833
1833
  //#region src/plugin/PartFrameHelper.ts
1834
+ function ensureColor(color) {
1835
+ if (color instanceof Color) return color;
1836
+ return new Color(color);
1837
+ }
1834
1838
  /**
1835
1839
  * 构件线框显示辅助器
1836
- * 通过 hideByOids + split mesh + 填充材质 + EdgesGeometry 实现线框效果
1840
+ * 通过 hidePartsByOids + split mesh + 填充材质 + EdgesGeometry 实现线框效果
1837
1841
  */
1842
+ var DEFAULT_FRAME_COLOR = 54442;
1838
1843
  var PartFrameHelper = class {
1839
1844
  frameOids = /* @__PURE__ */ new Set();
1840
1845
  originalMaterialByMesh = /* @__PURE__ */ new Map();
1841
1846
  frameDataByOid = /* @__PURE__ */ new Map();
1842
1847
  meshChangeHandlers = /* @__PURE__ */ new Map();
1843
- fillMaterial;
1844
- edgeMaterial;
1848
+ fillColorByOid = /* @__PURE__ */ new Map();
1849
+ edgeColorByOid = /* @__PURE__ */ new Map();
1850
+ fillMaterialCache = /* @__PURE__ */ new Map();
1851
+ edgeMaterialCache = /* @__PURE__ */ new Map();
1845
1852
  edgeThreshold;
1846
1853
  constructor(context) {
1847
1854
  this.context = context;
1848
- this.fillMaterial = new MeshBasicMaterial({
1849
- color: 54442,
1855
+ this.edgeThreshold = 15;
1856
+ }
1857
+ getFillMaterial(hex) {
1858
+ if (!this.fillMaterialCache.has(hex)) this.fillMaterialCache.set(hex, new MeshBasicMaterial({
1859
+ color: hex,
1850
1860
  transparent: true,
1851
1861
  opacity: .3,
1852
1862
  side: DoubleSide,
1853
1863
  depthWrite: false
1854
- });
1855
- this.edgeMaterial = new MeshBasicMaterial({
1856
- color: 54442,
1864
+ }));
1865
+ return this.fillMaterialCache.get(hex);
1866
+ }
1867
+ getEdgeMaterial(hex) {
1868
+ if (!this.edgeMaterialCache.has(hex)) this.edgeMaterialCache.set(hex, new MeshBasicMaterial({
1869
+ color: hex,
1857
1870
  transparent: true,
1858
1871
  opacity: .8
1859
- });
1860
- this.edgeThreshold = 15;
1872
+ }));
1873
+ return this.edgeMaterialCache.get(hex);
1861
1874
  }
1862
- createWireframeForMeshes(meshes, scene) {
1875
+ createWireframeForMeshes(meshes, scene, oid) {
1876
+ const fillHex = this.fillColorByOid.get(oid) ?? DEFAULT_FRAME_COLOR;
1877
+ const edgeHex = this.edgeColorByOid.get(oid) ?? DEFAULT_FRAME_COLOR;
1878
+ const fillMaterial = this.getFillMaterial(fillHex);
1879
+ const edgeMaterial = this.getEdgeMaterial(edgeHex);
1863
1880
  const frameMeshes = [];
1864
1881
  const lines = [];
1865
1882
  for (const mesh of meshes) {
1866
1883
  if (!this.originalMaterialByMesh.has(mesh.uuid)) this.originalMaterialByMesh.set(mesh.uuid, mesh.material);
1867
- mesh.material = this.fillMaterial;
1884
+ mesh.material = fillMaterial;
1868
1885
  scene.add(mesh);
1869
1886
  frameMeshes.push(mesh);
1870
- const line = new LineSegments(new EdgesGeometry(mesh.geometry, this.edgeThreshold), this.edgeMaterial);
1887
+ const line = new LineSegments(new EdgesGeometry(mesh.geometry, this.edgeThreshold), edgeMaterial);
1871
1888
  line.matrix.copy(mesh.matrixWorld);
1872
1889
  line.matrixAutoUpdate = false;
1873
1890
  scene.add(line);
@@ -1898,7 +1915,7 @@ var PartFrameHelper = class {
1898
1915
  const collector = this.context.getMeshCollectorByOid(oid);
1899
1916
  const oldData = this.frameDataByOid.get(oid);
1900
1917
  if (oldData) this.removeFrameData(oldData, scene);
1901
- const newData = this.createWireframeForMeshes(collector.meshes, scene);
1918
+ const newData = this.createWireframeForMeshes(collector.meshes, scene, oid);
1902
1919
  this.frameDataByOid.set(oid, newData);
1903
1920
  }
1904
1921
  /**
@@ -1912,13 +1929,13 @@ var PartFrameHelper = class {
1912
1929
  for (const oid of oids) {
1913
1930
  this.frameOids.add(oid);
1914
1931
  const collector = this.context.getMeshCollectorByOid(oid);
1915
- const data = this.createWireframeForMeshes(collector.meshes, scene);
1932
+ const data = this.createWireframeForMeshes(collector.meshes, scene, oid);
1916
1933
  this.frameDataByOid.set(oid, data);
1917
1934
  const handler = () => this.applyFrameToOid(oid);
1918
1935
  this.meshChangeHandlers.set(oid, handler);
1919
1936
  collector.addEventListener("mesh-change", handler);
1920
1937
  }
1921
- this.context.hideByOids(Array.from(this.frameOids));
1938
+ this.context.hidePartsByOids(Array.from(this.frameOids));
1922
1939
  }
1923
1940
  /**
1924
1941
  * 清除所有线框显示构件
@@ -1940,10 +1957,42 @@ var PartFrameHelper = class {
1940
1957
  }
1941
1958
  }
1942
1959
  this.frameOids.clear();
1943
- this.context.unhideByOids(oidsToUnhide);
1960
+ this.fillColorByOid.clear();
1961
+ this.edgeColorByOid.clear();
1962
+ this.context.showPartsByOids(oidsToUnhide);
1963
+ }
1964
+ /**
1965
+ * 设置指定构件的线框填充颜色
1966
+ * @param oids 构件 OID 数组
1967
+ * @param color 颜色值,支持 hex 数字、颜色字符串(如 "#ff0000")、THREE.Color 对象
1968
+ */
1969
+ setFrameFillColor(oids, color) {
1970
+ const hex = ensureColor(color).getHex();
1971
+ for (const oid of oids) {
1972
+ if (!this.frameOids.has(oid)) continue;
1973
+ this.fillColorByOid.set(oid, hex);
1974
+ this.applyFrameToOid(oid);
1975
+ }
1976
+ }
1977
+ /**
1978
+ * 设置指定构件的线框边框颜色
1979
+ * @param oids 构件 OID 数组
1980
+ * @param color 颜色值,支持 hex 数字、颜色字符串(如 "#ff0000")、THREE.Color 对象
1981
+ */
1982
+ setFrameEdgeColor(oids, color) {
1983
+ const hex = ensureColor(color).getHex();
1984
+ for (const oid of oids) {
1985
+ if (!this.frameOids.has(oid)) continue;
1986
+ this.edgeColorByOid.set(oid, hex);
1987
+ this.applyFrameToOid(oid);
1988
+ }
1944
1989
  }
1945
1990
  dispose() {
1946
1991
  this.clearAllFrameParts();
1992
+ this.fillMaterialCache.forEach((m) => m.dispose());
1993
+ this.fillMaterialCache.clear();
1994
+ this.edgeMaterialCache.forEach((m) => m.dispose());
1995
+ this.edgeMaterialCache.clear();
1947
1996
  }
1948
1997
  };
1949
1998
  //#endregion
@@ -2228,20 +2277,20 @@ var GLTFParserPlugin = class {
2228
2277
  init(tiles) {
2229
2278
  this.tiles = tiles;
2230
2279
  this._partColorHelper = new PartColorHelper({
2231
- hideByOids: (oids) => this.hideByOids(oids),
2232
- unhideByOids: (oids) => this.unhideByOids(oids),
2280
+ hidePartsByOids: (oids) => this.hidePartsByOids(oids),
2281
+ showPartsByOids: (oids) => this.showPartsByOids(oids),
2233
2282
  getMeshCollectorByOid: (oid) => this.getMeshCollectorByOid(oid),
2234
2283
  getScene: () => this.tiles?.group ?? null
2235
2284
  });
2236
2285
  this._partBlinkHelper = new PartBlinkHelper({
2237
- hideByOids: (oids) => this.hideByOids(oids),
2238
- unhideByOids: (oids) => this.unhideByOids(oids),
2286
+ hidePartsByOids: (oids) => this.hidePartsByOids(oids),
2287
+ showPartsByOids: (oids) => this.showPartsByOids(oids),
2239
2288
  getMeshCollectorByOid: (oid) => this.getMeshCollectorByOid(oid),
2240
2289
  getScene: () => this.tiles?.group ?? null
2241
2290
  });
2242
2291
  this._partFrameHelper = new PartFrameHelper({
2243
- hideByOids: (oids) => this.hideByOids(oids),
2244
- unhideByOids: (oids) => this.unhideByOids(oids),
2292
+ hidePartsByOids: (oids) => this.hidePartsByOids(oids),
2293
+ showPartsByOids: (oids) => this.showPartsByOids(oids),
2245
2294
  getMeshCollectorByOid: (oid) => this.getMeshCollectorByOid(oid),
2246
2295
  getScene: () => this.tiles?.group ?? null
2247
2296
  });
@@ -2596,14 +2645,14 @@ var GLTFParserPlugin = class {
2596
2645
  /**
2597
2646
  * Hide the corresponding part of the original mesh according to the OID array
2598
2647
  */
2599
- hideByOids(oids) {
2648
+ hidePartsByOids(oids) {
2600
2649
  this.oids = oids;
2601
2650
  this.featureIdCount = this._calculateFeatureIdCount();
2602
2651
  }
2603
2652
  /**
2604
2653
  * Restore the display of the corresponding mesh according to the OID array
2605
2654
  */
2606
- unhideByOids(oids) {
2655
+ showPartsByOids(oids) {
2607
2656
  const oidSet = new Set(oids);
2608
2657
  this.oids = this.oids.filter((existingOid) => !oidSet.has(existingOid));
2609
2658
  this.featureIdCount = this._calculateFeatureIdCount();
@@ -2619,7 +2668,7 @@ var GLTFParserPlugin = class {
2619
2668
  }
2620
2669
  /**
2621
2670
  * 恢复指定构件的颜色
2622
- * 从场景移除 split mesh,unhide mesh
2671
+ * 从场景移除 split mesh,恢复原 mesh 显示
2623
2672
  * @param oids 构件 OID 数组
2624
2673
  */
2625
2674
  restorePartColorByOids(oids) {
@@ -2681,9 +2730,25 @@ var GLTFParserPlugin = class {
2681
2730
  this._partFrameHelper?.clearAllFrameParts();
2682
2731
  }
2683
2732
  /**
2733
+ * 设置指定构件的线框填充颜色
2734
+ * @param oids 构件 OID 数组
2735
+ * @param color 颜色值,支持 hex 数字、颜色字符串(如 "#ff0000")、THREE.Color 对象
2736
+ */
2737
+ setFrameFillColor(oids, color) {
2738
+ this._partFrameHelper?.setFrameFillColor(oids, color);
2739
+ }
2740
+ /**
2741
+ * 设置指定构件的线框边框颜色
2742
+ * @param oids 构件 OID 数组
2743
+ * @param color 颜色值,支持 hex 数字、颜色字符串(如 "#ff0000")、THREE.Color 对象
2744
+ */
2745
+ setFrameEdgeColor(oids, color) {
2746
+ this._partFrameHelper?.setFrameEdgeColor(oids, color);
2747
+ }
2748
+ /**
2684
2749
  * Restore the original materials of the mesh
2685
2750
  */
2686
- unhide() {
2751
+ showAllParts() {
2687
2752
  this.oids = [];
2688
2753
  this.featureIdCount = this._calculateFeatureIdCount();
2689
2754
  }