refresh dat.gui with new values

前端 未结 8 1384
时光取名叫无心
时光取名叫无心 2021-01-31 19:55

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

相关标签:
8条回答
  • 2021-01-31 20:22

    Basically, you have to set the controllers to "listen" for input when you add them, for example,

    gui = new dat.GUI();
    var guiX = gui.add( parameters, 'x' ).min(0).max(200).listen();
    

    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

    0 讨论(0)
  • 2021-01-31 20:30

    Wrote a function to update dat.gui dropdowns with a new set of values:

    function updateDatDropdown(target, list){   
        innerHTMLStr = "";
        if(list.constructor.name == 'Array'){
            for(var i=0; i<list.length; i++){
                var str = "<option value='" + list[i] + "'>" + list[i] + "</option>";
                innerHTMLStr += str;        
            }
        }
    
        if(list.constructor.name == 'Object'){
            for(var key in list){
                var str = "<option value='" + list[key] + "'>" + key + "</option>";
                innerHTMLStr += str;
            }
        }
        if (innerHTMLStr != "") target.domElement.children[0].innerHTML = innerHTMLStr;
    }
    

    Usage:

    myDropdown = gui.add(MyObject, 'myVariable', ['one','two','three']);
    updateDatDropdown(myDropdown , ['A','B','C']);
    
    // Also accepts named values
    
    updateDatDropdown(myDropdown , {'A':1,'B':2,'C':3});
    
    0 讨论(0)
提交回复
热议问题