/** Copyright Stewart Allen -- All Rights Reserved */ import '../add/array.js'; import '../add/class.js'; import '../add/three.js'; import '../mesh/build.js'; import { api } from '../mesh/api.js'; import { space } from '../moto/space.js'; import { broker } from '../moto/broker.js'; import { $, $d, h, estop } from '../moto/webui.js'; import { handles } from '../mesh/handles.js'; import { client as motoClient } from '../moto/client.js'; import { split as meshSplit } from '../mesh/split.js'; import { model as meshModel, materials } from '../mesh/model.js'; import { edges as meshEdges } from '../mesh/edges.js'; import { open as dataOpen } from '../data/index.js'; import { load as fileLoad } from '../load/file.js'; import { THREE } from '../ext/three.js'; import { createDocumentManager } from '../mesh/document.js'; const version = '1.5.7'; const call = broker.send; const dbindex = [ "admin", "documents", "versions" ]; const DOC_META_KEY = '__doc'; const { Quaternion } = THREE; function log() { return api.log.emit(...arguments); } function boot_status(message = 'loading...') { const curtain = $('curtain'); if (!curtain) return; curtain.textContent = String(message || 'loading...'); } function boot_start(message = 'loading...') { $('app')?.classList?.add('booting'); boot_status(message); $d('curtain', 'flex'); } function boot_done() { $('app')?.classList?.remove('booting'); $d('curtain', 'none'); } function get_doc_meta(meta = metaCache) { if (!meta || typeof meta !== 'object') return {}; return meta[DOC_META_KEY] || {}; } function capture_camera_state() { return { place: space.view.save(), focus: space.view.getFocus() }; } function apply_camera_state(camera) { if (!camera) return; if (camera.place) { space.view.load(camera.place); } if (camera.focus) { space.view.setFocus(camera.focus); } } function save_camera_to_document() { const dmeta = get_doc_meta(metaCache); metaCache[DOC_META_KEY] = { ...dmeta, camera: capture_camera_state() }; store_meta(); } let cameraSaveTimer = null; function schedule_camera_save(delay = 120) { clearTimeout(cameraSaveTimer); cameraSaveTimer = setTimeout(() => { cameraSaveTimer = null; save_camera_to_document(); }, delay); } // set below. called once the DOM readyState = complete // this is the main() entrypoint called after all dependents load function init() { let stores = dataOpen('mesh', { stores: dbindex, version: 5 }).init(), dark = false, ortho = false, zoomrev = true, zoomspd = 1, platform = space.platform, db = api.db = { admin: stores.promise('admin'), documents: stores.promise('documents'), versions: stores.promise('versions') }; const docman = api.document = createDocumentManager({ admin: db.admin, documents: db.documents, versions: db.versions, maxRevisions: 200 }); db.space = docman.spaceStore; // initialize the API (to avoid circular dependencies) api.init(); boot_start('initializing mesh:tool'); // mark init time and use count db.admin.put("init", Date.now()); db.admin.get("uses").then(v => db.admin.put("uses", (v||0) + 1)); // setup default workspace space.setAntiAlias(true); space.useDefaultKeys(false); space.init($('container'), delta => { }, ortho); space.sky.set({ grid: false, color: dark ? 0 : 0xffffff }); platform.set({ volume: false, round: false, zOffset: 0, opacity: 0, color: 0xdddddd, zoom: { reverse: true, speed: 1 }, size: { width: 2000, depth: 2000, height: 0.05, maxz: 2000 }, grid: { major: 25, minor: 5, zOffset: 0, colorMajor: 0xcccccc, colorMinor: 0xeeeeee, colorX: 0xff7777, colorY: 0x7777ff }, }); platform.onMove(() => { // save camera per-document save_camera_to_document(); }, 100); space.view.setZoom(zoomrev, zoomspd); // trigger ui building call.ui_build(); // trigger space event binding call.space_init({ space: space, platform }); // CMMS embedding (not upstream): the host page (public/mesh-edit.php) // iframes this at /mesh/?cmms_load=...&cmms_save=...&cmms_owner=... // &cmms_csrf=...&cmms_name=... when launched job-scoped to repair one // specific attachment, rather than the normal freestanding app. // Query params, not a window.MESH_TOOL_CONFIG global set by the parent // frame: this app's own served index.html isn't something the CMMS // renders, so there's no point to inject a