misc_camera_path.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - path camera</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://github.com/mrdoob/three.js" target="_blank">three.js</a> - path camera example</br>
  31. mouse look around
  32. </div>
  33. <script src="../build/Three.js"></script>
  34. <script src="js/Stats.js"></script>
  35. <script src="js/Tween.js"></script>
  36. <script>
  37. var statsEnabled = true;
  38. var container, stats;
  39. var camera, scene, renderer;
  40. var cross;
  41. init();
  42. function init() {
  43. // scene and camera
  44. scene = new THREE.Scene();
  45. scene.fog = new THREE.FogExp2( 0xffffff, 0.002 );
  46. var waypoints = [
  47. [ -500, 0, 0 ],
  48. [ 0, 200, 0 ],
  49. [ 500, 0, 0 ]
  50. ];
  51. camera = new THREE.PathCamera( {
  52. fov: 40, aspect: window.innerWidth / window.innerHeight, near: 1, far: 1000,
  53. waypoints: waypoints, duration: 28,
  54. useConstantSpeed: true, resamplingCoef: 1,
  55. createDebugPath: true, createDebugDummy: true,
  56. lookSpeed: 0.0006, lookVertical: true, lookHorizontal: true,
  57. verticalAngleMap: { srcRange: [ 0.00, 6.28 ], dstRange: [ 1.1, 3.8 ] },
  58. horizontalAngleMap: { srcRange: [ 0.00, 6.28 ], dstRange: [ 0.3, Math.PI - 0.3 ] }
  59. } );
  60. camera.lon = 180;
  61. // world
  62. var cube = new THREE.CubeGeometry( 20, 60, 20 );
  63. cube.vertices[ 0 ].position.multiplyScalar( 0.01 );
  64. cube.vertices[ 1 ].position.multiplyScalar( 0.01 );
  65. cube.vertices[ 4 ].position.multiplyScalar( 0.01 );
  66. cube.vertices[ 5 ].position.multiplyScalar( 0.01 );
  67. var material = new THREE.MeshLambertMaterial( { color:0xffffff } );
  68. for( var i = 0; i < 500; i++ ) {
  69. var mesh = new THREE.Mesh( cube, material );
  70. mesh.position.set(( Math.random() - 0.5 ) * 1000,
  71. ( Math.random() - 0.5 ) * 1000,
  72. ( Math.random() - 0.5 ) * 1000 );
  73. mesh.updateMatrix();
  74. mesh.matrixAutoUpdate = false;
  75. scene.add( mesh );
  76. }
  77. scene.add( camera.animationParent );
  78. // lights
  79. light = new THREE.DirectionalLight( 0xffffff );
  80. light.position.set( 1, 1, 1 );
  81. scene.add( light );
  82. light = new THREE.DirectionalLight( 0x002288 );
  83. light.position.set( -1, -1, -1 );
  84. scene.add( light );
  85. light = new THREE.AmbientLight( 0x222222 );
  86. scene.add( light );
  87. // renderer
  88. renderer = new THREE.WebGLRenderer( { antialias: false } );
  89. renderer.setClearColorHex( 0xffffff, 1 );
  90. renderer.setSize( window.innerWidth, window.innerHeight );
  91. container = document.getElementById( 'container' );
  92. container.appendChild( renderer.domElement );
  93. if ( statsEnabled ) {
  94. stats = new Stats();
  95. stats.domElement.style.position = 'absolute';
  96. stats.domElement.style.top = '0px';
  97. stats.domElement.style.zIndex = 100;
  98. container.appendChild( stats.domElement );
  99. }
  100. setInterval( loop, 1000 / 60 );
  101. camera.animation.play( true, 0 );
  102. }
  103. function loop() {
  104. THREE.AnimationHandler.update( 1000/60 );
  105. /*
  106. cross.matrix.copy( camera.matrix );
  107. cross.matrix.n14 = 0;
  108. cross.matrix.n24 = 0;
  109. cross.matrix.n34 = -200;
  110. cross.matrixWorldNeedsUpdate = true;
  111. */
  112. renderer.render( scene, camera );
  113. if ( statsEnabled ) stats.update();
  114. }
  115. </script>
  116. </body>
  117. </html>