build-dxf 0.0.19 → 0.0.20-10
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/README.md +30 -0
- package/package.json +1 -3
- package/src/build.d.ts +23 -1
- package/src/build.js +70 -16
- package/src/index.css +661 -1
- package/src/index.js +4 -2
- package/src/index2.js +9 -3681
- package/src/index3.js +1546 -410
- package/src/pages/Editor.vue.d.ts +3 -1
- package/src/selectLocalFile.js +444 -21
- package/src/utils/CommandManager/CommandFlow.d.ts +16 -0
- package/src/utils/CommandManager/CommandManager.d.ts +23 -0
- package/src/utils/ComponentManager/Component.d.ts +1 -0
- package/src/utils/ComponentManager/ComponentManager.d.ts +1 -1
- package/src/utils/DxfSystem/components/Dxf.d.ts +1 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/CommandFlowComponent.d.ts +13 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/ConnectionLine.d.ts +33 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/Default.d.ts +5 -19
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DeleteSelectLine.d.ts +28 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DeleteSelectWindow.d.ts +33 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawDoorLine.d.ts +19 -3
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawLine.d.ts +22 -5
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawWindow.d.ts +22 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/IntersectionConnectionLine.d.ts +33 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/MergeLine.d.ts +32 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/PointDrag.d.ts +16 -2
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/SelectAll.d.ts +30 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalCorrection.d.ts +63 -0
- package/src/utils/DxfSystem/plugin/Editor/components/Editor.d.ts +7 -0
- package/src/utils/DxfSystem/plugin/Editor/components/index.d.ts +1 -0
- package/src/utils/DxfSystem/plugin/Editor/index.d.ts +8 -1
- package/src/utils/DxfSystem/plugin/Editor/pages/EditorTool.vue.d.ts +5 -1
- package/src/utils/DxfSystem/plugin/RenderPlugin/components/DomEventRegister.d.ts +28 -6
- package/src/utils/DxfSystem/plugin/RenderPlugin/components/Renderer.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/RenderPlugin/index.d.ts +2 -1
- package/src/utils/Quadtree/LineSegment.d.ts +2 -1
- package/src/utils/Quadtree/Point.d.ts +2 -1
- package/src/components/Editor.vue.d.ts +0 -26
- package/src/pages/Editor02.vue.d.ts +0 -4
package/README.md
CHANGED
|
@@ -40,6 +40,36 @@ detailsPoint.set("./json/dp8.json")
|
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
# 浏览器编辑功能使用示例
|
|
44
|
+
```html
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<div class="w-[100vw] h-[100vh]" ref="dom"> </div>
|
|
48
|
+
</template>
|
|
49
|
+
|
|
50
|
+
<style scoped></style>
|
|
51
|
+
|
|
52
|
+
<script setup lang="ts">
|
|
53
|
+
import data from "../data/d9.json"
|
|
54
|
+
import { createEditor } from "build-dxf"
|
|
55
|
+
import { onMounted, ref } from "vue"
|
|
56
|
+
import * as THREE from "three"
|
|
57
|
+
import "build-dxf/index.css"
|
|
58
|
+
|
|
59
|
+
const dom = ref<HTMLDivElement>()
|
|
60
|
+
|
|
61
|
+
onMounted(async ()=>{
|
|
62
|
+
if(dom.value) {
|
|
63
|
+
const camera = new THREE.OrthographicCamera( -100, 100, 100, -100, 0.1, 1000 )
|
|
64
|
+
const { dxfSystem } = await createEditor( dom.value, camera )
|
|
65
|
+
dxfSystem.Dxf.set( (data as any) )
|
|
66
|
+
dxfSystem.Dxf.lineOffset()
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
</script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
|
|
43
73
|
|
|
44
74
|
# 浏览器 使用示例
|
|
45
75
|
```html
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "build-dxf",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20-10",
|
|
4
4
|
"description": "线段构建双线墙壁的dxf版本",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -35,8 +35,6 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"clipper-lib": ">=6.4.2",
|
|
37
37
|
"dxf-writer": ">=1.18.4",
|
|
38
|
-
"three-bvh-csg": ">=0.0.17",
|
|
39
|
-
"three-csg-ts": ">=3.2.0",
|
|
40
38
|
"@tweenjs/tween.js": ">=25.0.0",
|
|
41
39
|
"vue": ">=3.0.0",
|
|
42
40
|
"obj2gltf": ">=3.1.6"
|
package/src/build.d.ts
CHANGED
|
@@ -7,6 +7,28 @@ export * from './utils/DxfSystem/plugin/ModelDataPlugin';
|
|
|
7
7
|
* @param camera
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
10
|
-
export declare function createEditor(dom: HTMLDivElement, camera?: THREE.
|
|
10
|
+
export declare function createEditor(dom: HTMLDivElement, camera?: THREE.Camera, orbitControls?: boolean, viewPermission?: 'admin'): Promise<{
|
|
11
11
|
dxfSystem: DxfSystem;
|
|
12
|
+
getFileAll: () => Promise<{
|
|
13
|
+
dxf: File;
|
|
14
|
+
obj: File;
|
|
15
|
+
glb: File;
|
|
16
|
+
gltf: File;
|
|
17
|
+
json: File;
|
|
18
|
+
}>;
|
|
12
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* 获取所有文件数据
|
|
22
|
+
* @param dxfSystem
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFileAll(dxfSystem?: DxfSystem): Promise<{
|
|
25
|
+
dxf: File;
|
|
26
|
+
obj: File;
|
|
27
|
+
glb: File;
|
|
28
|
+
gltf: File;
|
|
29
|
+
json: File;
|
|
30
|
+
}>;
|
|
31
|
+
/** 获取全局DxfSystem
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function getGlobalDxfSystem(): DxfSystem | null;
|
package/src/build.js
CHANGED
|
@@ -44,6 +44,7 @@ class EventDispatcher extends EventDispatcher$1 {
|
|
|
44
44
|
}
|
|
45
45
|
class Component extends EventDispatcher {
|
|
46
46
|
parent;
|
|
47
|
+
destroyed = false;
|
|
47
48
|
constructor(...arg) {
|
|
48
49
|
super();
|
|
49
50
|
this.addEventListener("addFromParent", (e) => {
|
|
@@ -60,6 +61,7 @@ class Component extends EventDispatcher {
|
|
|
60
61
|
onRemoveFromParent(parent) {
|
|
61
62
|
}
|
|
62
63
|
destroy() {
|
|
64
|
+
this.destroyed = true;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
class ComponentManager extends EventDispatcher {
|
|
@@ -120,7 +122,7 @@ class ComponentManager extends EventDispatcher {
|
|
|
120
122
|
* @param callBack
|
|
121
123
|
*/
|
|
122
124
|
findComponents(predicate) {
|
|
123
|
-
return this.components.
|
|
125
|
+
return this.components.filter(predicate);
|
|
124
126
|
}
|
|
125
127
|
/**
|
|
126
128
|
*
|
|
@@ -363,10 +365,11 @@ class Point {
|
|
|
363
365
|
this.x = p.x ?? 0;
|
|
364
366
|
this.y = p.y ?? 0;
|
|
365
367
|
}
|
|
366
|
-
toJson() {
|
|
368
|
+
toJson(z = 0) {
|
|
367
369
|
return {
|
|
368
370
|
x: this.x,
|
|
369
|
-
y: this.y
|
|
371
|
+
y: this.y,
|
|
372
|
+
z
|
|
370
373
|
};
|
|
371
374
|
}
|
|
372
375
|
static from(arr) {
|
|
@@ -850,6 +853,10 @@ class LineSegment {
|
|
|
850
853
|
constructor(p1 = new Point(), p2 = new Point()) {
|
|
851
854
|
this.points = [p1, p2];
|
|
852
855
|
}
|
|
856
|
+
set(p1, p2) {
|
|
857
|
+
this.start.copy(p1);
|
|
858
|
+
this.end.copy(p2);
|
|
859
|
+
}
|
|
853
860
|
/** 膨胀
|
|
854
861
|
* @description 向线段的两个端点分别膨胀 width
|
|
855
862
|
* @param width
|
|
@@ -1025,7 +1032,7 @@ class LineSegment {
|
|
|
1025
1032
|
return projP1;
|
|
1026
1033
|
}
|
|
1027
1034
|
/**
|
|
1028
|
-
*
|
|
1035
|
+
* 判断线段是否与另一条线段相交(包含共用端点或部分重合的情况)
|
|
1029
1036
|
* @param line
|
|
1030
1037
|
*/
|
|
1031
1038
|
intersectLineSegment(line) {
|
|
@@ -1033,14 +1040,32 @@ class LineSegment {
|
|
|
1033
1040
|
const p2 = this.end;
|
|
1034
1041
|
const p3 = line.start;
|
|
1035
1042
|
const p4 = line.end;
|
|
1036
|
-
function crossProduct(
|
|
1037
|
-
return (
|
|
1043
|
+
function crossProduct(a, b, c) {
|
|
1044
|
+
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
1045
|
+
}
|
|
1046
|
+
function isPointOnSegment(pt, segStart, segEnd) {
|
|
1047
|
+
return Math.min(segStart.x, segEnd.x) - 1e-10 <= pt.x && pt.x <= Math.max(segStart.x, segEnd.x) + 1e-10 && Math.min(segStart.y, segEnd.y) - 1e-10 <= pt.y && pt.y <= Math.max(segStart.y, segEnd.y) + 1e-10;
|
|
1038
1048
|
}
|
|
1039
1049
|
const d1 = crossProduct(p1, p2, p3);
|
|
1040
1050
|
const d2 = crossProduct(p1, p2, p4);
|
|
1041
1051
|
const d3 = crossProduct(p3, p4, p1);
|
|
1042
1052
|
const d4 = crossProduct(p3, p4, p2);
|
|
1043
|
-
|
|
1053
|
+
if (d1 * d2 < 0 && d3 * d4 < 0) {
|
|
1054
|
+
return true;
|
|
1055
|
+
}
|
|
1056
|
+
if (Math.abs(d1) < 1e-10 && isPointOnSegment(p3, p1, p2)) {
|
|
1057
|
+
return true;
|
|
1058
|
+
}
|
|
1059
|
+
if (Math.abs(d2) < 1e-10 && isPointOnSegment(p4, p1, p2)) {
|
|
1060
|
+
return true;
|
|
1061
|
+
}
|
|
1062
|
+
if (Math.abs(d3) < 1e-10 && isPointOnSegment(p1, p3, p4)) {
|
|
1063
|
+
return true;
|
|
1064
|
+
}
|
|
1065
|
+
if (Math.abs(d4) < 1e-10 && isPointOnSegment(p2, p3, p4)) {
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
return false;
|
|
1044
1069
|
}
|
|
1045
1070
|
/**
|
|
1046
1071
|
* 获取交点
|
|
@@ -1465,7 +1490,7 @@ class Dxf extends Component {
|
|
|
1465
1490
|
removeShortLine(path, shortLine = this.shortLine) {
|
|
1466
1491
|
const lines = pathToLines(path), filterLines = [], PI_1 = Math.PI / 180;
|
|
1467
1492
|
for (let i = 0; i < lines.length; i++) {
|
|
1468
|
-
const line = lines[i], len = line.length();
|
|
1493
|
+
const line = lines[i], len = line.length(), currentIndex = i;
|
|
1469
1494
|
if (len > shortLine || filterLines.length === 0) {
|
|
1470
1495
|
filterLines.push(line);
|
|
1471
1496
|
continue;
|
|
@@ -1478,7 +1503,9 @@ class Dxf extends Component {
|
|
|
1478
1503
|
nextline = lines[++i];
|
|
1479
1504
|
} else break;
|
|
1480
1505
|
}
|
|
1481
|
-
if (nextline)
|
|
1506
|
+
if (!nextline) continue;
|
|
1507
|
+
const targetLine = lines[i - 1];
|
|
1508
|
+
if (preLine.length() > targetLine.length()) {
|
|
1482
1509
|
const intersectPoint = preLine.getIntersection(nextline);
|
|
1483
1510
|
if (intersectPoint) {
|
|
1484
1511
|
const p0 = preLine.points[1].clone(), p1 = nextline.points[0].clone();
|
|
@@ -1495,6 +1522,8 @@ class Dxf extends Component {
|
|
|
1495
1522
|
preLine.points[1].copy(nextline.points[0]);
|
|
1496
1523
|
}
|
|
1497
1524
|
filterLines.push(nextline);
|
|
1525
|
+
} else {
|
|
1526
|
+
i = currentIndex;
|
|
1498
1527
|
}
|
|
1499
1528
|
}
|
|
1500
1529
|
return filterLines.length > 3 ? linesToPath(filterLines) : [];
|
|
@@ -2265,7 +2294,6 @@ class DoorsAnalysis {
|
|
|
2265
2294
|
console.warn(`门的线段顺序${item[4]} 没有drawDoorData属性`);
|
|
2266
2295
|
}
|
|
2267
2296
|
});
|
|
2268
|
-
console.log("门点位数量:", doorPoints.length);
|
|
2269
2297
|
return doorPoints;
|
|
2270
2298
|
}
|
|
2271
2299
|
/**
|
|
@@ -2704,10 +2732,12 @@ class DxfSystem extends ComponentManager {
|
|
|
2704
2732
|
return this;
|
|
2705
2733
|
}
|
|
2706
2734
|
destroy() {
|
|
2707
|
-
this.components.forEach((com) => {
|
|
2708
|
-
this.removeComponent(com);
|
|
2735
|
+
[...this.components].forEach((com) => {
|
|
2709
2736
|
com.destroy();
|
|
2710
2737
|
});
|
|
2738
|
+
[...this.components].forEach((com) => {
|
|
2739
|
+
this.removeComponent(com);
|
|
2740
|
+
});
|
|
2711
2741
|
}
|
|
2712
2742
|
}
|
|
2713
2743
|
const exporter = new OBJExporter();
|
|
@@ -3076,25 +3106,47 @@ function loadRenderPlugin() {
|
|
|
3076
3106
|
function loadEditorPlugin() {
|
|
3077
3107
|
return import("./index3.js");
|
|
3078
3108
|
}
|
|
3079
|
-
|
|
3109
|
+
let gloabalDxfSystem = null;
|
|
3110
|
+
async function createEditor(dom, camera, orbitControls = false, viewPermission) {
|
|
3080
3111
|
const mp = await Promise.resolve().then(() => index);
|
|
3081
3112
|
const rp = await loadRenderPlugin();
|
|
3082
3113
|
const editor = await loadEditorPlugin();
|
|
3083
3114
|
const dxfSystem = new DxfSystem().usePlugin(mp.ModelDataPlugin.create({
|
|
3084
3115
|
detailsPoint: false,
|
|
3085
|
-
whiteModel:
|
|
3116
|
+
whiteModel: true
|
|
3086
3117
|
})).usePlugin(rp.RenderPlugin.create({
|
|
3087
3118
|
originalLine: false,
|
|
3088
3119
|
modelData: false,
|
|
3089
3120
|
detailsPoint: false,
|
|
3121
|
+
orbitControls,
|
|
3090
3122
|
camera
|
|
3091
|
-
})).usePlugin(editor.Editor);
|
|
3123
|
+
})).usePlugin(editor.Editor.create({ viewPermission }));
|
|
3092
3124
|
const domContainer = dxfSystem.findComponentByType(rp.components.DomContainer);
|
|
3093
3125
|
domContainer && dom.appendChild(domContainer.domElement);
|
|
3126
|
+
gloabalDxfSystem = dxfSystem;
|
|
3094
3127
|
return {
|
|
3095
|
-
dxfSystem
|
|
3128
|
+
dxfSystem,
|
|
3129
|
+
getFileAll: () => getFileAll(dxfSystem)
|
|
3096
3130
|
};
|
|
3097
3131
|
}
|
|
3132
|
+
async function getFileAll(dxfSystem = gloabalDxfSystem) {
|
|
3133
|
+
const whiteModel = dxfSystem.findComponentByName("WhiteModel");
|
|
3134
|
+
const dxf = new File([dxfSystem.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" });
|
|
3135
|
+
const obj = new File([await whiteModel.toOBJBlob()], "model.obj", { type: "application/octet-stream" });
|
|
3136
|
+
const glb = new File([await whiteModel.toGltfBlob(true)], "model.glb", { type: "application/octet-stream" });
|
|
3137
|
+
const gltf = new File([await whiteModel.toGltfBlob(false)], "model.gltf", { type: "application/json" });
|
|
3138
|
+
const json = new File([JSON.stringify(dxfSystem.Dxf.originalData)], "json.json", { type: "application/json" });
|
|
3139
|
+
return {
|
|
3140
|
+
dxf,
|
|
3141
|
+
obj,
|
|
3142
|
+
glb,
|
|
3143
|
+
gltf,
|
|
3144
|
+
json
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
function getGlobalDxfSystem() {
|
|
3148
|
+
return gloabalDxfSystem;
|
|
3149
|
+
}
|
|
3098
3150
|
export {
|
|
3099
3151
|
Box2 as B,
|
|
3100
3152
|
Component as C,
|
|
@@ -3109,5 +3161,7 @@ export {
|
|
|
3109
3161
|
DetailsPoint as a,
|
|
3110
3162
|
PointVirtualGrid as b,
|
|
3111
3163
|
createEditor as c,
|
|
3164
|
+
getGlobalDxfSystem as d,
|
|
3165
|
+
getFileAll as g,
|
|
3112
3166
|
index$1 as i
|
|
3113
3167
|
};
|