VRMLoader.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // VRM Specification: https://dwango.github.io/vrm/vrm_spec/
  2. //
  3. // VRM is based on glTF 2.0 and VRM extension is defined
  4. // in top-level json.extensions.VRM
  5. THREE.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. } )();