misc_controls_path.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - path 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 { color: red; }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info">
  30. <a href="http://threejs.org" target="_blank">three.js</a> - path controls example</br>
  31. mouse look around
  32. </div>
  33. <script src="../build/three.min.js"></script>
  34. <script src="js/controls/PathControls.js"></script>
  35. <script src="js/Detector.js"></script>
  36. <script src="js/libs/stats.min.js"></script>
  37. <script>
  38. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  39. var container, stats;
  40. var camera, controls, scene, renderer;
  41. var cross;
  42. var clock = new THREE.Clock();
  43. init();
  44. animate();
  45. function init() {
  46. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
  47. controls = new THREE.PathControls( camera );
  48. controls.waypoints = [ [ -500, 0, 0 ], [ 0, 200, 0 ], [ 500, 0, 0 ] ];
  49. controls.duration = 28
  50. controls.useConstantSpeed = true;
  51. //controls.createDebugPath = true;
  52. //controls.createDebugDummy = true;
  53. controls.lookSpeed = 0.06;
  54. controls.lookVertical = true;
  55. controls.lookHorizontal = true;
  56. controls.verticalAngleMap = { srcRange: [ 0, 2 * Math.PI ], dstRange: [ 1.1, 3.8 ] };
  57. controls.horizontalAngleMap = { srcRange: [ 0, 2 * Math.PI ], dstRange: [ 0.3, Math.PI - 0.3 ] };
  58. controls.lon = 180;
  59. controls.init();
  60. // world
  61. scene = new THREE.Scene();
  62. scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
  63. scene.add( controls.animationParent );
  64. var geometry = new THREE.CylinderGeometry( 0, 10, 30, 4, 1 );
  65. var material = new THREE.MeshLambertMaterial( { color:0xffffff, shading: THREE.FlatShading } );
  66. for ( var i = 0; i < 500; i ++ ) {
  67. var mesh = new THREE.Mesh( geometry, material );
  68. mesh.position.x = ( Math.random() - 0.5 ) * 1000;
  69. mesh.position.y = ( Math.random() - 0.5 ) * 1000;
  70. mesh.position.z = ( Math.random() - 0.5 ) * 1000;
  71. mesh.updateMatrix();
  72. mesh.matrixAutoUpdate = false;
  73. scene.add( mesh );
  74. }
  75. // lights
  76. light = new THREE.DirectionalLight( 0xffffff );
  77. light.position.set( 1, 1, 1 );
  78. scene.add( light );
  79. light = new THREE.DirectionalLight( 0x002288 );
  80. light.position.set( -1, -1, -1 );
  81. scene.add( light );
  82. light = new THREE.AmbientLight( 0x222222 );
  83. scene.add( light );
  84. // renderer
  85. renderer = new THREE.WebGLRenderer( { antialias: false } );
  86. renderer.setClearColor( scene.fog.color, 1 );
  87. renderer.setSize( window.innerWidth, window.innerHeight );
  88. container = document.getElementById( 'container' );
  89. container.appendChild( renderer.domElement );
  90. // stats
  91. stats = new Stats();
  92. stats.domElement.style.position = 'absolute';
  93. stats.domElement.style.top = '0px';
  94. stats.domElement.style.zIndex = 100;
  95. container.appendChild( stats.domElement );
  96. //
  97. window.addEventListener( 'resize', onWindowResize, false );
  98. // start animation
  99. controls.animation.play( true, 0 );
  100. }
  101. function onWindowResize() {
  102. camera.aspect = window.innerWidth / window.innerHeight;
  103. camera.updateProjectionMatrix();
  104. renderer.setSize( window.innerWidth, window.innerHeight );
  105. controls.handleResize();
  106. }
  107. function animate() {
  108. requestAnimationFrame( animate );
  109. render();
  110. stats.update();
  111. }
  112. function render() {
  113. var delta = clock.getDelta();
  114. THREE.AnimationHandler.update( delta );
  115. controls.update( delta );
  116. renderer.render( scene, camera );
  117. }
  118. </script>
  119. </body>
  120. </html>