0

I'm making a small billiards game in THREE.js, and have opted to use Dat.Gui as a GUI library. I have a few small questions regarding the latter:

  • First Question: Can I make a class that returns the GUI?

Currently I have a mygui.js file where I put the code of the gui (the example code[1], let's say), and I include that in mygame.html before the main.js. However, all other objects (table, balls, lights, etc) are classes and I'd like to do that too with the GUI. When I place everything inside a

class MyGUI {
    constructor() {
        //javascript part of the example here
        return gui;
    }
}

and then call in main.js

var mygui = new MyGUI();

the GUI isn't showing up, but when I don't include the class and the line in main.js, it works. I have downloaded dat.gui.min.js and included it in the html.

  • Second Question: I want to change variables now and then based on when I call the gui's change function, but how would I go about that without classes (should that not work)?

  • Third Question: I want to use the GUI, only to display values. Users are not supposed to change it. Can I make the GUI read-only? (to be clear: changing the values in the GUI will not change gameplay, they're just textual representations of the state of the game)

  • Fourth Question: I want to remove the top part of the GUI (where you can load/save presets or something). How do I do that?

Diamundo
  • 148
  • 11
  • Have you had a look at [this](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage)? – prisoner849 Feb 28 '18 at 11:59
  • I had, but at first glance it didn't answer my questions. After a second look, I realise that the cleaner answer to question #2 than `gui.__controllers[i].setValue( newVal )` is at your link, page 9. Thanks! – Diamundo Feb 28 '18 at 12:03

1 Answers1

0

Progressive insights:

  1. As linked by @prisoner849: Page 9 of the example/tutorial. gui.add(param, 'theSetting').listen(); function updateTheSetting(newVal){ param.theSetting = newVal; }

When param.theSetting is updated, and the added param listen()s to it, a change in the param.theSetting will automatically update the GUI.

  1. Don't use gui.remember( someParameters ) and the save part will dissapear.

Diamundo
  • 148
  • 11