Skip to content

Commit

Permalink
Add MCAD library
Browse files Browse the repository at this point in the history
  • Loading branch information
DSchroer committed Mar 13, 2022
1 parent 6bfea09 commit 3d988de
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ libs/mpfr-4.1.0:
rm mpfr-4.1.0.tar.xz

res: \
res/liberation
res/liberation \
res/MCAD

res/liberation:
git clone --recurse https://github.com/shantigilbert/liberation-fonts-ttf.git ${SHALLOW} ${SINGLE_BRANCH} $@

res/MCAD:
git clone https://github.com/openscad/MCAD.git ${SHALLOW} ${SINGLE_BRANCH} $@
2 changes: 1 addition & 1 deletion runtime/plugins/embed-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function embedFile() {
async function loadFolder(path) {
const files = {};

const res = await promisify(glob)("**/*", { cwd: resolve(path) });
const res = await promisify(glob)("**/*", { cwd: resolve(path), nodir: true });
for (const file of res) {
files[file] = readFileSync(join(path, file)).toString("hex");
}
Expand Down
9 changes: 7 additions & 2 deletions runtime/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const bundle = (name) => ({
file: `dist/${name}.js`,
format: "esm",
},
plugins: [embedFile(), typescript({ tsconfig: "./tsconfig.json" })],
plugins: [
embedFile(),
typescript({ tsconfig: "./tsconfig.json" })],
});

export default [bundle("openscad.fonts")];
export default [
bundle("openscad.fonts"),
bundle("openscad.mcad")
];
3 changes: 3 additions & 0 deletions runtime/src/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function fromHex(hex: string): Uint8Array {
return new Uint8Array(hex.match(/../g)!.map((h) => parseInt(h, 16)));
}
6 changes: 2 additions & 4 deletions runtime/src/openscad.fonts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { OpenSCAD } from "./openscad";
import { fromHex } from "./files";

import config from "../../res/fonts/fonts.conf";
import fonts from "../../res/liberation";

Expand All @@ -9,7 +11,3 @@ export function addFonts(openscad: OpenSCAD) {
openscad.FS.writeFile("/fonts/" + file, fromHex(data));
}
}

function fromHex(hex: string): Uint8Array {
return new Uint8Array(hex.match(/../g)!.map(h=>parseInt(h,16)))
}
13 changes: 13 additions & 0 deletions runtime/src/openscad.mcad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OpenSCAD } from "./openscad";
import { fromHex } from "./files";

import mcad from "../../res/MCAD";

export function addMCAD(openscad: OpenSCAD) {
openscad.FS.mkdir("/libraries");
openscad.FS.mkdir("/libraries/MCAD");

for (const [file, data] of Object.entries(mcad as Record<string, string>)) {
openscad.FS.writeFile("/libraries/MCAD/" + file, fromHex(data));
}
}

0 comments on commit 3d988de

Please sign in to comment.