misc_controls_trackball_orthographic.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - orthographic trackball 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. <link type="text/css" rel="stylesheet" href="main.css">
  8. <style>
  9. body {
  10. background-color: #ccc;
  11. color: #000;
  12. }
  13. a {
  14. color: #f00;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div id="info">
  20. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - orthographic trackball controls<br />
  21. MOVE mouse &amp; press LEFT: rotate, MIDDLE: zoom, RIGHT: pan
  22. </div>
  23. <script type="module">
  24. import * as THREE from '../build/three.module.js';
  25. import Stats from './jsm/libs/stats.module.js';
  26. import { OrthographicTrackballControls } from './jsm/controls/OrthographicTrackballControls.js';
  27. var camera, controls, scene, renderer, stats;
  28. init();
  29. animate();
  30. function init() {
  31. camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 2000 );
  32. camera.position.z = 1000;
  33. // world
  34. scene = new THREE.Scene();
  35. scene.background = new THREE.Color( 0xcccccc );
  36. scene.fog = new THREE.FogExp2( 0xcccccc, 0.001 );
  37. var geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
  38. var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
  39. for ( var i = 0; i < 500; i ++ ) {
  40. var mesh = new THREE.Mesh( geometry, material );
  41. mesh.position.x = ( Math.random() - 0.5 ) * 1000;
  42. mesh.position.y = ( Math.random() - 0.5 ) * 1000;
  43. mesh.position.z = ( Math.random() - 0.5 ) * 1000;
  44. mesh.updateMatrix();
  45. mesh.matrixAutoUpdate = false;
  46. scene.add( mesh );
  47. }
  48. // lights
  49. var light = new THREE.DirectionalLight( 0xffffff );
  50. light.position.set( 1, 1, 1 );
  51. scene.add( light );
  52. var light = new THREE.DirectionalLight( 0x002288 );
  53. light.position.set( - 1, - 1, - 1 );
  54. scene.add( light );
  55. var light = new THREE.AmbientLight( 0x222222 );
  56. scene.add( light );
  57. // renderer
  58. renderer = new THREE.WebGLRenderer( { antialias: true } );
  59. renderer.setPixelRatio( window.devicePixelRatio );
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. document.body.appendChild( renderer.domElement );
  62. controls = new OrthographicTrackballControls( camera, renderer.domElement );
  63. controls.rotateSpeed = 1.0;
  64. controls.zoomSpeed = 1.2;
  65. controls.noZoom = false;
  66. controls.noPan = false;
  67. controls.staticMoving = true;
  68. controls.dynamicDampingFactor = 0.3;
  69. controls.keys = [ 65, 83, 68 ];
  70. controls.addEventListener( 'change', render );
  71. stats = new Stats();
  72. document.body.appendChild( stats.dom );
  73. //
  74. window.addEventListener( 'resize', onWindowResize, false );
  75. //
  76. render();
  77. }
  78. function onWindowResize() {
  79. camera.left = window.innerWidth / - 2;
  80. camera.right = window.innerWidth / 2;
  81. camera.top = window.innerHeight / 2;
  82. camera.bottom = window.innerHeight / - 2;
  83. camera.updateProjectionMatrix();
  84. renderer.setSize( window.innerWidth, window.innerHeight );
  85. controls.handleResize();
  86. render();
  87. }
  88. function animate() {
  89. requestAnimationFrame( animate );
  90. controls.update();
  91. stats.update();
  92. }
  93. function render() {
  94. renderer.render( scene, camera );
  95. }
  96. </script>
  97. </body>
  98. </html>