I would like to refresh the dat.gui menu with new values. I have loaded a model and display in folder the name of the objects inside a gui folder.
How can I display the new object name when I reload a other model ?
Or it's possible to reset/clear the gui.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
My answer does not reflect your question but will be helpful for others that programmatically change values within the 3d scene and need to update the GUI controls.
When you declare:
you have declared parameters beforehand, e.g.
Now you can listen to the key events or the appropriate event and change the values in the GUI like that:
Basically, you have to set the controllers to "listen" for input when you add them, for example,
For documentation, see:
http://workshop.chromeexperiments.com/examples/gui/#9--Updating-the-Display-Automatically
For an example of this in Three.js, see:
http://stemkoski.github.io/Three.js/GUI-Controller.html
It's easy when I have read the source code of dat.gui:
https://github.com/dataarts/dat.gui/blob/master/src/dat/controllers/Controller.js#L36
As you see,
this.object = object
,this
is a controller you add, andobject
is what you need to change. Here is example code:Echt Einfach's solution didn't work for me, and Stemkoski's one is a bit wide. I finally made it with the
updateDisplay
function:http://workshop.chromeexperiments.com/examples/gui/#10--Updating-the-Display-Manually
Note that if you have the values in some folder
folder1
the call is like this:If you do not want to hard-code
folder1
, or simply want to update all folders, you can proceed as follows:Lee Stemkoski's and Echt Einfach's solutions use the .listen() method on a selected controller in the GUI.
jmmut's solution ,using .updateDisplay(), loops through ALL of the controllers in the GUI
It strikes me that both these solution types are EXPENSIVE if you only want to manually update the value of a single controller at a particular time.
You can avoid this by using the method .updateDisplay() for a SINGLE controller.
One way to do this is if you know beforehand the index[i] of the single controller. But this is rather fiddly to implement.
A better way is to reference the particular controller by name
Note: I have not included the extra code required to make this work with controllers inside folders. You can get this from the other answers.
Wrote a function to update dat.gui dropdowns with a new set of values:
Usage: