Trouble translating over a three.js plugin to Babylons.js

I’m trying to translate this three.js Plugin for krpano into a Babylon.js version. My approach is mostly to just replace the three.js functions and variables with the babylon ones, however, I’m currently stuck trying to figure out a replacement for the “renderer.resetGLState();” -threejs-function. (Which is now legacy)

I think the plugin uses these functions to switch between 2 differenent WebGL states, but I don’t exactly understand how it works.

	function restore_krpano_WebGL_state()
	{
		var gl = krpano.webGL.context;

		gl.disable(gl.DEPTH_TEST);
		gl.cullFace(gl.FRONT);
		gl.frontFace(gl.CCW);
		gl.enable(gl.BLEND);
		gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
		gl.activeTexture(gl.TEXTURE0);
		gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
		gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
		gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
		
		// restore the current krpano WebGL program
		krpano.webGL.restoreProgram();
	}


	function restore_ThreeJS_WebGL_state()
	{
		
		var gl = krpano.webGL.context;

		gl.enable(gl.DEPTH_TEST);
		gl.depthFunc(gl.LEQUAL);
		gl.enable(gl.CULL_FACE);
		gl.cullFace(gl.BACK);
		gl.clearDepth(1);
		gl.clear(gl.DEPTH_BUFFER_BIT);

		renderer.resetGLState();
	}

        //simplified render function
	function render_frame()

		var gl = krpano.webGL.context;

		var sw = gl.drawingBufferWidth;
		var sh = gl.drawingBufferHeight;

		// setup WebGL for ThreeJS
		restore_ThreeJS_WebGL_state();

		renderer.setViewport(0,0, sw,sh);
		renderer.render(scene, camera);

		// important - restore the krpano WebGL state for correct krpano rendering
		restore_krpano_WebGL_state();
	{

I have my suspision that this approach won’t work or exceeds my (very limited) technical understanding of this. Are there maybe better approaches to this? I thought of maybe using an iframe on top of the krpano canvas, would that be better?

1 Like

Yeah I agree this is probably not a good idea (and in BJS we hide webgl context because we want users to switch between WebGPU or WebGL rendering easily)

Anyway: to reset webGL cache you can call engine.wipeCaches()

1 Like

Hi @Marxanqui just checking in, was your question answered? :slight_smile: