2
0

misc_animation_authoring.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - animation authoring</title>
  5. <meta charset="utf-8">
  6. <style>
  7. body {
  8. margin: 0px;
  9. background-color: #000000;
  10. color: #fff;
  11. font-family:Monospace;
  12. font-size: 15px;
  13. line-height: 30px;
  14. overflow: hidden;
  15. }
  16. #info {
  17. text-align: center;
  18. position: absolute;
  19. top: 0px; width: 100%;
  20. padding: 15px;
  21. z-index:100;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="info">
  27. "W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size<br />
  28. Press "Q" to toggle world/local space, hold down "Ctrl" to snap to grid
  29. </div>
  30. <script src="../build/three.js"></script>
  31. <script src="js/controls/TransformControls.js"></script>
  32. <script src="js/libs/timeliner_gui.min.js"></script>
  33. <script src="js/TimelinerController.js"></script>
  34. <script>
  35. var camera, scene, renderer, control;
  36. init();
  37. render();
  38. function init() {
  39. renderer = new THREE.WebGLRenderer();
  40. renderer.setPixelRatio( window.devicePixelRatio );
  41. renderer.setSize( window.innerWidth, window.innerHeight );
  42. renderer.sortObjects = false;
  43. document.body.appendChild( renderer.domElement );
  44. //
  45. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 3000 );
  46. camera.position.set( 1000, 500, 1000 );
  47. camera.lookAt( new THREE.Vector3( 0, 200, 0 ) );
  48. scene = new THREE.Scene();
  49. scene.add( new THREE.GridHelper( 500, 100 ) );
  50. var light = new THREE.DirectionalLight( 0xffffff, 2 );
  51. light.position.set( 1, 1, 1 );
  52. scene.add( light );
  53. var texture = THREE.ImageUtils.loadTexture( 'textures/crate.gif', THREE.UVMapping, render );
  54. texture.anisotropy = renderer.getMaxAnisotropy();
  55. var geometry = new THREE.BoxGeometry( 200, 200, 200 );
  56. var material = new THREE.MeshLambertMaterial( { map: texture } );
  57. control = new THREE.TransformControls( camera, renderer.domElement );
  58. control.addEventListener( 'change', render );
  59. var mesh = new THREE.Mesh( geometry, material );
  60. mesh.name = "MyBox";
  61. scene.add( mesh );
  62. control.attach( mesh );
  63. scene.add( control );
  64. window.addEventListener( 'resize', onWindowResize, false );
  65. window.addEventListener( 'keydown', function ( event ) {
  66. switch ( event.keyCode ) {
  67. case 81: // Q
  68. control.setSpace( control.space === "local" ? "world" : "local" );
  69. break;
  70. case 17: // Ctrl
  71. control.setTranslationSnap( 100 );
  72. control.setRotationSnap( THREE.Math.degToRad( 15 ) );
  73. break;
  74. case 87: // W
  75. control.setMode( "translate" );
  76. break;
  77. case 69: // E
  78. control.setMode( "rotate" );
  79. break;
  80. case 82: // R
  81. control.setMode( "scale" );
  82. break;
  83. case 187:
  84. case 107: // +, =, num+
  85. control.setSize( control.size + 0.1 );
  86. break;
  87. case 189:
  88. case 109: // -, _, num-
  89. control.setSize( Math.max( control.size - 0.1, 0.1 ) );
  90. break;
  91. }
  92. });
  93. window.addEventListener( 'keyup', function ( event ) {
  94. switch ( event.keyCode ) {
  95. case 17: // Ctrl
  96. control.setTranslationSnap( null );
  97. control.setRotationSnap( null );
  98. break;
  99. }
  100. });
  101. var trackInfo = [
  102. {
  103. type: THREE.VectorKeyframeTrack,
  104. propertyPath: 'MyBox.position',
  105. initialValue: [ 0, 0, 0 ],
  106. interpolation: THREE.InterpolateSmooth
  107. },
  108. {
  109. type: THREE.QuaternionKeyframeTrack,
  110. propertyPath: 'MyBox.quaternion',
  111. initialValue: [ 0, 0, 0, 1 ],
  112. interpolation: THREE.InterpolateLinear
  113. }
  114. ];
  115. new Timeliner(
  116. new THREE.TimelinerController( scene, trackInfo, render ) );
  117. }
  118. function onWindowResize() {
  119. camera.aspect = window.innerWidth / window.innerHeight;
  120. camera.updateProjectionMatrix();
  121. renderer.setSize( window.innerWidth, window.innerHeight );
  122. render();
  123. }
  124. function render() {
  125. control.update();
  126. renderer.render( scene, camera );
  127. }
  128. </script>
  129. </body>
  130. </html>