diff options
author | Colin Basnett <cmbasnett@gmail.com> | 2022-09-17 03:50:37 +0300 |
---|---|---|
committer | Colin Basnett <cmbasnett@gmail.com> | 2022-09-17 03:50:37 +0300 |
commit | 564bda241a973396da51d7c3ccd9efd97d51728a (patch) | |
tree | 4d9aa4cccd82e2e606b47774afa5e1015bf14768 /source/blender/freestyle/intern | |
parent | 0fff238150d076576053c25b646f653d6e3b0edb (diff) | |
parent | 48d7ff68f0df209c77bbb081ab46fbc109fd825a (diff) |
Merge branch 'master' into feature-imformatfeature-imformat
Diffstat (limited to 'source/blender/freestyle/intern')
7 files changed, 79 insertions, 63 deletions
diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index b5ef0fba1f7..8e59b277ff3 100644 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -20,6 +20,10 @@ # include "MEM_guardedalloc.h" #endif +struct Depsgraph; +struct Render; +struct ViewLayer; + namespace Freestyle { class AppCanvas; diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index e76e74b89e4..c4a633e920e 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -8,11 +8,14 @@ #include "BLI_utildefines.h" +#include "BKE_attribute.hh" #include "BKE_global.h" #include "BKE_object.h" #include <sstream> +using blender::Span; + namespace Freestyle { BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) @@ -77,6 +80,11 @@ NodeGroup *BlenderFileLoader::Load() continue; } + /* Evaluated metaballs will appear as mesh objects in the iterator. */ + if (ob->type == OB_MBALL) { + continue; + } + Mesh *mesh = BKE_object_to_mesh(nullptr, ob, false); if (mesh) { @@ -372,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. */ @@ -388,10 +399,15 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) { char *name = ob->id.name + 2; + const Span<MVert> mesh_verts = me->verts(); + const Span<MPoly> mesh_polys = me->polys(); + 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); @@ -402,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); @@ -429,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); @@ -492,16 +505,19 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id) FrsMaterial tmpMat; + const blender::VArray<int> material_indices = me->attributes().lookup_or_default<int>( + "material_index", ATTR_DOMAIN_FACE, 0); + // We parse the vlak nodes again and import meshes while applying the clipping // 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]; - Material *mat = BKE_object_material_get(ob, mp->mat_nr + 1); + 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 979673fd736..a3085768ea3 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -32,6 +32,7 @@ #include "BKE_idprop.h" #include "BKE_layer.h" #include "BKE_lib_id.h" /* free_libblock */ +#include "BKE_main.h" #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_node.h" @@ -127,7 +128,8 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) view_layer->layflag = SCE_LAY_SOLID; // Camera - Object *object_camera = BKE_object_add(freestyle_bmain, view_layer, OB_CAMERA, nullptr); + Object *object_camera = BKE_object_add( + freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, nullptr); Camera *camera = (Camera *)object_camera->data; camera->type = CAM_ORTHO; @@ -217,12 +219,12 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, break; } } + ma->nodetree = ntree; } else { - ntree = ntreeAddTree(nullptr, "stroke_shader", "ShaderNodeTree"); + ntree = ntreeAddTreeEmbedded(nullptr, &ma->id, "stroke_shader", "ShaderNodeTree"); } - ma->nodetree = ntree; - ma->use_nodes = 1; + ma->use_nodes = true; ma->blend_method = MA_BM_HASHED; bNode *input_attr_color = nodeAddStaticNode(nullptr, ntree, SH_NODE_ATTRIBUTE); @@ -231,7 +233,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, storage = (NodeShaderAttribute *)input_attr_color->storage; BLI_strncpy(storage->name, "Color", sizeof(storage->name)); - bNode *mix_rgb_color = nodeAddStaticNode(nullptr, ntree, SH_NODE_MIX_RGB); + bNode *mix_rgb_color = nodeAddStaticNode(nullptr, ntree, SH_NODE_MIX_RGB_LEGACY); mix_rgb_color->custom1 = MA_RAMP_BLEND; // Mix mix_rgb_color->locx = 200.0f; mix_rgb_color->locy = -200.0f; @@ -245,7 +247,7 @@ Material *BlenderStrokeRenderer::GetStrokeShader(Main *bmain, storage = (NodeShaderAttribute *)input_attr_alpha->storage; BLI_strncpy(storage->name, "Alpha", sizeof(storage->name)); - bNode *mix_rgb_alpha = nodeAddStaticNode(nullptr, ntree, SH_NODE_MIX_RGB); + bNode *mix_rgb_alpha = nodeAddStaticNode(nullptr, ntree, SH_NODE_MIX_RGB_LEGACY); mix_rgb_alpha->custom1 = MA_RAMP_BLEND; // Mix mix_rgb_alpha->locx = 600.0f; mix_rgb_alpha->locy = 300.0f; @@ -575,43 +577,36 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) mesh->totloop = group->totloop; mesh->totcol = group->materials.size(); - mesh->mvert = (MVert *)CustomData_add_layer( - &mesh->vdata, CD_MVERT, CD_CALLOC, nullptr, mesh->totvert); - mesh->medge = (MEdge *)CustomData_add_layer( - &mesh->edata, CD_MEDGE, CD_CALLOC, nullptr, mesh->totedge); - mesh->mpoly = (MPoly *)CustomData_add_layer( - &mesh->pdata, CD_MPOLY, CD_CALLOC, nullptr, mesh->totpoly); - mesh->mloop = (MLoop *)CustomData_add_layer( - &mesh->ldata, CD_MLOOP, CD_CALLOC, nullptr, mesh->totloop); - - MVert *vertices = mesh->mvert; - MEdge *edges = mesh->medge; - MPoly *polys = mesh->mpoly; - MLoop *loops = mesh->mloop; + MVert *verts = (MVert *)CustomData_add_layer( + &mesh->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, mesh->totvert); + MEdge *edges = (MEdge *)CustomData_add_layer( + &mesh->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, mesh->totedge); + MPoly *polys = (MPoly *)CustomData_add_layer( + &mesh->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, mesh->totpoly); + 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"); MLoopUV *loopsuv[2] = {nullptr}; if (hasTex) { // First UV layer - CustomData_add_layer_named( - &mesh->ldata, CD_MLOOPUV, CD_CALLOC, 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_CALLOC, 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) MLoopCol *colors = (MLoopCol *)CustomData_add_layer_named( - &mesh->ldata, CD_PROP_BYTE_COLOR, CD_CALLOC, nullptr, mesh->totloop, "Color"); + &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_CALLOC, nullptr, mesh->totloop, "Alpha"); - mesh->mloopcol = colors; + &mesh->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, nullptr, mesh->totloop, "Alpha"); + 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()) { @@ -669,19 +664,19 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) else { if (!visible) { // first vertex - vertices->co[0] = svRep[0]->point2d()[0]; - vertices->co[1] = svRep[0]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); + verts->co[0] = svRep[0]->point2d()[0]; + verts->co[1] = svRep[0]->point2d()[1]; + verts->co[2] = get_stroke_vertex_z(); - ++vertices; + ++verts; ++vertex_index; // second vertex - vertices->co[0] = svRep[1]->point2d()[0]; - vertices->co[1] = svRep[1]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); + verts->co[0] = svRep[1]->point2d()[0]; + verts->co[1] = svRep[1]->point2d()[1]; + verts->co[2] = get_stroke_vertex_z(); - ++vertices; + ++verts; ++vertex_index; // first edge @@ -693,10 +688,10 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) visible = true; // vertex - vertices->co[0] = svRep[2]->point2d()[0]; - vertices->co[1] = svRep[2]->point2d()[1]; - vertices->co[2] = get_stroke_vertex_z(); - ++vertices; + verts->co[0] = svRep[2]->point2d()[0]; + verts->co[1] = svRep[2]->point2d()[1]; + verts->co[2] = get_stroke_vertex_z(); + ++verts; ++vertex_index; // edges @@ -713,7 +708,8 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex) // poly polys->loopstart = loop_index; polys->totloop = 3; - polys->mat_nr = matnr; + *material_indices = matnr; + ++material_indices; ++polys; // Even and odd loops connect triangles vertices differently diff --git a/source/blender/freestyle/intern/geometry/FastGrid.h b/source/blender/freestyle/intern/geometry/FastGrid.h index 3d9ec6a64ca..b835e109faa 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.h +++ b/source/blender/freestyle/intern/geometry/FastGrid.h @@ -12,7 +12,7 @@ namespace Freestyle { /** Class to define a regular grid used for ray casting computations - * We don't use a hashtable here. The grid is explicitly stored for faster computations. + * We don't use a hash-table here. The grid is explicitly stored for faster computations. * However, this might result in significant increase in memory usage * (compared to the regular grid). */ @@ -31,7 +31,7 @@ class FastGrid : public Grid { /** * clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + * Deletes all the cells, clears the hash-table, resets size, size of cell, number of cells. */ virtual void clear(); diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index c25594e620f..d66982eef52 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -187,7 +187,7 @@ class Grid { } /** clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + * Deletes all the cells, clears the hash-table, resets size, size of cell, number of cells. */ virtual void clear(); diff --git a/source/blender/freestyle/intern/geometry/HashGrid.h b/source/blender/freestyle/intern/geometry/HashGrid.h index b08334d3474..18eeb579d07 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.h +++ b/source/blender/freestyle/intern/geometry/HashGrid.h @@ -52,7 +52,7 @@ class HashGrid : public Grid { } /** clears the grid - * Deletes all the cells, clears the hashtable, resets size, size of cell, number of cells. + * Deletes all the cells, clears the hash-table, resets size, size of cell, number of cells. */ virtual void clear(); diff --git a/source/blender/freestyle/intern/view_map/ViewMap.cpp b/source/blender/freestyle/intern/view_map/ViewMap.cpp index b26a833b32e..d918cfec2ae 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMap.cpp @@ -398,7 +398,7 @@ void TVertex::setBackEdgeB(ViewEdge *iBackEdgeB, bool incoming) void TVertex::Replace(ViewEdge *iOld, ViewEdge *iNew) { - // theoritically, we only replace edges for which this + // theoretically, we only replace edges for which this // view vertex is the B vertex if ((iOld == _FrontEdgeA.first) && (_FrontEdgeA.first->B() == this)) { _FrontEdgeA.first = iNew; |