Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

216 lines (169 sloc) 6.268 kb
<!doctype html>
<html>
<head>
<title>learningthree.js boiler plate for three.js</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="vendor/three.js/Three.js"></script>
<script src="vendor/three.js/Detector.js"></script>
<!-- https://github.com/mrdoob/stats.js -->
<script src="vendor/three.js/Stats.js"></script>
<script src="vendor/threex/THREEx.screenshot.js"></script>
<script src="vendor/threex/THREEx.FullScreen.js"></script>
<script src="vendor/threex/THREEx.WindowResize.js"></script>
<script src="vendor/threex.dragpancontrols.js"></script>
<script src='vendor/pixastic/pixastic.all.min.js'></script>
<script src="js/cubeMap.js"></script>
<script src="js/lensFlare.js"></script>
<script src="js/sunDial.js"></script>
<link href="css/main.css" rel="stylesheet"/>
</head>
<body>
<!-- three.js container -->
<div id="container"></div>
<!-- info on screen display -->
<div id="info">
<div class="top">
<a href="http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js/" target="_blank">LearningThree.js</a>
boiler plate for
<a href="https://github.com/mrdoob/three.js/" target="_blank">three.js</a>
</div>
<div class="bottom" id="inlineDoc" >
- <i>p</i> for screenshot
</div>
</div>
<script type="text/javascript">
var stats, scene, renderer;
var camera, cameraControl;
if( !init() ) animate();
// init the scene
function init(){
if( Detector.webgl ){
renderer = new THREE.WebGLRenderer({
antialias : true, // to get smoother output
preserveDrawingBuffer : true // to allow screenshot
});
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
}else{
Detector.addGetWebGLMessage();
return true;
}
renderer.setSize( window.innerWidth, window.innerHeight );
document.getElementById('container').appendChild(renderer.domElement);
// add Stats.js - https://github.com/mrdoob/stats.js
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
document.body.appendChild( stats.domElement );
// create a scene
scene = new THREE.Scene();
// put a camera in the scene
camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.01, 10000 );
camera.position.set(-0.5, 1.5, 7);
camera.lookAt(new THREE.Vector3(0, 3., 0));
scene.add(camera);
// create a camera contol
cameraControls = new THREEx.DragPanControls(camera)
cameraControls.target = new THREE.Vector3(0, 1, 0);
// transparently support window resize
THREEx.WindowResize.bind(renderer, camera);
// allow 'p' to make screenshot
THREEx.Screenshot.bindKey(renderer);
// allow 'f' to go fullscreen where this feature is supported
if( THREEx.FullScreen.available() ){
THREEx.FullScreen.bindKey();
document.getElementById('inlineDoc').innerHTML += "- <i>f</i> for fullscreen";
}
// here you add your objects
// - you will most likely replace this part by your own
var ambient = new THREE.AmbientLight( 0x888888 );
scene.add( ambient );
var light = new THREE.DirectionalLight( 0xAA8888 );
light.position.set( -0.1, 0.8, -1 ).normalize();
light.position.setLength(5);
light.castShadow = true;
light.shadowCameraLeft = -5;
light.shadowCameraRight = 5;
light.shadowCameraTop = 5;
light.shadowCameraBottom = -5;
light.shadowDarkness = 0.3;
shadowLight = light;
scene.add( light );
var light = new THREE.DirectionalLight( 0x222266 );
light.position.set( -0.1, 0.8, -1 ).negate().normalize();
scene.add( light );
//var light = new THREE.DirectionalLight( 0xff8080 );
//light.position.set( -1, -1, -1 ).normalize();
//scene.add( light );
// lens flares
addLensFlare();
// cube
addCubeMap()
buildSunDialObject();
var light = new THREE.SpotLight( 0x4444FF, 2 );
scene.add( light.target );
light.castShadow = true;
light.shadowCameraNear = 0.01;
light.shadowCameraFov = 100;
light.shadowDarkness = 0.6;
light.shadowCameraVisible = true;
scene.add( light );
spot1 = light;
console.log("light", light, light.target.position)
var material = new THREE.MeshPhongMaterial({
ambient : 0xAA88FF,
color : 0x8844FF,
ambient : 0xaaaaaa,
color : 0xaaaaaa,
shading : THREE.SmoothShading,
map : THREE.ImageUtils.loadTexture( "images/water.jpg" ),
blending : THREE.AdditiveBlending,
transparent : true,
opacity : 0.3,
//map : THREE.ImageUtils.loadTexture( "images/moon_1024.jpg" )
});
var geometry = new THREE.SphereGeometry(0.6 , 32, 16)
var mesh = new THREE.Mesh(geometry, material)
mesh.position = light.position;
scene.add( mesh );
moon = mesh;
}
// animation loop
function animate() {
// loop on request animation loop
// - it has to be at the begining of the function
// - see details at http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
requestAnimationFrame( animate );
// do the render
render();
// update stats
stats.update();
}
// render the scene
function render() {
var seconds = Date.now() / 1000;
var piPerSecond = seconds * Math.PI;
var hours = seconds % 12;
var date = new Date();
var hours = date.getHours() % 12 + date.getMinutes()/60;
sundial.rotation.y = hours * Math.PI/6;
var angle = (1/4)*piPerSecond;
var light = spot1;
light.position.set( Math.cos(angle)*5.5, 3.5, Math.sin(angle)*5.5 );
light.target.position.set(Math.cos(angle)*3, 0, Math.sin(angle)*3);
moon.rotation.y = 2*angle;
var intensity = Math.pow(Math.abs(Math.cos(angle*5)), 4);
moon.material.opacity = 0.5 + 0.5*intensity;
moon.scale.set( 0.5+0.5*intensity, 0.5+0.5*intensity, 0.5+0.5*intensity );
//spot1.color = 0x404040 + 0x800080*intensity;
spot1.shadowDarkness = 0.2 + 0.8*intensity;
spot1.intensity = 1+intensity*4;
// update camera controls
cameraControls.update();
// actually render the scene
renderer.render( scene, camera );
}
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.