webgpu_skinning_points.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - WebGPU - Skinning Points</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 Points<br />
  12. (Chrome Canary with flag: --enable-unsafe-webgpu)
  13. </div>
  14. <script type="importmap">
  15. {
  16. "imports": {
  17. "three": "../build/three.module.js"
  18. }
  19. }
  20. </script>
  21. <script type="module">
  22. import * as THREE from 'three';
  23. import { FBXLoader } from './jsm/loaders/FBXLoader.js';
  24. import WebGPURenderer from './jsm/renderers/webgpu/WebGPURenderer.js';
  25. import WebGPU from './jsm/renderers/webgpu/WebGPU.js';
  26. import * as Nodes from './jsm/renderers/nodes/Nodes.js';
  27. let camera, scene, renderer;
  28. let mixer, clock;
  29. init().then( animate ).catch( error );
  30. async function init() {
  31. if ( WebGPU.isAvailable() === false ) {
  32. document.body.appendChild( WebGPU.getErrorMessage() );
  33. throw 'No WebGPU support';
  34. }
  35. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
  36. camera.position.set( 100, 200, 300 );
  37. scene = new THREE.Scene();
  38. camera.lookAt( 0, 100, 0 );
  39. clock = new THREE.Clock();
  40. const loader = new FBXLoader();
  41. loader.load( 'models/fbx/Samba Dancing.fbx', function ( object ) {
  42. mixer = new THREE.AnimationMixer( object );
  43. const action = mixer.clipAction( object.animations[ 0 ] );
  44. action.play();
  45. object.traverse( function ( child ) {
  46. if ( child.isMesh ) {
  47. child.visible = false;
  48. const materialPoints = new Nodes.PointsNodeMaterial();
  49. materialPoints.colorNode = new Nodes.ColorNode();
  50. materialPoints.positionNode = new Nodes.SkinningNode( child );
  51. const pointCloud = new THREE.Points( child.geometry, materialPoints );
  52. scene.add( pointCloud );
  53. }
  54. } );
  55. scene.add( object );
  56. } );
  57. //renderer
  58. renderer = new WebGPURenderer();
  59. renderer.setPixelRatio( window.devicePixelRatio );
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. document.body.appendChild( renderer.domElement );
  62. window.addEventListener( 'resize', onWindowResize );
  63. return renderer.init();
  64. }
  65. function onWindowResize() {
  66. camera.aspect = window.innerWidth / window.innerHeight;
  67. camera.updateProjectionMatrix();
  68. renderer.setSize( window.innerWidth, window.innerHeight );
  69. }
  70. function animate() {
  71. requestAnimationFrame( animate );
  72. const delta = clock.getDelta();
  73. if ( mixer ) mixer.update( delta );
  74. renderer.render( scene, camera );
  75. }
  76. function error( error ) {
  77. console.error( error );
  78. }
  79. </script>
  80. </body>
  81. </html>