| 158 | } |
| 159 | |
| 160 | bool parseColor(const std::string &color, aiColor4D &diffuse) { |
| 161 | if (color.empty()) { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | if (!validateColorString(color)) { |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | if ('#' != color[0]) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | char r[3] = { color[1], color[2], '\0' }; |
| 174 | diffuse.r = static_cast<ai_real>(strtol(r, nullptr, 16)) / ai_real(255.0); |
| 175 | |
| 176 | char g[3] = { color[3], color[4], '\0' }; |
| 177 | diffuse.g = static_cast<ai_real>(strtol(g, nullptr, 16)) / ai_real(255.0); |
| 178 | |
| 179 | char b[3] = { color[5], color[6], '\0' }; |
| 180 | diffuse.b = static_cast<ai_real>(strtol(b, nullptr, 16)) / ai_real(255.0); |
| 181 | const size_t len = color.size(); |
| 182 | if (ColRGB_Len == len) { |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | char a[3] = { color[7], color[8], '\0' }; |
| 187 | diffuse.a = static_cast<ai_real>(strtol(a, nullptr, 16)) / ai_real(255.0); |
| 188 | |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | void assignDiffuseColor(XmlNode &node, aiMaterial *mat) { |
| 193 | const char *color = node.attribute(XmlTag::basematerials_displaycolor).as_string(); |
no test coverage detected