webgpu_skinning.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.module.js",
  17. "three/addons/": "./jsm/",
  18. "three/nodes": "./jsm/nodes/Nodes.js"
  19. }
  20. }
  21. </script>
  22. <script type="module">
  23. import * as THREE from 'three';
  24. import { toneMapping, color, viewportTopLeft } from 'three/nodes';
  25. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  26. import WebGPU from 'three/addons/capabilities/WebGPU.js';
  27. import WebGL from 'three/addons/capabilities/WebGL.js';
  28. import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
  29. let camera, scene, renderer;
  30. let mixer, clock;
  31. init();
  32. function init() {
  33. if ( WebGPU.isAvailable() === false && WebGL.isWebGL2Available() === false ) {
  34. document.body.appendChild( WebGPU.getErrorMessage() );
  35. throw new Error( 'No WebGPU or WebGL2 support' );
  36. }
  37. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 100 );
  38. camera.position.set( 1, 2, 3 );
  39. scene = new THREE.Scene();
  40. scene.backgroundNode = viewportTopLeft.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
  41. camera.lookAt( 0, 1, 0 );
  42. clock = new THREE.Clock();
  43. //lights
  44. const light = new THREE.PointLight( 0xffffff, 1, 100 );
  45. light.power = 2500;
  46. camera.add( light );
  47. scene.add( camera );
  48. const ambient = new THREE.AmbientLight( 0x4466ff, 1 );
  49. scene.add( ambient );
  50. const loader = new GLTFLoader();
  51. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  52. const object = gltf.scene;
  53. mixer = new THREE.AnimationMixer( object );
  54. const action = mixer.clipAction( gltf.animations[ 0 ] );
  55. action.play();
  56. scene.add( object );
  57. } );
  58. //renderer
  59. renderer = new WebGPURenderer( { antialias: true } );
  60. renderer.setPixelRatio( window.devicePixelRatio );
  61. renderer.setSize( window.innerWidth, window.innerHeight );
  62. renderer.setAnimationLoop( animate );
  63. renderer.toneMappingNode = toneMapping( THREE.LinearToneMapping, .4 );
  64. document.body.appendChild( renderer.domElement );
  65. window.addEventListener( 'resize', onWindowResize );
  66. }
  67. function onWindowResize() {
  68. camera.aspect = window.innerWidth / window.innerHeight;
  69. camera.updateProjectionMatrix();
  70. renderer.setSize( window.innerWidth, window.innerHeight );
  71. }
  72. function animate() {
  73. const delta = clock.getDelta();
  74. if ( mixer ) mixer.update( delta );
  75. renderer.render( scene, camera );
  76. }
  77. </script>
  78. </body>
  79. </html>