Changeset View
Changeset View
Standalone View
Standalone View
source/blender/alembic/intern/abc_customdata.cc
| Context not available. | |||||
| #include <Alembic/AbcGeom/All.h> | #include <Alembic/AbcGeom/All.h> | ||||
| #include <algorithm> | #include <algorithm> | ||||
| #include <unordered_map> | |||||
| extern "C" { | extern "C" { | ||||
| #include "DNA_customdata_types.h" | #include "DNA_customdata_types.h" | ||||
| Context not available. | |||||
| using Alembic::AbcGeom::OV2fGeomParam; | using Alembic::AbcGeom::OV2fGeomParam; | ||||
| using Alembic::AbcGeom::OC4fGeomParam; | using Alembic::AbcGeom::OC4fGeomParam; | ||||
| static inline uint64_t v2ftok(Imath::V2f v){ | |||||
| uint64_t ret; | |||||
| uint32_t* retp = (uint32_t*)&ret; | |||||
| memcpy((void*)&retp[0], (void*)&v.x, 4); | |||||
| memcpy((void*)&retp[1], (void*)&v.y, 4); | |||||
| return ret; | |||||
| } | |||||
| static void get_uvs(const CDStreamConfig &config, | static void get_uvs(const CDStreamConfig &config, | ||||
| std::vector<Imath::V2f> &uvs, | std::vector<Imath::V2f> &uvs, | ||||
| std::vector<uint32_t> &uvidx, | std::vector<uint32_t> &uvidx, | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| std::unordered_map<uint64_t, long> idx_map; | |||||
| int idx_count = 0; | |||||
| for (int i = 0; i < num_poly; ++i) { | for (int i = 0; i < num_poly; ++i) { | ||||
| MPoly ¤t_poly = polygons[i]; | MPoly ¤t_poly = polygons[i]; | ||||
| MLoopUV *loopuvpoly = mloopuv_array + current_poly.loopstart + current_poly.totloop; | MLoopUV *loopuvpoly = mloopuv_array + current_poly.loopstart + current_poly.totloop; | ||||
| Context not available. | |||||
| for (int j = 0; j < current_poly.totloop; ++j) { | for (int j = 0; j < current_poly.totloop; ++j) { | ||||
| loopuvpoly--; | loopuvpoly--; | ||||
| Imath::V2f uv(loopuvpoly->uv[0], loopuvpoly->uv[1]); | Imath::V2f uv(loopuvpoly->uv[0], loopuvpoly->uv[1]); | ||||
| uint64_t k = v2ftok(uv); | |||||
| std::vector<Imath::V2f>::iterator it = std::find(uvs.begin(), uvs.end(), uv); | std::unordered_map<uint64_t, long>::iterator it = idx_map.find(k); | ||||
| if (it == idx_map.end()){ | |||||
| if (it == uvs.end()) { | idx_map[k] = idx_count; | ||||
| uvidx.push_back(uvs.size()); | |||||
| uvs.push_back(uv); | uvs.push_back(uv); | ||||
| } | uvidx.push_back(idx_count++); | ||||
| else { | } else { | ||||
| uvidx.push_back(std::distance(uvs.begin(), it)); | uvidx.push_back(it->second); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||