From 9ad8b7fed9b08853d27a5060ff564ab08276f021 Mon Sep 17 00:00:00 2001 From: Steven Vergenz Date: Wed, 14 Feb 2018 15:54:25 -0800 Subject: [PATCH] Cache getBounds result, add spec-gloss to example --- examples/aframe/native-gltf.html | 7 +++++-- src/components/NGLTF.js | 28 ++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/examples/aframe/native-gltf.html b/examples/aframe/native-gltf.html index 407ec9b1..94124549 100644 --- a/examples/aframe/native-gltf.html +++ b/examples/aframe/native-gltf.html @@ -32,9 +32,12 @@ - + diff --git a/src/components/NGLTF.js b/src/components/NGLTF.js index 46cc546b..98fe3ce6 100644 --- a/src/components/NGLTF.js +++ b/src/components/NGLTF.js @@ -33,7 +33,12 @@ export default class NGLTF extends NativeComponent { sceneIndex: { type: 'int' } }; } - update(){ + init(){ + NativeComponent.prototype.init.call(this); + this.boundsCache = null; + } + update(oldData) + { let mesh = this.mesh || this.el.object3DMap.mesh; var data = Object.assign({}, this.data); data.url = new Url(data.url).toString(); @@ -41,6 +46,10 @@ export default class NGLTF extends NativeComponent { if(this.sendUpdates){ altspace.updateNativeComponent(mesh, this.name, data); } + + if(this.data.url && oldData && this.data.url !== oldData.url){ + this.boundsCache = null; + } } /** @@ -52,13 +61,16 @@ export default class NGLTF extends NativeComponent { */ getBoundingBox() { - return this.callComponentFunc('GetBoundingBox').then(data => { - const V3 = AFRAME.THREE.Vector3; - return new AFRAME.THREE.Box3( - new V3().subVectors(data.center, data.extents), - new V3().addVectors(data.center, data.extents) - ); - }) + if(!this.boundsCache){ + this.boundsCache = this.callComponentFunc('GetBoundingBox').then(data => { + const V3 = AFRAME.THREE.Vector3; + return new AFRAME.THREE.Box3( + new V3().subVectors(data.center, data.extents), + new V3().addVectors(data.center, data.extents) + ); + }); + } + return this.boundsCache; } }