experiment with namespace loading
This commit is contained in:
parent
5601760329
commit
d4f2ac21bd
4 changed files with 40 additions and 37 deletions
|
|
@ -63,8 +63,22 @@ let mods = [];
|
||||||
let modn = {};
|
let modn = {};
|
||||||
|
|
||||||
// register module without a load function
|
// register module without a load function
|
||||||
gapp.register = (name, deps) => {
|
gapp.register = (name, deps, fn) => {
|
||||||
gapp.load(undefined, name, deps);
|
gapp.load(undefined, name, deps);
|
||||||
|
if (fn) {
|
||||||
|
let toks = name.split('.');
|
||||||
|
let root = self;
|
||||||
|
let map = toks.pop();
|
||||||
|
for (let tok of toks) {
|
||||||
|
root = root[tok];
|
||||||
|
if (!root) {
|
||||||
|
console.log({missing_root: tok, at: name});
|
||||||
|
root = root[tok] = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map = root[map] = root[map] || {};
|
||||||
|
fn(self, exports => Object.assign(map, exports));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// register module with a load function
|
// register module with a load function
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,13 @@
|
||||||
let broker = gapp.broker;
|
let broker = gapp.broker;
|
||||||
let call = broker.send;
|
let call = broker.send;
|
||||||
let dbindex = [ "admin", "space" ];
|
let dbindex = [ "admin", "space" ];
|
||||||
let worker = moto.client.fn;
|
let { Quaternion, Mesh, MeshPhongMaterial, PlaneGeometry, DoubleSide } = THREE;
|
||||||
let { Quaternion, Vector3, Mesh, MeshPhongMaterial, PlaneGeometry, DoubleSide } = THREE;
|
|
||||||
|
|
||||||
// set below. called once the DOM readyState = complete
|
// set below. called once the DOM readyState = complete
|
||||||
// this is the main() entrypoint called after all dependents load
|
// this is the main() entrypoint called after all dependents load
|
||||||
function init() {
|
function init() {
|
||||||
let stores = data.open('mesh', { stores: dbindex, version: 4 }).init(),
|
let stores = data.open('mesh', { stores: dbindex, version: 4 }).init(),
|
||||||
moto = self.moto,
|
moto = self.moto,
|
||||||
api = mesh.api,
|
|
||||||
dark = false,
|
dark = false,
|
||||||
ortho = false,
|
ortho = false,
|
||||||
zoomrev = true,
|
zoomrev = true,
|
||||||
|
|
@ -403,7 +401,7 @@ function space_init(data) {
|
||||||
if (metaKey) {
|
if (metaKey) {
|
||||||
// set focus on intersected face
|
// set focus on intersected face
|
||||||
let { x, y, z } = int.point;
|
let { x, y, z } = int.point;
|
||||||
let q = new THREE.Quaternion().setFromRotationMatrix(group.object.matrix);
|
let q = new Quaternion().setFromRotationMatrix(group.object.matrix);
|
||||||
// rotate normal using group's matrix
|
// rotate normal using group's matrix
|
||||||
let normal = int.face.normal.applyQuaternion(q);
|
let normal = int.face.normal.applyQuaternion(q);
|
||||||
// y,z swap due to world rotation for orbit controls
|
// y,z swap due to world rotation for orbit controls
|
||||||
|
|
|
||||||
|
|
@ -2,38 +2,30 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
// dep: ext.three
|
// dep: ext.three
|
||||||
// dep: ext.three-bgu
|
// dep: ext.three-bgu
|
||||||
gapp.register("mesh.api", [
|
gapp.register("mesh.api", [
|
||||||
"moto.license", // dep: moto.license
|
|
||||||
"moto.client", // dep: moto.client
|
|
||||||
"moto.broker", // dep: moto.broker
|
|
||||||
"moto.space", // dep: moto.space
|
|
||||||
"data.index", // dep: data.index
|
|
||||||
"mesh.tool", // dep: mesh.tool
|
|
||||||
"mesh.util", // dep: mesh.util
|
|
||||||
"add.array", // dep: add.array
|
|
||||||
]);
|
|
||||||
|
|
||||||
let mesh = self.mesh = self.mesh || {};
|
"moto.license", // dep: moto.license
|
||||||
if (mesh.api) return;
|
"moto.client", // dep: moto.client
|
||||||
|
"moto.broker", // dep: moto.broker
|
||||||
|
"moto.space", // dep: moto.space
|
||||||
|
"data.index", // dep: data.index
|
||||||
|
"mesh.tool", // dep: mesh.tool
|
||||||
|
"mesh.util", // dep: mesh.util
|
||||||
|
"add.array", // dep: add.array
|
||||||
|
|
||||||
let { Matrix4, Vector3 } = THREE;
|
], (root, exports) => {
|
||||||
|
|
||||||
let space = moto.Space;
|
const { Matrix4, Vector3 } = THREE;
|
||||||
let worker = moto.client.fn;
|
const { mesh, moto } = root;
|
||||||
let util = mesh.util;
|
const { space } = moto;
|
||||||
|
const { util } = mesh;
|
||||||
|
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let selected = [];
|
let selected = [];
|
||||||
let toggle = {
|
|
||||||
wire: false,
|
|
||||||
bound: false
|
|
||||||
};
|
|
||||||
|
|
||||||
let selection = {
|
const selection = {
|
||||||
// @returns {MeshObject[]} or all groups if not strict and no selection
|
// @returns {MeshObject[]} or all groups if not strict and no selection
|
||||||
list(strict = false) {
|
list(strict = false) {
|
||||||
return selected.length || strict ? selected.slice() : groups.slice();
|
return selected.length || strict ? selected.slice() : groups.slice();
|
||||||
|
|
@ -208,7 +200,7 @@ let selection = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let group = {
|
const group = {
|
||||||
// @returns {MeshGroup[]}
|
// @returns {MeshGroup[]}
|
||||||
list() {
|
list() {
|
||||||
return groups.slice();
|
return groups.slice();
|
||||||
|
|
@ -292,7 +284,7 @@ function fallback(models, strict) {
|
||||||
return Array.isArray(models) ? models : selection.models(strict);
|
return Array.isArray(models) ? models : selection.models(strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tool = {
|
const tool = {
|
||||||
merge(models) {
|
merge(models) {
|
||||||
models = fallback(models);
|
models = fallback(models);
|
||||||
if (models.length <= 1) {
|
if (models.length <= 1) {
|
||||||
|
|
@ -457,10 +449,10 @@ let tool = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let modes = { object: "object", face: "face", line: "line", vertex: "vertex" };
|
const modes = { object: "object", face: "face", line: "line", vertex: "vertex" };
|
||||||
|
|
||||||
// edit mode
|
// edit mode
|
||||||
let mode = {
|
const mode = {
|
||||||
set(mode) {
|
set(mode) {
|
||||||
prefs.save(prefs.map.mode = mode);
|
prefs.save(prefs.map.mode = mode);
|
||||||
for (let key of Object.values(modes)) {
|
for (let key of Object.values(modes)) {
|
||||||
|
|
@ -495,7 +487,7 @@ let prefsig;
|
||||||
let prefsignew;
|
let prefsignew;
|
||||||
|
|
||||||
// persisted preference map
|
// persisted preference map
|
||||||
let prefs = {
|
const prefs = {
|
||||||
map: {
|
map: {
|
||||||
info: {
|
info: {
|
||||||
group: "show",
|
group: "show",
|
||||||
|
|
@ -541,7 +533,7 @@ let prefs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// api is augmented in mesh.build (log, modal, download)
|
// api is augmented in mesh.build (log, modal, download)
|
||||||
let api = mesh.api = {
|
const api = exports({
|
||||||
help() {
|
help() {
|
||||||
window.open("https://docs.grid.space/projects/mesh-tool");
|
window.open("https://docs.grid.space/projects/mesh-tool");
|
||||||
},
|
},
|
||||||
|
|
@ -634,9 +626,9 @@ let api = mesh.api = {
|
||||||
// return model objects suitable for finding ray intersections
|
// return model objects suitable for finding ray intersections
|
||||||
return group.list().map(o => o.models).flat().map(o => o.mesh);
|
return group.list().map(o => o.models).flat().map(o => o.mesh);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
let broker = gapp.broker;
|
const broker = gapp.broker;
|
||||||
// publish messages when api functions are called
|
// publish messages when api functions are called
|
||||||
broker.wrapObject(selection, 'selection');
|
broker.wrapObject(selection, 'selection');
|
||||||
broker.wrapObject(model, 'model');
|
broker.wrapObject(model, 'model');
|
||||||
|
|
@ -645,4 +637,4 @@ broker.wrapObject(group, 'group');
|
||||||
// optimize db writes by merging updates
|
// optimize db writes by merging updates
|
||||||
prefs.save = util.deferWrap(prefs.save, 100);
|
prefs.save = util.deferWrap(prefs.save, 100);
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ gapp.register("mesh.build",[
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let mesh = self.mesh = self.mesh || {};
|
let mesh = self.mesh = self.mesh || {};
|
||||||
if (mesh.build) return;
|
|
||||||
|
|
||||||
let broker = gapp.broker;
|
let broker = gapp.broker;
|
||||||
let call = broker.send;
|
let call = broker.send;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue