diff options
Diffstat (limited to 'source/blender/freestyle/intern/blender_interface')
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp | 35 | ||||
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp | 26 |
2 files changed, 30 insertions, 31 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index f82d6f6164b..1aa3f2cc54a 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -14,6 +14,8 @@ #include <sstream> +using blender::Span; + namespace Freestyle { BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) @@ -378,9 +380,12 @@ int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3 static bool testEdgeMark(Mesh *me, const FreestyleEdge *fed, const MLoopTri *lt, int i) { - MLoop *mloop = &me->mloop[lt->tri[i]]; - MLoop *mloop_next = &me->mloop[lt->tri[(i + 1) % 3]]; - MEdge *medge = &me->medge[mloop->e]; + const Span<MEdge> edges = me->edges(); + const Span<MLoop> loops = me->loops(); + + const MLoop *mloop = &loops[lt->tri[i]]; + const MLoop *mloop_next = &loops[lt->tri[(i + 1) % 3]]; + const MEdge *medge = &edges[mloop->e]; if (!ELEM(mloop_next->v, medge->v1, medge->v2)) { /* Not an edge in the original mesh before triangulation. */ @@ -394,10 +399,15 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) { char *name = ob->id.name + 2; + const Span<MVert> mesh_verts = me->vertices(); + const Span<MPoly> mesh_polys = me->polygons(); + const Span<MLoop> mesh_loops = me->loops(); + // Compute loop triangles int tottri = poly_to_tri_count(me->totpoly, me->totloop); MLoopTri *mlooptri = (MLoopTri *)MEM_malloc_arrayN(tottri, sizeof(*mlooptri), __func__); - BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, mlooptri); + BKE_mesh_recalc_looptri( + mesh_loops.data(), mesh_polys.data(), mesh_verts.data(), me->totloop, me->totpoly, mlooptri); // Compute loop normals BKE_mesh_calc_normals_split(me); @@ -408,9 +418,6 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) } // Get other mesh data - MVert *mvert = me->mvert; - MLoop *mloop = me->mloop; - MPoly *mpoly = me->mpoly; const FreestyleEdge *fed = (FreestyleEdge *)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE); const FreestyleFace *ffa = (FreestyleFace *)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE); @@ -435,9 +442,9 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) for (int a = 0; a < tottri; a++) { const MLoopTri *lt = &mlooptri[a]; - copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); - copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); - copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); + copy_v3_v3(v1, mesh_verts[mesh_loops[lt->tri[0]].v].co); + copy_v3_v3(v2, mesh_verts[mesh_loops[lt->tri[1]].v].co); + copy_v3_v3(v3, mesh_verts[mesh_loops[lt->tri[2]].v].co); mul_m4_v3(obmat, v1); mul_m4_v3(obmat, v2); @@ -506,12 +513,12 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) // by the near and far view planes. for (int a = 0; a < tottri; a++) { const MLoopTri *lt = &mlooptri[a]; - const MPoly *mp = &mpoly[lt->poly]; + const MPoly *mp = &mesh_polys[lt->poly]; Material *mat = BKE_object_material_get(ob, material_indices[lt->poly] + 1); - copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co); - copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co); - copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co); + copy_v3_v3(v1, mesh_verts[mesh_loops[lt->tri[0]].v].co); + copy_v3_v3(v2, mesh_verts[mesh_loops[lt->tri[1]].v].co); + copy_v3_v3(v3, mesh_verts[mesh_loops[lt->tri[2]].v].co); mul_m4_v3(obmat, v1); mul_m4_v3(obmat, v2); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index dd041abfd1f..0b035a08433 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -576,36 +576,28 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) mesh->totloop = group->totloop; mesh->totcol = group->materials.size(); - mesh->mvert = (MVert *)CustomData_add_layer( + MVert *vertices = (MVert *)CustomData_add_layer( &mesh->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, mesh->totvert); - mesh->medge = (MEdge *)CustomData_add_layer( + MEdge *edges = (MEdge *)CustomData_add_layer( &mesh->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, mesh->totedge); - mesh->mpoly = (MPoly *)CustomData_add_layer( + MPoly *polys = (MPoly *)CustomData_add_layer( &mesh->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, mesh->totpoly); - mesh->mloop = (MLoop *)CustomData_add_layer( + MLoop *loops = (MLoop *)CustomData_add_layer( &mesh->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, mesh->totloop); int *material_indices = (int *)CustomData_add_layer_named( &mesh->pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, mesh->totpoly, "material_index"); - MVert *vertices = mesh->mvert; - MEdge *edges = mesh->medge; - MPoly *polys = mesh->mpoly; - MLoop *loops = mesh->mloop; MLoopUV *loopsuv[2] = {nullptr}; if (hasTex) { // First UV layer - CustomData_add_layer_named( - &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, uvNames[0]); + loopsuv[0] = static_cast<MLoopUV *>(CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, uvNames[0])); CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0); - BKE_mesh_update_customdata_pointers(mesh, true); - loopsuv[0] = mesh->mloopuv; // Second UV layer - CustomData_add_layer_named( - &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, uvNames[1]); + loopsuv[1] = static_cast<MLoopUV *>(CustomData_add_layer_named( + &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, uvNames[1])); CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1); - BKE_mesh_update_customdata_pointers(mesh, true); - loopsuv[1] = mesh->mloopuv; } // colors and transparency (the latter represented by grayscale colors) @@ -613,7 +605,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) &mesh->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, mesh->totloop, "Color"); MLoopCol *transp = (MLoopCol *)CustomData_add_layer_named( &mesh->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, mesh->totloop, "Alpha"); - mesh->mloopcol = colors; + CustomData_set_layer_active(&mesh->ldata, CD_PROP_BYTE_COLOR, 0); mesh->mat = (Material **)MEM_mallocN(sizeof(Material *) * mesh->totcol, "MaterialList"); for (const auto item : group->materials.items()) { |