refresh dat.gui with new values

前端 未结 8 1382
时光取名叫无心
时光取名叫无心 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:20

    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

    // AT INITIALISATION TIME
    gui1 = new dat.GUI();
    Gparameters = { x: 0, y: 0, z: 0}
    var gui1_X = gui1.add( Gparameters, 'x' ).min(0).max(200); // note no need to use the method .listen()
    
    // AT RUN TIME
    Gparameters.x++;
    gui1_X.updateDisplay()  
    

    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.

提交回复
热议问题