Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. var width = section.offsetWidth,
  2. height = section.offsetHeight;
  3.  
  4. var topOfElement = section.getBoundingClientRect().top - height;
  5. var bottomOfElement = section.getBoundingClientRect().bottom;
  6.  
  7. const scene = new THREE.Scene();
  8. const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
  9. camera.position.z = 10;
  10. camera.position.x = -2.5;
  11.  
  12. const controls = new THREE.OrbitControls( camera, renderer.domElement );
  13. controls.enableZoom = false;
  14. controls.maxPolarAngle = Math.PI;
  15.  
  16. const renderer = new THREE.WebGLRenderer( { alpha: true } );
  17. renderer.setClearColor( 0x000000, 0 );
  18. renderer.setSize(width, height);
  19. section.appendChild(renderer.domElement);
  20.  
  21. const onEverythingLoaded = () => {
  22. render();
  23. };
  24.  
  25. const loadingManager = new THREE.LoadingManager(onEverythingLoaded);
  26. const loader = new THREE.TextureLoader(loadingManager);
  27.  
  28. const earthGeomerty = new THREE.SphereGeometry( 5.5, 32, 32 );
  29. const earthDiffuse = loader.load('assets/drought_earth_texture.png');
  30. const earthSpec = loader.load('assets/drought_earth_texture_bump.png');
  31.  
  32. const material = new THREE.MeshPhongMaterial( {
  33. specular: 0xffffff,
  34. map: earthDiffuse,
  35. specularMap: earthSpec,
  36. normalScale: new THREE.Vector2( 1, 1 ),
  37. shininess: 30,
  38. transparent: true,
  39. depthTest: true,
  40. depthWrite: false,
  41. polygonOffset: true,
  42. polygonOffsetFactor: - 4,
  43. wireframe: false
  44. } );
  45.  
  46. const sphere = new THREE.Mesh( earthGeomerty, material );
  47. const ambientLight = new THREE.AmbientLight( 0x667777 );
  48.  
  49. const directionalLight = new THREE.DirectionalLight( 0xffffdd, 2 );
  50. directionalLight.position.set( 4, 0, 0 );
  51. scene.add( sphere );
  52. scene.add( ambientLight );
  53. scene.add( directionalLight );
  54.  
  55. const render = () => {
  56. animationFrame = requestAnimationFrame( render );
  57. sphere.rotation.y += 0.001;
  58. renderer.render( scene, camera );
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement