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