Customize min and max values in dat.gui with Three JS

629 Views Asked by At

I am using dat.gui on MorphTargets . By Default GUI takes 0 as min and 1 as max, I want them to be displays as my respective values for e.g.: 0 as 10 and 1 as 20.

How can I do that ?

1

There are 1 best solutions below

0
On BEST ANSWER

You can calculate that value in .onChange like that:

<script type="module">
import {GUI} from "https://threejs.org/examples/jsm/libs/dat.gui.module.js";

let gui = new GUI();

let params = {
    value: 10
}
let influences = {
    value: 0
}

gui.add(params, "value", 10, 20).onChange(val => {
  influences.value = range01(val, 10, 20);
  console.log(influences.value);
})

function range01(val, min, max){
  return (val - min) / (max - min);
}

</script>