2
0

webgpu_skinning_points.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.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 { uniform, skinning, PointsNodeMaterial } from 'three/nodes';
  25. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  26. import WebGPU from 'three/addons/capabilities/WebGPU.js';
  27. import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
  28. let camera, scene, renderer;
  29. let mixer, clock;
  30. init();
  31. function init() {
  32. if ( WebGPU.isAvailable() === false ) {
  33. document.body.appendChild( WebGPU.getErrorMessage() );
  34. throw new Error( 'No WebGPU support' );
  35. }
  36. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
  37. camera.position.set( 0, 300, - 85 );
  38. scene = new THREE.Scene();
  39. camera.lookAt( 0, 0, - 85 );
  40. clock = new THREE.Clock();
  41. const loader = new GLTFLoader();
  42. loader.load( 'models/gltf/Michelle.glb', function ( gltf ) {
  43. const object = gltf.scene;
  44. mixer = new THREE.AnimationMixer( object );
  45. const action = mixer.clipAction( gltf.animations[ 0 ] );
  46. action.play();
  47. object.traverse( function ( child ) {
  48. if ( child.isMesh ) {
  49. child.visible = false;
  50. const materialPoints = new PointsNodeMaterial();
  51. materialPoints.colorNode = uniform( new THREE.Color() );
  52. materialPoints.positionNode = skinning( child );
  53. const pointCloud = new THREE.Points( child.geometry, materialPoints );
  54. scene.add( pointCloud );
  55. }
  56. } );
  57. scene.add( object );
  58. } );
  59. //renderer
  60. renderer = new WebGPURenderer( { antialias: true } );
  61. renderer.setPixelRatio( window.devicePixelRatio );
  62. renderer.setSize( window.innerWidth, window.innerHeight );
  63. renderer.setAnimationLoop( animate );
  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>