Skip to content

Commit

Permalink
Add visible polyfill, collapse-model
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvergenz committed Nov 7, 2017
1 parent 2f55654 commit fb3d303
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/components/AltspaceComponent.js
Expand Up @@ -267,4 +267,8 @@ class AltspaceComponent extends AFrameComponent
}
}

AFRAME.components.visible.Component.prototype.update = () => {
this.el.object3D.traverse(obj => obj.visible = this.data);
}

export default AltspaceComponent;
29 changes: 29 additions & 0 deletions src/components/CollapseModel.js
@@ -0,0 +1,29 @@
import {AFrameComponent} from './AFrameComponent';

/**
* Reaches into a model's hierarchy and directly assigns the first mesh found
* to the containing entity. This is mostly necessary for use alongside native
* components like [n-skeleton-parent]{@link module:altspace/components.n-skeleton-parent}. @aframe
*
* @alias collapse-model
* @memberof module:altspace/components
* @extends module:altspace/components.AFrameComponent
*/
export default 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));
});
}
}
22 changes: 0 additions & 22 deletions src/components/UtilComponents.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/index.js
Expand Up @@ -44,7 +44,7 @@ import NContainer from './NContainer';
import NPortal from './NPortal';
import NSound from './NSound';
import NLayoutBrowser from './NLayoutBrowser';
import {CollapseModel} from './UtilComponents';
import CollapseModel from './CollapseModel';

if (window.AFRAME)
{
Expand Down

0 comments on commit fb3d303

Please sign in to comment.