build-dxf 0.1.8 → 0.1.9

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/src/index.css CHANGED
@@ -806,7 +806,7 @@
806
806
  inherits: false
807
807
  }
808
808
 
809
- [data-v-436c0aab] {
809
+ [data-v-8028c98c] {
810
810
  font-family: 宋体;
811
811
  }
812
812
 
package/src/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import "three";
2
- import { l, D, m, i, o, g, j, k, h, n } from "./build.js";
2
+ import { k, D, l, h, n, f, i, j, g, m } from "./build.js";
3
3
  import "clipper-lib";
4
4
  export {
5
- l as Dxf,
5
+ k as Dxf,
6
6
  D as DxfSystem,
7
- m as ModelDataPlugin,
8
- i as buildJson,
9
- o as components,
10
- g as createEditor,
11
- j as getFileAll,
12
- k as getGlobalDxfSystem,
13
- h as getModels,
14
- n as utils
7
+ l as ModelDataPlugin,
8
+ h as buildJson,
9
+ n as components,
10
+ f as createEditor,
11
+ i as getFileAll,
12
+ j as getGlobalDxfSystem,
13
+ g as getModels,
14
+ m as utils
15
15
  };
package/src/index2.js CHANGED
@@ -1,344 +1,10 @@
1
- import { C as Component, L as Lines, P as Point, V as Variable, D as DxfSystem, M as ModelDataPlugin, a as DetailsPoint, W as WhiteModel, S as SelectLocalFile } from "./build.js";
1
+ import { D as DomEventRegister, a as DomContainer, R as Renderer, E as ElButton, b as ElCheckbox } from "./index4.js";
2
+ import { C as Component, V as Variable, D as DxfSystem, M as ModelDataPlugin, W as WhiteModel, S as SelectLocalFile } from "./build.js";
2
3
  import * as THREE from "three";
3
4
  import { Group } from "three";
4
5
  import "clipper-lib";
5
6
  import "dxf-writer";
6
- import { E as ElButton, R as Renderer, D as DomEventRegister, a as DomContainer, b as ElCheckbox } from "./DomEventRegister.js";
7
- import { defineComponent, createElementBlock, openBlock, createElementVNode, toDisplayString, createVNode, unref, withCtx, createTextVNode, createApp, ref, watch, onMounted, onUnmounted, createCommentVNode, createStaticVNode } from "vue";
8
- function drawLinePathToPng(points, width, height, color = "#fff", lineWidth = 2) {
9
- const can = document.createElement("canvas"), ctx = can.getContext("2d");
10
- can.width = width;
11
- can.height = height;
12
- ctx?.clearRect(0, 0, width, height);
13
- ctx?.save();
14
- ctx.strokeStyle = color;
15
- ctx.lineWidth = lineWidth;
16
- ctx?.beginPath();
17
- points.forEach((p, i) => {
18
- if (i === 0) ctx?.moveTo(p[0], p[1]);
19
- else ctx?.lineTo(p[0], p[1]);
20
- });
21
- ctx?.stroke();
22
- ctx?.restore();
23
- return can.toDataURL("image/png", 1);
24
- }
25
- const _hoisted_1$1 = { class: "bg-white rounded-lg p-[10px] w-[200px] text-[14px]" };
26
- const _hoisted_2$1 = { class: "flex" };
27
- const _hoisted_3$1 = { class: "flee-1 text-[14px] leading-[1.4em]" };
28
- const _hoisted_4$1 = { class: "mt-[10px] ml-[1.4em]" };
29
- const _sfc_main$1 = /* @__PURE__ */ defineComponent({
30
- __name: "Card",
31
- props: {
32
- message: {}
33
- },
34
- emits: ["look"],
35
- setup(__props, { emit: __emit }) {
36
- const emits = __emit;
37
- return (_ctx, _cache) => {
38
- return openBlock(), createElementBlock("div", _hoisted_1$1, [
39
- createElementVNode("div", _hoisted_2$1, [
40
- _cache[1] || (_cache[1] = createElementVNode("div", { class: "size-[1.4em] flex justify-center items-center" }, [
41
- createElementVNode("div", { class: "size-[6px] bg-[var(--el-color-primary)] rounded-[50px]" })
42
- ], -1)),
43
- createElementVNode("p", _hoisted_3$1, toDisplayString(_ctx.message), 1)
44
- ]),
45
- createElementVNode("div", _hoisted_4$1, [
46
- createVNode(unref(ElButton), {
47
- onClick: _cache[0] || (_cache[0] = () => emits("look")),
48
- type: "primary",
49
- size: "small"
50
- }, {
51
- default: withCtx(() => _cache[2] || (_cache[2] = [
52
- createTextVNode(" 查看 ", -1)
53
- ])),
54
- _: 1,
55
- __: [2]
56
- })
57
- ])
58
- ]);
59
- };
60
- }
61
- });
62
- const DES_POINT_DEFAULT_COLOR = "radial-gradient(circle at center, rgba(0,0,0, 1), transparent, rgba(0,0,0, 1))", DES_POINT_LINE_COLOR = "#409eff", DES_POINT_ACTIVE_COLOR = `radial-gradient(circle at center, ${DES_POINT_LINE_COLOR}, transparent, ${DES_POINT_LINE_COLOR})`;
63
- class DetailsPointRender extends Component {
64
- static name = "DetailsPointRender";
65
- Dxf = null;
66
- Renderer = null;
67
- WhiteModel = null;
68
- Variable = null;
69
- desPointGroup = new THREE.Group();
70
- rayLineGroup = new THREE.Group();
71
- data = [];
72
- onAddFromParent(parent) {
73
- this.Dxf = parent.findComponentByName("Dxf");
74
- this.WhiteModel = parent.findComponentByName("WhiteModel");
75
- this.Renderer = parent.findComponentByName("Renderer");
76
- this.Variable = parent.findComponentByName("Variable");
77
- const desPoint = parent.findComponentByName("DetailsPoint");
78
- this.Renderer?.container.add(this.desPointGroup);
79
- this.rayLineGroup.visible = false;
80
- this.Variable?.addEventListener("whiteModelVisible", (e) => {
81
- this.desPointGroup.visible = e.value;
82
- });
83
- this.Dxf?.addEventListener("setDta", () => this.updateModel());
84
- desPoint?.addEventListener("handleSuccess", () => this.updateModel());
85
- this.Variable?.addEventListener("isLook", (e) => {
86
- if (!e.value) this.cancelLook();
87
- });
88
- this.Variable?.addEventListener("currentWheel", (e) => {
89
- if (this.Variable?.isLook) {
90
- const v = e.value > 0 ? -0.5 : 0.5;
91
- const camera = this.Renderer?.camera;
92
- camera.fov += v;
93
- camera.updateProjectionMatrix();
94
- }
95
- });
96
- let rotationYSpeed = 0;
97
- this.Variable?.addEventListener("pointerMove", (e) => {
98
- rotationYSpeed = e.value.x * 2e-3;
99
- });
100
- this.addEventListener("update", () => {
101
- const variable = this.Variable;
102
- const renderer = this.Renderer;
103
- if (variable.isLook) {
104
- renderer.camera.rotation.y += rotationYSpeed;
105
- rotationYSpeed *= 0.8;
106
- if (Math.abs(rotationYSpeed) < 1e-5) rotationYSpeed = 0;
107
- }
108
- });
109
- this.Variable?.addEventListener("currentKeyUp", (e) => {
110
- const variable = this.Variable;
111
- if (variable.isLook) {
112
- if (e.value === "escape") variable.set("isLook", false);
113
- }
114
- if (e.value === "r") this.rayLineGroup.visible = !this.rayLineGroup.visible;
115
- });
116
- }
117
- /**
118
- * 更新模型
119
- */
120
- updateModel() {
121
- this.createDesPoint();
122
- this.createRayline();
123
- }
124
- createDesPoint() {
125
- const desPointHandle = this.parent?.findComponentByName("DetailsPoint");
126
- this.desPointGroup.clear();
127
- desPointHandle.desPoints.forEach(({ message, position, intersection }) => {
128
- const div = document.createElement("div");
129
- Object.assign(div.style, {
130
- width: "15px",
131
- height: "15px",
132
- background: DES_POINT_DEFAULT_COLOR,
133
- borderRadius: "40px",
134
- cursor: "pointer"
135
- });
136
- const css2DObject = new Renderer.CSS2DObject(div);
137
- css2DObject.position.copy(intersection);
138
- this.desPointGroup.add(css2DObject);
139
- div.addEventListener("mousedown", (e) => {
140
- e.stopPropagation();
141
- this.showDesBox(intersection, div, { message, position });
142
- });
143
- });
144
- }
145
- createRayline() {
146
- this.desPointGroup.add(this.rayLineGroup);
147
- const desPointHandle = this.parent?.findComponentByName("DetailsPoint");
148
- this.rayLineGroup.clear();
149
- desPointHandle.raylines.forEach(([p1, p2], index2) => {
150
- if (index2 % 2 === 0) {
151
- const box = new THREE.Mesh(new THREE.SphereGeometry(0.05), new THREE.MeshBasicMaterial({ color: 65280 }));
152
- box.position.copy(p1);
153
- this.rayLineGroup.add(box);
154
- }
155
- const lines = new Lines([p1, p2], index2 % 2 === 0 ? 16711680 : 65280);
156
- this.rayLineGroup.add(lines);
157
- });
158
- }
159
- _desBoxInfo;
160
- /**
161
- * 显示详情div盒子
162
- * @param point
163
- * @param div
164
- * @param param2
165
- * @returns
166
- */
167
- showDesBox(point, div, { message, position }) {
168
- const variable = this.Variable, renderer = this.Renderer;
169
- if (variable.isLook) return;
170
- this.hideDesBox();
171
- const content = document.createElement("div");
172
- Object.assign(content.style, {
173
- padding: "0px",
174
- fontSize: "14px",
175
- pointerEvents: "none"
176
- });
177
- const contentCss2DObject = new Renderer.CSS2DObject(content);
178
- const width = 80, height = 40;
179
- const img = document.createElement("img");
180
- img.style.pointerEvents = "none";
181
- img.style.width = width + "px";
182
- img.style.height = height + "px";
183
- img.style.marginTop = "1px";
184
- img.src = drawLinePathToPng([[0, height - 1], [width * 0.2, height - 1], [width * 0.6, 2], [width, 2]], width, height, DES_POINT_LINE_COLOR, 2);
185
- content.appendChild(img);
186
- div.style.background = DES_POINT_ACTIVE_COLOR;
187
- contentCss2DObject.position.copy(point);
188
- this.desPointGroup.add(contentCss2DObject);
189
- content.style.opacity = "0";
190
- setTimeout(() => {
191
- const { width: width2, height: height2 } = content.getBoundingClientRect();
192
- content.style.marginLeft = width2 * 0.5 + "px";
193
- content.style.marginTop = -height2 * 0.5 + "px";
194
- content.style.opacity = "1";
195
- }, 20);
196
- this._desBoxInfo = {
197
- targetEl: div,
198
- css2DObject: contentCss2DObject
199
- };
200
- const main = document.createElement("div");
201
- main.style.pointerEvents = "all";
202
- main.style.position = "absolute";
203
- main.style.left = "100%";
204
- main.style.top = "0px";
205
- main.style.margin = "-15px -20px";
206
- content.appendChild(main);
207
- createApp(_sfc_main$1, {
208
- message,
209
- onLook: () => {
210
- this.onLook(point, position);
211
- }
212
- }).mount(main);
213
- renderer.orbitControls.enabled = false;
214
- const cancelDesBox = () => {
215
- if (variable.isLook) return;
216
- renderer.orbitControls.enabled = true;
217
- this.hideDesBox();
218
- };
219
- main.addEventListener("mousedown", (e) => e.stopPropagation());
220
- document.addEventListener("mousedown", cancelDesBox);
221
- }
222
- /**
223
- * 隐藏详情盒子
224
- */
225
- hideDesBox() {
226
- if (this._desBoxInfo) {
227
- this._desBoxInfo.targetEl.style.background = DES_POINT_DEFAULT_COLOR;
228
- this._desBoxInfo.css2DObject.removeFromParent();
229
- this._desBoxInfo = null;
230
- }
231
- }
232
- orbitControlsTarget = new THREE.Vector3();
233
- fov = 0;
234
- /**
235
- * 查看详情点
236
- * @param point
237
- * @param position
238
- */
239
- onLook(point, position) {
240
- const variable = this.Variable, renderer = this.Renderer;
241
- variable.set("isLook", true);
242
- this.orbitControlsTarget.copy(renderer.orbitControls.target);
243
- renderer.orbitControls?.target.copy(point);
244
- this.fov = renderer.camera.fov;
245
- this.hideDesBox();
246
- renderer.cameraTo(position, point);
247
- renderer.html2DRenderer?.domElement.focus();
248
- }
249
- /**
250
- * 取消查看详情点
251
- */
252
- cancelLook() {
253
- const renderer = this.Renderer;
254
- renderer.cameraBack();
255
- renderer.orbitControls.enabled = true;
256
- renderer.orbitControls?.target.copy(this.orbitControlsTarget);
257
- renderer.camera.fov = this.fov;
258
- renderer.camera.updateProjectionMatrix();
259
- }
260
- }
261
- class OriginalLineRender extends Component {
262
- static name = "OriginalLineRender";
263
- Dxf = null;
264
- Renderer = null;
265
- originalLineMode = new THREE.LineSegments();
266
- appendLineMode = new THREE.LineSegments();
267
- textGroup = new THREE.Group();
268
- pointGroup = new THREE.Group();
269
- distanceGroup = new THREE.Group();
270
- onAddFromParent(parent) {
271
- this.Dxf = parent.findComponentByName("Dxf");
272
- this.Renderer = parent.findComponentByName("Renderer");
273
- const variable = parent.findComponentByName("Variable");
274
- this.Renderer?.container.add(this.originalLineMode);
275
- this.Renderer?.container.add(this.appendLineMode);
276
- this.Renderer?.container.add(this.textGroup);
277
- this.Renderer?.container.add(this.pointGroup);
278
- this.Renderer?.container.add(this.distanceGroup);
279
- this.appendLineMode.visible = false;
280
- this.textGroup.visible = false;
281
- this.pointGroup.visible = false;
282
- this.distanceGroup.visible = false;
283
- this.originalLineMode.material = new THREE.LineBasicMaterial({
284
- color: 5745151
285
- });
286
- this.Dxf?.addEventListener("setDta", (e) => {
287
- this.pointGroup.clear();
288
- this.updateMode(e.originalData);
289
- const dxf = this.Dxf;
290
- const center = dxf.originalBox.center;
291
- this.Renderer?.orbitControls?.target.set(center.x, center.y, 0);
292
- const lineAnalysis = parent.findComponentByName("LineAnalysis");
293
- const array = lineAnalysis.appendLineSegmentList.flatMap((line) => line.points.flatMap((p) => [p.x, p.y, dxf.originalZAverage]));
294
- this.appendLineMode.geometry = new THREE.BufferGeometry().setAttribute("position", new THREE.BufferAttribute(new Float32Array(array), 3, true));
295
- this.appendLineMode.material = new THREE.LineBasicMaterial({ color: 16711935 });
296
- });
297
- variable?.addEventListener("originalLineVisible", (e) => {
298
- this.originalLineMode.visible = e.value;
299
- });
300
- variable?.addEventListener("currentKeyUp", (e) => {
301
- if (e.value === "q") variable.set("originalLineVisible", !variable.originalLineVisible);
302
- else if (e.value === "a") this.appendLineMode.visible = !this.appendLineMode.visible;
303
- else if (e.value === "t") this.textGroup.visible = !this.textGroup.visible;
304
- else if (e.value === "p") this.pointGroup.visible = !this.pointGroup.visible;
305
- else if (e.value === "l") this.distanceGroup.visible = !this.distanceGroup.visible;
306
- });
307
- }
308
- updateMode(data) {
309
- const dxf = this.Dxf, renderer = this.Renderer;
310
- this.textGroup.clear();
311
- this.distanceGroup.clear();
312
- const originalArray = new Float32Array(data.flatMap(({ start, end }, i) => {
313
- const x = start.x + (end.x - start.x) * 0.5;
314
- const y = start.y + (end.y - start.y) * 0.5;
315
- renderer.createText(i, new THREE.Vector3(x, y, dxf.originalZAverage), { fontSize: "10px", color: "#ffff00" }, this.textGroup);
316
- renderer.createText(
317
- Number(Point.prototype.distance.call(start, end).toFixed(2)),
318
- new THREE.Vector3(x, y, dxf.originalZAverage),
319
- { fontSize: "10px", color: "#00ff00" },
320
- this.distanceGroup
321
- );
322
- renderer.createPointMesh(new THREE.Vector3(start.x, start.y, dxf.originalZAverage), 0.04, {
323
- color: 16777215,
324
- transparent: true,
325
- opacity: 0.5
326
- }, this.pointGroup);
327
- renderer.createPointMesh(new THREE.Vector3(end.x, end.y, dxf.originalZAverage), 0.02, {
328
- color: 16711680
329
- }, this.pointGroup);
330
- return [
331
- start.x,
332
- start.y,
333
- dxf.originalZAverage,
334
- end.x,
335
- end.y,
336
- dxf.originalZAverage
337
- ];
338
- }));
339
- this.originalLineMode.geometry = new THREE.BufferGeometry().setAttribute("position", new THREE.BufferAttribute(originalArray, 3, true));
340
- }
341
- }
7
+ import { defineComponent, ref, watch, onMounted, onUnmounted, createElementBlock, openBlock, createElementVNode, createCommentVNode, createVNode, unref, withCtx, createTextVNode, createStaticVNode } from "vue";
342
8
  class ModelDataRender extends Component {
343
9
  static name = "ModelDataRender";
344
10
  onAddFromParent(parent) {
@@ -349,7 +15,6 @@ class ModelDataRender extends Component {
349
15
  const renderer = parent.findComponentByName("Renderer");
350
16
  const variable = parent.findComponentByName("Variable");
351
17
  const dxfLineModel = parent.findComponentByName("DxfLineModel");
352
- const dxf = parent.findComponentByName("Dxf");
353
18
  renderer.container.add(dxfLineModel.dxfModelGroup);
354
19
  variable.addEventListener("dxfVisible", (e) => {
355
20
  dxfLineModel.dxfModelGroup.visible = e.value;
@@ -363,11 +28,6 @@ class ModelDataRender extends Component {
363
28
  else {
364
29
  group.visible = true;
365
30
  group.clear();
366
- dxf.wallsGroup.forEach((path, j) => {
367
- path.forEach((p, i) => {
368
- renderer.createText(`${j}-${i}`, p, { color: "#ff00ff", fontSize: "10px" }, group).position.z = dxf.originalZAverage * 0.99;
369
- });
370
- });
371
31
  }
372
32
  }
373
33
  });
@@ -377,8 +37,6 @@ class ModelDataRender extends Component {
377
37
  const variable = parent.findComponentByName("Variable");
378
38
  const whiteModel = parent.findComponentByName("WhiteModel");
379
39
  renderer.container.add(whiteModel.whiteModelGroup);
380
- renderer.container.add(whiteModel.originalWhiteMode);
381
- whiteModel.originalWhiteMode.visible = false;
382
40
  variable?.addEventListener("whiteModelVisible", (e) => whiteModel.whiteModelGroup.visible = e.value);
383
41
  variable?.addEventListener("currentKeyUp", (e) => e.value === "e" && variable.set("whiteModelVisible", !variable.whiteModelVisible));
384
42
  }
@@ -516,12 +174,10 @@ class EventInput extends Component {
516
174
  }
517
175
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
518
176
  __proto__: null,
519
- DetailsPointRender,
520
177
  DomContainer,
521
178
  DomEventRegister,
522
179
  EventInput,
523
180
  ModelDataRender,
524
- OriginalLineRender,
525
181
  Renderer
526
182
  }, Symbol.toStringTag, { value: "Module" }));
527
183
  const _hoisted_1 = { class: "pointer-events-none w-full flex justify-between absolute left-0 top-0 p-[10px] z-[1000] gap-[5px] select-none" };
@@ -537,7 +193,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
537
193
  setup(__props) {
538
194
  THREE.Object3D.DEFAULT_UP = new THREE.Vector3(0, 0, 1);
539
195
  const props = __props;
540
- const elRef = ref(), originalLineVisible = ref(true), dxfVisible = ref(true), whiteModelVisible = ref(true), isLook = ref(false), dxfSystem = new DxfSystem().usePlugin(ModelDataPlugin).usePlugin(RenderPlugin), desPoint = dxfSystem.findComponentByType(DetailsPoint), domContainer = dxfSystem.findComponentByType(DomContainer), whiteModel = dxfSystem.findComponentByType(WhiteModel);
196
+ const elRef = ref(), originalLineVisible = ref(true), dxfVisible = ref(true), whiteModelVisible = ref(true), isLook = ref(false), dxfSystem = new DxfSystem().usePlugin(ModelDataPlugin).usePlugin(RenderPlugin), desPoint = dxfSystem.findComponentByType(void 0), domContainer = dxfSystem.findComponentByType(DomContainer), whiteModel = dxfSystem.findComponentByType(WhiteModel);
541
197
  watch(() => props.lines, () => props.lines && setLines(props.lines));
542
198
  watch(() => props.detailsPoint, () => props.detailsPoint && desPoint?.set(props.detailsPoint));
543
199
  function setLines(lines) {
@@ -677,9 +333,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
677
333
  });
678
334
  function RenderPlugin_(dxfSystem, option = {}) {
679
335
  const {
680
- originalLine = true,
681
336
  modelData = true,
682
- detailsPoint = true,
683
337
  orbitControls = true,
684
338
  camera = new THREE.PerspectiveCamera(45, 1, 0.01, 1e3)
685
339
  } = option;
@@ -699,9 +353,7 @@ function RenderPlugin_(dxfSystem, option = {}) {
699
353
  dampingFactor: 0.15
700
354
  } : void 0
701
355
  }));
702
- originalLine && dxfSystem.addComponent(new OriginalLineRender());
703
356
  modelData && dxfSystem.addComponent(new ModelDataRender());
704
- detailsPoint && dxfSystem.addComponent(new DetailsPointRender());
705
357
  dxfSystem.addComponent(new DomEventRegister());
706
358
  dxfSystem.addComponent(new EventInput());
707
359
  }