VRMLoader.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. setDRACOLoader: function ( dracoLoader ) {
  34. this.glTFLoader.setDRACOLoader( dracoLoader );
  35. return this;
  36. },
  37. parse: function ( gltf, onLoad ) {
  38. var gltfParser = gltf.parser;
  39. var gltfExtensions = gltf.userData.gltfExtensions || {};
  40. var vrmExtension = gltfExtensions.VRM || {};
  41. // handle VRM Extension here
  42. onLoad( gltf );
  43. }
  44. };
  45. return VRMLoader;
  46. } )();