misc_controls_orbit.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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="container"></div>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - orbit controls example
  33. </div>
  34. <script src="../build/three.js"></script>
  35. <script src="js/controls/OrbitControls.js"></script>
  36. <script src="js/Detector.js"></script>
  37. <script>
  38. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  39. var camera, controls, scene, renderer;
  40. init();
  41. render(); // remove when using next line for animation loop (requestAnimationFrame)
  42. //animate();
  43. function init() {
  44. scene = new THREE.Scene();
  45. scene.background = new THREE.Color( 0xcccccc );
  46. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  47. renderer = new THREE.WebGLRenderer();
  48. renderer.setPixelRatio( window.devicePixelRatio );
  49. renderer.setSize( window.innerWidth, window.innerHeight );
  50. var container = document.getElementById( 'container' );
  51. container.appendChild( renderer.domElement );
  52. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  53. camera.position.z = 500;
  54. controls = new THREE.OrbitControls( camera, renderer.domElement );
  55. controls.addEventListener( 'change', render ); // remove when using animation loop
  56. // enable animation loop when using damping or autorotation
  57. //controls.enableDamping = true;
  58. //controls.dampingFactor = 0.25;
  59. controls.enableZoom = false;
  60. // world
  61. var geometry = new THREE.CylinderGeometry( 0, 10, 30, 4, 1 );
  62. var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
  63. for ( var i = 0; i < 500; i ++ ) {
  64. var mesh = new THREE.Mesh( geometry, material );
  65. mesh.position.x = ( Math.random() - 0.5 ) * 1000;
  66. mesh.position.y = ( Math.random() - 0.5 ) * 1000;
  67. mesh.position.z = ( Math.random() - 0.5 ) * 1000;
  68. mesh.updateMatrix();
  69. mesh.matrixAutoUpdate = false;
  70. scene.add( mesh );
  71. }
  72. // lights
  73. var light = new THREE.DirectionalLight( 0xffffff );
  74. light.position.set( 1, 1, 1 );
  75. scene.add( light );
  76. var light = new THREE.DirectionalLight( 0x002288 );
  77. light.position.set( -1, -1, -1 );
  78. scene.add( light );
  79. var light = new THREE.AmbientLight( 0x222222 );
  80. scene.add( light );
  81. //
  82. window.addEventListener( 'resize', onWindowResize, false );
  83. }
  84. function onWindowResize() {
  85. camera.aspect = window.innerWidth / window.innerHeight;
  86. camera.updateProjectionMatrix();
  87. renderer.setSize( window.innerWidth, window.innerHeight );
  88. }
  89. function animate() {
  90. requestAnimationFrame( animate );
  91. controls.update(); // required if controls.enableDamping = true, or if controls.autoRotate = true
  92. render();
  93. }
  94. function render() {
  95. renderer.render( scene, camera );
  96. }
  97. </script>
  98. </body>
  99. </html>