Changeset View
Changeset View
Standalone View
Standalone View
source/blender/render/intern/texture_margin.cc
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| int w_, h_; | int w_, h_; | ||||
| float uv_offset_[2]; | float uv_offset_[2]; | ||||
| Vector<uint32_t> pixel_data_; | Vector<uint32_t> pixel_data_; | ||||
| ZSpan zspan_; | ZSpan zspan_; | ||||
| uint32_t value_to_store_; | uint32_t value_to_store_; | ||||
| char *mask_; | char *mask_; | ||||
| MPoly const *mpoly_; | MPoly const *mpoly_; | ||||
| MLoop const *mloop_; | int const *corner_edges_; | ||||
| float2 const *mloopuv_; | float2 const *mloopuv_; | ||||
| int totpoly_; | int totpoly_; | ||||
| int totloop_; | int totloop_; | ||||
| int totedge_; | int totedge_; | ||||
| public: | public: | ||||
| TextureMarginMap(size_t w, | TextureMarginMap(size_t w, | ||||
| size_t h, | size_t h, | ||||
| const float uv_offset[2], | const float uv_offset[2], | ||||
| MPoly const *mpoly, | MPoly const *mpoly, | ||||
| MLoop const *mloop, | int const *corner_edges, | ||||
| float2 const *mloopuv, | float2 const *mloopuv, | ||||
| int totpoly, | int totpoly, | ||||
| int totloop, | int totloop, | ||||
| int totedge) | int totedge) | ||||
| : w_(w), | : w_(w), | ||||
| h_(h), | h_(h), | ||||
| mpoly_(mpoly), | mpoly_(mpoly), | ||||
| mloop_(mloop), | corner_edges_(corner_edges), | ||||
| mloopuv_(mloopuv), | mloopuv_(mloopuv), | ||||
| totpoly_(totpoly), | totpoly_(totpoly), | ||||
| totloop_(totloop), | totloop_(totloop), | ||||
| totedge_(totedge) | totedge_(totedge) | ||||
| { | { | ||||
| copy_v2_v2(uv_offset_, uv_offset); | copy_v2_v2(uv_offset_, uv_offset); | ||||
| pixel_data_.resize(w_ * h_, 0xFFFFFFFF); | pixel_data_.resize(w_ * h_, 0xFFFFFFFF); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| totloop_); | totloop_); | ||||
| loop_adjacency_map_.resize(totloop_, -1); | loop_adjacency_map_.resize(totloop_, -1); | ||||
| Vector<int> tmpmap; | Vector<int> tmpmap; | ||||
| tmpmap.resize(totedge_, -1); | tmpmap.resize(totedge_, -1); | ||||
| for (size_t i = 0; i < totloop_; i++) { | for (size_t i = 0; i < totloop_; i++) { | ||||
| int edge = mloop_[i].e; | int edge = corner_edges_[i]; | ||||
| if (tmpmap[edge] == -1) { | if (tmpmap[edge] == -1) { | ||||
| loop_adjacency_map_[i] = -1; | loop_adjacency_map_[i] = -1; | ||||
| tmpmap[edge] = i; | tmpmap[edge] = i; | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(tmpmap[edge] >= 0); | BLI_assert(tmpmap[edge] >= 0); | ||||
| loop_adjacency_map_[i] = tmpmap[edge]; | loop_adjacency_map_[i] = tmpmap[edge]; | ||||
| loop_adjacency_map_[tmpmap[edge]] = i; | loop_adjacency_map_[tmpmap[edge]] = i; | ||||
| ▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | |||||
| const int margin, | const int margin, | ||||
| const Mesh *me, | const Mesh *me, | ||||
| DerivedMesh *dm, | DerivedMesh *dm, | ||||
| char const *uv_layer, | char const *uv_layer, | ||||
| const float uv_offset[2]) | const float uv_offset[2]) | ||||
| { | { | ||||
| const MPoly *mpoly; | const MPoly *mpoly; | ||||
| const MLoop *mloop; | const int *corner_edges; | ||||
| const float2 *mloopuv; | const float2 *mloopuv; | ||||
| int totpoly, totloop, totedge; | int totpoly, totloop, totedge; | ||||
| int tottri; | int tottri; | ||||
| const MLoopTri *looptri; | const MLoopTri *looptri; | ||||
| MLoopTri *looptri_mem = nullptr; | MLoopTri *looptri_mem = nullptr; | ||||
| if (me) { | if (me) { | ||||
| BLI_assert(dm == nullptr); | BLI_assert(dm == nullptr); | ||||
| totpoly = me->totpoly; | totpoly = me->totpoly; | ||||
| totloop = me->totloop; | totloop = me->totloop; | ||||
| totedge = me->totedge; | totedge = me->totedge; | ||||
| mpoly = me->polys().data(); | mpoly = me->polys().data(); | ||||
| mloop = me->loops().data(); | corner_edges = me->corner_edges().data(); | ||||
| if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) { | if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) { | ||||
| mloopuv = static_cast<const float2 *>(CustomData_get_layer(&me->ldata, CD_PROP_FLOAT2)); | mloopuv = static_cast<const float2 *>(CustomData_get_layer(&me->ldata, CD_PROP_FLOAT2)); | ||||
| } | } | ||||
| else { | else { | ||||
| int uv_id = CustomData_get_named_layer(&me->ldata, CD_PROP_FLOAT2, uv_layer); | int uv_id = CustomData_get_named_layer(&me->ldata, CD_PROP_FLOAT2, uv_layer); | ||||
| mloopuv = static_cast<const float2 *>( | mloopuv = static_cast<const float2 *>( | ||||
| CustomData_get_layer_n(&me->ldata, CD_PROP_FLOAT2, uv_id)); | CustomData_get_layer_n(&me->ldata, CD_PROP_FLOAT2, uv_id)); | ||||
| } | } | ||||
| tottri = poly_to_tri_count(me->totpoly, me->totloop); | tottri = poly_to_tri_count(me->totpoly, me->totloop); | ||||
| looptri_mem = static_cast<MLoopTri *>(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); | looptri_mem = static_cast<MLoopTri *>(MEM_mallocN(sizeof(*looptri) * tottri, __func__)); | ||||
| BKE_mesh_recalc_looptri(mloop, | BKE_mesh_recalc_looptri(me->corner_verts().data(), | ||||
| mpoly, | mpoly, | ||||
| reinterpret_cast<const float(*)[3]>(me->vert_positions().data()), | reinterpret_cast<const float(*)[3]>(me->vert_positions().data()), | ||||
| me->totloop, | me->totloop, | ||||
| me->totpoly, | me->totpoly, | ||||
| looptri_mem); | looptri_mem); | ||||
| looptri = looptri_mem; | looptri = looptri_mem; | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(dm != nullptr); | BLI_assert(dm != nullptr); | ||||
| BLI_assert(me == nullptr); | BLI_assert(me == nullptr); | ||||
| totpoly = dm->getNumPolys(dm); | totpoly = dm->getNumPolys(dm); | ||||
| totedge = dm->getNumEdges(dm); | totedge = dm->getNumEdges(dm); | ||||
| totloop = dm->getNumLoops(dm); | totloop = dm->getNumLoops(dm); | ||||
| mpoly = dm->getPolyArray(dm); | mpoly = dm->getPolyArray(dm); | ||||
| mloop = dm->getLoopArray(dm); | corner_edges = dm->getCornerEdgeArray(dm); | ||||
| mloopuv = static_cast<const float2 *>(dm->getLoopDataArray(dm, CD_PROP_FLOAT2)); | mloopuv = static_cast<const float2 *>(dm->getLoopDataArray(dm, CD_PROP_FLOAT2)); | ||||
| looptri = dm->getLoopTriArray(dm); | looptri = dm->getLoopTriArray(dm); | ||||
| tottri = dm->getNumLoopTri(dm); | tottri = dm->getNumLoopTri(dm); | ||||
| } | } | ||||
| TextureMarginMap map( | TextureMarginMap map( | ||||
| ibuf->x, ibuf->y, uv_offset, mpoly, mloop, mloopuv, totpoly, totloop, totedge); | ibuf->x, ibuf->y, uv_offset, mpoly, corner_edges, mloopuv, totpoly, totloop, totedge); | ||||
| bool draw_new_mask = false; | bool draw_new_mask = false; | ||||
| /* Now the map contains 3 sorts of values: 0xFFFFFFFF for empty pixels, `0x80000000 + polyindex` | /* Now the map contains 3 sorts of values: 0xFFFFFFFF for empty pixels, `0x80000000 + polyindex` | ||||
| * for margin pixels, just `polyindex` for poly pixels. */ | * for margin pixels, just `polyindex` for poly pixels. */ | ||||
| if (mask) { | if (mask) { | ||||
| mask = (char *)MEM_dupallocN(mask); | mask = (char *)MEM_dupallocN(mask); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines | |||||