refresh dat.gui with new values

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

    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:

        var cubeX = folder1.add( parameters, 'x' ).min(-100).max(100).step(1).listen();
    

    you have declared parameters beforehand, e.g.

    parameters = {
        x: 0, y: 0, z: 0
    }
    

    Now you can listen to the key events or the appropriate event and change the values in the GUI like that:

    window.addEventListener('keydown', function(event) {
        if(event.keyCode == 88) { // x pressed
            parameters.x++; // GUI value changed
            cube.scale.x = parameters.x; // 3d object changed
        }
    }
    

提交回复
热议问题