123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - Omni-directional Shadow map viewer example </title>
- <meta charset="utf-8">
- <style>
- body {
- font-family: Monospace;
- background-color: #000;
- color: #fff;
- margin: 0px;
- overflow: hidden;
- }
- #info {
- position: absolute;
- top: 10px;
- width: 100%;
- text-align: center;
- z-index: 100;
- display:block;
- }
- #info a { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="http://threejs.org" target="_blank">three.js</a> - Omni-directional Shadow map viewer example by <a href="https://github.com/mkkellogg">mkkellogg</a>
- </div>
- <script src="../build/three.min.js"></script>
- <script src="js/controls/OrbitControls.js"></script>
- <script src="js/Detector.js"></script>
- <script src="js/libs/stats.min.js"></script>
- <script>
-
- if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
- var camera, scene, renderer, clock, stats;
- var dirLight, pointLight;
- var pointLightParent;
- var torusKnot, cube, cube2, cube3, cube4;
- var cubeMaterial;
- var wallMaterial;
- var ground;
- init();
- animate();
- function init() {
- initScene();
- initMisc();
- document.body.appendChild( renderer.domElement );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function initScene() {
- camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 1000 );
- camera.position.set( 0, 15, 35 );
- scene = new THREE.Scene();
- // Lights
- var ambient = new THREE.AmbientLight( 0x404040 );
- scene.add( ambient );
- pointLight = new THREE.PointLight( 0xffffff );
- pointLight.position.set( 0, 11, 4 );
- pointLight.castShadow = true;
- pointLight.shadowCameraNear = 1;
- pointLight.shadowCameraFar = 30;
- pointLight.shadowDarkness = 0.5;
- pointLight.shadowCameraVisible = true;
- pointLight.shadowMapWidth = 2048;
- pointLight.shadowMapHeight = 1024;
- pointLight.name = 'Point Light';
- scene.add( pointLight );
- /*dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
- dirLight.position.set( 0, 50, 0 );
- dirLight.castShadow = true;
- dirLight.shadowCameraNear = 0.01;
- dirLight.shadowCameraFar = 100;
- dirLight.shadowCameraRight = 15;
- dirLight.shadowCameraLeft = -15;
- dirLight.shadowCameraTop = 15;
- dirLight.shadowCameraBottom = -15;
- dirLight.shadowDarkness = 0.5;
- dirLight.shadowCameraVisible = true;
- dirLight.shadowMapWidth = 1024;
- dirLight.shadowMapHeight = 1024;
- dirLight.name = 'Dir. Light';
- scene.add( dirLight );*/
- cubeMaterial = new THREE.MeshPhongMaterial( {
- color: 0xff0000,
- shininess: 150,
- specular: 0x222222,
- shading: THREE.SmoothShading,
- } );
- var cubeGeometry = new THREE.BoxGeometry( 3, 3, 3 );
- cube = new THREE.Mesh( cubeGeometry, cubeMaterial );
- cube.name = "cube 1";
- cube.position.set( 8, 3, 6 );
- cube.castShadow = true;
- cube.receiveShadow = true;
- scene.add( cube );
- cube2 = new THREE.Mesh( cubeGeometry, cubeMaterial );
- cube2.name = "cube 2";
- cube2.position.set( -8, 3, 4 );
- cube2.castShadow = true;
- cube2.receiveShadow = true;
- scene.add( cube2 );
- cube3 = new THREE.Mesh( cubeGeometry, cubeMaterial );
- cube3.name = "cube 3";
- cube3.position.set( -4, 15, -6 );
- cube3.castShadow = true;
- cube3.receiveShadow = true;
- scene.add( cube3 );
- var torusGeometry = new THREE.TorusKnotGeometry( 25, 8, 75, 20 );
- torusKnot = new THREE.Mesh( torusGeometry, cubeMaterial );
- torusKnot.scale.multiplyScalar( 1 / 18 );
- torusKnot.position.set( -1, 3, -4 );
- torusKnot.castShadow = true;
- torusKnot.receiveShadow = true;
- scene.add( torusKnot );
-
- wallMaterial = new THREE.MeshPhongMaterial( {
- color: 0xa0adaf,
- shininess: 10,
- specular: 0x111111,
- shading: THREE.SmoothShading
- } );
- var wallGeometry = new THREE.BoxGeometry( 10, 0.15, 10 );
- ground = new THREE.Mesh( wallGeometry, wallMaterial );
- ground.name = "ground";
- ground.scale.multiplyScalar( 3 );
- ground.castShadow = false;
- ground.receiveShadow = true;
- scene.add( ground );
- ground.position.set( 0, -5, 0 );
- var ceiling = new THREE.Mesh( wallGeometry, wallMaterial );
- ceiling.name = "ceiling";
- ceiling.scale.multiplyScalar( 3 );
- ceiling.castShadow = false;
- ceiling.receiveShadow = true;
- scene.add( ceiling );
- ceiling.position.set( 0, 24, 0 );
- var wall = new THREE.Mesh( wallGeometry, wallMaterial );
- wall.name = "left wall";
- wall.scale.multiplyScalar( 3 );
- wall.castShadow = false;
- wall.receiveShadow = true;
- scene.add( wall );
- wall.position.set( -14, 10, 0 );
- wall.rotation.z = Math.PI / 2;
- wall = new THREE.Mesh( wallGeometry, wallMaterial );
- wall.name = "right wall";
- wall.scale.multiplyScalar( 3 );
- wall.castShadow = false;
- wall.receiveShadow = true;
- scene.add( wall );
- wall.position.set(14,10,0);
- wall.rotation.z = Math.PI / 2;
- wall = new THREE.Mesh( wallGeometry, wallMaterial );
- wall.name = "back wall";
- wall.scale.multiplyScalar( 3 );
- wall.castShadow = false;
- wall.receiveShadow = true;
- scene.add( wall );
- wall.position.set( 0, 10, -14 );
- wall.rotation.y = Math.PI / 2;
- wall.rotation.z = Math.PI / 2;
- /*wall = new THREE.Mesh( wallGeometry, wallMaterial );
- wall.name = "front wall";
- wall.scale.multiplyScalar( 3 );
- wall.castShadow = false;
- wall.receiveShadow = true;
- scene.add( wall );
- wall.position.set( 0, 10, 14 );
- wall.rotation.y = Math.PI / 2;
- wall.rotation.z = Math.PI / 2;*/
- var sphereGeometry = new THREE.SphereGeometry( 1, 32, 32 );
- var material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
- var sphere = new THREE.Mesh( sphereGeometry, material );
- sphere.castShadow = false;
- sphere.receiveShadow = false;
- sphere.position.set( 0, 11, 4 );
- scene.add( sphere );
- pointLightParent = new THREE.Object3D();
- pointLightParent.add( pointLight );
- pointLightParent.add( sphere );
- scene.add( pointLightParent );
- }
- function initMisc() {
- renderer = new THREE.WebGLRenderer();
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.setClearColor( 0x000000 );
- renderer.shadowMap.enabled = true;
- renderer.shadowMap.type = THREE.PCFShadowMap;
- // Mouse control
- controls = new THREE.OrbitControls( camera, renderer.domElement );
- controls.target.set( 0, 2, 0 );
- controls.update();
- clock = new THREE.Clock();
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.right = '0px';
- stats.domElement.style.top = '0px';
- document.body.appendChild( stats.domElement );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function renderScene() {
- renderer.render( scene, camera );
- }
- function render() {
- var delta = clock.getDelta();
- pointLightParent.rotation.y += delta * 2;
- renderScene();
- cube.rotation.x += 0.25 * delta;
- cube.rotation.y += 2 * delta;
- cube.rotation.z += 1 * delta;
- cube2.rotation.x += 0.25 * delta;
- cube2.rotation.y += 2 * delta;
- cube2.rotation.z += 1 * delta;
- cube3.rotation.x += 0.25 * delta;
- cube3.rotation.y += 2 * delta;
- cube3.rotation.z += 1 * delta;
- }
- </script>
- </body>
- </html>
|