webgpu_skinning.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - skinning
  12. </div>
  13. <script type="importmap">
  14. {
  15. "imports": {
  16. "three": "../build/three.webgpu.js",
  17. "three/tsl": "../build/three.webgpu.js",
  18. "three/addons/": "./jsm/"
  19. }
  20. }
  21. </script>
  22. <script type="module">
  23. import * as THREE from 'three';
  24. import { color, screenUV } from 'three/tsl';
  25. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  26. let camera, scene, renderer;
  27. let mixer, clock;
  28. init();
  29. function init() {
  30. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 100 );
  31. camera.position.set( 1, 2, 3 );
  32. scene = new THREE.Scene();
  33. scene.backgroundNode = screenUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
  34. camera.lookAt( 0, 1, 0 );
  35. clock = new THREE.Clock();
  36. //lights
  37. const light = new THREE.PointLight( 0xffffff, 1, 100 );
  38. light.power = 2500;
  39. camera.add( light );
  40. scene.add( camera );
  41. const ambient = new THREE.AmbientLight( 0x4466ff, 1 );
  42. scene.add( ambient );
  43. const loader = new GLTFLoader();
  44. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  45. const object = gltf.scene;
  46. mixer = new THREE.AnimationMixer( object );
  47. const action = mixer.clipAction( gltf.animations[ 0 ] );
  48. action.play();
  49. scene.add( object );
  50. } );
  51. //renderer
  52. renderer = new THREE.WebGPURenderer( { antialias: true } );
  53. renderer.setPixelRatio( window.devicePixelRatio );
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. renderer.setAnimationLoop( animate );
  56. renderer.toneMapping = THREE.LinearToneMapping;
  57. renderer.toneMappingExposure = 0.4;
  58. document.body.appendChild( renderer.domElement );
  59. window.addEventListener( 'resize', onWindowResize );
  60. }
  61. function onWindowResize() {
  62. camera.aspect = window.innerWidth / window.innerHeight;
  63. camera.updateProjectionMatrix();
  64. renderer.setSize( window.innerWidth, window.innerHeight );
  65. }
  66. function animate() {
  67. const delta = clock.getDelta();
  68. if ( mixer ) mixer.update( delta );
  69. renderer.render( scene, camera );
  70. }
  71. </script>
  72. </body>
  73. </html>