webgl_animation_keyframes_json.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - animation - keyframes - json</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: #fff;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. background-color: #fff;
  14. margin: 0px;
  15. overflow: hidden;
  16. }
  17. #info {
  18. position: absolute;
  19. top: 0px; width: 100%;
  20. padding: 5px;
  21. }
  22. a {
  23. color: #2983ff;
  24. }
  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> webgl - animation - keyframes
  31. </div>
  32. <script src="../build/three.js"></script>
  33. <script src="js/Detector.js"></script>
  34. <script src="js/libs/stats.min.js"></script>
  35. <script>
  36. var scene, camera, pointLight, stats;
  37. var renderer, mixer, animationClip;
  38. var clock = new THREE.Clock();
  39. var container = document.getElementById( 'container' );
  40. stats = new Stats();
  41. container.appendChild( stats.dom );
  42. renderer = new THREE.WebGLRenderer( { antialias: true } );
  43. renderer.setClearColor( 0x000000 );
  44. renderer.setPixelRatio( window.devicePixelRatio );
  45. renderer.setSize( window.innerWidth, window.innerHeight );
  46. container.appendChild( renderer.domElement );
  47. scene = new THREE.Scene();
  48. scene.add( new THREE.GridHelper( 20, 20 ) );
  49. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.01, 1000 );
  50. camera.position.set( - 5.00, 3.43, 11.31 );
  51. camera.lookAt( new THREE.Vector3( - 1.22, 2.18, 4.58 ) );
  52. pointLight = new THREE.PointLight( 0xffffff, 1.75 );
  53. pointLight.position.copy( camera.position );
  54. scene.add( pointLight );
  55. new THREE.ObjectLoader().load( 'models/json/pump/pump.json', function ( model ) {
  56. scene.add( model );
  57. mixer = new THREE.AnimationMixer( model );
  58. mixer.clipAction( model.animations[ 0 ] ).play();
  59. animate();
  60. } );
  61. window.onresize = function () {
  62. camera.aspect = window.innerWidth / window.innerHeight;
  63. camera.updateProjectionMatrix();
  64. renderer.setSize( window.innerWidth, window.innerHeight );
  65. };
  66. function animate() {
  67. requestAnimationFrame( animate );
  68. mixer.update( clock.getDelta() );
  69. stats.update();
  70. renderer.render( scene, camera );
  71. }
  72. </script>
  73. </body>
  74. </html>