@bitbybit-dev/jscad 1.1.0 → 1.2.0-rc.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/README.md +14 -4
- package/index.js +0 -3
- package/lib/api/inputs/base-inputs.js +0 -1
- package/lib/api/inputs/jscad-inputs.d.ts +91 -7
- package/lib/api/inputs/jscad-inputs.js +17 -1
- package/lib/api/jscad-service.d.ts +71 -17
- package/lib/api/jscad-service.js +99 -54
- package/lib/api/services/entity-narrowing.d.ts +30 -0
- package/lib/api/services/entity-narrowing.js +50 -0
- package/lib/api/services/jscad-booleans.d.ts +56 -0
- package/lib/api/services/jscad-booleans.js +64 -7
- package/lib/api/services/jscad-colors.d.ts +10 -2
- package/lib/api/services/jscad-colors.js +10 -2
- package/lib/api/services/jscad-expansions.d.ts +16 -0
- package/lib/api/services/jscad-expansions.js +21 -4
- package/lib/api/services/jscad-extrusions.d.ts +32 -0
- package/lib/api/services/jscad-extrusions.js +36 -5
- package/lib/api/services/jscad-hulls.d.ts +18 -0
- package/lib/api/services/jscad-hulls.js +21 -2
- package/lib/api/services/jscad-path.d.ts +63 -0
- package/lib/api/services/jscad-path.js +67 -3
- package/lib/api/services/jscad-polygon.d.ts +84 -0
- package/lib/api/services/jscad-polygon.js +87 -3
- package/lib/api/services/jscad-shapes.d.ts +160 -0
- package/lib/api/services/jscad-shapes.js +160 -1
- package/lib/api/services/jscad-text.d.ts +26 -1
- package/lib/api/services/jscad-text.js +26 -2
- package/package.json +6 -44
- package/babel.config.cjs +0 -14
- package/babel.config.d.cts +0 -5
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads an input that the kernel accepts either singly or as a list. The published type says one
|
|
3
|
+
* entity, and a list has always worked too because the kernel's operations are variadic; declaring
|
|
4
|
+
* the union would change the published type, so the coercion lives here instead.
|
|
5
|
+
*/
|
|
6
|
+
export function oneOrMany(geometry) {
|
|
7
|
+
return Array.isArray(geometry) ? geometry : [geometry];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hands a list of entities to an operation overloaded per geometry kind. The kernel still rejects a
|
|
11
|
+
* genuinely mixed list, and it is the right thing to decide that - it knows which combinations its
|
|
12
|
+
* operations support and we would only be guessing ahead of it. The type parameter is constrained to
|
|
13
|
+
* the three kinds, so this narrows within the union rather than escaping it.
|
|
14
|
+
*/
|
|
15
|
+
export function asKind(entities) {
|
|
16
|
+
return entities;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Narrows to the solid an operation needs, naming the operation that wanted one. Without this the
|
|
20
|
+
* kernel fails several frames deep on a property access, which tells a script author nothing about
|
|
21
|
+
* what they passed.
|
|
22
|
+
*/
|
|
23
|
+
export function asSolid(entity, operation) {
|
|
24
|
+
if (!("polygons" in entity)) {
|
|
25
|
+
throw new Error(`${operation} needs a 3D solid, but was given a 2D geometry or a path.`);
|
|
26
|
+
}
|
|
27
|
+
return entity;
|
|
28
|
+
}
|
|
29
|
+
/** Narrows to the 2D path an operation needs, naming the operation that wanted one. */
|
|
30
|
+
export function asPath(entity, operation) {
|
|
31
|
+
if (!("isClosed" in entity)) {
|
|
32
|
+
throw new Error(`${operation} needs a 2D path, but was given a 2D region or a solid.`);
|
|
33
|
+
}
|
|
34
|
+
return entity;
|
|
35
|
+
}
|
|
36
|
+
/** Narrows to the 2D region an operation needs, naming the operation that wanted one. */
|
|
37
|
+
export function asRegion(entity, operation) {
|
|
38
|
+
if (!("sides" in entity)) {
|
|
39
|
+
throw new Error(`${operation} needs a 2D geometry, but was given a path or a solid.`);
|
|
40
|
+
}
|
|
41
|
+
return entity;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads back what a variadic operation returned. The kernel hands back the geometry when it was
|
|
45
|
+
* given one and a list when it was given several, while the published return type describes only
|
|
46
|
+
* the first of those - so this is where the two meet.
|
|
47
|
+
*/
|
|
48
|
+
export function asEntity(result) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
@@ -7,11 +7,67 @@ import * as JSCAD from "@jscad/modeling";
|
|
|
7
7
|
export declare class JSCADBooleans {
|
|
8
8
|
private readonly jscad;
|
|
9
9
|
constructor(jscad: typeof JSCAD);
|
|
10
|
+
/**
|
|
11
|
+
* Intersect multiple solid mesh objects
|
|
12
|
+
* @param inputs Contains multiple solids for intersection
|
|
13
|
+
* @returns Solid mesh
|
|
14
|
+
* @group boolean
|
|
15
|
+
* @shortname intersect
|
|
16
|
+
* @drawable true
|
|
17
|
+
*/
|
|
10
18
|
intersect(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
19
|
+
/**
|
|
20
|
+
* Subtract multiple solid mesh objects
|
|
21
|
+
* @param inputs Contains multiple solids for subtraction
|
|
22
|
+
* @returns Solid mesh
|
|
23
|
+
* @group boolean
|
|
24
|
+
* @shortname subtract
|
|
25
|
+
* @drawable true
|
|
26
|
+
*/
|
|
11
27
|
subtract(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
28
|
+
/**
|
|
29
|
+
* Union multiple solid mesh objects
|
|
30
|
+
* @param inputs Contains multiple solids for union
|
|
31
|
+
* @returns Solid mesh
|
|
32
|
+
* @group boolean
|
|
33
|
+
* @shortname union
|
|
34
|
+
* @drawable true
|
|
35
|
+
*/
|
|
12
36
|
union(inputs: Inputs.JSCAD.BooleanObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
37
|
+
/**
|
|
38
|
+
* Intersect two solid mesh objects
|
|
39
|
+
* @param inputs Contains multiple solids for intersection
|
|
40
|
+
* @returns Solid mesh
|
|
41
|
+
* @group boolean
|
|
42
|
+
* @shortname intersect two
|
|
43
|
+
* @drawable true
|
|
44
|
+
*/
|
|
13
45
|
intersectTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
46
|
+
/**
|
|
47
|
+
* Subtract two solid mesh objects
|
|
48
|
+
* @param inputs Contains multiple solids for subtraction
|
|
49
|
+
* @returns Solid mesh
|
|
50
|
+
* @group boolean
|
|
51
|
+
* @shortname subtract two
|
|
52
|
+
* @drawable true
|
|
53
|
+
*/
|
|
14
54
|
subtractTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
55
|
+
/**
|
|
56
|
+
* Union two solid mesh objects
|
|
57
|
+
* @param inputs Contains multiple solids for union
|
|
58
|
+
* @returns Solid mesh
|
|
59
|
+
* @group boolean
|
|
60
|
+
* @shortname union two
|
|
61
|
+
* @drawable true
|
|
62
|
+
*/
|
|
15
63
|
unionTwo(inputs: Inputs.JSCAD.BooleanTwoObjectsDto): Inputs.JSCAD.JSCADEntity;
|
|
64
|
+
/**
|
|
65
|
+
* Subtract multiple meshes from one mesh object
|
|
66
|
+
* @param inputs Contains mesh from which to subtract and multiple meshes for subtraction
|
|
67
|
+
* @returns mesh
|
|
68
|
+
* @group boolean
|
|
69
|
+
* @shortname subtract from
|
|
70
|
+
* @drawable true
|
|
71
|
+
*/
|
|
16
72
|
subtractFrom(inputs: Inputs.JSCAD.BooleanObjectsFromDto): Inputs.JSCAD.JSCADEntity;
|
|
17
73
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { asKind } from "./entity-narrowing";
|
|
1
2
|
/**
|
|
2
3
|
* Contains various functions for Solid booleans from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
4
|
* Thanks JSCAD community for developing this kernel
|
|
@@ -6,29 +7,85 @@ export class JSCADBooleans {
|
|
|
6
7
|
constructor(jscad) {
|
|
7
8
|
this.jscad = jscad;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Intersect multiple solid mesh objects
|
|
12
|
+
* @param inputs Contains multiple solids for intersection
|
|
13
|
+
* @returns Solid mesh
|
|
14
|
+
* @group boolean
|
|
15
|
+
* @shortname intersect
|
|
16
|
+
* @drawable true
|
|
17
|
+
*/
|
|
9
18
|
intersect(inputs) {
|
|
10
|
-
return this.jscad.booleans.intersect(...inputs.meshes);
|
|
19
|
+
return this.jscad.booleans.intersect(...asKind(inputs.meshes));
|
|
11
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Subtract multiple solid mesh objects
|
|
23
|
+
* @param inputs Contains multiple solids for subtraction
|
|
24
|
+
* @returns Solid mesh
|
|
25
|
+
* @group boolean
|
|
26
|
+
* @shortname subtract
|
|
27
|
+
* @drawable true
|
|
28
|
+
*/
|
|
12
29
|
subtract(inputs) {
|
|
13
|
-
return this.jscad.booleans.subtract(...inputs.meshes);
|
|
30
|
+
return this.jscad.booleans.subtract(...asKind(inputs.meshes));
|
|
14
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Union multiple solid mesh objects
|
|
34
|
+
* @param inputs Contains multiple solids for union
|
|
35
|
+
* @returns Solid mesh
|
|
36
|
+
* @group boolean
|
|
37
|
+
* @shortname union
|
|
38
|
+
* @drawable true
|
|
39
|
+
*/
|
|
15
40
|
union(inputs) {
|
|
16
|
-
return this.jscad.booleans.union(...inputs.meshes);
|
|
41
|
+
return this.jscad.booleans.union(...asKind(inputs.meshes));
|
|
17
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Intersect two solid mesh objects
|
|
45
|
+
* @param inputs Contains multiple solids for intersection
|
|
46
|
+
* @returns Solid mesh
|
|
47
|
+
* @group boolean
|
|
48
|
+
* @shortname intersect two
|
|
49
|
+
* @drawable true
|
|
50
|
+
*/
|
|
18
51
|
intersectTwo(inputs) {
|
|
19
|
-
const meshes = [inputs.first, inputs.second];
|
|
52
|
+
const meshes = asKind([inputs.first, inputs.second]);
|
|
20
53
|
return this.jscad.booleans.intersect(...meshes);
|
|
21
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Subtract two solid mesh objects
|
|
57
|
+
* @param inputs Contains multiple solids for subtraction
|
|
58
|
+
* @returns Solid mesh
|
|
59
|
+
* @group boolean
|
|
60
|
+
* @shortname subtract two
|
|
61
|
+
* @drawable true
|
|
62
|
+
*/
|
|
22
63
|
subtractTwo(inputs) {
|
|
23
|
-
const meshes = [inputs.first, inputs.second];
|
|
64
|
+
const meshes = asKind([inputs.first, inputs.second]);
|
|
24
65
|
return this.jscad.booleans.subtract(...meshes);
|
|
25
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Union two solid mesh objects
|
|
69
|
+
* @param inputs Contains multiple solids for union
|
|
70
|
+
* @returns Solid mesh
|
|
71
|
+
* @group boolean
|
|
72
|
+
* @shortname union two
|
|
73
|
+
* @drawable true
|
|
74
|
+
*/
|
|
26
75
|
unionTwo(inputs) {
|
|
27
|
-
const meshes = [inputs.first, inputs.second];
|
|
76
|
+
const meshes = asKind([inputs.first, inputs.second]);
|
|
28
77
|
return this.jscad.booleans.union(...meshes);
|
|
29
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Subtract multiple meshes from one mesh object
|
|
81
|
+
* @param inputs Contains mesh from which to subtract and multiple meshes for subtraction
|
|
82
|
+
* @returns mesh
|
|
83
|
+
* @group boolean
|
|
84
|
+
* @shortname subtract from
|
|
85
|
+
* @drawable true
|
|
86
|
+
*/
|
|
30
87
|
subtractFrom(inputs) {
|
|
31
|
-
const meshes = [inputs.from, ...inputs.meshes];
|
|
88
|
+
const meshes = asKind([inputs.from, ...inputs.meshes]);
|
|
32
89
|
return this.jscad.booleans.subtract(...meshes);
|
|
33
90
|
}
|
|
34
91
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
2
|
import * as JSCAD from "@jscad/modeling";
|
|
3
3
|
/**
|
|
4
|
-
* Contains
|
|
5
|
-
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
* Contains functions for colorizing objects
|
|
6
5
|
*/
|
|
7
6
|
export declare class JSCADColors {
|
|
8
7
|
private readonly jscad;
|
|
9
8
|
constructor(jscad: typeof JSCAD);
|
|
9
|
+
/**
|
|
10
|
+
* Colorizes geometry of jscad. If geometry is in the array it will colorize all items and return them. If geometry is a single item it will return a single item.
|
|
11
|
+
* Keep in mind that colorized geometry in jscad will always be drawn in that color even if you try to change it via draw options.
|
|
12
|
+
* @param inputs contain geometry and hex color
|
|
13
|
+
* @returns Colorized geometry of jsacd
|
|
14
|
+
* @group colorize
|
|
15
|
+
* @shortname colorize geometry
|
|
16
|
+
* @drawable true
|
|
17
|
+
*/
|
|
10
18
|
colorize(inputs: Inputs.JSCAD.ColorizeDto): Inputs.JSCAD.JSCADEntity | Inputs.JSCAD.JSCADEntity[];
|
|
11
19
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Contains
|
|
3
|
-
* Thanks JSCAD community for developing this kernel
|
|
2
|
+
* Contains functions for colorizing objects
|
|
4
3
|
*/
|
|
5
4
|
export class JSCADColors {
|
|
6
5
|
constructor(jscad) {
|
|
7
6
|
this.jscad = jscad;
|
|
8
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Colorizes geometry of jscad. If geometry is in the array it will colorize all items and return them. If geometry is a single item it will return a single item.
|
|
10
|
+
* Keep in mind that colorized geometry in jscad will always be drawn in that color even if you try to change it via draw options.
|
|
11
|
+
* @param inputs contain geometry and hex color
|
|
12
|
+
* @returns Colorized geometry of jsacd
|
|
13
|
+
* @group colorize
|
|
14
|
+
* @shortname colorize geometry
|
|
15
|
+
* @drawable true
|
|
16
|
+
*/
|
|
9
17
|
colorize(inputs) {
|
|
10
18
|
const geometry = inputs.geometry;
|
|
11
19
|
const color = inputs.color;
|
|
@@ -7,6 +7,22 @@ import * as JSCAD from "@jscad/modeling";
|
|
|
7
7
|
export declare class JSCADExpansions {
|
|
8
8
|
private readonly jscad;
|
|
9
9
|
constructor(jscad: typeof JSCAD);
|
|
10
|
+
/**
|
|
11
|
+
* Expand geometries of solid category
|
|
12
|
+
* @param inputs Contains options and geometries for expansion
|
|
13
|
+
* @returns Expanded geometry
|
|
14
|
+
* @group expansion
|
|
15
|
+
* @shortname expand
|
|
16
|
+
* @drawable true
|
|
17
|
+
*/
|
|
10
18
|
expand(inputs: Inputs.JSCAD.ExpansionDto): Inputs.JSCAD.JSCADEntity;
|
|
19
|
+
/**
|
|
20
|
+
* Offset 2d geometries of solid category
|
|
21
|
+
* @param inputs Contains options and geometries for offset
|
|
22
|
+
* @returns Expanded geometry
|
|
23
|
+
* @group expansion
|
|
24
|
+
* @shortname offset
|
|
25
|
+
* @drawable true
|
|
26
|
+
*/
|
|
11
27
|
offset(inputs: Inputs.JSCAD.ExpansionDto): Inputs.JSCAD.JSCADEntity;
|
|
12
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import { asEntity, asKind, oneOrMany } from "./entity-narrowing";
|
|
2
3
|
/**
|
|
3
4
|
* Contains various functions for Solid expansions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
4
5
|
* Thanks JSCAD community for developing this kernel
|
|
@@ -7,8 +8,16 @@ export class JSCADExpansions {
|
|
|
7
8
|
constructor(jscad) {
|
|
8
9
|
this.jscad = jscad;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Expand geometries of solid category
|
|
13
|
+
* @param inputs Contains options and geometries for expansion
|
|
14
|
+
* @returns Expanded geometry
|
|
15
|
+
* @group expansion
|
|
16
|
+
* @shortname expand
|
|
17
|
+
* @drawable true
|
|
18
|
+
*/
|
|
10
19
|
expand(inputs) {
|
|
11
|
-
const geometry = inputs.geometry
|
|
20
|
+
const geometry = asKind(oneOrMany(inputs.geometry));
|
|
12
21
|
if (!inputs.corners) {
|
|
13
22
|
inputs.corners = Inputs.JSCAD.solidCornerTypeEnum.round;
|
|
14
23
|
}
|
|
@@ -17,10 +26,18 @@ export class JSCADExpansions {
|
|
|
17
26
|
corners: inputs.corners,
|
|
18
27
|
segments: inputs.segments,
|
|
19
28
|
}, ...geometry);
|
|
20
|
-
return result;
|
|
29
|
+
return asEntity(result);
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Offset 2d geometries of solid category
|
|
33
|
+
* @param inputs Contains options and geometries for offset
|
|
34
|
+
* @returns Expanded geometry
|
|
35
|
+
* @group expansion
|
|
36
|
+
* @shortname offset
|
|
37
|
+
* @drawable true
|
|
38
|
+
*/
|
|
22
39
|
offset(inputs) {
|
|
23
|
-
const geometry = inputs.geometry
|
|
40
|
+
const geometry = asKind(oneOrMany(inputs.geometry));
|
|
24
41
|
if (!inputs.corners) {
|
|
25
42
|
inputs.corners = Inputs.JSCAD.solidCornerTypeEnum.edge;
|
|
26
43
|
}
|
|
@@ -29,6 +46,6 @@ export class JSCADExpansions {
|
|
|
29
46
|
corners: inputs.corners,
|
|
30
47
|
segments: inputs.segments,
|
|
31
48
|
}, ...geometry);
|
|
32
|
-
return result;
|
|
49
|
+
return asEntity(result);
|
|
33
50
|
}
|
|
34
51
|
}
|
|
@@ -11,8 +11,40 @@ export declare class JSCADExtrusions {
|
|
|
11
11
|
private readonly geometryHelper;
|
|
12
12
|
private readonly math;
|
|
13
13
|
constructor(jscad: typeof JSCAD, geometryHelper: GeometryHelper, math: MathBitByBit);
|
|
14
|
+
/**
|
|
15
|
+
* Linear extrude 2D geometries of solid category
|
|
16
|
+
* @param inputs Contains options and geometries for linear extrude
|
|
17
|
+
* @returns Extruded geometry
|
|
18
|
+
* @group extrude
|
|
19
|
+
* @shortname linear
|
|
20
|
+
* @drawable true
|
|
21
|
+
*/
|
|
14
22
|
extrudeLinear(inputs: Inputs.JSCAD.ExtrudeLinearDto): Inputs.JSCAD.JSCADEntity;
|
|
23
|
+
/**
|
|
24
|
+
* Rectangular extrude 2D geometries of solid category. Creates a wall-type extrusion of certain height and size.
|
|
25
|
+
* @param inputs Contains options and geometries for rectangular extrude
|
|
26
|
+
* @returns Extruded geometry
|
|
27
|
+
* @group extrude
|
|
28
|
+
* @shortname rectangular
|
|
29
|
+
* @drawable true
|
|
30
|
+
*/
|
|
15
31
|
extrudeRectangular(inputs: Inputs.JSCAD.ExtrudeRectangularDto): Inputs.JSCAD.JSCADEntity;
|
|
32
|
+
/**
|
|
33
|
+
* Rectangular extrude a list of 2D points. Creates a wall-type extrusion of certain height and size.
|
|
34
|
+
* @param inputs Contains options and points for extrusion
|
|
35
|
+
* @returns Extruded geometry
|
|
36
|
+
* @group extrude
|
|
37
|
+
* @shortname rectangular points
|
|
38
|
+
* @drawable true
|
|
39
|
+
*/
|
|
16
40
|
extrudeRectangularPoints(inputs: Inputs.JSCAD.ExtrudeRectangularPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
41
|
+
/**
|
|
42
|
+
* Rectangular extrude a list of 2D points. Creates a wall-type extrusion of certain height and size.
|
|
43
|
+
* @param inputs Contains options and points for extrusion
|
|
44
|
+
* @returns Extruded geometry
|
|
45
|
+
* @group extrude
|
|
46
|
+
* @shortname rotational
|
|
47
|
+
* @drawable true
|
|
48
|
+
*/
|
|
17
49
|
extrudeRotate(inputs: Inputs.JSCAD.ExtrudeRotateDto): Inputs.JSCAD.JSCADEntity;
|
|
18
50
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { asKind, asRegion, oneOrMany } from "./entity-narrowing";
|
|
1
2
|
/**
|
|
2
3
|
* Contains various functions for Solid extrusions from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
4
|
* Thanks JSCAD community for developing this kernel
|
|
@@ -8,9 +9,16 @@ export class JSCADExtrusions {
|
|
|
8
9
|
this.geometryHelper = geometryHelper;
|
|
9
10
|
this.math = math;
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Linear extrude 2D geometries of solid category
|
|
14
|
+
* @param inputs Contains options and geometries for linear extrude
|
|
15
|
+
* @returns Extruded geometry
|
|
16
|
+
* @group extrude
|
|
17
|
+
* @shortname linear
|
|
18
|
+
* @drawable true
|
|
19
|
+
*/
|
|
11
20
|
extrudeLinear(inputs) {
|
|
12
|
-
const
|
|
13
|
-
const geometry = multipleGeometries ? inputs.geometry : [inputs.geometry];
|
|
21
|
+
const geometry = asKind(oneOrMany(inputs.geometry));
|
|
14
22
|
const extrusions = this.jscad.extrusions.extrudeLinear({
|
|
15
23
|
height: inputs.height,
|
|
16
24
|
twistAngle: this.math.degToRad({ number: inputs.twistAngle }),
|
|
@@ -18,12 +26,27 @@ export class JSCADExtrusions {
|
|
|
18
26
|
}, ...geometry);
|
|
19
27
|
return extrusions;
|
|
20
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Rectangular extrude 2D geometries of solid category. Creates a wall-type extrusion of certain height and size.
|
|
31
|
+
* @param inputs Contains options and geometries for rectangular extrude
|
|
32
|
+
* @returns Extruded geometry
|
|
33
|
+
* @group extrude
|
|
34
|
+
* @shortname rectangular
|
|
35
|
+
* @drawable true
|
|
36
|
+
*/
|
|
21
37
|
extrudeRectangular(inputs) {
|
|
22
|
-
const
|
|
23
|
-
const geometry = multipleGeometries ? inputs.geometry : [inputs.geometry];
|
|
38
|
+
const geometry = asKind(oneOrMany(inputs.geometry));
|
|
24
39
|
const extrusions = this.jscad.extrusions.extrudeRectangular({ height: inputs.height, size: inputs.size }, ...geometry);
|
|
25
40
|
return extrusions;
|
|
26
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Rectangular extrude a list of 2D points. Creates a wall-type extrusion of certain height and size.
|
|
44
|
+
* @param inputs Contains options and points for extrusion
|
|
45
|
+
* @returns Extruded geometry
|
|
46
|
+
* @group extrude
|
|
47
|
+
* @shortname rectangular points
|
|
48
|
+
* @drawable true
|
|
49
|
+
*/
|
|
27
50
|
extrudeRectangularPoints(inputs) {
|
|
28
51
|
const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
|
|
29
52
|
const duplicatePointsRemoved = this.geometryHelper.removeConsecutiveVectorDuplicates(twoDimensionalPoints);
|
|
@@ -31,6 +54,14 @@ export class JSCADExtrusions {
|
|
|
31
54
|
const extrusion = this.extrudeRectangular({ height: inputs.height, size: inputs.size, geometry: path });
|
|
32
55
|
return extrusion;
|
|
33
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Rectangular extrude a list of 2D points. Creates a wall-type extrusion of certain height and size.
|
|
59
|
+
* @param inputs Contains options and points for extrusion
|
|
60
|
+
* @returns Extruded geometry
|
|
61
|
+
* @group extrude
|
|
62
|
+
* @shortname rotational
|
|
63
|
+
* @drawable true
|
|
64
|
+
*/
|
|
34
65
|
extrudeRotate(inputs) {
|
|
35
66
|
const options = {
|
|
36
67
|
angle: this.math.degToRad({ number: inputs.angle }),
|
|
@@ -38,7 +69,7 @@ export class JSCADExtrusions {
|
|
|
38
69
|
overflow: "cap",
|
|
39
70
|
segments: inputs.segments
|
|
40
71
|
};
|
|
41
|
-
const extrusion = this.jscad.extrusions.extrudeRotate(options, inputs.polygon);
|
|
72
|
+
const extrusion = this.jscad.extrusions.extrudeRotate(options, asRegion(inputs.polygon, "extrudeRotate"));
|
|
42
73
|
return extrusion;
|
|
43
74
|
}
|
|
44
75
|
}
|
|
@@ -7,6 +7,24 @@ import * as JSCAD from "@jscad/modeling";
|
|
|
7
7
|
export declare class JSCADHulls {
|
|
8
8
|
private readonly jscad;
|
|
9
9
|
constructor(jscad: typeof JSCAD);
|
|
10
|
+
/**
|
|
11
|
+
* Hull chain connects solids or 2d geometries by filling an empty space in between objects in order.
|
|
12
|
+
* Geometries need to be of the same type.
|
|
13
|
+
* @param inputs Geometries
|
|
14
|
+
* @returns Chain hulled geometry
|
|
15
|
+
* @group hulls
|
|
16
|
+
* @shortname hull chain
|
|
17
|
+
* @drawable true
|
|
18
|
+
*/
|
|
10
19
|
hullChain(inputs: Inputs.JSCAD.HullDto): Inputs.JSCAD.JSCADEntity;
|
|
20
|
+
/**
|
|
21
|
+
* Convex hull connects solids or 2d geometries by filling an empty space in between without following order.
|
|
22
|
+
* Geometries need to be of the same type.
|
|
23
|
+
* @param inputs Geometries
|
|
24
|
+
* @returns Hulled geometry
|
|
25
|
+
* @group hulls
|
|
26
|
+
* @shortname hull
|
|
27
|
+
* @drawable true
|
|
28
|
+
*/
|
|
11
29
|
hull(inputs: Inputs.JSCAD.HullDto): Inputs.JSCAD.JSCADEntity;
|
|
12
30
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { asKind } from "./entity-narrowing";
|
|
1
2
|
/**
|
|
2
3
|
* Contains various functions for Solid hulls from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
4
|
* Thanks JSCAD community for developing this kernel
|
|
@@ -6,10 +7,28 @@ export class JSCADHulls {
|
|
|
6
7
|
constructor(jscad) {
|
|
7
8
|
this.jscad = jscad;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Hull chain connects solids or 2d geometries by filling an empty space in between objects in order.
|
|
12
|
+
* Geometries need to be of the same type.
|
|
13
|
+
* @param inputs Geometries
|
|
14
|
+
* @returns Chain hulled geometry
|
|
15
|
+
* @group hulls
|
|
16
|
+
* @shortname hull chain
|
|
17
|
+
* @drawable true
|
|
18
|
+
*/
|
|
9
19
|
hullChain(inputs) {
|
|
10
|
-
return this.jscad.hulls.hullChain(...inputs.meshes);
|
|
20
|
+
return this.jscad.hulls.hullChain(...asKind(inputs.meshes));
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Convex hull connects solids or 2d geometries by filling an empty space in between without following order.
|
|
24
|
+
* Geometries need to be of the same type.
|
|
25
|
+
* @param inputs Geometries
|
|
26
|
+
* @returns Hulled geometry
|
|
27
|
+
* @group hulls
|
|
28
|
+
* @shortname hull
|
|
29
|
+
* @drawable true
|
|
30
|
+
*/
|
|
12
31
|
hull(inputs) {
|
|
13
|
-
return this.jscad.hulls.hull(...inputs.meshes);
|
|
32
|
+
return this.jscad.hulls.hull(...asKind(inputs.meshes));
|
|
14
33
|
}
|
|
15
34
|
}
|
|
@@ -11,13 +11,76 @@ export declare class JSCADPath {
|
|
|
11
11
|
private readonly geometryHelper;
|
|
12
12
|
private readonly math;
|
|
13
13
|
constructor(jscad: typeof JSCAD, geometryHelper: GeometryHelper, math: MathBitByBit);
|
|
14
|
+
/**
|
|
15
|
+
* Create a 2D path from a list of points
|
|
16
|
+
* @param inputs Points and indication if we want a closed path or not
|
|
17
|
+
* @returns Path
|
|
18
|
+
* @group from
|
|
19
|
+
* @shortname points
|
|
20
|
+
* @drawable true
|
|
21
|
+
*/
|
|
14
22
|
createFromPoints(inputs: Inputs.JSCAD.PathFromPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
23
|
+
/**
|
|
24
|
+
* Create 2D paths from a lists of points
|
|
25
|
+
* @param inputs Points lists
|
|
26
|
+
* @returns Paths
|
|
27
|
+
* @group from
|
|
28
|
+
* @shortname paths from points
|
|
29
|
+
* @drawable true
|
|
30
|
+
*/
|
|
15
31
|
createPathsFromPoints(inputs: Inputs.JSCAD.PathsFromPointsDto): Inputs.JSCAD.JSCADEntity[];
|
|
32
|
+
/**
|
|
33
|
+
* Create a 2D path from a polyline
|
|
34
|
+
* @param inputs Polyline and indication if we want a closed path or not
|
|
35
|
+
* @returns Path
|
|
36
|
+
* @group from
|
|
37
|
+
* @shortname polyline
|
|
38
|
+
* @drawable true
|
|
39
|
+
*/
|
|
16
40
|
createFromPolyline(inputs: Inputs.JSCAD.PathFromPolylineDto): Inputs.JSCAD.JSCADEntity;
|
|
41
|
+
/**
|
|
42
|
+
* Create empty 2D path
|
|
43
|
+
* @returns Empty path
|
|
44
|
+
* @group create
|
|
45
|
+
* @shortname empty
|
|
46
|
+
* @drawable false
|
|
47
|
+
*/
|
|
17
48
|
createEmpty(): Inputs.JSCAD.JSCADEntity;
|
|
49
|
+
/**
|
|
50
|
+
* Closes an open 2D path
|
|
51
|
+
* @param inputs Path
|
|
52
|
+
* @returns Closed path
|
|
53
|
+
* @group edit
|
|
54
|
+
* @shortname close
|
|
55
|
+
* @drawable true
|
|
56
|
+
*/
|
|
18
57
|
close(inputs: Inputs.JSCAD.PathDto): Inputs.JSCAD.JSCADEntity;
|
|
58
|
+
/**
|
|
59
|
+
* Append the path with 2D points
|
|
60
|
+
* @param inputs Path to append and points
|
|
61
|
+
* @returns Appended path
|
|
62
|
+
* @group append
|
|
63
|
+
* @shortname points
|
|
64
|
+
* @drawable true
|
|
65
|
+
*/
|
|
19
66
|
appendPoints(inputs: Inputs.JSCAD.PathAppendPointsDto): Inputs.JSCAD.JSCADEntity;
|
|
67
|
+
/**
|
|
68
|
+
* Append the path with polyline
|
|
69
|
+
* @param inputs Path to append and polyline
|
|
70
|
+
* @returns Appended path
|
|
71
|
+
* @group append
|
|
72
|
+
* @shortname polyline
|
|
73
|
+
* @drawable true
|
|
74
|
+
*/
|
|
20
75
|
appendPolyline(inputs: Inputs.JSCAD.PathAppendPolylineDto): Inputs.JSCAD.JSCADEntity;
|
|
76
|
+
/**
|
|
77
|
+
* Append the arc to the path
|
|
78
|
+
* @param inputs Path and arc parameters
|
|
79
|
+
* @returns Appended path
|
|
80
|
+
* @group append
|
|
81
|
+
* @shortname arc
|
|
82
|
+
* @drawable true
|
|
83
|
+
*/
|
|
21
84
|
appendArc(inputs: Inputs.JSCAD.PathAppendArcDto): Inputs.JSCAD.JSCADEntity;
|
|
22
85
|
private removeDuplicatesAndCreateFromPoints;
|
|
23
86
|
}
|