From 6921142949e71726fe3ec71e7fb6af7792a230e7 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 8 Jan 2022 16:54:09 -0500 Subject: [PATCH] simplify cache code --- src/mesh/api.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mesh/api.js b/src/mesh/api.js index 2da7eedf..0d69c0b8 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -384,18 +384,14 @@ let util = mesh.util = { let matrix = object.matrixWorld; 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 + cached = boundsCache[object.id] = { bkey, + bounds: new THREE.Box3().setFromBufferAttribute(position) }; } - bounds = cached.bounds.clone(); - let bt = new THREE.Box3().copy(bounds); + let bt = cached.bounds.clone(); let m4 = new THREE.Matrix4(); m4.setPosition(new THREE.Vector3().setFromMatrixPosition(object.matrixWorld)); bt.applyMatrix4(m4);