Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_convert.cc
| Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| static void make_edges_mdata_extend(Mesh &mesh) | static void make_edges_mdata_extend(Mesh &mesh) | ||||
| { | { | ||||
| int totedge = mesh.totedge; | int totedge = mesh.totedge; | ||||
| const MPoly *mp; | const MPoly *mp; | ||||
| int i; | int i; | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| MutableSpan<MLoop> loops = mesh.loops_for_write(); | const Span<int> corner_verts = mesh.corner_verts(); | ||||
| MutableSpan<int> corner_edges = mesh.corner_edges_for_write(); | |||||
| const int eh_reserve = max_ii(totedge, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(mesh.totpoly)); | const int eh_reserve = max_ii(totedge, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(mesh.totpoly)); | ||||
| EdgeHash *eh = BLI_edgehash_new_ex(__func__, eh_reserve); | EdgeHash *eh = BLI_edgehash_new_ex(__func__, eh_reserve); | ||||
| for (const MPoly &poly : polys) { | for (const MPoly &poly : polys) { | ||||
| BKE_mesh_poly_edgehash_insert(eh, &poly, &loops[poly.loopstart]); | BKE_mesh_poly_edgehash_insert(eh, &poly, corner_verts.data()); | ||||
| } | } | ||||
| const int totedge_new = BLI_edgehash_len(eh); | const int totedge_new = BLI_edgehash_len(eh); | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| /* ensure that there's no overlap! */ | /* ensure that there's no overlap! */ | ||||
| if (totedge_new) { | if (totedge_new) { | ||||
| for (const MEdge &edge : mesh.edges()) { | for (const MEdge &edge : mesh.edges()) { | ||||
| Show All 17 Lines | for (ehi = BLI_edgehashIterator_new(eh); BLI_edgehashIterator_isDone(ehi) == false; | ||||
| BLI_edgehashIterator_getKey(ehi, &medge->v1, &medge->v2); | BLI_edgehashIterator_getKey(ehi, &medge->v1, &medge->v2); | ||||
| BLI_edgehashIterator_setValue(ehi, POINTER_FROM_UINT(e_index)); | BLI_edgehashIterator_setValue(ehi, POINTER_FROM_UINT(e_index)); | ||||
| medge->flag = ME_EDGEDRAW; | medge->flag = ME_EDGEDRAW; | ||||
| } | } | ||||
| BLI_edgehashIterator_free(ehi); | BLI_edgehashIterator_free(ehi); | ||||
| for (i = 0, mp = polys.data(); i < mesh.totpoly; i++, mp++) { | for (i = 0, mp = polys.data(); i < mesh.totpoly; i++, mp++) { | ||||
| MLoop *l = &loops[mp->loopstart]; | int corner = mp->loopstart; | ||||
| MLoop *l_prev = (l + (mp->totloop - 1)); | int corner_prev = mp->loopstart + (mp->totloop - 1); | ||||
| int j; | int j; | ||||
| for (j = 0; j < mp->totloop; j++, l++) { | for (j = 0; j < mp->totloop; j++, corner++) { | ||||
| /* lookup hashed edge index */ | /* lookup hashed edge index */ | ||||
| l_prev->e = POINTER_AS_UINT(BLI_edgehash_lookup(eh, l_prev->v, l->v)); | corner_edges[corner_prev] = POINTER_AS_UINT( | ||||
| l_prev = l; | BLI_edgehash_lookup(eh, corner_verts[corner_prev], corner_verts[corner])); | ||||
| corner_prev = corner; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BLI_edgehash_free(eh, nullptr); | BLI_edgehash_free(eh, nullptr); | ||||
| } | } | ||||
| static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispbase) | static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispbase) | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispbase) | ||||
| if (totvert == 0) { | if (totvert == 0) { | ||||
| return BKE_mesh_new_nomain(0, 0, 0, 0, 0); | return BKE_mesh_new_nomain(0, 0, 0, 0, 0); | ||||
| } | } | ||||
| Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly); | Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly); | ||||
| MutableSpan<float3> positions = mesh->vert_positions_for_write(); | MutableSpan<float3> positions = mesh->vert_positions_for_write(); | ||||
| MutableSpan<MEdge> edges = mesh->edges_for_write(); | MutableSpan<MEdge> edges = mesh->edges_for_write(); | ||||
| MutableSpan<MPoly> polys = mesh->polys_for_write(); | MutableSpan<MPoly> polys = mesh->polys_for_write(); | ||||
| MutableSpan<MLoop> loops = mesh->loops_for_write(); | MutableSpan<int> corner_verts = mesh->corner_verts_for_write(); | ||||
| MutableAttributeAccessor attributes = mesh->attributes_for_write(); | MutableAttributeAccessor attributes = mesh->attributes_for_write(); | ||||
| SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>( | SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>( | ||||
| "material_index", ATTR_DOMAIN_FACE); | "material_index", ATTR_DOMAIN_FACE); | ||||
| blender::float2 *mloopuv = static_cast<blender::float2 *>(CustomData_add_layer_named( | blender::float2 *mloopuv = static_cast<blender::float2 *>(CustomData_add_layer_named( | ||||
| &mesh->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap"))); | &mesh->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap"))); | ||||
| int dst_vert = 0; | int dst_vert = 0; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | else if (dl->type == DL_INDEX3) { | ||||
| copy_v3_v3(positions[dst_vert], data); | copy_v3_v3(positions[dst_vert], data); | ||||
| data += 3; | data += 3; | ||||
| dst_vert++; | dst_vert++; | ||||
| } | } | ||||
| a = dl->parts; | a = dl->parts; | ||||
| const int *index = dl->index; | const int *index = dl->index; | ||||
| while (a--) { | while (a--) { | ||||
| loops[dst_loop + 0].v = startvert + index[0]; | corner_verts[dst_loop + 0] = startvert + index[0]; | ||||
| loops[dst_loop + 1].v = startvert + index[2]; | corner_verts[dst_loop + 1] = startvert + index[2]; | ||||
| loops[dst_loop + 2].v = startvert + index[1]; | corner_verts[dst_loop + 2] = startvert + index[1]; | ||||
| polys[dst_poly].loopstart = dst_loop; | polys[dst_poly].loopstart = dst_loop; | ||||
| polys[dst_poly].totloop = 3; | polys[dst_poly].totloop = 3; | ||||
| material_indices.span[dst_poly] = dl->col; | material_indices.span[dst_poly] = dl->col; | ||||
| if (mloopuv) { | if (mloopuv) { | ||||
| for (int i = 0; i < 3; i++, mloopuv++) { | for (int i = 0; i < 3; i++, mloopuv++) { | ||||
| (*mloopuv)[0] = (loops[dst_loop + i].v - startvert) / float(dl->nr - 1); | (*mloopuv)[0] = (corner_verts[dst_loop + i] - startvert) / float(dl->nr - 1); | ||||
| (*mloopuv)[1] = 0.0f; | (*mloopuv)[1] = 0.0f; | ||||
| } | } | ||||
| } | } | ||||
| if (is_smooth) { | if (is_smooth) { | ||||
| polys[dst_poly].flag |= ME_SMOOTH; | polys[dst_poly].flag |= ME_SMOOTH; | ||||
| } | } | ||||
| dst_poly++; | dst_poly++; | ||||
| Show All 33 Lines | else if (dl->type == DL_SURF) { | ||||
| b = 1; | b = 1; | ||||
| } | } | ||||
| if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) { | if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) { | ||||
| p3 -= dl->parts * dl->nr; | p3 -= dl->parts * dl->nr; | ||||
| p4 -= dl->parts * dl->nr; | p4 -= dl->parts * dl->nr; | ||||
| } | } | ||||
| for (; b < dl->nr; b++) { | for (; b < dl->nr; b++) { | ||||
| loops[dst_loop + 0].v = p1; | corner_verts[dst_loop + 0] = p1; | ||||
| loops[dst_loop + 1].v = p3; | corner_verts[dst_loop + 1] = p3; | ||||
| loops[dst_loop + 2].v = p4; | corner_verts[dst_loop + 2] = p4; | ||||
| loops[dst_loop + 3].v = p2; | corner_verts[dst_loop + 3] = p2; | ||||
| polys[dst_poly].loopstart = dst_loop; | polys[dst_poly].loopstart = dst_loop; | ||||
| polys[dst_poly].totloop = 4; | polys[dst_poly].totloop = 4; | ||||
| material_indices.span[dst_poly] = dl->col; | material_indices.span[dst_poly] = dl->col; | ||||
| if (mloopuv) { | if (mloopuv) { | ||||
| int orco_sizeu = dl->nr - 1; | int orco_sizeu = dl->nr - 1; | ||||
| int orco_sizev = dl->parts - 1; | int orco_sizev = dl->parts - 1; | ||||
| /* exception as handled in convertblender.c too */ | /* exception as handled in convertblender.c too */ | ||||
| if (dl->flag & DL_CYCL_U) { | if (dl->flag & DL_CYCL_U) { | ||||
| orco_sizeu++; | orco_sizeu++; | ||||
| if (dl->flag & DL_CYCL_V) { | if (dl->flag & DL_CYCL_V) { | ||||
| orco_sizev++; | orco_sizev++; | ||||
| } | } | ||||
| } | } | ||||
| else if (dl->flag & DL_CYCL_V) { | else if (dl->flag & DL_CYCL_V) { | ||||
| orco_sizev++; | orco_sizev++; | ||||
| } | } | ||||
| for (int i = 0; i < 4; i++, mloopuv++) { | for (int i = 0; i < 4; i++, mloopuv++) { | ||||
| /* find uv based on vertex index into grid array */ | /* find uv based on vertex index into grid array */ | ||||
| int v = loops[dst_loop + i].v - startvert; | int v = corner_verts[dst_loop + i] - startvert; | ||||
| (*mloopuv)[0] = (v / dl->nr) / float(orco_sizev); | (*mloopuv)[0] = (v / dl->nr) / float(orco_sizev); | ||||
| (*mloopuv)[1] = (v % dl->nr) / float(orco_sizeu); | (*mloopuv)[1] = (v % dl->nr) / float(orco_sizeu); | ||||
| /* cyclic correction */ | /* cyclic correction */ | ||||
| if ((ELEM(i, 1, 2)) && (*mloopuv)[0] == 0.0f) { | if ((ELEM(i, 1, 2)) && (*mloopuv)[0] == 0.0f) { | ||||
| (*mloopuv)[0] = 1.0f; | (*mloopuv)[0] = 1.0f; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | static void appendPolyLineVert(ListBase *lb, uint index) | ||||
| BLI_addtail(lb, vl); | BLI_addtail(lb, vl); | ||||
| } | } | ||||
| void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int edge_users_test) | void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int edge_users_test) | ||||
| { | { | ||||
| const Span<float3> positions = me->vert_positions(); | const Span<float3> positions = me->vert_positions(); | ||||
| const Span<MEdge> mesh_edges = me->edges(); | const Span<MEdge> mesh_edges = me->edges(); | ||||
| const Span<MPoly> polys = me->polys(); | const Span<MPoly> polys = me->polys(); | ||||
| const Span<MLoop> loops = me->loops(); | const Span<int> corner_edges = me->corner_edges(); | ||||
| const MEdge *med; | const MEdge *med; | ||||
| const MPoly *mp; | const MPoly *mp; | ||||
| int medge_len = me->totedge; | int medge_len = me->totedge; | ||||
| int mpoly_len = me->totpoly; | int mpoly_len = me->totpoly; | ||||
| int totedges = 0; | int totedges = 0; | ||||
| int i; | int i; | ||||
| /* only to detect edge polylines */ | /* only to detect edge polylines */ | ||||
| int *edge_users; | int *edge_users; | ||||
| ListBase edges = {nullptr, nullptr}; | ListBase edges = {nullptr, nullptr}; | ||||
| /* get boundary edges */ | /* get boundary edges */ | ||||
| edge_users = (int *)MEM_calloc_arrayN(medge_len, sizeof(int), __func__); | edge_users = (int *)MEM_calloc_arrayN(medge_len, sizeof(int), __func__); | ||||
| for (i = 0, mp = polys.data(); i < mpoly_len; i++, mp++) { | for (i = 0, mp = polys.data(); i < mpoly_len; i++, mp++) { | ||||
| const MLoop *ml = &loops[mp->loopstart]; | |||||
| int j; | int j; | ||||
| for (j = 0; j < mp->totloop; j++, ml++) { | for (j = 0; j < mp->totloop; j++) { | ||||
| edge_users[ml->e]++; | edge_users[corner_edges[mp->loopstart + j]]++; | ||||
| } | } | ||||
| } | } | ||||
| /* create edges from all faces (so as to find edges not in any faces) */ | /* create edges from all faces (so as to find edges not in any faces) */ | ||||
| med = mesh_edges.data(); | med = mesh_edges.data(); | ||||
| for (i = 0; i < medge_len; i++, med++) { | for (i = 0; i < medge_len; i++, med++) { | ||||
| if (edge_users[i] == edge_users_test) { | if (edge_users[i] == edge_users_test) { | ||||
| EdgeLink *edl = MEM_cnew<EdgeLink>("EdgeLink"); | EdgeLink *edl = MEM_cnew<EdgeLink>("EdgeLink"); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||