VRMLoader.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {
  2. Loader
  3. } from '../../../build/three.module.js';
  4. import { GLTFLoader } from '../loaders/GLTFLoader.js';
  5. // VRM Specification: https://dwango.github.io/vrm/vrm_spec/
  6. //
  7. // VRM is based on glTF 2.0 and VRM extension is defined
  8. // in top-level json.extensions.VRM
  9. class VRMLoader extends Loader {
  10. constructor( manager ) {
  11. if ( GLTFLoader === undefined ) {
  12. throw new Error( 'THREE.VRMLoader: Import GLTFLoader.' );
  13. }
  14. super( manager );
  15. this.gltfLoader = new GLTFLoader( manager );
  16. }
  17. load( url, onLoad, onProgress, onError ) {
  18. const scope = this;
  19. this.gltfLoader.load( url, function ( gltf ) {
  20. try {
  21. scope.parse( gltf, onLoad );
  22. } catch ( e ) {
  23. if ( onError ) {
  24. onError( e );
  25. } else {
  26. console.error( e );
  27. }
  28. scope.manager.itemError( url );
  29. }
  30. }, onProgress, onError );
  31. }
  32. setDRACOLoader( dracoLoader ) {
  33. this.gltfLoader.setDRACOLoader( dracoLoader );
  34. return this;
  35. }
  36. parse( gltf, onLoad ) {
  37. // const gltfParser = gltf.parser;
  38. // const gltfExtensions = gltf.userData.gltfExtensions || {};
  39. // const vrmExtension = gltfExtensions.VRM || {};
  40. // handle VRM Extension here
  41. onLoad( gltf );
  42. }
  43. }
  44. export { VRMLoader };