@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,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for solid 3D shapes from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADShapes {
|
|
6
|
+
constructor(jscad, math) {
|
|
7
|
+
this.math = math;
|
|
8
|
+
this.jscad = jscad;
|
|
9
|
+
}
|
|
10
|
+
cube(inputs) {
|
|
11
|
+
return this.jscad.primitives.cube({
|
|
12
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
13
|
+
size: inputs.size
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
cubesOnCenterPoints(inputs) {
|
|
17
|
+
return inputs.centers.map(center => {
|
|
18
|
+
return this.cube({ center, size: inputs.size });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
cuboid(inputs) {
|
|
22
|
+
return this.jscad.primitives.cuboid({
|
|
23
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
24
|
+
size: [inputs.width, inputs.height, inputs.length]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
cuboidsOnCenterPoints(inputs) {
|
|
28
|
+
return inputs.centers.map(center => {
|
|
29
|
+
return this.cuboid({
|
|
30
|
+
center,
|
|
31
|
+
width: inputs.width,
|
|
32
|
+
length: inputs.length,
|
|
33
|
+
height: inputs.height
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
cylinderElliptic(inputs) {
|
|
38
|
+
return this.jscad.primitives.cylinderElliptic({
|
|
39
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
40
|
+
height: inputs.height,
|
|
41
|
+
startRadius: [inputs.startRadius[0], inputs.startRadius[1]],
|
|
42
|
+
endRadius: [inputs.endRadius[0], inputs.endRadius[1]],
|
|
43
|
+
segments: inputs.segments,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
cylinderEllipticOnCenterPoints(inputs) {
|
|
47
|
+
return inputs.centers.map(center => {
|
|
48
|
+
return this.cylinderElliptic({
|
|
49
|
+
center,
|
|
50
|
+
height: inputs.height,
|
|
51
|
+
startRadius: inputs.startRadius,
|
|
52
|
+
endRadius: inputs.endRadius,
|
|
53
|
+
segments: inputs.segments
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
cylinder(inputs) {
|
|
58
|
+
return this.jscad.primitives.cylinder({
|
|
59
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
60
|
+
height: inputs.height,
|
|
61
|
+
radius: inputs.radius,
|
|
62
|
+
segments: inputs.segments,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
cylindersOnCenterPoints(inputs) {
|
|
66
|
+
return inputs.centers.map(center => {
|
|
67
|
+
return this.cylinder({
|
|
68
|
+
center,
|
|
69
|
+
height: inputs.height,
|
|
70
|
+
radius: inputs.radius,
|
|
71
|
+
segments: inputs.segments
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
ellipsoid(inputs) {
|
|
76
|
+
return this.jscad.primitives.ellipsoid({
|
|
77
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
78
|
+
radius: [inputs.radius[0], inputs.radius[1], inputs.radius[2]],
|
|
79
|
+
segments: inputs.segments,
|
|
80
|
+
axes: [
|
|
81
|
+
[-1, 0, 0],
|
|
82
|
+
[0, -1, 0],
|
|
83
|
+
[0, 0, -1],
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
ellipsoidsOnCenterPoints(inputs) {
|
|
88
|
+
return inputs.centers.map(center => {
|
|
89
|
+
return this.ellipsoid({
|
|
90
|
+
center,
|
|
91
|
+
radius: inputs.radius,
|
|
92
|
+
segments: inputs.segments
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
geodesicSphere(inputs) {
|
|
97
|
+
let sphere = this.jscad.primitives.geodesicSphere({ radius: inputs.radius, frequency: inputs.frequency });
|
|
98
|
+
sphere = this.jscad.transforms.translate([inputs.center[0], inputs.center[1], inputs.center[2]], sphere);
|
|
99
|
+
return sphere;
|
|
100
|
+
}
|
|
101
|
+
geodesicSpheresOnCenterPoints(inputs) {
|
|
102
|
+
return inputs.centers.map(center => {
|
|
103
|
+
return this.geodesicSphere({
|
|
104
|
+
center,
|
|
105
|
+
radius: inputs.radius,
|
|
106
|
+
frequency: inputs.frequency
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
roundedCuboid(inputs) {
|
|
111
|
+
return this.jscad.primitives.roundedCuboid({
|
|
112
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
113
|
+
size: [inputs.width, inputs.height, inputs.length],
|
|
114
|
+
roundRadius: inputs.roundRadius,
|
|
115
|
+
segments: inputs.segments,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
roundedCuboidsOnCenterPoints(inputs) {
|
|
119
|
+
return inputs.centers.map(center => {
|
|
120
|
+
return this.roundedCuboid({
|
|
121
|
+
center,
|
|
122
|
+
width: inputs.width,
|
|
123
|
+
height: inputs.height,
|
|
124
|
+
length: inputs.length,
|
|
125
|
+
roundRadius: inputs.roundRadius,
|
|
126
|
+
segments: inputs.segments
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
roundedCylinder(inputs) {
|
|
131
|
+
return this.jscad.primitives.roundedCylinder({
|
|
132
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
133
|
+
height: inputs.height,
|
|
134
|
+
radius: inputs.radius,
|
|
135
|
+
roundRadius: inputs.roundRadius,
|
|
136
|
+
segments: inputs.segments,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
roundedCylindersOnCenterPoints(inputs) {
|
|
140
|
+
return inputs.centers.map(center => {
|
|
141
|
+
return this.roundedCylinder({
|
|
142
|
+
center,
|
|
143
|
+
radius: inputs.radius,
|
|
144
|
+
roundRadius: inputs.roundRadius,
|
|
145
|
+
segments: inputs.segments,
|
|
146
|
+
height: inputs.height,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
sphere(inputs) {
|
|
151
|
+
return this.jscad.primitives.sphere({
|
|
152
|
+
center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
153
|
+
radius: inputs.radius,
|
|
154
|
+
segments: inputs.segments
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
spheresOnCenterPoints(inputs) {
|
|
158
|
+
return inputs.centers.map(center => {
|
|
159
|
+
return this.sphere({
|
|
160
|
+
center,
|
|
161
|
+
radius: inputs.radius,
|
|
162
|
+
segments: inputs.segments,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
torus(inputs) {
|
|
167
|
+
return this.jscad.primitives.torus({
|
|
168
|
+
// center: [inputs.center[0], inputs.center[1], inputs.center[2]],
|
|
169
|
+
innerRadius: inputs.innerRadius,
|
|
170
|
+
outerRadius: inputs.outerRadius,
|
|
171
|
+
innerSegments: inputs.innerSegments,
|
|
172
|
+
outerSegments: inputs.outerSegments,
|
|
173
|
+
innerRotation: this.math.degToRad({ number: inputs.innerRotation }),
|
|
174
|
+
outerRotation: this.math.degToRad({ number: inputs.outerRotation }),
|
|
175
|
+
startAngle: this.math.degToRad({ number: inputs.startAngle }),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
fromPolygonPoints(inputs) {
|
|
179
|
+
const pts = inputs.polygonPoints.map(vertices => vertices.reverse());
|
|
180
|
+
return this.jscad.geometries.geom3.fromPoints(pts);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import * as JSCAD from "@jscad/modeling";
|
|
3
|
+
/**
|
|
4
|
+
* Contains various functions for solid 3D texts from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
5
|
+
* Thanks JSCAD community for developing this kernel
|
|
6
|
+
*/
|
|
7
|
+
export declare class JSCADText {
|
|
8
|
+
private readonly jscad;
|
|
9
|
+
constructor(jscad: typeof JSCAD);
|
|
10
|
+
cylindricalText(inputs: Inputs.JSCAD.CylinderTextDto): Inputs.JSCAD.JSCADEntity[];
|
|
11
|
+
sphericalText(inputs: Inputs.JSCAD.SphereTextDto): Inputs.JSCAD.JSCADEntity[];
|
|
12
|
+
private adjustTextToBeOnCenter;
|
|
13
|
+
createVectorText(inputs: Inputs.JSCAD.TextDto): JSCAD.text.VectorText;
|
|
14
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various functions for solid 3D texts from JSCAD library https://github.com/jscad/OpenJSCAD.org
|
|
3
|
+
* Thanks JSCAD community for developing this kernel
|
|
4
|
+
*/
|
|
5
|
+
export class JSCADText {
|
|
6
|
+
constructor(jscad) {
|
|
7
|
+
this.jscad = jscad;
|
|
8
|
+
}
|
|
9
|
+
cylindricalText(inputs) {
|
|
10
|
+
const text = this.createVectorText(inputs);
|
|
11
|
+
this.adjustTextToBeOnCenter(text);
|
|
12
|
+
return text.map(txt => {
|
|
13
|
+
const cylinders = txt.map(center => {
|
|
14
|
+
return this.jscad.primitives.cylinder({
|
|
15
|
+
center: [center[0], center[1], 0],
|
|
16
|
+
height: inputs.extrusionHeight,
|
|
17
|
+
radius: inputs.extrusionSize,
|
|
18
|
+
segments: inputs.segments,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return this.jscad.hulls.hullChain(...cylinders);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
sphericalText(inputs) {
|
|
25
|
+
const text = this.createVectorText(inputs);
|
|
26
|
+
this.adjustTextToBeOnCenter(text);
|
|
27
|
+
return text.map(txt => {
|
|
28
|
+
const spheres = txt.map(center => {
|
|
29
|
+
return this.jscad.primitives.sphere({
|
|
30
|
+
center: [center[0], center[1], 0],
|
|
31
|
+
radius: inputs.radius,
|
|
32
|
+
segments: inputs.segments,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return this.jscad.hulls.hullChain(...spheres);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
adjustTextToBeOnCenter(text) {
|
|
39
|
+
let maxX = 0;
|
|
40
|
+
text.forEach(txt => {
|
|
41
|
+
txt.forEach(center => {
|
|
42
|
+
if (center[0] > maxX) {
|
|
43
|
+
maxX = center[0];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const compensate = maxX / 2;
|
|
48
|
+
text.forEach(txt => {
|
|
49
|
+
txt.forEach(center => {
|
|
50
|
+
let z = center[0];
|
|
51
|
+
z = z - compensate;
|
|
52
|
+
center[0] = z;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
createVectorText(inputs) {
|
|
57
|
+
return this.jscad.text.vectorText({
|
|
58
|
+
input: inputs.text,
|
|
59
|
+
xOffset: inputs.xOffset,
|
|
60
|
+
yOffset: inputs.yOffset,
|
|
61
|
+
height: inputs.height,
|
|
62
|
+
lineSpacing: inputs.lineSpacing,
|
|
63
|
+
letterSpacing: inputs.letterSpacing,
|
|
64
|
+
align: inputs.align,
|
|
65
|
+
extrudeOffset: inputs.extrudeOffset,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitbybit-dev/jscad",
|
|
3
|
+
"version": "0.19.0-alpha.0",
|
|
4
|
+
"description": "Bit By Bit Developers JSCAD based CAD Library to Program Geometry",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/bitbybit-dev/bitbybit"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Bit By Bit Developers",
|
|
12
|
+
"bitbybit",
|
|
13
|
+
"bitbybit.dev",
|
|
14
|
+
"Geometry",
|
|
15
|
+
"CAD",
|
|
16
|
+
"3D",
|
|
17
|
+
"JSCAD",
|
|
18
|
+
"OCCT",
|
|
19
|
+
"OpenCascade",
|
|
20
|
+
"Creative coding",
|
|
21
|
+
"CSG",
|
|
22
|
+
"Mesh",
|
|
23
|
+
"Meshing",
|
|
24
|
+
"Manifold",
|
|
25
|
+
"Manifold-3D",
|
|
26
|
+
"WebGL",
|
|
27
|
+
"WebGPU",
|
|
28
|
+
"Parametric",
|
|
29
|
+
"Modeling",
|
|
30
|
+
"Browser CAD",
|
|
31
|
+
"3D algorithms",
|
|
32
|
+
"3D modeling",
|
|
33
|
+
"3D printing",
|
|
34
|
+
"3D printing algorithms",
|
|
35
|
+
"3D software",
|
|
36
|
+
"OpenCascade Technology",
|
|
37
|
+
"AEC",
|
|
38
|
+
"Automotive",
|
|
39
|
+
"Engineering",
|
|
40
|
+
"CAE",
|
|
41
|
+
"CAM"
|
|
42
|
+
],
|
|
43
|
+
"directories": {
|
|
44
|
+
"lib": "lib"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc -p tsconfig.bitbybit.json",
|
|
48
|
+
"build-p": "npm run build && npm run copy-package && npm run copy-readme && npm run delete-coverage",
|
|
49
|
+
"copy-package": "cp -R ./package.json ./dist",
|
|
50
|
+
"copy-readme": "cp -R ./README.md ./dist && cp -R ./LICENSE ./dist",
|
|
51
|
+
"delete-coverage": "rm -R ./dist/coverage",
|
|
52
|
+
"test": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --watchAll=true",
|
|
53
|
+
"test-c": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --coverage --watchAll=false",
|
|
54
|
+
"test-c-l": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --coverage --watchAll=true"
|
|
55
|
+
},
|
|
56
|
+
"author": "Bit by bit developers",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"types": "./index.d.ts",
|
|
59
|
+
"type": "module",
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@bitbybit-dev/base": "0.19.0-alpha.0",
|
|
62
|
+
"@jscad/io-utils": "2.0.28",
|
|
63
|
+
"@jscad/modeling": "2.12.3",
|
|
64
|
+
"@jscad/stl-serializer": "2.1.18",
|
|
65
|
+
"@jscad/dxf-serializer": "2.1.18",
|
|
66
|
+
"@jscad/3mf-serializer": "2.1.12"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"sass": "1.57.1",
|
|
70
|
+
"@testing-library/jest-dom": "5.14.1",
|
|
71
|
+
"mvdir": "1.0.21",
|
|
72
|
+
"jest": "29.4.1",
|
|
73
|
+
"ts-node": "10.9.1",
|
|
74
|
+
"ts-jest": "29.0.0",
|
|
75
|
+
"typescript": "4.8.2",
|
|
76
|
+
"@types/jest": "29.0.0",
|
|
77
|
+
"@types/three": "0.169.0",
|
|
78
|
+
"babel-jest": "29.0.0",
|
|
79
|
+
"@babel/core": "7.16.0",
|
|
80
|
+
"@babel/preset-env": "7.16.0",
|
|
81
|
+
"@babel/preset-typescript": "7.16.0",
|
|
82
|
+
"jest-html-reporters": "3.0.11"
|
|
83
|
+
},
|
|
84
|
+
"jest": {
|
|
85
|
+
"preset": "ts-jest",
|
|
86
|
+
"transform": {
|
|
87
|
+
"\\.[jt]sx?$": "babel-jest"
|
|
88
|
+
},
|
|
89
|
+
"extensionsToTreatAsEsm": [
|
|
90
|
+
".ts"
|
|
91
|
+
],
|
|
92
|
+
"transformIgnorePatterns": [
|
|
93
|
+
"node_modules/(?!@bitbybit-dev)/"
|
|
94
|
+
],
|
|
95
|
+
"collectCoverageFrom": [
|
|
96
|
+
"lib/api/**/*"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|