webgpu_skinning_points.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/webgpu": "../build/three.webgpu.js",
  18. "three/tsl": "../build/three.tsl.js",
  19. "three/addons/": "./jsm/"
  20. }
  21. }
  22. </script>
  23. <script type="module">
  24. import * as THREE from 'three';
  25. import { uniform, skinning } from 'three/tsl';
  26. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  27. let camera, scene, renderer;
  28. let mixer, clock;
  29. init();
  30. function init() {
  31. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
  32. camera.position.set( 0, 300, - 85 );
  33. scene = new THREE.Scene();
  34. camera.lookAt( 0, 0, - 85 );
  35. clock = new THREE.Clock();
  36. const loader = new GLTFLoader();
  37. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  38. const object = gltf.scene;
  39. mixer = new THREE.AnimationMixer( object );
  40. const action = mixer.clipAction( gltf.animations[ 0 ] );
  41. action.play();
  42. object.traverse( function ( child ) {
  43. if ( child.isMesh ) {
  44. child.visible = false;
  45. const materialPoints = new THREE.PointsNodeMaterial();
  46. materialPoints.colorNode = uniform( new THREE.Color() );
  47. materialPoints.positionNode = skinning( child );
  48. const pointCloud = new THREE.Points( child.geometry, materialPoints );
  49. scene.add( pointCloud );
  50. }
  51. } );
  52. scene.add( object );
  53. } );
  54. //renderer
  55. renderer = new THREE.WebGPURenderer( { antialias: true } );
  56. renderer.setPixelRatio( window.devicePixelRatio );
  57. renderer.setSize( window.innerWidth, window.innerHeight );
  58. renderer.setAnimationLoop( animate );
  59. document.body.appendChild( renderer.domElement );
  60. window.addEventListener( 'resize', onWindowResize );
  61. }
  62. function onWindowResize() {
  63. camera.aspect = window.innerWidth / window.innerHeight;
  64. camera.updateProjectionMatrix();
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. }
  67. function animate() {
  68. const delta = clock.getDelta();
  69. if ( mixer ) mixer.update( delta );
  70. renderer.render( scene, camera );
  71. }
  72. </script>
  73. </body>
  74. </html>
粤ICP备19079148号