-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
Open
Labels
Description
Description
Color classes often have methods such as lighten()
, darken()
, saturate()
, desaturate()
.
Such methods are guaranteed to result in another valid color.
three.js, on the other hand, includes some Color
methods that are more appropriate for a Vector
class, and they do not necessarily result in a valid color.
Many of these methods are not used often, it appears, but I assume there would be little support for removing them.
So in that context, it is reasonable to discuss if clamping should be added to any of the following Color
methods to ensure the color components remain in the [ 0, 1 ] range.
method | clamping | example use case |
---|---|---|
offsetHSL( h, s, l ) | calls setHSL, which clamps | used in many examples |
add( color ) | needs clamp | _color.multiply( _diffuseColor ).add( material.emissive ) |
addColors( color1, color2 ) | needs clamp | not used in the library |
addScalar( s ) | needs clamp | multiplyScalar( 0.5 ).addScalar( 0.5 ) |
sub( color ) | maxes with zero only | not used in the library |
multiply( color ) | OK, only darkens | _color.multiply( _diffuseColor ).add( material.emissive ) |
multiplyScalar( s ) | guaranteed OK if 0 < s < 1 | .multiplyScalar( 0.5 ).addScalar( 0.5 ) ) |
setScalar( scalar ) | OK if 0 < scalar < 1 | color.setScalar( 0.1 + 0.9 * Math.random() ) |
Comments requested.
Solution
Clamp to ensure valid colors are returned.
Alternatives
Do nothing, using the argument that three.js does not validate inputs.
Additional context
No response