Skip to content

Commit

Permalink
Add collapse-model utility component
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvergenz committed Oct 19, 2017
1 parent 58ae469 commit 2f55654
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/components/UtilComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {AFrameComponent} from './AFrameComponent';

class CollapseModel extends AFrameComponent
{
init()
{
function getFirstMesh(obj){
if(obj.isMesh)
return obj;
else if(obj.children.length === 0)
return null;
else
return obj.children.map(c => getFirstMesh(c)).find(o => !!o);
}

this.el.addEventListener('model-loaded', () => {
this.el.setObject3D('mesh', getFirstMesh(this.el.object3DMap.mesh));
});
}
}

export {CollapseModel}
4 changes: 3 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import NContainer from './NContainer';
import NPortal from './NPortal';
import NSound from './NSound';
import NLayoutBrowser from './NLayoutBrowser';
import {CollapseModel} from './UtilComponents';

if (window.AFRAME)
{
Expand Down Expand Up @@ -73,12 +74,13 @@ if (window.AFRAME)
registerComponentClass('n-capsule-collider', NCapsuleCollider);
registerComponentClass('n-mesh-collider', NMeshCollider);
registerComponentClass('n-layout-browser', NLayoutBrowser);
registerComponentClass('collapse-model', CollapseModel);
}

export {
AltspaceComponent, AltspaceCursorCollider, AltspaceTrackedControls, SyncSystem,
SyncComponent, SyncColor, SyncTransform, SyncNSound, Wire, OnePerUser, Instantiator,
SyncNSkeletonParent, NObject, NPortal, NSpawner, NText, NBillboard, NSkeletonParent,
NCockpitParent, NContainer, NSound, NSphereCollider, NBoxCollider, NCapsuleCollider,
NMeshCollider, NLayoutBrowser
NMeshCollider, NLayoutBrowser, CollapseModel
};

0 comments on commit 2f55654

Please sign in to comment.