Skip to content

Commit 3d988de

Browse files
committed
Add MCAD library
1 parent 6bfea09 commit 3d988de

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ libs/mpfr-4.1.0:
129129
rm mpfr-4.1.0.tar.xz
130130

131131
res: \
132-
res/liberation
132+
res/liberation \
133+
res/MCAD
133134

134135
res/liberation:
135136
git clone --recurse https://github.com/shantigilbert/liberation-fonts-ttf.git ${SHALLOW} ${SINGLE_BRANCH} $@
137+
138+
res/MCAD:
139+
git clone https://github.com/openscad/MCAD.git ${SHALLOW} ${SINGLE_BRANCH} $@

runtime/plugins/embed-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function embedFile() {
1313
async function loadFolder(path) {
1414
const files = {};
1515

16-
const res = await promisify(glob)("**/*", { cwd: resolve(path) });
16+
const res = await promisify(glob)("**/*", { cwd: resolve(path), nodir: true });
1717
for (const file of res) {
1818
files[file] = readFileSync(join(path, file)).toString("hex");
1919
}

runtime/rollup.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const bundle = (name) => ({
77
file: `dist/${name}.js`,
88
format: "esm",
99
},
10-
plugins: [embedFile(), typescript({ tsconfig: "./tsconfig.json" })],
10+
plugins: [
11+
embedFile(),
12+
typescript({ tsconfig: "./tsconfig.json" })],
1113
});
1214

13-
export default [bundle("openscad.fonts")];
15+
export default [
16+
bundle("openscad.fonts"),
17+
bundle("openscad.mcad")
18+
];

runtime/src/files.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function fromHex(hex: string): Uint8Array {
2+
return new Uint8Array(hex.match(/../g)!.map((h) => parseInt(h, 16)));
3+
}

runtime/src/openscad.fonts.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { OpenSCAD } from "./openscad";
2+
import { fromHex } from "./files";
3+
24
import config from "../../res/fonts/fonts.conf";
35
import fonts from "../../res/liberation";
46

@@ -9,7 +11,3 @@ export function addFonts(openscad: OpenSCAD) {
911
openscad.FS.writeFile("/fonts/" + file, fromHex(data));
1012
}
1113
}
12-
13-
function fromHex(hex: string): Uint8Array {
14-
return new Uint8Array(hex.match(/../g)!.map(h=>parseInt(h,16)))
15-
}

runtime/src/openscad.mcad.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { OpenSCAD } from "./openscad";
2+
import { fromHex } from "./files";
3+
4+
import mcad from "../../res/MCAD";
5+
6+
export function addMCAD(openscad: OpenSCAD) {
7+
openscad.FS.mkdir("/libraries");
8+
openscad.FS.mkdir("/libraries/MCAD");
9+
10+
for (const [file, data] of Object.entries(mcad as Record<string, string>)) {
11+
openscad.FS.writeFile("/libraries/MCAD/" + file, fromHex(data));
12+
}
13+
}

0 commit comments

Comments
 (0)