2
0

misc_controls_orbit.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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">three.js</a> - orbit controls example
  33. </div>
  34. <script src="../build/three.min.js"></script>
  35. <script src="js/controls/OrbitControls.js"></script>
  36. <script src="js/Detector.js"></script>
  37. <script src="js/libs/stats.min.js"></script>
  38. <script>
  39. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  40. var container, stats;
  41. var camera, controls, scene, renderer;
  42. init();
  43. render();
  44. function init() {
  45. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  46. camera.position.z = 500;
  47. controls = new THREE.OrbitControls( camera );
  48. controls.addEventListener( 'change', render );
  49. scene = new THREE.Scene();
  50. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  51. // world
  52. var geometry = new THREE.CylinderGeometry( 0, 10, 30, 4, 1 );
  53. var material = new THREE.MeshLambertMaterial( { color:0xffffff, shading: THREE.FlatShading } );
  54. for ( var i = 0; i < 500; i ++ ) {
  55. var mesh = new THREE.Mesh( geometry, material );
  56. mesh.position.x = ( Math.random() - 0.5 ) * 1000;
  57. mesh.position.y = ( Math.random() - 0.5 ) * 1000;
  58. mesh.position.z = ( Math.random() - 0.5 ) * 1000;
  59. mesh.updateMatrix();
  60. mesh.matrixAutoUpdate = false;
  61. scene.add( mesh );
  62. }
  63. // lights
  64. light = new THREE.DirectionalLight( 0xffffff );
  65. light.position.set( 1, 1, 1 );
  66. scene.add( light );
  67. light = new THREE.DirectionalLight( 0x002288 );
  68. light.position.set( -1, -1, -1 );
  69. scene.add( light );
  70. light = new THREE.AmbientLight( 0x222222 );
  71. scene.add( light );
  72. // renderer
  73. renderer = new THREE.WebGLRenderer( { antialias: false } );
  74. renderer.setClearColor( scene.fog.color, 1 );
  75. renderer.setSize( window.innerWidth, window.innerHeight );
  76. container = document.getElementById( 'container' );
  77. container.appendChild( renderer.domElement );
  78. stats = new Stats();
  79. stats.domElement.style.position = 'absolute';
  80. stats.domElement.style.top = '0px';
  81. stats.domElement.style.zIndex = 100;
  82. container.appendChild( stats.domElement );
  83. //
  84. window.addEventListener( 'resize', onWindowResize, false );
  85. }
  86. function onWindowResize() {
  87. camera.aspect = window.innerWidth / window.innerHeight;
  88. camera.updateProjectionMatrix();
  89. renderer.setSize( window.innerWidth, window.innerHeight );
  90. render();
  91. }
  92. function render() {
  93. renderer.render( scene, camera );
  94. stats.update();
  95. }
  96. </script>
  97. </body>
  98. </html>