build-dxf 0.0.13 → 0.0.14
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
CHANGED
|
@@ -27,7 +27,9 @@ detailsPoint.addEventListener("handleSuccess", () => {
|
|
|
27
27
|
// 下载dxf文件
|
|
28
28
|
dxfSystem.Dxf.download("01.dxf")
|
|
29
29
|
// 下载白模,obj格式
|
|
30
|
-
whiteModel.
|
|
30
|
+
whiteModel.downloadOBJ("001.obj")
|
|
31
|
+
// 下载白模,gltf或glb格式, 第二个参数为true时是glb,默认为true
|
|
32
|
+
whiteModel.downloadGltf("001.obj", true)
|
|
31
33
|
|
|
32
34
|
// desPoints 为射线点集合,根据需要使用
|
|
33
35
|
console.log("handleSuccess", detailsPoint.desPoints)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "build-dxf",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "线段构建双线墙壁的dxf版本",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"three-bvh-csg": ">=0.0.17",
|
|
39
39
|
"three-csg-ts": ">=3.2.0",
|
|
40
40
|
"@tweenjs/tween.js": ">=25.0.0",
|
|
41
|
-
"vue": ">=3.0.0"
|
|
41
|
+
"vue": ">=3.0.0",
|
|
42
|
+
"obj2gltf": ">=3.1.6"
|
|
42
43
|
},
|
|
43
44
|
"author": "夏过初秋",
|
|
44
45
|
"license": "ISC"
|
package/src/build.js
CHANGED
|
@@ -757,6 +757,18 @@ class LineSegment {
|
|
|
757
757
|
);
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
|
+
async function include(path, exportDefault = true) {
|
|
761
|
+
if (typeof global !== "undefined" && typeof require !== "undefined") {
|
|
762
|
+
return require(path);
|
|
763
|
+
} else {
|
|
764
|
+
let pack = await import(
|
|
765
|
+
/* @vite-ignore */
|
|
766
|
+
path
|
|
767
|
+
);
|
|
768
|
+
if (exportDefault) pack = pack.default;
|
|
769
|
+
return pack;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
760
772
|
const units = {
|
|
761
773
|
Unitless: 1,
|
|
762
774
|
// 无单位,1米 = 1(无单位)
|
|
@@ -1204,11 +1216,7 @@ class Dxf extends Component {
|
|
|
1204
1216
|
a.download = filename + ".dxf";
|
|
1205
1217
|
a.click();
|
|
1206
1218
|
} else if (typeof global !== "undefined") {
|
|
1207
|
-
const
|
|
1208
|
-
const { default: fs } = await import(
|
|
1209
|
-
/* @vite-ignore */
|
|
1210
|
-
packageName
|
|
1211
|
-
);
|
|
1219
|
+
const fs = await include("fs", false);
|
|
1212
1220
|
fs.writeFileSync(filename, this.toDxfString(unit));
|
|
1213
1221
|
}
|
|
1214
1222
|
}
|
|
@@ -2012,11 +2020,10 @@ class WhiteModel extends Component {
|
|
|
2012
2020
|
depth: 2.8,
|
|
2013
2021
|
bevelSize: 0
|
|
2014
2022
|
});
|
|
2015
|
-
const mesh = new THREE.Mesh(geometry);
|
|
2016
|
-
mesh.material = this.material;
|
|
2023
|
+
const mesh = new THREE.Mesh(geometry, this.material);
|
|
2017
2024
|
this.whiteModelGroup.add(mesh);
|
|
2018
2025
|
this.whiteModelLineGroup.add(
|
|
2019
|
-
new THREE.LineSegments(new THREE.EdgesGeometry(geometry), new THREE.LineBasicMaterial({ color:
|
|
2026
|
+
new THREE.LineSegments(new THREE.EdgesGeometry(geometry), new THREE.LineBasicMaterial({ color: 0 }))
|
|
2020
2027
|
);
|
|
2021
2028
|
});
|
|
2022
2029
|
const walls = dxf.originalData.map(({ start, end, insetionArr }) => {
|
|
@@ -2049,41 +2056,87 @@ class WhiteModel extends Component {
|
|
|
2049
2056
|
whiteModelGroup: this.whiteModelGroup
|
|
2050
2057
|
});
|
|
2051
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* 转为obj
|
|
2061
|
+
* @returns
|
|
2062
|
+
*/
|
|
2052
2063
|
toOBJ() {
|
|
2053
2064
|
return new Promise((resolve) => {
|
|
2054
|
-
|
|
2065
|
+
this.material.opacity = 1;
|
|
2066
|
+
this.material.needsUpdate = true;
|
|
2067
|
+
setTimeout(() => {
|
|
2068
|
+
resolve(exporter.parse(this.whiteModelGroup));
|
|
2069
|
+
this.material.opacity = 0.8;
|
|
2070
|
+
this.material.transparent = true;
|
|
2071
|
+
}, 20);
|
|
2055
2072
|
});
|
|
2056
2073
|
}
|
|
2057
|
-
|
|
2074
|
+
/**
|
|
2075
|
+
* 转为 glb
|
|
2076
|
+
* @param binary
|
|
2077
|
+
* @returns
|
|
2078
|
+
*/
|
|
2079
|
+
toGltf(binary = true) {
|
|
2058
2080
|
return new Promise((resolve) => {
|
|
2059
2081
|
this.material.opacity = 1;
|
|
2060
2082
|
this.material.needsUpdate = true;
|
|
2061
|
-
setTimeout(() => {
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2083
|
+
setTimeout(async () => {
|
|
2084
|
+
if (typeof window === "object") {
|
|
2085
|
+
glbExporter.parse(this.whiteModelGroup.children, (gltf) => {
|
|
2086
|
+
resolve(gltf);
|
|
2087
|
+
this.material.opacity = 0.8;
|
|
2088
|
+
this.material.transparent = true;
|
|
2089
|
+
}, () => {
|
|
2090
|
+
resolve(void 0);
|
|
2091
|
+
}, {
|
|
2092
|
+
binary
|
|
2093
|
+
});
|
|
2094
|
+
} else if (typeof global !== "function") {
|
|
2095
|
+
try {
|
|
2096
|
+
const obj2gltf = await include("obj2gltf", true);
|
|
2097
|
+
const fs = await include("fs", false);
|
|
2098
|
+
const obj = await this.toOBJ();
|
|
2099
|
+
fs.writeFileSync(this.uuid, obj);
|
|
2100
|
+
const result = await obj2gltf(this.uuid, {
|
|
2101
|
+
binary
|
|
2102
|
+
});
|
|
2103
|
+
fs.unlinkSync(this.uuid);
|
|
2104
|
+
if (binary) resolve(result);
|
|
2105
|
+
else resolve(JSON.stringify(result));
|
|
2106
|
+
} catch (error) {
|
|
2107
|
+
resolve(void 0);
|
|
2108
|
+
console.log(error);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}, 20);
|
|
2072
2112
|
});
|
|
2073
2113
|
}
|
|
2114
|
+
/**
|
|
2115
|
+
* 转为 OBJBlob
|
|
2116
|
+
* @returns
|
|
2117
|
+
*/
|
|
2074
2118
|
async toOBJBlob() {
|
|
2075
2119
|
const buffer = await this.toOBJ();
|
|
2076
2120
|
if (buffer) {
|
|
2077
2121
|
return new Blob([buffer], { type: "application/octet-stream" });
|
|
2078
2122
|
}
|
|
2079
2123
|
}
|
|
2080
|
-
|
|
2081
|
-
|
|
2124
|
+
/**
|
|
2125
|
+
* 转为 GltfBlob
|
|
2126
|
+
* @returns
|
|
2127
|
+
*/
|
|
2128
|
+
async toGltfBlob(binary = true) {
|
|
2129
|
+
const buffer = await this.toGltf(binary);
|
|
2082
2130
|
if (buffer) {
|
|
2083
2131
|
return new Blob([buffer], { type: "application/octet-stream" });
|
|
2084
2132
|
}
|
|
2085
2133
|
}
|
|
2086
|
-
|
|
2134
|
+
/**
|
|
2135
|
+
* 下载 OBJ
|
|
2136
|
+
* @param filename
|
|
2137
|
+
* @returns
|
|
2138
|
+
*/
|
|
2139
|
+
async downloadOBJ(filename) {
|
|
2087
2140
|
if (typeof window !== "undefined") {
|
|
2088
2141
|
const blob = await this.toOBJBlob();
|
|
2089
2142
|
if (!blob) return;
|
|
@@ -2094,32 +2147,29 @@ class WhiteModel extends Component {
|
|
|
2094
2147
|
} else if (typeof global !== "undefined") {
|
|
2095
2148
|
const buffer = await this.toOBJ();
|
|
2096
2149
|
if (buffer) {
|
|
2097
|
-
const
|
|
2098
|
-
const { default: fs } = await import(
|
|
2099
|
-
/* @vite-ignore */
|
|
2100
|
-
packageName
|
|
2101
|
-
);
|
|
2150
|
+
const fs = await include("fs", false);
|
|
2102
2151
|
fs.writeFileSync(filename, buffer);
|
|
2103
2152
|
}
|
|
2104
2153
|
}
|
|
2105
2154
|
}
|
|
2106
|
-
|
|
2155
|
+
/**
|
|
2156
|
+
* 下载 Gltf
|
|
2157
|
+
* @param filename
|
|
2158
|
+
* @returns
|
|
2159
|
+
*/
|
|
2160
|
+
async downloadGltf(filename, binary = true) {
|
|
2107
2161
|
if (typeof window !== "undefined") {
|
|
2108
|
-
const blob = await this.
|
|
2162
|
+
const blob = await this.toGltfBlob(binary);
|
|
2109
2163
|
if (!blob) return;
|
|
2110
2164
|
const a = document.createElement("a");
|
|
2111
2165
|
a.href = URL.createObjectURL(blob);
|
|
2112
2166
|
a.download = filename;
|
|
2113
2167
|
a.click();
|
|
2114
2168
|
} else if (typeof global !== "undefined") {
|
|
2115
|
-
const buffer = await this.
|
|
2169
|
+
const buffer = await this.toGltf(binary);
|
|
2116
2170
|
if (buffer) {
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2119
|
-
/* @vite-ignore */
|
|
2120
|
-
packageName
|
|
2121
|
-
);
|
|
2122
|
-
fs.writeFileSync(filename, buffer);
|
|
2171
|
+
const fs = await include("fs", false);
|
|
2172
|
+
fs.writeFileSync(filename, binary ? buffer : Buffer.from(buffer));
|
|
2123
2173
|
}
|
|
2124
2174
|
}
|
|
2125
2175
|
}
|
package/src/index2.js
CHANGED
|
@@ -7307,7 +7307,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
7307
7307
|
createVNode(unref(ElButton), {
|
|
7308
7308
|
size: "small",
|
|
7309
7309
|
type: "primary",
|
|
7310
|
-
onClick: _cache[1] || (_cache[1] = ($event) => unref(whiteModel).
|
|
7310
|
+
onClick: _cache[1] || (_cache[1] = ($event) => unref(whiteModel).downloadGltf("test.glb"))
|
|
7311
7311
|
}, {
|
|
7312
7312
|
default: withCtx(() => _cache[7] || (_cache[7] = [
|
|
7313
7313
|
createTextVNode(" 下载 白模 ", -1)
|
|
@@ -17,10 +17,37 @@ export declare class WhiteModel extends Component<{
|
|
|
17
17
|
material: THREE.MeshBasicMaterial;
|
|
18
18
|
onAddFromParent(parent: ComponentManager): void;
|
|
19
19
|
updateModel(): void;
|
|
20
|
+
/**
|
|
21
|
+
* 转为obj
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
20
24
|
toOBJ(): Promise<string>;
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 转为 glb
|
|
27
|
+
* @param binary
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
toGltf(binary?: boolean): Promise<string | ArrayBuffer | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* 转为 OBJBlob
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
22
35
|
toOBJBlob(): Promise<Blob | undefined>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
/**
|
|
37
|
+
* 转为 GltfBlob
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
toGltfBlob(binary?: boolean): Promise<Blob | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* 下载 OBJ
|
|
43
|
+
* @param filename
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
downloadOBJ(filename: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* 下载 Gltf
|
|
49
|
+
* @param filename
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
downloadGltf(filename: string, binary?: boolean): Promise<void>;
|
|
26
53
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function include(path: string, exportDefault?: boolean): Promise<any>;
|