浏览代码

Set camera to 0,0,0 in webvr_shadow.

Mr.doob 8 年之前
父节点
当前提交
eb71b74d47
共有 1 个文件被更改,包括 16 次插入9 次删除
  1. 16 9
      examples/webvr_shadow.html

+ 16 - 9
examples/webvr_shadow.html

@@ -43,18 +43,14 @@
 
 				scene = new THREE.Scene();
 
-				var dummy = new THREE.Camera();
-				dummy.position.set( 0, 0.5, 3 );
-				dummy.lookAt( new THREE.Vector3( 0, 0.5, 0 ) );
-				scene.add( dummy );
-
 				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
-				dummy.add( camera );
+				scene.add( camera );
 
 				var geometry = new THREE.TorusKnotGeometry( 0.4, 0.15, 150, 20 );
 				var material = new THREE.MeshStandardMaterial( { roughness: 0.01, metalness: 0.2 } );
 				var mesh = new THREE.Mesh( geometry, material );
 				mesh.position.y = 0.75;
+				mesh.position.z = - 2;
 				mesh.castShadow = true;
 				mesh.receiveShadow = true;
 				scene.add( mesh );
@@ -63,28 +59,39 @@
 				var material = new THREE.MeshStandardMaterial( { roughness: 1.0, metalness: 0.0 } );
 				var mesh = new THREE.Mesh( geometry, material );
 				mesh.position.y = - 0.2;
+				mesh.position.z = - 2;
 				mesh.castShadow = true;
 				mesh.receiveShadow = true;
 				scene.add( mesh );
 
 				var light = new THREE.DirectionalLight( 0x8800ff );
-				light.position.set( - 1, 1.5, 0.5 );
+				light.position.set( - 1, 1.5, - 1.5 );
 				light.castShadow = true;
 				light.shadow.camera.zoom = 4;
 				scene.add( light );
+				light.target.position.set( 0, 0, - 2 );
+				scene.add( light.target );
+
+				var helper = new THREE.CameraHelper( light.shadow.camera );
+				// scene.add( helper );
 
 				var light = new THREE.DirectionalLight( 0xff0000 );
-				light.position.set( 1, 1.5, - 0.5 );
+				light.position.set( 1, 1.5, - 2.5 );
 				light.castShadow = true;
 				light.shadow.camera.zoom = 4;
 				scene.add( light );
+				light.target.position.set( 0, 0, - 2 );
+				scene.add( light.target );
+
+				var helper = new THREE.CameraHelper( light.shadow.camera );
+				// scene.add( helper );
 
 				//
 
 				mirror = new THREE.Mirror( 1.4, 1.4, { textureWidth: window.innerWidth, textureHeight: window.innerHeight } );
 				mirror.position.x = 1;
 				mirror.position.y = 0.5;
-				mirror.position.z = -1;
+				mirror.position.z = -3;
 				mirror.rotation.y = - Math.PI / 4;
 				scene.add( mirror );