@bitbybit-dev/jscad 0.19.0-alpha.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/LICENSE +21 -0
- package/README.md +63 -0
- package/babel.config.cjs +14 -0
- package/babel.config.d.cts +5 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/jscad-generated.d.ts +1 -0
- package/jscad-generated.js +27486 -0
- package/lib/api/inputs/base-inputs.d.ts +38 -0
- package/lib/api/inputs/base-inputs.js +1 -0
- package/lib/api/inputs/index.d.ts +2 -0
- package/lib/api/inputs/index.js +2 -0
- package/lib/api/inputs/inputs.d.ts +2 -0
- package/lib/api/inputs/inputs.js +2 -0
- package/lib/api/inputs/jscad-inputs.d.ts +1646 -0
- package/lib/api/inputs/jscad-inputs.js +2137 -0
- package/lib/api/jscad-service.d.ts +51 -0
- package/lib/api/jscad-service.js +139 -0
- package/lib/api/services/index.d.ts +8 -0
- package/lib/api/services/index.js +8 -0
- package/lib/api/services/jscad-booleans.d.ts +17 -0
- package/lib/api/services/jscad-booleans.js +34 -0
- package/lib/api/services/jscad-colors.d.ts +11 -0
- package/lib/api/services/jscad-colors.js +14 -0
- package/lib/api/services/jscad-expansions.d.ts +12 -0
- package/lib/api/services/jscad-expansions.js +34 -0
- package/lib/api/services/jscad-extrusions.d.ts +18 -0
- package/lib/api/services/jscad-extrusions.js +44 -0
- package/lib/api/services/jscad-hulls.d.ts +12 -0
- package/lib/api/services/jscad-hulls.js +15 -0
- package/lib/api/services/jscad-path.d.ts +23 -0
- package/lib/api/services/jscad-path.js +64 -0
- package/lib/api/services/jscad-polygon.d.ts +25 -0
- package/lib/api/services/jscad-polygon.js +69 -0
- package/lib/api/services/jscad-shapes.d.ts +32 -0
- package/lib/api/services/jscad-shapes.js +182 -0
- package/lib/api/services/jscad-text.d.ts +14 -0
- package/lib/api/services/jscad-text.js +68 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/package.json +99 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSCADExpansions } from "./services/jscad-expansions";
|
|
2
|
+
import { JSCADBooleans } from "./services/jscad-booleans";
|
|
3
|
+
import { JSCADExtrusions } from "./services/jscad-extrusions";
|
|
4
|
+
import { JSCADPath } from "./services/jscad-path";
|
|
5
|
+
import { JSCADPolygon } from "./services/jscad-polygon";
|
|
6
|
+
import { JSCADShapes } from "./services/jscad-shapes";
|
|
7
|
+
import { JSCADText } from "./services/jscad-text";
|
|
8
|
+
import * as Inputs from "./inputs/jscad-inputs";
|
|
9
|
+
import { JSCADHulls } from "./services/jscad-hulls";
|
|
10
|
+
import { JSCADColors } from "./services/jscad-colors";
|
|
11
|
+
import * as JSCAD from "@jscad/modeling";
|
|
12
|
+
export declare class Jscad {
|
|
13
|
+
private jscad;
|
|
14
|
+
booleans: JSCADBooleans;
|
|
15
|
+
expansions: JSCADExpansions;
|
|
16
|
+
extrusions: JSCADExtrusions;
|
|
17
|
+
hulls: JSCADHulls;
|
|
18
|
+
path: JSCADPath;
|
|
19
|
+
polygon: JSCADPolygon;
|
|
20
|
+
shapes: JSCADShapes;
|
|
21
|
+
text: JSCADText;
|
|
22
|
+
colors: JSCADColors;
|
|
23
|
+
constructor(jscad: typeof JSCAD);
|
|
24
|
+
shapesToMeshes<T>(inputs: Inputs.JSCAD.DrawSolidMeshesDto<T>): {
|
|
25
|
+
positions: number[];
|
|
26
|
+
normals: number[];
|
|
27
|
+
indices: number[];
|
|
28
|
+
transforms: [];
|
|
29
|
+
}[];
|
|
30
|
+
shapeToMesh<T>(inputs: Inputs.JSCAD.DrawSolidMeshDto<T>): {
|
|
31
|
+
positions: number[];
|
|
32
|
+
normals: number[];
|
|
33
|
+
indices: number[];
|
|
34
|
+
transforms: [];
|
|
35
|
+
};
|
|
36
|
+
transformSolids(inputs: Inputs.JSCAD.TransformSolidsDto): any;
|
|
37
|
+
transformSolid(inputs: Inputs.JSCAD.TransformSolidDto): any;
|
|
38
|
+
downloadSolidSTL(inputs: Inputs.JSCAD.DownloadSolidDto): {
|
|
39
|
+
blob: Blob;
|
|
40
|
+
};
|
|
41
|
+
downloadGeometryDxf(inputs: Inputs.JSCAD.DownloadGeometryDto): {
|
|
42
|
+
blob: Blob;
|
|
43
|
+
};
|
|
44
|
+
downloadGeometry3MF(inputs: Inputs.JSCAD.DownloadGeometryDto): {
|
|
45
|
+
blob: Blob;
|
|
46
|
+
};
|
|
47
|
+
downloadSolidsSTL(inputs: Inputs.JSCAD.DownloadSolidsDto): {
|
|
48
|
+
blob: Blob;
|
|
49
|
+
};
|
|
50
|
+
private getArrayDepth;
|
|
51
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { VectorHelperService } from "@bitbybit-dev/occt";
|
|
2
|
+
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
3
|
+
import { JSCADExpansions } from "./services/jscad-expansions";
|
|
4
|
+
import { JSCADBooleans } from "./services/jscad-booleans";
|
|
5
|
+
import { JSCADExtrusions } from "./services/jscad-extrusions";
|
|
6
|
+
import { JSCADPath } from "./services/jscad-path";
|
|
7
|
+
import { JSCADPolygon } from "./services/jscad-polygon";
|
|
8
|
+
import { JSCADShapes } from "./services/jscad-shapes";
|
|
9
|
+
import { JSCADText } from "./services/jscad-text";
|
|
10
|
+
import { JSCADHulls } from "./services/jscad-hulls";
|
|
11
|
+
import { JSCADColors } from "./services/jscad-colors";
|
|
12
|
+
// Worker make an instance of this class itself
|
|
13
|
+
export class Jscad {
|
|
14
|
+
constructor(jscad) {
|
|
15
|
+
this.getArrayDepth = (value) => {
|
|
16
|
+
return Array.isArray(value) ?
|
|
17
|
+
1 + Math.max(...value.map(this.getArrayDepth)) :
|
|
18
|
+
0;
|
|
19
|
+
};
|
|
20
|
+
const vecHelper = new VectorHelperService();
|
|
21
|
+
const math = new MathBitByBit();
|
|
22
|
+
this.booleans = new JSCADBooleans(jscad);
|
|
23
|
+
this.expansions = new JSCADExpansions(jscad);
|
|
24
|
+
this.extrusions = new JSCADExtrusions(jscad, vecHelper, math);
|
|
25
|
+
this.hulls = new JSCADHulls(jscad);
|
|
26
|
+
this.path = new JSCADPath(jscad, vecHelper, math);
|
|
27
|
+
this.polygon = new JSCADPolygon(jscad, vecHelper, math);
|
|
28
|
+
this.shapes = new JSCADShapes(jscad, math);
|
|
29
|
+
this.text = new JSCADText(jscad);
|
|
30
|
+
this.colors = new JSCADColors(jscad);
|
|
31
|
+
this.jscad = jscad;
|
|
32
|
+
}
|
|
33
|
+
shapesToMeshes(inputs) {
|
|
34
|
+
return inputs.meshes.map(mesh => {
|
|
35
|
+
return this.shapeToMesh(Object.assign(Object.assign({}, inputs), { mesh }));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
shapeToMesh(inputs) {
|
|
39
|
+
let polygons = [];
|
|
40
|
+
if (inputs.mesh.toPolygons) {
|
|
41
|
+
polygons = inputs.mesh.toPolygons();
|
|
42
|
+
}
|
|
43
|
+
else if (inputs.mesh.polygons) {
|
|
44
|
+
polygons = inputs.mesh.polygons;
|
|
45
|
+
}
|
|
46
|
+
else if (inputs.mesh.sides || inputs.mesh.vertices) {
|
|
47
|
+
const extrusion = this.extrusions.extrudeLinear({ height: 0.001, twistAngle: 0, twistSteps: 1, geometry: inputs.mesh });
|
|
48
|
+
if (extrusion.toPolygons) {
|
|
49
|
+
polygons = extrusion.toPolygons();
|
|
50
|
+
}
|
|
51
|
+
else if (extrusion.polygons) {
|
|
52
|
+
polygons = extrusion.polygons;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const positions = [];
|
|
56
|
+
const normals = [];
|
|
57
|
+
const indices = [];
|
|
58
|
+
let countIndices = 0;
|
|
59
|
+
for (const polygon of polygons) {
|
|
60
|
+
if (polygon.vertices.length === 3) {
|
|
61
|
+
polygon.vertices.forEach(vert => {
|
|
62
|
+
positions.push(vert[0], vert[1], vert[2]);
|
|
63
|
+
indices.push(countIndices);
|
|
64
|
+
countIndices++;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const triangles = [];
|
|
69
|
+
const reversedVertices = polygon.vertices;
|
|
70
|
+
const firstVertex = reversedVertices[0];
|
|
71
|
+
for (let i = reversedVertices.length - 3; i >= 0; i--) {
|
|
72
|
+
triangles.push([
|
|
73
|
+
firstVertex,
|
|
74
|
+
reversedVertices[i + 1],
|
|
75
|
+
reversedVertices[i + 2],
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
triangles.forEach((triangle, index) => {
|
|
79
|
+
triangle.forEach(vert => {
|
|
80
|
+
positions.push(vert[0], vert[1], vert[2]);
|
|
81
|
+
indices.push(countIndices);
|
|
82
|
+
countIndices++;
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
positions, normals, indices, transforms: inputs.mesh.transforms,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
transformSolids(inputs) {
|
|
92
|
+
const solidsToTransform = inputs.meshes;
|
|
93
|
+
return solidsToTransform.map(mesh => {
|
|
94
|
+
return this.transformSolid({ mesh, transformation: inputs.transformation });
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
transformSolid(inputs) {
|
|
98
|
+
const transformation = inputs.transformation;
|
|
99
|
+
let transformedMesh = this.jscad.geometries.geom3.clone(inputs.mesh);
|
|
100
|
+
if (this.getArrayDepth(transformation) === 2) {
|
|
101
|
+
transformation.forEach(transform => {
|
|
102
|
+
transformedMesh = this.jscad.transforms.transform(transform, transformedMesh);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else if (this.getArrayDepth(transformation) === 3) {
|
|
106
|
+
transformation.forEach(transforms => {
|
|
107
|
+
transforms.forEach(mat => {
|
|
108
|
+
transformedMesh = this.jscad.transforms.transform(mat, transformedMesh);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
transformedMesh = this.jscad.transforms.transform(transformation, transformedMesh);
|
|
114
|
+
}
|
|
115
|
+
return transformedMesh;
|
|
116
|
+
}
|
|
117
|
+
downloadSolidSTL(inputs) {
|
|
118
|
+
const rawData = this.jscad.STLSERIALIZER.serialize({ binary: true }, inputs.mesh);
|
|
119
|
+
const madeBlob = new Blob(rawData, { type: "application/sla" });
|
|
120
|
+
return { blob: madeBlob };
|
|
121
|
+
}
|
|
122
|
+
downloadGeometryDxf(inputs) {
|
|
123
|
+
const options = inputs.options ? inputs.options : {};
|
|
124
|
+
const rawData = this.jscad.DXFSERIALIZER.serialize(options, inputs.geometry);
|
|
125
|
+
const madeBlob = new Blob(rawData);
|
|
126
|
+
return { blob: madeBlob };
|
|
127
|
+
}
|
|
128
|
+
downloadGeometry3MF(inputs) {
|
|
129
|
+
const options = inputs.options ? inputs.options : {};
|
|
130
|
+
const rawData = this.jscad.THREEMFSERIALIZER.serialize(options, inputs.geometry);
|
|
131
|
+
const madeBlob = new Blob(rawData);
|
|
132
|
+
return { blob: madeBlob };
|
|
133
|
+
}
|
|
134
|
+
downloadSolidsSTL(inputs) {
|
|
135
|
+
const rawData = this.jscad.STLSERIALIZER.serialize({ binary: true }, ...inputs.meshes);
|
|
136
|
+
const madeBlob = new Blob(rawData, { type: "application/sla" });
|
|
137
|
+
return { blob: madeBlob };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./jscad-booleans";
|
|
2
|
+
export * from "./jscad-expansions";
|
|
3
|
+
export * from "./jscad-extrusions";
|
|
4
|
+
export * from "./jscad-hulls";
|
|
5
|
+
export * from "./jscad-path";
|
|
6
|
+
export * from "./jscad-polygon";
|
|
7
|
+
export * from "./jscad-shapes";
|
|
8
|
+
export * from "./jscad-text";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./jscad-booleans";
|
|
2
|
+
export * from "./jscad-expansions";
|
|
3
|
+
export * from "./jscad-extrusions";
|
|
4
|
+
export * from "./jscad-hulls";
|
|
5
|
+
export * from "./jscad-path";
|
|
6
|
+
export * from "./jscad-polygon";
|
|
7
|
+
export * from "./jscad-shapes";
|
|
8
|
+
export * from "./jscad-text";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import * as JSCAD from "@jscad/modeling";
|
|
3
|
+
/**
|
|
4
|
+
* Contains various functions for Solid booleans from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
5
|
+
* Thanks JSCAD community for developing this kernel
|
|
6
|
+
*/
|
|
7
|
+
export declare class JSCADBooleans {
|
|
8
|
+
private readonly jscad;
|
|
9
|
+
constructor(jscad: typeof JSCAD);
|
|
10
|
+
intersect(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
11
|
+
subtract(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
12
|
+
union(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
13
|
+
intersectTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
14
|
+
subtractTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
15
|
+
unionTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
16
|
+
subtractFrom(inputs: Inputs.JSCAD.BooleanObjectsFromDto): Inputs.JSCAD.JSCADEntity;
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for Solid booleans from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADBooleans {
|
|
6
|
+
constructor(jscad) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
}
|
|
9
|
+
intersect(inputs) {
|
|
10
|
+
return this.jscad.booleans.intersect(...inputs.meshes);
|
|
11
|
+
}
|
|
12
|
+
subtract(inputs) {
|
|
13
|
+
return this.jscad.booleans.subtract(...inputs.meshes);
|
|
14
|
+
}
|
|
15
|
+
union(inputs) {
|
|
16
|
+
return this.jscad.booleans.union(...inputs.meshes);
|
|
17
|
+
}
|
|
18
|
+
intersectTwo(inputs) {
|
|
19
|
+
const meshes = [inputs.first, inputs.second];
|
|
20
|
+
return this.jscad.booleans.intersect(...meshes);
|
|
21
|
+
}
|
|
22
|
+
subtractTwo(inputs) {
|
|
23
|
+
const meshes = [inputs.first, inputs.second];
|
|
24
|
+
return this.jscad.booleans.subtract(...meshes);
|
|
25
|
+
}
|
|
26
|
+
unionTwo(inputs) {
|
|
27
|
+
const meshes = [inputs.first, inputs.second];
|
|
28
|
+
return this.jscad.booleans.union(...meshes);
|
|
29
|
+
}
|
|
30
|
+
subtractFrom(inputs) {
|
|
31
|
+
const meshes = [inputs.from, ...inputs.meshes];
|
|
32
|
+
return this.jscad.booleans.subtract(...meshes);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import * as JSCAD from "@jscad/modeling";
|
|
3
|
+
/**
|
|
4
|
+
* Contains various functions for colors from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
5
|
+
* Thanks JSCAD community for developing this kernel
|
|
6
|
+
*/
|
|
7
|
+
export declare class JSCADColors {
|
|
8
|
+
private readonly jscad;
|
|
9
|
+
constructor(jscad: typeof JSCAD);
|
|
10
|
+
colorize(inputs: Inputs.JSCAD.ColorizeDto): Inputs.JSCAD.JSCADEntity | Inputs.JSCAD.JSCADEntity[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for colors from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADColors {
|
|
6
|
+
constructor(jscad) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
}
|
|
9
|
+
colorize(inputs) {
|
|
10
|
+
const geometry = inputs.geometry;
|
|
11
|
+
const color = inputs.color;
|
|
12
|
+
return this.jscad.colors.colorize(this.jscad.colors.hexToRgb(color), geometry);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import * as JSCAD from "@jscad/modeling";
|
|
3
|
+
/**
|
|
4
|
+
* Contains various functions for Solid expansions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
5
|
+
* Thanks JSCAD community for developing this kernel
|
|
6
|
+
*/
|
|
7
|
+
export declare class JSCADExpansions {
|
|
8
|
+
private readonly jscad;
|
|
9
|
+
constructor(jscad: typeof JSCAD);
|
|
10
|
+
expand(inputs: Inputs.JSCAD.ExpansionDto): Inputs.JSCAD.JSCADEntity;
|
|
11
|
+
offset(inputs: Inputs.JSCAD.ExpansionDto): Inputs.JSCAD.JSCADEntity;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
/**
|
|
3
|
+
* Contains various functions for Solid expansions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
4
|
+
* Thanks JSCAD community for developing this kernel
|
|
5
|
+
*/
|
|
6
|
+
export class JSCADExpansions {
|
|
7
|
+
constructor(jscad) {
|
|
8
|
+
this.jscad = jscad;
|
|
9
|
+
}
|
|
10
|
+
expand(inputs) {
|
|
11
|
+
const geometry = inputs.geometry.length && inputs.geometry.length > 0 ? inputs.geometry : [inputs.geometry];
|
|
12
|
+
if (!inputs.corners) {
|
|
13
|
+
inputs.corners = Inputs.JSCAD.solidCornerTypeEnum.round;
|
|
14
|
+
}
|
|
15
|
+
const result = this.jscad.expansions.expand({
|
|
16
|
+
delta: inputs.delta,
|
|
17
|
+
corners: inputs.corners,
|
|
18
|
+
segments: inputs.segments,
|
|
19
|
+
}, ...geometry);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
offset(inputs) {
|
|
23
|
+
const geometry = inputs.geometry.length && inputs.geometry.length > 0 ? inputs.geometry : [inputs.geometry];
|
|
24
|
+
if (!inputs.corners) {
|
|
25
|
+
inputs.corners = Inputs.JSCAD.solidCornerTypeEnum.edge;
|
|
26
|
+
}
|
|
27
|
+
const result = this.jscad.expansions.offset({
|
|
28
|
+
delta: inputs.delta,
|
|
29
|
+
corners: inputs.corners,
|
|
30
|
+
segments: inputs.segments,
|
|
31
|
+
}, ...geometry);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { VectorHelperService } from "@bitbybit-dev/occt";
|
|
2
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
3
|
+
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
4
|
+
import * as JSCAD from "@jscad/modeling";
|
|
5
|
+
/**
|
|
6
|
+
* Contains various functions for Solid extrusions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
7
|
+
* Thanks JSCAD community for developing this kernel
|
|
8
|
+
*/
|
|
9
|
+
export declare class JSCADExtrusions {
|
|
10
|
+
private readonly jscad;
|
|
11
|
+
private readonly vecHelper;
|
|
12
|
+
private readonly math;
|
|
13
|
+
constructor(jscad: typeof JSCAD, vecHelper: VectorHelperService, math: MathBitByBit);
|
|
14
|
+
extrudeLinear(inputs: Inputs.JSCAD.ExtrudeLinearDto): Inputs.JSCAD.JSCADEntity;
|
|
15
|
+
extrudeRectangular(inputs: Inputs.JSCAD.ExtrudeRectangularDto): Inputs.JSCAD.JSCADEntity;
|
|
16
|
+
extrudeRectangularPoints(inputs: Inputs.JSCAD.ExtrudeRectangularPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
17
|
+
extrudeRotate(inputs: Inputs.JSCAD.ExtrudeRotateDto): Inputs.JSCAD.JSCADEntity;
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for Solid extrusions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADExtrusions {
|
|
6
|
+
constructor(jscad, vecHelper, math) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
this.vecHelper = vecHelper;
|
|
9
|
+
this.math = math;
|
|
10
|
+
}
|
|
11
|
+
extrudeLinear(inputs) {
|
|
12
|
+
const multipleGeometries = inputs.geometry.length && inputs.geometry.length > 0;
|
|
13
|
+
const geometry = multipleGeometries ? inputs.geometry : [inputs.geometry];
|
|
14
|
+
const extrusions = this.jscad.extrusions.extrudeLinear({
|
|
15
|
+
height: inputs.height,
|
|
16
|
+
twistAngle: this.math.degToRad({ number: inputs.twistAngle }),
|
|
17
|
+
twistSteps: inputs.twistSteps
|
|
18
|
+
}, ...geometry);
|
|
19
|
+
return extrusions;
|
|
20
|
+
}
|
|
21
|
+
extrudeRectangular(inputs) {
|
|
22
|
+
const multipleGeometries = inputs.geometry.length && inputs.geometry.length > 0;
|
|
23
|
+
const geometry = multipleGeometries ? inputs.geometry : [inputs.geometry];
|
|
24
|
+
const extrusions = this.jscad.extrusions.extrudeRectangular({ height: inputs.height, size: inputs.size }, ...geometry);
|
|
25
|
+
return extrusions;
|
|
26
|
+
}
|
|
27
|
+
extrudeRectangularPoints(inputs) {
|
|
28
|
+
const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
|
|
29
|
+
const duplicatePointsRemoved = this.vecHelper.removeConsecutiveDuplicates(twoDimensionalPoints);
|
|
30
|
+
const path = this.jscad.geometries.path2.fromPoints({}, duplicatePointsRemoved);
|
|
31
|
+
const extrusion = this.extrudeRectangular({ height: inputs.height, size: inputs.size, geometry: path });
|
|
32
|
+
return extrusion;
|
|
33
|
+
}
|
|
34
|
+
extrudeRotate(inputs) {
|
|
35
|
+
const options = {
|
|
36
|
+
angle: this.math.degToRad({ number: inputs.angle }),
|
|
37
|
+
startAngle: this.math.degToRad({ number: inputs.startAngle }),
|
|
38
|
+
overflow: "cap",
|
|
39
|
+
segments: inputs.segments
|
|
40
|
+
};
|
|
41
|
+
const extrusion = this.jscad.extrusions.extrudeRotate(options, inputs.polygon);
|
|
42
|
+
return extrusion;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import * as JSCAD from "@jscad/modeling";
|
|
3
|
+
/**
|
|
4
|
+
* Contains various functions for Solid hulls from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
5
|
+
* Thanks JSCAD community for developing this kernel
|
|
6
|
+
*/
|
|
7
|
+
export declare class JSCADHulls {
|
|
8
|
+
private readonly jscad;
|
|
9
|
+
constructor(jscad: typeof JSCAD);
|
|
10
|
+
hullChain(inputs: Inputs.JSCAD.HullDto): Inputs.JSCAD.JSCADEntity;
|
|
11
|
+
hull(inputs: Inputs.JSCAD.HullDto): Inputs.JSCAD.JSCADEntity;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for Solid hulls from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADHulls {
|
|
6
|
+
constructor(jscad) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
}
|
|
9
|
+
hullChain(inputs) {
|
|
10
|
+
return this.jscad.hulls.hullChain(...inputs.meshes);
|
|
11
|
+
}
|
|
12
|
+
hull(inputs) {
|
|
13
|
+
return this.jscad.hulls.hull(...inputs.meshes);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VectorHelperService } from "@bitbybit-dev/occt";
|
|
2
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
3
|
+
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
4
|
+
import * as JSCAD from "@jscad/modeling";
|
|
5
|
+
/**
|
|
6
|
+
* Contains various functions for Path from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
7
|
+
* Thanks JSCAD community for developing this kernel
|
|
8
|
+
*/
|
|
9
|
+
export declare class JSCADPath {
|
|
10
|
+
private readonly jscad;
|
|
11
|
+
private readonly vecHelper;
|
|
12
|
+
private readonly math;
|
|
13
|
+
constructor(jscad: typeof JSCAD, vecHelper: VectorHelperService, math: MathBitByBit);
|
|
14
|
+
createFromPoints(inputs: Inputs.JSCAD.PathFromPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
15
|
+
createPathsFromPoints(inputs: Inputs.JSCAD.PathsFromPointsDto): Inputs.JSCAD.JSCADEntity[];
|
|
16
|
+
createFromPolyline(inputs: Inputs.JSCAD.PathFromPolylineDto): Inputs.JSCAD.JSCADEntity;
|
|
17
|
+
createEmpty(): Inputs.JSCAD.JSCADEntity;
|
|
18
|
+
close(inputs: Inputs.JSCAD.PathDto): Inputs.JSCAD.JSCADEntity;
|
|
19
|
+
appendPoints(inputs: Inputs.JSCAD.PathAppendPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
20
|
+
appendPolyline(inputs: Inputs.JSCAD.PathAppendPolylineDto): Inputs.JSCAD.JSCADEntity;
|
|
21
|
+
appendArc(inputs: Inputs.JSCAD.PathAppendArcDto): Inputs.JSCAD.JSCADEntity;
|
|
22
|
+
private removeDuplicatesAndCreateFromPoints;
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for Path from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADPath {
|
|
6
|
+
constructor(jscad, vecHelper, math) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
this.vecHelper = vecHelper;
|
|
9
|
+
this.math = math;
|
|
10
|
+
}
|
|
11
|
+
createFromPoints(inputs) {
|
|
12
|
+
const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
|
|
13
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, inputs.closed);
|
|
14
|
+
}
|
|
15
|
+
createPathsFromPoints(inputs) {
|
|
16
|
+
return inputs.pointsLists.map(points => {
|
|
17
|
+
const twoDimensionalPoints = points.map(pt => [pt[0], pt[1]]);
|
|
18
|
+
if (twoDimensionalPoints.length > 1 &&
|
|
19
|
+
this.vecHelper.vectorsTheSame(twoDimensionalPoints[0], twoDimensionalPoints[twoDimensionalPoints.length - 1], 0.00001)) {
|
|
20
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, true);
|
|
21
|
+
}
|
|
22
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, false);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
createFromPolyline(inputs) {
|
|
26
|
+
const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
|
|
27
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, inputs.closed);
|
|
28
|
+
}
|
|
29
|
+
createEmpty() {
|
|
30
|
+
return this.jscad.geometries.path2.create();
|
|
31
|
+
}
|
|
32
|
+
close(inputs) {
|
|
33
|
+
return this.jscad.geometries.path2.close(inputs.path);
|
|
34
|
+
}
|
|
35
|
+
appendPoints(inputs) {
|
|
36
|
+
const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
|
|
37
|
+
const duplicatePointsRemoved = this.vecHelper.removeConsecutiveDuplicates(twoDimensionalPoints);
|
|
38
|
+
return this.jscad.geometries.path2.appendPoints(duplicatePointsRemoved, inputs.path);
|
|
39
|
+
}
|
|
40
|
+
appendPolyline(inputs) {
|
|
41
|
+
const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
|
|
42
|
+
return this.appendPoints({ points: twoDimensionalPoints, path: inputs.path });
|
|
43
|
+
}
|
|
44
|
+
appendArc(inputs) {
|
|
45
|
+
const endpoint = [inputs.endPoint[0], inputs.endPoint[1]];
|
|
46
|
+
const radius = [inputs.radiusX, inputs.radiusY];
|
|
47
|
+
return this.jscad.geometries.path2.appendArc({
|
|
48
|
+
endpoint,
|
|
49
|
+
radius,
|
|
50
|
+
xaxisrotation: this.math.degToRad({ number: inputs.xAxisRotation }),
|
|
51
|
+
clockwise: inputs.clockwise,
|
|
52
|
+
large: inputs.large,
|
|
53
|
+
segments: inputs.segments,
|
|
54
|
+
}, inputs.path);
|
|
55
|
+
}
|
|
56
|
+
removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, closed) {
|
|
57
|
+
const duplicatePointsRemoved = this.vecHelper.removeConsecutiveDuplicates(twoDimensionalPoints);
|
|
58
|
+
let path2d = this.jscad.geometries.path2.fromPoints({}, duplicatePointsRemoved);
|
|
59
|
+
if (closed) {
|
|
60
|
+
path2d = this.jscad.geometries.path2.close(path2d);
|
|
61
|
+
}
|
|
62
|
+
return path2d;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VectorHelperService } from "@bitbybit-dev/occt";
|
|
2
|
+
import * as Inputs from "../inputs";
|
|
3
|
+
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
4
|
+
import * as JSCAD from "@jscad/modeling";
|
|
5
|
+
/**
|
|
6
|
+
* Contains various functions for Polygon from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
7
|
+
* Thanks JSCAD community for developing this kernel
|
|
8
|
+
*/
|
|
9
|
+
export declare class JSCADPolygon {
|
|
10
|
+
private readonly jscad;
|
|
11
|
+
private readonly vecHelper;
|
|
12
|
+
private readonly math;
|
|
13
|
+
constructor(jscad: typeof JSCAD, vecHelper: VectorHelperService, math: MathBitByBit);
|
|
14
|
+
createFromPoints(inputs: Inputs.Point.PointsDto): Inputs.JSCAD.JSCADEntity;
|
|
15
|
+
createFromPolyline(inputs: Inputs.JSCAD.PolylineDto): Inputs.JSCAD.JSCADEntity;
|
|
16
|
+
createFromCurve(inputs: Inputs.JSCAD.CurveDto): Inputs.JSCAD.JSCADEntity;
|
|
17
|
+
createFromPath(inputs: Inputs.JSCAD.PathDto): Inputs.JSCAD.JSCADEntity;
|
|
18
|
+
circle(inputs: Inputs.JSCAD.CircleDto): Inputs.JSCAD.JSCADEntity;
|
|
19
|
+
ellipse(inputs: Inputs.JSCAD.EllipseDto): Inputs.JSCAD.JSCADEntity;
|
|
20
|
+
rectangle(inputs: Inputs.JSCAD.RectangleDto): Inputs.JSCAD.JSCADEntity;
|
|
21
|
+
roundedRectangle(inputs: Inputs.JSCAD.RoundedRectangleDto): Inputs.JSCAD.JSCADEntity;
|
|
22
|
+
square(inputs: Inputs.JSCAD.SquareDto): Inputs.JSCAD.JSCADEntity;
|
|
23
|
+
star(inputs: Inputs.JSCAD.StarDto): Inputs.JSCAD.JSCADEntity;
|
|
24
|
+
private removeDuplicatesAndCreateFromPoints;
|
|
25
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for Polygon from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADPolygon {
|
|
6
|
+
constructor(jscad, vecHelper, math) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
this.vecHelper = vecHelper;
|
|
9
|
+
this.math = math;
|
|
10
|
+
}
|
|
11
|
+
createFromPoints(inputs) {
|
|
12
|
+
const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
|
|
13
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
|
|
14
|
+
}
|
|
15
|
+
createFromPolyline(inputs) {
|
|
16
|
+
const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
|
|
17
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
|
|
18
|
+
}
|
|
19
|
+
// TODO conversions between various CAD kernels should happen on higher levels of abstraction (this was meant to create jscad polygons from VERB-NURBS curves)
|
|
20
|
+
createFromCurve(inputs) {
|
|
21
|
+
const twoDimensionalPoints = inputs.curve.tessellate().map(pt => [pt[0], pt[1]]);
|
|
22
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
|
|
23
|
+
}
|
|
24
|
+
createFromPath(inputs) {
|
|
25
|
+
return this.removeDuplicatesAndCreateFromPoints(inputs.path.points);
|
|
26
|
+
}
|
|
27
|
+
circle(inputs) {
|
|
28
|
+
return this.jscad.primitives.circle({ center: inputs.center, radius: inputs.radius, segments: inputs.segments });
|
|
29
|
+
}
|
|
30
|
+
ellipse(inputs) {
|
|
31
|
+
return this.jscad.primitives.ellipse({
|
|
32
|
+
center: inputs.center,
|
|
33
|
+
radius: [inputs.radius[0], inputs.radius[1]],
|
|
34
|
+
segments: inputs.segments
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
rectangle(inputs) {
|
|
38
|
+
return this.jscad.primitives.rectangle({
|
|
39
|
+
center: [inputs.center[0], inputs.center[1]],
|
|
40
|
+
size: [inputs.width, inputs.length]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
roundedRectangle(inputs) {
|
|
44
|
+
return this.jscad.primitives.roundedRectangle({
|
|
45
|
+
center: [inputs.center[0], inputs.center[1]],
|
|
46
|
+
size: [inputs.width, inputs.length],
|
|
47
|
+
roundRadius: inputs.roundRadius,
|
|
48
|
+
segments: inputs.segments,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
square(inputs) {
|
|
52
|
+
return this.jscad.primitives.square({ center: [inputs.center[0], inputs.center[1]], size: inputs.size });
|
|
53
|
+
}
|
|
54
|
+
star(inputs) {
|
|
55
|
+
return this.jscad.primitives.star({
|
|
56
|
+
center: [inputs.center[0], inputs.center[1]],
|
|
57
|
+
vertices: inputs.vertices,
|
|
58
|
+
density: inputs.density,
|
|
59
|
+
outerRadius: inputs.outerRadius,
|
|
60
|
+
innerRadius: inputs.innerRadius,
|
|
61
|
+
startAngle: this.math.degToRad({ number: inputs.startAngle }),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
removeDuplicatesAndCreateFromPoints(twoDimensionalPoints) {
|
|
65
|
+
const duplicatePointsRemoved = this.vecHelper.removeConsecutiveDuplicates(twoDimensionalPoints);
|
|
66
|
+
const polygon = this.jscad.primitives.polygon({ points: duplicatePointsRemoved });
|
|
67
|
+
return polygon;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
3
|
+
import * as JSCAD from "@jscad/modeling";
|
|
4
|
+
/**
|
|
5
|
+
* Contains various functions for solid 3D shapes from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
6
|
+
* Thanks JSCAD community for developing this kernel
|
|
7
|
+
*/
|
|
8
|
+
export declare class JSCADShapes {
|
|
9
|
+
private readonly math;
|
|
10
|
+
jscad: typeof JSCAD;
|
|
11
|
+
constructor(jscad: typeof JSCAD, math: MathBitByBit);
|
|
12
|
+
cube(inputs: Inputs.JSCAD.CubeDto): Inputs.JSCAD.JSCADEntity;
|
|
13
|
+
cubesOnCenterPoints(inputs: Inputs.JSCAD.CubeCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
14
|
+
cuboid(inputs: Inputs.JSCAD.CuboidDto): Inputs.JSCAD.JSCADEntity;
|
|
15
|
+
cuboidsOnCenterPoints(inputs: Inputs.JSCAD.CuboidCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
16
|
+
cylinderElliptic(inputs: Inputs.JSCAD.CylidnerEllipticDto): Inputs.JSCAD.JSCADEntity;
|
|
17
|
+
cylinderEllipticOnCenterPoints(inputs: Inputs.JSCAD.CylidnerCentersEllipticDto): Inputs.JSCAD.JSCADEntity[];
|
|
18
|
+
cylinder(inputs: Inputs.JSCAD.CylidnerDto): Inputs.JSCAD.JSCADEntity;
|
|
19
|
+
cylindersOnCenterPoints(inputs: Inputs.JSCAD.CylidnerCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
20
|
+
ellipsoid(inputs: Inputs.JSCAD.EllipsoidDto): Inputs.JSCAD.JSCADEntity;
|
|
21
|
+
ellipsoidsOnCenterPoints(inputs: Inputs.JSCAD.EllipsoidCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
22
|
+
geodesicSphere(inputs: Inputs.JSCAD.GeodesicSphereDto): Inputs.JSCAD.JSCADEntity;
|
|
23
|
+
geodesicSpheresOnCenterPoints(inputs: Inputs.JSCAD.GeodesicSphereCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
24
|
+
roundedCuboid(inputs: Inputs.JSCAD.RoundedCuboidDto): Inputs.JSCAD.JSCADEntity;
|
|
25
|
+
roundedCuboidsOnCenterPoints(inputs: Inputs.JSCAD.RoundedCuboidCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
26
|
+
roundedCylinder(inputs: Inputs.JSCAD.RoundedCylidnerDto): Inputs.JSCAD.JSCADEntity;
|
|
27
|
+
roundedCylindersOnCenterPoints(inputs: Inputs.JSCAD.RoundedCylidnerCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
28
|
+
sphere(inputs: Inputs.JSCAD.SphereDto): Inputs.JSCAD.JSCADEntity;
|
|
29
|
+
spheresOnCenterPoints(inputs: Inputs.JSCAD.SphereCentersDto): Inputs.JSCAD.JSCADEntity[];
|
|
30
|
+
torus(inputs: Inputs.JSCAD.TorusDto): Inputs.JSCAD.JSCADEntity;
|
|
31
|
+
fromPolygonPoints(inputs: Inputs.JSCAD.FromPolygonPoints): Inputs.JSCAD.JSCADEntity;
|
|
32
|
+
}
|