This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
198 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,87 @@ | ||
import immutable from 'object-path-immutable'; | ||
import * as $ from '../util'; | ||
import { wiggleReducer } from './wiggle'; | ||
import { boxesReducer } from './boxes'; | ||
import * as wiggle from './wiggle'; | ||
import * as boxes from './boxes'; | ||
import * as vox from './vox'; | ||
import * as X from '../selectors'; | ||
|
||
// @todo: clean up for full example stack | ||
const children = { boxes, vox }; | ||
|
||
export const SET_EXAMPLE = 'Examples:SET_EXAMPLE'; | ||
export const actions = { | ||
setExample: d => (dispatch, getState) => { | ||
const local = X.example(getState()) || {}; | ||
|
||
const old = children[local.selected]; | ||
if (old && old.actions && old.actions.hide) { | ||
dispatch(old.actions.hide()); | ||
} | ||
|
||
const res = dispatch($.act(SET_EXAMPLE, d)); | ||
|
||
const updated = X.example(getState()) || {}; | ||
const current = children[updated.selected]; | ||
if (current && current.actions && current.actions.show) { | ||
return dispatch(current.actions.show()); | ||
} | ||
|
||
return res; | ||
}, | ||
}; | ||
|
||
|
||
// @todo: weird pattern: fucking poltergeist | ||
// @todo @todo -- classes of reducers.... hmmmmm.... | ||
const bluh = $.keyedReducer({ | ||
a: wiggleReducer, | ||
b: boxesReducer, | ||
a: wiggle.reducer, | ||
b: boxes.reducer, | ||
}); | ||
// @todo: weird pattern: fucking poltergeist -- composition?! WHAT. | ||
|
||
|
||
// @todo: this is a nice template reducer -- basics of "slice" reducer? | ||
// examples as discrete slices | ||
export const registry = { | ||
boxes: (slice, action, global) => bluh(global, action), | ||
vox: vox.reducer, | ||
}; | ||
|
||
export const registryKeys = Object.keys(registry); | ||
|
||
// Discrete examples | ||
const defaultState = { | ||
selected: registryKeys[0], | ||
selected: undefined, | ||
slice: {}, | ||
}; | ||
|
||
const sliceReducer = $.keyedReducer(registry); | ||
export const reducer = (state = defaultState, action, global) => { | ||
const sliceReducer = registry[state.selected]; | ||
const sliceState = state.slice[state.selected]; | ||
|
||
switch (action.type) { | ||
case SET_EXAMPLE: | ||
case SET_EXAMPLE: { | ||
if (!registry[action.payload]) { | ||
throw new Error('Unknown slice selected.'); | ||
} | ||
|
||
return { | ||
...state, | ||
example: action.payload, | ||
selected: action.payload, | ||
}; | ||
} | ||
|
||
// Run the current slice | ||
default: | ||
if (!sliceReducer) { | ||
return state; | ||
} | ||
|
||
return { | ||
...state, | ||
slice: sliceReducer(global, action), | ||
slice: immutable.set( | ||
state.slice, | ||
state.selected, | ||
sliceReducer(sliceState, action, global) | ||
), | ||
}; | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Mesh } from 'three'; | ||
import fp from 'lodash/fp'; | ||
|
||
import * as G from '../geom'; | ||
import * as S from '../scene'; | ||
|
||
const initVoxState = (state) => { | ||
const boxes = new Array(1000).fill(0).map(() => { | ||
const mesh = new Mesh(G.newBox(), G.Debug.normals); | ||
|
||
mesh.position.x = fp.random(-10000, 10000); | ||
mesh.position.y = fp.random(-10000, 10000); | ||
mesh.position.z = fp.random(-10000, 10000); | ||
|
||
return mesh; | ||
}); | ||
|
||
S.addActors(boxes, state.engine.scene); | ||
|
||
Object.assign(state.actors, { boxes }); | ||
|
||
return { | ||
boxes, | ||
}; | ||
}; | ||
|
||
export const reducer = (state, action, global) => { | ||
if (!state) { | ||
return initVoxState(global, action); | ||
} | ||
|
||
for (let i = 0; i < state.boxes.length; i++) { | ||
state.boxes[i].rotation.x += (i % 3) * 0.01; | ||
state.boxes[i].rotation.y += (i % 4) * 0.01; | ||
} | ||
|
||
return state; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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