Created
October 29, 2013 23:28
-
-
Save hapticdata/7224594 to your computer and use it in GitHub Desktop.
A quick + consistent way to setup a three.js scene
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
define([ | |
'three' | |
], function( THREE ){ | |
/** | |
* quickly set up all of the basics of a THREE.js canvas | |
* @param {Object} [app] the settings for the app | |
* @param {Number} [app.width] | |
* @param {Number} [app.height] | |
* @param {Number} [app.fov] | |
* @param {Number} [app.aspect] | |
* @param {Number} [app.near] | |
* @param {Number} [app.far] | |
* @param {Number} [app.scene] | |
* @param {Number} [app.camera] | |
* @param {Number} [app.renderer] | |
* @param {Function} [fn] function to call will param signature `( scene, camera, renderer )` | |
* @return {Object} app | |
*/ | |
return function( app, fn ){ | |
if( arguments.length === 1 && typeof app === 'function' ){ | |
fn = app; | |
app = {}; | |
} | |
app = app || {}; | |
fn = fn || function(){}; | |
app.width = app.width || window.innerWidth; | |
app.height = app.height || window.innerHeight; | |
app.fov = app.fov || 65; | |
app.aspect = app.width / app.height; | |
app.near = typeof app.near === 'number' ? app.near : 0.1; | |
app.far = app.far || 10000; | |
app.scene = app.scene || new THREE.Scene(); | |
app.camera = app.camera || new THREE.PerspectiveCamera( app.fov, app.aspect, app.near, app.far ); | |
app.renderer = app.renderer || new THREE.WebGLRenderer({ antialias: true }); | |
app.renderer.setSize( app.width , app.height ); | |
fn.call(app, app.scene, app.camera, app.renderer); | |
return app; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
basic example:
animitter is a simple requestAnimationFrame lib