rm-graphical-computing 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.js +1529 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1529 @@
|
|
|
1
|
+
import * as e from "three";
|
|
2
|
+
import { BufferAttribute as t, BufferGeometry as n, Matrix4 as r, Object3D as i, Plane as a, Vector2 as o, Vector3 as s } from "three";
|
|
3
|
+
//#region node_modules/three/examples/jsm/utils/BufferGeometryUtils.js
|
|
4
|
+
function c(e, t = !1) {
|
|
5
|
+
let r = e[0].index !== null, i = new Set(Object.keys(e[0].attributes)), a = new Set(Object.keys(e[0].morphAttributes)), o = {}, s = {}, c = e[0].morphTargetsRelative, u = new n(), d = 0;
|
|
6
|
+
for (let n = 0; n < e.length; ++n) {
|
|
7
|
+
let l = e[n], f = 0;
|
|
8
|
+
if (r !== (l.index !== null)) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."), null;
|
|
9
|
+
for (let e in l.attributes) {
|
|
10
|
+
if (!i.has(e)) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". All geometries must have compatible attributes; make sure \"" + e + "\" attribute exists among all geometries, or in none of them."), null;
|
|
11
|
+
o[e] === void 0 && (o[e] = []), o[e].push(l.attributes[e]), f++;
|
|
12
|
+
}
|
|
13
|
+
if (f !== i.size) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". Make sure all geometries have the same number of attributes."), null;
|
|
14
|
+
if (c !== l.morphTargetsRelative) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". .morphTargetsRelative must be consistent throughout all geometries."), null;
|
|
15
|
+
for (let e in l.morphAttributes) {
|
|
16
|
+
if (!a.has(e)) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". .morphAttributes must be consistent throughout all geometries."), null;
|
|
17
|
+
s[e] === void 0 && (s[e] = []), s[e].push(l.morphAttributes[e]);
|
|
18
|
+
}
|
|
19
|
+
if (t) {
|
|
20
|
+
let e;
|
|
21
|
+
if (r) e = l.index.count;
|
|
22
|
+
else if (l.attributes.position !== void 0) e = l.attributes.position.count;
|
|
23
|
+
else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index " + n + ". The geometry must have either an index or a position attribute"), null;
|
|
24
|
+
u.addGroup(d, e, n), d += e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (r) {
|
|
28
|
+
let t = 0, n = [];
|
|
29
|
+
for (let r = 0; r < e.length; ++r) {
|
|
30
|
+
let i = e[r].index;
|
|
31
|
+
for (let e = 0; e < i.count; ++e) n.push(i.getX(e) + t);
|
|
32
|
+
t += e[r].attributes.position.count;
|
|
33
|
+
}
|
|
34
|
+
u.setIndex(n);
|
|
35
|
+
}
|
|
36
|
+
for (let e in o) {
|
|
37
|
+
let t = l(o[e]);
|
|
38
|
+
if (!t) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the " + e + " attribute."), null;
|
|
39
|
+
u.setAttribute(e, t);
|
|
40
|
+
}
|
|
41
|
+
for (let e in s) {
|
|
42
|
+
let t = s[e][0].length;
|
|
43
|
+
if (t === 0) break;
|
|
44
|
+
u.morphAttributes = u.morphAttributes || {}, u.morphAttributes[e] = [];
|
|
45
|
+
for (let n = 0; n < t; ++n) {
|
|
46
|
+
let t = [];
|
|
47
|
+
for (let r = 0; r < s[e].length; ++r) t.push(s[e][r][n]);
|
|
48
|
+
let r = l(t);
|
|
49
|
+
if (!r) return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the " + e + " morphAttribute."), null;
|
|
50
|
+
u.morphAttributes[e].push(r);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return u;
|
|
54
|
+
}
|
|
55
|
+
function l(e) {
|
|
56
|
+
let n, r, i, a = -1, o = 0;
|
|
57
|
+
for (let t = 0; t < e.length; ++t) {
|
|
58
|
+
let s = e[t];
|
|
59
|
+
if (n === void 0 && (n = s.array.constructor), n !== s.array.constructor) return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."), null;
|
|
60
|
+
if (r === void 0 && (r = s.itemSize), r !== s.itemSize) return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."), null;
|
|
61
|
+
if (i === void 0 && (i = s.normalized), i !== s.normalized) return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."), null;
|
|
62
|
+
if (a === -1 && (a = s.gpuType), a !== s.gpuType) return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."), null;
|
|
63
|
+
o += s.count * r;
|
|
64
|
+
}
|
|
65
|
+
let s = new n(o), c = new t(s, r, i), l = 0;
|
|
66
|
+
for (let t = 0; t < e.length; ++t) {
|
|
67
|
+
let n = e[t];
|
|
68
|
+
if (n.isInterleavedBufferAttribute) {
|
|
69
|
+
let e = l / r;
|
|
70
|
+
for (let t = 0, i = n.count; t < i; t++) for (let i = 0; i < r; i++) {
|
|
71
|
+
let r = n.getComponent(t, i);
|
|
72
|
+
c.setComponent(t + e, i, r);
|
|
73
|
+
}
|
|
74
|
+
} else s.set(n.array, l);
|
|
75
|
+
l += n.count * r;
|
|
76
|
+
}
|
|
77
|
+
return a !== void 0 && (c.gpuType = a), c;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region node_modules/three/examples/jsm/renderers/CSS2DRenderer.js
|
|
81
|
+
var u = class extends i {
|
|
82
|
+
constructor(e = document.createElement("div")) {
|
|
83
|
+
super(), this.isCSS2DObject = !0, this.element = e, this.element.style.position = "absolute", this.element.style.userSelect = "none", this.element.setAttribute("draggable", !1), this.center = new o(.5, .5), this.addEventListener("removed", function() {
|
|
84
|
+
this.traverse(function(e) {
|
|
85
|
+
e.element && e.element instanceof e.element.ownerDocument.defaultView.Element && e.element.parentNode !== null && e.element.remove();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
copy(e, t) {
|
|
90
|
+
return super.copy(e, t), this.element = e.element.cloneNode(!0), this.center = e.center, this;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
new s(), new r(), new r(), new s(), new s();
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/utils/utils.mjs
|
|
96
|
+
var d = (t, n, r, i, a = 1e-8) => {
|
|
97
|
+
let o = n.x - t.x, s = n.y - t.y, c = i.x - r.x, l = i.y - r.y, u = o * l - s * c;
|
|
98
|
+
if (Math.abs(u) < a) return null;
|
|
99
|
+
let d = ((r.x - t.x) * l - (r.y - t.y) * c) / u, f = ((r.x - t.x) * s - (r.y - t.y) * o) / u;
|
|
100
|
+
return d < -a || d > 1 + a || f < -a || f > 1 + a ? null : { point: new e.Vector3(t.x + d * o, t.y + d * s, t.z) };
|
|
101
|
+
}, f = (t, n, r = {}) => {
|
|
102
|
+
let { fontSize: i = 36, fontFamily: a = "sans-serif", backgroundColor: o = "rgba(0,0,0,0)", textColor: s = "#ffffff", padding: c = 10, maxWidth: l = 256 } = r, u = document.createElement("canvas").getContext("2d");
|
|
103
|
+
u.font = `bold ${i}px ${a}`;
|
|
104
|
+
let d = u.measureText(t).width, f = Math.min(d + c * 2, l), m = i + c * 2, h = document.createElement("canvas");
|
|
105
|
+
h.width = f, h.height = m;
|
|
106
|
+
let g = h.getContext("2d");
|
|
107
|
+
g.fillStyle = o, g.fillRect(0, 0, f, m), g.fillStyle = s, g.font = `bold ${i}px ${a}`, g.textAlign = "center", g.textBaseline = "middle", d > l - c * 2 ? p(g, t, f / 2, m / 2, l, i) : g.fillText(t, f / 2, m / 2);
|
|
108
|
+
let _ = new e.CanvasTexture(h), v = new e.SpriteMaterial({
|
|
109
|
+
map: _,
|
|
110
|
+
depthTest: !1,
|
|
111
|
+
transparent: !0
|
|
112
|
+
}), y = new e.Sprite(v);
|
|
113
|
+
y.position.set(n.x, n.y, n.z);
|
|
114
|
+
let b = .005;
|
|
115
|
+
return y.scale.set(f * b, m * b, 1), y;
|
|
116
|
+
};
|
|
117
|
+
function p(e, t, n, r, i, a) {
|
|
118
|
+
let o = t.split(""), s = "", c = a * 1.2, l = r;
|
|
119
|
+
for (let t = 0; t < o.length; t++) {
|
|
120
|
+
let r = s + o[t];
|
|
121
|
+
e.measureText(r).width > i && t > 0 ? (e.fillText(s, n, l), s = o[t], l += c) : s = r;
|
|
122
|
+
}
|
|
123
|
+
e.fillText(s, n, l);
|
|
124
|
+
}
|
|
125
|
+
var m = (e, t, n = .01) => {
|
|
126
|
+
let r = Math.sqrt(e.x * e.x + e.y * e.y + e.z * e.z), i = Math.sqrt(t.x * t.x + t.y * t.y + t.z * t.z);
|
|
127
|
+
if (r < 1e-10 || i < 1e-10) return {
|
|
128
|
+
parallel: !1,
|
|
129
|
+
sameDirection: null,
|
|
130
|
+
angle: NaN
|
|
131
|
+
};
|
|
132
|
+
let a = {
|
|
133
|
+
x: e.x / r,
|
|
134
|
+
y: e.y / r,
|
|
135
|
+
z: e.z / r
|
|
136
|
+
}, o = {
|
|
137
|
+
x: t.x / i,
|
|
138
|
+
y: t.y / i,
|
|
139
|
+
z: t.z / i
|
|
140
|
+
}, s = a.x * o.x + a.y * o.y + a.z * o.z;
|
|
141
|
+
s = Math.max(-1, Math.min(1, s));
|
|
142
|
+
let c = Math.acos(Math.abs(s)), l = c <= n;
|
|
143
|
+
return {
|
|
144
|
+
parallel: l,
|
|
145
|
+
sameDirection: l ? s > 0 : null,
|
|
146
|
+
angle: c
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
function h(t, n) {
|
|
150
|
+
let r = new e.BufferGeometry(), i = [], a = [];
|
|
151
|
+
t.forEach((e) => i.push(e.x, e.y, e.z)), n.forEach((e) => i.push(e.x, e.y, e.z)), a.push(0, 2, 1, 0, 3, 2), a.push(4, 5, 6, 4, 6, 7), a.push(0, 1, 5, 0, 5, 4), a.push(1, 2, 6, 1, 6, 5), a.push(2, 3, 7, 2, 7, 6), a.push(3, 0, 4, 3, 4, 7), r.setAttribute("position", new e.Float32BufferAttribute(i, 3)), r.setIndex(a), r.computeVertexNormals();
|
|
152
|
+
let o = new e.MeshBasicMaterial({
|
|
153
|
+
color: "green",
|
|
154
|
+
transparent: !0,
|
|
155
|
+
opacity: .5,
|
|
156
|
+
side: e.DoubleSide
|
|
157
|
+
});
|
|
158
|
+
return new e.Mesh(r, o);
|
|
159
|
+
}
|
|
160
|
+
var g = class {
|
|
161
|
+
constructor(t = {}) {
|
|
162
|
+
this.config = {
|
|
163
|
+
value: t.value || "0.0000m",
|
|
164
|
+
position: t.position || new e.Vector3(0, 0, 0),
|
|
165
|
+
style: {
|
|
166
|
+
fontFamily: t.style?.fontFamily || "Arial, sans-serif",
|
|
167
|
+
fontSize: t.style?.fontSize || "16px",
|
|
168
|
+
fontWeight: t.style?.fontWeight || "normal",
|
|
169
|
+
fontStyle: t.style?.fontStyle || "normal"
|
|
170
|
+
},
|
|
171
|
+
backgroundOpacity: t.backgroundOpacity || .7
|
|
172
|
+
}, this.label = null, this.labelElement = null, this.createLabel();
|
|
173
|
+
}
|
|
174
|
+
createLabel() {
|
|
175
|
+
return this.labelElement = document.createElement("div"), this.labelElement.textContent = this.config.value, this.applyBlackWhiteStyle(), this.label = new u(this.labelElement), this.label.position.copy(this.config.position), this.label;
|
|
176
|
+
}
|
|
177
|
+
applyBlackWhiteStyle() {
|
|
178
|
+
let e = this.labelElement.style, t = this.config;
|
|
179
|
+
e.fontFamily = t.style.fontFamily, e.fontSize = t.style.fontSize, e.fontWeight = t.style.fontWeight, e.fontStyle = t.style.fontStyle, e.color = "#FFFFFF", e.textShadow = "0 1px 2px rgba(0, 0, 0, 0.5)", e.backgroundColor = `rgba(0, 0, 0, ${t.backgroundOpacity})`, e.padding = "6px 12px", e.borderRadius = "4px", e.position = "absolute", e.whiteSpace = "nowrap", e.userSelect = "none", e.pointerEvents = "none", e.zIndex = "1000", e.textAlign = "center", e.lineHeight = "1.2";
|
|
180
|
+
}
|
|
181
|
+
updateValue(e) {
|
|
182
|
+
this.labelElement && (this.labelElement.textContent = e);
|
|
183
|
+
}
|
|
184
|
+
updatePosition(e) {
|
|
185
|
+
this.label && this.label.position.copy(e);
|
|
186
|
+
}
|
|
187
|
+
updateFontStyle(e) {
|
|
188
|
+
if (this.labelElement) {
|
|
189
|
+
let t = this.labelElement.style;
|
|
190
|
+
e.fontFamily && (t.fontFamily = e.fontFamily), e.fontSize && (t.fontSize = e.fontSize), e.fontWeight && (t.fontWeight = e.fontWeight), e.fontStyle && (t.fontStyle = e.fontStyle);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
getLabel() {
|
|
194
|
+
return this.label;
|
|
195
|
+
}
|
|
196
|
+
getLabelElement() {
|
|
197
|
+
return this.labelElement;
|
|
198
|
+
}
|
|
199
|
+
dispose() {
|
|
200
|
+
this.labelElement && this.labelElement.parentNode && this.labelElement.parentNode.removeChild(this.labelElement), this.label = null, this.labelElement = null;
|
|
201
|
+
}
|
|
202
|
+
}, _ = (t) => {
|
|
203
|
+
let n = new e.Group();
|
|
204
|
+
if (t && t.length) {
|
|
205
|
+
let r = /* @__PURE__ */ "green.red.pink.white.azure.yellow.bisque.grey.blanchedalmond.blue.blueviolet.brown.burlywood.cadetblue.chartreuse.chocolate.coral.cornflowerblue.cornsilk.crimson.cyan.darkblue.darkcyan.darkgoldenrod.darkgray.darkgreen.darkgrey.darkkhaki.darkmagenta.darkolivegreen.darkorange.darkorchid.darkred.darksalmon.darkseagreen.darkslateblue.darkslategray.darkslategrey.darkturquoise.darkviolet.deeppink.deepskyblue.dimgray.dimgrey.dodgerblue.firebrick.floralwhite.forestgreen.fuchsia.gainsboro.ghostwhite.gold.goldenrod.gray.aliceblue.greenyellow.black.honeydew.hotpink.indianred.indigo.ivory.khaki.lavender.lavenderblush.lawngreen.lemonchiffon.lightblue.lightcoral.lightcyan.lightgoldenrodyellow.lightgray.lightgreen.lightgrey.lightpink.lightsalmon.lightseagreen.lightskyblue.lightslategray.lightslategrey.lightsteelblue.lightyellow.lime.limegreen.linen.magenta.maroon.mediumaquamarine.mediumblue.mediumorchid.mediumpurple.mediumseagreen.mediumslateblue.mediumspringgreen.mediumturquoise.mediumvioletred.midnightblue.mintcream.mistyrose.moccasin.navajowhite.navy.oldlace.olive.olivedrab.orange.orangered.orchid.palegoldenrod.palegreen.paleturquoise.palevioletred.papayawhip.peachpuff.peru.pink.plum.powderblue.purple.rebeccapurple.yellow.rosybrown.royalblue.saddlebrown.salmon.sandybrown.seagreen.seashell.sienna.silver.skyblue.slateblue.slategray.slategrey.snow.springgreen.steelblue.tan.teal.thistle.tomato.turquoise.violet.wheat.white.whitesmoke.yellow.yellowgreen".split(".");
|
|
206
|
+
t.forEach((t, i) => {
|
|
207
|
+
let a = r[i], o = new e.Group(), { pcdPoints: s, category: c, name: l, center: u, box: d, obbBox: f, contour: p, nline: m, coordinatesByWidth: _, coordinatesByArea: v } = t, y = s.length;
|
|
208
|
+
if (c != "door") return;
|
|
209
|
+
c === "balcony railing" && console.log("pcdObj", t);
|
|
210
|
+
let b = new e.Box3(new e.Vector3(d.min.x, d.min.y, d.min.z), new e.Vector3(d.max.x, d.max.y, d.max.z)), x = new e.Box3Helper(b, a);
|
|
211
|
+
o.add(x);
|
|
212
|
+
let S = new g({
|
|
213
|
+
value: l,
|
|
214
|
+
position: new e.Vector3(u.x, u.y, u.z)
|
|
215
|
+
}).getLabel();
|
|
216
|
+
o.add(S);
|
|
217
|
+
let C = new e.InstancedMesh(new e.SphereGeometry(.007, 8, 8), new e.MeshBasicMaterial({ color: a }), y);
|
|
218
|
+
o.add(C);
|
|
219
|
+
let w = new e.Matrix4(), T = 0;
|
|
220
|
+
if (s.forEach((e) => {
|
|
221
|
+
w.setPosition(e.x, e.y, e.z), C.setMatrixAt(T, w), T++;
|
|
222
|
+
}), C.instanceMatrix.needsUpdate = !0, m) {
|
|
223
|
+
let t = new e.BufferGeometry();
|
|
224
|
+
t.setFromPoints([new e.Vector3(m.start.x, m.start.y, m.start.z), new e.Vector3(m.end.x, m.end.y, m.end.z)]);
|
|
225
|
+
let n = new e.LineBasicMaterial({
|
|
226
|
+
color: "red",
|
|
227
|
+
depthTest: !1,
|
|
228
|
+
depthWrite: !1
|
|
229
|
+
});
|
|
230
|
+
new e.Line(t, n);
|
|
231
|
+
let r = new e.Vector3().copy(new e.Vector3(m.start.x, m.start.y, m.start.z)).add(new e.Vector3(m.end.x, m.end.y, m.end.z)).multiplyScalar(.5), i = new e.Vector3(m.centerDir.x, m.centerDir.y, m.centerDir.z);
|
|
232
|
+
new e.ArrowHelper(i, r, 1, "red");
|
|
233
|
+
}
|
|
234
|
+
if (p) {
|
|
235
|
+
let t = [];
|
|
236
|
+
p.forEach((n, r) => {
|
|
237
|
+
t.push(new e.Vector3(n.x, n.y, n.z));
|
|
238
|
+
});
|
|
239
|
+
let r = new e.BufferGeometry();
|
|
240
|
+
r.setFromPoints(t);
|
|
241
|
+
let i = new e.LineBasicMaterial({
|
|
242
|
+
color: "yellow",
|
|
243
|
+
depthTest: !1,
|
|
244
|
+
depthWrite: !1
|
|
245
|
+
}), a = new e.Line(r, i);
|
|
246
|
+
n.add(a);
|
|
247
|
+
}
|
|
248
|
+
if (v) {
|
|
249
|
+
let t = [], r = [];
|
|
250
|
+
v.coordinates.forEach((n, i) => {
|
|
251
|
+
t.push(new e.Vector3(n.x, n.y, n.z)), r.length < 4 && r.push(new e.Vector3(n.x, n.y, n.z));
|
|
252
|
+
});
|
|
253
|
+
let i = new e.BufferGeometry();
|
|
254
|
+
i.setFromPoints(t);
|
|
255
|
+
let a = new e.LineBasicMaterial({
|
|
256
|
+
color: "green",
|
|
257
|
+
depthTest: !1,
|
|
258
|
+
depthWrite: !1
|
|
259
|
+
}), o = new e.Line(i, a);
|
|
260
|
+
n.add(o);
|
|
261
|
+
let s = h(r.map((t) => new e.Vector3(t.x, t.y, v.heightData.minZ)), r.map((t) => new e.Vector3(t.x, t.y, t.z)));
|
|
262
|
+
n.add(s);
|
|
263
|
+
let [c, l, u] = t, d = c.distanceTo(l), f = new e.Vector3().copy(c).add(l).multiplyScalar(.5);
|
|
264
|
+
new g({
|
|
265
|
+
value: String(d.toFixed(3)),
|
|
266
|
+
position: f
|
|
267
|
+
}).getLabel();
|
|
268
|
+
let p = l.distanceTo(u), m = new e.Vector3().copy(l).add(u).multiplyScalar(.5);
|
|
269
|
+
new g({
|
|
270
|
+
value: String(p.toFixed(3)),
|
|
271
|
+
position: m
|
|
272
|
+
}).getLabel();
|
|
273
|
+
}
|
|
274
|
+
if (f) {
|
|
275
|
+
let t = new e.BoxGeometry(f.size.x, f.size.y, f.size.z), r = new e.LineBasicMaterial({
|
|
276
|
+
color: a,
|
|
277
|
+
linewidth: 2
|
|
278
|
+
}), i = new e.EdgesGeometry(t), o = new e.LineSegments(i, r), s = new Vector3(f.center.x, f.center.y, f.center.z), c = new Quaternion(f.rotation.x, f.rotation.y, f.rotation.z, f.rotation.w);
|
|
279
|
+
o.position.copy(s), o.quaternion.copy(c), n.add(o);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return n;
|
|
284
|
+
}, v = (t, n, r, i) => {
|
|
285
|
+
let a = t, o = [];
|
|
286
|
+
if (i && i.length && (o = i.map((e) => e.clone())), !a || a.length < 4) return {};
|
|
287
|
+
let s = new e.Vector3().subVectors(a[1], a[0]).normalize(), c = new e.Vector3().subVectors(a[3], a[0]).normalize(), l = s.clone().cross(c).normalize(), u = Infinity, d = -Infinity, f = Infinity, p = -Infinity;
|
|
288
|
+
for (let e of a) {
|
|
289
|
+
let t = e.dot(s), n = e.dot(c);
|
|
290
|
+
t < u && (u = t), t > d && (d = t), n < f && (f = n), n > p && (p = n);
|
|
291
|
+
}
|
|
292
|
+
let h = a[0].dot(l), g = s.clone().multiplyScalar(u).add(c.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(h)), _ = s.clone().multiplyScalar(d).add(c.clone().multiplyScalar(f)).add(l.clone().multiplyScalar(h)), v = s.clone().multiplyScalar(d).add(c.clone().multiplyScalar(p)).add(l.clone().multiplyScalar(h)), y = s.clone().multiplyScalar(u).add(c.clone().multiplyScalar(p)).add(l.clone().multiplyScalar(h)), b = [
|
|
293
|
+
g,
|
|
294
|
+
_,
|
|
295
|
+
v,
|
|
296
|
+
y
|
|
297
|
+
], x = m(new e.Vector3().subVectors(g, _), new e.Vector3(0, 0, 1));
|
|
298
|
+
if (x && x.parallel && (b = [
|
|
299
|
+
g,
|
|
300
|
+
y,
|
|
301
|
+
v,
|
|
302
|
+
_
|
|
303
|
+
]), i.length > 0) {
|
|
304
|
+
let t = new e.Vector3().subVectors(b[1], b[0]).normalize(), i = t.clone().negate(), a = new e.Vector3().subVectors(b[3], b[0]).normalize(), s = a.clone().negate(), c = b[0].distanceTo(b[1]), l = b[0].distanceTo(b[3]), u = c / n, d = l / r, f = .001;
|
|
305
|
+
for (let i = 0; i < u; i++) {
|
|
306
|
+
let i = b[0], s = 0;
|
|
307
|
+
for (let c = 0; c < d; c++) {
|
|
308
|
+
let c = i.clone().addScaledVector(t, n), l = c.clone().addScaledVector(a, r), u = i.clone().addScaledVector(a, r), d = new e.Vector3().add(i).add(c).add(l).add(u).multiplyScalar(.25);
|
|
309
|
+
for (let e = 0; e < o.length; e++) if (o[e].distanceTo(d) < f) {
|
|
310
|
+
s++, o.splice(e, 1);
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
i = u;
|
|
314
|
+
}
|
|
315
|
+
if (s >= d / 2) break;
|
|
316
|
+
b[0] = b[0].addScaledVector(t, n), b[3] = b[3].addScaledVector(t, n);
|
|
317
|
+
}
|
|
318
|
+
c = b[0].distanceTo(b[1]), u = c / n;
|
|
319
|
+
for (let t = 0; t < u; t++) {
|
|
320
|
+
let t = b[1], s = 0;
|
|
321
|
+
for (let c = 0; c < d; c++) {
|
|
322
|
+
let c = t.clone().addScaledVector(i, n), l = c.clone().addScaledVector(a, r), u = t.clone().addScaledVector(a, r), d = new e.Vector3().add(t).add(c).add(l).add(u).multiplyScalar(.25);
|
|
323
|
+
for (let e = 0; e < o.length; e++) if (o[e].distanceTo(d) < f) {
|
|
324
|
+
s++, o.splice(e, 1);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
t = u;
|
|
328
|
+
}
|
|
329
|
+
if (s >= d / 2) break;
|
|
330
|
+
b[1] = b[1].addScaledVector(i, n), b[2] = b[2].addScaledVector(i, n);
|
|
331
|
+
}
|
|
332
|
+
c = b[0].distanceTo(b[1]), u = c / n;
|
|
333
|
+
for (let i = 0; i < d; i++) {
|
|
334
|
+
let i = b[3], a = 0;
|
|
335
|
+
for (let c = 0; c < u; c++) {
|
|
336
|
+
let c = i.clone().addScaledVector(t, n), l = c.clone().addScaledVector(s, r), u = i.clone().addScaledVector(s, r), d = new e.Vector3().add(i).add(c).add(l).add(u).multiplyScalar(.25);
|
|
337
|
+
for (let e = 0; e < o.length; e++) if (o[e].distanceTo(d) < f) {
|
|
338
|
+
a++, o.splice(e, 1);
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
i = c;
|
|
342
|
+
}
|
|
343
|
+
if (a >= u / 2) break;
|
|
344
|
+
b[2] = b[2].addScaledVector(s, r), b[3] = b[3].addScaledVector(s, r);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
let S = b[0].distanceTo(b[1]) * b[0].distanceTo(b[3]);
|
|
348
|
+
return {
|
|
349
|
+
facePoints: b,
|
|
350
|
+
boxArea: S
|
|
351
|
+
};
|
|
352
|
+
}, y = (t, n, r, i, a = e.MathUtils.degToRad(10)) => {
|
|
353
|
+
let o = new e.Vector3(), s = new e.Vector3();
|
|
354
|
+
o.subVectors(new e.Vector3(n.x, n.y, 0), new e.Vector3(t.x, t.y, 0)).normalize(), s.subVectors(new e.Vector3(i.x, i.y, 0), new e.Vector3(r.x, r.y, 0)).normalize();
|
|
355
|
+
let c = o.dot(s), l = Math.acos(Math.min(Math.abs(c), 1)), u = 1 - Math.min(l / a, 1), d = c > 0 ? "same" : "opposite";
|
|
356
|
+
return {
|
|
357
|
+
parallelism: u,
|
|
358
|
+
angle: l,
|
|
359
|
+
angleDeg: e.MathUtils.radToDeg(l),
|
|
360
|
+
isParallel: l < a,
|
|
361
|
+
direction: d,
|
|
362
|
+
vectors: {
|
|
363
|
+
v1: o,
|
|
364
|
+
v2: s
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}, b = (t, n, r, i) => {
|
|
368
|
+
let a = new e.Vector3().subVectors(n, t), o = new e.Vector3().subVectors(i, r), s = a.length(), c = o.length();
|
|
369
|
+
if (s === 0 || c === 0) return {
|
|
370
|
+
rate: NaN,
|
|
371
|
+
angle: NaN,
|
|
372
|
+
isPerpendicular: !1,
|
|
373
|
+
isParallel: !1
|
|
374
|
+
};
|
|
375
|
+
a.normalize(), o.normalize();
|
|
376
|
+
let l = Math.abs(a.dot(o)), u = Math.min(1, Math.max(0, l)), d = Math.acos(u), f = e.MathUtils.radToDeg(d), p = 1 - u;
|
|
377
|
+
return {
|
|
378
|
+
rate: p,
|
|
379
|
+
percent: `${(p * 100).toFixed(2)}%`,
|
|
380
|
+
angle: f,
|
|
381
|
+
isPerpendicular: Math.abs(f - 90) < .01,
|
|
382
|
+
isParallel: f < .01
|
|
383
|
+
};
|
|
384
|
+
}, x = (t, n, r = !1) => new e.Vector3((t.x + n.x) / 2, (t.y + n.y) / 2, r ? 0 : (t.z + n.z) / 2), S = (t, n, r, i, a = {}) => {
|
|
385
|
+
let { parallelAngleMax: o = e.MathUtils.degToRad(10), collinearAngleMax: s = e.MathUtils.degToRad(7), distanceThreshold: c = 2, overlapThreshold: l = .01 } = a, u = new e.Vector3().subVectors(n, t), d = new e.Vector3().subVectors(i, r), f = u.clone().normalize(), p = d.clone().normalize(), m = e.MathUtils.clamp(f.dot(p), -1, 1), h = Math.acos(Math.abs(m)), g = e.MathUtils.radToDeg(h);
|
|
386
|
+
if (h > o) return {
|
|
387
|
+
type: "not_parallel",
|
|
388
|
+
angleDeg: g,
|
|
389
|
+
avgPerpendicularDistance: null,
|
|
390
|
+
maxPerpendicularDistance: null,
|
|
391
|
+
gap: null,
|
|
392
|
+
overlap: null,
|
|
393
|
+
closestDistance: null
|
|
394
|
+
};
|
|
395
|
+
m < 0 && p.negate();
|
|
396
|
+
let _ = new e.Vector3().addVectors(f, p).normalize(), v = new e.Vector3().addVectors(t, n).multiplyScalar(.5), y = C(r, v, f), b = C(i, v, f), x = (y + b) / 2, S = Math.max(y, b), T = t.dot(_), E = n.dot(_), D = r.dot(_), O = i.dot(_), k = Math.min(T, E), A = Math.max(T, E), j = Math.min(D, O), M = Math.max(D, O), N = A - k, P = M - j, F = Math.min(N, P), I = Math.min(A, M) - Math.max(k, j), L = I < 0 ? -I : 0, R = I > 0 ? I : 0, z = F > 0 ? R / F : 0, B = w(t, n, r, i), V = h <= s && x < c, H;
|
|
397
|
+
return V ? H = z > .5 ? "collinear_overlap" : "collinear_gap" : h <= o && (H = "parallel_offset"), {
|
|
398
|
+
type: H,
|
|
399
|
+
angleDeg: g,
|
|
400
|
+
avgPerpendicularDistance: x,
|
|
401
|
+
maxPerpendicularDistance: S,
|
|
402
|
+
gap: L,
|
|
403
|
+
overlap: R,
|
|
404
|
+
closestDistance: B
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
function C(t, n, r) {
|
|
408
|
+
let i = new e.Vector3().subVectors(t, n), a = i.dot(r), o = r.clone().multiplyScalar(a);
|
|
409
|
+
return new e.Vector3().subVectors(i, o).length();
|
|
410
|
+
}
|
|
411
|
+
function w(t, n, r, i) {
|
|
412
|
+
let a = new e.Vector3().subVectors(n, t), o = new e.Vector3().subVectors(i, r), s = new e.Vector3().subVectors(r, t), c = a.dot(a), l = a.dot(o), u = o.dot(o), d = a.dot(s), f = o.dot(s), p = c * u - l * l, m, h;
|
|
413
|
+
p < 1e-10 ? (m = 0, h = u === 0 ? 0 : f / u) : (m = (l * f - u * d) / p, h = (c * f - l * d) / p), m = e.MathUtils.clamp(m, 0, 1), h = u === 0 ? 0 : e.MathUtils.clamp((l * m + f) / u, 0, 1), m = c === 0 ? 0 : e.MathUtils.clamp((l * h - d) / c, 0, 1);
|
|
414
|
+
let g = t.clone().add(a.clone().multiplyScalar(m)), _ = r.clone().add(o.clone().multiplyScalar(h));
|
|
415
|
+
return g.distanceTo(_);
|
|
416
|
+
}
|
|
417
|
+
var T = (t, n, r, i = .05, a = .02) => {
|
|
418
|
+
let [o, s, c, l] = t, u = new e.Vector3().subVectors(s, o), d = new e.Vector3().subVectors(l, o), f = new e.Vector3().crossVectors(u, d).normalize(), p = u.length(), m = d.length(), h = u.clone().normalize(), g = d.clone().normalize(), _ = r - i, v = r + i, y = new e.Vector3(), b = [], x = Math.ceil(p / a), S = Math.ceil(m / a), C = p / x, w = m / S, T = new Uint8Array(x * S);
|
|
419
|
+
for (let t = 0; t < n.length; t++) {
|
|
420
|
+
y.subVectors(n[t], o);
|
|
421
|
+
let r = Math.abs(y.dot(f));
|
|
422
|
+
if (r < _ || r > v) continue;
|
|
423
|
+
let i = y.dot(h), a = y.dot(g);
|
|
424
|
+
if (i < 0 || i > p || a < 0 || a > m) continue;
|
|
425
|
+
b.push(new e.Vector3(n[t].x, n[t].y, n[t].z));
|
|
426
|
+
let s = Math.min(Math.floor(i / C), x - 1), c = Math.min(Math.floor(a / w), S - 1);
|
|
427
|
+
T[c * x + s] = 1;
|
|
428
|
+
}
|
|
429
|
+
let E = 0;
|
|
430
|
+
for (let e = 0; e < T.length; e++) T[e] && E++;
|
|
431
|
+
let D = x * S, O = p * m, k = E == 0 || D == 0 ? 0 : E / D * O;
|
|
432
|
+
return {
|
|
433
|
+
filteredPoints: b,
|
|
434
|
+
coveragePercent: E == 0 || D == 0 ? 0 : E / D * 100,
|
|
435
|
+
quadArea: O,
|
|
436
|
+
coveredArea: k
|
|
437
|
+
};
|
|
438
|
+
}, E = (e, t) => Math.round(Math.max(5, Math.min(350, t * Math.sqrt(e)))), D = (t) => {
|
|
439
|
+
let n = new e.Vector3(t.start.x, t.start.y, t.start.z), r = new e.Vector3(t.end.x, t.end.y, t.end.z), i = n.distanceTo(r), a = t.rooftopPz - t.start.z, o = E(i, 100), s = E(a, 70), c = a / s, l = /* @__PURE__ */ new Map();
|
|
440
|
+
for (let e = 0; e < s; e++) l.set((e + 1) * c, {
|
|
441
|
+
count: 0,
|
|
442
|
+
minZ: Infinity,
|
|
443
|
+
maxZ: -Infinity
|
|
444
|
+
});
|
|
445
|
+
let u = new e.Line3(n, r), d = t.originalPoints, f = new e.Vector3();
|
|
446
|
+
for (let e = 0; e < d.length; e++) {
|
|
447
|
+
let t = d[e], n = u.closestPointToPoint(t, !0, f).distanceTo(t), r = Math.floor(n / c);
|
|
448
|
+
if (r < s) {
|
|
449
|
+
let e = l.get((r + 1) * c);
|
|
450
|
+
e.count++, t.z < e.minZ && (e.minZ = t.z), t.z > e.maxZ && (e.maxZ = t.z);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
let p, m, h = o / 2;
|
|
454
|
+
for (let [e, t] of l) if (t.count >= h) {
|
|
455
|
+
p = t.minZ;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
for (let [e, t] of [...l.entries()].reverse()) if (t.count >= h) {
|
|
459
|
+
m = t.maxZ;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
minZ: p,
|
|
464
|
+
maxZ: m
|
|
465
|
+
};
|
|
466
|
+
}, O = (t, n) => {
|
|
467
|
+
function r(t, n, r, i, a, o, s, c, l) {
|
|
468
|
+
let u = new e.Line3(t, n), d = /* @__PURE__ */ new Map(), f = new e.Vector3(), p = t.clone(), m = n.clone(), h = 0;
|
|
469
|
+
for (;;) {
|
|
470
|
+
let g = /* @__PURE__ */ new Map(), _ = 0;
|
|
471
|
+
for (let t = 0; t < l.checkResults.length; t++) if (!(l.checkResults[t].allCenterPoints.length / c * 100 < 1)) for (let n = 0; n < l.checkResults[t].allCenterPoints.length; n++) {
|
|
472
|
+
if (d.has(t) && d.get(t).removePtsIndex.includes(n)) continue;
|
|
473
|
+
let r = l.checkResults[t].allCenterPoints[n];
|
|
474
|
+
r = new e.Vector3(r.x, r.y, r.z);
|
|
475
|
+
let i = u.closestPointToPoint(r, !0, f), o = r.distanceTo(i);
|
|
476
|
+
Math.abs(o - a) < .01 && (_++, g.has(t) ? g.get(t).removePtsIndex.push(n) : g.set(t, {
|
|
477
|
+
index: t,
|
|
478
|
+
removePtsIndex: [n]
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
if (h == s) {
|
|
482
|
+
t = p, n = m;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
if (_ < o / 20 * 19 || _ == 0) {
|
|
486
|
+
g.clear(), s - h < 5 && (t = p, n = m, d.clear());
|
|
487
|
+
break;
|
|
488
|
+
} else {
|
|
489
|
+
h++;
|
|
490
|
+
for (let [e, t] of g) d.has(e) ? d.get(e).removePtsIndex.push(...t.removePtsIndex) : d.set(e, t);
|
|
491
|
+
g.clear(), t = t.addScaledVector(r, i), n = n.addScaledVector(r, i), u.set(t, n);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (d.size > 0 && h != s) for (let [e, t] of d) {
|
|
495
|
+
let n = [], r = [];
|
|
496
|
+
for (let i = 0; i < l.checkResults[e].allCenterPoints.length; i++) t.removePtsIndex.includes(i) || (n.push(l.checkResults[e].allCenterPoints[i]), r.push(l.checkResults[e].originalVertices[i]));
|
|
497
|
+
l.checkResults[e].allCenterPoints = n, l.checkResults[e].originalVertices = r;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
for (let n = 0; n < t.length; n++) {
|
|
501
|
+
let i = t[n];
|
|
502
|
+
if (i.length < .5) continue;
|
|
503
|
+
let a = -1, o = -1;
|
|
504
|
+
if (!i.checkResults || i.checkResults.length <= 0) continue;
|
|
505
|
+
if (i.checkResults[0].originalVertices && i.checkResults[0].originalVertices.length > 0) {
|
|
506
|
+
let [t, n, r, s] = i.checkResults[0].originalVertices[0];
|
|
507
|
+
t = new e.Vector3(t.x, t.y, t.z), n = new e.Vector3(n.x, n.y, n.z), r = new e.Vector3(r.x, r.y, r.z), s = new e.Vector3(s.x, s.y, s.z), a = t.distanceTo(n), o = t.distanceTo(s);
|
|
508
|
+
let c = m(new e.Vector3().subVectors(t, n).normalize(), new e.Vector3(0, 0, 1));
|
|
509
|
+
c && c.parallel && ([o, a] = [a, o]);
|
|
510
|
+
}
|
|
511
|
+
if (a < 0 || o < 0) continue;
|
|
512
|
+
let s = new e.Vector3(i.start.x, i.start.y, i.start.z), c = new e.Vector3(i.end.x, i.end.y, i.end.z), l = s.distanceTo(c), u = i.rooftopPz - i.start.z, d = Math.ceil(l / a), f = Math.ceil(u / o), p = s.clone(), h = c.clone(), g = h.clone().add(new e.Vector3(0, 0, u)), _ = p.clone().add(new e.Vector3(0, 0, u)), v = new e.Vector3().subVectors(h, p).normalize(), y = v.clone().negate();
|
|
513
|
+
new e.Vector3().subVectors(g, p).normalize().clone().negate();
|
|
514
|
+
let b = a / 2;
|
|
515
|
+
o / 2;
|
|
516
|
+
let x = l * u / (a * o);
|
|
517
|
+
r(p, _, v, a, b, f, d, x, i), r(h, g, y, a, b, f, d, x, i), i.start = p, i.end = h;
|
|
518
|
+
let S = new e.Plane();
|
|
519
|
+
S.setFromCoplanarPoints(p, h, g);
|
|
520
|
+
let C = [];
|
|
521
|
+
i.originalPoints.forEach((t) => {
|
|
522
|
+
let n = new e.Vector3();
|
|
523
|
+
S.projectPoint(t, n), n.z = p.z, C.push(n);
|
|
524
|
+
});
|
|
525
|
+
let w = new e.Vector3(), T = new e.Vector3();
|
|
526
|
+
S.projectPoint(p, w), S.projectPoint(h, T);
|
|
527
|
+
let E = new e.Line3(w, T), D = [], O = new e.Vector3();
|
|
528
|
+
C.forEach((e, t) => {
|
|
529
|
+
E.closestPointToPoint(e, !0, O).distanceTo(e) < .001 && D.push(i.originalPoints[t]);
|
|
530
|
+
}), i.originalPoints = D;
|
|
531
|
+
}
|
|
532
|
+
}, k = class {
|
|
533
|
+
results;
|
|
534
|
+
clusterResults;
|
|
535
|
+
constructor() {
|
|
536
|
+
this.results = null;
|
|
537
|
+
}
|
|
538
|
+
initLimits1(e, t) {
|
|
539
|
+
let n, r;
|
|
540
|
+
return n = e < .3 ? 5 : e < .5 ? 8 : e < .8 ? 10 : e < 1 ? 15 : e < 2 ? 30 : e < 3 ? 35 : e < 4 ? 40 : e < 5 ? 45 : e < 6 ? 50 : e < 7 ? 60 : e < 8.5 ? 70 : e < 10 ? 80 : e < 15 ? 100 : e < 20 ? 120 : e < 25 ? 140 : e < 30 ? 160 : e < 35 ? 180 : e < 40 ? 200 : e < 45 ? 230 : e < 50 ? 250 : 350, t < 1 ? r = 30 : t < 2 ? r = 40 : t < 2.5 ? r = 45 : t < 3 ? r = 60 : t < 3.6 ? r = 70 : t < 4 && (r = 80), {
|
|
541
|
+
horizontalSubdivisions: n,
|
|
542
|
+
verticalSubdivisions: r
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
initLimits2(e, t) {
|
|
546
|
+
return {
|
|
547
|
+
horizontalSubdivisions: Math.round(Math.max(5, Math.min(350, e / .08))),
|
|
548
|
+
verticalSubdivisions: Math.round(Math.max(30, Math.min(80, t / .06)))
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
initLimits4(e, t) {
|
|
552
|
+
return {
|
|
553
|
+
horizontalSubdivisions: Math.round(Math.max(5, Math.min(350, 25 * Math.sqrt(e)))) * 1,
|
|
554
|
+
verticalSubdivisions: Math.round(Math.max(30, Math.min(80, 25 * Math.sqrt(t)))) * 1
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
initLimits3(e, t) {
|
|
558
|
+
let n;
|
|
559
|
+
return n = e < 2 ? .06 : e < 10 ? .1 : .15, {
|
|
560
|
+
horizontalSubdivisions: Math.round(Math.max(5, Math.min(350, e / n))),
|
|
561
|
+
verticalSubdivisions: Math.round(Math.max(30, Math.min(80, t / .06)))
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
createWallPlaneMeshFromFourPoints(t, n, r, i, a, o, s = 16777215) {
|
|
565
|
+
let c = [
|
|
566
|
+
t,
|
|
567
|
+
n,
|
|
568
|
+
r,
|
|
569
|
+
i
|
|
570
|
+
];
|
|
571
|
+
for (let t = 0; t < c.length; t++) this.isValidVector3(c[t]) || (console.error(`点${t + 1}包含无效数据:`, c[t]), c[t] = new e.Vector3(t, 0, t));
|
|
572
|
+
let l = new e.BufferGeometry(), u = new Float32Array([
|
|
573
|
+
c[0].x,
|
|
574
|
+
c[0].y,
|
|
575
|
+
c[0].z,
|
|
576
|
+
c[1].x,
|
|
577
|
+
c[1].y,
|
|
578
|
+
c[1].z,
|
|
579
|
+
c[2].x,
|
|
580
|
+
c[2].y,
|
|
581
|
+
c[2].z,
|
|
582
|
+
c[3].x,
|
|
583
|
+
c[3].y,
|
|
584
|
+
c[3].z
|
|
585
|
+
]), d = [
|
|
586
|
+
0,
|
|
587
|
+
1,
|
|
588
|
+
2,
|
|
589
|
+
0,
|
|
590
|
+
2,
|
|
591
|
+
3
|
|
592
|
+
], f = new Float32Array([
|
|
593
|
+
0,
|
|
594
|
+
0,
|
|
595
|
+
1,
|
|
596
|
+
0,
|
|
597
|
+
1,
|
|
598
|
+
1,
|
|
599
|
+
0,
|
|
600
|
+
1
|
|
601
|
+
]);
|
|
602
|
+
l.setAttribute("position", new e.BufferAttribute(u, 3)), l.setAttribute("uv", new e.BufferAttribute(f, 2)), l.setIndex(d), l.computeVertexNormals();
|
|
603
|
+
let p = new e.Mesh(l, a), m = new e.EdgesGeometry(l), h = new e.LineSegments(m, new e.LineBasicMaterial({ color: s }));
|
|
604
|
+
return o.add(h), p;
|
|
605
|
+
}
|
|
606
|
+
createSubdividedWallPlane(t, n, r, i, a) {
|
|
607
|
+
let o = [];
|
|
608
|
+
if (!t || !t.start || !t.end || isNaN(t.rooftopPz)) return o;
|
|
609
|
+
let s = new e.Vector3(t.start.x, t.start.y, t.start.z), c = new e.Vector3(t.end.x, t.end.y, t.end.z), l = [
|
|
610
|
+
s,
|
|
611
|
+
c,
|
|
612
|
+
new e.Vector3(t.end.x, t.end.y, t.rooftopPz),
|
|
613
|
+
new e.Vector3(t.start.x, t.start.y, t.rooftopPz)
|
|
614
|
+
];
|
|
615
|
+
for (let e = 0; e < l.length; e++) if (!this.isValidVector3(l[e])) return console.error(`墙体基础点${e}无效:`, l[e]), o;
|
|
616
|
+
let u = s.distanceTo(c), d = Math.abs(t.rooftopPz - t.start.z);
|
|
617
|
+
if (u === 0 || d === 0) return console.error("墙体宽度或高度为0"), console.log("line.rooftopPz", t.rooftopPz), console.log("bottomLeft", s), console.log("bottomRight", c), console.log(t.length), o;
|
|
618
|
+
let f = u / r, p = d / n, m = new e.Vector3().subVectors(c, s).normalize(), h = new e.Vector3(0, 0, 1);
|
|
619
|
+
for (let t = 0; t < n; t++) for (let n = 0; n < r; n++) try {
|
|
620
|
+
let r = {
|
|
621
|
+
points: [
|
|
622
|
+
new e.Vector3().copy(s).add(m.clone().multiplyScalar(n * f)).add(h.clone().multiplyScalar(t * p)),
|
|
623
|
+
new e.Vector3().copy(s).add(m.clone().multiplyScalar((n + 1) * f)).add(h.clone().multiplyScalar(t * p)),
|
|
624
|
+
new e.Vector3().copy(s).add(m.clone().multiplyScalar((n + 1) * f)).add(h.clone().multiplyScalar((t + 1) * p)),
|
|
625
|
+
new e.Vector3().copy(s).add(m.clone().multiplyScalar(n * f)).add(h.clone().multiplyScalar((t + 1) * p))
|
|
626
|
+
],
|
|
627
|
+
userData: {}
|
|
628
|
+
};
|
|
629
|
+
r.userData = {
|
|
630
|
+
type: "wallSegment",
|
|
631
|
+
row: t,
|
|
632
|
+
col: n,
|
|
633
|
+
originalMaterial: i,
|
|
634
|
+
width: f,
|
|
635
|
+
height: p
|
|
636
|
+
}, o.push(r);
|
|
637
|
+
} catch (e) {
|
|
638
|
+
console.error(`创建墙体小平面(${t}, ${n})时出错:`, e);
|
|
639
|
+
}
|
|
640
|
+
return o;
|
|
641
|
+
}
|
|
642
|
+
calculateMinRequiredPoints(e) {
|
|
643
|
+
let t = Math.floor(Math.log1p(e) * .5);
|
|
644
|
+
return Math.max(1, t);
|
|
645
|
+
}
|
|
646
|
+
calculateExpectedDensity(e) {
|
|
647
|
+
return e < 1 ? 10 : e < 4 ? 5 : 2;
|
|
648
|
+
}
|
|
649
|
+
evaluateSegmentByArea(e, t, n, r) {
|
|
650
|
+
if (t === 0) return !1;
|
|
651
|
+
let i = e.area, a = e.minRequiredPoints, o = e.expectedDensity, s = t / Math.max(i, .001), c = t >= a, l = s >= o * .3, u = !0;
|
|
652
|
+
return i < .5 && t > 0 && (u = this.checkSmallAreaDistribution(e, n, r)), c && l && u;
|
|
653
|
+
}
|
|
654
|
+
checkSmallAreaDistribution(e, t, n) {
|
|
655
|
+
if (t.length < 2) return !0;
|
|
656
|
+
let r = t.map((e) => n[e]);
|
|
657
|
+
e.bounds;
|
|
658
|
+
let i = e.center, a = 0, o = Math.sqrt(e.area) * .3;
|
|
659
|
+
return r.forEach((e) => {
|
|
660
|
+
e.distanceTo(i) <= o && a++;
|
|
661
|
+
}), a / r.length >= .3;
|
|
662
|
+
}
|
|
663
|
+
getFailureReason(e, t) {
|
|
664
|
+
let n = e.area, r = e.minRequiredPoints, i = e.expectedDensity, a = t / Math.max(n, .001), o = [];
|
|
665
|
+
return t === 0 ? o.push("无点") : (t < r && o.push(`点数不足: ${t}/${r}`), a < i * .3 && o.push(`密度不足: ${a.toFixed(2)}/${i.toFixed(2)}`), n < .5 && t > 0 && (this.checkSmallAreaDistribution(e, [], []) || o.push("小平面分布不均"))), o.length > 0 ? o.join(", ") : "未知原因";
|
|
666
|
+
}
|
|
667
|
+
calculateMedian(e) {
|
|
668
|
+
let t = [...e].sort((e, t) => e - t), n = Math.floor(t.length / 2);
|
|
669
|
+
return t.length % 2 == 0 ? (t[n - 1] + t[n]) / 2 : t[n];
|
|
670
|
+
}
|
|
671
|
+
isPointInBoundingBox(e, t, n = .1) {
|
|
672
|
+
return e.x >= t.min[0] - n && e.x <= t.max[0] + n && e.y >= t.min[1] - n && e.y <= t.max[1] + n && e.z >= t.min[2] - n && e.z <= t.max[2] + n;
|
|
673
|
+
}
|
|
674
|
+
getSegmentPlane(t) {
|
|
675
|
+
let n = t.geometry;
|
|
676
|
+
if (!n || !n.attributes.position) return null;
|
|
677
|
+
let r = n.attributes.position;
|
|
678
|
+
if (r.count < 3) return null;
|
|
679
|
+
let i = new e.Vector3().fromBufferAttribute(r, 0), a = new e.Vector3().fromBufferAttribute(r, 1), o = new e.Vector3().fromBufferAttribute(r, 2);
|
|
680
|
+
i.applyMatrix4(t.matrixWorld), a.applyMatrix4(t.matrixWorld), o.applyMatrix4(t.matrixWorld);
|
|
681
|
+
let s = new e.Plane();
|
|
682
|
+
return s.setFromCoplanarPoints(i, a, o), s;
|
|
683
|
+
}
|
|
684
|
+
analyzePointDistribution(t, n, r = .01) {
|
|
685
|
+
this.results = {
|
|
686
|
+
totalSegments: 0,
|
|
687
|
+
segmentsWithPoints: 0,
|
|
688
|
+
segmentsWithoutPoints: 0,
|
|
689
|
+
missingSegments: [],
|
|
690
|
+
pointsInSegments: /* @__PURE__ */ new Map(),
|
|
691
|
+
segmentsByPoint: /* @__PURE__ */ new Map(),
|
|
692
|
+
segmentDetails: /* @__PURE__ */ new Map(),
|
|
693
|
+
tolerance: r,
|
|
694
|
+
analysisTime: null
|
|
695
|
+
};
|
|
696
|
+
let i = performance.now(), a = [];
|
|
697
|
+
t.forEach((t) => {
|
|
698
|
+
if (t.userData && t.userData.type === "wallSegment") {
|
|
699
|
+
let n = this.getWorldVerticesNew(t.points);
|
|
700
|
+
if (n.length < 4) return;
|
|
701
|
+
let r = new e.Vector3().add(n[0]).add(n[1]).add(n[2]).add(n[3]).multiplyScalar(.25);
|
|
702
|
+
t.userData.center = r, t.vertices = n, a.push(t);
|
|
703
|
+
}
|
|
704
|
+
}), this.results.totalSegments = a.length;
|
|
705
|
+
for (let t of a) {
|
|
706
|
+
if (t.vertices.length < 4) continue;
|
|
707
|
+
let i = t.userData.center, a = `row${t.userData.row}_col${t.userData.col}`, [o, s, c, l] = t.vertices, u = new e.Vector3().subVectors(s, o).normalize(), d = new e.Vector3().subVectors(l, o).normalize(), f = o.distanceTo(s), p = o.distanceTo(l), m = new e.Plane();
|
|
708
|
+
m.setFromCoplanarPoints(o, s, l);
|
|
709
|
+
let h = f / 2, g = p / 2;
|
|
710
|
+
for (let e = 0; e < n.length; e++) this.isPointInWallSegmentOptimized(n[e], i, m, o, u, d, f, p, h, g, r) && (this.results.pointsInSegments.has(a) || this.results.pointsInSegments.set(a, []), this.results.pointsInSegments.get(a).push(e));
|
|
711
|
+
}
|
|
712
|
+
return a.forEach((e) => {
|
|
713
|
+
let t = `row${e.userData.row}_col${e.userData.col}`, n = this.results.pointsInSegments.has(t) ? this.results.pointsInSegments.get(t).length : 0;
|
|
714
|
+
n >= 1 ? this.results.segmentsWithPoints++ : (this.results.segmentsWithoutPoints++, this.results.missingSegments.push({
|
|
715
|
+
row: e.userData.row,
|
|
716
|
+
col: e.userData.col,
|
|
717
|
+
width: e.userData.width,
|
|
718
|
+
height: e.userData.height,
|
|
719
|
+
segmentKey: t,
|
|
720
|
+
vertices: e.vertices,
|
|
721
|
+
center: e.userData.center,
|
|
722
|
+
mesh: e,
|
|
723
|
+
pointCount: n,
|
|
724
|
+
hasPointsButNotEnough: n > 0 && n < 1
|
|
725
|
+
}));
|
|
726
|
+
}), this.results.analysisTime = performance.now() - i, this.printAnalysisResults(), this.results;
|
|
727
|
+
}
|
|
728
|
+
isPointInWallSegmentOptimized(t, n, r, i, a, o, s, c, l, u, d) {
|
|
729
|
+
if (Math.abs(r.distanceToPoint(t)) > d) return !1;
|
|
730
|
+
let f = new e.Vector3().subVectors(t, n), p = Math.abs(f.dot(a)), m = Math.abs(f.dot(o));
|
|
731
|
+
if (p > l && m > u) return !1;
|
|
732
|
+
let h = new e.Vector3().subVectors(t, i), g = h.dot(a), _ = h.dot(o), v = g >= -d && g <= s + d, y = _ >= -d && _ <= c + d;
|
|
733
|
+
return v && y;
|
|
734
|
+
}
|
|
735
|
+
isPointInWallSegment(e, t, n, r = .1) {
|
|
736
|
+
if (!e.geometry) return !1;
|
|
737
|
+
try {
|
|
738
|
+
let i = this.getWorldVertices(e);
|
|
739
|
+
return i.length < 4 ? !1 : this.isPointInRotatedWall(i, t, n, r);
|
|
740
|
+
} catch (e) {
|
|
741
|
+
return console.error("判断点是否在墙体平面内时出错:", e), !1;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
isPointInRotatedWall(t, n, r, i = .1) {
|
|
745
|
+
let [a, o, s, c] = t, l = new e.Plane();
|
|
746
|
+
if (l.setFromCoplanarPoints(a, o, c), Math.abs(l.distanceToPoint(n)) > i) return !1;
|
|
747
|
+
let u = new e.Vector3().subVectors(o, a).normalize(), d = new e.Vector3().subVectors(c, a).normalize();
|
|
748
|
+
new e.Vector3().crossVectors(u, d).normalize();
|
|
749
|
+
let f = new e.Vector3().subVectors(n, a), p = f.dot(u), m = f.dot(d), h = a.distanceTo(o), g = a.distanceTo(c), _ = p >= -i && p <= h + i, v = m >= -i && m <= g + i;
|
|
750
|
+
return _ && v && r.distanceTo(n) < h / 2 && r.distanceTo(n) < g / 2;
|
|
751
|
+
}
|
|
752
|
+
getWorldVertices(t) {
|
|
753
|
+
if (t._cachedWorldVertices && t.matrixWorld.equals(t._cachedMatrixWorld)) return t._cachedWorldVertices;
|
|
754
|
+
let n = t.geometry.getAttribute("position"), r = [];
|
|
755
|
+
for (let i = 0; i < Math.min(4, n.count); i++) {
|
|
756
|
+
let a = new e.Vector3();
|
|
757
|
+
a.fromBufferAttribute(n, i), a.applyMatrix4(t.matrixWorld), r.push(a);
|
|
758
|
+
}
|
|
759
|
+
return t._cachedWorldVertices = r, t._cachedMatrixWorld = t.matrixWorld.clone(), r;
|
|
760
|
+
}
|
|
761
|
+
getWorldVerticesNew(e) {
|
|
762
|
+
let t = [];
|
|
763
|
+
for (let n = 0; n < e.length; n++) {
|
|
764
|
+
let r = e[n].clone();
|
|
765
|
+
t.push(r);
|
|
766
|
+
}
|
|
767
|
+
return t;
|
|
768
|
+
}
|
|
769
|
+
getWallSegmentBounds(t) {
|
|
770
|
+
if (!t.geometry) return null;
|
|
771
|
+
let n = t.geometry.getAttribute("position"), r = new e.Box3();
|
|
772
|
+
for (let i = 0; i < n.count; i++) {
|
|
773
|
+
let a = new e.Vector3();
|
|
774
|
+
a.fromBufferAttribute(n, i), a.applyMatrix4(t.matrixWorld), r.expandByPoint(a);
|
|
775
|
+
}
|
|
776
|
+
return {
|
|
777
|
+
min: r.min.toArray(),
|
|
778
|
+
max: r.max.toArray(),
|
|
779
|
+
center: r.getCenter(new e.Vector3()).toArray(),
|
|
780
|
+
size: r.getSize(new e.Vector3()).toArray()
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
highlightEmptySegments(e, t, n, r = 1) {
|
|
784
|
+
if (!this.results) {
|
|
785
|
+
console.warn("请先运行分析函数");
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
789
|
+
this.results.missingSegments.forEach((e) => {
|
|
790
|
+
i.set(e.segmentKey, e), a.has(e.row) || a.set(e.row, /* @__PURE__ */ new Map()), a.get(e.row).set(e.col, {
|
|
791
|
+
segmentKey: e.segmentKey,
|
|
792
|
+
isEmpty: !0,
|
|
793
|
+
visited: !1
|
|
794
|
+
});
|
|
795
|
+
}), e.forEach((e) => {
|
|
796
|
+
if (e.userData && e.userData.type === "wallSegment") {
|
|
797
|
+
let t = `row${e.userData.row}_col${e.userData.col}`, n = i.has(t);
|
|
798
|
+
a.has(e.userData.row) || a.set(e.userData.row, /* @__PURE__ */ new Map()), a.get(e.userData.row).has(e.userData.col) || a.get(e.userData.row).set(e.userData.col, {
|
|
799
|
+
segmentKey: t,
|
|
800
|
+
isEmpty: n,
|
|
801
|
+
visited: !1
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
let o = [], s = [
|
|
806
|
+
[0, 1],
|
|
807
|
+
[1, 0],
|
|
808
|
+
[0, -1],
|
|
809
|
+
[-1, 0]
|
|
810
|
+
];
|
|
811
|
+
for (let [e, t] of i) {
|
|
812
|
+
let e = a.get(t.row)?.get(t.col);
|
|
813
|
+
if (e && !e.visited) {
|
|
814
|
+
let n = [], c = [[t.row, t.col]];
|
|
815
|
+
for (e.visited = !0; c.length > 0;) {
|
|
816
|
+
let [e, t] = c.shift(), r = `row${e}_col${t}`;
|
|
817
|
+
i.has(r) && n.push(i.get(r));
|
|
818
|
+
for (let [n, r] of s) {
|
|
819
|
+
let i = e + n, o = t + r;
|
|
820
|
+
if (a.has(i) && a.get(i).has(o)) {
|
|
821
|
+
let e = a.get(i).get(o);
|
|
822
|
+
!e.visited && e.isEmpty && (e.visited = !0, c.push([i, o]));
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
n.length >= r && o.push(n);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
let c = this.createClusterMaterials(o.length), l = [];
|
|
830
|
+
return this.clusterResults = {
|
|
831
|
+
clusters: o.sort((e, t) => t.length - e.length),
|
|
832
|
+
highlightedMeshes: l,
|
|
833
|
+
clusterMaterials: c,
|
|
834
|
+
totalClusters: o.length,
|
|
835
|
+
totalHighlighted: l.length
|
|
836
|
+
}, this.clusterResults;
|
|
837
|
+
}
|
|
838
|
+
calculateBoundaryRegularity(e, t, n, r, i) {
|
|
839
|
+
let a = 0, o = 0, s = t, c = !0;
|
|
840
|
+
for (let t = r; t <= i; t++) e.has(s) && e.get(s).has(t) ? o++ : c = !1;
|
|
841
|
+
c && a++;
|
|
842
|
+
let l = n, u = !0;
|
|
843
|
+
for (let t = r; t <= i; t++) e.has(l) && e.get(l).has(t) ? o++ : u = !1;
|
|
844
|
+
u && a++;
|
|
845
|
+
let d = r, f = !0;
|
|
846
|
+
for (let r = t; r <= n; r++) e.has(r) && e.get(r).has(d) ? o++ : f = !1;
|
|
847
|
+
f && a++;
|
|
848
|
+
let p = i, m = !0;
|
|
849
|
+
for (let r = t; r <= n; r++) e.has(r) && e.get(r).has(p) ? o++ : m = !1;
|
|
850
|
+
return m && a++, a / 4;
|
|
851
|
+
}
|
|
852
|
+
calculateClusterQualityScore(e) {
|
|
853
|
+
let t = 1 / Math.max(1, e.aspectRatio);
|
|
854
|
+
return e.compactness * .4 + e.boundaryRegularity * .4 + t * .2;
|
|
855
|
+
}
|
|
856
|
+
calculateStrictClusterBounds(e) {
|
|
857
|
+
if (e.length === 0) return {
|
|
858
|
+
width: 0,
|
|
859
|
+
height: 0
|
|
860
|
+
};
|
|
861
|
+
let t = [];
|
|
862
|
+
if (e.forEach((e) => {
|
|
863
|
+
e.vertices && e.vertices.length > 0 && t.push(...e.vertices);
|
|
864
|
+
}), t.length === 0) {
|
|
865
|
+
let t = [...new Set(e.map((e) => e.row))];
|
|
866
|
+
return {
|
|
867
|
+
width: [...new Set(e.map((e) => e.col))].length * (e[0].bounds?.width || 1),
|
|
868
|
+
height: t.length * (e[0].bounds?.height || 1)
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
let n = Math.min(...t.map((e) => e.x)), r = Math.max(...t.map((e) => e.x)), i = Math.min(...t.map((e) => e.y)), a = Math.max(...t.map((e) => e.y)), o = Math.min(...t.map((e) => e.z)), s = Math.max(...t.map((e) => e.z));
|
|
872
|
+
return {
|
|
873
|
+
width: Math.abs(r - n),
|
|
874
|
+
height: Math.max(Math.abs(a - i), Math.abs(s - o))
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
createClusterMaterials(t) {
|
|
878
|
+
let n = [], r = [
|
|
879
|
+
16711935,
|
|
880
|
+
65535,
|
|
881
|
+
16753920,
|
|
882
|
+
16738740,
|
|
883
|
+
9055202,
|
|
884
|
+
3329330,
|
|
885
|
+
"lavenderblush",
|
|
886
|
+
"lawngreen",
|
|
887
|
+
"lemonchiffon",
|
|
888
|
+
"lightblue",
|
|
889
|
+
"lightcoral"
|
|
890
|
+
];
|
|
891
|
+
for (let i = 0; i < t; i++) {
|
|
892
|
+
let t = r[i % r.length], a = new e.MeshBasicMaterial({
|
|
893
|
+
color: t,
|
|
894
|
+
transparent: !0,
|
|
895
|
+
opacity: .6,
|
|
896
|
+
side: e.DoubleSide
|
|
897
|
+
});
|
|
898
|
+
n.push(a);
|
|
899
|
+
}
|
|
900
|
+
return n;
|
|
901
|
+
}
|
|
902
|
+
clearHighlights(e) {
|
|
903
|
+
this.clusterResults && this.clusterResults.highlightedMeshes && (this.clusterResults.highlightedMeshes.forEach((t) => {
|
|
904
|
+
e.remove(t), t.material && t.material.dispose();
|
|
905
|
+
}), this.results && this.results.segmentDetails && this.results.segmentDetails.forEach((e, t) => {
|
|
906
|
+
e.mesh && e.mesh.userData.originalMaterial && (e.mesh.material = e.mesh.userData.originalMaterial);
|
|
907
|
+
}), this.clusterResults.highlightedMeshes = []);
|
|
908
|
+
}
|
|
909
|
+
getClusterInfo() {
|
|
910
|
+
return this.clusterResults ? {
|
|
911
|
+
totalClusters: this.clusterResults.totalClusters,
|
|
912
|
+
clusterSizes: this.clusterResults.clusters.map((e, t) => ({
|
|
913
|
+
clusterIndex: t,
|
|
914
|
+
size: e.length,
|
|
915
|
+
segments: e.map((e) => e.segmentKey)
|
|
916
|
+
})),
|
|
917
|
+
largestCluster: Math.max(...this.clusterResults.clusters.map((e) => e.length)),
|
|
918
|
+
smallestCluster: Math.min(...this.clusterResults.clusters.map((e) => e.length))
|
|
919
|
+
} : null;
|
|
920
|
+
}
|
|
921
|
+
restoreOriginalMaterials(e) {
|
|
922
|
+
let t = 0;
|
|
923
|
+
e.traverse((e) => {
|
|
924
|
+
e.userData && e.userData.originalMaterial && (e.material = e.userData.originalMaterial, delete e.userData.originalMaterial, t++);
|
|
925
|
+
}), console.log(`恢复了 ${t} 个平面的原始材质`);
|
|
926
|
+
}
|
|
927
|
+
createDebugHelpers(t) {
|
|
928
|
+
let n = new e.Group();
|
|
929
|
+
return t.traverse((t) => {
|
|
930
|
+
if (t.userData && t.userData.type === "wallSegment") {
|
|
931
|
+
let r = this.getWorldVertices(t);
|
|
932
|
+
if (r.length < 4) return;
|
|
933
|
+
let i = new e.Vector3().add(r[0]).add(r[1]).add(r[2]).add(r[3]).multiplyScalar(.25), a = new e.Vector3().subVectors(r[1], r[0]).normalize(), o = new e.Vector3().subVectors(r[3], r[0]).normalize(), s = new e.Vector3().crossVectors(a, o).normalize(), c = new e.ArrowHelper(s, i, .3, 16711680), l = new e.ArrowHelper(a, i, .2, 65280), u = new e.ArrowHelper(o, i, .2, 255);
|
|
934
|
+
n.add(c), n.add(l), n.add(u);
|
|
935
|
+
}
|
|
936
|
+
}), n;
|
|
937
|
+
}
|
|
938
|
+
printAnalysisResults() {
|
|
939
|
+
if (!this.results) {
|
|
940
|
+
console.warn("没有可用的分析结果");
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
this.results.missingSegments.length > 0 && this.results.missingSegments.forEach((e) => {}), this.results.pointsInSegments.forEach((e, t) => {});
|
|
944
|
+
}
|
|
945
|
+
isValidVector3(e) {
|
|
946
|
+
return e && !isNaN(e.x) && !isNaN(e.y) && !isNaN(e.z) && isFinite(e.x) && isFinite(e.y) && isFinite(e.z);
|
|
947
|
+
}
|
|
948
|
+
mergeWallGroupMeshes(t) {
|
|
949
|
+
let n = [];
|
|
950
|
+
if (t.traverse((e) => {
|
|
951
|
+
e.isMesh && e.geometry && n.push(e);
|
|
952
|
+
}), n.length === 0) return null;
|
|
953
|
+
try {
|
|
954
|
+
let t = n.map((e) => e.geometry);
|
|
955
|
+
t.forEach((e, t) => {
|
|
956
|
+
e.applyMatrix4(n[t].matrixWorld);
|
|
957
|
+
});
|
|
958
|
+
let r = c(t), i = n[0].material.clone(), a = new e.Mesh(r, i);
|
|
959
|
+
return a.name = "mergedWalls", a;
|
|
960
|
+
} catch (e) {
|
|
961
|
+
return console.error("合并网格时出错:", e), null;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}, A = (e) => {
|
|
965
|
+
let t = {}, n = [], r = [], i = [];
|
|
966
|
+
return e[0].width, e[0].height, e.forEach((e) => {
|
|
967
|
+
r.push(...e.vertices), i.push(e.center), n.push(e.vertices);
|
|
968
|
+
}), t.originalVertices = n, t.allCenterPoints = i, t;
|
|
969
|
+
}, j = (e) => {
|
|
970
|
+
let t = new s().copy(e.start).add(e.end).multiplyScalar(.5), n = new s().subVectors(new s(t.x, t.y, t.z + 1), t).normalize(), r = new s(e.direction.x, e.direction.y, 0);
|
|
971
|
+
r.applyAxisAngle(n, Math.PI / 2);
|
|
972
|
+
let i = new s().copy(t).add(r.clone().multiplyScalar(e.length)), a = new s().copy(t).sub(r.clone().multiplyScalar(e.length));
|
|
973
|
+
return t.z = e.start.z, i.z = e.start.z, a.z = e.start.z, {
|
|
974
|
+
start: i,
|
|
975
|
+
end: a,
|
|
976
|
+
center: t,
|
|
977
|
+
direction: r
|
|
978
|
+
};
|
|
979
|
+
}, M = (t, n, r = !0) => {
|
|
980
|
+
let i = [];
|
|
981
|
+
if (!t) return [];
|
|
982
|
+
for (let o = 0; o < t.length; o++) {
|
|
983
|
+
let c = t[o];
|
|
984
|
+
if (!c) continue;
|
|
985
|
+
let l = new e.Vector3(c.start.x, c.start.y, c.start.z);
|
|
986
|
+
l.applyEuler(new e.Euler(-Math.PI / 2, 0, 0));
|
|
987
|
+
let u = new e.Vector3(c.end.x, c.end.y, c.end.z);
|
|
988
|
+
if (u.applyEuler(new e.Euler(-Math.PI / 2, 0, 0)), n.add(f(String(o), new e.Vector3((l.x + u.x) / 2, (l.y + u.y) / 2, (l.z + u.z) / 2))), (c.isBayWindow || c.isWindow) && r) continue;
|
|
989
|
+
let d = new a().setFromCoplanarPoints(new s(c.start.x, c.start.y, c.start.z), new s(c.end.x, c.end.y, c.end.z), new s(c.start.x, c.start.y, c.rooftopPz)), p = [];
|
|
990
|
+
c.originalPoints.forEach((e, t) => {
|
|
991
|
+
let n = new s();
|
|
992
|
+
d.projectPoint(e, n), p.push(n);
|
|
993
|
+
});
|
|
994
|
+
let m = new s(c.start.x, c.start.y, c.start.z).distanceTo(new s(c.end.x, c.end.y, c.end.z)), h = Math.abs(c.rooftopPz - c.start.z), g = new e.MeshBasicMaterial({
|
|
995
|
+
color: "red",
|
|
996
|
+
side: e.DoubleSide,
|
|
997
|
+
wireframe: !1,
|
|
998
|
+
transparent: !0,
|
|
999
|
+
opacity: .5
|
|
1000
|
+
}), _ = new e.Group(), v = new k(), { horizontalSubdivisions: y, verticalSubdivisions: b } = v.initLimits4(m, h), x = v.createSubdividedWallPlane(c, b, y, g, _);
|
|
1001
|
+
v.analyzePointDistribution(x, p, .01);
|
|
1002
|
+
let S = new e.MeshBasicMaterial({
|
|
1003
|
+
color: "black",
|
|
1004
|
+
transparent: !0,
|
|
1005
|
+
opacity: .8,
|
|
1006
|
+
side: e.DoubleSide
|
|
1007
|
+
}), C = v.highlightEmptySegments(x, S, _), w = [];
|
|
1008
|
+
for (let e of C.clusters) {
|
|
1009
|
+
let t = A(e);
|
|
1010
|
+
t && w.push(t);
|
|
1011
|
+
}
|
|
1012
|
+
let T = j(c).direction;
|
|
1013
|
+
c.checkResults = w, c.verticalDirection = T, c.originaIndex = o, i.push(c);
|
|
1014
|
+
}
|
|
1015
|
+
return i;
|
|
1016
|
+
}, N = async (t, n, r, i) => {
|
|
1017
|
+
let a = await fetch(t);
|
|
1018
|
+
if (!a) return;
|
|
1019
|
+
let o = await a.json();
|
|
1020
|
+
for (let t = 0; t < o.length; t++) {
|
|
1021
|
+
let n = o[t];
|
|
1022
|
+
if (!n) continue;
|
|
1023
|
+
let r = new e.Vector3(n.start.x, n.start.y, n.start.z);
|
|
1024
|
+
r.applyEuler(new e.Euler(-Math.PI / 2, 0, 0));
|
|
1025
|
+
let a = new e.Vector3(n.end.x, n.end.y, n.end.z);
|
|
1026
|
+
a.applyEuler(new e.Euler(-Math.PI / 2, 0, 0)), i.add(f(String(t), new e.Vector3((r.x + a.x) / 2, (r.y + a.y) / 2, (r.z + a.z) / 2)));
|
|
1027
|
+
}
|
|
1028
|
+
o.sort((e, t) => e.originalIndex - t.originalIndex), console.log("lins", o);
|
|
1029
|
+
let s = await fetch(n);
|
|
1030
|
+
if (!s) return;
|
|
1031
|
+
let l = await s.json(), u = Array.isArray(l) ? l : Object.values(l), d = await fetch(r);
|
|
1032
|
+
if (console.log("respcd", d), !d) return;
|
|
1033
|
+
let p = await d.json();
|
|
1034
|
+
console.time(), o = await P(o, u, p, i), console.timeEnd();
|
|
1035
|
+
let m = new e.MeshBasicMaterial({
|
|
1036
|
+
color: "#cffd00",
|
|
1037
|
+
transparent: !0,
|
|
1038
|
+
opacity: .4,
|
|
1039
|
+
side: e.DoubleSide
|
|
1040
|
+
}), h = new e.MeshBasicMaterial({
|
|
1041
|
+
color: "#ff0000",
|
|
1042
|
+
transparent: !0,
|
|
1043
|
+
opacity: .4,
|
|
1044
|
+
side: e.DoubleSide
|
|
1045
|
+
});
|
|
1046
|
+
new e.LineBasicMaterial({ color: "#cffd00" });
|
|
1047
|
+
let g = new e.PointsMaterial({
|
|
1048
|
+
color: 65535,
|
|
1049
|
+
size: .01
|
|
1050
|
+
}), v = [], y = [];
|
|
1051
|
+
for (let t of o) {
|
|
1052
|
+
if (!t.originalPoints || t.originalPoints.length === 0) continue;
|
|
1053
|
+
let n = new Float32Array(t.originalPoints.length * 3);
|
|
1054
|
+
t.originalPoints.forEach((e, t) => {
|
|
1055
|
+
n[t * 3] = e.x, n[t * 3 + 1] = e.y, n[t * 3 + 2] = e.z;
|
|
1056
|
+
});
|
|
1057
|
+
let r = new e.BufferGeometry();
|
|
1058
|
+
r.setAttribute("position", new e.BufferAttribute(n, 3)), v.push(r);
|
|
1059
|
+
let i = [];
|
|
1060
|
+
i.push(new e.Vector3(t.start.x, t.start.y, t.start.z)), i.push(new e.Vector3(t.end.x, t.end.y, t.end.z));
|
|
1061
|
+
let a = new e.BufferGeometry();
|
|
1062
|
+
a.setFromPoints(i), y.push(a);
|
|
1063
|
+
}
|
|
1064
|
+
if (v.length > 0) {
|
|
1065
|
+
let t = c(v, !1);
|
|
1066
|
+
t.rotateX(-Math.PI / 2), i.add(new e.Points(t, g)), v.forEach((e) => e.dispose());
|
|
1067
|
+
}
|
|
1068
|
+
let b = [], x = [], S = new e.LineBasicMaterial({ color: "#f30606" }), C = new e.MeshBasicMaterial({ color: "#071ac4" });
|
|
1069
|
+
for (let t = 0; t < u.length; t++) {
|
|
1070
|
+
let n = new e.SphereGeometry(.05);
|
|
1071
|
+
n.translate(u[t].x, u[t].y, u[t].z);
|
|
1072
|
+
let r = [], i = new e.Vector3(u[t].x, u[t].y, u[t].z), a = new e.Quaternion(u[t].qx, u[t].qy, u[t].qz, u[t].qw), o = new e.Vector3(0, 0, -1).applyQuaternion(a), s = i.clone().addScaledVector(o, .001);
|
|
1073
|
+
r.push(i), r.push(s);
|
|
1074
|
+
let c = new e.BufferGeometry();
|
|
1075
|
+
c.setFromPoints(r), x.push(c), b.push(n);
|
|
1076
|
+
}
|
|
1077
|
+
if (b.length > 0) {
|
|
1078
|
+
let t = c(b, !1);
|
|
1079
|
+
t.rotateX(-Math.PI / 2), i.add(new e.Mesh(t, C)), b.forEach((e) => e.dispose());
|
|
1080
|
+
}
|
|
1081
|
+
if (x.length > 0) {
|
|
1082
|
+
let t = c(x, !1);
|
|
1083
|
+
t.rotateX(-Math.PI / 2), i.add(new e.Line(t, S)), x.forEach((e) => e.dispose());
|
|
1084
|
+
}
|
|
1085
|
+
let w = _(p);
|
|
1086
|
+
w.rotateX(-Math.PI / 2), i.add(w), console.log("jsonpcdData", p), o.forEach((t) => {
|
|
1087
|
+
if (t.doorAndBeamData && t.doorAndBeamData.length > 0) {
|
|
1088
|
+
let n = new e.Group();
|
|
1089
|
+
t.doorAndBeamData.forEach((t) => {
|
|
1090
|
+
if (t.beamStart) {
|
|
1091
|
+
let r = new e.BufferGeometry(), i = new Float32Array([
|
|
1092
|
+
t.beamStart.x,
|
|
1093
|
+
t.beamStart.y,
|
|
1094
|
+
t.beamStart.z,
|
|
1095
|
+
t.beamEnd.x,
|
|
1096
|
+
t.beamEnd.y,
|
|
1097
|
+
t.beamEnd.z,
|
|
1098
|
+
t.beamEnd.x,
|
|
1099
|
+
t.beamEnd.y,
|
|
1100
|
+
t.beamEnd.z + t.beamHeight,
|
|
1101
|
+
t.beamStart.x,
|
|
1102
|
+
t.beamStart.y,
|
|
1103
|
+
t.beamStart.z + t.beamHeight
|
|
1104
|
+
]);
|
|
1105
|
+
r.setAttribute("position", new e.BufferAttribute(i, 3)), r.setIndex([
|
|
1106
|
+
0,
|
|
1107
|
+
1,
|
|
1108
|
+
2,
|
|
1109
|
+
0,
|
|
1110
|
+
2,
|
|
1111
|
+
3
|
|
1112
|
+
]), r.computeVertexNormals(), r.rotateX(-Math.PI / 2), n.add(new e.Mesh(r, m));
|
|
1113
|
+
}
|
|
1114
|
+
let r = new e.BufferGeometry(), i = new Float32Array([
|
|
1115
|
+
t.doorStart.x,
|
|
1116
|
+
t.doorStart.y,
|
|
1117
|
+
t.doorStart.z,
|
|
1118
|
+
t.doorEnd.x,
|
|
1119
|
+
t.doorEnd.y,
|
|
1120
|
+
t.doorEnd.z,
|
|
1121
|
+
t.doorEnd.x,
|
|
1122
|
+
t.doorEnd.y,
|
|
1123
|
+
t.doorEnd.z + t.doorHeight,
|
|
1124
|
+
t.doorStart.x,
|
|
1125
|
+
t.doorStart.y,
|
|
1126
|
+
t.doorStart.z + t.doorHeight
|
|
1127
|
+
]);
|
|
1128
|
+
r.setAttribute("position", new e.BufferAttribute(i, 3)), r.setIndex([
|
|
1129
|
+
0,
|
|
1130
|
+
1,
|
|
1131
|
+
2,
|
|
1132
|
+
0,
|
|
1133
|
+
2,
|
|
1134
|
+
3
|
|
1135
|
+
]), r.computeVertexNormals(), r.rotateX(-Math.PI / 2), n.add(new e.Mesh(r, h));
|
|
1136
|
+
let a = `id:${t.id},Nid:${t.nearId}`, o = new e.Vector3((t.doorStart.x + t.doorEnd.x) / 2, (t.doorStart.y + t.doorEnd.y) / 2, t.doorStart.z + t.doorHeight);
|
|
1137
|
+
o.applyEuler(new e.Euler(-Math.PI / 2, 0, 0)), n.add(f(a, o));
|
|
1138
|
+
}), i.add(n);
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}, P = async (t, n, r) => {
|
|
1142
|
+
if (t.length <= 0 || n.length <= 0) return t;
|
|
1143
|
+
r ||= [];
|
|
1144
|
+
for (let n of t) {
|
|
1145
|
+
let t = [];
|
|
1146
|
+
if (!(!n.checkResults || n.checkResults.length <= 0)) {
|
|
1147
|
+
for (let r = 0; r < n.checkResults.length; r++) {
|
|
1148
|
+
let i = n.checkResults[r];
|
|
1149
|
+
if (i.isDoor = !1, !i.originalVertices || i.originalVertices.length == 0) continue;
|
|
1150
|
+
let a = [];
|
|
1151
|
+
i.originalVertices.forEach((t) => {
|
|
1152
|
+
let n = [];
|
|
1153
|
+
t.forEach((t) => {
|
|
1154
|
+
n.push(new e.Vector3(t.x, t.y, t.z));
|
|
1155
|
+
}), a.push(n);
|
|
1156
|
+
});
|
|
1157
|
+
let o = a.length, s = Array.from({ length: o }, (e, t) => t);
|
|
1158
|
+
function c(e) {
|
|
1159
|
+
for (; s[e] !== e;) s[e] = s[s[e]], e = s[e];
|
|
1160
|
+
return e;
|
|
1161
|
+
}
|
|
1162
|
+
for (let e = 0; e < o; e++) for (let t = e + 1; t < o; t++) {
|
|
1163
|
+
let n = a[e], r = a[t];
|
|
1164
|
+
if (n.some((e) => r.some((t) => e.equals(t)))) {
|
|
1165
|
+
let n = c(e), r = c(t);
|
|
1166
|
+
n !== r && (s[n] = r);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
let l = /* @__PURE__ */ new Map(), u = -1, d = -1;
|
|
1170
|
+
for (let t = 0; t < o; t++) {
|
|
1171
|
+
let n = c(t);
|
|
1172
|
+
l.has(n) || l.set(n, {
|
|
1173
|
+
points: [],
|
|
1174
|
+
area: 0,
|
|
1175
|
+
originalVertices: [],
|
|
1176
|
+
index: -1,
|
|
1177
|
+
gridWidth: -1,
|
|
1178
|
+
gridHeight: -1,
|
|
1179
|
+
centerPts: []
|
|
1180
|
+
});
|
|
1181
|
+
let i = l.get(n), [o, s, f, p] = a[t], h = new e.Vector3().add(o).add(s).add(f).add(p).multiplyScalar(.25);
|
|
1182
|
+
if (i.points.push(...a[t]), i.area += o.distanceTo(s) * o.distanceTo(p), i.originalVertices.push(a[t]), i.index = r, i.centerPts.push(h), u == -1 || d == -1) {
|
|
1183
|
+
let t = new e.Vector3().subVectors(o, s).normalize();
|
|
1184
|
+
d = o.distanceTo(p), u = o.distanceTo(s);
|
|
1185
|
+
let n = m(t, new e.Vector3(0, 0, 1));
|
|
1186
|
+
n && n.parallel && ([d, u] = [u, d]);
|
|
1187
|
+
}
|
|
1188
|
+
i.gridWidth = u, i.gridHeight = d;
|
|
1189
|
+
}
|
|
1190
|
+
t.push(...l.values());
|
|
1191
|
+
}
|
|
1192
|
+
n.mergeCheckRegion = t;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
let i = /* @__PURE__ */ new Map();
|
|
1196
|
+
for (let e of t) {
|
|
1197
|
+
let t = e.rooftopPz - e.start.z, n = Math.floor(e.rooftopPz - e.start.z);
|
|
1198
|
+
i.has(n) ? i.set(n, {
|
|
1199
|
+
num: i.get(n).num + 1,
|
|
1200
|
+
totalHeight: i.get(n).totalHeight + t
|
|
1201
|
+
}) : i.set(n, {
|
|
1202
|
+
num: 1,
|
|
1203
|
+
totalHeight: t
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
let a = [...i.entries()].reduce((e, t) => t[1].num > e[1].num ? t : e), o = a[0];
|
|
1207
|
+
a[1].totalHeight / a[1].num;
|
|
1208
|
+
let s = [];
|
|
1209
|
+
for (let t = 0; t < r.length; t++) {
|
|
1210
|
+
let n = r[t];
|
|
1211
|
+
if (n.isFindBeam = !1, n.category == "door") {
|
|
1212
|
+
let r = [];
|
|
1213
|
+
n.coordinatesByArea.coordinates.forEach((t) => {
|
|
1214
|
+
r.push(new e.Vector3(t.x, t.y, t.z));
|
|
1215
|
+
}), r[0].equals(r[r.length - 1]) && r.pop();
|
|
1216
|
+
let i = r[0].distanceTo(r[1]), a = r[0].distanceTo(r[3]);
|
|
1217
|
+
if (a > i && ([i, a] = [a, i], r = [
|
|
1218
|
+
r[0],
|
|
1219
|
+
r[3],
|
|
1220
|
+
r[2],
|
|
1221
|
+
r[1]
|
|
1222
|
+
]), i < .5) continue;
|
|
1223
|
+
let o = x(r[0], r[3], !0), c = x(r[1], r[2], !0);
|
|
1224
|
+
s.push({
|
|
1225
|
+
doorStartPt: o,
|
|
1226
|
+
doorEndPt: c,
|
|
1227
|
+
boxPoints: r,
|
|
1228
|
+
minZ: n.coordinatesByArea.heightData.minZ,
|
|
1229
|
+
maxZ: n.coordinatesByArea.heightData.maxZ,
|
|
1230
|
+
index: t,
|
|
1231
|
+
isFind: !1
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
for (let n = 0; n < s.length; n++) {
|
|
1236
|
+
let r = s[n];
|
|
1237
|
+
for (let n = 0; n < t.length; n++) {
|
|
1238
|
+
if (t[n].length < .8) continue;
|
|
1239
|
+
let i = [], a = x(t[n].start, t[n].end, !0);
|
|
1240
|
+
i.push(a), i.push(x(a, t[n].start, !0)), i.push(x(a, t[n].end, !0));
|
|
1241
|
+
let o = !1, s = r.boxPoints.length;
|
|
1242
|
+
for (let e = 0; e < i.length; e++) {
|
|
1243
|
+
let t = i[e].x, n = i[e].y;
|
|
1244
|
+
for (let e = 0, i = s - 1; e < s; i = e++) {
|
|
1245
|
+
let a = r.boxPoints[e].x, s = r.boxPoints[e].y, c = r.boxPoints[i].x, l = r.boxPoints[i].y;
|
|
1246
|
+
s > n != l > n && t < (c - a) * (n - s) / (l - s) + a && (o = !o);
|
|
1247
|
+
}
|
|
1248
|
+
if (o) break;
|
|
1249
|
+
}
|
|
1250
|
+
if (o) {
|
|
1251
|
+
let i = new e.Vector3(t[n].start.x, t[n].start.y, 0), a = new e.Vector3(t[n].end.x, t[n].end.y, 0), o = r.doorStartPt.distanceTo(r.doorEndPt), s = i.distanceTo(a), c = y(r.doorStartPt, r.doorEndPt, i, a);
|
|
1252
|
+
if (Math.abs(s - o) < .5 && c && c.isParallel) {
|
|
1253
|
+
r.doorStartPt = new e.Vector3(t[n].start.x, t[n].start.y, 0), r.doorEndPt = new e.Vector3(t[n].end.x, t[n].end.y, 0);
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1256
|
+
} else continue;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
let c = 0, l = [];
|
|
1260
|
+
for (let i = 0; i < t.length; i++) {
|
|
1261
|
+
let a = t[i];
|
|
1262
|
+
if (!a.mergeCheckRegion || a.mergeCheckRegion.length == 0) continue;
|
|
1263
|
+
a.doorAndBeamData = [], a.completePointAreaPercentage = -1;
|
|
1264
|
+
let u = new e.Box3();
|
|
1265
|
+
u.setFromPoints(a.originalPoints);
|
|
1266
|
+
let f = u.max.z, p = u.min.z, m = a.rooftopPz - a.start.z;
|
|
1267
|
+
if (m < o - .5 || m > o + 2) continue;
|
|
1268
|
+
let h = 0;
|
|
1269
|
+
for (let o of a.mergeCheckRegion) {
|
|
1270
|
+
let { facePoints: u, boxArea: g } = v(o.points, o.gridWidth, o.gridHeight, o.centerPts);
|
|
1271
|
+
if (!(!u || u.length <= 0) && (h += o.area, o.area / g * 100 > 60)) {
|
|
1272
|
+
let h = u[0].distanceTo(u[1]), g = h / a.length * 100, _ = u[0].distanceTo(u[3]), v = a.rooftopPz - u[2].z, b = p > a.start.z - .15 && a.length < 1.5 || a.length > 1.5;
|
|
1273
|
+
if (_ < .5 || !b || f < u[2].z || v > m / 2) continue;
|
|
1274
|
+
let C = !1, w = !1, T = !1, E = -1, D = u[2].clone(), O = u[3].clone(), k = u[0].clone(), A = u[1].clone();
|
|
1275
|
+
if (Math.abs(u[0].z - a.start.z) < .1 && (g < 85 && h > .4 || h > .7 && _ > m - m / 3)) {
|
|
1276
|
+
let t = !1;
|
|
1277
|
+
for (let r = 0; r < n.length; r++) {
|
|
1278
|
+
let i = r + 1;
|
|
1279
|
+
if (i >= n.length) continue;
|
|
1280
|
+
let a = new e.Vector3(n[r].x, n[r].y, n[r].z), o = new e.Vector3(n[i].x, n[i].y, n[i].z);
|
|
1281
|
+
if (d(new e.Vector3(a.x, a.y, 0), new e.Vector3(o.x, o.y, 0), new e.Vector3(u[0].x, u[0].y, 0), new e.Vector3(u[1].x, u[1].y, 0), .1) != null) {
|
|
1282
|
+
t = !0;
|
|
1283
|
+
break;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
for (let t = 0; t < s.length; t++) {
|
|
1287
|
+
let n = new e.Vector3(s[t].doorStartPt.x, s[t].doorStartPt.y, 0), i = new e.Vector3(s[t].doorEndPt.x, s[t].doorEndPt.y, 0), o = new e.Vector3(u[0].x, u[0].y, 0), c = new e.Vector3(u[1].x, u[1].y, 0), l = new e.Vector3().subVectors(n, i).normalize(), f = new e.Vector3().subVectors(o, c).normalize(), p = .2, m = d(n.clone().addScaledVector(l, p), i.clone().addScaledVector(l.clone().negate(), p), o.clone().addScaledVector(f, p), c.clone().addScaledVector(f.clone().negate(), p)), h = u[2].z < s[t].maxZ || Math.abs(u[2].z - s[t].maxZ) < .3, g = y(n.clone(), i.clone(), o.clone(), c.clone());
|
|
1288
|
+
if (m && h) r[s[t].index].isFindBeam = !0, w = !0, s[t].isFind = !0;
|
|
1289
|
+
else if (h && g && g.isParallel) {
|
|
1290
|
+
let o = x(n, i), c = new e.Line3(new e.Vector3(a.start.x, a.start.y, 0), new e.Vector3(a.end.x, a.end.y, 0)), l = new e.Vector3(), u = c.closestPointToPoint(o, !0, l);
|
|
1291
|
+
o.distanceTo(u) < .3 && (r[s[t].index].isFindBeam = !0);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
if (!w) for (let t = 0; t < s.length; t++) {
|
|
1295
|
+
let n = new e.Vector3(s[t].doorStartPt.x, s[t].doorStartPt.y, 0), i = new e.Vector3(s[t].doorEndPt.x, s[t].doorEndPt.y, 0), o = new e.Vector3(u[0].x, u[0].y, 0), l = new e.Vector3(u[1].x, u[1].y, 0), d = u[2].z < s[t].maxZ || Math.abs(u[2].z - s[t].maxZ) < .3, f = Math.abs(u[2].z - s[t].maxZ) > .2;
|
|
1296
|
+
if (d && !f) {
|
|
1297
|
+
let d = S(n.clone(), i.clone(), o.clone(), l.clone(), { distanceThreshold: 2 });
|
|
1298
|
+
if (c == 4 && console.log(s[t], d), d && d.type == "collinear_gap") {
|
|
1299
|
+
let c = x(n, i), f = new e.Line3(new e.Vector3(a.start.x, a.start.y, 0), new e.Vector3(a.end.x, a.end.y, 0)), p = new e.Vector3(), m = f.closestPointToPoint(c, !0, p);
|
|
1300
|
+
if (c.distanceTo(m) < .15) {
|
|
1301
|
+
let a = o.distanceTo(n), c = l.distanceTo(n);
|
|
1302
|
+
if (a > .25 && c > .25) {
|
|
1303
|
+
let e = o.distanceTo(i), t = l.distanceTo(i);
|
|
1304
|
+
if (e > .2 && t > .2) continue;
|
|
1305
|
+
}
|
|
1306
|
+
w = !0, T = !0, E = s[t].index, s[t].isFind = !0, r[s[t].index].isFindBeam = !0;
|
|
1307
|
+
let f = new e.Vector3().subVectors(o, l).normalize(), p = n.distanceTo(i) - d.overlap;
|
|
1308
|
+
c < a && f.negate(), a > c ? (D = u[2].clone().addScaledVector(f, p), O = u[3].clone(), k = D.clone(), A = O.clone(), k.z = A.z = u[0].z) : (D = u[2].clone(), O = u[3].clone().addScaledVector(f, p), k = D.clone(), A = O.clone(), k.z = A.z = u[0].z);
|
|
1309
|
+
}
|
|
1310
|
+
} else if (d && d.type == "collinear_overlap") {
|
|
1311
|
+
let e = o.distanceTo(l), a = i.distanceTo(n);
|
|
1312
|
+
(Math.abs(e - d.overlap) < .25 || Math.abs(a - d.overlap) < .25) && (w = !0, T = !0, E = s[t].index, s[t].isFind = !0, r[s[t].index].isFindBeam = !0);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
(w || t || _ > m / 2 && h > .8 && Math.abs(p - a.start.z) < .4) && (C = !0);
|
|
1317
|
+
}
|
|
1318
|
+
if (C) {
|
|
1319
|
+
a.checkResults[o.index].isDoor = !0;
|
|
1320
|
+
let n = {
|
|
1321
|
+
id: c,
|
|
1322
|
+
beamStart: D,
|
|
1323
|
+
beamEnd: O,
|
|
1324
|
+
beamHeight: a.rooftopPz - u[2].z,
|
|
1325
|
+
doorStart: k,
|
|
1326
|
+
doorEnd: A,
|
|
1327
|
+
doorHeight: _,
|
|
1328
|
+
nearId: -1,
|
|
1329
|
+
type: "doorBeam",
|
|
1330
|
+
isDoor: w,
|
|
1331
|
+
isPullOutDoor: T,
|
|
1332
|
+
pcbDoorIndex: E
|
|
1333
|
+
};
|
|
1334
|
+
for (let r = 0; r < l.length; r++) {
|
|
1335
|
+
let i = t[l[r].linesIndex].doorAndBeamData[l[r].doorIndex];
|
|
1336
|
+
if (i.nearId != -1) continue;
|
|
1337
|
+
let a = y(D.clone(), O.clone(), i.beamStart.clone(), i.beamEnd.clone());
|
|
1338
|
+
if (a && a.isParallel) {
|
|
1339
|
+
let t = D.distanceTo(O), r = i.beamStart.distanceTo(i.beamEnd), a = new e.Line3(D.clone(), O.clone());
|
|
1340
|
+
a.start.z = 0, a.end.z = 0;
|
|
1341
|
+
let o = x(i.beamStart, i.beamEnd, !0);
|
|
1342
|
+
r > t && (a.start = new e.Vector3(i.beamStart.x, i.beamStart.y, 0), a.end = new e.Vector3(i.beamEnd.x, i.beamEnd.y, 0), o = x(D, O, !0));
|
|
1343
|
+
let s = new e.Vector3(), l = a.closestPointToPoint(o, !0, s), u = l.distanceTo(o), f = new e.Vector3().subVectors(o, l).normalize(), p = f.clone().negate(), m = o.clone().addScaledVector(p, u + .1), h = d(a.start, a.end, o, m);
|
|
1344
|
+
if (u < .5 && h != null) {
|
|
1345
|
+
i.nearId = c, n.nearId = i.id;
|
|
1346
|
+
let e = .8;
|
|
1347
|
+
(i.isDoor || n.isDoor) && (i.isDoor = !0, n.isDoor = !0), t < r ? t > e && !i.isPullOutDoor ? (i.beamStart = D.clone().addScaledVector(p, u), i.beamEnd = O.clone().addScaledVector(p, u), i.doorStart = k.clone().addScaledVector(p, u), i.doorEnd = A.clone().addScaledVector(p, u), i.doorHeight = n.doorHeight, i.beamStart.z = i.beamEnd.z = i.doorStart.z + i.doorHeight) : !T || T && i.isPullOutDoor && E == i.pcbDoorIndex ? (n.beamStart = i.beamStart.clone().addScaledVector(f, u), n.beamEnd = i.beamEnd.clone().addScaledVector(f, u), n.doorStart = i.doorStart.clone().addScaledVector(f, u), n.doorEnd = i.doorEnd.clone().addScaledVector(f, u), n.doorHeight = i.doorHeight, n.beamStart.z = n.beamEnd.z = n.doorStart.z + n.doorHeight) : (i.beamStart = D.clone().addScaledVector(p, u), i.beamEnd = O.clone().addScaledVector(p, u), i.doorStart = k.clone().addScaledVector(p, u), i.doorEnd = A.clone().addScaledVector(p, u), i.doorHeight = n.doorHeight, i.beamStart.z = i.beamEnd.z = i.doorStart.z + i.doorHeight) : t > r && (r > e && !T ? (n.beamStart = i.beamStart.clone().addScaledVector(p, u), n.beamEnd = i.beamEnd.clone().addScaledVector(p, u), n.doorStart = i.doorStart.clone().addScaledVector(p, u), n.doorEnd = i.doorEnd.clone().addScaledVector(p, u), n.doorHeight = i.doorHeight, n.beamStart.z = n.beamEnd.z = n.doorStart.z + n.doorHeight) : !i.isPullOutDoor || T && i.isPullOutDoor && E == i.pcbDoorIndex ? (i.beamStart = D.clone().addScaledVector(f, u), i.beamEnd = O.clone().addScaledVector(f, u), i.doorStart = k.clone().addScaledVector(f, u), i.doorEnd = A.clone().addScaledVector(f, u), i.doorHeight = n.doorHeight, i.beamStart.z = i.beamEnd.z = i.doorStart.z + i.doorHeight) : (n.beamStart = i.beamStart.clone().addScaledVector(p, u), n.beamEnd = i.beamEnd.clone().addScaledVector(p, u), n.doorStart = i.doorStart.clone().addScaledVector(p, u), n.doorEnd = i.doorEnd.clone().addScaledVector(p, u), n.doorHeight = i.doorHeight, n.beamStart.z = n.beamEnd.z = n.doorStart.z + n.doorHeight));
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
a.doorAndBeamData.push(n), l.push({
|
|
1353
|
+
linesIndex: i,
|
|
1354
|
+
doorIndex: a.doorAndBeamData.length - 1
|
|
1355
|
+
}), c++;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
let g = a.length * (a.rooftopPz - a.start.z);
|
|
1360
|
+
a.completePointAreaPercentage = h / g * 100;
|
|
1361
|
+
}
|
|
1362
|
+
let u = .65, f = [], p = [], h = .2;
|
|
1363
|
+
for (let n = 0; n < s.length; n++) {
|
|
1364
|
+
if (s[n].isFind) continue;
|
|
1365
|
+
let i = new e.Vector3(s[n].doorStartPt.x, s[n].doorStartPt.y, 0), a = new e.Vector3(s[n].doorEndPt.x, s[n].doorEndPt.y, 0), o = new e.Vector3().subVectors(i, a).normalize();
|
|
1366
|
+
for (let l = 0; l < t.length; l++) {
|
|
1367
|
+
if (t[l].length < 1 || t[l].completePointAreaPercentage > 60) continue;
|
|
1368
|
+
let m = new e.Vector3(t[l].start.x, t[l].start.y, 0), g = new e.Vector3(t[l].end.x, t[l].end.y, 0), _ = new e.Vector3().subVectors(m, g).normalize(), v = .3, x = i.clone().addScaledVector(o, v), C = a.clone().addScaledVector(o.clone().negate(), v), w = m.clone().addScaledVector(_, v), T = g.clone().addScaledVector(_.clone().negate(), v);
|
|
1369
|
+
d(x, C, w, T);
|
|
1370
|
+
let E = y(x, C, w, T), D = i.distanceTo(m) > a.distanceTo(m) ? a : i, O = D.distanceTo(m), k = D.distanceTo(g);
|
|
1371
|
+
if ((O < h || k < h) && E && !E.isParallel) {
|
|
1372
|
+
let a = i.distanceTo(m) < i.distanceTo(g) ? m : g, o = !1;
|
|
1373
|
+
for (let i = 0; i < t.length; i++) {
|
|
1374
|
+
if (i == l || f.includes(i) || t[i].length < 1) continue;
|
|
1375
|
+
let d = new e.Vector3(t[i].start.x, t[i].start.y, 0), h = new e.Vector3(t[i].end.x, t[i].end.y, 0), _ = b(m, g, d, h);
|
|
1376
|
+
if (_ && _.angle > 85) {
|
|
1377
|
+
let _ = new e.Line3(m, g), v = new e.Vector3(), b = _.closestPointToPoint(d, !0, v), x = _.closestPointToPoint(h, !0, v), C = b.distanceTo(d), w = x.distanceTo(h), T, E;
|
|
1378
|
+
if (C > w && w > u) T = h, E = x;
|
|
1379
|
+
else if (C < w && C > u) T = d, E = b;
|
|
1380
|
+
else continue;
|
|
1381
|
+
if (C = a.distanceTo(d), w = a.distanceTo(h), C > 2 && w > 2) continue;
|
|
1382
|
+
let D = y(T, E, d, h);
|
|
1383
|
+
if (!D || !D.isParallel) continue;
|
|
1384
|
+
T.z = E.z = t[i].start.z;
|
|
1385
|
+
let O = !1;
|
|
1386
|
+
for (let e = 0; e < p.length; e++) {
|
|
1387
|
+
let t = S(p[e].start, p[e].end, T, E);
|
|
1388
|
+
if (t && t.type == "collinear_overlap") {
|
|
1389
|
+
O = !0;
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (O) continue;
|
|
1394
|
+
p.push({
|
|
1395
|
+
start: T,
|
|
1396
|
+
end: E
|
|
1397
|
+
}), f.push(i);
|
|
1398
|
+
let k = t[i].rooftopPz - t[i].start.z, A = t[l].rooftopPz - t[l].start.z, j = k < A ? k : A;
|
|
1399
|
+
t[i].doorAndBeamData.push({
|
|
1400
|
+
id: c,
|
|
1401
|
+
doorStart: T,
|
|
1402
|
+
doorEnd: E,
|
|
1403
|
+
doorHeight: j,
|
|
1404
|
+
nearId: -1,
|
|
1405
|
+
type: "onlyDoor",
|
|
1406
|
+
isDoor: !0
|
|
1407
|
+
}), r[s[n].index].isFindBeam = !0, r[s[n].index].isFindOnlyDoor = !0, c++, o = !0;
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
if (o) break;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
let g = 0;
|
|
1416
|
+
for (let n = 0; n < t.length; n++) {
|
|
1417
|
+
let r = t[n];
|
|
1418
|
+
r.mainBeamDataIds ||= [], r.isMainBeam ||= !1;
|
|
1419
|
+
let { minZ: i, maxZ: a } = D(r);
|
|
1420
|
+
if (i == null || a == null) continue;
|
|
1421
|
+
a - i;
|
|
1422
|
+
let s = r.rooftopPz - r.start.z;
|
|
1423
|
+
if (s < o - .5 || s > o + 2 || Math.abs(i - r.start.z) > .3 || r.length < 1) continue;
|
|
1424
|
+
let c = new e.Vector3(r.start.x, r.start.y, 0), l = new e.Vector3(r.end.x, r.end.y, 0);
|
|
1425
|
+
for (let i = 0; i < t.length; i++) {
|
|
1426
|
+
if (i == n || t[i].length < 1) continue;
|
|
1427
|
+
let o = t[i], s = new e.Vector3(o.start.x, o.start.y, 0), u = new e.Vector3(o.end.x, o.end.y, 0), d = y(c, l, s, u), f = x(c, l), p = new e.Line3(s, u).closestPointToPoint(f, !0, new e.Vector3()), m = f.distanceTo(p), h = D(o);
|
|
1428
|
+
if (!(h.minZ === void 0 || h.maxZ === void 0) && !(h.maxZ - h.minZ > 1) && d && d.isParallel && m < .25 && Math.abs(a - h.minZ) < .1) {
|
|
1429
|
+
let e = `mainBeamId${g}`;
|
|
1430
|
+
o.mainBeamDataIds ||= [], o.isMainBeam ||= !0, o.mainBeamDataIds.push(e), r.mainBeamDataIds.push(e), g++;
|
|
1431
|
+
break;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
return t;
|
|
1436
|
+
}, F = (t, n) => {
|
|
1437
|
+
if (t.length <= 0) return t;
|
|
1438
|
+
for (let n of t) {
|
|
1439
|
+
let t = [];
|
|
1440
|
+
for (let r = 0; r < n.checkResults.length; r++) {
|
|
1441
|
+
let i = n.checkResults[r];
|
|
1442
|
+
if (i.isDoor = !1, !i.originalVertices || i.originalVertices.length == 0) continue;
|
|
1443
|
+
let a = [];
|
|
1444
|
+
i.originalVertices.forEach((t) => {
|
|
1445
|
+
let n = [];
|
|
1446
|
+
t.forEach((t) => {
|
|
1447
|
+
n.push(new e.Vector3(t.x, t.y, t.z));
|
|
1448
|
+
}), a.push(n);
|
|
1449
|
+
});
|
|
1450
|
+
let o = a.length, s = Array.from({ length: o }, (e, t) => t);
|
|
1451
|
+
function c(e) {
|
|
1452
|
+
for (; s[e] !== e;) s[e] = s[s[e]], e = s[e];
|
|
1453
|
+
return e;
|
|
1454
|
+
}
|
|
1455
|
+
for (let e = 0; e < o; e++) for (let t = e + 1; t < o; t++) {
|
|
1456
|
+
let n = a[e], r = a[t];
|
|
1457
|
+
if (n.some((e) => r.some((t) => e.equals(t)))) {
|
|
1458
|
+
let n = c(e), r = c(t);
|
|
1459
|
+
n !== r && (s[n] = r);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
let l = /* @__PURE__ */ new Map(), u = -1, d = -1;
|
|
1463
|
+
for (let t = 0; t < o; t++) {
|
|
1464
|
+
let n = c(t);
|
|
1465
|
+
l.has(n) || l.set(n, {
|
|
1466
|
+
points: [],
|
|
1467
|
+
area: 0,
|
|
1468
|
+
originalVertices: [],
|
|
1469
|
+
index: -1,
|
|
1470
|
+
gridWidth: -1,
|
|
1471
|
+
gridHeight: -1,
|
|
1472
|
+
centerPts: []
|
|
1473
|
+
});
|
|
1474
|
+
let i = l.get(n), [o, s, f, p] = a[t], h = new e.Vector3().add(o).add(s).add(f).add(p).multiplyScalar(.25);
|
|
1475
|
+
if (i.points.push(...a[t]), i.area += o.distanceTo(s) * o.distanceTo(p), i.originalVertices.push(a[t]), i.index = r, i.centerPts.push(h), u == -1 || d == -1) {
|
|
1476
|
+
let t = new e.Vector3().subVectors(o, s).normalize();
|
|
1477
|
+
d = o.distanceTo(p), u = o.distanceTo(s);
|
|
1478
|
+
let n = m(t, new e.Vector3(0, 0, 1));
|
|
1479
|
+
n && n.parallel && ([d, u] = [u, d]);
|
|
1480
|
+
}
|
|
1481
|
+
i.gridWidth = u, i.gridHeight = d;
|
|
1482
|
+
}
|
|
1483
|
+
t.push(...l.values());
|
|
1484
|
+
}
|
|
1485
|
+
n.mergeCheckRegion = t;
|
|
1486
|
+
}
|
|
1487
|
+
let r = /* @__PURE__ */ new Map();
|
|
1488
|
+
for (let e of t) {
|
|
1489
|
+
let t = e.rooftopPz - e.start.z, n = Math.floor(e.rooftopPz - e.start.z);
|
|
1490
|
+
r.has(n) ? r.set(n, {
|
|
1491
|
+
num: r.get(n).num + 1,
|
|
1492
|
+
totalHeight: r.get(n).totalHeight + t
|
|
1493
|
+
}) : r.set(n, {
|
|
1494
|
+
num: 1,
|
|
1495
|
+
totalHeight: t
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
let i = [...r.entries()].reduce((e, t) => t[1].num > e[1].num ? t : e), a = i[0];
|
|
1499
|
+
i[1].totalHeight / i[1].num, new e.MeshBasicMaterial({
|
|
1500
|
+
color: "#cffd00",
|
|
1501
|
+
transparent: !0,
|
|
1502
|
+
opacity: .4,
|
|
1503
|
+
side: e.DoubleSide
|
|
1504
|
+
}), new e.PointsMaterial({
|
|
1505
|
+
color: 65535,
|
|
1506
|
+
size: .01
|
|
1507
|
+
});
|
|
1508
|
+
for (let r = 0; r < t.length; r++) {
|
|
1509
|
+
let i = t[r], { minZ: o, maxZ: s } = D(i);
|
|
1510
|
+
if (o == null || s == null) continue;
|
|
1511
|
+
i.doorAndBeamData = [], i.completePointAreaPercentage = -1, s - o;
|
|
1512
|
+
let c = i.rooftopPz - i.start.z;
|
|
1513
|
+
if (c < a - .5 || c > a + 2 || Math.abs(o - i.start.z) > .3 || i.length < 1) continue;
|
|
1514
|
+
let l = new e.Vector3(i.start.x, i.start.y, 0), u = new e.Vector3(i.end.x, i.end.y, 0);
|
|
1515
|
+
for (let i = 0; i < t.length; i++) {
|
|
1516
|
+
if (i == r || t[i].length < 1) continue;
|
|
1517
|
+
let a = t[i], o = new e.Vector3(a.start.x, a.start.y, 0), c = new e.Vector3(a.end.x, a.end.y, 0), d = y(l, u, o, c), p = x(l, u), m = new e.Line3(o, c).closestPointToPoint(p, !0, new e.Vector3()), h = p.distanceTo(m), g = D(a);
|
|
1518
|
+
if (!(g.minZ === void 0 || g.maxZ === void 0) && !(g.maxZ - g.minZ > 1) && d && d.isParallel && h < .25 && Math.abs(s - g.minZ) < .1) {
|
|
1519
|
+
let a = x(l, u), s = x(o, c);
|
|
1520
|
+
a.z = s.z = 1, a.applyEuler(new e.Euler(-Math.PI / 2, 0, 0)), s.applyEuler(new e.Euler(-Math.PI / 2, 0, 0));
|
|
1521
|
+
let d = `w:${t[r].originaIndex},b:${t[i].originaIndex}`, p = `b:${t[i].originaIndex},w:${t[r].originaIndex}`;
|
|
1522
|
+
n.add(f(d, a, { textColor: "#fd0000" })), n.add(f(p, s, { textColor: "#fd0000" }));
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
return t;
|
|
1527
|
+
};
|
|
1528
|
+
//#endregion
|
|
1529
|
+
export { S as classifySegments, M as getAllGeometry, P as getBeamLine, F as getMainBeamLine, y as getParallelism, D as getPointCloudMinMax, T as getPointCoverageOnQuad, m as isParallel, b as perpendicularInfo, O as removeNoisePoints, d as segmentsIntersect2D, N as usegetBeamLine };
|