<commit_before>function WorldEditor() {
	this.domElement = E2.dom.webgl_canvas[0]
	this.camera = new WorldEditorCamera(this.domElement)

	var active = false

	this.activate = function() {
		active = true
	}

	this.deactivate = function() {
		if (this.editorTree.parent) {
			this.editorTree.parent.remove(this.editorTree)
		}
		active = false
	}

	this.isActive = function() {
		return active
	}

	this.editorTree = new THREE.Object3D()

	// grid around origin along x, z axises
	this.grid = new WorldEditorOriginGrid()
	this.editorTree.add(this.grid.mesh)

	// root for any selection bboxes
	this.selectionTree = new THREE.Object3D()
	this.editorTree.add(this.selectionTree)

	// root for 3d handles
	this.handleTree = new THREE.Object3D()
	this.editorTree.add(this.handleTree)

	// editor controls
	this.editorControls = new THREE.EditorControls(this.camera.perspectiveCamera, this.domElement)

	// transform controls
	this.transformControls = new THREE.TransformControls(this.camera.perspectiveCamera, this.domElement)

	var that = this

	this.transformControls.addEventListener('mouseDown', function() {
		that.editorControls.enabled = false
		if (E2.app.alt_pressed) {
			E2.app.onCopy()
			E2.app.onPaste()
		}
	})

	this.transformControls.addEventListener('mouseUp', function() {
		that.editorControls.enabled = true
	})

	this.setupObjectPicking()

	E2.ui.state.on('changed:modifyMode', function(modifyMode){
		switch (modifyMode) {
			case 'translate':
				return that.setModifyModeTranslate()
			case 'rotate':
				return that.setModifyModeRotate()
			case 'scale':
				return that.setModifyModeScale()
		}
		return that
	});

}

WorldEditor.prototype.update = function() {
	if (!this.isActive()) {
		return
	}

	// update the reference grid scale based on camera distance from target
	var f = function(v, n) {
		if (v / 10 < n) { return n }
		return f(v, n * 10)
	}

	var len = this.camera.perspectiveCamera.position.clone().sub(this.editorControls.center).length() || 1
	var v = f(len, 0.01)

	this.grid.scale(v)

}

WorldEditor.prototype.setModifyModeTranslate = function() {
	this.transformControls.setMode('translate')
	this.transformControls.setSpace('local')
	return this
}

WorldEditor.prototype.setModifyModeRotate = function() {
	this.transformControls.setMode('rotate')
	this.transformControls.setSpace('local')
	return this
}

WorldEditor.prototype.setModifyModeScale = function() {
	this.transformControls.setMode('scale')
	this.transformControls.setSpace('local')
	return this<commit_msg>back a step for Three<commit_after>function WorldEditor() {
	this.domElement = E2.dom.webgl_canvas[0]
	this.camera = new WorldEditorCamera(this.domElement)

	var active = false

	this.activate = function() {
		active = true
	}

	this.deactivate = function() {
		if (this.editorTree.parent) {
			this.editorTree.parent.remove(this.editorTree)
		}
		active = false
	}

	this.isActive = function() {
		return active
	}

	this.transformMode = 'translate'

	this.editorTree = new THREE.Object3D()

	// grid around origin along x, z axises
	this.grid = new WorldEditorOriginGrid()
	this.editorTree.add(this.grid.mesh)

	// root for any selection bboxes
	this.selectionTree = new THREE.Object3D()
	this.editorTree.add(this.selectionTree)

	// root for 3d handles
	this.handleTree = new THREE.Object3D()
	this.editorTree.add(this.handleTree)

	// editor controls
	this.editorControls = new THREE.EditorControls(this.camera.perspectiveCamera, this.domElement)

	// transform controls
	this.transformControls = new THREE.TransformControls(this.camera.perspectiveCamera, this.domElement)

	var that = this

	this.transformControls.addEventListener('mouseDown', function() {
		that.editorControls.enabled = false
		if (E2.app.alt_pressed) {
			E2.app.onCopy()
			E2.app.onPaste()
		}
	})

	this.transformControls.addEventListener('mouseUp', function() {
		that.editorControls.enabled = true
	})

	this.setupObjectPicking()

	E2.ui.state.on('changed:modifyMode', this.setTransformMode.bind(this));

}

WorldEditor.prototype.setTransformMode = function(mode) {
	this.transformMode = mode
}

WorldEditor.prototype.update = function() {
	if (!this.isActive()) {
		return
	}

	// update the reference grid scale based on camera distance from target
	var f = function(v, n) {
		if (v / 10 < n) { return n }
		return f(v, n * 10)
	}

	var len = this.camera.perspectiveCamera.position.clone().sub(this.editorControls.center).length() || 1
	var v = f(len, 0.01)

	this.grid.scale(v)

	// needs calling on every update otherwise the transform controls draw incorrectly
	this.transformControls.setMode(this.transformMode)
	this.transformControls.setSpace('local')
{'fraction_non_alphanumeric': 0.12274290627687016, 'fraction_numerical': 0.007738607050730868, 'mean_word_length': 4.3544303797468356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5439301', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1488, 'n_words': 306}