Created
October 4, 2013 20:30
-
-
Save kishalmi/6832247 to your computer and use it in GitHub Desktop.
three.js traverse scenegraph and trigger event from all objects found
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
function render() { | |
var t = new Date().getTime() / 1000; // unixtime | |
var dt = clock.getDelta(); | |
dispatchSceneGraphEvent(scene, {type: 'preRender', t: t, dt: dt}); | |
renderer.clear(true, true, true); | |
renderer.render(scene, camera); | |
} | |
/** | |
* traverse the scenegraph and dispatch an event from every object found | |
* example usage: dispatchSceneGraphEvent( scene, {type: 'render', time: clock.getElapsedTime()} ); | |
* @param parent | |
* @param event | |
*/ | |
function dispatchSceneGraphEvent(parent, event) { | |
parent.dispatchEvent(event); | |
for (var i in parent.children) | |
dispatchSceneGraphEvent(parent.children[i], event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment