VRMLoader.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @author Takahiro / https://github.com/takahirox
  3. */
  4. // VRM Specification: https://dwango.github.io/vrm/vrm_spec/
  5. //
  6. // VRM is based on glTF 2.0 and VRM extension is defined
  7. // in top-level json.extensions.VRM
  8. THREE.VRMLoader = ( function () {
  9. function VRMLoader( manager ) {
  10. if ( THREE.GLTFLoader === undefined ) {
  11. throw new Error( 'THREE.VRMLoader: Import THREE.GLTFLoader.' );
  12. }
  13. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  14. this.gltfLoader = new THREE.GLTFLoader( this.manager );
  15. }
  16. VRMLoader.prototype = {
  17. constructor: VRMLoader,
  18. crossOrigin: 'anonymous',
  19. load: function ( url, onLoad, onProgress, onError ) {
  20. var scope = this;
  21. this.gltfLoader.load( url, function ( gltf ) {
  22. scope.parse( gltf, onLoad );
  23. }, onProgress, onError );
  24. },
  25. setCrossOrigin: function ( value ) {
  26. this.glTFLoader.setCrossOrigin( value );
  27. return this;
  28. },
  29. setPath: function ( value ) {
  30. this.glTFLoader.setPath( value );
  31. return this;
  32. },
  33. setResourcePath: function ( value ) {
  34. this.glTFLoader.setResourcePath( value );
  35. return this;
  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. } )();