use*_*949 11 user-interface three.js dat.gui
我发现这个函数删除了一个gui元素,但我认为它已经过时了.到目前为止,我还没有找到任何知道如何删除gui的任何部分的人,无论是整个dat.GUI()还是只是添加到dat.GUI()的元素.第一个可能就足够了我需要的东西(只是将dat.GUI()一起移除)但是任何一个都会超级有用!
应该删除dat.GUI()
gui = new dat.GUI();
Run Code Online (Sandbox Code Playgroud)
...
removeGui(gui);
function removeGui(gui, parent)
{
if(!parent)
{
parent = dat.GUI.autoPlaceContainer;
}
parent.removeChild(gui.domElement);
}
Run Code Online (Sandbox Code Playgroud)
但是给出了错误:无法调用undefined的方法'removeChild',所以我猜测autoPlaceContainer是错误的.
这个函数的原作者留下了这些笔记:
其中参数gui表示要删除的DAT.GUI,parent是父容器,如果在实例化DAT.GUI时未指定domElement,则不需要传递父级.
小智 10
var gui = new dat.GUI();
item = gui.add(text, 'message');
Run Code Online (Sandbox Code Playgroud)
删除:
gui.remove(item);
Run Code Online (Sandbox Code Playgroud)
如果您的商品位于文件夹中,则必须执行以下操作:
folder.remove(item);
Run Code Online (Sandbox Code Playgroud)
如果要删除整个dat.GUI元素及其所有侦听器,则可以使用 gui.destroy()
如果要重置dat.GUI的值,可以使用 datGUI.__controllers.forEach(controller => controller.setValue(controller.initialValue));