In previous versions of the C3D Modeler kernel, the color of the body and its child topological entities (faces, edges, vertices) was stored in the MbColor attribute. This attribute uses the four-component RGBA color representation. However, 3D applications use more properties to render objects. If some of them are not available, default values are used instead. In some cases, this results in different colors when the same model is displayed in different viewers.
To preserve all the properties needed for visualization, only a MbVisual attribute will be used. It contains detailed information about each visualization component:
- The ambient color is represented by its RED, GREEN, and BLUE components, and the ambient color coefficient in the 0.0…1.0 range (or 0…255 in the uint8 data type)
- The diffuse reflectance color is represented by its RED, GREEN, and BLUE components, and the diffuse reflectance coefficient in the 0.0…1.0 range (or 0…255 in the uint8 data type)
- The specular color is represented by its RED, GREEN, and BLUE components, and the specular reflectance coefficient in the 0.0…1.0 range (or 0…255 in the uint8 data type)
- The emission color is represented by its RED, GREEN, and BLUE components, and the luminance coefficient in the 0.0…1.0 range (or 0…255 in the uint8 data type)
- shininess in the 0…128 range (uint8 data type)
- opacity in the 0…128 range (uint8 data type)
- specular reflectance 0…128 range (uint8 data type)
The data type of values 1-4 is MbRGBA. The RGB fields contain the color components, and the alpha field stores the utilization factor.
The C3D kernel code has been modified to accommodate changes in object color management:
- When setting the color for the body (or face, edge, vertex) with the MbAttributeContainer::SetColor (int iR, int iG, int iB) method, the MbVisual attribute is returned or created if it does not exist. The RGB color is stored in the _diffuse component, and 255 (1.0, 100%) is stored in the alpha channel.
- When we get the color with the uint32 MbAttributeContainer::GetColor() const method, it returns the MbVisual attribute. If it is not available, the default color (MB_C3DCOLOR) is returned. If the attribute is present, the color is taken from the _diffuse (RGB) component.
- When reading a file with only MbVisual values (the new version), all color attributes and blend ratios are used according to the MbVisual specification.
- When reading a file in the previous formats that contains only MbColor, a new MbVisual attribute is created, the color from MbColor is stored in the _diffuse component, and 255 (1.0, 100%) is stored in the alpha channel. The MbColor attribute is removed.
- When reading a file in the previous formats that contains MbColor and MbVisual, where each component (RGB) of MbVisual stores a blending factor (as the MbVisual attribute used to be), and MbColor stores the primary color, the following steps are performed:
- A new MbVisual attribute is created. The primary color read from MbColoris stored in all the components (_ambient, _diffuse, _specularity, and _emission).
- The MbVisual value read from the file is stored in the alpha channel of each component.
- The read MbColor and MbVisual attributes are deleted and replaced with only the new MbVisual attribute.
- When saving a C3D file in the old format, the MbColor attribute is created and populated with the color from _diffuse of the new MbVisual attribute. Another MbVisual attribute is created and populated with the factors from the alpha channels of the existing MbVisual attribute components. The MbVisual attribute that used to be in the model (the new format) is removed and the file is saved in the old format.
- The MbColor class is now deprecated and not recommended for use. Use the MbVisual attribute instead.
Maksim Kulagin
Head of QA & Support
C3D Labs