Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Jul 28, 2023
1 parent e39162f commit f37aaac
Showing 1 changed file with 31 additions and 37 deletions.
68 changes: 31 additions & 37 deletions bindings/wasm/examples/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ function finishRun() {
}

const mv = document.querySelector('model-viewer');
let glbURL = null;
let threeMFURL = null;
const output = {
glbURL: null,
threeMFURL: null
};
let manifoldWorker = null;

function createWorker() {
Expand All @@ -382,16 +384,16 @@ function createWorker() {
finishRun();
runButton.disabled = true;

if (threeMFURL != undefined) {
URL.revokeObjectURL(threeMFURL);
threeMFURL = undefined;
if (output.threeMFURL != null) {
URL.revokeObjectURL(output.threeMFURL);
output.threeMFURL = null;
}
URL.revokeObjectURL(glbURL);
glbURL = e.data.glbURL;
threeMFURL = e.data.threeMFURL;
threemfButton.disabled = threeMFURL == undefined;
mv.src = glbURL;
if (glbURL == null) {
URL.revokeObjectURL(output.glbURL);
output.glbURL = e.data.glbURL;
output.threeMFURL = e.data.threeMFURL;
threemfButton.disabled = output.threeMFURL == null;
mv.src = output.glbURL;
if (output.glbURL == null) {
mv.showPoster();
poster.textContent = 'Error';
createWorker();
Expand Down Expand Up @@ -429,32 +431,24 @@ runButton.onclick = function() {
}
};

function clickSave(saveButton, filename, outputName) {
const container = saveButton.parentElement;
return () => {
const oldSave = saveContainer.firstElementChild;
if (oldSave !== container) {
saveDropdown.insertBefore(oldSave, saveDropdown.firstElementChild);
saveContainer.insertBefore(container, saveDropdown);
container.appendChild(saveArrow.parentElement);
}
const link = document.createElement('a');
link.download = filename;
link.href = output[outputName];
link.click();
};
}

const glbButton = document.querySelector('#glb');
const glbContainer = glbButton.parentElement;
glbButton.onclick = function() {
const oldSave = saveContainer.firstElementChild;
if (oldSave !== glbContainer) {
saveDropdown.insertBefore(oldSave, saveDropdown.firstElementChild);
saveContainer.insertBefore(glbContainer, saveDropdown);
glbContainer.appendChild(saveArrow.parentElement);
}
const link = document.createElement('a');
link.download = 'manifold.glb';
link.href = glbURL;
link.click();
};
glbButton.onclick = clickSave(glbButton, 'manifold.glb', 'glbURL');

const threemfButton = document.querySelector('#threemf');
const threemfContainer = threemfButton.parentElement;
threemfButton.onclick = function() {
const oldSave = saveContainer.firstElementChild;
if (oldSave !== threemfContainer) {
saveDropdown.insertBefore(oldSave, saveDropdown.firstElementChild);
saveContainer.insertBefore(threemfContainer, saveDropdown);
threemfContainer.appendChild(saveArrow.parentElement);
}
const link = document.createElement('a');
link.download = 'manifold.3mf';
link.href = threeMFURL;
link.click();
};
threemfButton.onclick = clickSave(threemfButton, 'manifold.3mf', 'threeMFURL');

0 comments on commit f37aaac

Please sign in to comment.