You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: node-graph/gmath-nodes/src/lib.rs
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -325,6 +325,44 @@ impl TangentInverse for DVec2 {
325
325
}
326
326
}
327
327
328
+
#[node_macro::node(category("Math: Numeric"))]
329
+
fnremap<U: num_traits::float::Float>(
330
+
_:implCtx,
331
+
#[implementations(f64,f32)]value:U,
332
+
#[implementations(f64,f32)]input_min:U,
333
+
#[implementations(f64,f32)]
334
+
#[default(1.)]
335
+
input_max:U,
336
+
#[implementations(f64,f32)]output_min:U,
337
+
#[implementations(f64,f32)]
338
+
#[default(1.)]
339
+
output_max:U,
340
+
clamped:bool,
341
+
) -> U{
342
+
let input_range = input_max - input_min;
343
+
344
+
// Handle division by zero
345
+
if input_range.abs() < U::epsilon(){
346
+
return output_min;
347
+
}
348
+
349
+
let normalized = (value - input_min) / input_range;
350
+
let output_range = output_max - output_min;
351
+
352
+
let result = output_min + normalized * output_range;
353
+
354
+
if clamped {
355
+
// Handle both normal and inverted ranges, since we want to allow the user to use this node to also reverse a range.
356
+
if output_min <= output_max {
357
+
result.clamp(output_min, output_max)
358
+
}else{
359
+
result.clamp(output_max, output_min)
360
+
}
361
+
}else{
362
+
result
363
+
}
364
+
}
365
+
328
366
/// The random function (rand) converts a seed into a random number within the specified range, inclusive of the minimum and exclusive of the maximum. The minimum and maximum values are automatically swapped if they are reversed.
0 commit comments