AI and some googling told me that the color space in a XmlXCAF file is sRGB. But it seems not align with what I observed.
I used CadQuery-OCP to create a simple box and saved it to a XmlXCAF file with a name and a color assigned to the box.
In the resulting file, I got the following. The only color in the file is #A70B0BFF which is the same as the linear RGB from the above python code. Does it mean the XmlXCAF file saves the color in linear RGB?
The only color in the file is #A70B0BFF which is the same as the linear RGB from the above python code. Does it mean the XmlXCAF file saves the color in linear RGB?
Actually, it neither. The line you've spotted in XML file:
is only a Name tag, it isn't used by persistence for a color value and holds an arbitrary text.
The fact that you see linear RGB in hex here is a bug of name generator XCAFDoc_ColorTool::AddColor:
https://github.com/Open-Cascade-SAS/OCCT/pull/317
The actual value is stored in another tag:
<xcaf:Color id="14">30</xcaf:Color>
and it is 30, which corresponds to Quantity_NOC_BROWN3 value of enumeration Quantity_NameOfColor.
That is it, the color is XmlXCAF color is stored as an enumerated value (just an artifact of a past).
You may also notice that color transparency is lost within XmlXCAF format.
It would be nice improving XmlXCAF in this regard, but this format is rarely used in practice.
Notice that in BinXCAF the color is stored as linear RGB values as floating point numbers - I would suggest using this format, when possible.
02Author
Thanks for the clarification. I will certainly look at BinXCAF.