VRMLoader.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. THREE.Loader.call( this, manager );
  14. this.gltfLoader = new THREE.GLTFLoader( this.manager );
  15. }
  16. VRMLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
  17. constructor: VRMLoader,
  18. load: function ( url, onLoad, onProgress, onError ) {
  19. var scope = this;
  20. this.gltfLoader.load( url, function ( gltf ) {
  21. try {
  22. scope.parse( gltf, onLoad );
  23. } catch ( e ) {
  24. if ( onError ) {
  25. onError( e );
  26. } else {
  27. console.error( e );
  28. }
  29. scope.manager.itemError( url );
  30. }
  31. }, onProgress, onError );
  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. } )();