VRMLoader.js 1.5 KB

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