diff --git a/src/mesh/model.js b/src/mesh/model.js index f0229544..3d5f0f04 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -149,8 +149,9 @@ mesh.model = class MeshModel extends mesh.object { let geo = this.mesh.geometry; geo.setAttribute('position', new BufferAttribute(vertices, 3)); geo.setAttribute('normal', undefined); + // signal util.box3expand that geometry changed + geo._model_invalid = true; if (indices) geo.setIndex(new BufferAttribute(indices, 1)); - geo.attributes.position.needsUpdate = true; if (!normals) geo.computeVertexNormals(); // persist in db so it can be restored on page load mapp.db.space.put(this.id, { file: this.file, mesh: vertices }); diff --git a/src/mesh/util.js b/src/mesh/util.js index 8172e929..98db5a4c 100644 --- a/src/mesh/util.js +++ b/src/mesh/util.js @@ -110,7 +110,8 @@ let util = mesh.util = { let matrix = object.matrixWorld; let bkey = [matrix.elements.map(v => v.round(5))].join(',') let cached = boundsCache[object.id]; - if (!cached || cached.bkey !== bkey) { + // geometry._model_invalid set on model.reload(), usually after a split + if (!cached || cached.bkey !== bkey || geometry._model_invalid) { let position = geometry.attributes.position.clone(); position.applyMatrix4(new Matrix4().extractRotation(matrix)); let bounds = new Box3().setFromBufferAttribute(position); @@ -118,6 +119,7 @@ let util = mesh.util = { // bounds.min.multiply(scale); // bounds.max.multiply(scale); cached = boundsCache[object.id] = { bkey, bounds }; + geometry._model_invalid = undefined; } let bt = cached.bounds.clone(); let m4 = new Matrix4();