webgl_morphtargets_face.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - morph targets - face</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. <style>
  9. body {
  10. color: black;
  11. }
  12. a {
  13. color: #f00;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div id="info">
  19. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - morph targets - face<br/>
  20. model by <a href="https://www.bannaflak.com/face-cap" target="_blank" rel="noopener">Face Cap</a>
  21. </div>
  22. <script type="module">
  23. import * as THREE from '../build/three.module.js';
  24. import Stats from './jsm/libs/stats.module.js';
  25. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  26. import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
  27. import { KTX2Loader } from './jsm/loaders/KTX2Loader.js';
  28. import { MeshoptDecoder } from './jsm/libs/meshopt_decoder.module.js';
  29. import { RoomEnvironment } from './jsm/environments/RoomEnvironment.js';
  30. init();
  31. function init() {
  32. let mixer;
  33. const clock = new THREE.Clock();
  34. const container = document.createElement( 'div' );
  35. document.body.appendChild( container );
  36. const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 20 );
  37. camera.position.set( - 1.8, 0.8, 3 );
  38. const scene = new THREE.Scene();
  39. const renderer = new THREE.WebGLRenderer( { antialias: true } );
  40. renderer.setPixelRatio( window.devicePixelRatio );
  41. renderer.setSize( window.innerWidth, window.innerHeight );
  42. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  43. renderer.outputEncoding = THREE.sRGBEncoding;
  44. container.appendChild( renderer.domElement );
  45. const ktx2Loader = new KTX2Loader()
  46. .setTranscoderPath( 'js/libs/basis/' )
  47. .detectSupport( renderer );
  48. new GLTFLoader()
  49. .setKTX2Loader( ktx2Loader )
  50. .setMeshoptDecoder( MeshoptDecoder )
  51. .load( 'models/gltf/facecap.glb', ( gltf ) => {
  52. const mesh = gltf.scene.children[ 0 ];
  53. scene.add( mesh );
  54. mixer = new THREE.AnimationMixer( mesh );
  55. mixer.clipAction( gltf.animations[ 0 ] ).play();
  56. } );
  57. const environment = new RoomEnvironment();
  58. const pmremGenerator = new THREE.PMREMGenerator( renderer );
  59. scene.background = new THREE.Color( 0xD5F7F7 );
  60. scene.environment = pmremGenerator.fromScene( environment ).texture;
  61. const controls = new OrbitControls( camera, renderer.domElement );
  62. controls.minDistance = 2.5;
  63. controls.maxDistance = 5;
  64. controls.minAzimuthAngle = - Math.PI / 2;
  65. controls.maxAzimuthAngle = Math.PI / 2;
  66. controls.maxPolarAngle = Math.PI / 1.8;
  67. controls.target.set( 0, 0, - 0.2 );
  68. controls.enableDamping = true;
  69. const stats = new Stats();
  70. container.appendChild( stats.dom );
  71. renderer.setAnimationLoop( () => {
  72. const delta = clock.getDelta();
  73. if ( mixer ) {
  74. mixer.update( delta );
  75. }
  76. renderer.render( scene, camera );
  77. controls.update();
  78. stats.update();
  79. } );
  80. window.addEventListener( 'resize', () => {
  81. camera.aspect = window.innerWidth / window.innerHeight;
  82. camera.updateProjectionMatrix();
  83. renderer.setSize( window.innerWidth, window.innerHeight );
  84. } );
  85. }
  86. </script>
  87. </body>
  88. </html>