From e2d3e36ca7866916363a06310af840f7978e98c2 Mon Sep 17 00:00:00 2001 From: Martijn Berger Date: Sat, 27 Jun 2015 12:05:05 +0200 Subject: Cycles standalone: add support for reading UV coordinates to the XML scene reader --- intern/cycles/app/cycles_xml.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index 3ce2d475035..edea8cd0ec4 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -906,6 +906,7 @@ static void xml_read_mesh(const XMLReadState& state, pugi::xml_node node) /* read vertices and polygons, RIB style */ vector P; + vector UV; vector 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 */ -- cgit v1.2.3