VRMLoader.js 1.4 KB
Newer Older
M
r106  
Mr.doob 已提交
1
import {
M
r109  
Mr.doob 已提交
2
	Loader
M
r106  
Mr.doob 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
} from "../../../build/three.module.js";
import { GLTFLoader } from "../loaders/GLTFLoader.js";

// VRM Specification: https://dwango.github.io/vrm/vrm_spec/
//
// VRM is based on glTF 2.0 and VRM extension is defined
// in top-level json.extensions.VRM

var VRMLoader = ( function () {

	function VRMLoader( manager ) {

		if ( GLTFLoader === undefined ) {

			throw new Error( 'THREE.VRMLoader: Import GLTFLoader.' );

		}

M
r109  
Mr.doob 已提交
21 22
		Loader.call( this, manager );

M
r106  
Mr.doob 已提交
23 24 25 26
		this.gltfLoader = new GLTFLoader( this.manager );

	}

M
r109  
Mr.doob 已提交
27
	VRMLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
M
r106  
Mr.doob 已提交
28 29 30 31 32 33 34 35 36

		constructor: VRMLoader,

		load: function ( url, onLoad, onProgress, onError ) {

			var scope = this;

			this.gltfLoader.load( url, function ( gltf ) {

M
r117  
Mr.doob 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
				try {

					scope.parse( gltf, onLoad );

				} catch ( e ) {

					if ( onError ) {

						onError( e );

					} else {

						console.error( e );

					}

					scope.manager.itemError( url );

				}
M
r106  
Mr.doob 已提交
56 57 58 59 60 61 62

			}, onProgress, onError );

		},

		setDRACOLoader: function ( dracoLoader ) {

M
r117  
Mr.doob 已提交
63
			this.gltfLoader.setDRACOLoader( dracoLoader );
M
r106  
Mr.doob 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
			return this;

		},

		parse: function ( gltf, onLoad ) {

			// var gltfParser = gltf.parser;
			// var gltfExtensions = gltf.userData.gltfExtensions || {};
			// var vrmExtension = gltfExtensions.VRM || {};

			// handle VRM Extension here

			onLoad( gltf );

		}

M
r109  
Mr.doob 已提交
80
	} );
M
r106  
Mr.doob 已提交
81 82 83 84 85 86

	return VRMLoader;

} )();

export { VRMLoader };