workaround for geometry bounds changes not triggered by matrix changes

This commit is contained in:
Stewart Allen 2022-01-18 10:51:02 -05:00
commit 30fe38d662
2 changed files with 5 additions and 2 deletions

View file

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

View file

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