save restore workspace view

This commit is contained in:
Stewart Allen 2022-01-04 09:48:36 -05:00
commit 77393a9c2e
5 changed files with 38 additions and 27 deletions

View file

@ -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});
}

View file

@ -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;
}
};