build-dxf 0.0.67 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-dxf",
3
- "version": "0.0.67",
3
+ "version": "0.1.1",
4
4
  "description": "线段构建双线墙壁的dxf版本",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/build.d.ts CHANGED
@@ -15,7 +15,6 @@ export declare function createEditor(dom: HTMLDivElement, camera?: THREE.Camera,
15
15
  dxfSystem: DxfSystem;
16
16
  getFileAll: () => Promise<{
17
17
  dxf: File;
18
- obj: File;
19
18
  glb: File;
20
19
  gltf: File;
21
20
  json: File;
@@ -28,7 +27,6 @@ export declare function createEditor(dom: HTMLDivElement, camera?: THREE.Camera,
28
27
  * @param trajectory
29
28
  */
30
29
  export declare function getModels(originData: OriginalDataItem[], trajectory: any, itemList: any): Promise<{
31
- obj: File;
32
30
  glb: File;
33
31
  gltf: File;
34
32
  }>;
@@ -60,7 +58,6 @@ export declare function buildJson(opt: HandleJsonOption): Promise<{
60
58
  */
61
59
  export declare function getFileAll(dxfSystem?: DxfSystem): Promise<{
62
60
  dxf: File;
63
- obj: File;
64
61
  glb: File;
65
62
  gltf: File;
66
63
  json: File;
package/src/build.js CHANGED
@@ -3491,6 +3491,42 @@ class Polygon extends Array {
3491
3491
  }
3492
3492
  return inside ? "inside" : "outside";
3493
3493
  }
3494
+ getMaxLengthInfo() {
3495
+ let len = -Infinity, start = Point.zero(), end = start;
3496
+ for (let i = 0; i < this.length - 1; i++) {
3497
+ const p1 = this[i];
3498
+ const p2 = this[i + 1];
3499
+ const l = p1.distance(p2);
3500
+ if (p1.distance(p2) > len) {
3501
+ len = l;
3502
+ start = p1;
3503
+ end = p2;
3504
+ }
3505
+ }
3506
+ return {
3507
+ start,
3508
+ end,
3509
+ length: len
3510
+ };
3511
+ }
3512
+ getMinLengthInfo() {
3513
+ let len = Infinity, start = Point.zero(), end = start;
3514
+ for (let i = 0; i < this.length - 1; i++) {
3515
+ const p1 = this[i];
3516
+ const p2 = this[i + 1];
3517
+ const l = p1.distance(p2);
3518
+ if (p1.distance(p2) < len) {
3519
+ len = l;
3520
+ start = p1;
3521
+ end = p2;
3522
+ }
3523
+ }
3524
+ return {
3525
+ start,
3526
+ end,
3527
+ length: len
3528
+ };
3529
+ }
3494
3530
  /** 点在多边形上:包括路径和内部
3495
3531
  * @param point
3496
3532
  * @returns
@@ -13685,7 +13721,6 @@ LoadModel.addNameMap("table", "桌子");
13685
13721
  LoadModel.addNameMap("chair", "椅子");
13686
13722
  LoadModel.addNameMap("switch", "开关");
13687
13723
  LoadModel.addNameMap("cabinet", "柜子");
13688
- LoadModel.addNameMap("tv", "电视");
13689
13724
  LoadModel.addNameMap("socket", "插座");
13690
13725
  LoadModel.addNameMap("refrigerator", "冰箱");
13691
13726
  LoadModel.addNameMap("kitchen hood", "抽油烟机");
@@ -13696,6 +13731,403 @@ LoadModel.addNameMap("door", "门");
13696
13731
  LoadModel.addNameMap("window", "窗户");
13697
13732
  LoadModel.addNameMap("wall", "单线墙");
13698
13733
  LoadModel.addNameMap("doubleWall", "双线墙");
13734
+ const sofa = [
13735
+ {
13736
+ x: 1.6238664388656616,
13737
+ y: 3.284672498703003,
13738
+ z: 0.04527417570352554
13739
+ },
13740
+ {
13741
+ x: 1.6244992017745972,
13742
+ y: 3.2571842670440674,
13743
+ z: 0.04527417570352554
13744
+ },
13745
+ {
13746
+ x: 1.5927159786224365,
13747
+ y: 3.171643018722534,
13748
+ z: 0.04527417570352554
13749
+ },
13750
+ {
13751
+ x: 1.5818978548049927,
13752
+ y: 3.1519744396209717,
13753
+ z: 0.04527417570352554
13754
+ },
13755
+ {
13756
+ x: 1.5510364770889282,
13757
+ y: 3.1041781902313232,
13758
+ z: 0.04527417570352554
13759
+ },
13760
+ {
13761
+ x: 1.4407778978347778,
13762
+ y: 2.970461845397949,
13763
+ z: 0.04527417570352554
13764
+ },
13765
+ {
13766
+ x: 1.4077634811401367,
13767
+ y: 2.9355101585388184,
13768
+ z: 0.04527417570352554
13769
+ },
13770
+ {
13771
+ x: 1.3402506113052368,
13772
+ y: 2.864572525024414,
13773
+ z: 0.04527417570352554
13774
+ },
13775
+ {
13776
+ x: 1.3176355361938477,
13777
+ y: 2.8394219875335693,
13778
+ z: 0.04527417570352554
13779
+ },
13780
+ {
13781
+ x: 1.2685059309005737,
13782
+ y: 2.783170461654663,
13783
+ z: 0.04527417570352554
13784
+ },
13785
+ {
13786
+ x: 1.2415951490402222,
13787
+ y: 2.7510077953338623,
13788
+ z: 0.04527417570352554
13789
+ },
13790
+ {
13791
+ x: 1.2056515216827393,
13792
+ y: 2.7169594764709473,
13793
+ z: 0.04527417570352554
13794
+ },
13795
+ {
13796
+ x: 1.187517762184143,
13797
+ y: 2.6988108158111572,
13798
+ z: 0.04527417570352554
13799
+ },
13800
+ {
13801
+ x: 1.1168668270111084,
13802
+ y: 2.622985363006592,
13803
+ z: 0.04527417570352554
13804
+ },
13805
+ {
13806
+ x: 1.066234827041626,
13807
+ y: 2.5612404346466064,
13808
+ z: 0.04527417570352554
13809
+ },
13810
+ {
13811
+ x: 1.0390440225601196,
13812
+ y: 2.5321192741394043,
13813
+ z: 0.04527417570352554
13814
+ },
13815
+ {
13816
+ x: 0.9529030919075012,
13817
+ y: 2.4387099742889404,
13818
+ z: 0.04527417570352554
13819
+ },
13820
+ {
13821
+ x: 0.9174349308013916,
13822
+ y: 2.394899368286133,
13823
+ z: 0.04527417570352554
13824
+ },
13825
+ {
13826
+ x: 0.825821578502655,
13827
+ y: 2.292377233505249,
13828
+ z: 0.04527417570352554
13829
+ },
13830
+ {
13831
+ x: 0.7657923102378845,
13832
+ y: 2.22959303855896,
13833
+ z: 0.04527417570352554
13834
+ },
13835
+ {
13836
+ x: 0.7357281446456909,
13837
+ y: 2.1975302696228027,
13838
+ z: 0.04527417570352554
13839
+ },
13840
+ {
13841
+ x: 0.7079773545265198,
13842
+ y: 2.166670322418213,
13843
+ z: 0.04527417570352554
13844
+ },
13845
+ {
13846
+ x: 0.6856369376182556,
13847
+ y: 2.141892433166504,
13848
+ z: 0.04527417570352554
13849
+ },
13850
+ {
13851
+ x: 0.6400769948959351,
13852
+ y: 2.0864980220794678,
13853
+ z: 0.04527417570352554
13854
+ },
13855
+ {
13856
+ x: 0.5879752039909363,
13857
+ y: 2.0353236198425293,
13858
+ z: 0.04527417570352554
13859
+ },
13860
+ {
13861
+ x: 0.5560364723205566,
13862
+ y: 2.0000483989715576,
13863
+ z: 0.04527417570352554
13864
+ },
13865
+ {
13866
+ x: 0.473638653755188,
13867
+ y: 1.894063949584961,
13868
+ z: 0.04527417570352554
13869
+ },
13870
+ {
13871
+ x: 0.43561145663261414,
13872
+ y: 1.8449041843414307,
13873
+ z: 0.04527417570352554
13874
+ },
13875
+ {
13876
+ x: 0.42559874057769775,
13877
+ y: 1.832397699356079,
13878
+ z: 0.04527417570352554
13879
+ },
13880
+ {
13881
+ x: 0.410190224647522,
13882
+ y: 1.8149422407150269,
13883
+ z: 0.04527417570352554
13884
+ },
13885
+ {
13886
+ x: 0.363402783870697,
13887
+ y: 1.760341763496399,
13888
+ z: 0.04527417570352554
13889
+ },
13890
+ {
13891
+ x: 0.33721745014190674,
13892
+ y: 1.727489709854126,
13893
+ z: 0.04527417570352554
13894
+ },
13895
+ {
13896
+ x: 0.2884461581707001,
13897
+ y: 1.6703766584396362,
13898
+ z: 0.04527417570352554
13899
+ },
13900
+ {
13901
+ x: 0.20839639008045197,
13902
+ y: 1.577893853187561,
13903
+ z: 0.04527417570352554
13904
+ },
13905
+ {
13906
+ x: 0.20270870625972748,
13907
+ y: 1.5719205141067505,
13908
+ z: 0.04527417570352554
13909
+ },
13910
+ {
13911
+ x: 0.1153828576207161,
13912
+ y: 1.4826784133911133,
13913
+ z: 0.04527417570352554
13914
+ },
13915
+ {
13916
+ x: 0.08456073701381683,
13917
+ y: 1.4474365711212158,
13918
+ z: 0.04527417570352554
13919
+ },
13920
+ {
13921
+ x: 0.04536956921219826,
13922
+ y: 1.4040511846542358,
13923
+ z: 0.04527417570352554
13924
+ },
13925
+ {
13926
+ x: 0.016785871237516403,
13927
+ y: 1.375108003616333,
13928
+ z: 0.04527417570352554
13929
+ },
13930
+ {
13931
+ x: -0.01269896887242794,
13932
+ y: 1.343769907951355,
13933
+ z: 0.04527417570352554
13934
+ },
13935
+ {
13936
+ x: -0.06614634394645691,
13937
+ y: 1.2908459901809692,
13938
+ z: 0.04527417570352554
13939
+ },
13940
+ {
13941
+ x: -0.07980315387248993,
13942
+ y: 1.2767953872680664,
13943
+ z: 0.04527417570352554
13944
+ },
13945
+ {
13946
+ x: -0.13434025645256042,
13947
+ y: 1.217846393585205,
13948
+ z: 0.04527417570352554
13949
+ },
13950
+ {
13951
+ x: -0.20500518381595612,
13952
+ y: 1.2183390855789185,
13953
+ z: 0.04527417570352554
13954
+ },
13955
+ {
13956
+ x: -0.20903858542442322,
13957
+ y: 1.2200990915298462,
13958
+ z: 0.04527417570352554
13959
+ },
13960
+ {
13961
+ x: -0.24315717816352844,
13962
+ y: 1.2350893020629883,
13963
+ z: 0.04527417570352554
13964
+ },
13965
+ {
13966
+ x: -0.33582064509391785,
13967
+ y: 1.330154299736023,
13968
+ z: 0.04527417570352554
13969
+ },
13970
+ {
13971
+ x: -0.407009482383728,
13972
+ y: 1.3944091796875,
13973
+ z: 0.04527417570352554
13974
+ },
13975
+ {
13976
+ x: -0.436004102230072,
13977
+ y: 1.4175184965133667,
13978
+ z: 0.04527417570352554
13979
+ },
13980
+ {
13981
+ x: -0.5406937599182129,
13982
+ y: 1.4983491897583008,
13983
+ z: 0.04527417570352554
13984
+ },
13985
+ {
13986
+ x: -0.5918427109718323,
13987
+ y: 1.5407732725143433,
13988
+ z: 0.04527417570352554
13989
+ },
13990
+ {
13991
+ x: -0.6926348805427551,
13992
+ y: 1.627001166343689,
13993
+ z: 0.04527417570352554
13994
+ },
13995
+ {
13996
+ x: -0.7242612838745117,
13997
+ y: 1.6550514698028564,
13998
+ z: 0.04527417570352554
13999
+ },
14000
+ {
14001
+ x: -0.7268859148025513,
14002
+ y: 1.6611504554748535,
14003
+ z: 0.04527417570352554
14004
+ },
14005
+ {
14006
+ x: -0.7366707921028137,
14007
+ y: 1.6863963603973389,
14008
+ z: 0.04527417570352554
14009
+ },
14010
+ {
14011
+ x: -0.7353513836860657,
14012
+ y: 1.7125723361968994,
14013
+ z: 0.04527417570352554
14014
+ },
14015
+ {
14016
+ x: -0.7360835075378418,
14017
+ y: 1.8862329721450806,
14018
+ z: 0.04527417570352554
14019
+ },
14020
+ {
14021
+ x: -0.735418975353241,
14022
+ y: 1.892752766609192,
14023
+ z: 0.04527417570352554
14024
+ },
14025
+ {
14026
+ x: -0.5135520100593567,
14027
+ y: 2.352489948272705,
14028
+ z: 0.04527417570352554
14029
+ },
14030
+ {
14031
+ x: -0.49001386761665344,
14032
+ y: 2.3860416412353516,
14033
+ z: 0.04527417570352554
14034
+ },
14035
+ {
14036
+ x: -0.32206565141677856,
14037
+ y: 2.6847586631774902,
14038
+ z: 0.04527417570352554
14039
+ },
14040
+ {
14041
+ x: -0.3155321776866913,
14042
+ y: 2.7002644538879395,
14043
+ z: 0.04527417570352554
14044
+ },
14045
+ {
14046
+ x: -0.16775445640087128,
14047
+ y: 2.882310152053833,
14048
+ z: 0.04527417570352554
14049
+ },
14050
+ {
14051
+ x: -0.10523588210344315,
14052
+ y: 2.958411931991577,
14053
+ z: 0.04527417570352554
14054
+ },
14055
+ {
14056
+ x: -0.013106819242238998,
14057
+ y: 3.0644092559814453,
14058
+ z: 0.04527417570352554
14059
+ },
14060
+ {
14061
+ x: 0.0596558041870594,
14062
+ y: 3.14784574508667,
14063
+ z: 0.04527417570352554
14064
+ },
14065
+ {
14066
+ x: 0.10449352860450745,
14067
+ y: 3.1983754634857178,
14068
+ z: 0.04527417570352554
14069
+ },
14070
+ {
14071
+ x: 0.1318368911743164,
14072
+ y: 3.2273011207580566,
14073
+ z: 0.04527417570352554
14074
+ },
14075
+ {
14076
+ x: 0.313530296087265,
14077
+ y: 3.43524169921875,
14078
+ z: 0.04527417570352554
14079
+ },
14080
+ {
14081
+ x: 0.35493549704551697,
14082
+ y: 3.488212823867798,
14083
+ z: 0.04527417570352554
14084
+ },
14085
+ {
14086
+ x: 0.36869028210639954,
14087
+ y: 3.506091594696045,
14088
+ z: 0.04527417570352554
14089
+ },
14090
+ {
14091
+ x: 0.39403417706489563,
14092
+ y: 3.5318570137023926,
14093
+ z: 0.04527417570352554
14094
+ },
14095
+ {
14096
+ x: 0.4346749186515808,
14097
+ y: 3.5670950412750244,
14098
+ z: 0.04527417570352554
14099
+ },
14100
+ {
14101
+ x: 0.9730985760688782,
14102
+ y: 3.7458245754241943,
14103
+ z: 0.04527417570352554
14104
+ },
14105
+ {
14106
+ x: 1.0080010890960693,
14107
+ y: 3.7384610176086426,
14108
+ z: 0.04527417570352554
14109
+ },
14110
+ {
14111
+ x: 1.3947365283966064,
14112
+ y: 3.726346969604492,
14113
+ z: 0.04527417570352554
14114
+ },
14115
+ {
14116
+ x: 1.3991360664367676,
14117
+ y: 3.7256264686584473,
14118
+ z: 0.04527417570352554
14119
+ },
14120
+ {
14121
+ x: 1.6213877201080322,
14122
+ y: 3.3178341388702393,
14123
+ z: 0.04527417570352554
14124
+ },
14125
+ {
14126
+ x: 1.6238664388656616,
14127
+ y: 3.284672498703003,
14128
+ z: 0.04527417570352554
14129
+ }
14130
+ ];
13699
14131
  let globalScenario;
13700
14132
  class SceneAutoGenerat {
13701
14133
  lines;
@@ -13703,13 +14135,26 @@ class SceneAutoGenerat {
13703
14135
  z;
13704
14136
  scene = new THREE.Group();
13705
14137
  trajectory;
14138
+ angle = 0;
13706
14139
  constructor(lines, itemList, z, trajectory) {
13707
14140
  this.lines = lines;
13708
14141
  this.itemList = itemList;
13709
14142
  this.z = z;
13710
14143
  this.trajectory = trajectory;
13711
14144
  globalScenario = globalScenario ?? Scenario.Instance ?? new Scenario(new THREE.Scene(), {}, {}, {});
13712
- globalScenario.scene.add(this.scene);
14145
+ const vrLine = findVerticalReference(lines);
14146
+ this.angle = -vrLine.direction().angleBetween(new Point(0, 1), "angle", "360") * (Math.PI / 180);
14147
+ }
14148
+ /**
14149
+ * 获取包围矩形
14150
+ */
14151
+ getSurroundRect(path, angle = this.angle) {
14152
+ const points = path.map((p) => Point.from(p)), box2 = Box2.fromByPoints(...points), center = box2.center;
14153
+ drawLines(points);
14154
+ points.forEach((p) => p.rotate(center, angle));
14155
+ const rectangle = Box2.fromByPoints(...points).points;
14156
+ rectangle.forEach((p) => p.rotate(center, -angle));
14157
+ return new Polygon(rectangle);
13713
14158
  }
13714
14159
  buildPlane() {
13715
14160
  const texture = new THREE.TextureLoader().load(planeSrc);
@@ -13724,7 +14169,8 @@ class SceneAutoGenerat {
13724
14169
  }
13725
14170
  async init() {
13726
14171
  await this.buildWall();
13727
- await this.buildItem();
14172
+ await this.buildItem1();
14173
+ globalScenario.scene.add(this.scene);
13728
14174
  }
13729
14175
  wallGroup = null;
13730
14176
  async buildWall() {
@@ -13739,7 +14185,84 @@ class SceneAutoGenerat {
13739
14185
  // [new THREE.Vector3(0, 0, 1), "z"],
13740
14186
  // [new THREE.Vector3(0, 0, -1), "z"]
13741
14187
  ];
13742
- adsorption(walls, box3, proximityThreshold = 0.05) {
14188
+ adsorption(walls, group2, proximityThreshold = 0.05) {
14189
+ let newPosition = new THREE.Vector3();
14190
+ const box3 = new THREE.Box3();
14191
+ box3.setFromObject(group2);
14192
+ const center = box3.getCenter(new THREE.Vector3()), size = box3.getSize(new THREE.Vector3()), raycaster = new THREE.Raycaster(), keyMap = /* @__PURE__ */ new Map(), results = this.directs.map((item) => {
14193
+ raycaster.set(center, item[0]);
14194
+ raycaster.near = 1e-4;
14195
+ raycaster.far = size[item[1]] * 0.5 + proximityThreshold;
14196
+ const intersects = raycaster.intersectObjects(walls, true);
14197
+ if (intersects.length) {
14198
+ keyMap.set(intersects[0], item);
14199
+ return intersects[0];
14200
+ }
14201
+ return;
14202
+ }).filter((i) => !!i);
14203
+ if (results.length) {
14204
+ this.scene.add(new THREE.Box3Helper(box3));
14205
+ let closestIntersection = results[0];
14206
+ results.forEach((result) => {
14207
+ if (result.distance <= closestIntersection.distance) {
14208
+ closestIntersection = result;
14209
+ }
14210
+ });
14211
+ const info = keyMap.get(closestIntersection), key = info[1];
14212
+ if (closestIntersection.face?.normal) {
14213
+ const normal = new THREE.Vector3().copy(closestIntersection.face.normal).applyMatrix3(new THREE.Matrix3().getNormalMatrix(closestIntersection.object.matrixWorld));
14214
+ newPosition.copy(closestIntersection.point).add(normal.clone().multiplyScalar(size[key] * 0.5));
14215
+ group2.position.set(newPosition.x, newPosition.y, group2.position.z);
14216
+ }
14217
+ }
14218
+ }
14219
+ getModel(item, walls) {
14220
+ const direction = new THREE.Vector3().copy(item.direction);
14221
+ const angle = Math.atan2(direction.x, direction.y);
14222
+ const rectangle = this.getSurroundRect(item.contour, angle);
14223
+ drawLines(rectangle, { color: randomColor() });
14224
+ const max = rectangle.getMaxLengthInfo();
14225
+ const min = rectangle.getMinLengthInfo();
14226
+ const center = Box2.fromByPoints(...rectangle).center;
14227
+ LoadModel.loadGlb(item.category)?.then((model) => {
14228
+ model = model.clone(true);
14229
+ model.rotateX(Math.PI * 0.5);
14230
+ model.traverse((mesh) => {
14231
+ if (mesh instanceof THREE.Mesh) {
14232
+ mesh.material.map = null;
14233
+ mesh.material.vertexColors = false;
14234
+ mesh.material.color = new THREE.Color(16777215);
14235
+ }
14236
+ });
14237
+ const group2 = new THREE.Group();
14238
+ group2.add(model);
14239
+ const box3 = new THREE.Box3();
14240
+ box3.setFromObject(group2);
14241
+ const size = box3.getSize(new THREE.Vector3());
14242
+ const maxKey = size.x > size.y ? "x" : "y";
14243
+ const mimKey = size.x < size.y ? "x" : "y";
14244
+ const maxS = max.length / size[maxKey];
14245
+ const minS = min.length / size[mimKey];
14246
+ const scale = (sofa[0].z - this.z) / size.z;
14247
+ group2.scale[maxKey] *= maxS;
14248
+ group2.scale[mimKey] *= minS;
14249
+ group2.scale.z *= scale;
14250
+ group2.position.set(center.x, center.y, this.z);
14251
+ group2.rotateZ(-angle);
14252
+ box3.setFromObject(group2);
14253
+ this.scene.add(group2);
14254
+ });
14255
+ }
14256
+ async buildItem() {
14257
+ const walls = [];
14258
+ this.wallGroup?.traverse((object) => {
14259
+ if (object instanceof THREE.Mesh) walls.push(object);
14260
+ });
14261
+ await Promise.all(
14262
+ this.itemList.map(async (item) => this.getModel(item, walls))
14263
+ );
14264
+ }
14265
+ adsorption1(walls, box3, proximityThreshold = 0.05) {
13743
14266
  let newPosition = new THREE.Vector3();
13744
14267
  const center = box3.getCenter(new THREE.Vector3()), size = box3.getSize(new THREE.Vector3()), raycaster = new THREE.Raycaster(), keyMap = /* @__PURE__ */ new Map(), results = this.directs.map((item) => {
13745
14268
  raycaster.set(center, item[0]);
@@ -13776,48 +14299,50 @@ class SceneAutoGenerat {
13776
14299
  }
13777
14300
  }
13778
14301
  }
13779
- async buildItem() {
14302
+ async buildItem1() {
13780
14303
  const walls = [];
13781
14304
  this.wallGroup?.traverse((object) => {
13782
14305
  if (object instanceof THREE.Mesh) walls.push(object);
13783
14306
  });
13784
- this.itemList.forEach(async (item) => {
13785
- let model = await LoadModel.loadGlb(item.category);
13786
- if (model) {
13787
- const containerBox3 = new THREE.Box3(
13788
- new THREE.Vector3().copy(item.box.min),
13789
- new THREE.Vector3().copy(item.box.max)
13790
- );
13791
- let angle = 0;
13792
- if (["socket", "switch"].includes(item.category)) {
13793
- angle = this.adsorption(walls, containerBox3) ?? 0;
13794
- }
13795
- model.name = `${item.category}_${THREE.MathUtils.randFloat(0, 16777215).toString(16)}`;
13796
- model.userData.category = item.category;
13797
- const containerSize = containerBox3.getSize(new THREE.Vector3());
13798
- const box3 = new THREE.Box3();
13799
- model = model.clone(true);
13800
- model.rotateX(Math.PI * 0.5);
13801
- box3.setFromObject(model);
13802
- const size = box3.getSize(new THREE.Vector3());
13803
- model.traverse((mesh) => {
13804
- if (mesh instanceof THREE.Mesh) {
13805
- mesh.material.map = null;
13806
- mesh.material.vertexColors = false;
13807
- mesh.material.color = new THREE.Color(16777215);
14307
+ await Promise.all(
14308
+ this.itemList.map(async (item) => {
14309
+ let model = await LoadModel.loadGlb(item.category);
14310
+ if (model) {
14311
+ const containerBox3 = new THREE.Box3(
14312
+ new THREE.Vector3().copy(item.box.min),
14313
+ new THREE.Vector3().copy(item.box.max)
14314
+ );
14315
+ let angle = 0;
14316
+ if (["socket", "switch"].includes(item.category)) {
14317
+ angle = this.adsorption1(walls, containerBox3) ?? 0;
13808
14318
  }
13809
- });
13810
- model.scale.set(containerSize.x / size.x, containerSize.z / size.z, containerSize.y / size.y);
13811
- const group2 = new THREE.Group();
13812
- containerBox3.getCenter(group2.position);
13813
- group2.rotation.z = angle;
13814
- group2.add(model);
13815
- box3.setFromObject(group2);
13816
- box3.getSize(size);
13817
- group2.position.z -= size.z * 0.5;
13818
- this.scene.add(group2);
13819
- }
13820
- });
14319
+ model.name = `${item.category}_${THREE.MathUtils.randFloat(0, 16777215).toString(16)}`;
14320
+ model.userData.category = item.category;
14321
+ const containerSize = containerBox3.getSize(new THREE.Vector3());
14322
+ const box3 = new THREE.Box3();
14323
+ model = model.clone(true);
14324
+ model.rotateX(Math.PI * 0.5);
14325
+ box3.setFromObject(model);
14326
+ const size = box3.getSize(new THREE.Vector3());
14327
+ model.traverse((mesh) => {
14328
+ if (mesh instanceof THREE.Mesh) {
14329
+ mesh.material.map = null;
14330
+ mesh.material.vertexColors = false;
14331
+ mesh.material.color = new THREE.Color(16777215);
14332
+ }
14333
+ });
14334
+ model.scale.set(containerSize.x / size.x, containerSize.z / size.z, containerSize.y / size.y);
14335
+ const group2 = new THREE.Group();
14336
+ containerBox3.getCenter(group2.position);
14337
+ group2.rotation.z = angle;
14338
+ group2.add(model);
14339
+ box3.setFromObject(group2);
14340
+ box3.getSize(size);
14341
+ group2.position.z -= size.z * 0.5;
14342
+ this.scene.add(group2);
14343
+ }
14344
+ })
14345
+ );
13821
14346
  }
13822
14347
  }
13823
14348
  const exporter = new OBJExporter();
@@ -13881,11 +14406,10 @@ class WhiteModel extends Component {
13881
14406
  const lines = dxfSystem.Dxf.getLineSegments(true);
13882
14407
  if (typeof window !== "undefined") {
13883
14408
  const sceneAutoGenerat = new SceneAutoGenerat(lines, this.itemList, dxfSystem.Dxf.originalZAverage, dxfSystem.CorrectionDxf.trajectory);
13884
- sceneAutoGenerat.init();
13885
- const globalScenario2 = Scenario.Instance ?? new Scenario(new THREE.Scene(), {}, {}, {});
13886
- const group2 = globalScenario2.scene;
14409
+ await sceneAutoGenerat.init();
14410
+ const group2 = sceneAutoGenerat.scene;
13887
14411
  if (group2) {
13888
- this.whiteModelLineGroup.add(group2);
14412
+ this.whiteModelLineGroup.add(group2.clone(true));
13889
14413
  }
13890
14414
  } else {
13891
14415
  dxf.wallsGroup.forEach((points) => {
@@ -14262,11 +14786,10 @@ async function getModels(originData, trajectory, itemList) {
14262
14786
  const model = sceneAutoGenerat.scene;
14263
14787
  const whiteModel = new WhiteModel();
14264
14788
  whiteModel.whiteModelGroup.add(model);
14265
- const obj = new File([await whiteModel.toOBJBlob() || ""], "model.obj", { type: "application/octet-stream" });
14266
14789
  const glb = new File([await whiteModel.toGltfBlob(true) || ""], "model.glb", { type: "application/octet-stream" });
14267
14790
  const gltf = new File([await whiteModel.toGltfBlob(false) || ""], "model.gltf", { type: "application/json" });
14268
14791
  return {
14269
- obj,
14792
+ // obj,
14270
14793
  glb,
14271
14794
  gltf
14272
14795
  };
@@ -14334,13 +14857,12 @@ async function getFileAll(dxfSystem = gloabalDxfSystem) {
14334
14857
  const jpg = new File([await dxfSystem.CorrectionDxf.toDxfImageBlob()], "img.jpg", { type: "image/jpeg" });
14335
14858
  const dxf = new File([dxfSystem.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" });
14336
14859
  const correctionDxf = new File([dxfSystem.CorrectionDxf.toDxfBlob() ?? ""], "dxf.dxf", { type: "application/dxf" });
14337
- const obj = new File([await whiteModel.toOBJBlob()], "model.obj", { type: "application/octet-stream" });
14338
14860
  const glb = new File([await whiteModel.toGltfBlob(true)], "model.glb", { type: "application/octet-stream" });
14339
14861
  const gltf = new File([await whiteModel.toGltfBlob(false)], "model.gltf", { type: "application/json" });
14340
14862
  const json = new File([JSON.stringify(dxfSystem.Dxf.originalData)], "json.json", { type: "application/json" });
14341
14863
  return {
14342
14864
  dxf,
14343
- obj,
14865
+ // obj,
14344
14866
  glb,
14345
14867
  gltf,
14346
14868
  json,
@@ -15,6 +15,16 @@ export declare class Polygon<T = any> extends Array<Point<T>> {
15
15
  * @returns 'on' 边上,'inside' 内部,'outside' 外部
16
16
  */
17
17
  pointPosition(point: Point): "outside" | "on" | "inside";
18
+ getMaxLengthInfo(): {
19
+ start: Point<any>;
20
+ end: Point<any>;
21
+ length: number;
22
+ };
23
+ getMinLengthInfo(): {
24
+ start: Point<any>;
25
+ end: Point<any>;
26
+ length: number;
27
+ };
18
28
  /** 点在多边形上:包括路径和内部
19
29
  * @param point
20
30
  * @returns
@@ -1,5 +1,6 @@
1
1
  import { Group } from 'three';
2
2
  import { LineSegment } from '../LineSegment';
3
+ import { Polygon } from '../Polygon';
3
4
  import * as THREE from "three";
4
5
  export declare class SceneAutoGenerat {
5
6
  lines: LineSegment[];
@@ -7,12 +8,20 @@ export declare class SceneAutoGenerat {
7
8
  z: number;
8
9
  scene: Group<THREE.Object3DEventMap>;
9
10
  trajectory?: any;
11
+ angle: number;
10
12
  constructor(lines: LineSegment[], itemList: any[], z: number, trajectory?: any);
13
+ /**
14
+ * 获取包围矩形
15
+ */
16
+ getSurroundRect(path: any[], angle?: number): Polygon<Record<string, any>>;
11
17
  buildPlane(): void;
12
18
  init(): Promise<void>;
13
19
  wallGroup: Group | null;
14
20
  buildWall(): Promise<void>;
15
21
  directs: [THREE.Vector3, string][];
16
- adsorption(walls: THREE.Mesh[], box3: THREE.Box3, proximityThreshold?: number): void;
22
+ adsorption(walls: THREE.Mesh[], group: THREE.Group, proximityThreshold?: number): void;
23
+ getModel(item: any, walls: THREE.Mesh[]): void;
17
24
  buildItem(): Promise<void>;
25
+ adsorption1(walls: THREE.Mesh[], box3: THREE.Box3, proximityThreshold?: number): void;
26
+ buildItem1(): Promise<void>;
18
27
  }