<commit_before>(function() {
	var ThreeWebGLRendererPlugin = E2.plugins.three_webgl_renderer = function(core) {
		Plugin.apply(this, arguments)

		this.desc = 'THREE.js WebGL renderer'

		this.input_slots = [
			{
				name: 'camera',
				dt: core.datatypes.CAMERA,
				desc: 'Camera to use for rendering.'
			},
			{
				name: 'scene',
				dt: core.datatypes.SCENE,
				desc: 'Scene to render'
			},
			{
				name: 'bgcolor',
				dt: core.datatypes.COLOR,
				desc: 'Background color'
			},
			{
				name: 'shadowsEnabled',
				dt: core.datatypes.BOOL,
				desc: 'Master control for whether shadows are rendered',
				def: false
			}
		]

		this.output_slots = []

		this.always_update = true
		this.state = { always_update: true }

		this.clearColor = new THREE.Color(0,0,0)
	}

	ThreeWebGLRendererPlugin.prototype = Object.create(Plugin.prototype)

	ThreeWebGLRendererPlugin.prototype.stop = function() {
		if (this.renderer) {
			this.renderer.clear()
		}
	}

	ThreeWebGLRendererPlugin.prototype.reset = function() {
		this.domElement = E2.dom.webgl_canvas[0]

		console.log('reset',
			this.domElement.clientWidth,
			this.domElement.clientHeight,
			this.domElement.clientWidth / this.domElement.clientHeight)

		this.scene = new THREE.Scene()

		this.perspectiveCamera = new THREE.PerspectiveCamera(
			90,
			this.domElement.clientWidth / this.domElement.clientHeight,
			0.1,
			1000)
	}

	ThreeWebGLRendererPlugin.prototype.update_input = function(slot, data) {
		switch(slot.index) {
			case 0:
				this.perspectiveCamera = data
				return
			case 1:
				this.scene = data
				this.patchSceneForWorldEditor(this.scene)
				return
			case 2:
				this.clearColor = new THREE.Color(data.r, data.g, data.b)
				return
		}

		Plugin.prototype.update_input.apply(this, arguments)
	}

	ThreeWebGLRendererPlugin.prototype.update_state = function() {
		//this.updatePresentationMode()

		// workaround for having to share the renderer between render to texture & render to screen
		// tbd: remove once https://github.com/mrdoob/three.js/pull/6723 is merged into a three release
		this.renderer.setPixelRatio(window.devicePixelRatio)
		this.renderer.setClearColor(this.clearColor)

		if (!this.scene || !this.perspectiveCamera) {
			this.renderer.clear()

			return
		}

		this.renderer.shadowMap.enabled = this.inputValues.shadowsEnabled

		if (this.manager.isVRMode()) {
			// vr mode doesn't necessarily update the world matrix
			// could be a bug in new version of three.js
			this.perspectiveCamera.updateMatrixWorld()
		}

		if (E2.app.worldEditor.isActive()) {
			E2.app.worldEditor.preRenderUpdate()

			// Render the scene through the world editor camera
			this.manager.render(this.scene, E2.app.worldEditor.getCamera())
		}
		else {
			// Render the scene through the experience camera
			this.manager.render(this.scene, this.perspectiveCamera)
		}
	}

	ThreeWebGLRendererPlugin.prototype.patchSceneForWorldEditor = function() {
		if (E2.app.worldEditor.updateScene) {
			// tell the editor about changes in the scene
			E2.app.worldEditor.updateScene(this.scene, this.perspectiveCamera)
		}
	}

	ThreeWebGLRendererPlugin.prototype.play = function() {
		this.resize()
	}

	ThreeWebGLRendererPlugin.prototype.onVRPresentChange = function() {
		// change canvas size
		this.resize()
	}

	ThreeWebGLRendererPlugin.prototype.resize = function() {
		console.log('ThreeWebGLRendererPlugin.resize')

		var hmd = this.manager.hmd
		var isPresenting = hmd && hmd.isPresenting

		if (isPresenting) {
			var leftEye = hmd.getEyeParameters("left")
			var rightEye = hmd.getEyeParameters("right")

			this.domElement.width = leftEye.renderWidth * 2
			this.domElement.height = leftEye.renderHeight
		}
		else {
			this.domElement.width = this.domElement.offsetWidth * window.devicePixelRatio
			this.domElement.height = this.domElement.offsetHeight * window.devicePixelRatio
		}

		var isFullscreen = !!(document.mozFullScreenElement || document.webkitFullscreenElement);
		var wh = { width: window.innerWidth, height: window.innerHeight }

		if (!isFullscreen) {
			wh.width = this.domElement.offsetWidth
			wh.height = this.domElement.offsetHeight
		}

		this.effect.setSize(wh.width, wh.height)
	}

	ThreeWebGLRendererPlugin.prototype.enterVROrFullscreen = function() {
		this.manager.toggleFullScreen()
	}

	ThreeWebGLRendererPlugin.prototype.exitVROrFullscreen = function() {
		var that = this

		// to get back to normal mode, we have to:
		// 1) exit presentation mode
		// 2) do an equivalent to WebVRManager.prototype.onBackClick_()
		if (this.manager.hmd && this.manager.hmd.isPresenting) {
			this.manager.hmd.exitPresent()
			.then(function() {
				that.manager.setMode_(1)
				that.manager.exitFullscreen_()
			})
		}
		else {
			// no hmd, we still want to go to normal mode
			that.manager.setMode_(1);
			that.manager.exitFullscreen_();
		}
	}
/*
	ThreeWebGLRendererPlugin.prototype.updatePresentationMode = function() {
		// work around browser not sending events when going in/out of VR
		// presentation mode in Android / Desktop VR Chromium

		// this is called on update_state() and exits full screen if
		// presentation mode has changed without us knowing about it

		// update presentation mode
		var shouldBePresenting = E2.ui.isVisible()

		if (shouldBePresenting && !this.wasPresenting) {
			// we can't accidentally have gone to presentation mode so do nothing here
		}
		else if (!shouldBePresenting && this.wasPresenting) {
			// exit presentation mode
			this.exitVROrFullscreen()
		}

		this.wasPresenting = shouldBePresenting
	}
*/
	/*
	application calls this when we intend to get to fullscreen
	or come back from it to normal mode
	*/
	ThreeWebGLRendererPlugin.prototype.toggleFullScreen = function() {
		var goingToFullscreen = this.manager.mode === 1
		console.log('ThreeWebGLRendererPlugin.toggleFullScreen', goingToFullscreen)

		var that = this

		if (goingToFullscreen) {
			// normal to VR or full screen
			this.enterVROrFullscreen()
		}
		else {
			// toggleFullScreen doesn't get back from VR mode so we have to
			// do it ourselves

			this.exitVROrFullscreen()
		}

		// update the flag to tell updatePresentationMode() that we know where
		// we are
		this.wasPresenting = this.effect.isPresenting()
	}
<commit_msg>remove commented out code & one line that caused an error<commit_after>(function() {
	var ThreeWebGLRendererPlugin = E2.plugins.three_webgl_renderer = function(core) {
		Plugin.apply(this, arguments)

		this.desc = 'THREE.js WebGL renderer'

		this.input_slots = [
			{
				name: 'camera',
				dt: core.datatypes.CAMERA,
				desc: 'Camera to use for rendering.'
			},
			{
				name: 'scene',
				dt: core.datatypes.SCENE,
				desc: 'Scene to render'
			},
			{
				name: 'bgcolor',
				dt: core.datatypes.COLOR,
				desc: 'Background color'
			},
			{
				name: 'shadowsEnabled',
				dt: core.datatypes.BOOL,
				desc: 'Master control for whether shadows are rendered',
				def: false
			}
		]

		this.output_slots = []

		this.always_update = true
		this.state = { always_update: true }

		this.clearColor = new THREE.Color(0,0,0)
	}

	ThreeWebGLRendererPlugin.prototype = Object.create(Plugin.prototype)

	ThreeWebGLRendererPlugin.prototype.stop = function() {
		if (this.renderer) {
			this.renderer.clear()
		}
	}

	ThreeWebGLRendererPlugin.prototype.reset = function() {
		this.domElement = E2.dom.webgl_canvas[0]

		console.log('reset',
			this.domElement.clientWidth,
			this.domElement.clientHeight,
			this.domElement.clientWidth / this.domElement.clientHeight)

		this.scene = new THREE.Scene()

		this.perspectiveCamera = new THREE.PerspectiveCamera(
			90,
			this.domElement.clientWidth / this.domElement.clientHeight,
			0.1,
			1000)
	}

	ThreeWebGLRendererPlugin.prototype.update_input = function(slot, data) {
		switch(slot.index) {
			case 0:
				this.perspectiveCamera = data
				return
			case 1:
				this.scene = data
				this.patchSceneForWorldEditor(this.scene)
				return
			case 2:
				this.clearColor = new THREE.Color(data.r, data.g, data.b)
				return
		}

		Plugin.prototype.update_input.apply(this, arguments)
	}

	ThreeWebGLRendererPlugin.prototype.update_state = function() {
		// workaround for having to share the renderer between render to texture & render to screen
		// tbd: remove once https://github.com/mrdoob/three.js/pull/6723 is merged into a three release
		this.renderer.setPixelRatio(window.devicePixelRatio)
		this.renderer.setClearColor(this.clearColor)

		if (!this.scene || !this.perspectiveCamera) {
			this.renderer.clear()

			return
		}

		this.renderer.shadowMap.enabled = this.inputValues.shadowsEnabled

		if (this.manager.isVRMode()) {
			// vr mode doesn't necessarily update the world matrix
			// could be a bug in new version of three.js
			this.perspectiveCamera.updateMatrixWorld()
		}

		if (E2.app.worldEditor.isActive()) {
			E2.app.worldEditor.preRenderUpdate()

			// Render the scene through the world editor camera
			this.manager.render(this.scene, E2.app.worldEditor.getCamera())
		}
		else {
			// Render the scene through the experience camera
			this.manager.render(this.scene, this.perspectiveCamera)
		}
	}

	ThreeWebGLRendererPlugin.prototype.patchSceneForWorldEditor = function() {
		if (E2.app.worldEditor.updateScene) {
			// tell the editor about changes in the scene
			E2.app.worldEditor.updateScene(this.scene, this.perspectiveCamera)
		}
	}

	ThreeWebGLRendererPlugin.prototype.play = function() {
		this.resize()
	}

	ThreeWebGLRendererPlugin.prototype.onVRPresentChange = function() {
		// change canvas size
		this.resize()
	}

	ThreeWebGLRendererPlugin.prototype.resize = function() {
		console.log('ThreeWebGLRendererPlugin.resize')

		var hmd = this.manager.hmd
		var isPresenting = hmd && hmd.isPresenting

		if (isPresenting) {
			var leftEye = hmd.getEyeParameters("left")
			var rightEye = hmd.getEyeParameters("right")

			this.domElement.width = leftEye.renderWidth * 2
			this.domElement.height = leftEye.renderHeight
		}
		else {
			this.domElement.width = this.domElement.offsetWidth * window.devicePixelRatio
			this.domElement.height = this.domElement.offsetHeight * window.devicePixelRatio
		}

		var isFullscreen = !!(document.mozFullScreenElement || document.webkitFullscreenElement);
		var wh = { width: window.innerWidth, height: window.innerHeight }

		if (!isFullscreen) {
			wh.width = this.domElement.offsetWidth
			wh.height = this.domElement.offsetHeight
		}

		this.effect.setSize(wh.width, wh.height)
	}

	ThreeWebGLRendererPlugin.prototype.enterVROrFullscreen = function() {
		this.manager.toggleFullScreen()
	}

	ThreeWebGLRendererPlugin.prototype.exitVROrFullscreen = function() {
		var that = this

		// to get back to normal mode, we have to:
		// 1) exit presentation mode
		// 2) do an equivalent to WebVRManager.prototype.onBackClick_()
		if (this.manager.hmd && this.manager.hmd.isPresenting) {
			this.manager.hmd.exitPresent()
			.then(function() {
				that.manager.setMode_(1)
				that.manager.exitFullscreen_()
			})
		}
		else {
			// no hmd, we still want to go to normal mode
			that.manager.setMode_(1);
			that.manager.exitFullscreen_();
		}
	}

	/*
	application calls this when we intend to get to fullscreen
	or come back from it to normal mode
	*/
	ThreeWebGLRendererPlugin.prototype.toggleFullScreen = function() {
		var goingToFullscreen = this.manager.mode === 1
		console.log('ThreeWebGLRendererPlugin.toggleFullScreen', goingToFullscreen)

		var that = this

		if (goingToFullscreen) {
			// normal to VR or full screen
			this.enterVROrFullscreen()
		}
		else {
			// toggleFullScreen doesn't get back from VR mode so we have to
			// do it ourselves

			this.exitVROrFullscreen()
		}
	}

{'fraction_non_alphanumeric': 0.10739632321504916, 'fraction_numerical': 0.0055579307396323215, 'mean_word_length': 3.615627466456196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7580847', 'n_tokens_mistral': 4297, 'n_tokens_neox': 3691, 'n_words': 818}