add widget vertex replace. bump rev 3.1.D0

This commit is contained in:
Stewart Allen 2021-11-02 11:58:00 -04:00
commit 0cb2323aaf
9 changed files with 100 additions and 4 deletions

1
app.js
View file

@ -252,6 +252,7 @@ const script = {
"moto/load-stl",
"moto/load-svg",
"moto/load-url",
"moto/load-file",
"moto/db",
"kiri/ui",
"kiri/do",

View file

@ -1,6 +1,6 @@
{
"name": "grid-apps",
"version": "3.0.34D",
"version": "3.1.0D",
"description": "grid.space 3d slice & modeling tools",
"author": "Stewart Allen <sa@grid.space>",
"license": "MIT",

View file

@ -6,7 +6,7 @@
if (!self.kiri) {
let kiri = self.kiri = {
beta: 3034,
beta: 3100,
driver: {}, // driver modules
loader: [], // module loading: array of functions
load: (fn) => kiri.loader.push(fn)

View file

@ -2626,6 +2626,7 @@
$('render-solid').onclick = () => { API.view.wireframe(false, 0, 1); };
// mesh buttons
$('mesh-heal').onclick = () => { API.widgets.heal() };
$('mesh-swap').onclick = () => { API.widgets.replace() };
$('mesh-export-stl').onclick = () => { objectsExport('stl') };
$('mesh-export-obj').onclick = () => { objectsExport('obj') };
// context menu

View file

@ -401,6 +401,7 @@
for: forAllWidgets,
load: Widget.loadFromCatalog,
heal: healWidgets,
replace: replaceVertices,
meshes: meshArray,
opacity: setOpacity,
annotate: (id) => {
@ -884,6 +885,37 @@
return out;
}
function replaceVertices(vertices) {
let widgets = API.selection.widgets(true);
if (!widgets.length) {
return;
}
function onload(vertices) {
for (let w of widgets) {
let track = Object.clone(w.track);
let { scale, rot, pos } = track;
let roto = w.roto.slice();
w.loadVertices(vertices);
for (let m of roto) {
w.mesh.geometry.applyMatrix4(m.clone());
}
w._scale(scale.x, scale.y, scale.z);
}
platform.update();
}
if (vertices) {
onload(vertices);
} else {
// dialog
$('load-file').onchange = function(event) {
MOTO.File.load(event.target.files[0])
.then(data => onload(data[0].mesh))
.catch(error => console.log({error}));
};
$('load-file').click();
}
}
function healWidgets() {
let widgets = API.widgets.all();
let marker;

View file

@ -3,7 +3,7 @@
let terms = {
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE: "See the license.md file included with the source distribution",
VERSION: "3.0.D34"
VERSION: "3.1.D0"
};
if (typeof(module) === 'object') {

60
src/moto/load-file.js Normal file
View file

@ -0,0 +1,60 @@
'use strict';
(function() {
if (!self.moto) self.moto = {};
if (self.moto.File) return;
function load_data(data, file, ext) {
ext = ext || name.toLowerCase().split('.').pop();
return new Promise((resolve, reject) => {
switch (ext) {
case "stl":
resolve([{
mesh: new moto.STL().parse(data), file
}]);
break;
case "obj":
resolve(moto.OBJ.parse(data).map(m => { return {mesh: m.toFloat32(), file} }));
break;
case "3mf":
moto.TMF.parseAsync(data).then((meshes) => {
resolve(meshes.map(m => {
return { mesh: m.faces.toFloat32(), file }
}));
});
break;
case "svg":
resolve(moto.SVG.parse(data).map(m => { return {mesh: m.toFloat32(), file} }));
break;
default:
reject(`unknown file type: "${ext}" from ${url}`);
break;
}
});
}
function load(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader();
let name = file.name;
let ext = name.toLowerCase().split('.').pop();
reader.file = file;
reader.onloadend = function (event) {
load_data(event.target.result, name, ext)
.then(data => resolve(data))
.catch(e => reject(e));
};
if (ext === 'stl') {
reader.readAsArrayBuffer(reader.file);
} else {
reader.readAsBinaryString(reader.file);
}
});
}
self.moto.File = {
load_data,
load
};
})();

View file

@ -139,7 +139,8 @@
</div>
<button id="mesh-export-obj" lk="rc_xobj">export OBJ</button>
<button id="mesh-export-stl" lk="rc_xstl">export STL</button>
<button id="mesh-heal" lk="rc_heal">heal</button>
<button id="mesh-heal" lk="rc_heal">heal mesh</button>
<button id="mesh-swap" lk="rc_swap">replace vertices</button>
</div>
<div id="ft-select" class="grow f-col"></div>
</div>

View file

@ -57,6 +57,7 @@ kiri.lang['en-us'] = {
rc_dupl: "duplicate",
rc_focs: "set focus",
rc_heal: "heal meshes",
rc_swap: "replace vertices",
rc_xobj: "export OBJ",
rc_xstl: "export STL",