VRMLoader.js 1.1 KB

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