diff options
author | Martijn Berger <martijn.berger@gmail.com> | 2015-06-27 13:05:05 +0300 |
---|---|---|
committer | Martijn Berger <martijn.berger@gmail.com> | 2015-06-27 13:05:05 +0300 |
commit | e2d3e36ca7866916363a06310af840f7978e98c2 (patch) | |
tree | e95b6228c4d2f4a2a6046f312cebf474910e31a5 /intern/cycles/app | |
parent | c68322c7e5aca565454e49c23b02d0d346969e91 (diff) |
Cycles standalone: add support for reading UV coordinates to the XML scene reader
Diffstat (limited to 'intern/cycles/app')
-rw-r--r-- | intern/cycles/app/cycles_xml.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
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<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 */ |