misc_controls_map.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - map 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. box-sizing: border-box;
  24. }
  25. a {
  26. color: red;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - map controls example
  33. </div>
  34. <script src="../build/three.js"></script>
  35. <script src="js/controls/MapControls.js"></script>
  36. <script src="js/WebGL.js"></script>
  37. <script src='js/libs/dat.gui.min.js'></script>
  38. <script>
  39. if ( WEBGL.isWebGLAvailable() === false ) {
  40. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  41. }
  42. var camera, controls, scene, renderer;
  43. init();
  44. //render(); // remove when using next line for animation loop (requestAnimationFrame)
  45. animate();
  46. function init() {
  47. scene = new THREE.Scene();
  48. scene.background = new THREE.Color( 0xcccccc );
  49. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  50. renderer = new THREE.WebGLRenderer( { antialias: true } );
  51. renderer.setPixelRatio( window.devicePixelRatio );
  52. renderer.setSize( window.innerWidth, window.innerHeight );
  53. document.body.appendChild( renderer.domElement );
  54. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  55. camera.position.set( 400, 200, 0 );
  56. // controls
  57. controls = new THREE.MapControls( camera, renderer.domElement );
  58. //controls.addEventListener( 'change', render ); // call this only in static scenes (i.e., if there is no animation loop)
  59. controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
  60. controls.dampingFactor = 0.25;
  61. controls.screenSpacePanning = false;
  62. controls.minDistance = 100;
  63. controls.maxDistance = 500;
  64. controls.maxPolarAngle = Math.PI / 2;
  65. // world
  66. var geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
  67. geometry.translate( 0, 0.5, 0 );
  68. var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
  69. for ( var i = 0; i < 500; i ++ ) {
  70. var mesh = new THREE.Mesh( geometry, material );
  71. mesh.position.x = Math.random() * 1600 - 800;
  72. mesh.position.y = 0;
  73. mesh.position.z = Math.random() * 1600 - 800;
  74. mesh.scale.x = 20;
  75. mesh.scale.y = Math.random() * 80 + 10;
  76. mesh.scale.z = 20;
  77. mesh.updateMatrix();
  78. mesh.matrixAutoUpdate = false;
  79. scene.add( mesh );
  80. }
  81. // lights
  82. var light = new THREE.DirectionalLight( 0xffffff );
  83. light.position.set( 1, 1, 1 );
  84. scene.add( light );
  85. var light = new THREE.DirectionalLight( 0x002288 );
  86. light.position.set( - 1, - 1, - 1 );
  87. scene.add( light );
  88. var light = new THREE.AmbientLight( 0x222222 );
  89. scene.add( light );
  90. //
  91. window.addEventListener( 'resize', onWindowResize, false );
  92. var gui = new dat.GUI();
  93. gui.add( controls, 'screenSpacePanning' );
  94. }
  95. function onWindowResize() {
  96. camera.aspect = window.innerWidth / window.innerHeight;
  97. camera.updateProjectionMatrix();
  98. renderer.setSize( window.innerWidth, window.innerHeight );
  99. }
  100. function animate() {
  101. requestAnimationFrame( animate );
  102. controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true
  103. render();
  104. }
  105. function render() {
  106. renderer.render( scene, camera );
  107. }
  108. </script>
  109. </body>
  110. </html>