Commit: ac8c589b7c98aa06ff2f1de8fb050724e38e50d5 Author: Pablo Dobarro Date: Thu Dec 24 16:30:12 2020 +0100 Branches: sculpt-dev https://developer.blender.org/rBac8c589b7c98aa06ff2f1de8fb050724e38e50d5
Preparte curvature fairing and Fairing edit mode operator =================================================================== M release/scripts/startup/bl_ui/space_view3d.py M source/blender/blenkernel/BKE_mesh_fair.h M source/blender/blenkernel/intern/mesh_fair.cc M source/blender/editors/mesh/CMakeLists.txt A source/blender/editors/mesh/editmesh_fair.c M source/blender/editors/mesh/mesh_intern.h M source/blender/editors/mesh/mesh_ops.c M source/blender/editors/sculpt_paint/sculpt_face_set.c =================================================================== diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 8b5183faf62..d8d24f4ff81 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -3624,6 +3624,8 @@ class VIEW3D_MT_edit_mesh(Menu): if with_bullet: layout.operator("mesh.convex_hull") + layout.operator("mesh.fair_vertices", text="Fair") + layout.separator() layout.operator("mesh.symmetrize") diff --git a/source/blender/blenkernel/BKE_mesh_fair.h b/source/blender/blenkernel/BKE_mesh_fair.h index 2d5c85d4129..b7037abcfe1 100644 --- a/source/blender/blenkernel/BKE_mesh_fair.h +++ b/source/blender/blenkernel/BKE_mesh_fair.h @@ -36,6 +36,7 @@ extern "C" { typedef enum eMeshFairingDepth { MESH_FAIRING_DEPTH_POSITION = 1, MESH_FAIRING_DEPTH_TANGENCY = 2, + MESH_FAIRING_DEPTH_CURVATURE = 3, } eMeshFairingDepth; /* affect_vertices is used to define the fairing area. Indexed by vertex index, set to true when diff --git a/source/blender/blenkernel/intern/mesh_fair.cc b/source/blender/blenkernel/intern/mesh_fair.cc index ccd1434b60b..0538875c07f 100644 --- a/source/blender/blenkernel/intern/mesh_fair.cc +++ b/source/blender/blenkernel/intern/mesh_fair.cc @@ -67,6 +67,9 @@ class FairingContext { /* Get the other vertex index for a loop. */ virtual int other_vertex_index_from_loop(const int loop, const unsigned int v) = 0; + virtual int vertex_index_from_loop(const int loop) = 0; + virtual float cotangent_loop_weight_get(const int loop) = 0; + int vertex_count_get() { return totvert_; @@ -74,7 +77,7 @@ class FairingContext { int loop_count_get() { - return totvert_; + return totloop_; } MeshElemMap *vertex_loop_map_get(const int v) @@ -219,6 +222,15 @@ class MeshFairingContext : public FairingContext { mesh->totpoly, mesh->totloop); + BKE_mesh_edge_loop_map_create(&elmap_, + &elmap_mem_, + mesh->medge, + mesh->totedge, + mesh->mpoly, + mesh->totpoly, + mesh->mloop, + mesh->totloop); + /* Deformation coords. */ co_.reserve(mesh->totvert); if (deform_mverts) { @@ -244,6 +256,8 @@ class MeshFairingContext : public FairingContext { { MEM_SAFE_FREE(vlmap_); MEM_SAFE_FREE(vlmap_mem_); + MEM_SAFE_FREE(elmap_); + MEM_SAFE_FREE(elmap_mem_); } void adjacents_coords_from_loop(const int loop, @@ -266,12 +280,26 @@ class MeshFairingContext : public FairingContext { return e->v1; } + int vertex_index_from_loop(const int loop) override + { + return mloop_[loop].v; + } + + float cotangent_loop_weight_get(const int UNUSED(loop)) override + { + /* TODO: Implement cotangent loop weights for meshes. */ + return 1.0f; + } + protected: Mesh *mesh_; MLoop *mloop_; MPoly *mpoly_; MEdge *medge_; Vector<int> loop_to_poly_map_; + + MeshElemMap *elmap_; + int *elmap_mem_; }; class BMeshFairingContext : public FairingContext { @@ -307,6 +335,7 @@ class BMeshFairingContext : public FairingContext { int loop_count = 0; const int vert_index = BM_elem_index_get(v); vlmap_[vert_index].indices = &vlmap_mem_[index_iter]; + BM_ITER_ELEM (l, &loop_iter, v, BM_LOOPS_OF_VERT) { const int loop_index = BM_elem_index_get(l); bmloop_[loop_index] = l; @@ -340,6 +369,47 @@ class BMeshFairingContext : public FairingContext { return BM_elem_index_get(bm_other_vert); } + int vertex_index_from_loop(const int loop) override + { + return BM_elem_index_get(bmloop_[loop]->v); + } + + float cotangent_loop_weight_get(const int loop) override + { + return 1.0f; + + /* TODO: enable this when it works. */ + BMLoop *l = bmloop_[loop]; + float *co_c[2]; + int co_c_count = 1; + + float *co_a = l->v->co; + float *co_b = l->next->v->co; + co_c[0] = l->prev->v->co; + if (!BM_edge_is_boundary(l->e)) { + co_c_count = 2; + co_c[1] = l->radial_next->next->next->v->co; + } + + float weight = 0.0f; + for (int c = 0; c < co_c_count; c++) { + float v1[3]; + float v2[3]; + sub_v3_v3v3(v1, co_a, co_c[c]); + sub_v3_v3v3(v2, co_b, co_c[c]); + const float angle = angle_v3v3(v1, v2); + const float tangent = tan(angle); + if (tangent != 0) { + weight += 1.0f / tangent; + } + else { + weight += 1e-4; + } + } + weight *= 0.5f; + return weight; + } + protected: BMesh *bm; Vector<BMLoop *> bmloop_; @@ -464,6 +534,27 @@ class UniformLoopWeight : public LoopWeight { } }; +class CotangentLoopWeight : public LoopWeight { + public: + CotangentLoopWeight(FairingContext *fairing_context) + { + const int totloop = fairing_context->loop_count_get(); + loop_weights_.reserve(totloop); + for (int i = 0; i < totloop; i++) { + loop_weights_[i] = fairing_context->cotangent_loop_weight_get(i); + } + } + ~CotangentLoopWeight() = default; + + float weight_at_index(const int index) override + { + return loop_weights_[index]; + } + + private: + Vector<float> loop_weights_; +}; + static void prefair_and_fair_vertices(FairingContext *fairing_context, bool *affected_vertices, const eMeshFairingDepth depth) @@ -471,18 +562,22 @@ static void prefair_and_fair_vertices(FairingContext *fairing_context, /* Prefair. */ UniformVertexWeight *uniform_vertex_weights = new UniformVertexWeight(fairing_context); UniformLoopWeight *uniform_loop_weights = new UniformLoopWeight(); - fairing_context->fair_vertices( - affected_vertices, depth, uniform_vertex_weights, uniform_loop_weights); + fairing_context->fair_vertices(affected_vertices, + MESH_FAIRING_DEPTH_POSITION, + uniform_vertex_weights, + uniform_loop_weights); + delete uniform_vertex_weights; + delete uniform_loop_weights; /* Fair. */ VoronoiVertexWeight *voronoi_vertex_weights = new VoronoiVertexWeight(fairing_context); - /* TODO: Implemente cotangent loop weights. */ + CotangentLoopWeight *cotangent_loop_weights = new CotangentLoopWeight(fairing_context); fairing_context->fair_vertices( - affected_vertices, depth, voronoi_vertex_weights, uniform_loop_weights); + affected_vertices, depth, voronoi_vertex_weights, cotangent_loop_weights); - delete uniform_loop_weights; delete voronoi_vertex_weights; + delete cotangent_loop_weights; } void BKE_mesh_prefair_and_fair_vertices(struct Mesh *mesh, diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 35bf295a678..7ca120fa95a 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -46,6 +46,7 @@ set(SRC editmesh_extrude_screw.c editmesh_extrude_spin.c editmesh_extrude_spin_gizmo.c + editmesh_fair.c editmesh_inset.c editmesh_intersect.c editmesh_knife.c diff --git a/source/blender/editors/mesh/editmesh_fair.c b/source/blender/editors/mesh/editmesh_fair.c new file mode 100644 index 00000000000..321369d864b --- /dev/null +++ b/source/blender/editors/mesh/editmesh_fair.c @@ -0,0 +1,162 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edmesh + * + * Interactive editmesh knife tool. + */ + +#ifdef _MSC_VER +# define _USE_MATH_DEFINES +#endif + +#include "MEM_guardedalloc.h" + +#include "DNA_object_types.h" + +#include "BLI_alloca.h" +#include "BLI_array.h" +#include "BLI_linklist.h" +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_memarena.h" +#include "BLI_smallhash.h" +#include "BLI_string.h" + +#include "BLT_translation.h" + +#include "BKE_bvhutils.h" +#include "BKE_mesh_fair.h" +#include "BKE_context.h" +#include "BKE_editmesh.h" +#include "BKE_layer.h" +#include "BKE_editmesh_bvh.h" +#include "BKE_report.h" + +#include "ED_mesh.h" +#include "ED_screen.h" +#include "ED_space_api.h" +#include "ED_view3d.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "DNA_object_types.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + +#include "mesh_intern.h" /* own include */ + +static EnumPropertyItem prop_edit_mesh_fair_selection_mode_items[] = { + { + MESH_FAIRING_DEPTH_POSITION, + "POSITION", + 0, + "Position", + "Fair positions", + }, + { + MESH_FAIRING_DEPTH_TANGENCY, + "TANGENCY", + 0, + "Tangency", + "Fair tangency", + }, + /* + { + MESH_FAIRING_DEPTH_CURVATURE, + "CURVATURE", + 0, + "Curvature", + "Fair curvature", + }, + */ + {0, NULL, 0, NULL, NULL}, +}; + +static int edbm_fair_vertices_exec(bContext *C, wmOperator *op) +{ + const int mode = RNA_enum_get(op->ptr, "mode"); + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs