Skip to content

Commit

Permalink
Cache getBounds result, add spec-gloss to example
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvergenz committed Feb 14, 2018
1 parent 9517e78 commit 9ad8b7f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
7 changes: 5 additions & 2 deletions examples/aframe/native-gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
</head>
<body>
<a-scene altspace>
<a-entity id='native'
n-gltf='url: https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf'
<a-entity id='helmet' position='-1 0 0'
n-gltf='url: https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF-Binary/DamagedHelmet.glb'
draw-bounds></a-entity>
<a-entity id='lantern' position='1 -1.5 0' scale='.1 .1 .1'
n-gltf='url: https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/2.0/Lantern/glTF-pbrSpecularGlossiness/Lantern.gltf'
></a-entity>
</a-scene>
</body>
</html>
28 changes: 20 additions & 8 deletions src/components/NGLTF.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@ 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();

if(this.sendUpdates){
altspace.updateNativeComponent(mesh, this.name, data);
}

if(this.data.url && oldData && this.data.url !== oldData.url){
this.boundsCache = null;
}
}

/**
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 9ad8b7f

Please sign in to comment.