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 = {};
|
||||
|
||||
// register module without a load function
|
||||
gapp.register = (name, deps) => {
|
||||
gapp.register = (name, deps, fn) => {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -7,15 +7,13 @@
|
|||
let broker = gapp.broker;
|
||||
let call = broker.send;
|
||||
let dbindex = [ "admin", "space" ];
|
||||
let worker = moto.client.fn;
|
||||
let { Quaternion, Vector3, Mesh, MeshPhongMaterial, PlaneGeometry, DoubleSide } = THREE;
|
||||
let { Quaternion, Mesh, MeshPhongMaterial, PlaneGeometry, DoubleSide } = THREE;
|
||||
|
||||
// set below. called once the DOM readyState = complete
|
||||
// this is the main() entrypoint called after all dependents load
|
||||
function init() {
|
||||
let stores = data.open('mesh', { stores: dbindex, version: 4 }).init(),
|
||||
moto = self.moto,
|
||||
api = mesh.api,
|
||||
dark = false,
|
||||
ortho = false,
|
||||
zoomrev = true,
|
||||
|
|
@ -403,7 +401,7 @@ function space_init(data) {
|
|||
if (metaKey) {
|
||||
// set focus on intersected face
|
||||
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
|
||||
let normal = int.face.normal.applyQuaternion(q);
|
||||
// y,z swap due to world rotation for orbit controls
|
||||
|
|
|
|||
|
|
@ -2,38 +2,30 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
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 || {};
|
||||
if (mesh.api) return;
|
||||
"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 { Matrix4, Vector3 } = THREE;
|
||||
], (root, exports) => {
|
||||
|
||||
let space = moto.Space;
|
||||
let worker = moto.client.fn;
|
||||
let util = mesh.util;
|
||||
const { Matrix4, Vector3 } = THREE;
|
||||
const { mesh, moto } = root;
|
||||
const { space } = moto;
|
||||
const { util } = mesh;
|
||||
|
||||
let groups = [];
|
||||
let selected = [];
|
||||
let toggle = {
|
||||
wire: false,
|
||||
bound: false
|
||||
};
|
||||
|
||||
let selection = {
|
||||
const selection = {
|
||||
// @returns {MeshObject[]} or all groups if not strict and no selection
|
||||
list(strict = false) {
|
||||
return selected.length || strict ? selected.slice() : groups.slice();
|
||||
|
|
@ -208,7 +200,7 @@ let selection = {
|
|||
}
|
||||
};
|
||||
|
||||
let group = {
|
||||
const group = {
|
||||
// @returns {MeshGroup[]}
|
||||
list() {
|
||||
return groups.slice();
|
||||
|
|
@ -292,7 +284,7 @@ function fallback(models, strict) {
|
|||
return Array.isArray(models) ? models : selection.models(strict);
|
||||
}
|
||||
|
||||
let tool = {
|
||||
const tool = {
|
||||
merge(models) {
|
||||
models = fallback(models);
|
||||
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
|
||||
let mode = {
|
||||
const mode = {
|
||||
set(mode) {
|
||||
prefs.save(prefs.map.mode = mode);
|
||||
for (let key of Object.values(modes)) {
|
||||
|
|
@ -495,7 +487,7 @@ let prefsig;
|
|||
let prefsignew;
|
||||
|
||||
// persisted preference map
|
||||
let prefs = {
|
||||
const prefs = {
|
||||
map: {
|
||||
info: {
|
||||
group: "show",
|
||||
|
|
@ -541,7 +533,7 @@ let prefs = {
|
|||
};
|
||||
|
||||
// api is augmented in mesh.build (log, modal, download)
|
||||
let api = mesh.api = {
|
||||
const api = exports({
|
||||
help() {
|
||||
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 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
|
||||
broker.wrapObject(selection, 'selection');
|
||||
broker.wrapObject(model, 'model');
|
||||
|
|
@ -645,4 +637,4 @@ broker.wrapObject(group, 'group');
|
|||
// optimize db writes by merging updates
|
||||
prefs.save = util.deferWrap(prefs.save, 100);
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ gapp.register("mesh.build",[
|
|||
]);
|
||||
|
||||
let mesh = self.mesh = self.mesh || {};
|
||||
if (mesh.build) return;
|
||||
|
||||
let broker = gapp.broker;
|
||||
let call = broker.send;
|
||||
|
|
|
|||
Loading…
Reference in a new issue