Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.              var perspectiveCamera, scene, renderer,cameraControls,box,plane,light,light2;
  2.             var dxPerFrame = 0.1;
  3.             var dyPerFrame = 0.1;
  4.             init();
  5.             animate();
  6.             function init() {
  7.                
  8.                 var aspect = window.innerWidth / window.innerHeight;
  9.  
  10.                 perspectiveCamera = new THREE.PerspectiveCamera( 60, aspect, 1, 100 );
  11.                 perspectiveCamera.position.z = 10;
  12.  
  13.  
  14.                 scene = new THREE.Scene();
  15.                 var textureLoader= new THREE.TextureLoader();
  16.                 textureLoader.load('dsj.png', function(texture){
  17.                     scene.background = texture;
  18.                 });
  19.                 light2 = new THREE.PointLight( 0xf2eeeb );
  20.                 light2.position.set(5,5,0);
  21.                 light2.castShadow = true;
  22.                 light2.intensity = 0.5;
  23.                 scene.add(light2);
  24.  
  25.                 light = new THREE.PointLight( 0xf2eeeb );
  26.                 light.castShadow = true;
  27.                 //scene.add( light );
  28.  
  29.                 var geometryBox = new THREE.BoxGeometry(1.5,1.5,1.5,1.0);
  30.                 var textureBox = new THREE.TextureLoader().load( 'malysz.jpg' );
  31.                 var materialBox = new THREE.MeshBasicMaterial({ map: textureBox });
  32.                 box = new THREE.Mesh(geometryBox,materialBox);
  33.                 box.castShadow = true;
  34.                 scene.add(box);
  35.  
  36.                 var geometryPlane = new THREE.BoxBufferGeometry( 10, 0.2, 10 );
  37.                 var materialPlane = new THREE.MeshPhongMaterial({
  38.                     color: 0xfff25c
  39.                 });
  40.                 plane = new THREE.Mesh( geometryPlane, materialPlane );
  41.                 plane.position.y = -0.75;
  42.                 plane.receiveShadow = true;
  43.                 scene.add(plane);
  44.  
  45.                
  46.  
  47.                 renderer = new THREE.WebGLRenderer( { antialias: true } );
  48.                 renderer.setSize( window.innerWidth, window.innerHeight );
  49.                 renderer.shadowMap.enabled = true;
  50.                 renderer.shadowMap.type = THREE.PCFSoftShadowMap;
  51.                 document.body.appendChild( renderer.domElement );
  52.                 cameraControls = new THREE.OrbitControls(perspectiveCamera,render.domElement);
  53.                 perspectiveCamera.add(light);
  54.                 //light.target = box;
  55.                 scene.add(perspectiveCamera);
  56.             }
  57.             function animate() {
  58.                 box.rotation.y += 0.03;
  59.                 requestAnimationFrame( animate );
  60.                 cameraControls.update();
  61.                 light.position.copy( perspectiveCamera.position );
  62.                 renderer.render(scene, perspectiveCamera);
  63.             }
  64.             function render() {
  65.                 renderer.render( scene, perspectiveCamera );
  66.  
  67.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement