hyperbook 0.99.0 → 0.99.1
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.
|
@@ -34436,12 +34436,68 @@ void main() {
|
|
|
34436
34436
|
}
|
|
34437
34437
|
return { vertices, faces, colors };
|
|
34438
34438
|
};
|
|
34439
|
+
var splitByColor = (vertices, faces, colorCount) => {
|
|
34440
|
+
const groups = Array.from({ length: colorCount }, () => ({ faceIndices: [] }));
|
|
34441
|
+
faces.forEach((face, faceIdx) => {
|
|
34442
|
+
groups[face.colorIndex].faceIndices.push(faceIdx);
|
|
34443
|
+
});
|
|
34444
|
+
return groups.filter((g) => g.faceIndices.length > 0).map(({ faceIndices }, groupIdx) => {
|
|
34445
|
+
const oldToNew = /* @__PURE__ */ new Map();
|
|
34446
|
+
const groupVertices = [];
|
|
34447
|
+
for (const faceIdx of faceIndices) {
|
|
34448
|
+
for (const vIdx of faces[faceIdx].vertices) {
|
|
34449
|
+
if (!oldToNew.has(vIdx)) {
|
|
34450
|
+
oldToNew.set(vIdx, groupVertices.length);
|
|
34451
|
+
groupVertices.push(vertices[vIdx]);
|
|
34452
|
+
}
|
|
34453
|
+
}
|
|
34454
|
+
}
|
|
34455
|
+
const groupFaces = faceIndices.map((faceIdx) => ({
|
|
34456
|
+
...faces[faceIdx],
|
|
34457
|
+
vertices: faces[faceIdx].vertices.map((vIdx) => oldToNew.get(vIdx))
|
|
34458
|
+
}));
|
|
34459
|
+
return { vertices: groupVertices, faces: groupFaces };
|
|
34460
|
+
});
|
|
34461
|
+
};
|
|
34439
34462
|
var exportIndexedPolyhedronTo3mf = (polyhedron) => {
|
|
34440
|
-
const objectUuid = createUuid();
|
|
34441
34463
|
const buildUuid = createUuid();
|
|
34442
34464
|
const extruderIndexByColorIndex = polyhedron.colors.map(
|
|
34443
34465
|
(_, idx) => idx % PAINT_COLOR_MAP.length
|
|
34444
34466
|
);
|
|
34467
|
+
const materialsId = 1;
|
|
34468
|
+
const components = splitByColor(polyhedron.vertices, polyhedron.faces, polyhedron.colors.length);
|
|
34469
|
+
const objectXmls = components.map((comp, compIdx) => {
|
|
34470
|
+
const objectId = compIdx + 2;
|
|
34471
|
+
const objectUuid = createUuid();
|
|
34472
|
+
const colorIndex = comp.faces[0]?.colorIndex ?? 0;
|
|
34473
|
+
const paintColor = PAINT_COLOR_MAP[extruderIndexByColorIndex[colorIndex]];
|
|
34474
|
+
return [
|
|
34475
|
+
`<object id="${objectId}" name="OpenSCAD Model ${compIdx + 1}" type="model" p:UUID="${objectUuid}" pid="${materialsId}" pindex="${colorIndex}">`,
|
|
34476
|
+
"<mesh>",
|
|
34477
|
+
"<vertices>",
|
|
34478
|
+
...comp.vertices.map(
|
|
34479
|
+
(vertex2) => `<vertex x="${vertex2.x}" y="${vertex2.y}" z="${vertex2.z}" />`
|
|
34480
|
+
),
|
|
34481
|
+
"</vertices>",
|
|
34482
|
+
"<triangles>",
|
|
34483
|
+
...comp.faces.map((face) => {
|
|
34484
|
+
const [v1, v2, v3] = face.vertices;
|
|
34485
|
+
const attrs = [`v1="${v1}"`, `v2="${v2}"`, `v3="${v3}"`];
|
|
34486
|
+
if (paintColor) {
|
|
34487
|
+
attrs.push(`paint_color="${paintColor}"`);
|
|
34488
|
+
}
|
|
34489
|
+
return `<triangle ${attrs.join(" ")} />`;
|
|
34490
|
+
}),
|
|
34491
|
+
"</triangles>",
|
|
34492
|
+
"</mesh>",
|
|
34493
|
+
"</object>"
|
|
34494
|
+
].join("\n");
|
|
34495
|
+
});
|
|
34496
|
+
const buildItems = components.map((_, compIdx) => {
|
|
34497
|
+
const objectId = compIdx + 2;
|
|
34498
|
+
const objectUuid = createUuid();
|
|
34499
|
+
return `<item objectid="${objectId}" p:UUID="${objectUuid}"/>`;
|
|
34500
|
+
});
|
|
34445
34501
|
const modelXml = [
|
|
34446
34502
|
'<?xml version="1.0" encoding="utf-8"?>',
|
|
34447
34503
|
'<model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02" xmlns:p="http://schemas.microsoft.com/3dmanufacturing/production/2015/06">',
|
|
@@ -34449,37 +34505,15 @@ void main() {
|
|
|
34449
34505
|
'<meta name="slic3rpe:Version3mf" value="1"/>',
|
|
34450
34506
|
'<meta name="slic3rpe:MmPaintingVersion" value="1"/>',
|
|
34451
34507
|
"<resources>",
|
|
34452
|
-
|
|
34508
|
+
`<basematerials id="${materialsId}">`,
|
|
34453
34509
|
...polyhedron.colors.map(
|
|
34454
34510
|
(color, i) => `<base name="color_${i}" displaycolor="${colorToDisplayColor(color)}"/>`
|
|
34455
34511
|
),
|
|
34456
34512
|
"</basematerials>",
|
|
34457
|
-
|
|
34458
|
-
"<mesh>",
|
|
34459
|
-
"<vertices>",
|
|
34460
|
-
...polyhedron.vertices.map(
|
|
34461
|
-
(vertex2) => `<vertex x="${vertex2.x}" y="${vertex2.y}" z="${vertex2.z}" />`
|
|
34462
|
-
),
|
|
34463
|
-
"</vertices>",
|
|
34464
|
-
"<triangles>",
|
|
34465
|
-
...polyhedron.faces.map((face) => {
|
|
34466
|
-
const [v1, v2, v3] = face.vertices;
|
|
34467
|
-
const attrs = [`v1="${v1}"`, `v2="${v2}"`, `v3="${v3}"`];
|
|
34468
|
-
if (face.colorIndex > 0) {
|
|
34469
|
-
attrs.push(`pid="2"`, `p1="${face.colorIndex}"`);
|
|
34470
|
-
}
|
|
34471
|
-
const paintColor = PAINT_COLOR_MAP[extruderIndexByColorIndex[face.colorIndex]];
|
|
34472
|
-
if (paintColor) {
|
|
34473
|
-
attrs.push(`paint_color="${paintColor}"`);
|
|
34474
|
-
}
|
|
34475
|
-
return `<triangle ${attrs.join(" ")} />`;
|
|
34476
|
-
}),
|
|
34477
|
-
"</triangles>",
|
|
34478
|
-
"</mesh>",
|
|
34479
|
-
"</object>",
|
|
34513
|
+
...objectXmls,
|
|
34480
34514
|
"</resources>",
|
|
34481
34515
|
`<build p:UUID="${buildUuid}">`,
|
|
34482
|
-
|
|
34516
|
+
...buildItems,
|
|
34483
34517
|
"</build>",
|
|
34484
34518
|
"</model>"
|
|
34485
34519
|
].join("\n");
|
package/dist/index.js
CHANGED
|
@@ -202298,7 +202298,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
|
|
|
202298
202298
|
/***/ ((module) => {
|
|
202299
202299
|
|
|
202300
202300
|
"use strict";
|
|
202301
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.99.
|
|
202301
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.99.1","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=18"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
|
|
202302
202302
|
|
|
202303
202303
|
/***/ })
|
|
202304
202304
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperbook",
|
|
3
|
-
"version": "0.99.
|
|
3
|
+
"version": "0.99.1",
|
|
4
4
|
"author": "Mike Barkmin",
|
|
5
5
|
"homepage": "https://github.com/openpatch/hyperbook#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"ws": "^8.18.0",
|
|
59
59
|
"create-hyperbook": "0.3.6",
|
|
60
60
|
"@hyperbook/fs": "0.25.0",
|
|
61
|
-
"@hyperbook/
|
|
62
|
-
"@hyperbook/
|
|
61
|
+
"@hyperbook/markdown": "0.70.1",
|
|
62
|
+
"@hyperbook/types": "0.23.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"version": "pnpm build",
|