Boz Posted October 6, 2015 Share Posted October 6, 2015 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 ? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 6, 2015 Share Posted October 6, 2015 Thank you for your comment. Ok, fixed. You can check with your link here: http://playground.babylonjs.com/#1IRV2X#65 Quote Link to comment Share on other sites More sharing options...
Boz Posted October 6, 2015 Author Share Posted October 6, 2015 Thanks, I will try it !! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 6, 2015 Share Posted October 6, 2015 Essaye de vider tes caches, il fonctionne tres bien sur le playground chez moi. Quote Link to comment Share on other sites More sharing options...
Boz Posted October 6, 2015 Author Share Posted October 6, 2015 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 ? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 6, 2015 Share Posted October 6, 2015 I will check more carefully tomorrow. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 7, 2015 Share Posted October 7, 2015 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 thiswindow.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 Quote Link to comment Share on other sites More sharing options...
Boz Posted October 7, 2015 Author Share Posted October 7, 2015 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() ;-) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted October 7, 2015 Share Posted October 7, 2015 No probleme. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.