misc_controls_orbit.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - orbit controls</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. color: #000;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. font-weight: bold;
  14. background-color: #fff;
  15. margin: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. color:#000;
  20. position: absolute;
  21. top: 0px; width: 100%;
  22. padding: 5px;
  23. }
  24. a {
  25. color: red;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="info">
  31. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - orbit controls example
  32. </div>
  33. <script src="../build/three.js"></script>
  34. <script src="js/controls/OrbitControls.js"></script>
  35. <script src="js/Detector.js"></script>
  36. <script>
  37. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  38. var camera, controls, scene, renderer;
  39. init();
  40. //render(); // remove when using next line for animation loop (requestAnimationFrame)
  41. animate();
  42. function init() {
  43. scene = new THREE.Scene();
  44. scene.background = new THREE.Color( 0xcccccc );
  45. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  46. renderer = new THREE.WebGLRenderer( { antialias: true } );
  47. renderer.setPixelRatio( window.devicePixelRatio );
  48. renderer.setSize( window.innerWidth, window.innerHeight );
  49. document.body.appendChild( renderer.domElement );
  50. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  51. camera.position.set( 400, 200, 0 );
  52. // controls
  53. controls = new THREE.OrbitControls( camera, renderer.domElement );
  54. //controls.addEventListener( 'change', render ); // call this only in static scenes (i.e., if there is no animation loop)
  55. controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
  56. controls.dampingFactor = 0.25;
  57. controls.screenSpacePanning = false;
  58. controls.minDistance = 100;
  59. controls.maxDistance = 500
  60. controls.maxPolarAngle = Math.PI / 2;
  61. // world
  62. var geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
  63. var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
  64. for ( var i = 0; i < 500; i ++ ) {
  65. var mesh = new THREE.Mesh( geometry, material );
  66. mesh.position.x = Math.random() * 1600 - 800;
  67. mesh.position.y = 0;
  68. mesh.position.z = Math.random() * 1600 - 800;
  69. mesh.updateMatrix();
  70. mesh.matrixAutoUpdate = false;
  71. scene.add( mesh );
  72. }
  73. // lights
  74. var light = new THREE.DirectionalLight( 0xffffff );
  75. light.position.set( 1, 1, 1 );
  76. scene.add( light );
  77. var light = new THREE.DirectionalLight( 0x002288 );
  78. light.position.set( - 1, - 1, - 1 );
  79. scene.add( light );
  80. var light = new THREE.AmbientLight( 0x222222 );
  81. scene.add( light );
  82. //
  83. window.addEventListener( 'resize', onWindowResize, false );
  84. }
  85. function onWindowResize() {
  86. camera.aspect = window.innerWidth / window.innerHeight;
  87. camera.updateProjectionMatrix();
  88. renderer.setSize( window.innerWidth, window.innerHeight );
  89. }
  90. function animate() {
  91. requestAnimationFrame( animate );
  92. controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true
  93. render();
  94. }
  95. function render() {
  96. renderer.render( scene, camera );
  97. }
  98. </script>
  99. </body>
  100. </html>