Cycles standalone: add support for reading UV coordinates to the XML scene reader
authorMartijn Berger <martijn.berger@gmail.com>
Sat, 27 Jun 2015 10:05:05 +0000 (12:05 +0200)
committerMartijn Berger <martijn.berger@gmail.com>
Sat, 27 Jun 2015 10:05:05 +0000 (12:05 +0200)
intern/cycles/app/cycles_xml.cpp

index 3ce2d4750359731bc02d29b2a452e974a3becc72..edea8cd0ec4f61f8d028891e06e6845ccc909955 100644 (file)
@@ -906,6 +906,7 @@ static void xml_read_mesh(const XMLReadState& state, pugi::xml_node node)
 
        /* read vertices and polygons, RIB style */
        vector<float3> P;
+       vector<float> UV;
        vector<int> verts, nverts;
 
        xml_read_float3_array(P, node, "P");
@@ -977,6 +978,31 @@ static void xml_read_mesh(const XMLReadState& state, pugi::xml_node node)
 
                        index_offset += nverts[i];
                }
+
+               if(xml_read_float_array(UV, node, "UV")) {
+                       ustring name = ustring("UVMap");
+                       Attribute *attr = mesh->attributes.add(ATTR_STD_UV, name);
+                       float3 *fdata = attr->data_float3();
+
+                       /* loop over the triangles */
+                       index_offset = 0;
+                       for(size_t i = 0; i < nverts.size(); i++) {
+                               for(int j = 0; j < nverts[i]-2; j++) {
+                                       int v0 = verts[index_offset];
+                                       int v1 = verts[index_offset + j + 1];
+                                       int v2 = verts[index_offset + j + 2];
+
+                                       assert(v0*2+1 < (int)UV.size());
+                                       assert(v1*2+1 < (int)UV.size());
+                                       assert(v2*2+1 < (int)UV.size());
+
+                                       fdata[0] = make_float3(UV[v0*2], UV[v0*2+1], 0.0);
+                                       fdata[1] = make_float3(UV[v1*2], UV[v1*2+1], 0.0);
+                                       fdata[2] = make_float3(UV[v2*2], UV[v2*2+1], 0.0);
+                                       fdata += 3;
+                               }
+                       }
+               }
        }
 
        /* temporary for test compatibility */