| 2613 | |
| 2614 | |
| 2615 | static OptionalError<Object*> parseMaterial(const Scene& scene, const Element& element, Allocator& allocator) |
| 2616 | { |
| 2617 | MaterialImpl* material = allocator.allocate<MaterialImpl>(scene, element); |
| 2618 | const char* property_id = "P"; |
| 2619 | int property_offset = 4; |
| 2620 | const Element* prop = findChild(element, "Properties70"); |
| 2621 | if (!prop) { |
| 2622 | property_id = "Property"; |
| 2623 | property_offset = 3; |
| 2624 | prop = findChild(element, "Properties60"); |
| 2625 | } |
| 2626 | material->diffuse_color = {1, 1, 1}; |
| 2627 | if (prop) prop = prop->child; |
| 2628 | while (prop) |
| 2629 | { |
| 2630 | if (prop->id == property_id && prop->first_property) |
| 2631 | { |
| 2632 | if (prop->first_property->value == "DiffuseColor") |
| 2633 | { |
| 2634 | material->diffuse_color.r = (float)prop->getProperty(property_offset + 0)->getValue().toDouble(); |
| 2635 | material->diffuse_color.g = (float)prop->getProperty(property_offset + 1)->getValue().toDouble(); |
| 2636 | material->diffuse_color.b = (float)prop->getProperty(property_offset + 2)->getValue().toDouble(); |
| 2637 | } |
| 2638 | else if (prop->first_property->value == "SpecularColor") |
| 2639 | { |
| 2640 | material->specular_color.r = (float)prop->getProperty(property_offset + 0)->getValue().toDouble(); |
| 2641 | material->specular_color.g = (float)prop->getProperty(property_offset + 1)->getValue().toDouble(); |
| 2642 | material->specular_color.b = (float)prop->getProperty(property_offset + 2)->getValue().toDouble(); |
| 2643 | } |
| 2644 | else if (prop->first_property->value == "Shininess") |
| 2645 | { |
| 2646 | material->shininess = (float)prop->getProperty(property_offset)->getValue().toDouble(); |
| 2647 | } |
| 2648 | else if (prop->first_property->value == "ShininessExponent") |
| 2649 | { |
| 2650 | material->shininess_exponent = (float)prop->getProperty(property_offset)->getValue().toDouble(); |
| 2651 | } |
| 2652 | else if (prop->first_property->value == "ReflectionColor") |
| 2653 | { |
| 2654 | material->reflection_color.r = (float)prop->getProperty(property_offset + 0)->getValue().toDouble(); |
| 2655 | material->reflection_color.g = (float)prop->getProperty(property_offset + 1)->getValue().toDouble(); |
| 2656 | material->reflection_color.b = (float)prop->getProperty(property_offset + 2)->getValue().toDouble(); |
| 2657 | } |
| 2658 | else if (prop->first_property->value == "AmbientColor") |
| 2659 | { |
| 2660 | material->ambient_color.r = (float)prop->getProperty(property_offset + 0)->getValue().toDouble(); |
| 2661 | material->ambient_color.g = (float)prop->getProperty(property_offset + 1)->getValue().toDouble(); |
| 2662 | material->ambient_color.b = (float)prop->getProperty(property_offset + 2)->getValue().toDouble(); |
| 2663 | } |
| 2664 | else if (prop->first_property->value == "EmissiveColor") |
| 2665 | { |
| 2666 | material->emissive_color.r = (float)prop->getProperty(property_offset + 0)->getValue().toDouble(); |
| 2667 | material->emissive_color.g = (float)prop->getProperty(property_offset + 1)->getValue().toDouble(); |
| 2668 | material->emissive_color.b = (float)prop->getProperty(property_offset + 2)->getValue().toDouble(); |
| 2669 | } |
| 2670 | else if (prop->first_property->value == "ReflectionFactor") |
| 2671 | { |
| 2672 | material->reflection_factor = (float)prop->getProperty(property_offset)->getValue().toDouble(); |
no test coverage detected