webgl_morphtargets_horse.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - morph targets - horse</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. font-family: Monospace;
  10. background-color: #f0f0f0;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script src="../build/three.min.js"></script>
  18. <script src="js/libs/stats.min.js"></script>
  19. <script>
  20. var container, stats;
  21. var camera, scene, projector, renderer;
  22. var mesh, animation;
  23. init();
  24. animate();
  25. function init() {
  26. container = document.createElement( 'div' );
  27. document.body.appendChild( container );
  28. var info = document.createElement( 'div' );
  29. info.style.position = 'absolute';
  30. info.style.top = '10px';
  31. info.style.width = '100%';
  32. info.style.textAlign = 'center';
  33. info.innerHTML = '<a href="http://threejs.org" target="_blank">three.js</a> webgl - morph targets - horse. model by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a>';
  34. container.appendChild( info );
  35. //
  36. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
  37. camera.position.y = 300;
  38. camera.target = new THREE.Vector3( 0, 150, 0 );
  39. scene = new THREE.Scene();
  40. //
  41. var light = new THREE.DirectionalLight( 0xefefff, 2 );
  42. light.position.set( 1, 1, 1 ).normalize();
  43. scene.add( light );
  44. var light = new THREE.DirectionalLight( 0xffefef, 2 );
  45. light.position.set( -1, -1, -1 ).normalize();
  46. scene.add( light );
  47. var loader = new THREE.JSONLoader( true );
  48. loader.load( "models/animated/horse.js", function( geometry ) {
  49. mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x606060, morphTargets: true } ) );
  50. mesh.scale.set( 1.5, 1.5, 1.5 );
  51. scene.add( mesh );
  52. animation = new THREE.MorphAnimation( mesh );
  53. animation.play();
  54. } );
  55. //
  56. renderer = new THREE.WebGLRenderer();
  57. renderer.setClearColor( 0xf0f0f0 );
  58. renderer.setSize( window.innerWidth, window.innerHeight );
  59. container.appendChild(renderer.domElement);
  60. //
  61. stats = new Stats();
  62. stats.domElement.style.position = 'absolute';
  63. stats.domElement.style.top = '0px';
  64. container.appendChild( stats.domElement );
  65. //
  66. window.addEventListener( 'resize', onWindowResize, false );
  67. }
  68. function onWindowResize() {
  69. camera.aspect = window.innerWidth / window.innerHeight;
  70. camera.updateProjectionMatrix();
  71. renderer.setSize( window.innerWidth, window.innerHeight );
  72. }
  73. //
  74. function animate() {
  75. requestAnimationFrame( animate );
  76. render();
  77. stats.update();
  78. }
  79. var radius = 600;
  80. var theta = 0;
  81. var prevTime = Date.now();
  82. function render() {
  83. theta += 0.1;
  84. camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
  85. camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
  86. camera.lookAt( camera.target );
  87. if ( animation ) {
  88. var time = Date.now();
  89. animation.update( time - prevTime );
  90. prevTime = time;
  91. }
  92. renderer.render( scene, camera );
  93. }
  94. </script>
  95. </body>
  96. </html>