Skip to content

Instantly share code, notes, and snippets.

@BlueMagnificent
Last active July 31, 2021 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlueMagnificent/70344e1ddc3640cc28cb75de1b255e68 to your computer and use it in GitHub Desktop.
Save BlueMagnificent/70344e1ddc3640cc28cb75de1b255e68 to your computer and use it in GitHub Desktop.
Javascript 3D Physics Setup Graphics
function setupGraphics(){
//create clock for timing
clock = new THREE.Clock();
//create the scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xbfd1e5 );
//create camera
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.2, 5000 );
camera.position.set( 0, 30, 70 );
camera.lookAt(new THREE.Vector3(0, 0, 0));
//Add hemisphere light
let hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.1 );
hemiLight.color.setHSL( 0.6, 0.6, 0.6 );
hemiLight.groundColor.setHSL( 0.1, 1, 0.4 );
hemiLight.position.set( 0, 50, 0 );
scene.add( hemiLight );
//Add directional light
let dirLight = new THREE.DirectionalLight( 0xffffff , 1);
dirLight.color.setHSL( 0.1, 1, 0.95 );
dirLight.position.set( -1, 1.75, 1 );
dirLight.position.multiplyScalar( 100 );
scene.add( dirLight );
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 2048;
dirLight.shadow.mapSize.height = 2048;
let d = 50;
dirLight.shadow.camera.left = -d;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = -d;
dirLight.shadow.camera.far = 13500;
//Setup the renderer
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0xbfd1e5 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.shadowMap.enabled = true;
}
function renderFrame(){
let deltaTime = clock.getDelta();
renderer.render( scene, camera );
requestAnimationFrame( renderFrame );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment