diff --git a/src/main/mesh.js b/src/main/mesh.js index b23a3a83..5452eed7 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -47,6 +47,13 @@ function init() { colorMajor: 0xcccccc, colorMinor: 0xeeeeee, colorX: 0xff7777, colorY: 0x7777ff }, }); + platform.onMove(() => { + // save last location and focus + db.admin.put('camera', { + place: space.view.save(), + focus: space.view.getFocus() + }); + }, 100); space.view.setZoom(zoomrev, zoomspd); // start worker @@ -65,30 +72,32 @@ function init() { $d('curtain','none'); } +// restore space layout and view from previous session function restore_space() { + let space = moto.Space; + mesh.db.admin.get("camera") + .then(saved => { + space.view.load(saved.place); + space.view.setFocus(saved.focus); + }); mesh.db.space.iterate({ map: true }).then(cached => { - let loaded = false; for (let [id, data] of Object.entries(cached)) { // restore group if (Array.isArray(data)) { - let models = loaded = data.map(id => { + let models = data.map(id => { let md = cached[id]; return new mesh.model(md, id); }); mesh.api.group.new(models, id) .centerModels() .centerXY() - .floor() - .focus(); + .floor(); } } - if (loaded) { - let space = moto.Space; - space.view.load(space.preset.top); - } }) } +// create html elements function ui_build() { // set app version $h('app-name', "Mesh:Tool"); @@ -197,11 +206,16 @@ function space_init(data) { moto.client.fn.model_heal(m.id) .then(data => { if (data) { - console.log({data}); + // api.group.new([new mesh.model({ + // file: 'healed', + // mesh: data.vertices.toFloat32(), + // // mesh: Float32Array.from([...data.v]), + // // index: Uint32Array.from([...data.f]) + // })]); m.reload( - // Float32Array.from(data.vertices.toFloat32()), - Float32Array.from([...data.v]), - Uint32Array.from([...data.f]) + Float32Array.from(data.vertices), + // Float32Array.from([...data.v]), + // Uint32Array.from([...data.f]) ); } }); diff --git a/src/mesh/model.js b/src/mesh/model.js index 9cd8c0e7..ba98c0e6 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -49,7 +49,7 @@ let materials = mesh.material = { mesh.model = class MeshModel extends mesh.object { constructor(data, id) { super(id); - let { file, mesh } = data; + let { file, mesh, index, vertices, indices } = data; if (!mesh) { dbug.error(`'${file}' missing mesh data`); @@ -62,7 +62,7 @@ mesh.model = class MeshModel extends mesh.object { if (dot > 0) file = text.substring(0, dot); this.file = file || 'unnamed'; - this.mesh = this.load(mesh); + this.load(mesh || vertices, index || indices); // persist in db so it can be restored on page load mapp.db.space.put(this.id, { file, mesh }); @@ -94,7 +94,7 @@ mesh.model = class MeshModel extends mesh.object { geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3)); if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1)); geo.computeVertexNormals(); - let meh = new THREE.Mesh(geo, materials.unselected); + let meh = this.mesh = new THREE.Mesh(geo, materials.unselected); meh.receiveShadow = true; meh.castShadow = true; meh.renderOrder = 1; @@ -102,7 +102,6 @@ mesh.model = class MeshModel extends mesh.object { meh.model = this; // sync data to worker worker.model_load({id: this.id, name: this.file, vertices, indices}); - return meh; } optimize(geo) { @@ -114,12 +113,9 @@ mesh.model = class MeshModel extends mesh.object { reload(vertices, indices) { this.wireframe(false); let geo = this.mesh.geometry; - geo.attributes.position.array = vertices; - geo.attributes.position.needsUpdate = true; + geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3)); geo.setAttribute('normal', undefined); - if (indices) { - geo.setIndex(new THREE.BufferAttribute(indices, 1)); - } + if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1)); geo.computeVertexNormals(); worker.model_load({id: this.id, name: this.name, vertices, indices}); } diff --git a/src/mesh/work.js b/src/mesh/work.js index 4919d8ea..dbff6f2e 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -55,13 +55,13 @@ let model = { debug: false }); dbug.log('...imported data'); - // tool.heal(); + tool.heal(); dbug.log('...healed'); dbug.log(tool); return true || tool.newFaces ? { vertices: tool.unrolled(), - v: tool.vertices, - f: tool.faces.map(f => f/3) + // v: tool.vertices, + // f: tool.faces.map(f => f/3) } : 0; } }; diff --git a/src/moto/orbit.js b/src/moto/orbit.js index dd3033f8..80ada152 100644 --- a/src/moto/orbit.js +++ b/src/moto/orbit.js @@ -202,8 +202,8 @@ MOTO.Orbit = function (object, domElement, notify, slider) { }; this.setTarget = function(t) { - this.target = t; - this.target0 = t.clone(); + this.target = new THREE.Vector3().add(t); + this.target0 = this.target.clone(); } function isValue(v) { diff --git a/src/moto/space.js b/src/moto/space.js index 3f296d5d..7cc82599 100644 --- a/src/moto/space.js +++ b/src/moto/space.js @@ -93,6 +93,7 @@ platformClick, platformClickAt, platformOnMove, + platformOnMoveTime = 500, platformMoveTimer, volume, light1, @@ -1012,7 +1013,7 @@ isHidden: () => { return !showPlatform }, isVisible: () => { return platform.visible }, opacity: (o) => { platform.material.opacity = o }, - onMove: (f) => { platformOnMove = f }, + onMove: (f,t) => { platformOnMove = f, platformOnMoveTime = t || platformOnMoveTime }, onHover: (f) => { platformHover = f }, onClick: (f) => { platformClick = f}, size: () => { return platform.scale },