add widget vertex replace. bump rev 3.1.D0
This commit is contained in:
parent
86f956ba98
commit
0cb2323aaf
9 changed files with 100 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
60
src/moto/load-file.js
Normal 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
|
||||
};
|
||||
|
||||
})();
|
||||
Loading…
Reference in a new issue