pmndrs / leva

🌋 React-first components GUI
https://leva.pmnd.rs
MIT License
4.98k stars 198 forks source link

Improve vectors min/max range initialization #141

Open RenaudRohlinger opened 3 years ago

RenaudRohlinger commented 3 years ago

At this moment the only syntax possible for the vectors range initialization is the following: { value: [0,0], x: {min: -5, max: 10 }, y: {min: -5, max: 10 } }

It would be amazing to allow the following:

Vector2: {value: [0,0], min: [-5,-5], max: [10,10]} Vector3: {value: [0,0,0], min: [-5,-5,-5], max: [10,10,10]}

dbismut commented 3 years ago

Let's say the vector[0] doesn't have a min or a max, how do you think we should handle this?

{value: [0,0], min: [-Infinity,-5], max: [Infinity,10]}
// or
{value: [0,0], min: [undefined,-5], max: [undefined,10]}
RenaudRohlinger commented 3 years ago

Actually I add more feature/security to the thing, something like :

///{value: [0,0,0], min: [-5], max: [Infinity,10]}
 if(min.length === 1 && isVec3) {
  const temp = new Array(3).fill(min[0]);
  min = temp
}

and if a whole prop is missing something like that for both min and max

if(min && !max) {

 for (i; i++; min...) {
   max[i] = Math.abs(min[i])
}