Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-03-26 23:03:42 +0300
committerJulian Eisel <julian@blender.org>2020-03-26 23:18:45 +0300
commitc94b6209861ca7cc3985b53474feed7d94c0221a (patch)
tree752054f0dca1338cda5cf8ad4f6d18573fcca3b9 /source/blender/modifiers
parent357ed79cb93f9d655501a828c6cddd68282de62d (diff)
parentafb1a64ccb81b7ed792f64151986f40f53af8da5 (diff)
Merge branch 'master' into wm-drag-drop-rewrite
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/CMakeLists.txt4
-rw-r--r--source/blender/modifiers/MOD_modifiertypes.h8
-rw-r--r--source/blender/modifiers/intern/MOD_armature.c8
-rw-r--r--source/blender/modifiers/intern/MOD_array.c8
-rw-r--r--source/blender/modifiers/intern/MOD_bevel.c22
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.c8
-rw-r--r--source/blender/modifiers/intern/MOD_build.c2
-rw-r--r--source/blender/modifiers/intern/MOD_cast.c36
-rw-r--r--source/blender/modifiers/intern/MOD_cloth.c12
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c4
-rw-r--r--source/blender/modifiers/intern/MOD_correctivesmooth.c15
-rw-r--r--source/blender/modifiers/intern/MOD_curve.c16
-rw-r--r--source/blender/modifiers/intern/MOD_datatransfer.c8
-rw-r--r--source/blender/modifiers/intern/MOD_decimate.c6
-rw-r--r--source/blender/modifiers/intern/MOD_displace.c12
-rw-r--r--source/blender/modifiers/intern/MOD_dynamicpaint.c6
-rw-r--r--source/blender/modifiers/intern/MOD_explode.c12
-rw-r--r--source/blender/modifiers/intern/MOD_fluid.c11
-rw-r--r--source/blender/modifiers/intern/MOD_hook.c20
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciandeform.c10
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciansmooth.c6
-rw-r--r--source/blender/modifiers/intern/MOD_lattice.c14
-rw-r--r--source/blender/modifiers/intern/MOD_mask.c388
-rw-r--r--source/blender/modifiers/intern/MOD_mask.cc417
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache.c4
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache_mdd.c12
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache_pc2.c10
-rw-r--r--source/blender/modifiers/intern/MOD_meshdeform.c10
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.c6
-rw-r--r--source/blender/modifiers/intern/MOD_mirror.c6
-rw-r--r--source/blender/modifiers/intern/MOD_multires.c16
-rw-r--r--source/blender/modifiers/intern/MOD_normal_edit.c29
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c8
-rw-r--r--source/blender/modifiers/intern/MOD_particleinstance.c4
-rw-r--r--source/blender/modifiers/intern/MOD_particlesystem.c2
-rw-r--r--source/blender/modifiers/intern/MOD_remesh.c2
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c10
-rw-r--r--source/blender/modifiers/intern/MOD_shapekey.c2
-rw-r--r--source/blender/modifiers/intern/MOD_shrinkwrap.c15
-rw-r--r--source/blender/modifiers/intern/MOD_simpledeform.c8
-rw-r--r--source/blender/modifiers/intern/MOD_skin.c8
-rw-r--r--source/blender/modifiers/intern/MOD_smooth.c9
-rw-r--r--source/blender/modifiers/intern/MOD_softbody.c7
-rw-r--r--source/blender/modifiers/intern/MOD_solidify.c12
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_extrude.c16
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c266
-rw-r--r--source/blender/modifiers/intern/MOD_subsurf.c8
-rw-r--r--source/blender/modifiers/intern/MOD_surface.c6
-rw-r--r--source/blender/modifiers/intern/MOD_surfacedeform.c28
-rw-r--r--source/blender/modifiers/intern/MOD_triangulate.c10
-rw-r--r--source/blender/modifiers/intern/MOD_util.c10
-rw-r--r--source/blender/modifiers/intern/MOD_uvproject.c4
-rw-r--r--source/blender/modifiers/intern/MOD_uvwarp.c94
-rw-r--r--source/blender/modifiers/intern/MOD_warp.c15
-rw-r--r--source/blender/modifiers/intern/MOD_wave.c8
-rw-r--r--source/blender/modifiers/intern/MOD_weighted_normal.c11
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.c42
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.h11
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgedit.c17
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgmix.c35
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c37
-rw-r--r--source/blender/modifiers/intern/MOD_weld.c30
-rw-r--r--source/blender/modifiers/intern/MOD_wireframe.c2
63 files changed, 1072 insertions, 811 deletions
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index cec7ddb4b68..48acbdc17f3 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -59,7 +59,7 @@ set(SRC
intern/MOD_laplaciandeform.c
intern/MOD_laplaciansmooth.c
intern/MOD_lattice.c
- intern/MOD_mask.c
+ intern/MOD_mask.cc
intern/MOD_meshcache.c
intern/MOD_meshcache_mdd.c
intern/MOD_meshcache_pc2.c
@@ -116,7 +116,7 @@ set(LIB
if(WITH_ALEMBIC)
add_definitions(-DWITH_ALEMBIC)
list(APPEND INC
- ../alembic
+ ../io/alembic
)
list(APPEND LIB
bf_alembic
diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h
index 7dd1ce830aa..5dc4adf4393 100644
--- a/source/blender/modifiers/MOD_modifiertypes.h
+++ b/source/blender/modifiers/MOD_modifiertypes.h
@@ -23,6 +23,10 @@
#include "BKE_modifier.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* ****************** Type structures for all modifiers ****************** */
extern ModifierTypeInfo modifierType_None;
@@ -86,4 +90,8 @@ extern ModifierTypeInfo modifierType_WeightedNormal;
/* MOD_util.c */
void modifier_type_init(ModifierTypeInfo *types[]);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __MOD_MODIFIERTYPES_H__ */
diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c
index 9f3802a4fa1..3e78662da6c 100644
--- a/source/blender/modifiers/intern/MOD_armature.c
+++ b/source/blender/modifiers/intern/MOD_armature.c
@@ -23,18 +23,18 @@
#include <string.h>
-#include "BLI_utildefines.h"
#include "BLI_listbase.h"
+#include "BLI_utildefines.h"
#include "DNA_armature_types.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
#include "BKE_action.h"
#include "BKE_editmesh.h"
#include "BKE_lattice.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 3b50cfe704a..ff5bf3d0ee4 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -35,12 +35,12 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BKE_displist.h"
#include "BKE_curve.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
-#include "BKE_modifier.h"
+#include "BKE_displist.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
+#include "BKE_modifier.h"
#include "BKE_object_deform.h"
#include "MOD_util.h"
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index f5bb1cb0ef8..bd2f8a6dca3 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -27,11 +27,11 @@
#include "BLI_math.h"
+#include "DNA_curveprofile_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_curveprofile_types.h"
#include "BKE_deform.h"
#include "BKE_mesh.h"
@@ -39,9 +39,9 @@
#include "MOD_util.h"
+#include "BKE_curveprofile.h"
#include "bmesh.h"
#include "bmesh_tools.h"
-#include "BKE_curveprofile.h"
#include "DEG_depsgraph_query.h"
@@ -118,6 +118,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
const float spread = bmd->spread;
const bool use_custom_profile = (bmd->flags & MOD_BEVEL_CUSTOM_PROFILE);
const int vmesh_method = bmd->vmesh_method;
+ const bool invert_vgroup = (bmd->flags & MOD_BEVEL_INVERT_VGROUP) != 0;
bm = BKE_mesh_to_bmesh_ex(mesh,
&(struct BMeshCreateParams){0},
@@ -146,7 +147,10 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
}
else if (vgroup != -1) {
- weight = defvert_array_find_weight_safe(dvert, BM_elem_index_get(v), vgroup);
+ weight = invert_vgroup ?
+ 1.0f -
+ BKE_defvert_array_find_weight_safe(dvert, BM_elem_index_get(v), vgroup) :
+ BKE_defvert_array_find_weight_safe(dvert, BM_elem_index_get(v), vgroup);
/* Check is against 0.5 rather than != 0.0 because cascaded bevel modifiers will
* interpolate weights for newly created vertices, and may cause unexpected "selection" */
if (weight < 0.5f) {
@@ -180,8 +184,14 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
}
else if (vgroup != -1) {
- weight = defvert_array_find_weight_safe(dvert, BM_elem_index_get(e->v1), vgroup);
- weight2 = defvert_array_find_weight_safe(dvert, BM_elem_index_get(e->v2), vgroup);
+ weight = invert_vgroup ?
+ 1.0f - BKE_defvert_array_find_weight_safe(
+ dvert, BM_elem_index_get(e->v1), vgroup) :
+ BKE_defvert_array_find_weight_safe(dvert, BM_elem_index_get(e->v1), vgroup);
+ weight2 = invert_vgroup ? 1.0f - BKE_defvert_array_find_weight_safe(
+ dvert, BM_elem_index_get(e->v2), vgroup) :
+ BKE_defvert_array_find_weight_safe(
+ dvert, BM_elem_index_get(e->v2), vgroup);
if (weight < 0.5f || weight2 < 0.5f) {
continue;
}
@@ -196,7 +206,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
Object *ob = ctx->object;
if (harden_normals && (ob->type == OB_MESH) && !(((Mesh *)ob->data)->flag & ME_AUTOSMOOTH)) {
- modifier_setError(md, "Enable 'Auto Smooth' option in mesh settings for hardening");
+ modifier_setError(md, "Enable 'Auto Smooth' in Object Data Properties");
harden_normals = false;
}
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index 9868395c0e8..67610e8cd29 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -36,8 +36,8 @@
#include "DNA_object_types.h"
#include "BKE_global.h" /* only to check G.debug */
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -260,7 +260,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
/* Using original (not evaluated) object here since we are writing to it. */
/* XXX Pretty sure comment above is fully wrong now with CoW & co ? */
- BKE_material_remap_object_calc(ctx->object, other, material_remap);
+ BKE_object_material_remap_calc(ctx->object, other, material_remap);
BMFace *efa;
i = 0;
@@ -351,7 +351,7 @@ ModifierTypeInfo modifierType_Boolean = {
/* structName */ "BooleanModifierData",
/* structSize */ sizeof(BooleanModifierData),
/* type */ eModifierTypeType_Nonconstructive,
- /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_UsesPointCache,
+ /* flags */ eModifierTypeFlag_AcceptsMesh,
/* copyData */ modifier_copyData_generic,
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index e61f6877d09..3c1a5744b33 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -29,8 +29,8 @@
#include "BLI_math_vector.h"
#include "BLI_rand.h"
-#include "DNA_meshdata_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DEG_depsgraph_query.h"
diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c
index b070a3c7127..ed4a53ba2f3 100644
--- a/source/blender/modifiers/intern/MOD_cast.c
+++ b/source/blender/modifiers/intern/MOD_cast.c
@@ -31,8 +31,8 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -153,7 +153,9 @@ static void sphere_do(CastModifierData *cmd,
/* 3) if we were given a vertex group name,
* only those vertices should be affected */
- MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
+ if (cmd->defgrp_name[0] != '\0') {
+ MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
+ }
if (flag & MOD_CAST_SIZE_FROM_RADIUS) {
len = cmd->radius;
@@ -199,8 +201,9 @@ static void sphere_do(CastModifierData *cmd,
}
if (dvert) {
- const float weight = invert_vgroup ? 1.0f - defvert_find_weight(&dvert[i], defgrp_index) :
- defvert_find_weight(&dvert[i], defgrp_index);
+ const float weight = invert_vgroup ?
+ 1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index) :
+ BKE_defvert_find_weight(&dvert[i], defgrp_index);
if (weight == 0.0f) {
continue;
@@ -243,11 +246,12 @@ static void cuboid_do(CastModifierData *cmd,
int numVerts)
{
MDeformVert *dvert = NULL;
+ int defgrp_index;
const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0;
Object *ctrl_ob = NULL;
- int i, defgrp_index;
+ int i;
bool has_radius = false;
short flag;
float fac = cmd->fac;
@@ -272,7 +276,9 @@ static void cuboid_do(CastModifierData *cmd,
/* 3) if we were given a vertex group name,
* only those vertices should be affected */
- MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
+ if (cmd->defgrp_name[0] != '\0') {
+ MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
+ }
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
@@ -370,8 +376,9 @@ static void cuboid_do(CastModifierData *cmd,
}
if (dvert) {
- const float weight = invert_vgroup ? 1.0f - defvert_find_weight(&dvert[i], defgrp_index) :
- defvert_find_weight(&dvert[i], defgrp_index);
+ const float weight = invert_vgroup ?
+ 1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index) :
+ BKE_defvert_find_weight(&dvert[i], defgrp_index);
if (weight == 0.0f) {
continue;
@@ -489,10 +496,15 @@ static void deformVertsEM(ModifierData *md,
int numVerts)
{
CastModifierData *cmd = (CastModifierData *)md;
- Mesh *mesh_src = MOD_deform_mesh_eval_get(
- ctx->object, editData, mesh, NULL, numVerts, false, false);
+ Mesh *mesh_src = NULL;
- BLI_assert(mesh_src->totvert == numVerts);
+ if (cmd->defgrp_name[0] != '\0') {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
+ }
+
+ if (mesh_src) {
+ BLI_assert(mesh_src->totvert == numVerts);
+ }
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
cuboid_do(cmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index cc91e345c8f..0cab6144de8 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -30,8 +30,8 @@
#include "DNA_cloth_types.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "MEM_guardedalloc.h"
@@ -39,8 +39,8 @@
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_key.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
@@ -179,7 +179,11 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
}
else {
tclmd->point_cache = BKE_ptcache_add(&tclmd->ptcaches);
- tclmd->point_cache->step = 1;
+ if (clmd->point_cache != NULL) {
+ tclmd->point_cache->step = clmd->point_cache->step;
+ tclmd->point_cache->startframe = clmd->point_cache->startframe;
+ tclmd->point_cache->endframe = clmd->point_cache->endframe;
+ }
}
tclmd->sim_parms = MEM_dupallocN(clmd->sim_parms);
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 56e84423db4..af468cb2d27 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -25,15 +25,15 @@
#include "BLI_math.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
#include "BKE_collision.h"
#include "BKE_global.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index ff241550bdc..4eea9092e10 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -27,17 +27,17 @@
#include "BLI_math.h"
-#include "DNA_scene_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
#include "MEM_guardedalloc.h"
#include "BKE_deform.h"
-#include "BKE_mesh.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
+#include "BKE_mesh.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
@@ -64,6 +64,7 @@ static void initData(ModifierData *md)
csmd->bind_coords_num = 0;
csmd->lambda = 0.5f;
+ csmd->scale = 1.0f;
csmd->repeat = 5;
csmd->flag = 0;
csmd->smooth_type = MOD_CORRECTIVESMOOTH_SMOOTH_SIMPLE;
@@ -124,7 +125,7 @@ static void mesh_get_weights(MDeformVert *dvert,
uint i;
for (i = 0; i < numVerts; i++, dvert++) {
- const float w = defvert_find_weight(dvert, defgrp_index);
+ const float w = BKE_defvert_find_weight(dvert, defgrp_index);
if (use_invert_vgroup == false) {
smooth_weights[i] = w;
@@ -696,7 +697,7 @@ static void correctivesmooth_modifier_do(ModifierData *md,
uint i;
float(*tangent_spaces)[3][3];
-
+ const float scale = csmd->scale;
/* calloc, since values are accumulated */
tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__);
@@ -710,7 +711,7 @@ static void correctivesmooth_modifier_do(ModifierData *md,
#endif
mul_v3_m3v3(delta, tangent_spaces[i], csmd->delta_cache.deltas[i]);
- add_v3_v3(vertexCos[i], delta);
+ madd_v3_v3fl(vertexCos[i], delta, scale);
}
MEM_freeN(tangent_spaces);
diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c
index f9137572d6f..e287685a9e5 100644
--- a/source/blender/modifiers/intern/MOD_curve.c
+++ b/source/blender/modifiers/intern/MOD_curve.c
@@ -26,13 +26,13 @@
#include "BLI_utildefines.h"
#include "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_editmesh.h"
#include "BKE_lattice.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -119,8 +119,14 @@ static void deformVerts(ModifierData *md,
/* silly that defaxis and curve_deform_verts are off by 1
* but leave for now to save having to call do_versions */
- curve_deform_verts(
- cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
+ curve_deform_verts(cmd->object,
+ ctx->object,
+ vertexCos,
+ numVerts,
+ dvert,
+ defgrp_index,
+ cmd->flag,
+ cmd->defaxis - 1);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c
index bb032f9725c..72cbe197251 100644
--- a/source/blender/modifiers/intern/MOD_datatransfer.c
+++ b/source/blender/modifiers/intern/MOD_datatransfer.c
@@ -32,8 +32,8 @@
#include "BKE_customdata.h"
#include "BKE_data_transfer.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_remap.h"
#include "BKE_modifier.h"
@@ -184,7 +184,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
if (((result == me) || (me->mvert == result->mvert) || (me->medge == result->medge)) &&
(dtmd->data_types & DT_TYPES_AFFECT_MESH)) {
- /* We need to duplicate data here, otherwise setting custom normals, edges' shaprness, etc.,
+ /* We need to duplicate data here, otherwise setting custom normals, edges' sharpness, etc.,
* could modify org mesh, see T43671. */
BKE_id_copy_ex(NULL, &me_mod->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
}
@@ -220,7 +220,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
modifier_setError(md, "%s", BKE_reports_string(&reports, RPT_ERROR));
}
else if ((dtmd->data_types & DT_TYPE_LNOR) && !(me->flag & ME_AUTOSMOOTH)) {
- modifier_setError((ModifierData *)dtmd, "Enable 'Auto Smooth' option in mesh settings");
+ modifier_setError((ModifierData *)dtmd, "Enable 'Auto Smooth' in Object Data Properties");
}
else if (result->totvert > HIGH_POLY_WARNING ||
((Mesh *)(ob_source->data))->totvert > HIGH_POLY_WARNING) {
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index c113a2767a0..cf07b5460e1 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -25,9 +25,9 @@
#include "BLI_math.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
@@ -147,12 +147,12 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
if (dmd->flag & MOD_DECIM_FLAG_INVERT_VGROUP) {
for (i = 0; i < vert_tot; i++) {
- vweights[i] = 1.0f - defvert_find_weight(&dvert[i], defgrp_index);
+ vweights[i] = 1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index);
}
}
else {
for (i = 0; i < vert_tot; i++) {
- vweights[i] = defvert_find_weight(&dvert[i], defgrp_index);
+ vweights[i] = BKE_defvert_find_weight(&dvert[i], defgrp_index);
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index 9cb694be88b..a1b02e201d9 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -31,15 +31,15 @@
#include "DNA_object_types.h"
#include "BKE_customdata.h"
+#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
#include "BKE_image.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
-#include "BKE_texture.h"
-#include "BKE_deform.h"
#include "BKE_object.h"
+#include "BKE_texture.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
@@ -174,6 +174,7 @@ static void displaceModifier_do_task(void *__restrict userdata,
DisplaceUserdata *data = (DisplaceUserdata *)userdata;
DisplaceModifierData *dmd = data->dmd;
MDeformVert *dvert = data->dvert;
+ const bool invert_vgroup = (dmd->flag & MOD_DISP_INVERT_VGROUP) != 0;
float weight = data->weight;
int defgrp_index = data->defgrp_index;
int direction = data->direction;
@@ -192,7 +193,8 @@ static void displaceModifier_do_task(void *__restrict userdata,
float local_vec[3];
if (dvert) {
- weight = defvert_find_weight(dvert + iter, defgrp_index);
+ weight = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dvert + iter, defgrp_index) :
+ BKE_defvert_find_weight(dvert + iter, defgrp_index);
if (weight == 0.0f) {
return;
}
diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c
index 83d8439f046..457f47bf025 100644
--- a/source/blender/modifiers/intern/MOD_dynamicpaint.c
+++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c
@@ -23,14 +23,14 @@
#include "BLI_utildefines.h"
#include "DNA_dynamicpaint_types.h"
-#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_force_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_mesh_types.h"
#include "BKE_dynamicpaint.h"
#include "BKE_layer.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index 5f0bbc8ecf1..d380747eb31 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -28,14 +28,14 @@
#include "BLI_math.h"
#include "BLI_rand.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_scene_types.h"
#include "DNA_object_types.h"
-#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
#include "BKE_deform.h"
#include "BKE_lattice.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
@@ -97,6 +97,7 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
float center[3], co[3];
int *facepa = NULL, *vertpa = NULL, totvert = 0, totface = 0, totpart = 0;
int i, p, v1, v2, v3, v4 = 0;
+ const bool invert_vgroup = (emd->flag & eExplodeFlag_INVERT_VGROUP) != 0;
mvert = mesh->mvert;
mface = mesh->mface;
@@ -129,7 +130,9 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
for (i = 0; i < totvert; i++, dvert++) {
float val = BLI_rng_get_float(rng);
val = (1.0f - emd->protect) * val + emd->protect * 0.5f;
- if (val < defvert_find_weight(dvert, defgrp_index)) {
+ const float weight = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dvert, defgrp_index) :
+ BKE_defvert_find_weight(dvert, defgrp_index);
+ if (val < weight) {
vertpa[i] = -1;
}
}
@@ -974,7 +977,6 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
explode = BKE_mesh_new_nomain_from_template(mesh, totdup, 0, totface - delface, 0, 0);
mtface = CustomData_get_layer_named(&explode->fdata, CD_MTFACE, emd->uvname);
- /*dupvert = CDDM_get_verts(explode);*/
/* getting back to object space */
invert_m4_m4(imat, ctx->object->obmat);
diff --git a/source/blender/modifiers/intern/MOD_fluid.c b/source/blender/modifiers/intern/MOD_fluid.c
index b48c80d8e32..1c2f0a413a7 100644
--- a/source/blender/modifiers/intern/MOD_fluid.c
+++ b/source/blender/modifiers/intern/MOD_fluid.c
@@ -28,17 +28,16 @@
#include "BLI_utildefines.h"
#include "DNA_collection_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
#include "DNA_fluid_types.h"
-#include "DNA_object_force_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_object_force_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
-#include "BKE_cdderivedmesh.h"
+#include "BKE_fluid.h"
#include "BKE_layer.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_modifier.h"
-#include "BKE_fluid.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c
index 1a62010abe7..1ae2c5e4424 100644
--- a/source/blender/modifiers/intern/MOD_hook.c
+++ b/source/blender/modifiers/intern/MOD_hook.c
@@ -30,13 +30,13 @@
#include "DNA_object_types.h"
#include "BKE_action.h"
+#include "BKE_colortools.h"
+#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
-#include "BKE_deform.h"
-#include "BKE_colortools.h"
#include "DEG_depsgraph_query.h"
@@ -143,6 +143,8 @@ struct HookData_cb {
float mat_uniform[3][3];
float mat[4][4];
+
+ bool invert_vgroup;
};
static float hook_falloff(const struct HookData_cb *hd, const float len_sq)
@@ -236,7 +238,8 @@ static void hook_co_apply(struct HookData_cb *hd, const int j)
if (fac) {
if (hd->dvert) {
- fac *= defvert_find_weight(&hd->dvert[j], hd->defgrp_index);
+ fac *= hd->invert_vgroup ? 1.0f - BKE_defvert_find_weight(&hd->dvert[j], hd->defgrp_index) :
+ BKE_defvert_find_weight(&hd->dvert[j], hd->defgrp_index);
}
if (fac) {
@@ -259,6 +262,7 @@ static void deformVerts_do(HookModifierData *hmd,
float dmat[4][4];
int i, *index_pt;
struct HookData_cb hd;
+ const bool invert_vgroup = (hmd->flag & MOD_HOOK_INVERT_VGROUP) != 0;
if (hmd->curfalloff == NULL) {
/* should never happen, but bad lib linking could cause it */
@@ -277,12 +281,14 @@ static void deformVerts_do(HookModifierData *hmd,
hd.falloff_type = hmd->falloff_type;
hd.falloff = (hmd->falloff_type == eHook_Falloff_None) ? 0.0f : hmd->falloff;
- hd.falloff_sq = SQUARE(hd.falloff);
+ hd.falloff_sq = square_f(hd.falloff);
hd.fac_orig = hmd->force;
hd.use_falloff = (hd.falloff_sq != 0.0f);
hd.use_uniform = (hmd->flag & MOD_HOOK_UNIFORM_SPACE) != 0;
+ hd.invert_vgroup = invert_vgroup;
+
if (hd.use_uniform) {
copy_m3_m4(hd.mat_uniform, hmd->parentinv);
mul_v3_m3v3(hd.cent, hd.mat_uniform, hmd->cent);
@@ -310,7 +316,7 @@ static void deformVerts_do(HookModifierData *hmd,
* This should always be true and I don't generally like
* "paranoid" style code like this, but old files can have
* indices that are out of range because old blender did
- * not correct them on exit editmode. - zr
+ * not correct them on exit edit-mode. - zr
*/
if (hmd->force == 0.0f) {
diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c
index 0fc2e0971da..683696b0725 100644
--- a/source/blender/modifiers/intern/MOD_laplaciandeform.c
+++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c
@@ -34,7 +34,7 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_runtime.h"
#include "BKE_particle.h"
@@ -528,6 +528,7 @@ static void initSystem(
MDeformVert *dvert = NULL;
MDeformVert *dv = NULL;
LaplacianSystem *sys;
+ const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0;
if (isValidVertexGroup(lmd, ob, mesh)) {
int *index_anchors = MEM_malloc_arrayN(numVerts, sizeof(int), __func__); /* over-alloc */
@@ -542,7 +543,8 @@ static void initSystem(
BLI_assert(dvert != NULL);
dv = dvert;
for (i = 0; i < numVerts; i++) {
- wpaint = defvert_find_weight(dv, defgrp_index);
+ wpaint = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) :
+ BKE_defvert_find_weight(dv, defgrp_index);
dv++;
if (wpaint > 0.0f) {
STACK_PUSH(index_anchors, i);
@@ -596,6 +598,7 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd,
MDeformVert *dvert = NULL;
MDeformVert *dv = NULL;
LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system;
+ const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0;
if (sys->total_verts != numVerts) {
return LAPDEFORM_SYSTEM_CHANGE_VERTEXES;
@@ -612,7 +615,8 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd,
}
dv = dvert;
for (i = 0; i < numVerts; i++) {
- wpaint = defvert_find_weight(dv, defgrp_index);
+ wpaint = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) :
+ BKE_defvert_find_weight(dv, defgrp_index);
dv++;
if (wpaint > 0.0f) {
total_anchors++;
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
index 86d4124e5db..97e94c46340 100644
--- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c
+++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
@@ -33,7 +33,7 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -378,6 +378,7 @@ static void laplaciansmoothModifier_do(
float w, wpaint;
int i, iter;
int defgrp_index;
+ const bool invert_vgroup = (smd->flag & MOD_LAPLACIANSMOOTH_INVERT_VGROUP) != 0;
sys = init_laplacian_system(mesh->totedge, mesh->totpoly, mesh->totloop, numVerts);
if (!sys) {
@@ -420,7 +421,8 @@ static void laplaciansmoothModifier_do(
EIG_linear_solver_right_hand_side_add(sys->context, 2, i, vertexCos[i][2]);
if (iter == 0) {
if (dv) {
- wpaint = defvert_find_weight(dv, defgrp_index);
+ wpaint = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) :
+ BKE_defvert_find_weight(dv, defgrp_index);
dv++;
}
else {
diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c
index a73e96da975..2b39f40a2b9 100644
--- a/source/blender/modifiers/intern/MOD_lattice.c
+++ b/source/blender/modifiers/intern/MOD_lattice.c
@@ -29,8 +29,8 @@
#include "BKE_editmesh.h"
#include "BKE_lattice.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -101,8 +101,14 @@ static void deformVerts(ModifierData *md,
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
- lattice_deform_verts(
- lmd->object, ctx->object, mesh_src, vertexCos, numVerts, lmd->name, lmd->strength);
+ lattice_deform_verts(lmd->object,
+ ctx->object,
+ mesh_src,
+ vertexCos,
+ numVerts,
+ lmd->flag,
+ lmd->name,
+ lmd->strength);
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c
deleted file mode 100644
index cf7d227e898..00000000000
--- a/source/blender/modifiers/intern/MOD_mask.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * 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) 2005 by the Blender Foundation.
- * All rights reserved.
- */
-
-/** \file
- * \ingroup modifiers
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-
-#include "BLI_listbase.h"
-#include "BLI_ghash.h"
-
-#include "DNA_armature_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
-
-#include "BKE_action.h" /* BKE_pose_channel_find_name */
-#include "BKE_customdata.h"
-#include "BKE_library_query.h"
-#include "BKE_mesh.h"
-#include "BKE_modifier.h"
-#include "BKE_deform.h"
-
-#include "DEG_depsgraph_build.h"
-#include "DEG_depsgraph_query.h"
-
-#include "MOD_modifiertypes.h"
-
-#include "BLI_strict_flags.h"
-
-static void requiredDataMask(Object *UNUSED(ob),
- ModifierData *UNUSED(md),
- CustomData_MeshMasks *r_cddata_masks)
-{
- r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
-}
-
-static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
-{
- MaskModifierData *mmd = (MaskModifierData *)md;
- walk(userData, ob, &mmd->ob_arm, IDWALK_CB_NOP);
-}
-
-static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- MaskModifierData *mmd = (MaskModifierData *)md;
- if (mmd->ob_arm) {
- bArmature *arm = (bArmature *)mmd->ob_arm->data;
- /* Tag relationship in depsgraph, but also on the armature. */
- /* TODO(sergey): Is it a proper relation here? */
- DEG_add_object_relation(ctx->node, mmd->ob_arm, DEG_OB_COMP_TRANSFORM, "Mask Modifier");
- arm->flag |= ARM_HAS_VIZ_DEPS;
- DEG_add_modifier_to_transform_relation(ctx->node, "Mask Modifier");
- }
-}
-
-static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
-{
- MaskModifierData *mmd = (MaskModifierData *)md;
- Object *ob = ctx->object;
- const bool found_test = (mmd->flag & MOD_MASK_INV) == 0;
- Mesh *result = NULL;
- GHash *vertHash = NULL, *edgeHash, *polyHash;
- GHashIterator gh_iter;
- MDeformVert *dvert, *dv;
- int numPolys = 0, numLoops = 0, numEdges = 0, numVerts = 0;
- int maxVerts, maxEdges, maxPolys;
- int i;
-
- const MVert *mvert_src;
- const MEdge *medge_src;
- const MPoly *mpoly_src;
- const MLoop *mloop_src;
-
- MPoly *mpoly_dst;
- MLoop *mloop_dst;
- MEdge *medge_dst;
- MVert *mvert_dst;
-
- int *loop_mapping;
-
- dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
- if (dvert == NULL) {
- return found_test ? BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0) : mesh;
- }
-
- /* Overview of Method:
- * 1. Get the vertices that are in the vertexgroup of interest.
- * 2. Filter out unwanted geometry (i.e. not in vertexgroup),
- * by populating mappings with new vs old indices.
- * 3. Make a new mesh containing only the mapping data.
- */
-
- /* get original number of verts, edges, and faces */
- maxVerts = mesh->totvert;
- maxEdges = mesh->totedge;
- maxPolys = mesh->totpoly;
-
- /* check if we can just return the original mesh
- * - must have verts and therefore verts assigned to vgroups to do anything useful
- */
- if (!(ELEM(mmd->mode, MOD_MASK_MODE_ARM, MOD_MASK_MODE_VGROUP)) || (maxVerts == 0) ||
- BLI_listbase_is_empty(&ob->defbase)) {
- return mesh;
- }
-
- /* if mode is to use selected armature bones, aggregate the bone groups */
- if (mmd->mode == MOD_MASK_MODE_ARM) { /* --- using selected bones --- */
- Object *oba = mmd->ob_arm;
- bPoseChannel *pchan;
- bDeformGroup *def;
- bool *bone_select_array;
- int bone_select_tot = 0;
- const int defbase_tot = BLI_listbase_count(&ob->defbase);
-
- /* check that there is armature object with bones to use, otherwise return original mesh */
- if (ELEM(NULL, oba, oba->pose, ob->defbase.first)) {
- return mesh;
- }
-
- /* Determine whether each vertex-group is associated with a selected bone or not:
- * - Each cell is a boolean saying whether bone corresponding to the i'th group selected.
- * - Groups that don't match a bone are treated as not existing
- * (along with the corresponding un-grouped verts).
- */
- bone_select_array = MEM_malloc_arrayN((size_t)defbase_tot, sizeof(char), "mask array");
-
- for (i = 0, def = ob->defbase.first; def; def = def->next, i++) {
- pchan = BKE_pose_channel_find_name(oba->pose, def->name);
- if (pchan && pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
- bone_select_array[i] = true;
- bone_select_tot++;
- }
- else {
- bone_select_array[i] = false;
- }
- }
-
- /* verthash gives mapping from original vertex indices to the new indices
- * (including selected matches only):
- * key = oldindex, value = newindex
- */
- vertHash = BLI_ghash_int_new_ex("mask vert gh", (uint)maxVerts);
-
- /* add vertices which exist in vertexgroups into vertHash for filtering
- * - dv = for each vertex, what vertexgroups does it belong to
- * - dw = weight that vertex was assigned to a vertexgroup it belongs to
- */
- for (i = 0, dv = dvert; i < maxVerts; i++, dv++) {
- MDeformWeight *dw = dv->dw;
- bool found = false;
- int j;
-
- /* check the groups that vertex is assigned to, and see if it was any use */
- for (j = 0; j < dv->totweight; j++, dw++) {
- if (dw->def_nr < defbase_tot) {
- if (bone_select_array[dw->def_nr]) {
- if (dw->weight > mmd->threshold) {
- found = true;
- break;
- }
- }
- }
- }
-
- if (found_test != found) {
- continue;
- }
-
- /* add to ghash for verts (numVerts acts as counter for mapping) */
- BLI_ghash_insert(vertHash, POINTER_FROM_INT(i), POINTER_FROM_INT(numVerts));
- numVerts++;
- }
-
- /* free temp hashes */
- MEM_freeN(bone_select_array);
- }
- else { /* --- Using Nominated VertexGroup only --- */
- int defgrp_index = defgroup_name_index(ob, mmd->vgroup);
-
- /* if no vgroup (i.e. dverts) found, return the initial mesh */
- if (defgrp_index == -1) {
- return mesh;
- }
-
- /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
- vertHash = BLI_ghash_int_new_ex("mask vert2 bh", (uint)maxVerts);
-
- /* add vertices which exist in vertexgroup into ghash for filtering */
- for (i = 0, dv = dvert; i < maxVerts; i++, dv++) {
- const bool found = defvert_find_weight(dv, defgrp_index) > mmd->threshold;
- if (found_test != found) {
- continue;
- }
-
- /* add to ghash for verts (numVerts acts as counter for mapping) */
- BLI_ghash_insert(vertHash, POINTER_FROM_INT(i), POINTER_FROM_INT(numVerts));
- numVerts++;
- }
- }
-
- /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
- edgeHash = BLI_ghash_int_new_ex("mask ed2 gh", (uint)maxEdges);
- polyHash = BLI_ghash_int_new_ex("mask fa2 gh", (uint)maxPolys);
-
- mvert_src = mesh->mvert;
- medge_src = mesh->medge;
- mpoly_src = mesh->mpoly;
- mloop_src = mesh->mloop;
-
- /* overalloc, assume all polys are seen */
- loop_mapping = MEM_malloc_arrayN((size_t)maxPolys, sizeof(int), "mask loopmap");
-
- /* loop over edges and faces, and do the same thing to
- * ensure that they only reference existing verts
- */
- for (i = 0; i < maxEdges; i++) {
- const MEdge *me = &medge_src[i];
-
- /* only add if both verts will be in new mesh */
- if (BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v1)) &&
- BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v2))) {
- BLI_ghash_insert(edgeHash, POINTER_FROM_INT(i), POINTER_FROM_INT(numEdges));
- numEdges++;
- }
- }
- for (i = 0; i < maxPolys; i++) {
- const MPoly *mp_src = &mpoly_src[i];
- const MLoop *ml_src = &mloop_src[mp_src->loopstart];
- bool ok = true;
- int j;
-
- for (j = 0; j < mp_src->totloop; j++, ml_src++) {
- if (!BLI_ghash_haskey(vertHash, POINTER_FROM_INT(ml_src->v))) {
- ok = false;
- break;
- }
- }
-
- /* all verts must be available */
- if (ok) {
- BLI_ghash_insert(polyHash, POINTER_FROM_INT(i), POINTER_FROM_INT(numPolys));
- loop_mapping[numPolys] = numLoops;
- numPolys++;
- numLoops += mp_src->totloop;
- }
- }
-
- /* now we know the number of verts, edges and faces,
- * we can create the new (reduced) mesh
- */
- result = BKE_mesh_new_nomain_from_template(mesh, numVerts, numEdges, 0, numLoops, numPolys);
-
- mpoly_dst = result->mpoly;
- mloop_dst = result->mloop;
- medge_dst = result->medge;
- mvert_dst = result->mvert;
-
- /* using ghash-iterators, map data into new mesh */
- /* vertices */
- GHASH_ITER (gh_iter, vertHash) {
- const MVert *v_src;
- MVert *v_dst;
- const int i_src = POINTER_AS_INT(BLI_ghashIterator_getKey(&gh_iter));
- const int i_dst = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
-
- v_src = &mvert_src[i_src];
- v_dst = &mvert_dst[i_dst];
-
- *v_dst = *v_src;
- CustomData_copy_data(&mesh->vdata, &result->vdata, i_src, i_dst, 1);
- }
-
- /* edges */
- GHASH_ITER (gh_iter, edgeHash) {
- const MEdge *e_src;
- MEdge *e_dst;
- const int i_src = POINTER_AS_INT(BLI_ghashIterator_getKey(&gh_iter));
- const int i_dst = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
-
- e_src = &medge_src[i_src];
- e_dst = &medge_dst[i_dst];
-
- CustomData_copy_data(&mesh->edata, &result->edata, i_src, i_dst, 1);
- *e_dst = *e_src;
- e_dst->v1 = POINTER_AS_UINT(BLI_ghash_lookup(vertHash, POINTER_FROM_UINT(e_src->v1)));
- e_dst->v2 = POINTER_AS_UINT(BLI_ghash_lookup(vertHash, POINTER_FROM_UINT(e_src->v2)));
- }
-
- /* faces */
- GHASH_ITER (gh_iter, polyHash) {
- const int i_src = POINTER_AS_INT(BLI_ghashIterator_getKey(&gh_iter));
- const int i_dst = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
- const MPoly *mp_src = &mpoly_src[i_src];
- MPoly *mp_dst = &mpoly_dst[i_dst];
- const int i_ml_src = mp_src->loopstart;
- const int i_ml_dst = loop_mapping[i_dst];
- const MLoop *ml_src = &mloop_src[i_ml_src];
- MLoop *ml_dst = &mloop_dst[i_ml_dst];
-
- CustomData_copy_data(&mesh->pdata, &result->pdata, i_src, i_dst, 1);
- CustomData_copy_data(&mesh->ldata, &result->ldata, i_ml_src, i_ml_dst, mp_src->totloop);
-
- *mp_dst = *mp_src;
- mp_dst->loopstart = i_ml_dst;
- for (i = 0; i < mp_src->totloop; i++) {
- ml_dst[i].v = POINTER_AS_UINT(BLI_ghash_lookup(vertHash, POINTER_FROM_UINT(ml_src[i].v)));
- ml_dst[i].e = POINTER_AS_UINT(BLI_ghash_lookup(edgeHash, POINTER_FROM_UINT(ml_src[i].e)));
- }
- }
-
- MEM_freeN(loop_mapping);
-
- /* why is this needed? - campbell */
- /* recalculate normals */
- result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
-
- /* free hashes */
- BLI_ghash_free(vertHash, NULL, NULL);
- BLI_ghash_free(edgeHash, NULL, NULL);
- BLI_ghash_free(polyHash, NULL, NULL);
-
- /* return the new mesh */
- return result;
-}
-
-static bool isDisabled(const struct Scene *UNUSED(scene),
- ModifierData *md,
- bool UNUSED(useRenderParams))
-{
- MaskModifierData *mmd = (MaskModifierData *)md;
-
- /* The object type check is only needed here in case we have a placeholder
- * object assigned (because the library containing the armature is missing).
- *
- * In other cases it should be impossible to have a type mismatch.
- */
- return mmd->ob_arm && mmd->ob_arm->type != OB_ARMATURE;
-}
-
-ModifierTypeInfo modifierType_Mask = {
- /* name */ "Mask",
- /* structName */ "MaskModifierData",
- /* structSize */ sizeof(MaskModifierData),
- /* type */ eModifierTypeType_Nonconstructive,
- /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
- eModifierTypeFlag_SupportsEditmode,
-
- /* copyData */ modifier_copyData_generic,
-
- /* deformVerts */ NULL,
- /* deformMatrices */ NULL,
- /* deformVertsEM */ NULL,
- /* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
-
- /* initData */ NULL,
- /* requiredDataMask */ requiredDataMask,
- /* freeData */ NULL,
- /* isDisabled */ isDisabled,
- /* updateDepsgraph */ updateDepsgraph,
- /* dependsOnTime */ NULL,
- /* dependsOnNormals */ NULL,
- /* foreachObjectLink */ foreachObjectLink,
- /* foreachIDLink */ NULL,
- /* foreachTexLink */ NULL,
- /* freeRuntimeData */ NULL,
-};
diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc
new file mode 100644
index 00000000000..3bdb5a3fd54
--- /dev/null
+++ b/source/blender/modifiers/intern/MOD_mask.cc
@@ -0,0 +1,417 @@
+/*
+ * 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) 2005 by the Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup modifiers
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+
+#include "DNA_armature_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_action.h" /* BKE_pose_channel_find_name */
+#include "BKE_customdata.h"
+#include "BKE_deform.h"
+#include "BKE_lib_query.h"
+#include "BKE_mesh.h"
+#include "BKE_modifier.h"
+
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
+#include "MOD_modifiertypes.h"
+
+#include "BLI_array_cxx.h"
+#include "BLI_listbase_wrapper.h"
+#include "BLI_vector.h"
+
+using BLI::Array;
+using BLI::ArrayRef;
+using BLI::IndexRange;
+using BLI::IntrusiveListBaseWrapper;
+using BLI::MutableArrayRef;
+using BLI::Vector;
+
+static void requiredDataMask(Object *UNUSED(ob),
+ ModifierData *UNUSED(md),
+ CustomData_MeshMasks *r_cddata_masks)
+{
+ r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
+}
+
+static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
+{
+ MaskModifierData *mmd = (MaskModifierData *)md;
+ walk(userData, ob, &mmd->ob_arm, IDWALK_CB_NOP);
+}
+
+static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
+{
+ MaskModifierData *mmd = (MaskModifierData *)md;
+ if (mmd->ob_arm) {
+ bArmature *arm = (bArmature *)mmd->ob_arm->data;
+ /* Tag relationship in depsgraph, but also on the armature. */
+ /* TODO(sergey): Is it a proper relation here? */
+ DEG_add_object_relation(ctx->node, mmd->ob_arm, DEG_OB_COMP_TRANSFORM, "Mask Modifier");
+ arm->flag |= ARM_HAS_VIZ_DEPS;
+ DEG_add_modifier_to_transform_relation(ctx->node, "Mask Modifier");
+ }
+}
+
+/* A vertex will be in the mask if a selected bone influences it more than a certain threshold. */
+static void compute_vertex_mask__armature_mode(MDeformVert *dvert,
+ Object *ob,
+ Object *armature_ob,
+ float threshold,
+ MutableArrayRef<bool> r_vertex_mask)
+{
+ /* Element i is true if there is a selected bone that uses vertex group i. */
+ Vector<bool> selected_bone_uses_group;
+
+ for (bDeformGroup *def : IntrusiveListBaseWrapper<bDeformGroup>(ob->defbase)) {
+ bPoseChannel *pchan = BKE_pose_channel_find_name(armature_ob->pose, def->name);
+ bool bone_for_group_exists = pchan && pchan->bone && (pchan->bone->flag & BONE_SELECTED);
+ selected_bone_uses_group.append(bone_for_group_exists);
+ }
+
+ ArrayRef<bool> use_vertex_group = selected_bone_uses_group;
+
+ for (int i : r_vertex_mask.index_range()) {
+ ArrayRef<MDeformWeight> weights(dvert[i].dw, dvert[i].totweight);
+ r_vertex_mask[i] = false;
+
+ /* check the groups that vertex is assigned to, and see if it was any use */
+ for (const MDeformWeight &dw : weights) {
+ if (use_vertex_group.get(dw.def_nr, false)) {
+ if (dw.weight > threshold) {
+ r_vertex_mask[i] = true;
+ break;
+ }
+ }
+ }
+ }
+}
+
+/* A vertex will be in the mask if the vertex group influences it more than a certain threshold. */
+static void compute_vertex_mask__vertex_group_mode(MDeformVert *dvert,
+ int defgrp_index,
+ float threshold,
+ MutableArrayRef<bool> r_vertex_mask)
+{
+ for (int i : r_vertex_mask.index_range()) {
+ const bool found = BKE_defvert_find_weight(&dvert[i], defgrp_index) > threshold;
+ r_vertex_mask[i] = found;
+ }
+}
+
+static void invert_boolean_array(MutableArrayRef<bool> array)
+{
+ for (bool &value : array) {
+ value = !value;
+ }
+}
+
+static void compute_masked_vertices(ArrayRef<bool> vertex_mask,
+ MutableArrayRef<int> r_vertex_map,
+ uint *r_num_masked_vertices)
+{
+ BLI_assert(vertex_mask.size() == r_vertex_map.size());
+
+ uint num_masked_vertices = 0;
+ for (uint i_src : r_vertex_map.index_range()) {
+ if (vertex_mask[i_src]) {
+ r_vertex_map[i_src] = num_masked_vertices;
+ num_masked_vertices++;
+ }
+ else {
+ r_vertex_map[i_src] = -1;
+ }
+ }
+
+ *r_num_masked_vertices = num_masked_vertices;
+}
+
+static void computed_masked_edges(const Mesh *mesh,
+ ArrayRef<bool> vertex_mask,
+ MutableArrayRef<int> r_edge_map,
+ uint *r_num_masked_edges)
+{
+ BLI_assert(mesh->totedge == r_edge_map.size());
+
+ uint num_masked_edges = 0;
+ for (int i : IndexRange(mesh->totedge)) {
+ const MEdge &edge = mesh->medge[i];
+
+ /* only add if both verts will be in new mesh */
+ if (vertex_mask[edge.v1] && vertex_mask[edge.v2]) {
+ r_edge_map[i] = num_masked_edges;
+ num_masked_edges++;
+ }
+ else {
+ r_edge_map[i] = -1;
+ }
+ }
+
+ *r_num_masked_edges = num_masked_edges;
+}
+
+static void computed_masked_polygons(const Mesh *mesh,
+ ArrayRef<bool> vertex_mask,
+ Vector<int> &r_masked_poly_indices,
+ Vector<int> &r_loop_starts,
+ uint *r_num_masked_polys,
+ uint *r_num_masked_loops)
+{
+ BLI_assert(mesh->totvert == vertex_mask.size());
+
+ r_masked_poly_indices.reserve(mesh->totpoly);
+ r_loop_starts.reserve(mesh->totloop);
+
+ uint num_masked_loops = 0;
+ for (int i : IndexRange(mesh->totpoly)) {
+ const MPoly &poly_src = mesh->mpoly[i];
+
+ bool all_verts_in_mask = true;
+ ArrayRef<MLoop> loops_src(&mesh->mloop[poly_src.loopstart], poly_src.totloop);
+ for (const MLoop &loop : loops_src) {
+ if (!vertex_mask[loop.v]) {
+ all_verts_in_mask = false;
+ break;
+ }
+ }
+
+ if (all_verts_in_mask) {
+ r_masked_poly_indices.append_unchecked(i);
+ r_loop_starts.append_unchecked(num_masked_loops);
+ num_masked_loops += poly_src.totloop;
+ }
+ }
+
+ *r_num_masked_polys = r_masked_poly_indices.size();
+ *r_num_masked_loops = num_masked_loops;
+}
+
+static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh,
+ Mesh &dst_mesh,
+ ArrayRef<int> vertex_map)
+{
+ BLI_assert(src_mesh.totvert == vertex_map.size());
+ for (const int i_src : vertex_map.index_range()) {
+ const int i_dst = vertex_map[i_src];
+ if (i_dst == -1) {
+ continue;
+ }
+
+ const MVert &v_src = src_mesh.mvert[i_src];
+ MVert &v_dst = dst_mesh.mvert[i_dst];
+
+ v_dst = v_src;
+ CustomData_copy_data(&src_mesh.vdata, &dst_mesh.vdata, i_src, i_dst, 1);
+ }
+}
+
+static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh,
+ Mesh &dst_mesh,
+ ArrayRef<int> vertex_map,
+ ArrayRef<int> edge_map)
+{
+ BLI_assert(src_mesh.totvert == vertex_map.size());
+ BLI_assert(src_mesh.totedge == edge_map.size());
+ for (const int i_src : IndexRange(src_mesh.totedge)) {
+ const int i_dst = edge_map[i_src];
+ if (i_dst == -1) {
+ continue;
+ }
+
+ const MEdge &e_src = src_mesh.medge[i_src];
+ MEdge &e_dst = dst_mesh.medge[i_dst];
+
+ CustomData_copy_data(&src_mesh.edata, &dst_mesh.edata, i_src, i_dst, 1);
+ e_dst = e_src;
+ e_dst.v1 = vertex_map[e_src.v1];
+ e_dst.v2 = vertex_map[e_src.v2];
+ }
+}
+
+static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh,
+ Mesh &dst_mesh,
+ ArrayRef<int> vertex_map,
+ ArrayRef<int> edge_map,
+ ArrayRef<int> masked_poly_indices,
+ ArrayRef<int> new_loop_starts)
+{
+ for (const int i_dst : masked_poly_indices.index_range()) {
+ const int i_src = masked_poly_indices[i_dst];
+
+ const MPoly &mp_src = src_mesh.mpoly[i_src];
+ MPoly &mp_dst = dst_mesh.mpoly[i_dst];
+ const int i_ml_src = mp_src.loopstart;
+ const int i_ml_dst = new_loop_starts[i_dst];
+
+ CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1);
+ CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src, i_ml_dst, mp_src.totloop);
+
+ const MLoop *ml_src = src_mesh.mloop + i_ml_src;
+ MLoop *ml_dst = dst_mesh.mloop + i_ml_dst;
+
+ mp_dst = mp_src;
+ mp_dst.loopstart = i_ml_dst;
+ for (int i : IndexRange(mp_src.totloop)) {
+ ml_dst[i].v = vertex_map[ml_src[i].v];
+ ml_dst[i].e = edge_map[ml_src[i].e];
+ }
+ }
+}
+
+/* Components of the algorithm:
+ * 1. Figure out which vertices should be present in the output mesh.
+ * 2. Find edges and polygons only using those vertices.
+ * 3. Create a new mesh that only uses the found vertices, edges and polygons.
+ */
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
+{
+ MaskModifierData *mmd = (MaskModifierData *)md;
+ Object *ob = ctx->object;
+ const bool invert_mask = mmd->flag & MOD_MASK_INV;
+
+ /* Return empty or input mesh when there are no vertex groups. */
+ MDeformVert *dvert = (MDeformVert *)CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
+ if (dvert == NULL) {
+ return invert_mask ? mesh : BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0);
+ }
+
+ /* Quick test to see if we can return early. */
+ if (!(ELEM(mmd->mode, MOD_MASK_MODE_ARM, MOD_MASK_MODE_VGROUP)) || (mesh->totvert == 0) ||
+ BLI_listbase_is_empty(&ob->defbase)) {
+ return mesh;
+ }
+
+ Array<bool> vertex_mask;
+ if (mmd->mode == MOD_MASK_MODE_ARM) {
+ Object *armature_ob = mmd->ob_arm;
+
+ /* Return input mesh if there is no armature with bones. */
+ if (ELEM(NULL, armature_ob, armature_ob->pose, ob->defbase.first)) {
+ return mesh;
+ }
+
+ vertex_mask = Array<bool>(mesh->totvert);
+ compute_vertex_mask__armature_mode(dvert, ob, armature_ob, mmd->threshold, vertex_mask);
+ }
+ else {
+ int defgrp_index = BKE_object_defgroup_name_index(ob, mmd->vgroup);
+
+ /* Return input mesh if the vertex group does not exist. */
+ if (defgrp_index == -1) {
+ return mesh;
+ }
+
+ vertex_mask = Array<bool>(mesh->totvert);
+ compute_vertex_mask__vertex_group_mode(dvert, defgrp_index, mmd->threshold, vertex_mask);
+ }
+
+ if (invert_mask) {
+ invert_boolean_array(vertex_mask);
+ }
+
+ Array<int> vertex_map(mesh->totvert);
+ uint num_masked_vertices;
+ compute_masked_vertices(vertex_mask, vertex_map, &num_masked_vertices);
+
+ Array<int> edge_map(mesh->totedge);
+ uint num_masked_edges;
+ computed_masked_edges(mesh, vertex_mask, edge_map, &num_masked_edges);
+
+ Vector<int> masked_poly_indices;
+ Vector<int> new_loop_starts;
+ uint num_masked_polys;
+ uint num_masked_loops;
+ computed_masked_polygons(mesh,
+ vertex_mask,
+ masked_poly_indices,
+ new_loop_starts,
+ &num_masked_polys,
+ &num_masked_loops);
+
+ Mesh *result = BKE_mesh_new_nomain_from_template(
+ mesh, num_masked_vertices, num_masked_edges, 0, num_masked_loops, num_masked_polys);
+
+ copy_masked_vertices_to_new_mesh(*mesh, *result, vertex_map);
+ copy_masked_edges_to_new_mesh(*mesh, *result, vertex_map, edge_map);
+ copy_masked_polys_to_new_mesh(
+ *mesh, *result, vertex_map, edge_map, masked_poly_indices, new_loop_starts);
+
+ /* Tag to recalculate normals later. */
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+
+ return result;
+}
+
+static bool isDisabled(const struct Scene *UNUSED(scene),
+ ModifierData *md,
+ bool UNUSED(useRenderParams))
+{
+ MaskModifierData *mmd = (MaskModifierData *)md;
+
+ /* The object type check is only needed here in case we have a placeholder
+ * object assigned (because the library containing the armature is missing).
+ *
+ * In other cases it should be impossible to have a type mismatch.
+ */
+ return mmd->ob_arm && mmd->ob_arm->type != OB_ARMATURE;
+}
+
+ModifierTypeInfo modifierType_Mask = {
+ /* name */ "Mask",
+ /* structName */ "MaskModifierData",
+ /* structSize */ sizeof(MaskModifierData),
+ /* type */ eModifierTypeType_Nonconstructive,
+ /* flags */
+ (ModifierTypeFlag)(eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
+ eModifierTypeFlag_SupportsEditmode),
+
+ /* copyData */ modifier_copyData_generic,
+
+ /* deformVerts */ NULL,
+ /* deformMatrices */ NULL,
+ /* deformVertsEM */ NULL,
+ /* deformMatricesEM */ NULL,
+ /* applyModifier */ applyModifier,
+
+ /* initData */ NULL,
+ /* requiredDataMask */ requiredDataMask,
+ /* freeData */ NULL,
+ /* isDisabled */ isDisabled,
+ /* updateDepsgraph */ updateDepsgraph,
+ /* dependsOnTime */ NULL,
+ /* dependsOnNormals */ NULL,
+ /* foreachObjectLink */ foreachObjectLink,
+ /* foreachIDLink */ NULL,
+ /* foreachTexLink */ NULL,
+ /* freeRuntimeData */ NULL,
+};
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index e01f07584ee..c2cbddf806c 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -26,10 +26,10 @@
#include "BLI_path_util.h"
#include "BLI_string.h"
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
diff --git a/source/blender/modifiers/intern/MOD_meshcache_mdd.c b/source/blender/modifiers/intern/MOD_meshcache_mdd.c
index a3ab0120ff9..60376f61708 100644
--- a/source/blender/modifiers/intern/MOD_meshcache_mdd.c
+++ b/source/blender/modifiers/intern/MOD_meshcache_mdd.c
@@ -18,9 +18,9 @@
* \ingroup modifiers
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include "BLI_utildefines.h"
@@ -155,12 +155,12 @@ bool MOD_meshcache_read_mdd_index(FILE *fp,
return false;
}
- if (fseek(fp, mdd_head.frame_tot * sizeof(int), SEEK_CUR) != 0) {
+ if (BLI_fseek(fp, mdd_head.frame_tot * sizeof(int), SEEK_CUR) != 0) {
*err_str = "Header seek failed";
return false;
}
- if (fseek(fp, sizeof(float) * 3 * index * mdd_head.verts_tot, SEEK_CUR) != 0) {
+ if (BLI_fseek(fp, sizeof(float) * 3 * index * mdd_head.verts_tot, SEEK_CUR) != 0) {
*err_str = "Failed to seek frame";
return false;
}
@@ -234,7 +234,7 @@ bool MOD_meshcache_read_mdd_frame(FILE *fp,
if (index_range[0] == index_range[1]) {
/* read single */
- if ((fseek(fp, 0, SEEK_SET) == 0) &&
+ if ((BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_mdd_index(fp, vertexCos, verts_tot, index_range[0], 1.0f, err_str)) {
return true;
}
@@ -244,9 +244,9 @@ bool MOD_meshcache_read_mdd_frame(FILE *fp,
}
else {
/* read both and interpolate */
- if ((fseek(fp, 0, SEEK_SET) == 0) &&
+ if ((BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_mdd_index(fp, vertexCos, verts_tot, index_range[0], 1.0f, err_str) &&
- (fseek(fp, 0, SEEK_SET) == 0) &&
+ (BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_mdd_index(fp, vertexCos, verts_tot, index_range[1], factor, err_str)) {
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_meshcache_pc2.c b/source/blender/modifiers/intern/MOD_meshcache_pc2.c
index 7b8ad0bd705..60011458c67 100644
--- a/source/blender/modifiers/intern/MOD_meshcache_pc2.c
+++ b/source/blender/modifiers/intern/MOD_meshcache_pc2.c
@@ -18,9 +18,9 @@
* \ingroup modifiers
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include "BLI_utildefines.h"
@@ -146,7 +146,7 @@ bool MOD_meshcache_read_pc2_index(FILE *fp,
return false;
}
- if (fseek(fp, sizeof(float) * 3 * index * pc2_head.verts_tot, SEEK_CUR) != 0) {
+ if (BLI_fseek(fp, sizeof(float) * 3 * index * pc2_head.verts_tot, SEEK_CUR) != 0) {
*err_str = "Failed to seek frame";
return false;
}
@@ -209,7 +209,7 @@ bool MOD_meshcache_read_pc2_frame(FILE *fp,
if (index_range[0] == index_range[1]) {
/* read single */
- if ((fseek(fp, 0, SEEK_SET) == 0) &&
+ if ((BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_pc2_index(fp, vertexCos, verts_tot, index_range[0], 1.0f, err_str)) {
return true;
}
@@ -219,9 +219,9 @@ bool MOD_meshcache_read_pc2_frame(FILE *fp,
}
else {
/* read both and interpolate */
- if ((fseek(fp, 0, SEEK_SET) == 0) &&
+ if ((BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_pc2_index(fp, vertexCos, verts_tot, index_range[0], 1.0f, err_str) &&
- (fseek(fp, 0, SEEK_SET) == 0) &&
+ (BLI_fseek(fp, 0, SEEK_SET) == 0) &&
MOD_meshcache_read_pc2_index(fp, vertexCos, verts_tot, index_range[1], factor, err_str)) {
return true;
}
diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c
index 21fdc010a1d..7125d0df3a1 100644
--- a/source/blender/modifiers/intern/MOD_meshdeform.c
+++ b/source/blender/modifiers/intern/MOD_meshdeform.c
@@ -31,14 +31,14 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "BKE_deform.h"
+#include "BKE_editmesh.h"
#include "BKE_global.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
-#include "BKE_deform.h"
-#include "BKE_editmesh.h"
#include "MEM_guardedalloc.h"
@@ -284,7 +284,7 @@ static void meshdeform_vert_task(void *__restrict userdata,
}
if (dvert) {
- fac = defvert_find_weight(&dvert[iter], defgrp_index);
+ fac = BKE_defvert_find_weight(&dvert[iter], defgrp_index);
if (mmd->flag & MOD_MDEF_INVERT_VGROUP) {
fac = 1.0f - fac;
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index 0f57b759e38..7357f18eb6a 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -20,8 +20,8 @@
#include <string.h>
-#include "BLI_utildefines.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
#include "DNA_cachefile_types.h"
#include "DNA_mesh_types.h"
@@ -31,7 +31,7 @@
#include "DNA_scene_types.h"
#include "BKE_cachefile.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_scene.h"
#include "DEG_depsgraph_build.h"
@@ -42,7 +42,7 @@
#ifdef WITH_ALEMBIC
# include "ABC_alembic.h"
# include "BKE_global.h"
-# include "BKE_library.h"
+# include "BKE_lib_id.h"
#endif
static void initData(ModifierData *md)
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c
index fe3e608fcbe..3b3dfa2bda2 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/modifiers/intern/MOD_mirror.c
@@ -27,12 +27,12 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_deform.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mirror.h"
#include "BKE_modifier.h"
-#include "BKE_deform.h"
#include "bmesh.h"
#include "bmesh_tools.h"
diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c
index 883c17aa1e1..ad8e0a9f259 100644
--- a/source/blender/modifiers/intern/MOD_multires.c
+++ b/source/blender/modifiers/intern/MOD_multires.c
@@ -33,8 +33,8 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_mesh.h"
-#include "BKE_multires.h"
#include "BKE_modifier.h"
+#include "BKE_multires.h"
#include "BKE_paint.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_ccg.h"
@@ -60,8 +60,8 @@ static void initData(ModifierData *md)
mmd->renderlvl = 0;
mmd->totlvl = 0;
mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
- mmd->quality = 3;
- mmd->flags |= eMultiresModifierFlag_UseCrease;
+ mmd->quality = 4;
+ mmd->flags |= (eMultiresModifierFlag_UseCrease | eMultiresModifierFlag_ControlEdges);
}
static void copyData(const ModifierData *md_src, ModifierData *md_dst, const int flag)
@@ -119,11 +119,17 @@ static Mesh *multires_as_mesh(MultiresModifierData *mmd,
Mesh *result = mesh;
const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER);
const bool ignore_simplify = (ctx->flag & MOD_APPLY_IGNORE_SIMPLIFY);
+ const bool ignore_control_edges = (ctx->flag & MOD_APPLY_TO_BASE_MESH);
const Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
Object *object = ctx->object;
SubdivToMeshSettings mesh_settings;
- BKE_multires_subdiv_mesh_settings_init(
- &mesh_settings, scene, object, mmd, use_render_params, ignore_simplify);
+ BKE_multires_subdiv_mesh_settings_init(&mesh_settings,
+ scene,
+ object,
+ mmd,
+ use_render_params,
+ ignore_simplify,
+ ignore_control_edges);
if (mesh_settings.resolution < 3) {
return result;
}
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c
index 10852ed6148..0b101b26906 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.c
+++ b/source/blender/modifiers/intern/MOD_normal_edit.c
@@ -27,14 +27,14 @@
#include "BLI_bitmap.h"
#include "BLI_math.h"
-#include "DNA_object_types.h"
-#include "DNA_meshdata_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
-#include "BKE_mesh.h"
#include "BKE_deform.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
+#include "BKE_mesh.h"
#include "DEG_depsgraph_query.h"
@@ -494,7 +494,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
if (!(((Mesh *)ob->data)->flag & ME_AUTOSMOOTH))
#endif
{
- modifier_setError((ModifierData *)enmd, "Enable 'Auto Smooth' option in mesh settings");
+ modifier_setError((ModifierData *)enmd, "Enable 'Auto Smooth' in Object Data Properties");
return mesh;
}
@@ -502,7 +502,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
if (mesh->medge == ((Mesh *)ob->data)->medge) {
/* We need to duplicate data here, otherwise setting custom normals
* (which may also affect sharp edges) could
- * modify org mesh, see T43671. */
+ * modify original mesh, see T43671. */
BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
}
else {
@@ -527,18 +527,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
float(*polynors)[3];
CustomData *ldata = &result->ldata;
- if (CustomData_has_layer(ldata, CD_NORMAL)) {
- loopnors = CustomData_get_layer(ldata, CD_NORMAL);
- }
- else {
- loopnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, num_loops);
- }
/* Compute poly (always needed) and vert normals. */
CustomData *pdata = &result->pdata;
polynors = CustomData_get_layer(pdata, CD_NORMAL);
if (!polynors) {
polynors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, num_polys);
+ CustomData_set_layer_flag(pdata, CD_NORMAL, CD_FLAG_TEMPORARY);
}
BKE_mesh_calc_normals_poly(mvert,
NULL,
@@ -552,8 +547,10 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
result->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
+ clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
if (use_current_clnors) {
clnors = CustomData_duplicate_referenced_layer(ldata, CD_CUSTOMLOOPNORMAL, num_loops);
+ loopnors = MEM_malloc_arrayN((size_t)num_loops, sizeof(*loopnors), __func__);
BKE_mesh_normals_loop_split(mvert,
num_verts,
@@ -572,7 +569,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
NULL);
}
- if (!clnors) {
+ if (clnors == NULL) {
clnors = CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops);
}
@@ -625,6 +622,10 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
num_polys);
}
+ /* Currently Modifier stack assumes there is no poly normal data passed around... */
+ CustomData_free_layers(pdata, CD_NORMAL, num_polys);
+ MEM_SAFE_FREE(loopnors);
+
return result;
}
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 97be42367d4..fddfc74f267 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -28,13 +28,13 @@
#include "BLI_task.h"
#include "DNA_customdata_types.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_ocean.h"
@@ -92,6 +92,10 @@ static void initData(ModifierData *md)
omd->seed = 0;
omd->time = 1.0;
+ omd->spectrum = MOD_OCEAN_SPECTRUM_PHILLIPS;
+ omd->sharpen_peak_jonswap = 0.0f;
+ omd->fetch_jonswap = 120.0f;
+
omd->size = 1.0;
omd->repeat_x = 1;
omd->repeat_y = 1;
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index f4c2e78d1ac..8a4468ec91e 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -25,8 +25,8 @@
#include "BLI_utildefines.h"
-#include "BLI_math.h"
#include "BLI_listbase.h"
+#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_string.h"
@@ -35,7 +35,7 @@
#include "BKE_effect.h"
#include "BKE_lattice.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c
index 67a64921bbc..e6229e27e4b 100644
--- a/source/blender/modifiers/intern/MOD_particlesystem.c
+++ b/source/blender/modifiers/intern/MOD_particlesystem.c
@@ -29,8 +29,8 @@
#include "DNA_mesh_types.h"
#include "BKE_editmesh.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
-#include "BKE_library.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index df84f3db55c..3300cda947c 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -26,10 +26,10 @@
#include "BLI_math_base.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
-#include "DNA_mesh_types.h"
#include "MOD_modifiertypes.h"
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 773cbf72d5b..8921ddb894f 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -26,21 +26,21 @@
#include "BLI_utildefines.h"
-#include "BLI_math.h"
#include "BLI_alloca.h"
+#include "BLI_math.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
-#include "MOD_modifiertypes.h"
#include "MEM_guardedalloc.h"
+#include "MOD_modifiertypes.h"
#include "BLI_strict_flags.h"
@@ -112,7 +112,7 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
const float axis_offset[3],
const float merge_threshold)
{
- const float merge_threshold_sq = SQUARE(merge_threshold);
+ const float merge_threshold_sq = square_f(merge_threshold);
const bool use_offset = axis_offset != NULL;
uint tot_doubles = 0;
for (uint i = 0; i < totvert; i += 1) {
@@ -1090,7 +1090,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
/* validate loop edges */
#if 0
{
- unsigned i = 0;
+ uint i = 0;
printf("\n");
for (; i < maxPolys * 4; i += 4) {
uint ii;
diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c
index 69db6f5565d..25f702bf696 100644
--- a/source/blender/modifiers/intern/MOD_shapekey.c
+++ b/source/blender/modifiers/intern/MOD_shapekey.c
@@ -25,8 +25,8 @@
#include "BLI_math.h"
-#include "DNA_mesh_types.h"
#include "DNA_key_types.h"
+#include "DNA_mesh_types.h"
#include "BKE_key.h"
#include "BKE_particle.h"
diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c
index 6e4b0edb004..842ec46f364 100644
--- a/source/blender/modifiers/intern/MOD_shrinkwrap.c
+++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c
@@ -29,8 +29,8 @@
#include "DNA_object_types.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_shrinkwrap.h"
@@ -136,12 +136,17 @@ static void deformVertsEM(ModifierData *md,
{
ShrinkwrapModifierData *swmd = (ShrinkwrapModifierData *)md;
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
- Mesh *mesh_src = MOD_deform_mesh_eval_get(
- ctx->object, editData, mesh, NULL, numVerts, false, false);
+ Mesh *mesh_src = NULL;
+
+ if ((swmd->vgroup_name[0] != '\0') || (swmd->shrinkType == MOD_SHRINKWRAP_PROJECT)) {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
+ }
struct MDeformVert *dvert = NULL;
int defgrp_index = -1;
- MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index);
+ if (swmd->vgroup_name[0] != '\0') {
+ MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index);
+ }
shrinkwrapModifier_deform(
swmd, ctx, scene, ctx->object, mesh_src, dvert, defgrp_index, vertexCos, numVerts);
diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c
index d10d74da453..65ea6b95824 100644
--- a/source/blender/modifiers/intern/MOD_simpledeform.c
+++ b/source/blender/modifiers/intern/MOD_simpledeform.c
@@ -29,12 +29,12 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
+#include "BKE_deform.h"
#include "BKE_editmesh.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "BKE_deform.h"
#include "DEG_depsgraph_query.h"
@@ -316,7 +316,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd,
axis_map_table[(smd->mode != MOD_SIMPLEDEFORM_MODE_BEND) ? deform_axis : 2];
for (i = 0; i < numVerts; i++) {
- float weight = defvert_array_find_weight_safe(dvert, i, vgroup);
+ float weight = BKE_defvert_array_find_weight_safe(dvert, i, vgroup);
if (invert_vgroup) {
weight = 1.0f - weight;
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index 6e7a0b0dbae..ec7c2b5b1a4 100644
--- a/source/blender/modifiers/intern/MOD_skin.c
+++ b/source/blender/modifiers/intern/MOD_skin.c
@@ -63,11 +63,11 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
#include "BKE_deform.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_modifier.h"
@@ -943,7 +943,7 @@ static Mesh *subdivide_base(Mesh *orig)
weight = interpf(vg->w2, vg->w1, t);
if (weight > 0) {
- defvert_add_index_notest(&outdvert[v], vg->def_nr, weight);
+ BKE_defvert_add_index_notest(&outdvert[v], vg->def_nr, weight);
}
}
@@ -1058,7 +1058,7 @@ static void output_frames(BMesh *bm, SkinNode *sn, const MDeformVert *input_dver
dv = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MDEFORMVERT);
BLI_assert(dv->totweight == 0);
- defvert_copy(dv, input_dvert);
+ BKE_defvert_copy(dv, input_dvert);
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c
index c8bc3aaa484..2a0376fd291 100644
--- a/source/blender/modifiers/intern/MOD_smooth.c
+++ b/source/blender/modifiers/intern/MOD_smooth.c
@@ -30,11 +30,11 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_particle.h"
-#include "BKE_deform.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
@@ -101,6 +101,7 @@ static void smoothModifier_do(
const float fac_new = smd->fac;
const float fac_orig = 1.0f - fac_new;
+ const bool invert_vgroup = (smd->flag & MOD_SMOOTH_INVERT_VGROUP) != 0;
MEdge *medges = mesh->medge;
const int num_edges = mesh->totedge;
@@ -139,7 +140,9 @@ static void smoothModifier_do(
}
float *vco_new = accumulated_vecs[i];
- const float f_new = defvert_find_weight(dv, defgrp_index) * fac_new;
+ const float f_new = invert_vgroup ?
+ (1.0f - BKE_defvert_find_weight(dv, defgrp_index)) * fac_new :
+ BKE_defvert_find_weight(dv, defgrp_index) * fac_new;
if (f_new <= 0.0f) {
continue;
}
diff --git a/source/blender/modifiers/intern/MOD_softbody.c b/source/blender/modifiers/intern/MOD_softbody.c
index 48ccd9b83ed..efe6b188fa0 100644
--- a/source/blender/modifiers/intern/MOD_softbody.c
+++ b/source/blender/modifiers/intern/MOD_softbody.c
@@ -25,9 +25,9 @@
#include "BLI_utildefines.h"
-#include "DNA_scene_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_force_types.h"
+#include "DNA_scene_types.h"
#include "BKE_layer.h"
#include "BKE_particle.h"
@@ -69,6 +69,8 @@ static void updateDepsgraph(ModifierData *UNUSED(md), const ModifierUpdateDepsgr
DEG_add_forcefield_relations(
ctx->node, ctx->object, ctx->object->soft->effector_weights, true, 0, "Softbody Field");
}
+ /* We need own transformation as well. */
+ DEG_add_modifier_to_transform_relation(ctx->node, "SoftBody Modifier");
}
ModifierTypeInfo modifierType_Softbody = {
@@ -77,7 +79,8 @@ ModifierTypeInfo modifierType_Softbody = {
/* structSize */ sizeof(SoftbodyModifierData),
/* type */ eModifierTypeType_OnlyDeform,
/* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsLattice |
- eModifierTypeFlag_RequiresOriginalData | eModifierTypeFlag_Single,
+ eModifierTypeFlag_RequiresOriginalData | eModifierTypeFlag_Single |
+ eModifierTypeFlag_UsesPointCache,
/* copyData */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 8ea0a602b65..41852272787 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -70,11 +70,13 @@ static void requiredDataMask(Object *UNUSED(ob),
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
const SolidifyModifierData *smd = (SolidifyModifierData *)md;
- if (smd->mode == MOD_SOLIDIFY_MODE_EXTRUDE) {
- return MOD_solidify_extrude_applyModifier(md, ctx, mesh);
- }
- else if (smd->mode == MOD_SOLIDIFY_MODE_NONMANIFOLD) {
- return MOD_solidify_nonmanifold_applyModifier(md, ctx, mesh);
+ switch (smd->mode) {
+ case MOD_SOLIDIFY_MODE_EXTRUDE:
+ return MOD_solidify_extrude_applyModifier(md, ctx, mesh);
+ case MOD_SOLIDIFY_MODE_NONMANIFOLD:
+ return MOD_solidify_nonmanifold_applyModifier(md, ctx, mesh);
+ default:
+ BLI_assert(0);
}
return mesh;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c
index 8c5a2551c0b..8febf78fef5 100644
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@ -29,13 +29,13 @@
#include "MEM_guardedalloc.h"
+#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "BKE_particle.h"
-#include "BKE_deform.h"
#include "MOD_modifiertypes.h"
-#include "MOD_util.h"
#include "MOD_solidify_util.h" /* own include */
+#include "MOD_util.h"
#ifdef __GNUC__
# pragma GCC diagnostic error "-Wsign-conversion"
@@ -578,10 +578,10 @@ Mesh *MOD_solidify_extrude_applyModifier(ModifierData *md,
if (dvert) {
MDeformVert *dv = &dvert[i];
if (defgrp_invert) {
- scalar_short_vgroup = 1.0f - defvert_find_weight(dv, defgrp_index);
+ scalar_short_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
}
else {
- scalar_short_vgroup = defvert_find_weight(dv, defgrp_index);
+ scalar_short_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
}
scalar_short_vgroup = (offset_fac_vg + (scalar_short_vgroup * offset_fac_vg_inv)) *
scalar_short;
@@ -625,10 +625,10 @@ Mesh *MOD_solidify_extrude_applyModifier(ModifierData *md,
if (dvert) {
MDeformVert *dv = &dvert[i];
if (defgrp_invert) {
- scalar_short_vgroup = 1.0f - defvert_find_weight(dv, defgrp_index);
+ scalar_short_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
}
else {
- scalar_short_vgroup = defvert_find_weight(dv, defgrp_index);
+ scalar_short_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
}
scalar_short_vgroup = (offset_fac_vg + (scalar_short_vgroup * offset_fac_vg_inv)) *
scalar_short;
@@ -740,14 +740,14 @@ Mesh *MOD_solidify_extrude_applyModifier(ModifierData *md,
if (defgrp_invert) {
for (i = 0; i < numVerts; i++, dv++) {
- scalar = 1.0f - defvert_find_weight(dv, defgrp_index);
+ scalar = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
scalar = offset_fac_vg + (scalar * offset_fac_vg_inv);
vert_angles[i] *= scalar;
}
}
else {
for (i = 0; i < numVerts; i++, dv++) {
- scalar = defvert_find_weight(dv, defgrp_index);
+ scalar = BKE_defvert_find_weight(dv, defgrp_index);
scalar = offset_fac_vg + (scalar * offset_fac_vg_inv);
vert_angles[i] *= scalar;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index 799c1c966a3..22fc56bdeaf 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -27,13 +27,13 @@
#include "MEM_guardedalloc.h"
+#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "BKE_particle.h"
-#include "BKE_deform.h"
#include "MOD_modifiertypes.h"
-#include "MOD_util.h"
#include "MOD_solidify_util.h" /* Own include. */
+#include "MOD_util.h"
#ifdef __GNUC__
# pragma GCC diagnostic error "-Wsign-conversion"
@@ -243,6 +243,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
if (mp->totloop > largest_ngon) {
largest_ngon = (uint)mp->totloop;
}
+ /* add to final mesh face count */
if (do_shell) {
numNewPolys += 2;
numNewLoops += (uint)mp->totloop * 2;
@@ -272,7 +273,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
/* Edge groups for every original vert. */
EdgeGroup **orig_vert_groups_arr = MEM_calloc_arrayN(
numVerts, sizeof(*orig_vert_groups_arr), "orig_vert_groups_arr in solidify");
- /* Duplicate verts map. */
+ /* vertex map used to map duplicates. */
uint *vm = MEM_malloc_arrayN(numVerts, sizeof(*vm), "orig_vert_map in solidify");
for (uint i = 0; i < numVerts; i++) {
vm[i] = i;
@@ -285,8 +286,6 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
bool has_singularities = false;
/* Vert edge adjacent map. */
- uint *vert_adj_edges_len = MEM_calloc_arrayN(
- numVerts, sizeof(*vert_adj_edges_len), "vert_adj_edges_len in solidify");
OldVertEdgeRef **vert_adj_edges = MEM_calloc_arrayN(
numVerts, sizeof(*vert_adj_edges), "vert_adj_edges in solidify");
@@ -309,15 +308,15 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
BLI_assert(len > 0);
uint *adj_faces = MEM_malloc_arrayN(
len, sizeof(*adj_faces), "OldEdgeFaceRef::faces in solidify");
- bool *adj_faces_loops_reversed = MEM_malloc_arrayN(
- len, sizeof(*adj_faces_loops_reversed), "OldEdgeFaceRef::reversed in solidify");
+ bool *adj_faces_reversed = MEM_malloc_arrayN(
+ len, sizeof(*adj_faces_reversed), "OldEdgeFaceRef::reversed in solidify");
adj_faces[0] = i;
for (uint k = 1; k < len; k++) {
adj_faces[k] = MOD_SOLIDIFY_EMPTY_TAG;
}
- adj_faces_loops_reversed[0] = reversed;
+ adj_faces_reversed[0] = reversed;
OldEdgeFaceRef *ref = MEM_mallocN(sizeof(*ref), "OldEdgeFaceRef in solidify");
- *ref = (OldEdgeFaceRef){adj_faces, len, adj_faces_loops_reversed, 1};
+ *ref = (OldEdgeFaceRef){adj_faces, len, adj_faces_reversed, 1};
edge_adj_faces[edge] = ref;
}
else {
@@ -334,11 +333,14 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
float edgedir[3] = {0, 0, 0};
+ uint *vert_adj_edges_len = MEM_calloc_arrayN(
+ numVerts, sizeof(*vert_adj_edges_len), "vert_adj_edges_len in solidify");
/* Calculate edge lengths and len vert_adj edges. */
{
bool *face_singularity = MEM_calloc_arrayN(
numPolys, sizeof(*face_singularity), "face_sides_arr in solidify");
+
ed = orig_medge;
for (uint i = 0; i < numEdges; i++, ed++) {
if (edge_adj_faces_len[i] > 0) {
@@ -347,63 +349,82 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
if (v1 != v2) {
sub_v3_v3v3(edgedir, orig_mvert[v2].co, orig_mvert[v1].co);
orig_edge_lengths[i] = len_squared_v3(edgedir);
- }
- if (v1 == v2 || orig_edge_lengths[i] <= FLT_EPSILON) {
- if (v2 > v1) {
- for (uint j = v2; j < numVerts; j++) {
- if (vm[j] == v2) {
- vm[j] = v1;
- vert_adj_edges_len[v1] += vert_adj_edges_len[j];
- vert_adj_edges_len[j] = 0;
+ if (orig_edge_lengths[i] <= FLT_EPSILON) {
+ if (v2 > v1) {
+ for (uint j = v2; j < numVerts; j++) {
+ if (vm[j] == v2) {
+ vm[j] = v1;
+ vert_adj_edges_len[v1] += vert_adj_edges_len[j];
+ vert_adj_edges_len[j] = 0;
+ }
}
}
- }
- else if (v2 < v1) {
- for (uint j = v1; j < numVerts; j++) {
- if (vm[j] == v1) {
- vm[j] = v2;
- vert_adj_edges_len[v2] += vert_adj_edges_len[j];
- vert_adj_edges_len[j] = 0;
+ else if (v2 < v1) {
+ for (uint j = v1; j < numVerts; j++) {
+ if (vm[j] == v1) {
+ vm[j] = v2;
+ vert_adj_edges_len[v2] += vert_adj_edges_len[j];
+ vert_adj_edges_len[j] = 0;
+ }
}
}
+ if (do_shell) {
+ numNewLoops -= edge_adj_faces_len[i] * 2;
+ }
+
+ edge_adj_faces_len[i] = 0;
+ MEM_freeN(edge_adj_faces[i]->faces);
+ MEM_freeN(edge_adj_faces[i]->faces_reversed);
+ MEM_freeN(edge_adj_faces[i]);
+ edge_adj_faces[i] = NULL;
}
- if (do_shell) {
- numNewLoops -= edge_adj_faces_len[i] * 2;
+ else {
+ orig_edge_lengths[i] = sqrtf(orig_edge_lengths[i]);
+ vert_adj_edges_len[v1]++;
+ vert_adj_edges_len[v2]++;
}
- if (v1 == v2) {
- /* Remove polys. */
- for (uint j = 0; j < edge_adj_faces[i]->faces_len; j++) {
- const uint face = edge_adj_faces[i]->faces[j];
- if (!face_singularity[face]) {
- bool is_singularity = true;
- for (uint k = 0; k < orig_mpoly[face].totloop; k++) {
- if (vm[orig_mloop[((uint)orig_mpoly[face].loopstart) + k].v] != v1) {
- is_singularity = false;
- break;
- }
- }
- if (is_singularity) {
- face_singularity[face] = true;
- if (do_shell) {
- numNewPolys -= 2;
- }
- }
+ }
+ }
+ }
+ /* remove zero faces in a second pass */
+ ed = orig_medge;
+ for (uint i = 0; i < numEdges; i++, ed++) {
+ const uint v1 = vm[ed->v1];
+ const uint v2 = vm[ed->v2];
+ if (v1 == v2 && edge_adj_faces[i]) {
+ /* Remove polys. */
+ for (uint j = 0; j < edge_adj_faces[i]->faces_len; j++) {
+ const uint face = edge_adj_faces[i]->faces[j];
+ if (!face_singularity[face]) {
+ bool is_singularity = true;
+ for (uint k = 0; k < orig_mpoly[face].totloop; k++) {
+ if (vm[orig_mloop[((uint)orig_mpoly[face].loopstart) + k].v] != v1) {
+ is_singularity = false;
+ break;
+ }
+ }
+ if (is_singularity) {
+ face_singularity[face] = true;
+ /* remove from final mesh poly count */
+ if (do_shell) {
+ numNewPolys -= 2;
}
}
}
- edge_adj_faces_len[i] = 0;
- MEM_freeN(edge_adj_faces[i]->faces);
- MEM_freeN(edge_adj_faces[i]->faces_reversed);
- MEM_freeN(edge_adj_faces[i]);
- edge_adj_faces[i] = NULL;
}
- else if (edge_adj_faces_len[i] > 0) {
- orig_edge_lengths[i] = sqrtf(orig_edge_lengths[i]);
- vert_adj_edges_len[v1]++;
- vert_adj_edges_len[v2]++;
+
+ if (do_shell) {
+ numNewLoops -= edge_adj_faces_len[i] * 2;
}
+
+ edge_adj_faces_len[i] = 0;
+ MEM_freeN(edge_adj_faces[i]->faces);
+ MEM_freeN(edge_adj_faces[i]->faces_reversed);
+ MEM_freeN(edge_adj_faces[i]);
+ edge_adj_faces[i] = NULL;
}
}
+
MEM_freeN(face_singularity);
}
@@ -452,8 +473,8 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
if (invalid_edge_index) {
- /* Should never actually be executed. */
if (j == 1) {
+ /* Should never actually be executed. */
vert_adj_edges[vs[0]]->edges_len--;
}
break;
@@ -461,6 +482,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
}
+ /* Remove zero faces that are in shape of an edge. */
if (invalid_edge_index) {
const uint tmp = invalid_edge_index - 1;
invalid_edge_index = i;
@@ -478,6 +500,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
}
+ /* remove from final face count */
if (do_shell) {
numNewPolys -= 2 * j;
numNewLoops -= 4 * j;
@@ -487,6 +510,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
len, sizeof(*adj_faces), "OldEdgeFaceRef::faces in solidify");
bool *adj_faces_loops_reversed = MEM_malloc_arrayN(
len, sizeof(*adj_faces_loops_reversed), "OldEdgeFaceRef::reversed in solidify");
+ /* Clean merge of adj_faces. */
j = 0;
for (uint k = 0; k < i_adj_faces->faces_len; k++) {
if (i_adj_faces->faces[k] != MOD_SOLIDIFY_EMPTY_TAG) {
@@ -521,13 +545,19 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
+ MEM_freeN(vert_adj_edges_len);
+
/* Filter duplicate polys. */
{
ed = orig_medge;
+ /* Iterate over edges and only check the faces around an edge for duplicates
+ * (performance optimization). */
for (uint i = 0; i < numEdges; i++, ed++) {
if (edge_adj_faces_len[i] > 0) {
const OldEdgeFaceRef *adj_faces = edge_adj_faces[i];
uint adj_len = adj_faces->faces_len;
+ /* Not that #adj_len doesn't need to equal edge_adj_faces_len anymore
+ * because #adj_len is shared when a face got collapsed to an edge. */
if (adj_len > 1) {
/* For each face pair check if they have equal verts. */
for (uint j = 0; j < adj_len; j++) {
@@ -564,40 +594,56 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
uint del_loops = 0;
for (uint m = 0; m < totloop; m++, ml++) {
const uint e = ml->e;
- uint face_index = j;
- uint *e_adj_faces_faces = edge_adj_faces[e]->faces;
- bool *e_adj_faces_reversed = edge_adj_faces[e]->faces_reversed;
- const uint faces_len = edge_adj_faces[e]->faces_len;
- if (e != i) {
- /* Find index of e in #adj_faces. */
- for (face_index = 0;
- face_index < faces_len && e_adj_faces_faces[face_index] != face;
- face_index++) {
- /* Pass. */
+ OldEdgeFaceRef *e_adj_faces = edge_adj_faces[e];
+ if (e_adj_faces) {
+ uint face_index = j;
+ uint *e_adj_faces_faces = e_adj_faces->faces;
+ bool *e_adj_faces_reversed = e_adj_faces->faces_reversed;
+ const uint faces_len = e_adj_faces->faces_len;
+ if (e != i) {
+ /* Find index of e in #adj_faces. */
+ for (face_index = 0;
+ face_index < faces_len && e_adj_faces_faces[face_index] != face;
+ face_index++) {
+ /* Pass. */
+ }
+ /* If not found. */
+ if (face_index == faces_len) {
+ continue;
+ }
}
- /* If not found. */
- if (face_index == faces_len) {
- continue;
+ else {
+ /* If we shrink #edge_adj_faces[i] we need to update this field. */
+ adj_len--;
}
- }
- else {
- adj_len--;
- }
- memmove(e_adj_faces_faces + face_index,
- e_adj_faces_faces + face_index + 1,
- (faces_len - face_index - 1) * sizeof(*e_adj_faces_faces));
- memmove(e_adj_faces_reversed + face_index,
- e_adj_faces_reversed + face_index + 1,
- (faces_len - face_index - 1) * sizeof(*e_adj_faces_reversed));
- edge_adj_faces[e]->faces_len--;
- if (edge_adj_faces_len[e] > 0) {
- edge_adj_faces_len[e]--;
- if (edge_adj_faces_len[e] == 0) {
- edge_adj_faces[e]->used--;
- edge_adj_faces[e] = NULL;
+ memmove(e_adj_faces_faces + face_index,
+ e_adj_faces_faces + face_index + 1,
+ (faces_len - face_index - 1) * sizeof(*e_adj_faces_faces));
+ memmove(e_adj_faces_reversed + face_index,
+ e_adj_faces_reversed + face_index + 1,
+ (faces_len - face_index - 1) * sizeof(*e_adj_faces_reversed));
+ e_adj_faces->faces_len--;
+ if (edge_adj_faces_len[e] > 0) {
+ edge_adj_faces_len[e]--;
+ if (edge_adj_faces_len[e] == 0) {
+ e_adj_faces->used--;
+ edge_adj_faces[e] = NULL;
+ }
}
+ else if (e_adj_faces->used > 1) {
+ for (uint n = 0; n < numEdges; n++) {
+ if (edge_adj_faces[n] == e_adj_faces && edge_adj_faces_len[n] > 0) {
+ edge_adj_faces_len[n]--;
+ if (edge_adj_faces_len[n] == 0) {
+ edge_adj_faces[n]->used--;
+ edge_adj_faces[n] = NULL;
+ }
+ break;
+ }
+ }
+ }
+ del_loops++;
}
- del_loops++;
}
if (do_shell) {
numNewPolys -= 2;
@@ -755,8 +801,6 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
MEM_freeN(edge_adj_faces);
}
- MEM_freeN(vert_adj_edges_len);
-
/* Create sorted edge groups for every vert. */
{
OldVertEdgeRef **adj_edges_ptr = vert_adj_edges;
@@ -779,6 +823,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
/* TODO check where the null pointer come from,
* because there should not be any... */
if (new_edges) {
+ /* count the number of new edges around the original vert */
while (*new_edges) {
unassigned_edges_len++;
new_edges++;
@@ -797,8 +842,11 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
+ /* An edge group will always contain min 2 edges
+ * so max edge group count can be calculated. */
+ uint edge_groups_len = unassigned_edges_len / 2;
edge_groups = MEM_calloc_arrayN(
- (unassigned_edges_len / 2) + 1, sizeof(*edge_groups), "edge_groups in solidify");
+ edge_groups_len + 1, sizeof(*edge_groups), "edge_groups in solidify");
uint assigned_edges_len = 0;
NewEdgeRef *found_edge = NULL;
@@ -807,14 +855,16 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
uint eg_capacity = 5;
NewFaceRef *eg_track_faces[2] = {NULL, NULL};
NewFaceRef *last_open_edge_track = NULL;
- NewEdgeRef *edge = NULL;
while (assigned_edges_len < unassigned_edges_len) {
found_edge = NULL;
insert_at_start = false;
if (eg_index >= 0 && edge_groups[eg_index].edges_len == 0) {
+ /* Called every time a new group was started in the last iteration. */
+ /* Find an unused edge to start the next group
+ * and setup variables to start creating it. */
uint j = 0;
- edge = NULL;
+ NewEdgeRef *edge = NULL;
while (!edge && j < unassigned_edges_len) {
edge = unassigned_edges[j++];
if (edge && last_open_edge_track &&
@@ -856,7 +906,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
for (found_edge_index = 0; found_edge_index < unassigned_edges_len;
found_edge_index++, edge_ptr++) {
if (*edge_ptr) {
- edge = *edge_ptr;
+ NewEdgeRef *edge = *edge_ptr;
if (edge->faces[0] == eg_track_faces[1]) {
insert_at_start = false;
eg_track_faces[1] = edge->faces[1];
@@ -932,8 +982,10 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
}
else {
+ /* called on first iteration to clean up the eg_index = -1 and start the first group,
+ * or when the current group is found to be complete (no new found_edge) */
eg_index++;
- BLI_assert(eg_index < (unassigned_edges_len / 2));
+ BLI_assert(eg_index < edge_groups_len);
eg_capacity = 5;
NewEdgeRef **edges = MEM_calloc_arrayN(
eg_capacity, sizeof(*edges), "edge_group in solidify");
@@ -959,7 +1011,11 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
eg_index++;
/* #topo_groups is the number of topo groups from here on. */
topo_groups++;
+
MEM_freeN(unassigned_edges);
+
+ /* TODO reshape the edge_groups array to its actual size
+ * after writing is finished to save on memory. */
}
/* Split of long self intersection groups */
@@ -1595,10 +1651,10 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
if (dvert) {
MDeformVert *dv = &dvert[i];
if (defgrp_invert) {
- scalar_vgroup = 1.0f - defvert_find_weight(dv, defgrp_index);
+ scalar_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index);
}
else {
- scalar_vgroup = defvert_find_weight(dv, defgrp_index);
+ scalar_vgroup = BKE_defvert_find_weight(dv, defgrp_index);
}
scalar_vgroup = offset_fac_vg + (scalar_vgroup * offset_fac_vg_inv);
}
@@ -1785,13 +1841,32 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
MEM_freeN(singularity_edges);
}
- /* DEBUG CODE FOR BUGFIXING (can not be removed because every bugfix needs this badly!). */
+ /* DEBUG CODE FOR BUG-FIXING (can not be removed because every bug-fix needs this badly!). */
#if 0
{
+ /* this code will output the content of orig_vert_groups_arr.
+ * in orig_vert_groups_arr these conditions must be met for every vertex:
+ * - new_edge value should have no duplicates
+ * - every old_edge value should appear twice
+ * - every group should have at least two members (edges)
+ * Note: that there can be vertices that only have one group. They are called singularities.
+ * These vertices will only have one side (there is no way of telling apart front
+ * from back like on a mobius strip)
+ */
+
+ /* Debug output format:
+ * <original vertex id>:
+ * {
+ * { <old edge id>/<new edge id>, } \
+ * (tg:<topology group id>)(s:<is split group>,c:<is closed group (before splitting)>)
+ * }
+ */
gs_ptr = orig_vert_groups_arr;
for (uint i = 0; i < numVerts; i++, gs_ptr++) {
EdgeGroup *gs = *gs_ptr;
+ /* check if the vertex is present (may be dissolved because of proximity) */
if (gs) {
+ printf("%d:\n", i);
for (EdgeGroup *g = gs; g->valid; g++) {
NewEdgeRef **e = g->edges;
for (uint j = 0; j < g->edges_len; j++, e++) {
@@ -1799,7 +1874,6 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
}
printf("(tg:%u)(s:%u,c:%d)\n", g->topo_group, g->split, g->is_orig_closed);
}
- printf("\n");
}
}
}
@@ -2164,7 +2238,7 @@ Mesh *MOD_solidify_nonmanifold_applyModifier(ModifierData *md,
CustomData_copy_data(&mesh->pdata, &result->pdata, (int)(i / 2), (int)poly_index, 1);
mpoly[poly_index].loopstart = (int)loop_index;
mpoly[poly_index].totloop = (int)k;
- mpoly[poly_index].mat_nr = fr->face->mat_nr + mat_ofs;
+ mpoly[poly_index].mat_nr = fr->face->mat_nr + (fr->reversed ? mat_ofs : 0);
CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max);
mpoly[poly_index].flag = fr->face->flag;
if (fr->reversed != do_flip) {
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index 4a5887c3122..b3bc5a66e8c 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -27,11 +27,10 @@
#include "BLI_utildefines.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_mesh_types.h"
-#include "BKE_cdderivedmesh.h"
#include "BKE_scene.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_ccg.h"
@@ -59,7 +58,7 @@ static void initData(ModifierData *md)
smd->renderLevels = 2;
smd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
smd->quality = 3;
- smd->flags |= eSubsurfModifierFlag_UseCrease;
+ smd->flags |= (eSubsurfModifierFlag_UseCrease | eSubsurfModifierFlag_ControlEdges);
}
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
@@ -149,7 +148,8 @@ static void subdiv_mesh_settings_init(SubdivToMeshSettings *settings,
{
const int level = subdiv_levels_for_modifier_get(smd, ctx);
settings->resolution = (1 << level) + 1;
- settings->use_optimal_display = (smd->flags & eSubsurfModifierFlag_ControlEdges);
+ settings->use_optimal_display = (smd->flags & eSubsurfModifierFlag_ControlEdges) &&
+ !(ctx->flag & MOD_APPLY_TO_BASE_MESH);
}
static Mesh *subdiv_as_mesh(SubsurfModifierData *smd,
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index 97e6bb9e804..0e318e9b092 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -25,13 +25,13 @@
#include "BLI_math.h"
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_bvhutils.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "DEG_depsgraph.h"
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 6ec7d1069de..57e7e2fa98b 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -30,10 +30,10 @@
#include "DNA_scene_types.h"
#include "BKE_bvhutils.h"
-#include "BKE_mesh_runtime.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
+#include "BKE_mesh_runtime.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph.h"
@@ -1121,20 +1121,25 @@ static void deformVert(void *__restrict userdata,
{
const SDefDeformData *const data = (SDefDeformData *)userdata;
const SDefBind *sdbind = data->bind_verts[index].binds;
+ const int num_binds = data->bind_verts[index].numbinds;
float *const vertexCos = data->vertexCos[index];
float norm[3], temp[3];
zero_v3(vertexCos);
- for (int j = 0; j < data->bind_verts[index].numbinds; j++, sdbind++) {
- /* Mode-generic operations (allocate poly coordinates) */
- float(*coords)[3] = MEM_malloc_arrayN(sdbind->numverts, sizeof(*coords), "SDefDoPolyCoords");
+ /* Allocate a `coords_buffer` that fits all the temp-data. */
+ int max_verts = 0;
+ for (int j = 0; j < num_binds; j++) {
+ max_verts = MAX2(max_verts, sdbind[j].numverts);
+ }
+ float(*coords_buffer)[3] = MEM_malloc_arrayN(max_verts, sizeof(*coords_buffer), __func__);
+ for (int j = 0; j < num_binds; j++, sdbind++) {
for (int k = 0; k < sdbind->numverts; k++) {
- copy_v3_v3(coords[k], data->targetCos[sdbind->vert_inds[k]]);
+ copy_v3_v3(coords_buffer[k], data->targetCos[sdbind->vert_inds[k]]);
}
- normal_poly_v3(norm, coords, sdbind->numverts);
+ normal_poly_v3(norm, coords_buffer, sdbind->numverts);
zero_v3(temp);
/* ---------- looptri mode ---------- */
@@ -1147,14 +1152,14 @@ static void deformVert(void *__restrict userdata,
/* ---------- ngon mode ---------- */
if (sdbind->mode == MOD_SDEF_MODE_NGON) {
for (int k = 0; k < sdbind->numverts; k++) {
- madd_v3_v3fl(temp, coords[k], sdbind->vert_weights[k]);
+ madd_v3_v3fl(temp, coords_buffer[k], sdbind->vert_weights[k]);
}
}
/* ---------- centroid mode ---------- */
else if (sdbind->mode == MOD_SDEF_MODE_CENTROID) {
float cent[3];
- mid_v3_v3_array(cent, coords, sdbind->numverts);
+ mid_v3_v3_array(cent, coords_buffer, sdbind->numverts);
madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], sdbind->vert_weights[0]);
madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], sdbind->vert_weights[1]);
@@ -1162,13 +1167,12 @@ static void deformVert(void *__restrict userdata,
}
}
- MEM_freeN(coords);
-
/* Apply normal offset (generic for all modes) */
madd_v3_v3fl(temp, norm, sdbind->normal_dist);
madd_v3_v3fl(vertexCos, temp, sdbind->influence);
}
+ MEM_freeN(coords_buffer);
}
static void surfacedeformModifier_do(ModifierData *md,
diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c
index 7fba7e864ae..1e6bc2e1819 100644
--- a/source/blender/modifiers/intern/MOD_triangulate.c
+++ b/source/blender/modifiers/intern/MOD_triangulate.c
@@ -26,8 +26,8 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "BKE_modifier.h"
#include "BKE_mesh.h"
+#include "BKE_modifier.h"
#include "bmesh.h"
#include "bmesh_tools.h"
@@ -44,7 +44,7 @@ static Mesh *triangulate_mesh(Mesh *mesh,
BMesh *bm;
int total_edges, i;
MEdge *me;
- CustomData_MeshMasks cddata_masks = {
+ CustomData_MeshMasks cd_mask_extra = {
.vmask = CD_MASK_ORIGINDEX, .emask = CD_MASK_ORIGINDEX, .pmask = CD_MASK_ORIGINDEX};
bool keep_clnors = (flag & MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS) != 0;
@@ -53,19 +53,19 @@ static Mesh *triangulate_mesh(Mesh *mesh,
BKE_mesh_calc_normals_split(mesh);
/* We need that one to 'survive' to/from BMesh conversions. */
CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
- cddata_masks.lmask |= CD_MASK_NORMAL;
+ cd_mask_extra.lmask |= CD_MASK_NORMAL;
}
bm = BKE_mesh_to_bmesh_ex(mesh,
&((struct BMeshCreateParams){0}),
&((struct BMeshFromMeshParams){
.calc_face_normal = true,
- .cd_mask_extra = cddata_masks,
+ .cd_mask_extra = cd_mask_extra,
}));
BM_mesh_triangulate(bm, quad_method, ngon_method, min_vertices, false, NULL, NULL, NULL);
- result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cddata_masks, mesh);
+ result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cd_mask_extra, mesh);
BM_mesh_free(bm);
if (keep_clnors) {
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 0b72c31ad7b..c0014a2c0cd 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -26,12 +26,12 @@
#include "BLI_utildefines.h"
#include "BLI_bitmap.h"
-#include "BLI_math_vector.h"
#include "BLI_math_matrix.h"
+#include "BLI_math_vector.h"
#include "DNA_image_types.h"
-#include "DNA_meshdata_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -40,7 +40,7 @@
#include "BKE_editmesh.h"
#include "BKE_image.h"
#include "BKE_lattice.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
@@ -49,8 +49,8 @@
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
-#include "MOD_util.h"
#include "MOD_modifiertypes.h"
+#include "MOD_util.h"
#include "MEM_guardedalloc.h"
@@ -235,7 +235,7 @@ Mesh *MOD_deform_mesh_eval_get(Object *ob,
void MOD_get_vgroup(
Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index)
{
- *defgrp_index = defgroup_name_index(ob, name);
+ *defgrp_index = BKE_object_defgroup_name_index(ob, name);
*dvert = NULL;
if (*defgrp_index != -1) {
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c
index 9698e150850..242f31b6434 100644
--- a/source/blender/modifiers/intern/MOD_uvproject.c
+++ b/source/blender/modifiers/intern/MOD_uvproject.c
@@ -28,13 +28,13 @@
#include "BLI_math.h"
#include "BLI_uvproject.h"
+#include "DNA_camera_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_camera_types.h"
#include "DNA_object_types.h"
#include "BKE_camera.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c
index 2c5f4b66c23..46298c0e00d 100644
--- a/source/blender/modifiers/intern/MOD_uvwarp.c
+++ b/source/blender/modifiers/intern/MOD_uvwarp.c
@@ -31,25 +31,20 @@
#include "BKE_action.h" /* BKE_pose_channel_find_name */
#include "BKE_deform.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_modifier.h"
#include "DEG_depsgraph_query.h"
#include "MOD_util.h"
-static void uv_warp_from_mat4_pair(
- float uv_dst[2], const float uv_src[2], float warp_mat[4][4], int axis_u, int axis_v)
+static void uv_warp_from_mat4_pair(float uv_dst[2], const float uv_src[2], float warp_mat[4][4])
{
float tuv[3] = {0.0f};
- tuv[axis_u] = uv_src[0];
- tuv[axis_v] = uv_src[1];
-
+ copy_v2_v2(tuv, uv_src);
mul_m4_v3(warp_mat, tuv);
-
- uv_dst[0] = tuv[axis_u];
- uv_dst[1] = tuv[axis_v];
+ copy_v2_v2(uv_dst, tuv);
}
static void initData(ModifierData *md)
@@ -58,6 +53,7 @@ static void initData(ModifierData *md)
umd->axis_u = 0;
umd->axis_v = 1;
copy_v2_fl(umd->center, 0.5f);
+ copy_v2_fl(umd->scale, 1.0f);
}
static void requiredDataMask(Object *UNUSED(ob),
@@ -92,8 +88,7 @@ typedef struct UVWarpData {
int defgrp_index;
float (*warp_mat)[4];
- int axis_u;
- int axis_v;
+ bool invert_vgroup;
} UVWarpData;
static void uv_warp_compute(void *__restrict userdata,
@@ -110,23 +105,23 @@ static void uv_warp_compute(void *__restrict userdata,
const int defgrp_index = data->defgrp_index;
float(*warp_mat)[4] = data->warp_mat;
- const int axis_u = data->axis_u;
- const int axis_v = data->axis_v;
int l;
if (dvert) {
for (l = 0; l < mp->totloop; l++, ml++, mluv++) {
float uv[2];
- const float weight = defvert_find_weight(&dvert[ml->v], defgrp_index);
+ const float weight = data->invert_vgroup ?
+ 1.0f - BKE_defvert_find_weight(&dvert[ml->v], defgrp_index) :
+ BKE_defvert_find_weight(&dvert[ml->v], defgrp_index);
- uv_warp_from_mat4_pair(uv, mluv->uv, warp_mat, axis_u, axis_v);
+ uv_warp_from_mat4_pair(uv, mluv->uv, warp_mat);
interp_v2_v2v2(mluv->uv, mluv->uv, uv, weight);
}
}
else {
for (l = 0; l < mp->totloop; l++, ml++, mluv++) {
- uv_warp_from_mat4_pair(mluv->uv, mluv->uv, warp_mat, axis_u, axis_v);
+ uv_warp_from_mat4_pair(mluv->uv, mluv->uv, warp_mat);
}
}
}
@@ -141,43 +136,61 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
MDeformVert *dvert;
int defgrp_index;
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
- float mat_src[4][4];
- float mat_dst[4][4];
- float imat_dst[4][4];
float warp_mat[4][4];
const int axis_u = umd->axis_u;
const int axis_v = umd->axis_v;
+ const bool invert_vgroup = (umd->flag & MOD_UVWARP_INVERT_VGROUP) != 0;
/* make sure there are UV Maps available */
if (!CustomData_has_layer(&mesh->ldata, CD_MLOOPUV)) {
return mesh;
}
- else if (ELEM(NULL, umd->object_src, umd->object_dst)) {
- modifier_setError(md, "From/To objects must be set");
- return mesh;
- }
- /* make sure anything moving UVs is available */
- matrix_from_obj_pchan(mat_src, umd->object_src, umd->bone_src);
- matrix_from_obj_pchan(mat_dst, umd->object_dst, umd->bone_dst);
+ if (!ELEM(NULL, umd->object_src, umd->object_dst)) {
+ float mat_src[4][4];
+ float mat_dst[4][4];
+ float imat_dst[4][4];
+ float shuf_mat[4][4];
+
+ /* make sure anything moving UVs is available */
+ matrix_from_obj_pchan(mat_src, umd->object_src, umd->bone_src);
+ matrix_from_obj_pchan(mat_dst, umd->object_dst, umd->bone_dst);
- invert_m4_m4(imat_dst, mat_dst);
- mul_m4_m4m4(warp_mat, imat_dst, mat_src);
+ invert_m4_m4(imat_dst, mat_dst);
+ mul_m4_m4m4(warp_mat, imat_dst, mat_src);
- /* apply warp */
- if (!is_zero_v2(umd->center)) {
- float mat_cent[4][4];
- float imat_cent[4][4];
+ /* apply warp */
+ if (!is_zero_v2(umd->center)) {
+ float mat_cent[4][4];
+ float imat_cent[4][4];
- unit_m4(mat_cent);
- mat_cent[3][axis_u] = umd->center[0];
- mat_cent[3][axis_v] = umd->center[1];
+ unit_m4(mat_cent);
+ mat_cent[3][axis_u] = umd->center[0];
+ mat_cent[3][axis_v] = umd->center[1];
- invert_m4_m4(imat_cent, mat_cent);
+ invert_m4_m4(imat_cent, mat_cent);
- mul_m4_m4m4(warp_mat, warp_mat, imat_cent);
- mul_m4_m4m4(warp_mat, mat_cent, warp_mat);
+ mul_m4_m4m4(warp_mat, warp_mat, imat_cent);
+ mul_m4_m4m4(warp_mat, mat_cent, warp_mat);
+ }
+
+ int shuf_indices[4] = {axis_u, axis_v, -1, 3};
+ shuffle_m4(shuf_mat, shuf_indices);
+ mul_m4_m4m4(warp_mat, shuf_mat, warp_mat);
+ transpose_m4(shuf_mat);
+ mul_m4_m4m4(warp_mat, warp_mat, shuf_mat);
}
+ else {
+ unit_m4(warp_mat);
+ }
+
+ /* Apply direct 2d transform. */
+ translate_m4(warp_mat, umd->center[0], umd->center[1], 0.0f);
+ const float scale[3] = {umd->scale[0], umd->scale[1], 1.0f};
+ rescale_m4(warp_mat, scale);
+ rotate_m4(warp_mat, 'Z', umd->rotation);
+ translate_m4(warp_mat, umd->offset[0], umd->offset[1], 0.0f);
+ translate_m4(warp_mat, -umd->center[0], -umd->center[1], 0.0f);
/* make sure we're using an existing layer */
CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, umd->uvlayer_name, uvname);
@@ -199,8 +212,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
.dvert = dvert,
.defgrp_index = defgrp_index,
.warp_mat = warp_mat,
- .axis_u = axis_u,
- .axis_v = axis_v,
+ .invert_vgroup = invert_vgroup,
};
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
@@ -226,7 +238,7 @@ static void uv_warp_deps_object_bone_new(struct DepsNodeHandle *node,
const char *bonename)
{
if (object != NULL) {
- if (bonename[0]) {
+ if (object->type == OB_ARMATURE && bonename[0]) {
DEG_add_object_relation(node, object, DEG_OB_COMP_EVAL_POSE, "UVWarp Modifier");
}
else {
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 7155498c942..4a98afbb91c 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -30,14 +30,14 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
+#include "BKE_colortools.h"
+#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
-#include "BKE_deform.h"
#include "BKE_texture.h"
-#include "BKE_colortools.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
@@ -169,13 +169,13 @@ static void warpModifier_do(WarpModifierData *wmd,
float tmat[4][4];
- const float falloff_radius_sq = SQUARE(wmd->falloff_radius);
+ const float falloff_radius_sq = square_f(wmd->falloff_radius);
float strength = wmd->strength;
float fac = 1.0f, weight;
int i;
int defgrp_index;
MDeformVert *dvert, *dv = NULL;
-
+ const bool invert_vgroup = (wmd->flag & MOD_WARP_INVERT_VGROUP) != 0;
float(*tex_co)[3] = NULL;
if (!(wmd->object_from && wmd->object_to)) {
@@ -235,7 +235,8 @@ static void warpModifier_do(WarpModifierData *wmd,
/* skip if no vert group found */
if (defgrp_index != -1) {
dv = &dvert[i];
- weight = defvert_find_weight(dv, defgrp_index) * strength;
+ weight = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) * strength :
+ BKE_defvert_find_weight(dv, defgrp_index) * strength;
if (weight <= 0.0f) {
continue;
}
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index 908abeb6f76..56b2a81fdb1 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -32,8 +32,8 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
@@ -154,6 +154,7 @@ static void waveModifier_do(WaveModifierData *md,
const int wmd_axis = wmd->flag & (MOD_WAVE_X | MOD_WAVE_Y);
const float falloff = wmd->falloff;
float falloff_fac = 1.0f; /* when falloff == 0.0f this stays at 1.0f */
+ const bool invert_group = (wmd->flag & MOD_WAVE_INVERT_VGROUP) != 0;
if ((wmd->flag & MOD_WAVE_NORM) && (mesh != NULL)) {
mvert = mesh->mvert;
@@ -213,7 +214,8 @@ static void waveModifier_do(WaveModifierData *md,
/* get weights */
if (dvert) {
- def_weight = defvert_find_weight(&dvert[i], defgrp_index);
+ def_weight = invert_group ? 1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index) :
+ BKE_defvert_find_weight(&dvert[i], defgrp_index);
/* if this vert isn't in the vgroup, don't deform it */
if (def_weight == 0.0f) {
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index 0accbe607eb..04b503e588b 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -20,16 +20,17 @@
#include "MEM_guardedalloc.h"
+#include "BLI_bitmap.h"
#include "BLI_linklist.h"
#include "BLI_math.h"
#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BKE_cdderivedmesh.h"
#include "BKE_deform.h"
-#include "BKE_library.h"
+#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "MOD_modifiertypes.h"
@@ -142,7 +143,7 @@ static void aggregate_item_normal(WeightedNormalModifierData *wnmd,
const bool has_vgroup = dvert != NULL;
const bool vert_of_group = has_vgroup &&
- defvert_find_index(&dvert[mv_index], defgrp_index) != NULL;
+ BKE_defvert_find_index(&dvert[mv_index], defgrp_index) != NULL;
if (has_vgroup &&
((vert_of_group && use_invert_vgroup) || (!vert_of_group && !use_invert_vgroup))) {
@@ -360,7 +361,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
}
else {
/* TODO: Ideally, we could add an option to BKE_mesh_normals_loop_custom_[from_vertices_]set()
- * to keep current clnors instead of resetting them to default autocomputed ones,
+ * to keep current clnors instead of resetting them to default auto-computed ones,
* when given new custom normal is zero-vec.
* But this is not exactly trivial change, better to keep this optimization for later...
*/
@@ -561,7 +562,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
if (!(((Mesh *)ob->data)->flag & ME_AUTOSMOOTH))
#endif
{
- modifier_setError((ModifierData *)wnmd, "Enable 'Auto Smooth' option in mesh settings");
+ modifier_setError((ModifierData *)wnmd, "Enable 'Auto Smooth' in Object Data Properties");
return mesh;
}
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c
index 4ff07b21ef4..23e4da32ed7 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.c
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.c
@@ -54,20 +54,22 @@
* mapping to the real vertex index (in case the weight tables do not cover the whole vertices...).
* cmap might be NULL, in which case curve mapping mode will return unmodified data.
*/
-void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cmap, RNG *rng)
+void weightvg_do_map(
+ int num, float *new_w, short falloff_type, const bool do_invert, CurveMapping *cmap, RNG *rng)
{
int i;
/* Return immediately, if we have nothing to do! */
/* Also security checks... */
- if (((falloff_type == MOD_WVG_MAPPING_CURVE) && (cmap == NULL)) || !ELEM(falloff_type,
- MOD_WVG_MAPPING_CURVE,
- MOD_WVG_MAPPING_SHARP,
- MOD_WVG_MAPPING_SMOOTH,
- MOD_WVG_MAPPING_ROOT,
- MOD_WVG_MAPPING_SPHERE,
- MOD_WVG_MAPPING_RANDOM,
- MOD_WVG_MAPPING_STEP)) {
+ if (!do_invert && (((falloff_type == MOD_WVG_MAPPING_CURVE) && (cmap == NULL)) ||
+ !ELEM(falloff_type,
+ MOD_WVG_MAPPING_CURVE,
+ MOD_WVG_MAPPING_SHARP,
+ MOD_WVG_MAPPING_SMOOTH,
+ MOD_WVG_MAPPING_ROOT,
+ MOD_WVG_MAPPING_SPHERE,
+ MOD_WVG_MAPPING_RANDOM,
+ MOD_WVG_MAPPING_STEP))) {
return;
}
@@ -103,9 +105,14 @@ void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cm
case MOD_WVG_MAPPING_STEP:
fac = (fac >= 0.5f) ? 1.0f : 0.0f;
break;
+ case MOD_WVG_MAPPING_NONE:
+ BLI_assert(do_invert);
+ break;
+ default:
+ BLI_assert(0);
}
- new_w[i] = fac;
+ new_w[i] = do_invert ? 1.0f - fac : fac;
}
}
@@ -130,7 +137,8 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
const int tex_use_channel,
const int tex_mapping,
Object *tex_map_object,
- const char *tex_uvlayer_name)
+ const char *tex_uvlayer_name,
+ const bool invert_vgroup_mask)
{
int ref_didx;
int i;
@@ -211,7 +219,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
MEM_freeN(tex_co);
}
- else if ((ref_didx = defgroup_name_index(ob, defgrp_name)) != -1) {
+ else if ((ref_didx = BKE_object_defgroup_name_index(ob, defgrp_name)) != -1) {
MDeformVert *dvert = NULL;
/* Check whether we want to set vgroup weights from a constant weight factor or a vertex
@@ -230,7 +238,9 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
/* For each weight (vertex), make the mix between org and new weights. */
for (i = 0; i < num; i++) {
int idx = indices ? indices[i] : i;
- const float f = defvert_find_weight(&dvert[idx], ref_didx) * fact;
+ const float f = invert_vgroup_mask ?
+ 1.0f - BKE_defvert_find_weight(&dvert[idx], ref_didx) * fact :
+ BKE_defvert_find_weight(&dvert[idx], ref_didx) * fact;
org_w[i] = (new_w[i] * f) + (org_w[i] * (1.0f - f));
/* If that vertex is not in ref vgroup, assume null factor, and hence do nothing! */
}
@@ -268,7 +278,7 @@ void weightvg_update_vg(MDeformVert *dvert,
float w = weights[i];
MDeformVert *dv = &dvert[indices ? indices[i] : i];
MDeformWeight *dw = dws ? dws[i] :
- ((defgrp_idx >= 0) ? defvert_find_index(dv, defgrp_idx) : NULL);
+ ((defgrp_idx >= 0) ? BKE_defvert_find_index(dv, defgrp_idx) : NULL);
/* Never allow weights out of [0.0, 1.0] range. */
CLAMP(w, 0.0f, 1.0f);
@@ -276,7 +286,7 @@ void weightvg_update_vg(MDeformVert *dvert,
/* If the vertex is in this vgroup, remove it if needed, or just update it. */
if (dw != NULL) {
if (do_rem && w < rem_thresh) {
- defvert_remove_group(dv, dw);
+ BKE_defvert_remove_group(dv, dw);
}
else {
dw->weight = w;
@@ -284,7 +294,7 @@ void weightvg_update_vg(MDeformVert *dvert,
}
/* Else, add it if needed! */
else if (do_add && w > add_thresh) {
- defvert_add_index_notest(dv, defgrp_idx, w);
+ BKE_defvert_add_index_notest(dv, defgrp_idx, w);
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h
index 08967b7400d..bcd1076eac6 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.h
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.h
@@ -52,8 +52,12 @@ struct Tex;
*/
#define MOD_WVG_ZEROFLOOR 1.0e-32f
-void weightvg_do_map(
- int num, float *new_w, short mode, struct CurveMapping *cmap, struct RNG *rng);
+void weightvg_do_map(int num,
+ float *new_w,
+ short mode,
+ const bool do_invert,
+ struct CurveMapping *cmap,
+ struct RNG *rng);
void weightvg_do_mask(const ModifierEvalContext *ctx,
const int num,
@@ -69,7 +73,8 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
const int tex_use_channel,
const int tex_mapping,
Object *tex_map_object,
- const char *tex_uvlayer_name);
+ const char *tex_uvlayer_name,
+ const bool invert_vgroup_mask);
void weightvg_update_vg(struct MDeformVert *dvert,
int defgrp_idx,
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index 045ba78fab5..ba1745f7b5e 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -35,7 +35,7 @@
#include "BKE_colortools.h" /* CurveMapping. */
#include "BKE_deform.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
@@ -44,8 +44,8 @@
#include "MEM_guardedalloc.h"
-#include "MOD_weightvg_util.h"
#include "MOD_modifiertypes.h"
+#include "MOD_weightvg_util.h"
/**************************************
* Modifiers functions. *
@@ -167,6 +167,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
float *org_w; /* Array original weights. */
float *new_w; /* Array new weights. */
int i;
+ const bool invert_vgroup_mask = (wmd->edit_flags & MOD_WVG_EDIT_INVERT_VGROUP_MASK) != 0;
/* Flags. */
const bool do_add = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0;
@@ -187,7 +188,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Get vgroup idx from its name. */
- const int defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name);
+ const int defgrp_index = BKE_object_defgroup_name_index(ctx->object, wmd->defgrp_name);
if (defgrp_index == -1) {
return mesh;
}
@@ -219,7 +220,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
new_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, new_w");
dw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGEdit Modifier, dw");
for (i = 0; i < numVerts; i++) {
- dw[i] = defvert_find_index(&dvert[i], defgrp_index);
+ dw[i] = BKE_defvert_find_index(&dvert[i], defgrp_index);
if (dw[i]) {
org_w[i] = new_w[i] = dw[i]->weight;
}
@@ -229,14 +230,15 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Do mapping. */
- if (wmd->falloff_type != MOD_WVG_MAPPING_NONE) {
+ const bool do_invert_mapping = (wmd->edit_flags & MOD_WVG_INVERT_FALLOFF) != 0;
+ if (do_invert_mapping || wmd->falloff_type != MOD_WVG_MAPPING_NONE) {
RNG *rng = NULL;
if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM) {
rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ctx->object->id.name + 2));
}
- weightvg_do_map(numVerts, new_w, wmd->falloff_type, wmd->cmap_curve, rng);
+ weightvg_do_map(numVerts, new_w, wmd->falloff_type, do_invert_mapping, wmd->cmap_curve, rng);
if (rng) {
BLI_rng_free(rng);
@@ -259,7 +261,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
wmd->mask_tex_use_channel,
wmd->mask_tex_mapping,
wmd->mask_tex_map_obj,
- wmd->mask_tex_uvlayer_name);
+ wmd->mask_tex_uvlayer_name,
+ invert_vgroup_mask);
/* Update/add/remove from vgroup. */
weightvg_update_vg(dvert,
diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c
index 368a6b46c7e..4984853d41e 100644
--- a/source/blender/modifiers/intern/MOD_weightvgmix.c
+++ b/source/blender/modifiers/intern/MOD_weightvgmix.c
@@ -33,7 +33,7 @@
#include "BKE_customdata.h"
#include "BKE_deform.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_query.h"
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
@@ -42,8 +42,8 @@
#include "MEM_guardedalloc.h"
-#include "MOD_weightvg_util.h"
#include "MOD_modifiertypes.h"
+#include "MOD_weightvg_util.h"
/**
* This mixes the old weight with the new weight factor.
@@ -218,6 +218,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
int *tidx, *indices = NULL;
int numIdx = 0;
int i;
+ const bool invert_vgroup_mask = (wmd->flag & MOD_WVG_MIX_INVERT_VGROUP_MASK) != 0;
/* Flags. */
#if 0
const bool do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview) != 0;
@@ -234,14 +235,14 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Get vgroup idx from its name. */
- const int defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name_a);
+ const int defgrp_index = BKE_object_defgroup_name_index(ctx->object, wmd->defgrp_name_a);
if (defgrp_index == -1) {
return mesh;
}
/* Get second vgroup idx from its name, if given. */
int defgrp_index_other = -1;
if (wmd->defgrp_name_b[0] != '\0') {
- defgrp_index_other = defgroup_name_index(ctx->object, wmd->defgrp_name_b);
+ defgrp_index_other = BKE_object_defgroup_name_index(ctx->object, wmd->defgrp_name_b);
if (defgrp_index_other == -1) {
return mesh;
}
@@ -277,11 +278,11 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
case MOD_WVG_SET_A:
/* All vertices in first vgroup. */
for (i = 0; i < numVerts; i++) {
- MDeformWeight *dw = defvert_find_index(&dvert[i], defgrp_index);
+ MDeformWeight *dw = BKE_defvert_find_index(&dvert[i], defgrp_index);
if (dw) {
tdw1[numIdx] = dw;
tdw2[numIdx] = (defgrp_index_other >= 0) ?
- defvert_find_index(&dvert[i], defgrp_index_other) :
+ BKE_defvert_find_index(&dvert[i], defgrp_index_other) :
NULL;
tidx[numIdx++] = i;
}
@@ -291,10 +292,10 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
/* All vertices in second vgroup. */
for (i = 0; i < numVerts; i++) {
MDeformWeight *dw = (defgrp_index_other >= 0) ?
- defvert_find_index(&dvert[i], defgrp_index_other) :
+ BKE_defvert_find_index(&dvert[i], defgrp_index_other) :
NULL;
if (dw) {
- tdw1[numIdx] = defvert_find_index(&dvert[i], defgrp_index);
+ tdw1[numIdx] = BKE_defvert_find_index(&dvert[i], defgrp_index);
tdw2[numIdx] = dw;
tidx[numIdx++] = i;
}
@@ -303,9 +304,9 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
case MOD_WVG_SET_OR:
/* All vertices in one vgroup or the other. */
for (i = 0; i < numVerts; i++) {
- MDeformWeight *adw = defvert_find_index(&dvert[i], defgrp_index);
+ MDeformWeight *adw = BKE_defvert_find_index(&dvert[i], defgrp_index);
MDeformWeight *bdw = (defgrp_index_other >= 0) ?
- defvert_find_index(&dvert[i], defgrp_index_other) :
+ BKE_defvert_find_index(&dvert[i], defgrp_index_other) :
NULL;
if (adw || bdw) {
tdw1[numIdx] = adw;
@@ -317,9 +318,9 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
case MOD_WVG_SET_AND:
/* All vertices in both vgroups. */
for (i = 0; i < numVerts; i++) {
- MDeformWeight *adw = defvert_find_index(&dvert[i], defgrp_index);
+ MDeformWeight *adw = BKE_defvert_find_index(&dvert[i], defgrp_index);
MDeformWeight *bdw = (defgrp_index_other >= 0) ?
- defvert_find_index(&dvert[i], defgrp_index_other) :
+ BKE_defvert_find_index(&dvert[i], defgrp_index_other) :
NULL;
if (adw && bdw) {
tdw1[numIdx] = adw;
@@ -332,9 +333,10 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
default:
/* Use all vertices. */
for (i = 0; i < numVerts; i++) {
- tdw1[i] = defvert_find_index(&dvert[i], defgrp_index);
- tdw2[i] = (defgrp_index_other >= 0) ? defvert_find_index(&dvert[i], defgrp_index_other) :
- NULL;
+ tdw1[i] = BKE_defvert_find_index(&dvert[i], defgrp_index);
+ tdw2[i] = (defgrp_index_other >= 0) ?
+ BKE_defvert_find_index(&dvert[i], defgrp_index_other) :
+ NULL;
}
numIdx = -1;
break;
@@ -393,7 +395,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
wmd->mask_tex_use_channel,
wmd->mask_tex_mapping,
wmd->mask_tex_map_obj,
- wmd->mask_tex_uvlayer_name);
+ wmd->mask_tex_uvlayer_name,
+ invert_vgroup_mask);
/* Update (add to) vgroup.
* XXX Depending on the MOD_WVG_SET_xxx option chosen, we might have to add vertices to vgroup.
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 553743272a2..7c9242ed900 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -38,8 +38,8 @@
#include "BKE_curve.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
@@ -49,9 +49,9 @@
#include "MEM_guardedalloc.h"
-#include "MOD_weightvg_util.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
+#include "MOD_weightvg_util.h"
//#define USE_TIMEIT
@@ -239,8 +239,13 @@ static float get_ob2ob_distance(const Object *ob, const Object *obr)
/**
* Maps distances to weights, with an optional "smoothing" mapping.
*/
-static void do_map(
- Object *ob, float *weights, const int nidx, const float min_d, const float max_d, short mode)
+static void do_map(Object *ob,
+ float *weights,
+ const int nidx,
+ const float min_d,
+ const float max_d,
+ short mode,
+ const bool do_invert_mapping)
{
const float range_inv = 1.0f / (max_d - min_d); /* invert since multiplication is faster */
uint i = nidx;
@@ -276,14 +281,15 @@ static void do_map(
}
}
- if (!ELEM(mode, MOD_WVG_MAPPING_NONE, MOD_WVG_MAPPING_CURVE)) {
+ BLI_assert(mode != MOD_WVG_MAPPING_CURVE);
+ if (do_invert_mapping || mode != MOD_WVG_MAPPING_NONE) {
RNG *rng = NULL;
if (mode == MOD_WVG_MAPPING_RANDOM) {
rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ob->id.name + 2));
}
- weightvg_do_map(nidx, weights, mode, NULL, rng);
+ weightvg_do_map(nidx, weights, mode, do_invert_mapping, NULL, rng);
if (rng) {
BLI_rng_free(rng);
@@ -411,6 +417,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
int *tidx, *indices = NULL;
int numIdx = 0;
int i;
+ const bool invert_vgroup_mask = (wmd->proximity_flags & MOD_WVG_PROXIMITY_INVERT_VGROUP_MASK) !=
+ 0;
/* Flags. */
#if 0
const bool do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview) != 0;
@@ -437,7 +445,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Get vgroup idx from its name. */
- defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
+ defgrp_index = BKE_object_defgroup_name_index(ob, wmd->defgrp_name);
if (defgrp_index == -1) {
return mesh;
}
@@ -461,7 +469,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
tw = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGProximity Modifier, tw");
tdw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGProximity Modifier, tdw");
for (i = 0; i < numVerts; i++) {
- MDeformWeight *_dw = defvert_find_index(&dvert[i], defgrp_index);
+ MDeformWeight *_dw = BKE_defvert_find_index(&dvert[i], defgrp_index);
if (_dw) {
tidx[numIdx] = i;
tw[numIdx] = _dw->weight;
@@ -557,7 +565,13 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
}
/* Map distances to weights. */
- do_map(ob, new_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->falloff_type);
+ do_map(ob,
+ new_w,
+ numIdx,
+ wmd->min_dist,
+ wmd->max_dist,
+ wmd->falloff_type,
+ (wmd->proximity_flags & MOD_WVG_PROXIMITY_INVERT_FALLOFF) != 0);
/* Do masking. */
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -575,7 +589,8 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
wmd->mask_tex_use_channel,
wmd->mask_tex_mapping,
wmd->mask_tex_map_obj,
- wmd->mask_tex_uvlayer_name);
+ wmd->mask_tex_uvlayer_name,
+ invert_vgroup_mask);
/* Update vgroup. Note we never add nor remove vertices from vgroup here. */
weightvg_update_vg(dvert, defgrp_index, dw, numIdx, indices, org_w, false, 0.0f, false, 0.0f);
diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c
index f96ec9a82e5..5d56152e0ff 100644
--- a/source/blender/modifiers/intern/MOD_weld.c
+++ b/source/blender/modifiers/intern/MOD_weld.c
@@ -37,15 +37,18 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
-#include "BKE_deform.h"
#include "BKE_bvhutils.h"
-#include "BKE_modifier.h"
+#include "BKE_deform.h"
#include "BKE_mesh.h"
+#include "BKE_modifier.h"
#include "DEG_depsgraph.h"
+#include "MOD_modifiertypes.h"
+
//#define USE_WELD_DEBUG
//#define USE_WELD_NORMALS
@@ -1626,16 +1629,17 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, const ModifierEvalContex
totvert = mesh->totvert;
/* Vertex Group. */
- const int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
+ const int defgrp_index = BKE_object_defgroup_name_index(ob, wmd->defgrp_name);
if (defgrp_index != -1) {
MDeformVert *dvert, *dv;
dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
if (dvert) {
+ const bool invert_vgroup = (wmd->flag & MOD_WELD_INVERT_VGROUP) != 0;
dv = &dvert[0];
v_mask = BLI_BITMAP_NEW(totvert, __func__);
for (i = 0; i < totvert; i++, dv++) {
- const bool found = defvert_find_weight(dv, defgrp_index) > 0.0f;
- if (found) {
+ const bool found = BKE_defvert_find_weight(dv, defgrp_index) > 0.0f;
+ if (found != invert_vgroup) {
BLI_BITMAP_ENABLE(v_mask, i);
v_mask_act++;
}
@@ -1659,7 +1663,7 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, const ModifierEvalContex
struct WeldOverlapData data;
data.mvert = mvert;
- data.merge_dist_sq = SQUARE(wmd->merge_dist);
+ data.merge_dist_sq = square_f(wmd->merge_dist);
uint overlap_len;
BVHTreeOverlap *overlap = BLI_bvhtree_overlap_ex(bvhtree,
@@ -1886,6 +1890,18 @@ static void initData(ModifierData *md)
wmd->defgrp_name[0] = '\0';
}
+static void requiredDataMask(Object *UNUSED(ob),
+ ModifierData *md,
+ CustomData_MeshMasks *r_cddata_masks)
+{
+ WeldModifierData *wmd = (WeldModifierData *)md;
+
+ /* Ask for vertexgroups if we need them. */
+ if (wmd->defgrp_name[0] != '\0') {
+ r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
+ }
+}
+
ModifierTypeInfo modifierType_Weld = {
/* name */ "Weld",
/* structName */ "WeldModifierData",
@@ -1904,7 +1920,7 @@ ModifierTypeInfo modifierType_Weld = {
/* applyModifier */ applyModifier,
/* initData */ initData,
- /* requiredDataMask */ NULL,
+ /* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
/* updateDepsgraph */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_wireframe.c b/source/blender/modifiers/intern/MOD_wireframe.c
index 3dd6e00c3a5..04473b30585 100644
--- a/source/blender/modifiers/intern/MOD_wireframe.c
+++ b/source/blender/modifiers/intern/MOD_wireframe.c
@@ -61,7 +61,7 @@ static Mesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, Mesh *
Mesh *result;
BMesh *bm;
- const int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
+ const int defgrp_index = BKE_object_defgroup_name_index(ob, wmd->defgrp_name);
bm = BKE_mesh_to_bmesh_ex(mesh,
&(struct BMeshCreateParams){0},