webgl_animation_keyframes_json.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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" rel="noopener">three.js</a> webgl - animation - keyframes - json
  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.setPixelRatio( window.devicePixelRatio );
  44. renderer.setSize( window.innerWidth, window.innerHeight );
  45. container.appendChild( renderer.domElement );
  46. scene = new THREE.Scene();
  47. var grid = new THREE.GridHelper( 20, 20, 0x888888, 0x888888 );
  48. grid.position.set( 0, - 1.1, 0 );
  49. scene.add( grid );
  50. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
  51. camera.position.set( - 5.00, 3.43, 11.31 );
  52. camera.lookAt( new THREE.Vector3( - 1.22, 2.18, 4.58 ) );
  53. scene.add( new THREE.AmbientLight( 0x404040 ) );
  54. pointLight = new THREE.PointLight( 0xffffff, 1 );
  55. pointLight.position.copy( camera.position );
  56. scene.add( pointLight );
  57. new THREE.ObjectLoader().load( 'models/json/pump/pump.json', function ( model ) {
  58. scene.add( model );
  59. mixer = new THREE.AnimationMixer( model );
  60. mixer.clipAction( model.animations[ 0 ] ).play();
  61. animate();
  62. } );
  63. window.onresize = function () {
  64. camera.aspect = window.innerWidth / window.innerHeight;
  65. camera.updateProjectionMatrix();
  66. renderer.setSize( window.innerWidth, window.innerHeight );
  67. };
  68. function animate() {
  69. requestAnimationFrame( animate );
  70. mixer.update( clock.getDelta() );
  71. stats.update();
  72. renderer.render( scene, camera );
  73. }
  74. </script>
  75. </body>
  76. </html>