webgpu_skinning.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. <!-- WebGPU (For Chrome 94-101), expires 09/01/2022 -->
  9. <meta http-equiv="origin-trial" content="AoS1pSJwCV3KRe73TO0YgJkK9FZ/qhmvKeafztp0ofiE8uoGrnKzfxGVKKICvoBfL8dgE0zpkp2g/oEJNS0fDgkAAABeeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJHUFUiLCJleHBpcnkiOjE2NTI4MzE5OTksImlzU3ViZG9tYWluIjp0cnVlfQ==">
  10. </head>
  11. <body>
  12. <div id="info">
  13. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> WebGPU - Skinning
  14. </div>
  15. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  16. <script type="importmap">
  17. {
  18. "imports": {
  19. "three": "../build/three.module.js"
  20. }
  21. }
  22. </script>
  23. <script type="module">
  24. import * as THREE from 'three';
  25. import { FBXLoader } from './jsm/loaders/FBXLoader.js';
  26. import WebGPU from './jsm/capabilities/WebGPU.js';
  27. import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
  28. import LightsNode from './jsm/renderers/nodes/lights/LightsNode.js';
  29. let camera, scene, renderer;
  30. let mixer, clock;
  31. init().then( animate ).catch( error );
  32. async function init() {
  33. if ( WebGPU.isAvailable() === false ) {
  34. document.body.appendChild( WebGPU.getErrorMessage() );
  35. throw new Error( 'No WebGPU support' );
  36. }
  37. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
  38. camera.position.set( 100, 200, 300 );
  39. scene = new THREE.Scene();
  40. camera.lookAt( 0, 100, 0 );
  41. clock = new THREE.Clock();
  42. //lights
  43. const light = new THREE.PointLight( 0xffffff );
  44. camera.add( light );
  45. scene.add( camera );
  46. const lightNode = LightsNode.fromLights( [ light ] );
  47. const loader = new FBXLoader();
  48. loader.load( 'models/fbx/Samba Dancing.fbx', function ( object ) {
  49. mixer = new THREE.AnimationMixer( object );
  50. const action = mixer.clipAction( object.animations[ 0 ] );
  51. action.play();
  52. object.traverse( function ( child ) {
  53. if ( child.isMesh ) {
  54. child.material = new THREE.MeshStandardMaterial();
  55. child.material.lightNode = lightNode;
  56. }
  57. } );
  58. scene.add( object );
  59. } );
  60. //renderer
  61. renderer = new WebGPURenderer();
  62. renderer.setPixelRatio( window.devicePixelRatio );
  63. renderer.setSize( window.innerWidth, window.innerHeight );
  64. document.body.appendChild( renderer.domElement );
  65. window.addEventListener( 'resize', onWindowResize );
  66. return renderer.init();
  67. }
  68. function onWindowResize() {
  69. camera.aspect = window.innerWidth / window.innerHeight;
  70. camera.updateProjectionMatrix();
  71. renderer.setSize( window.innerWidth, window.innerHeight );
  72. }
  73. function animate() {
  74. requestAnimationFrame( animate );
  75. const delta = clock.getDelta();
  76. if ( mixer ) mixer.update( delta );
  77. renderer.render( scene, camera );
  78. }
  79. function error( error ) {
  80. console.error( error );
  81. }
  82. </script>
  83. </body>
  84. </html>