{"size": 2229, "ext": "js", "max_stars_repo_path": "browser/scripts/loaders/sceneLoader.js", "max_stars_repo_name": "waskosky/patches", "max_stars_repo_stars_event_min_datetime": "2015-09-21T15:08:57.000Z", "max_stars_repo_stars_event_max_datetime": "2017-07-31T08:01:22.000Z", "max_issues_repo_path": "browser/scripts/loaders/sceneLoader.js", "max_issues_repo_name": "waskosky/patches", "max_issues_repo_issues_event_min_datetime": "2015-09-15T23:49:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-01T08:52:00.000Z", "max_forks_repo_path": "browser/scripts/loaders/sceneLoader.js", "max_forks_repo_name": "waskosky/patches", "max_forks_repo_forks_event_min_datetime": "2015-10-11T10:42:50.000Z", "max_forks_repo_forks_event_max_datetime": "2017-07-16T22:31:42.000Z"}
{"max_stars_count": 187, "max_issues_count": 1533, "max_forks_count": 52, "avg_line_length": 25.3295454545, "max_line_length": 136, "alphanum_fraction": 0.6890982503}
(function() {

function SceneLoader() {
	E2.Loaders.ModelLoader.apply(this, arguments)
}
SceneLoader.prototype = Object.create(E2.Loaders.ModelLoader.prototype)

SceneLoader.prototype.loadObject3D = function(url) {
	if (!this.loader) {
		this.loader = new MultiObjectLoader()
	}

	this.loader.crossOrigin = 'Anonymous'
	this.loader.load(
			url,
			this.onObjLoaded.bind(this),
			this.onHierarchyLoaded.bind(this),
			this.progressHandler.bind(this),
			this.errorHandler.bind(this))
}

SceneLoader.prototype.onHierarchyLoaded = function(scene) {
	if (scene.animations) {
		var len = scene.animations.length
		for (var i = 0; i < len; ++i) {
			var animation = scene.animations[i]
			animation.loop = true
			animation.play()
		}
	}

	if (scene.scene) {
		if (scene.scene instanceof THREE.Object3D) {
			this.object3d = scene.scene
		}
		else {
			this.object3d = new THREE.Object3D()
			this.object3d.copy(scene.scene, /*recursive = */false)

			while (scene.scene.children.length > 0) {
				var obj = scene.scene.children[0]
				scene.scene.remove(obj)
				this.object3d.add(obj)
			}
		}
	}
	else {
		this.object3d = scene
	}

	this.emit('loaded', this.object3d)
}

SceneLoader.prototype.onObjLoaded = function(geoms, mats) {
	var hasMorphAnimations = geoms.length > 0 && geoms[0].morphTargets && geoms[0].morphTargets.length > 0

	var createMesh = hasMorphAnimations ?
			function(geom, mat) {return new THREE.MorphAnimMesh(geom, mat)}
		:   function(geom, mat) {return new THREE.Mesh(geom, mat)}

	if (geoms.length === 1 && mats.length === 1) {
		this.object3d = createMesh(geoms[0], mats[0])
	}
	else if (geoms.length > 1 && mats.length === geoms.length) {
		this.object3d = new THREE.Group()

		for (var i = 0; i < geoms.length; ++i) {
			this.object3d.add(createMesh(geoms[i], mats[i]))
		}
	}
	else if (geoms.length === 1) {
		this.object3d = THREE.SceneUtils.createMultiMaterialObject(geoms[0], mats)
	}
	else {
		console.error('ThreeLoaderScenePlugin: Invalid geometry + material combination', geoms.length, 'geometries', mats.length, 'materials')
	}

	this.emit('loaded', this.object3d)
}

E2.Loaders.SceneLoader = SceneLoader

if (typeof(module) !== 'undefined') {
	module.exports.SceneLoader = SceneLoader
}

})()
