Created
May 10, 2017 01:19
-
-
Save kevzettler/5cc1290e4439e1123c10f8a174de024d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //COMPONENT | |
| class Scene extends Component { | |
| componentDidMount(){ | |
| this.props.addNodeToScene({ | |
| asset: "mechsniper-hands.qb", | |
| position: [0,0,0] | |
| }); | |
| } | |
| renderNodes(){ | |
| if(!this.props.root || !!this.props.root.children){ | |
| return null; | |
| } | |
| return this.props.root.children.map((sceneTreeNode) => { | |
| return sceneTreeNode.component; | |
| }); | |
| } | |
| render(){ | |
| return( | |
| <Camera> | |
| {this.renderNodes()}; | |
| </Camera> | |
| ); | |
| } | |
| }; | |
| const mapStateToProps = (state, ownProps) => { | |
| return { | |
| root: ownProps.root, | |
| }; | |
| }; | |
| export default connect({ | |
| addNodeToScene | |
| })(Scene); | |
| //ACCTION | |
| export const addNodeToScene = (nodeDefinition) => (dispatch, getState) => { | |
| if(nodeDefinition.asset){ | |
| return fetchAssetBinary(nodeDefinition.asset)(dispatch, getState).then((buffer) => { | |
| dispatch({ | |
| type: ADD_NODE_TO_SCENE, | |
| node: nodeDefinition | |
| }); | |
| }); | |
| } | |
| dispatch({ | |
| type: ADD_NODE_TO_SCENE, | |
| node: nodeDefinition | |
| }); | |
| }; | |
| //REDUCER | |
| const sceneReducer = (scene = {}, action) => { | |
| switch(action.type){ | |
| case ADD_NODE_TO_SCENE: | |
| const node = Node(action.node); | |
| root.addOne(QBNode); | |
| return Object.assign({}, scene); | |
| break; | |
| default: | |
| return scene; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment