webgl_tsl_skinning.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - 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="example.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  12. <div class="title-wrapper">
  13. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>Skinning</span>
  14. </div>
  15. <small>
  16. Basic skinning example using a model from Mixamo.
  17. </small>
  18. </div>
  19. <script type="importmap">
  20. {
  21. "imports": {
  22. "three": "../build/three.module.js",
  23. "three/webgpu": "../build/three.webgpu.js",
  24. "three/tsl": "../build/three.tsl.js",
  25. "three/addons/": "./jsm/"
  26. }
  27. }
  28. </script>
  29. <script type="module">
  30. import * as THREE from 'three/webgpu';
  31. import { WebGLNodesHandler } from 'three/addons/tsl/WebGLNodesHandler.js';
  32. import { WebGLRenderer } from 'three';
  33. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  34. let camera, scene, renderer;
  35. let mixer, timer;
  36. init();
  37. function init() {
  38. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 100 );
  39. camera.position.set( 1, 2, 3 );
  40. scene = new THREE.Scene();
  41. scene.background = new THREE.Color( 0x3355aa );
  42. camera.lookAt( 0, 1, 0 );
  43. timer = new THREE.Timer();
  44. timer.connect( document );
  45. //lights
  46. const light = new THREE.PointLight( 0xffffff, 1, 100 );
  47. light.power = 2500;
  48. camera.add( light );
  49. scene.add( camera );
  50. const ambient = new THREE.AmbientLight( 0x4466ff, 1 );
  51. scene.add( ambient );
  52. const loader = new GLTFLoader();
  53. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  54. const object = gltf.scene;
  55. mixer = new THREE.AnimationMixer( object );
  56. const action = mixer.clipAction( gltf.animations[ 0 ] );
  57. action.play();
  58. scene.add( object );
  59. } );
  60. //renderer
  61. renderer = new WebGLRenderer( { antialias: true } );
  62. renderer.setNodesHandler( new WebGLNodesHandler() );
  63. renderer.setPixelRatio( window.devicePixelRatio );
  64. renderer.setSize( window.innerWidth, window.innerHeight );
  65. renderer.setAnimationLoop( animate );
  66. renderer.toneMapping = THREE.LinearToneMapping;
  67. renderer.toneMappingExposure = 0.4;
  68. document.body.appendChild( renderer.domElement );
  69. window.addEventListener( 'resize', onWindowResize );
  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. timer.update();
  78. const delta = timer.getDelta();
  79. if ( mixer ) mixer.update( delta );
  80. renderer.render( scene, camera );
  81. }
  82. </script>
  83. </body>
  84. </html>
粤ICP备19079148号