Color Functions Manual

内容表

关于

Along with the ColorSwatchData and ColorSwatchGroup types these utility functions were introduced to handle colors. The functions are defined in the lib_colorchooser.h header file.

String Conversion

These functions convert a given RGB color value to a formatted String :

// This example reads the color parameter of the given material // and prints the value as RGB and HSV.

// access MATERIAL_COLOR_COLOR parameter GeData data; if (!material-> GetParameter ( MATERIAL_COLOR_COLOR , data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

const 向量 color = data. GetVector ();
const String rgbString = ColorRGBToString (color); const String hsvString = ColorHSVToString (color); ApplicationOutput ( "Material Color: RGB " + rgbString + ", HSV " + hsvString);

Color Format Conversion

The following functions allow easy conversion of colors stored in different formats.

These functions convert float colors (0.0 ... 1.0) to 8-bit colors (0 .. 255):

These functions convert float colors (0.0 ... 1.0) to 16-bit colors (0 .. 65536):

Also, a Kelvin color temperature can be converted:

// This example calculates a RGB value from a light temperature // and applies it to the given "Light" object. const Float kelvin = 2600.0; // light bulb const 向量 rgb = ColorKelvinTemperatureToRGB (kelvin); light->SetParameter( LIGHT_COLOR , rgb, DESCFLAGS_SET::NONE );

Color Harmony

These functions are used to calculate color palettes based on the given input color.

注意
The output maxon::BaseArray contains also the original color.
// This example reads the color value from the given material. // The complementary color is calculated and applied to a new material.

// access MATERIAL_COLOR_COLOR parameter GeData data; if (!material-> GetParameter ( MATERIAL_COLOR_COLOR , data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// the original color const 向量 color = data. GetVector (); maxon::BaseArray<Vector> results;

// calculate the complementary color if (! ColorHarmonyGetComplementary (color, false , results)) return maxon::UnknownError( MAXON_SOURCE_LOCATION );

// check if the result contains both the original and complementary color if (results. GetCount () != 2) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );

// get the result color const 向量 complementaryColor = results[1];

// create new material with complementary color BaseMaterial * const newMaterial = BaseMaterial::Alloc ( Mmaterial ); if (newMaterial == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); newMaterial-> SetParameter ( MATERIAL_COLOR_COLOR , complementaryColor, DESCFLAGS_SET::NONE ); doc-> InsertMaterial (newMaterial);

延伸阅读

LIGHT_COLOR
@ LIGHT_COLOR
定义: olight.h:6
ColorHSVToString
String ColorHSVToString(const Vector &color)
Float
maxon::Float Float
定义: ge_sys_math.h:64
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::BaseArray
定义: basearray.h:366
DESCFLAGS_SET::NONE
@ NONE
None.
String
定义: c4d_string.h:38
BaseDocument::InsertMaterial
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
C4DAtom::SetParameter
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
maxon::BaseArray::GetCount
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
定义: basearray.h:527
maxon::Vec3< maxon::Float64, 1 >
ColorHarmonyGetComplementary
Bool ColorHarmonyGetComplementary(const Vector &color, Bool ryb, maxon::BaseArray< Vector > &palette)
GeData
定义: c4d_gedata.h:82
ColorKelvinTemperatureToRGB
Vector ColorKelvinTemperatureToRGB(Float kelvinDegrees, Float tint=0.0)
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
ColorRGBToString
String ColorRGBToString(const Vector &color)
Mmaterial
#define Mmaterial
Standard material.
定义: ge_prepass.h:950
BaseMaterial::Alloc
static BaseMaterial * Alloc(Int32 type)
DESCFLAGS_GET::NONE
@ NONE
None.
MATERIAL_COLOR_COLOR
@ MATERIAL_COLOR_COLOR
定义: mmaterial.h:56
BaseMaterial
定义: c4d_basematerial.h:27
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
GeData::GetVector
const Vector & GetVector(void) const
定义: c4d_gedata.h:451

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1