From 53df5eb6849b0bd34cbc9c444b09536c82d7848e Mon Sep 17 00:00:00 2001 From: Steven Vergenz Date: Fri, 9 Feb 2018 15:45:48 -0800 Subject: [PATCH] Add n-gltf loaded event, bounding box --- examples/aframe/native-gltf.html | 29 ++++++++++++++++++++++++++++- src/components/NGLTF.js | 23 +++++++++++++++++++++++ src/components/NativeComponent.js | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/examples/aframe/native-gltf.html b/examples/aframe/native-gltf.html index fd97d3ac..407ec9b1 100644 --- a/examples/aframe/native-gltf.html +++ b/examples/aframe/native-gltf.html @@ -4,10 +4,37 @@ Native glTF + - + diff --git a/src/components/NGLTF.js b/src/components/NGLTF.js index e0bfdab0..44606fde 100644 --- a/src/components/NGLTF.js +++ b/src/components/NGLTF.js @@ -42,4 +42,27 @@ export default class NGLTF extends NativeComponent { altspace.updateNativeComponent(mesh, this.name, data); } } + + /** + * Returns a promise that resolves with a [THREE.Box3](https://threejs.org/docs/index.html#api/math/Box3) + * @instance + * @method getBoundingBox + * @memberof module:altspace/components.n-gltf + * @returns {Promise} + */ + getBoundingBox() + { + return this.callComponent('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) + ); + }) + } } + +/** +* Emitted when the glTF model is finished loading +* @event module:altspace/components.n-gltf#n-gltf-loaded +*/ diff --git a/src/components/NativeComponent.js b/src/components/NativeComponent.js index 0db05626..33c36fbe 100644 --- a/src/components/NativeComponent.js +++ b/src/components/NativeComponent.js @@ -73,7 +73,7 @@ class NativeComponent extends AFrameComponent callComponent(name, ...args){ let mesh = this.mesh || this.el.object3DMap.mesh; - altspace.callNativeComponent(mesh, this.name, name, args); + return altspace.callNativeComponent(mesh, this.name, name, args); } }