canvas_morphtargets_horse.html 3.3 KB

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