1
0

VRMLookAtSmootherLoaderPlugin.ts 808 B

1234567891011121314151617181920212223242526
  1. import {
  2. VRMHumanoid,
  3. VRMLookAt,
  4. VRMLookAtLoaderPlugin,
  5. } from "@pixiv/three-vrm";
  6. import { GLTF } from "three/examples/jsm/loaders/GLTFLoader.js";
  7. import { VRMLookAtSmoother } from "./VRMLookAtSmoother";
  8. export class VRMLookAtSmootherLoaderPlugin extends VRMLookAtLoaderPlugin {
  9. public get name(): string {
  10. return "VRMLookAtSmootherLoaderPlugin";
  11. }
  12. public async afterRoot(gltf: GLTF): Promise<void> {
  13. await super.afterRoot(gltf);
  14. const humanoid = gltf.userData.vrmHumanoid as VRMHumanoid | null;
  15. const lookAt = gltf.userData.vrmLookAt as VRMLookAt | null;
  16. if (humanoid != null && lookAt != null) {
  17. const lookAtSmoother = new VRMLookAtSmoother(humanoid, lookAt.applier);
  18. lookAtSmoother.copy(lookAt);
  19. gltf.userData.vrmLookAt = lookAtSmoother;
  20. }
  21. }
  22. }