webgpu_skinning.html 3.1 KB

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