webgl_loader_collada_skinning.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - collada - skinning</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. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="container"></div>
  11. <div id="info">
  12. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> collada loader - skinning<br/>
  13. Dancing Stormtrooper by <a href="https://sketchfab.com/strykerdoesgames" target="_blank" rel="noopener">StrykerDoesAnimation</a>, <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC Attribution</a>
  14. </div>
  15. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import Stats from './jsm/libs/stats.module.js';
  18. import { ColladaLoader } from './jsm/loaders/ColladaLoader.js';
  19. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  20. var container, stats, clock, controls;
  21. var camera, scene, renderer, mixer;
  22. init();
  23. animate();
  24. function init() {
  25. container = document.getElementById( 'container' );
  26. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 1000 );
  27. camera.position.set( 15, 10, - 15 );
  28. scene = new THREE.Scene();
  29. clock = new THREE.Clock();
  30. // collada
  31. var loader = new ColladaLoader();
  32. loader.load( './models/collada/stormtrooper/stormtrooper.dae', function ( collada ) {
  33. var animations = collada.animations;
  34. var avatar = collada.scene;
  35. avatar.traverse( function ( node ) {
  36. if ( node.isSkinnedMesh ) {
  37. node.frustumCulled = false;
  38. }
  39. } );
  40. mixer = new THREE.AnimationMixer( avatar );
  41. mixer.clipAction( animations[ 0 ] ).play();
  42. scene.add( avatar );
  43. } );
  44. //
  45. var gridHelper = new THREE.GridHelper( 10, 20 );
  46. scene.add( gridHelper );
  47. //
  48. var ambientLight = new THREE.AmbientLight( 0xffffff, 0.2 );
  49. scene.add( ambientLight );
  50. var pointLight = new THREE.PointLight( 0xffffff, 0.8 );
  51. scene.add( camera );
  52. camera.add( pointLight );
  53. //
  54. renderer = new THREE.WebGLRenderer( { antialias: true } );
  55. renderer.setPixelRatio( window.devicePixelRatio );
  56. renderer.setSize( window.innerWidth, window.innerHeight );
  57. container.appendChild( renderer.domElement );
  58. //
  59. controls = new OrbitControls( camera, renderer.domElement );
  60. controls.screenSpacePanning = true;
  61. controls.minDistance = 5;
  62. controls.maxDistance = 40;
  63. controls.target.set( 0, 2, 0 );
  64. controls.update();
  65. //
  66. stats = new Stats();
  67. container.appendChild( stats.dom );
  68. //
  69. window.addEventListener( 'resize', onWindowResize, false );
  70. }
  71. function onWindowResize() {
  72. camera.aspect = window.innerWidth / window.innerHeight;
  73. camera.updateProjectionMatrix();
  74. renderer.setSize( window.innerWidth, window.innerHeight );
  75. }
  76. function animate() {
  77. requestAnimationFrame( animate );
  78. render();
  79. stats.update();
  80. }
  81. function render() {
  82. var delta = clock.getDelta();
  83. if ( mixer !== undefined ) {
  84. mixer.update( delta );
  85. }
  86. renderer.render( scene, camera );
  87. }
  88. </script>
  89. </body>
  90. </html>