disable step debug. add mesh script persistance, control, error dialog
This commit is contained in:
parent
7688623d53
commit
b52ab788e5
6 changed files with 73 additions and 20 deletions
|
|
@ -3,6 +3,9 @@
|
|||
import { tool as MeshTool } from '../mesh/tool.js';
|
||||
|
||||
const { Vector3 } = THREE;
|
||||
function debug() {
|
||||
if (false) console.log(...arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert STL triangles to STEP file format
|
||||
|
|
@ -279,9 +282,9 @@ export function meshToSTEPWithFaces(triangles, options = {}) {
|
|||
const outlines = tool.generateOutlines(connectedFaces);
|
||||
|
||||
if (outlines.length > 1) {
|
||||
console.log(`Surface with ${connectedFaces.length} faces has ${outlines.length} outlines:`);
|
||||
debug(`Surface with ${connectedFaces.length} faces has ${outlines.length} outlines:`);
|
||||
outlines.forEach((outline, idx) => {
|
||||
console.log(` Outline ${idx}: ${outline.length} vertices`);
|
||||
debug(` Outline ${idx}: ${outline.length} vertices`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +308,7 @@ export function meshToSTEPWithFaces(triangles, options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(`[v4] Merged ${totalFaces} triangles into ${surfaces.length} faces`);
|
||||
debug(`[v4] Merged ${totalFaces} triangles into ${surfaces.length} faces`);
|
||||
|
||||
// Generate STEP file
|
||||
let step = `ISO-10303-21;
|
||||
|
|
@ -519,7 +522,7 @@ DATA;
|
|||
outline = mergeColinearEdges(outline);
|
||||
|
||||
if (originalLength !== outline.length) {
|
||||
console.log(` Merged outline ${outlineIdx}: ${originalLength} -> ${outline.length} vertices`);
|
||||
debug(` Merged outline ${outlineIdx}: ${originalLength} -> ${outline.length} vertices`);
|
||||
}
|
||||
|
||||
if (outline.length < 3) {
|
||||
|
|
@ -655,8 +658,8 @@ DATA;
|
|||
}
|
||||
|
||||
// Now write CLOSED_SHELL with only the faces that were actually created
|
||||
console.log(`[v4] Created ${createdFaceIds.length} faces for CLOSED_SHELL (expected ${surfaces.length})`);
|
||||
console.log(`[v4] Shared ${edgeMap.size} unique edges across all faces`);
|
||||
debug(`[v4] Created ${createdFaceIds.length} faces for CLOSED_SHELL (expected ${surfaces.length})`);
|
||||
debug(`[v4] Shared ${edgeMap.size} unique edges across all faces`);
|
||||
step += `#${closedShellId}=CLOSED_SHELL('',(${createdFaceIds.map(fid => `#${fid}`).join(',')}));\n`;
|
||||
|
||||
// Append all the face geometry
|
||||
|
|
|
|||
|
|
@ -187,7 +187,11 @@ async function restore_space() {
|
|||
// hide loading curtain
|
||||
$d('curtain','none');
|
||||
// restore handles visibility
|
||||
handles.setEnabled(api.prefs.map.space.bounds);
|
||||
handles.setEnabled(api.prefs.map.space.bounds ?? false);
|
||||
// restore script if was showing
|
||||
if (api.prefs.map.space.script) {
|
||||
api.script.show();
|
||||
}
|
||||
if (api.prefs.map.info.welcome !== false) {
|
||||
api.welcome(version);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -815,7 +815,7 @@ let add = {
|
|||
},
|
||||
|
||||
cube() {
|
||||
const [ x,y,z ] = [ ...arguments ];
|
||||
const [ x,y,z ] = [ ...arguments ].map(v => parseFloat(v) || undefined);
|
||||
const box = new THREE.BoxGeometry(1,1,1).toNonIndexed();
|
||||
const vert = box.attributes.position.array;
|
||||
const nmdl = new meshModel({ file: "box", mesh: vert });
|
||||
|
|
@ -1445,6 +1445,7 @@ const prefs = {
|
|||
dark: false,
|
||||
floor: false,
|
||||
grid: true,
|
||||
script: false,
|
||||
select: [],
|
||||
snap: 1,
|
||||
snapon: false,
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ function menu_item(text, fn, short, id) {
|
|||
|
||||
// create html elements
|
||||
function ui_build() {
|
||||
let { bind, div, input, hr, label, textarea } = h;
|
||||
let { bind, button, div, input, hr, label, span, textarea } = h;
|
||||
let { file, selection, mode, tool, sketch, prefs, add } = api;
|
||||
let trash = FontAwesome.icon({ prefix: "fas", iconName: "trash" }).html[0];
|
||||
let eye_open = FontAwesome.icon({ prefix: "fas", iconName: "eye" }).html[0];
|
||||
|
|
@ -581,8 +581,13 @@ function ui_build() {
|
|||
div({ id: 'logger', onmouseover() { log.show() } }),
|
||||
]),
|
||||
div({ id: 'script', class: "hide" }, [
|
||||
div({ id: 'script-header', _: "script" }),
|
||||
textarea({ id: 'script-editor', rows: 50, cols: 60 }),
|
||||
div({ id: 'script-header' }, [
|
||||
span("script"),
|
||||
div({ class: "grow" }),
|
||||
button({ _: "run", onclick: api.script.execute }),
|
||||
button({ _: "×", class: "close", onclick: api.script.hide })
|
||||
]),
|
||||
textarea({ id: 'script-editor', rows: 30, cols: 65 }),
|
||||
]),
|
||||
div({ id: 'grouplist' }),
|
||||
div({ id: 'selectlist' }),
|
||||
|
|
|
|||
|
|
@ -4,18 +4,25 @@ import { api } from '../mesh/api.js';
|
|||
import { $, h, estop } from '../moto/webui.js';
|
||||
|
||||
export const script = {
|
||||
running: false,
|
||||
visible: false,
|
||||
changed() {
|
||||
localStorage.script = $('script-editor').value;
|
||||
},
|
||||
error(e) {
|
||||
api.modal.dialog({
|
||||
title: "script error",
|
||||
body: [ h.div({ id: "script-error", _: e.message || e.toString() }) ]
|
||||
});
|
||||
},
|
||||
hide() {
|
||||
$('script').classList.add('hide');
|
||||
script.visible = false;
|
||||
api.prefs.save(api.prefs.map.space.script = script.visible = false);
|
||||
},
|
||||
show() {
|
||||
$('script').classList.remove('hide');
|
||||
$('script-editor').value = localStorage.script ?? '';
|
||||
script.visible = true;
|
||||
api.prefs.save(api.prefs.map.space.script = script.visible = true);
|
||||
},
|
||||
toggle() {
|
||||
if (script.visible) {
|
||||
|
|
@ -27,12 +34,25 @@ export const script = {
|
|||
execute() {
|
||||
let cmd = localStorage.script || `console.log('no script')`;
|
||||
if (cmd) {
|
||||
if (script.running) {
|
||||
return script.error('script running');
|
||||
}
|
||||
cmd = [
|
||||
'(async () => {',
|
||||
cmd,
|
||||
'})();'
|
||||
'})()',
|
||||
'.catch(error => {',
|
||||
'api.script.error(error)',
|
||||
'})',
|
||||
'.finally(() => {',
|
||||
'api.script.running = false;',
|
||||
'});'
|
||||
].join('\n');
|
||||
eval(`{ \n ${cmd} \n }`);
|
||||
try {
|
||||
eval(`{ \n ${cmd} \n }`);
|
||||
} catch (e) {
|
||||
script.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -144,6 +144,10 @@ button:hover {
|
|||
|
||||
/** misc ui **/
|
||||
|
||||
.grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
|
|
@ -209,10 +213,6 @@ button:hover {
|
|||
padding: 4px 8px 4px 8px;
|
||||
}
|
||||
|
||||
.menu-items .grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.menu-items .short {
|
||||
gap: 1px;
|
||||
}
|
||||
|
|
@ -630,10 +630,13 @@ button:hover {
|
|||
}
|
||||
|
||||
#script {
|
||||
margin-left: 5px;
|
||||
margin: 5px 0px 5px 5px;
|
||||
/* margin-top: 5px;
|
||||
margin-left: 5px; */
|
||||
flex-direction: column;
|
||||
justify-content: end;
|
||||
color: white;
|
||||
height: calc(100% - 10px);
|
||||
}
|
||||
|
||||
#script-header {
|
||||
|
|
@ -645,12 +648,29 @@ button:hover {
|
|||
border-left: 1px solid #999;
|
||||
border-right: 1px solid #999;
|
||||
flex-direction: row;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
#script-header button {
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#script-header .close {
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
#script-editor {
|
||||
color: white;
|
||||
background-color: #222;
|
||||
outline: none;
|
||||
height: 100%;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
#script-error {
|
||||
flex-direction: column;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
/** group/model buttons top/right of workspace **/
|
||||
|
|
|
|||
Loading…
Reference in a new issue