workaround for geometry bounds changes not triggered by matrix changes
This commit is contained in:
parent
1048cee330
commit
30fe38d662
2 changed files with 5 additions and 2 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue