VRMLoader.js 1.4 KB

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