VRMLoader.js 1.3 KB

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