Does saving parameters with dat.gui seem violated?

There seems to be a problem with saving the parameters in dat.gui, or am I missing something really obvious.

The problem occurs when you click on the gear icon, which should open a pop-up window with JSON saved. Also, saving to local storage does not work for me. Here are two JSFiddles:

The sample that they have on the Internet works fine (see comment on the link). But they minimize all their code examples, including lib itself. Therefore, I can’t even decide, even if they use the latest build.

Any help would be greatly appreciated.

+4
source share
2 answers

I made a mistake in the call gui.remember(obj);and gui.add(obj, 'x');in the wrong order.

So this solution:

var obj = { x: 5 };
var gui = new dat.GUI();
gui.remember(obj);
gui.add(obj, 'x');

What happens is that dat.gui makes the internal map of objects remember when the function is called gui.add(). This map is gui.__rememberedObjectIndecesToControllers[]used in the internal function getCurrentPreset()when storing values.

, gui.__rememberedObjects[], .

, - , , gui.__rememberedObjectIndecesToControllers[], undefined.

http://workshop.chromeexperiments.com/examples/gui/#5--Saving-Values , :

var fizzyText = new FizzyText();
var gui = new dat.GUI();

gui.remember(fizzyText);

// Add controllers ...
+4

-. , .

x, , . , , , , , .

FizzyText.

, , dat.gui, x , :

var gui = new dat.GUI({load:
{
  "preset": "Default",
  "closed": false,
  "remembered": {
    "Default": {
      "0": {"x": 8}
    }
  },
  "folders": {}
}
});

, , , .

+1

Source: https://habr.com/ru/post/1534016/


All Articles