rename catalog to files

This commit is contained in:
Stewart Allen 2022-02-18 11:30:00 -05:00
commit 8e208c99d5
4 changed files with 83 additions and 72 deletions

2
app.js
View file

@ -349,7 +349,7 @@ const script = {
"kiri/pack", "kiri/pack",
"kiri/lang", "kiri/lang",
"kiri/lang-en", "kiri/lang-en",
"kiri/catalog", "kiri/files",
"kiri/slice", "kiri/slice",
"kiri/layers", "kiri/layers",
"kiri/client", "kiri/client",

View file

@ -4,12 +4,12 @@
(function() { (function() {
const KIRI = self.kiri; const { kiri } = self;
class Catalog { class Files {
constructor(motodb, options) { constructor(indexdb, options) {
let store = this; let store = this;
this.db = motodb; this.db = indexdb;
this.files = {}; this.files = {};
this.listeners = []; this.listeners = [];
this.options = options || {}; this.options = options || {};
@ -23,6 +23,10 @@
return this; return this;
} }
get index() {
return this.db;
}
refresh() { refresh() {
let store = this; let store = this;
store.db.get('files', function(files) { store.db.get('files', function(files) {
@ -60,7 +64,7 @@
if (vertices.length < (options.threshold || 500000)) { if (vertices.length < (options.threshold || 500000)) {
return callback(vertices); return callback(vertices);
} }
KIRI.work.decimate(vertices, this.options, function(reply) { kiri.work.decimate(vertices, this.options, function(reply) {
callback(reply); callback(reply);
}); });
}; };
@ -188,6 +192,16 @@
} }
if (callback) callback(false); if (callback) callback(false);
}; };
deleteFilter(fn, from, to) {
this.db.keys(keys => {
for (let key of keys) {
if (fn(key)) {
this.db.remove(key);
}
}
}, from, to);
}
} }
function saveFileList(store) { function saveFileList(store) {
@ -201,8 +215,8 @@
} }
} }
KIRI.openCatalog = function(motodb, options) { kiri.openFiles = function(indexdb, options) {
return new Catalog(motodb, options); return new Files(indexdb, options);
}; };
})(); })();

View file

@ -20,10 +20,8 @@
LOCAL = self.debug && !SETUP.remote, LOCAL = self.debug && !SETUP.remote,
EVENT = kiri.broker = gapp.broker, EVENT = kiri.broker = gapp.broker,
SDB = data.local, SDB = data.local,
ODB = kiri.odb = new data.Index(SETUP.d ? SETUP.d[0] : 'kiri'),
// K3DB = kiri.wdb = new data.Index('kiri3', { stores:["file","work"] }).init(),
SPACE = kiri.space = moto.Space, SPACE = kiri.space = moto.Space,
CATALOG = kiri.catalog = kiri.openCatalog(ODB), FILES = kiri.catalog = kiri.openFiles(new data.Index(SETUP.d ? SETUP.d[0] : 'kiri')),
STATS = new Stats(SDB), STATS = new Stats(SDB),
// --------------- // ---------------
CONF = kiri.conf, CONF = kiri.conf,
@ -51,7 +49,7 @@
version = kiri.version = gapp.version; version = kiri.version = gapp.version;
// add show() to catalog for API // add show() to catalog for API
CATALOG.show = showCatalog; FILES.show = showCatalog;
// patch broker for api backward compatibility // patch broker for api backward compatibility
EVENT.on = (topic, listener) => { EVENT.on = (topic, listener) => {
@ -96,7 +94,7 @@
uc: UC, uc: UC,
focus: noop, focus: noop,
stats: STATS, stats: STATS,
catalog: CATALOG, catalog: FILES,
busy: { busy: {
val() { return busy }, val() { return busy },
inc() { kiri.api.event.emit("busy", ++busy) }, inc() { kiri.api.event.emit("busy", ++busy) },
@ -2054,8 +2052,8 @@
function saveWorkspace(quiet) { function saveWorkspace(quiet) {
api.conf.save(); api.conf.save();
let newWidgets = [], const newWidgets = [];
oldWidgets = js2o(SDB.getItem('ws-widgets'), []); const oldWidgets = js2o(SDB.getItem('ws-widgets'), []);
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
if (widget.synth) return; if (widget.synth) return;
newWidgets.push(widget.id); newWidgets.push(widget.id);
@ -2070,13 +2068,7 @@
Widget.deleteFromState(wid); Widget.deleteFromState(wid);
}); });
// eliminate dangling saved widgets // eliminate dangling saved widgets
ODB.keys(keys => { FILES.deleteFilter(key => newWidgets.indexOf(key.substring(8)) < 0, "ws-save-", "ws-savf");
keys.forEach(key => {
if (newWidgets.indexOf(key.substring(8)) < 0) {
ODB.remove(key);
}
})
}, "ws-save-" ,"ws-savf");
if (!quiet) { if (!quiet) {
alert2("workspace saved", 1); alert2("workspace saved", 1);
} }

View file

@ -6,30 +6,33 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (self.kiri.Widget) return; if (self.kiri.Widget) return;
const KIRI = self.kiri, const { base, kiri } = self;
DRIVERS = KIRI.driver, const { driver } = kiri;
BASE = self.base, const { config, util, polygons } = base;
CONF = BASE.config, const { Mesh, newPoint, verticesToPoints } = base;
UTIL = BASE.util, const { inRange, time } = util;
POLY = BASE.polygons,
MATH = Math, const POLY = polygons;
PRO = Widget.prototype, const PRO = Widget.prototype;
time = UTIL.time, const solid_opacity = 1.0;
solid_opacity = 1.0;
let nextId = 0, let nextId = 0,
groups = []; groups = [];
KIRI.Widget = Widget; kiri.Widget = Widget;
KIRI.newWidget = newWidget; kiri.newWidget = newWidget;
function newWidget(id,group) { return new Widget(id,group) } function newWidget(id,group) { return new Widget(id,group) }
function catalog() { return kiri.catalog }
function index() { return catalog().index }
/** ****************************************************************** /** ******************************************************************
* Group helpers * Group helpers
******************************************************************* */ ******************************************************************* */
let Group = Widget.Groups = { const Group = Widget.Groups = {
list: () => { list: () => {
return groups.slice() return groups.slice()
@ -129,9 +132,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
} }
}; };
/** ****************************************************************** // class Widget {
* Constructor // constructor(id, group) {
******************************************************************* */ //
// }
// }
/** /**
* @params {String} [id] * @params {String} [id]
@ -209,7 +214,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
******************************************************************* */ ******************************************************************* */
Widget.loadFromCatalog = function(filename, ondone) { Widget.loadFromCatalog = function(filename, ondone) {
KIRI.catalog.getFile(filename, function(data) { catalog().getFile(filename, function(data) {
let widget = newWidget().loadVertices(data); let widget = newWidget().loadVertices(data);
widget.meta.file = filename; widget.meta.file = filename;
ondone(widget); ondone(widget);
@ -217,7 +222,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}; };
Widget.loadFromState = function(id, ondone, move) { Widget.loadFromState = function(id, ondone, move) {
KIRI.odb.get('ws-save-'+id, function(data) { index().get('ws-save-'+id, function(data) {
if (data) { if (data) {
let vertices = data.geo || data, let vertices = data.geo || data,
indices = data.ind || undefined, indices = data.ind || undefined,
@ -242,7 +247,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}; };
Widget.deleteFromState = function(id,ondone) { Widget.deleteFromState = function(id,ondone) {
KIRI.odb.remove('ws-save-'+id, ondone); index().remove('ws-save-'+id, ondone);
}; };
/** ****************************************************************** /** ******************************************************************
@ -254,12 +259,12 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
return this; return this;
} }
let widget = this; let widget = this;
let time = UTIL.time(); let time = time();
widget.meta.file = filename; widget.meta.file = filename;
widget.meta.save = time; widget.meta.save = time;
KIRI.catalog.putFile(filename, this.getGeoVertices(true), function(vertices) { catalog().putFile(filename, this.getGeoVertices(true), function(vertices) {
if (vertices && vertices.length) { if (vertices && vertices.length) {
console.log("saving decimated mesh ["+vertices.length+"] time ["+(UTIL.time()-time)+"]"); console.log("saving decimated mesh ["+vertices.length+"] time ["+(time()-time)+"]");
widget.loadVertices(vertices); widget.loadVertices(vertices);
} }
}); });
@ -276,7 +281,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
return; return;
} }
let widget = this; let widget = this;
KIRI.odb.put('ws-save-'+this.id, { index().put('ws-save-'+this.id, {
geo: widget.getGeoVertices(false), geo: widget.getGeoVertices(false),
ind: widget.getGeoIndices(), ind: widget.getGeoIndices(),
track: widget.track, track: widget.track,
@ -340,7 +345,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
} }
} }
if (options.index && !indices) { if (options.index && !indices) {
let mesh = new BASE.Mesh({vertices}); let mesh = new Mesh({vertices});
vertices = mesh.vertices.toFloat32(); vertices = mesh.vertices.toFloat32();
indices = Uint32Array.from(mesh.faces.map(v => v/3)); indices = Uint32Array.from(mesh.faces.map(v => v/3));
} }
@ -379,7 +384,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
PRO.indexGeo = function() { PRO.indexGeo = function() {
let indices = this.getGeoIndices(); let indices = this.getGeoIndices();
if (!indices) { if (!indices) {
let mesh = new BASE.Mesh({vertices: this.getGeoVertices()}); let mesh = new Mesh({vertices: this.getGeoVertices()});
vertices = mesh.vertices.toFloat32(); vertices = mesh.vertices.toFloat32();
indices = Uint32Array.from(mesh.faces.map(v => v/3)); indices = Uint32Array.from(mesh.faces.map(v => v/3));
this.loadData({vertices, indices}); this.loadData({vertices, indices});
@ -392,12 +397,12 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
let verts = mesh.vertices; let verts = mesh.vertices;
let edges = mesh.edges; let edges = mesh.edges;
let split = mesh.edges.filter(l => l.split); let split = mesh.edges.filter(l => l.split);
let layrz = new KIRI.Layers(); let layrz = new kiri.Layers();
layrz.setLayer("edges", {line: 0}); layrz.setLayer("edges", {line: 0});
for (let line of edges) { for (let line of edges) {
layrz.addLine( layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2]), newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2]),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2]) newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2])
); );
} }
for (let l=0; l<mesh.loops.length; l++) { for (let l=0; l<mesh.loops.length; l++) {
@ -405,24 +410,24 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
let zo = [0.15, 0.3, 0.45][l % 3]; let zo = [0.15, 0.3, 0.45][l % 3];
for (let line of mesh.loops[l]) { for (let line of mesh.loops[l]) {
layrz.addLine( layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - zo), newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - zo),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - zo) newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - zo)
); );
} }
} }
layrz.setLayer("split", {line: 0xff00ff}); layrz.setLayer("split", {line: 0xff00ff});
for (let line of split) { for (let line of split) {
layrz.addLine( layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - 0.6), newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - 0.6),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - 0.6) newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - 0.6)
); );
} }
let stack = new KIRI.Stack(this.mesh); let stack = new kiri.Stack(this.mesh);
stack.addLayers(layrz); stack.addLayers(layrz);
return { mesh, layrz, stack }; return { mesh, layrz, stack };
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
KIRI.client.heal(this.getVertices().array, data => { kiri.client.heal(this.getVertices().array, data => {
if (data.vertices) { if (data.vertices) {
this.loadVertices(data.vertices); this.loadVertices(data.vertices);
this.modified = true; this.modified = true;
@ -541,7 +546,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
mesh.material.transparent = solid_opacity < 1.0; mesh.material.transparent = solid_opacity < 1.0;
mesh.material.opacity = solid_opacity; mesh.material.opacity = solid_opacity;
mesh.material.visible = false; mesh.material.visible = false;
} else if (UTIL.inRange(value, 0.0, solid_opacity)) { } else if (inRange(value, 0.0, solid_opacity)) {
mesh.material.transparent = value < 1.0; mesh.material.transparent = value < 1.0;
mesh.material.opacity = value; mesh.material.opacity = value;
mesh.material.visible = true; mesh.material.visible = true;
@ -655,7 +660,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
} }
if (x || y || z) { if (x || y || z) {
this.setModified(); this.setModified();
KIRI.api.event.emit('widget.move', {widget: this, pos}); kiri.api.event.emit('widget.move', {widget: this, pos});
} }
}; };
@ -798,7 +803,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
next: () => { next: () => {
let done = index >= count; let done = index >= count;
return done ? { done } : return done ? { done } :
{ value: BASE.newPoint(verts[index++], verts[index++], verts[index++]) }; { value: newPoint(verts[index++], verts[index++], verts[index++]) };
} }
} } } }
}; };
@ -807,7 +812,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
PRO.getPoints = function() { PRO.getPoints = function() {
if (!this.points) { if (!this.points) {
// convert and cache points from geometry vertices // convert and cache points from geometry vertices
this.points = BASE.verticesToPoints(this.getGeoVertices(), { this.points = verticesToPoints(this.getGeoVertices(), {
maxpass: 0 // disable decimation maxpass: 0 // disable decimation
}); });
} }
@ -869,18 +874,18 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
*/ */
PRO.slice = function(settings, ondone, onupdate) { PRO.slice = function(settings, ondone, onupdate) {
let widget = this; let widget = this;
let startTime = UTIL.time(); let startTime = time();
widget.settings = settings; widget.settings = settings;
widget.clearSlices(); widget.clearSlices();
onupdate(0.0001, "slicing"); onupdate(0.0001, "slicing");
if (KIRI.client && !widget.inWorker) { if (kiri.client && !widget.inWorker) {
// in case result of slice is nothing, do not preserve previous // in case result of slice is nothing, do not preserve previous
widget.slices = [] widget.slices = []
// executed from kiri.js // executed from kiri.js
KIRI.client.slice(settings, this, function(reply) { kiri.client.slice(settings, this, function(reply) {
if (reply.update) { if (reply.update) {
onupdate(reply.update, reply.updateStatus); onupdate(reply.update, reply.updateStatus);
} }
@ -894,7 +899,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
widget.stats.load_time = widget.xfer.start - reply.send_end; widget.stats.load_time = widget.xfer.start - reply.send_end;
} }
if (reply.slice) { if (reply.slice) {
widget.slices.push(KIRI.codec.decode(reply.slice, {mesh:widget.mesh})); widget.slices.push(kiri.codec.decode(reply.slice, {mesh:widget.mesh}));
} }
if (reply.rotinfo) { if (reply.rotinfo) {
widget.rotinfo = reply.rotinfo; widget.rotinfo = reply.rotinfo;
@ -908,7 +913,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}); });
} }
if (KIRI.server) { if (kiri.server) {
// executed from kiri-worker.js // executed from kiri-worker.js
let catchdone = function(error) { let catchdone = function(error) {
if (error) { if (error) {
@ -917,7 +922,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
onupdate(1.0, "transfer"); onupdate(1.0, "transfer");
widget.stats.slice_time = UTIL.time() - startTime; widget.stats.slice_time = time() - startTime;
ondone(); ondone();
}; };
@ -926,10 +931,10 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
onupdate(progress, message); onupdate(progress, message);
}; };
let driver = DRIVERS[settings.mode.toUpperCase()]; let drv = driver[settings.mode.toUpperCase()];
if (driver) { if (drv) {
driver.slice(settings, widget, catchupdate, catchdone); drv.slice(settings, widget, catchupdate, catchdone);
} else { } else {
console.log('invalid mode: '+settings.mode); console.log('invalid mode: '+settings.mode);
ondone('invalid mode: '+settings.mode); ondone('invalid mode: '+settings.mode);
@ -954,7 +959,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}; };
PRO.setWireframe = function(set, color, opacity) { PRO.setWireframe = function(set, color, opacity) {
if (!(KIRI.api && KIRI.api.conf)) { if (!(kiri.api && kiri.api.conf)) {
// missing api features in engine mode // missing api features in engine mode
return; return;
} }
@ -966,7 +971,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
this.wire = null; this.wire = null;
} }
if (set) { if (set) {
let dark = KIRI.api.conf.get().controller.dark; let dark = kiri.api.conf.get().controller.dark;
let mat = new THREE.MeshBasicMaterial({ let mat = new THREE.MeshBasicMaterial({
wireframe: true, wireframe: true,
color: dark ? 0xaaaaaa : 0, color: dark ? 0xaaaaaa : 0,
@ -976,7 +981,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
let wire = widget.wire = new THREE.Mesh(mesh.geometry.shallowClone(), mat); let wire = widget.wire = new THREE.Mesh(mesh.geometry.shallowClone(), mat);
mesh.add(wire); mesh.add(wire);
} }
if (KIRI.api.view.get() === KIRI.consts.VIEWS.ARRANGE) { if (kiri.api.view.get() === kiri.consts.VIEWS.ARRANGE) {
this.setColor(this.color); this.setColor(this.color);
} else { } else {
this.setColor(0x888888,undefined,false); this.setColor(0x888888,undefined,false);