Commit: 30874d84bc32d65495349a295bb742d207337dad
Author: Lukas Stockner
Date:   Thu May 19 11:35:50 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB30874d84bc32d65495349a295bb742d207337dad

Cycles: Add XML parsing of MappingNodes to Cycles Standalone

Reviewers: dingto, sergey

Differential Revision: https://developer.blender.org/D2009

===================================================================

M       intern/cycles/app/cycles_xml.cpp
M       intern/cycles/render/nodes.cpp
M       intern/cycles/render/nodes.h

===================================================================

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 6b0ef32..ab081a7 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -230,6 +230,24 @@ static bool xml_read_enum(ustring *str, ShaderEnum& enm, 
pugi::xml_node node, co
        return false;
 }
 
+static bool xml_read_enum_value(int *value, ShaderEnum& enm, pugi::xml_node 
node, const char *name)
+{
+       pugi::xml_attribute attr = node.attribute(name);
+
+       if(attr) {
+               ustring ustr(attr.value());
+
+               if(enm.exists(ustr)) {
+                       *value = enm[ustr];
+                       return true;
+               }
+               else
+                       fprintf(stderr, "Unknown value \"%s\" for attribute 
\"%s\".\n", ustr.c_str(), name);
+       }
+
+       return false;
+}
+
 static ShaderSocketType xml_read_socket_type(pugi::xml_node node, const char 
*name)
 {
        pugi::xml_attribute attr = node.attribute(name);
@@ -529,7 +547,24 @@ static void xml_read_shader_graph(const XMLReadState& 
state, Shader *shader, pug
                        snode = bump;
                }
                else if(string_iequals(node.name(), "mapping")) {
-                       snode = new MappingNode();
+                       MappingNode *map = new MappingNode();
+
+                       TextureMapping *texmap = &map->tex_mapping;
+                       xml_read_enum_value((int*) &texmap->type, 
TextureMapping::type_enum, node, "type");
+                       xml_read_enum_value((int*) &texmap->projection, 
TextureMapping::projection_enum, node, "projection");
+                       xml_read_enum_value((int*) &texmap->x_mapping, 
TextureMapping::mapping_enum, node, "x_mapping");
+                       xml_read_enum_value((int*) &texmap->y_mapping, 
TextureMapping::mapping_enum, node, "y_mapping");
+                       xml_read_enum_value((int*) &texmap->z_mapping, 
TextureMapping::mapping_enum, node, "z_mapping");
+                       xml_read_bool(&texmap->use_minmax, node, "use_minmax");
+                       if(texmap->use_minmax) {
+                               xml_read_float3(&texmap->min, node, "min");
+                               xml_read_float3(&texmap->max, node, "max");
+                       }
+                       xml_read_float3(&texmap->translation, node, 
"translation");
+                       xml_read_float3(&texmap->rotation, node, "rotation");
+                       xml_read_float3(&texmap->scale, node, "scale");
+
+                       snode = map;
                }
                else if(string_iequals(node.name(), "anisotropic_bsdf")) {
                        AnisotropicBsdfNode *aniso = new AnisotropicBsdfNode();
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 194723e..b14363d 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -30,6 +30,46 @@ CCL_NAMESPACE_BEGIN
 
 /* Texture Mapping */
 
+static ShaderEnum texture_mapping_type_init()
+{
+       ShaderEnum enm;
+
+       enm.insert("Point", TextureMapping::POINT);
+       enm.insert("Texture", TextureMapping::TEXTURE);
+       enm.insert("Vector", TextureMapping::VECTOR);
+       enm.insert("Normal", TextureMapping::NORMAL);
+
+       return enm;
+}
+
+static ShaderEnum texture_mapping_mapping_init()
+{
+       ShaderEnum enm;
+
+       enm.insert("None", TextureMapping::NONE);
+       enm.insert("X", TextureMapping::X);
+       enm.insert("Y", TextureMapping::Y);
+       enm.insert("Z", TextureMapping::Z);
+
+       return enm;
+}
+
+static ShaderEnum texture_mapping_projection_init()
+{
+       ShaderEnum enm;
+
+       enm.insert("Flat", TextureMapping::FLAT);
+       enm.insert("Cube", TextureMapping::CUBE);
+       enm.insert("Tube", TextureMapping::TUBE);
+       enm.insert("Sphere", TextureMapping::SPHERE);
+
+       return enm;
+}
+
+ShaderEnum TextureMapping::type_enum = texture_mapping_type_init();
+ShaderEnum TextureMapping::mapping_enum = texture_mapping_mapping_init();
+ShaderEnum TextureMapping::projection_enum = texture_mapping_projection_init();
+
 TextureMapping::TextureMapping()
 {
        translation = make_float3(0.0f, 0.0f, 0.0f);
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 8d3e2a5..40fda070 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -49,12 +49,15 @@ public:
 
        enum Type { POINT = 0, TEXTURE = 1, VECTOR = 2, NORMAL = 3 };
        Type type;
+       static ShaderEnum type_enum;
 
        enum Mapping { NONE = 0, X = 1, Y = 2, Z = 3 };
        Mapping x_mapping, y_mapping, z_mapping;
+       static ShaderEnum mapping_enum;
 
        enum Projection { FLAT, CUBE, TUBE, SPHERE };
        Projection projection;
+       static ShaderEnum projection_enum;
 
        bool equals(const TextureMapping& other) {
                return translation == other.translation &&

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to