Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete dat.GUI element?

I found this function to remove a gui element but i think it is outdated. So far I haven't been able to find anyone else who knows how to remove any part of a gui, whether its an entire dat.GUI() or just an added element to a dat.GUI(). The first would probably be enough for what i need (just removing the dat.GUI() all together) but either one would be super helpful!

supposed to remove a dat.GUI()

gui = new dat.GUI();

...

removeGui(gui);

function removeGui(gui, parent) 
{
    if(!parent) 
    {
        parent = dat.GUI.autoPlaceContainer;
    }
    parent.removeChild(gui.domElement);
}

But gives back the error: cannot call method 'removeChild' of undefined, so i am guessing that autoPlaceContainer is wrong.

The original author of this function left these notes:

where the parameters gui represents the DAT.GUI you want to remove and parent is the parent container where if you didn't specify a domElement when instantiating DAT.GUI then you don't need to pass a parent.

like image 757
user2287949 Avatar asked May 01 '13 15:05

user2287949


1 Answers

If you want to remove the entire dat.GUI element along with all of its listeners, you can use gui.destroy()

If you want to reset the dat.GUI's values, you can use datGUI.__controllers.forEach(controller => controller.setValue(controller.initialValue));

like image 152
Zach Saucier Avatar answered Oct 11 '22 14:10

Zach Saucier