Skip to content

Commit

Permalink
Merge pull request #619 from MaslowCNC/Messing-with-importing-files
Browse files Browse the repository at this point in the history
Partial work, not fixed
  • Loading branch information
BarbourSmith committed Aug 6, 2022
2 parents fc58066 + 79248dd commit e566f66
Show file tree
Hide file tree
Showing 13 changed files with 3,889 additions and 3,744 deletions.
Binary file modified dist/cgal_browser.wasm
Binary file not shown.
40 changes: 29 additions & 11 deletions dist/jsxcad-algorithm-cgal.js

Large diffs are not rendered by default.

1,149 changes: 593 additions & 556 deletions dist/jsxcad-api-shape.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jsxcad-api-v1-tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Shape, seq, XY } from './jsxcad-api-shape.js';
import { taggedGroup, outline, translate } from './jsxcad-geometry.js';
import { outline, translate, taggedGroup } from './jsxcad-geometry.js';
import { toToolFromTags } from './jsxcad-algorithm-tool.js';

const Z = 2;
Expand Down
17 changes: 3 additions & 14 deletions dist/jsxcad-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './jsxcad-api-v1-tools.js';
import * as mathApi from './jsxcad-api-v1-math.js';
import * as shapeApi from './jsxcad-api-shape.js';
import { Group, Shape, saveGeometry, loadGeometry } from './jsxcad-api-shape.js';
import { addOnEmitHandler, addPending, write, read, emit, flushEmitGroup, computeHash, logInfo, beginEmitGroup, resolvePending, finishEmitGroup, getConfig, saveEmitGroup, ErrorWouldBlock, restoreEmitGroup, isWebWorker, isNode, getSourceLocation, getControlValue } from './jsxcad-sys.js';
import { addOnEmitHandler, addPending, write, read, emit, flushEmitGroup, computeHash, logInfo, startTime, beginEmitGroup, resolvePending, finishEmitGroup, endTime, saveEmitGroup, ErrorWouldBlock, restoreEmitGroup, isWebWorker, isNode, getSourceLocation, getControlValue } from './jsxcad-sys.js';
import { toEcmascript } from './jsxcad-compiler.js';
import { readStl, stl } from './jsxcad-api-v1-stl.js';
import { readObj } from './jsxcad-api-v1-obj.js';
Expand Down Expand Up @@ -70,7 +70,7 @@ const $run = async (op, { path, id, text, sha }) => {
const meta = await read(`meta/def/${path}/${id}`);
if (!meta || meta.sha !== sha) {
logInfo('api/core/$run', text);
const startTime = new Date();
const timer = startTime(`${path}/${id}`);
beginRecordingNotes();
beginEmitGroup({ path, id });
emitSourceText(text);
Expand All @@ -91,18 +91,7 @@ const $run = async (op, { path, id, text, sha }) => {
throw error;
}
await resolvePending();
const endTime = new Date();
const durationMinutes = (endTime - startTime) / 60000;
try {
if (getConfig().api.evaluate.showTimeViaMd) {
const md = `Evaluation time ${durationMinutes.toFixed(2)} minutes.`;
emit({ md, hash: computeHash(md) });
}
} catch (error) {}
logInfo(
'api/core/evaluate/duration',
`Evaluation time ${durationMinutes.toFixed(2)}: ${text}`
);
endTime(timer);
finishEmitGroup({ path, id });
if (typeof result === 'object') {
const type = result.constructor.name;
Expand Down
2 changes: 1 addition & 1 deletion dist/jsxcad-convert-ldraw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromPolygons, rotateX, scale, taggedGroup, read, write, transformCoordinate, transform as transform$1 } from './jsxcad-geometry.js';
import { fromPolygons, rotateX, scale, taggedGroup, read, write, transform as transform$1, transformCoordinate } from './jsxcad-geometry.js';
import { read as read$1 } from './jsxcad-sys.js';

const transform = (matrix, polygons) =>
Expand Down
90 changes: 72 additions & 18 deletions dist/jsxcad-geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ const isType =
({ tags }) =>
tags.includes(type);

const typeReference = 'type:reference';
const hasNotTypeReference = hasNotType(typeReference);
const hasTypeReference = hasType(typeReference);
const isNotTypeReference = isNotType(typeReference);
const isTypeReference = isType(typeReference);

const typeGhost = 'type:ghost';
const hasNotTypeGhost = hasNotType(typeGhost);
const hasTypeGhost = hasType(typeGhost);
Expand Down Expand Up @@ -368,6 +374,9 @@ const store = async (geometry) => {
if (graph.hash === undefined) {
throw Error(`Graph has no hash`);
}
if (!graph.serializedSurfaceMesh) {
throw Error('Attempted to store graph without serialization');
}
await write$1(`graph/${graph.hash}`, graph);
stored.graph = {
hash: graph.hash,
Expand Down Expand Up @@ -412,6 +421,9 @@ const load = async (geometry) => {
// Link to any associated graph structure.
if (geometry.graph && geometry.graph.hash) {
geometry.graph = await read$1(`graph/${geometry.graph.hash}`);
if (!geometry.graph.serializedSurfaceMesh) {
throw Error('die');
}
}
if (geometry.content) {
for (let nth = 0; nth < geometry.content.length; nth++) {
Expand Down Expand Up @@ -441,11 +453,13 @@ const loadNonblocking = (geometry) => {
if (geometry[isLoaded]) {
return geometry;
}
geometry[isLoaded] = true;
geometry[isStored] = true;
// Link to any associated graph structure.
if (geometry.graph && geometry.graph.hash) {
geometry.graph = readNonblocking$1(`graph/${geometry.graph.hash}`);
if (!geometry.graph.serializedSurfaceMesh) {
throw Error('die');
}
}
if (geometry.content) {
for (let nth = 0; nth < geometry.content.length; nth++) {
Expand All @@ -458,6 +472,7 @@ const loadNonblocking = (geometry) => {
}
}
}
geometry[isLoaded] = true;
return geometry;
};

Expand Down Expand Up @@ -605,19 +620,17 @@ const filter$w = (geometry) =>
geometry.type
) && isNotTypeGhost(geometry);

const filterClips = (geometry) => filter$w(geometry) && isNotTypeGhost(geometry);

const clip = (geometry, geometries, open) => {
const concreteGeometry = toConcreteGeometry(geometry);
const inputs = [];
linearize(concreteGeometry, filter$w, inputs);
const count = inputs.length;
for (const geometry of geometries) {
linearize(geometry, filterClips, inputs);
linearize(geometry, filter$w, inputs);
}
const outputs = clip$1(inputs, count, open);
const ghosts = [];
for (let nth = count; nth < inputs.length; nth++) {
for (let nth = 0; nth < inputs.length; nth++) {
ghosts.push(hasMaterial(hasTypeGhost(inputs[nth]), 'ghost'));
}
deletePendingSurfaceMeshes();
Expand Down Expand Up @@ -926,6 +939,7 @@ const inset = (geometry, ...args) => {
const inputs = [];
linearize(concreteGeometry, filter$q, inputs);
const outputs = inset$1(inputs, ...args);
// Put the inner insets first.
deletePendingSurfaceMeshes();
return taggedGroup({}, ...outputs);
};
Expand All @@ -945,7 +959,9 @@ const measureBoundingBox = (geometry) => {
};

const filterInputs = (geometry) =>
['graph', 'polygonsWithHoles', 'segments', 'points'].includes(geometry.type);
['graph', 'polygonsWithHoles', 'segments', 'points'].includes(
geometry.type
) && isNotTypeGhost(geometry);

const filterReferences = (geometry) =>
['graph', 'polygonsWithHoles', 'segments', 'points', 'empty'].includes(
Expand All @@ -961,8 +977,12 @@ const section = (inputGeometry, referenceGeometries) => {
linearize(referenceGeometry, filterReferences, inputs);
}
const outputs = section$1(inputs, count);
const ghosts = [];
for (let nth = 0; nth < count; nth++) {
ghosts.push(hasMaterial(hasTypeGhost(inputs[nth]), 'ghost'));
}
deletePendingSurfaceMeshes();
return taggedGroup({}, ...outputs);
return taggedGroup({}, ...outputs, ...ghosts);
};

const taggedToolpath = ({ tags = [], provenance }, toolpath) => {
Expand Down Expand Up @@ -1471,15 +1491,15 @@ const filterRemoves = (geometry) =>
isNotTypeMasked(geometry) &&
(isNotTypeGhost(geometry) || isTypeVoid(geometry));

const cut = (geometry, geometries, open = false) => {
const cut = (geometry, geometries, open = false, exact = true) => {
const concreteGeometry = toConcreteGeometry(geometry);
const inputs = [];
linearize(concreteGeometry, filterTargets$1, inputs);
const count = inputs.length;
for (const geometry of geometries) {
linearize(geometry, filterRemoves, inputs);
}
const outputs = cut$1(inputs, count, open);
const outputs = cut$1(inputs, count, open, exact);
const ghosts = [];
for (let nth = count; nth < inputs.length; nth++) {
ghosts.push(hasMaterial(hasTypeGhost(inputs[nth]), 'ghost'));
Expand Down Expand Up @@ -1574,7 +1594,8 @@ const eachPoint = (geometry, emit) => {
deletePendingSurfaceMeshes();
};

const filterTargets = (geometry) => ['graph'].includes(geometry.type);
const filterTargets = (geometry) =>
['graph'].includes(geometry.type) && isNotTypeGhost(geometry);

const eachTriangle = (geometry, emitTriangle) => {
const concreteGeometry = toConcreteGeometry(geometry);
Expand Down Expand Up @@ -1834,8 +1855,16 @@ const grow = (geometry, offset, selections, options) => {
linearize(toConcreteGeometry(selection), filter$g, inputs);
}
const outputs = grow$1(inputs, count, options);
const ghosts = [];
for (let nth = count; nth < inputs.length; nth++) {
ghosts.push(hasMaterial(hasTypeGhost(inputs[nth]), 'ghost'));
}
deletePendingSurfaceMeshes();
return replacer(inputs, outputs)(concreteGeometry);
return taggedGroup(
{},
replacer(inputs, outputs)(concreteGeometry),
...ghosts
);
};

const filter$f = (geometry) =>
Expand Down Expand Up @@ -2114,28 +2143,53 @@ const seam = (geometry, selections) => {

const filter$4 = (geometry) => ['graph'].includes(geometry.type);

const simplify = (geometry, ratio, simplifyPoints, eps) => {
const simplify = (geometry, ratio, eps) => {
const concreteGeometry = toConcreteGeometry(geometry);
const inputs = [];
linearize(concreteGeometry, filter$4, inputs);
const outputs = simplify$1(inputs, ratio, simplifyPoints, eps);
const outputs = simplify$1(inputs, ratio, eps);
deletePendingSurfaceMeshes();
return replacer(inputs, outputs)(concreteGeometry);
};

const filter$3 = (geometry) => ['graph'].includes(geometry.type);
const filter$3 = (geometry) =>
['graph'].includes(geometry.type) && isNotTypeGhost(geometry);

const smooth = (geometry, selections, iterations, time) => {
const smooth = (
geometry,
selections,
resolution,
iterations,
time,
remeshIterations,
remeshRelaxationSteps
) => {
const concreteGeometry = toConcreteGeometry(geometry);
const inputs = [];
linearize(concreteGeometry, filter$3, inputs);
const count = inputs.length;
for (const selection of selections) {
linearize(toConcreteGeometry(selection), filter$3, inputs);
}
const outputs = smooth$1(inputs, count, iterations, time);
const outputs = smooth$1(
inputs,
count,
resolution,
iterations,
time,
remeshIterations,
remeshRelaxationSteps
);
const ghosts = [];
for (let nth = count; nth < inputs.length; nth++) {
ghosts.push(hasMaterial(hasTypeGhost(inputs[nth]), 'ghost'));
}
deletePendingSurfaceMeshes();
return replacer(inputs, outputs)(concreteGeometry);
return taggedGroup(
{},
replacer(inputs, outputs, count)(concreteGeometry),
...ghosts
);
};

const filter$2 = (geometry) =>
Expand Down Expand Up @@ -2467,4 +2521,4 @@ const translate = (vector, geometry) =>
const scale = (vector, geometry) =>
transform$1(fromScaleToTransform(...vector), geometry);

export { allTags, assemble, bend, cached, cast, clip, computeCentroid, computeImplicitVolume, computeNormal, computeToolpath, convexHull, cut, deform, demesh, disjoint, drop, eachItem, eachPoint, eachSegment, eachTriangle, extrude, faces, fill, fix, fresh, fromPolygons, fuse, generateLowerEnvelope, generateUpperEnvelope, getAnySurfaces, getGraphs, getInverseMatrices, getItems, getLayouts, getLeafs, getLeafsIn, getPlans, getPoints, getTags, grow, hasMaterial, hasNotShow, hasNotShowOutline, hasNotShowOverlay, hasNotShowSkin, hasNotShowWireframe, hasNotType, hasNotTypeGhost, hasNotTypeMasked, hasNotTypeVoid, hasShow, hasShowOutline, hasShowOverlay, hasShowSkin, hasShowWireframe, hasType, hasTypeGhost, hasTypeMasked, hasTypeVoid, hash, inset, involute, isNotShow, isNotShowOutline, isNotShowOverlay, isNotShowSkin, isNotShowWireframe, isNotType, isNotTypeGhost, isNotTypeMasked, isNotTypeVoid, isShow, isShowOutline, isShowOverlay, isShowSkin, isShowWireframe, isType, isTypeGhost, isTypeMasked, isTypeVoid, join, keep, linearize, link, loft, makeAbsolute, measureArea, measureBoundingBox, measureVolume, noGhost, offset, op, outline, read, readNonblocking, registerReifier, reify, remesh, rewrite, rewriteTags, rotateX, rotateY, rotateZ, scale, seam, section, separate, serialize, showOutline, showOverlay, showSkin, showWireframe, simplify, smooth, soup, taggedDisplayGeometry, taggedGraph, taggedGroup, taggedItem, taggedLayout, taggedPlan, taggedPoints, taggedPolygons, taggedPolygonsWithHoles, taggedSegments, taggedSketch, taggedTriangles, toConcreteGeometry, toDisplayGeometry, toPoints, toTransformedGeometry, toTriangleArray, transform$1 as transform, transformCoordinate, transformingCoordinates, translate, twist, typeGhost, typeMasked, typeVoid, update, visit, wrap, write, writeNonblocking };
export { allTags, assemble, bend, cached, cast, clip, computeCentroid, computeImplicitVolume, computeNormal, computeToolpath, convexHull, cut, deform, demesh, disjoint, drop, eachItem, eachPoint, eachSegment, eachTriangle, extrude, faces, fill, fix, fresh, fromPolygons, fuse, generateLowerEnvelope, generateUpperEnvelope, getAnySurfaces, getGraphs, getInverseMatrices, getItems, getLayouts, getLeafs, getLeafsIn, getPlans, getPoints, getTags, grow, hasMaterial, hasNotShow, hasNotShowOutline, hasNotShowOverlay, hasNotShowSkin, hasNotShowWireframe, hasNotType, hasNotTypeGhost, hasNotTypeMasked, hasNotTypeReference, hasNotTypeVoid, hasShow, hasShowOutline, hasShowOverlay, hasShowSkin, hasShowWireframe, hasType, hasTypeGhost, hasTypeMasked, hasTypeReference, hasTypeVoid, hash, inset, involute, isNotShow, isNotShowOutline, isNotShowOverlay, isNotShowSkin, isNotShowWireframe, isNotType, isNotTypeGhost, isNotTypeMasked, isNotTypeReference, isNotTypeVoid, isShow, isShowOutline, isShowOverlay, isShowSkin, isShowWireframe, isType, isTypeGhost, isTypeMasked, isTypeReference, isTypeVoid, join, keep, linearize, link, loft, makeAbsolute, measureArea, measureBoundingBox, measureVolume, noGhost, offset, op, outline, read, readNonblocking, registerReifier, reify, remesh, rewrite, rewriteTags, rotateX, rotateY, rotateZ, scale, seam, section, separate, serialize, showOutline, showOverlay, showSkin, showWireframe, simplify, smooth, soup, taggedDisplayGeometry, taggedGraph, taggedGroup, taggedItem, taggedLayout, taggedPlan, taggedPoints, taggedPolygons, taggedPolygonsWithHoles, taggedSegments, taggedSketch, taggedTriangles, toConcreteGeometry, toDisplayGeometry, toPoints, toTransformedGeometry, toTriangleArray, transform$1 as transform, transformCoordinate, transformingCoordinates, translate, twist, typeGhost, typeMasked, typeReference, typeVoid, update, visit, wrap, write, writeNonblocking };
9 changes: 7 additions & 2 deletions dist/jsxcad-sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,11 @@ const unwatchLog = (thunk) => {

const aggregates = new Map();

const clearTimes = () => {
aggregates.clear();
};
const getTimes = () => [...aggregates];

const startTime$1 = (name) => {
if (!aggregates.has(name)) {
aggregates.set(name, { name, count: 0, total: 0, average: 0 });
Expand Down Expand Up @@ -813,7 +818,7 @@ const reportTimes = () => {
const entries = [...aggregates.values()].sort((a, b) => a.total - b.total);
for (const { average, count, last, name, total } of entries) {
logInfo(
'sys/profile',
'profile',
`${name} average: ${average.toFixed(
2
)} count: ${count} last: ${last.toFixed(2)} total: ${total.toFixed(2)}`
Expand Down Expand Up @@ -3099,4 +3104,4 @@ let nanoid = (size = 21) => {

const generateUniqueId = () => nanoid();

export { ErrorWouldBlock, addOnEmitHandler, addPending, ask, askService, askServices, beginEmitGroup, boot, clearCacheDb, clearEmitted, computeHash, createConversation, createService, elapsed, emit, endTime, finishEmitGroup, flushEmitGroup, generateUniqueId, getActiveServices, getConfig, getControlValue, getFilesystem, getPendingErrorHandler, getServicePoolInfo, getSourceLocation, getWorkspace, isBrowser, isNode$1 as isNode, isWebWorker, listFiles, log, logError, logInfo, onBoot, qualifyPath, read, readNonblocking, readOrWatch, remove, removeOnEmitHandler, reportTimes, resolvePending, restoreEmitGroup, saveEmitGroup, setConfig, setControlValue, setHandleAskUser, setPendingErrorHandler, setupFilesystem, setupWorkspace, sleep, startTime$1 as startTime, tellServices, terminateActiveServices, unwatchFile, unwatchFileCreation, unwatchFileDeletion, unwatchLog, unwatchServices, waitServices, watchFile, watchFileCreation, watchFileDeletion, watchLog, watchServices, write, writeNonblocking };
export { ErrorWouldBlock, addOnEmitHandler, addPending, ask, askService, askServices, beginEmitGroup, boot, clearCacheDb, clearEmitted, clearTimes, computeHash, createConversation, createService, elapsed, emit, endTime, finishEmitGroup, flushEmitGroup, generateUniqueId, getActiveServices, getConfig, getControlValue, getFilesystem, getPendingErrorHandler, getServicePoolInfo, getSourceLocation, getTimes, getWorkspace, isBrowser, isNode$1 as isNode, isWebWorker, listFiles, log, logError, logInfo, onBoot, qualifyPath, read, readNonblocking, readOrWatch, remove, removeOnEmitHandler, reportTimes, resolvePending, restoreEmitGroup, saveEmitGroup, setConfig, setControlValue, setHandleAskUser, setPendingErrorHandler, setupFilesystem, setupWorkspace, sleep, startTime$1 as startTime, tellServices, terminateActiveServices, unwatchFile, unwatchFileCreation, unwatchFileDeletion, unwatchLog, unwatchServices, waitServices, watchFile, watchFileCreation, watchFileDeletion, watchLog, watchServices, write, writeNonblocking };
17 changes: 2 additions & 15 deletions dist/jsxcad-ui-app-webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,8 @@ const agent = async ({
}

case 'app/evaluate':
await sys.log({
op: 'text',
text: 'Evaluation Started'
});
sys.clearEmitted();
sys.clearTimes();

try {
// console.log({ op: 'text', text: `QQ/script: ${script}` });
Expand All @@ -164,25 +161,15 @@ const agent = async ({
api,
path
});
await sys.log({
op: 'text',
text: 'Evaluation Succeeded',
level: 'serious'
});
await sys.log({
op: 'evaluate',
status: 'success'
}); // Wait for any pending operations.
// Finally answer the top level question.

return true;
return sys.getTimes();
} catch (error) {
reportError(error);
await sys.log({
op: 'text',
text: 'Evaluation Failed',
level: 'serious'
});
await sys.log({
op: 'evaluate',
status: 'failure'
Expand Down

0 comments on commit e566f66

Please sign in to comment.