保存dat.gui预设以动态添加控件吗? [英] Save dat.gui presets for dynamically added controls?

查看:186
本文介绍了保存dat.gui预设以动态添加控件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将控件动态添加到dat.gui界面,但是保存设置"功能无法识别它们.

I'm dynamically adding controls to a dat.gui interface, but the "save settings" functionality doesn't recognize them.

var mygui = new dat.GUI();
mygui.remember(mygui);

// standard way of adding a control
mygui.control1 = 0.0;
var control = mygui.add(mygui, 'control1', -1, 1);

// adding controls dynamically
var myArray = ['control2', 'control3'];
var controls = [];
for (x in myArray) {
    controls[myArray[x]] = 0.0;
    var newControl = mygui.add(controls, myArray[x], -1, 1);
}

所有控件均按预期工作,但是当我单击齿轮图标时,设置JSON仅包含第一个控件或我以常规方式添加的任何其他控件:

The controls all work as expected, but when I click the gear icon, the settings JSON only contains the first control, or any other controls I add in the normal way:

{
  "preset": "Default",
  "closed": false,
  "remembered": {
    "Default": {
      "0": {
        "control1": 0.5,
      }
    }
  },
  "folders": {}
}

我认为我在某种程度上混淆了牢记()功能,有什么想法吗?

I assume I'm confusing the remember() functionality somehow, any ideas?

推荐答案

for循环中的行应为:

The lines in the for loop should be:

mygui[myArray[x]] = 0.0;
var newControl = mygui2.add(mygui, myArray[x], -1, 1);

add函数的第一个参数执行两个功能:它都是第二个参数的 source (要添加的控件的名称,在这种情况下为myArray [x ]),还有目的地.您可以在任意位置存储控件名称,但是如果第一个参数不是gui,则remember()函数将不知道控件,也不会将其添加到gui的__rememberedObjects属性中或将其保存.在JSON对象中.

The first parameter of the add function performs two functions: it is both the source of the second parameter (the name of the control to be added, which in this case is myArray[x]) but also the destination. You can store the control names wherever you like, but if the first parameter isn't the gui, the remember() function won't know about the controls, and they won't be added to the gui's __rememberedObjects attribute or saved in the JSON object.

这篇关于保存dat.gui预设以动态添加控件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆