VRMLoader.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @author Takahiro / https://github.com/takahirox
  3. */
  4. import {
  5. DefaultLoadingManager
  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. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18. this.gltfLoader = new GLTFLoader( this.manager );
  19. }
  20. VRMLoader.prototype = {
  21. constructor: VRMLoader,
  22. crossOrigin: 'anonymous',
  23. load: function ( url, onLoad, onProgress, onError ) {
  24. var scope = this;
  25. this.gltfLoader.load( url, function ( gltf ) {
  26. scope.parse( gltf, onLoad );
  27. }, onProgress, onError );
  28. },
  29. setCrossOrigin: function ( value ) {
  30. this.glTFLoader.setCrossOrigin( value );
  31. return this;
  32. },
  33. setPath: function ( value ) {
  34. this.glTFLoader.setPath( value );
  35. return this;
  36. },
  37. setResourcePath: function ( value ) {
  38. this.glTFLoader.setResourcePath( value );
  39. return this;
  40. },
  41. setDRACOLoader: function ( dracoLoader ) {
  42. this.glTFLoader.setDRACOLoader( dracoLoader );
  43. return this;
  44. },
  45. parse: function ( gltf, onLoad ) {
  46. // var gltfParser = gltf.parser;
  47. // var gltfExtensions = gltf.userData.gltfExtensions || {};
  48. // var vrmExtension = gltfExtensions.VRM || {};
  49. // handle VRM Extension here
  50. onLoad( gltf );
  51. }
  52. };
  53. return VRMLoader;
  54. } )();
  55. export { VRMLoader };