Jump to content

CastorGUI dispose system


Boz
 Share

Recommended Posts

Hi !

Thanks for the CastorGUI engine, it looks promising :)

But I got problems with the GUIManager.dispose() function.

I created a playground : http://playground.babylonjs.com/#1IRV2X#65

In my scene, I have this code :

var button = new CASTORGUI.GUITexture("button", "textures/vault11.png", {w: button_w, h: button_h, x: button_x, y: button_y}, guiManager, function() {	if(selectedPlayer != "NULL"){	// Dispose GUI	//guiManager.setVisible(false);	//guiManager.dispose();	// Cancel menu state	window.cancelAnimationFrame(menu_animate);	// Game init	init(selectedPlayer);	// Game animate	animate();});

this code call the init() function

function init(selectedPlayer) {	// Dispose GUIManager from the menu	//guiManager.dispose();	//guiManager.setVisible(false, false);		// Initialise scene	createScene();}

and creates a new scene !!

Everything works well, except I can not dispose the GUIManager. It still appears on the screen.

Is there a way to remove the GUIManager ?

And another problem appears just after that. This code  worked before :

window.addEventListener("click", function () {	// We try to pick an object	var pickResult = babylonScene.pick(babylonScene.pointerX, babylonScene.pointerY);	console.log(pickResult);        if(pickResult.hit)	{		// Mesh name picked		var pickName = pickResult.pickedMesh.name;		console.log(pickName);			}});

But not now, the ground is always the only picked mesh :/

So I suppose it is because the GUIManager is still present ?

Link to comment
Share on other sites

OK it works, the GUI remove elements. But I still got one problem.

 

I was using bGUI this way :

var gui = new bGUI.GUISystem(babylonScene, 1200, 780);gui.enableClick();            // Logovar logo = new bGUI.GUIPanel("logo", assets["logo"], null, gui);logo.relativePosition(new BABYLON.Vector3(0.5, 0.05, 0));// Buttonvar vault = new bGUI.GUIPanel("button", assets["vault11"], null, gui);vault.relativePosition(new BABYLON.Vector3(0.5, 0.9, 0));vault.onClick = function(){        if(selectedPlayer != "NULL"){        // Cancel menu state	window.cancelAnimationFrame(menu_animate);	// Game init	init(selectedPlayer);	// Game animate        animate();}

I replaced it by this code from CastorGUI :

// CSSvar css = '';	// Empty, no CSS for now// ManagerguiManager = new CASTORGUI.GUIManager(canvas, css);			// Logovar logo_h = guiManager.getCanvasWidth().height * 20/100;		// height : 15% du canvasvar logo_w = logo_h;											// width = height (logo carré)var logo_x = (guiManager.getCanvasWidth().width - logo_w) / 2;	// centré en xvar logo_y = 10;												// marge en yvar logo = new CASTORGUI.GUITexture("logo", "textures/tlk_logo_256.png",												{w: logo_w, h: logo_h, x: logo_x, y: logo_y}, guiManager, null);			// Buttonvar button_h = guiManager.getCanvasWidth().height * 15/100;			// height : 10% du canvasvar button_w = button_h * 2.5;										// approximatif (img = 255x98)var button_x = (guiManager.getCanvasWidth().width - button_w) / 2;	// centré en xvar button_y = guiManager.getCanvasWidth().height - button_h - 10;	// marge en yvar button = new CASTORGUI.GUITexture("button", "textures/vault11.png", {w: button_w, h: button_h, x: button_x, y: button_y}, guiManager, function() {	if(selectedPlayer != "NULL"){		// Dispose GUI		guiManager.dispose();		// Cancel menu state		window.cancelAnimationFrame(menu_animate);		// Game init		init(selectedPlayer);		// Game animate		animate();	}});

So with bGUI, when I clicked the button, a new scene was created and I can pick meshes on the scene.

But with CastorGUI, I always pick the same mesh, it is strange...

 

Do you have an idea why this code returns different results with these GUI ?

window.addEventListener("click", function () {	// We try to pick an object	var pickResult = babylonScene.pick(babylonScene.pointerX, babylonScene.pointerY);	console.log(pickResult);        if(pickResult.hit)	{		// Mesh name picked		var pickName = pickResult.pickedMesh.name;		console.log(pickName);	}});

Maybe it comes from the "window" element ? Do you modify something from the window, the document, or something else, to create your GUI ?

Link to comment
Share on other sites

try this:

scene.onPointerDown = function (evt, pickResult) {	console.log(pickResult);	if (pickResult.hit && pickResult.pickedMesh) {		// Mesh name picked		var pickName = pickResult.pickedMesh.name;		console.log(pickName);	}			};

instead of this

window.addEventListener("click", function () {	// We try to pick an object	var pickResult = babylonScene.pick(babylonScene.pointerX, babylonScene.pointerY);	console.log(pickResult);        if(pickResult.hit)	{		// Mesh name picked		var pickName = pickResult.pickedMesh.name;		console.log(pickName);	}});

CastorGUI being a layer on top of the canvas, it has no impact on the scene

Link to comment
Share on other sites

Hm, the fact is I was calling scene.dispose(), to clean the scene, and after that I add some new elements.

 

But the dispose() function calls detachControl() on the scene, and you have to call attachControl() yourself to re-activate the click and keyboard events. That was my mistake.

It is strange because controls worked anyway (click was detected but worked bad)

 

Thank you Dad to have fixed guimanager.dispose() ;-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...