diff --git a/src/mesh/api.js b/src/mesh/api.js index 524a7903..2da7eedf 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -298,6 +298,7 @@ let api = mesh.api = { }; let deferFn = []; +let boundsCache = {}; let util = mesh.util = { @@ -381,9 +382,19 @@ let util = mesh.util = { if (geometry) { let matrix = object.matrixWorld; - let position = geometry.attributes.position.clone(); - position.applyMatrix4(new THREE.Matrix4().extractRotation(matrix)); - let bounds = new THREE.Box3().setFromBufferAttribute(position); + let bkey = [matrix.elements.map(v => v.round(5))].join(',') + let cached = boundsCache[object.id]; + let bounds; + if (!cached || cached.bkey !== bkey) { + let position = geometry.attributes.position.clone(); + position.applyMatrix4(new THREE.Matrix4().extractRotation(matrix)); + bounds = new THREE.Box3().setFromBufferAttribute(position); + cached = boundsCache[object.id] = { + bkey, + bounds + }; + } + bounds = cached.bounds.clone(); let bt = new THREE.Box3().copy(bounds); let m4 = new THREE.Matrix4(); m4.setPosition(new THREE.Vector3().setFromMatrixPosition(object.matrixWorld));