use bounds caching to speed up rotate & scale operations
This commit is contained in:
parent
6ca6479c58
commit
155d01db5b
1 changed files with 14 additions and 3 deletions
|
|
@ -298,6 +298,7 @@ let api = mesh.api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let deferFn = [];
|
let deferFn = [];
|
||||||
|
let boundsCache = {};
|
||||||
|
|
||||||
let util = mesh.util = {
|
let util = mesh.util = {
|
||||||
|
|
||||||
|
|
@ -381,9 +382,19 @@ let util = mesh.util = {
|
||||||
|
|
||||||
if (geometry) {
|
if (geometry) {
|
||||||
let matrix = object.matrixWorld;
|
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();
|
let position = geometry.attributes.position.clone();
|
||||||
position.applyMatrix4(new THREE.Matrix4().extractRotation(matrix));
|
position.applyMatrix4(new THREE.Matrix4().extractRotation(matrix));
|
||||||
let bounds = new THREE.Box3().setFromBufferAttribute(position);
|
bounds = new THREE.Box3().setFromBufferAttribute(position);
|
||||||
|
cached = boundsCache[object.id] = {
|
||||||
|
bkey,
|
||||||
|
bounds
|
||||||
|
};
|
||||||
|
}
|
||||||
|
bounds = cached.bounds.clone();
|
||||||
let bt = new THREE.Box3().copy(bounds);
|
let bt = new THREE.Box3().copy(bounds);
|
||||||
let m4 = new THREE.Matrix4();
|
let m4 = new THREE.Matrix4();
|
||||||
m4.setPosition(new THREE.Vector3().setFromMatrixPosition(object.matrixWorld));
|
m4.setPosition(new THREE.Vector3().setFromMatrixPosition(object.matrixWorld));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue