webgpu_skinning_points.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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
  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 { uniform, skinning } 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, 1, 1000 );
  31. camera.position.set( 0, 300, - 85 );
  32. scene = new THREE.Scene();
  33. camera.lookAt( 0, 0, - 85 );
  34. clock = new THREE.Clock();
  35. const loader = new GLTFLoader();
  36. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  37. const object = gltf.scene;
  38. mixer = new THREE.AnimationMixer( object );
  39. const action = mixer.clipAction( gltf.animations[ 0 ] );
  40. action.play();
  41. object.traverse( function ( child ) {
  42. if ( child.isMesh ) {
  43. child.visible = false;
  44. const materialPoints = new THREE.PointsNodeMaterial();
  45. materialPoints.colorNode = uniform( new THREE.Color() );
  46. materialPoints.positionNode = skinning( child );
  47. const pointCloud = new THREE.Points( child.geometry, materialPoints );
  48. scene.add( pointCloud );
  49. }
  50. } );
  51. scene.add( object );
  52. } );
  53. //renderer
  54. renderer = new THREE.WebGPURenderer( { antialias: true } );
  55. renderer.setPixelRatio( window.devicePixelRatio );
  56. renderer.setSize( window.innerWidth, window.innerHeight );
  57. renderer.setAnimationLoop( animate );
  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>