diff options
Diffstat (limited to 'source/blender/modifiers/intern')
25 files changed, 412 insertions, 191 deletions
diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index b62c03d1b03..e7f47a09d95 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -165,10 +165,15 @@ static void deformVerts(ModifierData *md, static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em, - Mesh *UNUSED(mesh), + Mesh *mesh, float (*vertexCos)[3], int numVerts) { + if (mesh != NULL) { + deformVerts(md, ctx, mesh, vertexCos, numVerts); + return; + } + ArmatureModifierData *amd = (ArmatureModifierData *)md; MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */ diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 21bb7f4764a..c0428785009 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -73,6 +73,7 @@ static void initData(ModifierData *md) bmd->face_str_mode = MOD_BEVEL_FACE_STRENGTH_NONE; bmd->miter_inner = MOD_BEVEL_MITER_SHARP; bmd->miter_outer = MOD_BEVEL_MITER_SHARP; + bmd->affect_type = MOD_BEVEL_AFFECT_EDGES; bmd->spread = 0.1f; bmd->mat = -1; bmd->profile = 0.5f; @@ -117,7 +118,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * MDeformVert *dvert = NULL; BevelModifierData *bmd = (BevelModifierData *)md; const float threshold = cosf(bmd->bevel_angle + 0.000000175f); - const bool vertex_only = (bmd->flags & MOD_BEVEL_VERT) != 0; const bool do_clamp = !(bmd->flags & MOD_BEVEL_OVERLAP_OK); const int offset_type = bmd->val_flags; const int profile_type = bmd->profile_type; @@ -131,7 +131,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * const int miter_outer = bmd->miter_outer; const int miter_inner = bmd->miter_inner; const float spread = bmd->spread; - 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, @@ -152,7 +151,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * MOD_get_vgroup(ctx->object, mesh, bmd->defgrp_name, &dvert, &vgroup); } - if (vertex_only) { + if (bmd->affect_type == MOD_BEVEL_AFFECT_VERTICES) { BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { if (bmd->lim_flags & MOD_BEVEL_WEIGHT) { weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT); @@ -230,7 +229,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * profile_type, bmd->res, bmd->profile, - vertex_only, + bmd->affect_type, bmd->lim_flags & MOD_BEVEL_WEIGHT, do_clamp, dvert, @@ -246,7 +245,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * spread, mesh->smoothresh, bmd->custom_profile, - vmesh_method); + bmd->vmesh_method); result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh); @@ -286,7 +285,7 @@ static void panel_draw(const bContext *C, Panel *panel) PointerRNA ob_ptr; modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr); - bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_VERT; + bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_AFFECT_VERTICES; uiItemR(layout, &ptr, "affect", UI_ITEM_R_EXPAND, NULL, ICON_NONE); @@ -308,7 +307,7 @@ static void panel_draw(const bContext *C, Panel *panel) col = uiLayoutColumn(layout, false); uiItemR(col, &ptr, "limit_method", 0, NULL, ICON_NONE); int limit_method = RNA_enum_get(&ptr, "limit_method"); - if (limit_method != MOD_BEVEL_ANGLE) { + if (limit_method == MOD_BEVEL_ANGLE) { sub = uiLayoutColumn(col, false); uiLayoutSetActive(sub, edge_bevel); uiItemR(col, &ptr, "angle_limit", 0, NULL, ICON_NONE); @@ -331,7 +330,7 @@ static void profile_panel_draw(const bContext *C, Panel *panel) int profile_type = RNA_enum_get(&ptr, "profile_type"); int miter_inner = RNA_enum_get(&ptr, "miter_inner"); int miter_outer = RNA_enum_get(&ptr, "miter_outer"); - bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_VERT; + bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_AFFECT_VERTICES; uiItemR(layout, &ptr, "profile_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); @@ -368,7 +367,7 @@ static void geometry_panel_draw(const bContext *C, Panel *panel) PointerRNA ptr; modifier_panel_get_property_pointers(C, panel, NULL, &ptr); - bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_VERT; + bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_AFFECT_VERTICES; uiLayoutSetPropSep(layout, true); @@ -402,7 +401,7 @@ static void shading_panel_draw(const bContext *C, Panel *panel) PointerRNA ptr; modifier_panel_get_property_pointers(C, panel, NULL, &ptr); - bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_VERT; + bool edge_bevel = RNA_enum_get(&ptr, "affect") != MOD_BEVEL_AFFECT_VERTICES; uiLayoutSetPropSep(layout, true); diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index 760e4717b6d..42adf305ee9 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -150,10 +150,15 @@ static void deformVerts(ModifierData *md, static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, BMEditMesh *em, - Mesh *UNUSED(mesh), + Mesh *mesh, float (*vertexCos)[3], int numVerts) { + if (mesh != NULL) { + deformVerts(md, ctx, mesh, vertexCos, numVerts); + return; + } + CurveModifierData *cmd = (CurveModifierData *)md; bool use_dverts = false; int defgrp_index = -1; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index f6ad25ce282..4e46e135b72 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -254,7 +254,7 @@ static void remap_faces_3_6_9_12(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, @@ -322,7 +322,7 @@ static void remap_faces_5_10(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, @@ -378,7 +378,7 @@ static void remap_faces_15(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, @@ -462,7 +462,7 @@ static void remap_faces_7_11_13_14(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, @@ -531,7 +531,7 @@ static void remap_faces_19_21_22(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, @@ -585,7 +585,7 @@ static void remap_faces_23(Mesh *mesh, Mesh *split, MFace *mf, int *facepa, - int *vertpa, + const int *vertpa, int i, EdgeHash *eh, int cur, diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index c8cfc07562f..746f9e56c06 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -23,6 +23,7 @@ #include "BLI_utildefines.h" +#include "BLI_bitmap.h" #include "BLI_math.h" #include "BLT_translation.h" @@ -40,6 +41,7 @@ #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_mesh.h" +#include "BKE_mesh_wrapper.h" #include "BKE_modifier.h" #include "BKE_screen.h" @@ -139,7 +141,10 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte struct HookData_cb { float (*vertexCos)[3]; - MDeformVert *dvert; + /** + * When anything other than -1, use deform groups. + * This is not the same as checking `dvert` for NULL when we have edit-meshes. + */ int defgrp_index; struct CurveMapping *curfalloff; @@ -160,6 +165,20 @@ struct HookData_cb { bool invert_vgroup; }; +static BLI_bitmap *hook_index_array_to_bitmap(HookModifierData *hmd, const int numVerts) +{ + BLI_bitmap *indexar_used = BLI_BITMAP_NEW(numVerts, __func__); + int i; + int *index_pt; + for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { + const int j = *index_pt; + if (j < numVerts) { + BLI_BITMAP_ENABLE(indexar_used, i); + } + } + return indexar_used; +} + static float hook_falloff(const struct HookData_cb *hd, const float len_sq) { BLI_assert(hd->falloff_sq); @@ -226,7 +245,7 @@ static float hook_falloff(const struct HookData_cb *hd, const float len_sq) } } -static void hook_co_apply(struct HookData_cb *hd, const int j) +static void hook_co_apply(struct HookData_cb *hd, int j, const MDeformVert *dv) { float *co = hd->vertexCos[j]; float fac; @@ -250,9 +269,9 @@ static void hook_co_apply(struct HookData_cb *hd, const int j) } if (fac) { - if (hd->dvert) { - 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 (dv != NULL) { + fac *= hd->invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, hd->defgrp_index) : + BKE_defvert_find_weight(dv, hd->defgrp_index); } if (fac) { @@ -267,6 +286,7 @@ static void deformVerts_do(HookModifierData *hmd, const ModifierEvalContext *UNUSED(ctx), Object *ob, Mesh *mesh, + BMEditMesh *em, float (*vertexCos)[3], int numVerts) { @@ -274,6 +294,7 @@ static void deformVerts_do(HookModifierData *hmd, bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget); float dmat[4][4]; int i, *index_pt; + MDeformVert *dvert; struct HookData_cb hd; const bool invert_vgroup = (hmd->flag & MOD_HOOK_INVERT_VGROUP) != 0; @@ -283,12 +304,21 @@ static void deformVerts_do(HookModifierData *hmd, } if (hmd->curfalloff) { - BKE_curvemapping_initialize(hmd->curfalloff); + BKE_curvemapping_init(hmd->curfalloff); } /* Generic data needed for applying per-vertex calculations (initialize all members) */ hd.vertexCos = vertexCos; - MOD_get_vgroup(ob, mesh, hmd->name, &hd.dvert, &hd.defgrp_index); + + MOD_get_vgroup(ob, mesh, hmd->name, &dvert, &hd.defgrp_index); + int cd_dvert_offset = -1; + + if ((em != NULL) && (hd.defgrp_index != -1)) { + cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + if (cd_dvert_offset == -1) { + hd.defgrp_index = -1; + } + } hd.curfalloff = hmd->curfalloff; @@ -337,32 +367,62 @@ static void deformVerts_do(HookModifierData *hmd, } else if (hmd->indexar) { /* vertex indices? */ const int *origindex_ar; - /* if mesh is present and has original index data, use it */ if (mesh && (origindex_ar = CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX))) { - for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { - if (*index_pt < numVerts) { - int j; - - for (j = 0; j < numVerts; j++) { - if (origindex_ar[j] == *index_pt) { - hook_co_apply(&hd, j); - } - } + int numVerts_orig = numVerts; + if (ob->type == OB_MESH) { + const Mesh *me_orig = ob->data; + numVerts_orig = me_orig->totvert; + } + BLI_bitmap *indexar_used = hook_index_array_to_bitmap(hmd, numVerts_orig); + for (i = 0; i < numVerts; i++) { + int i_orig = origindex_ar[i]; + BLI_assert(i_orig < numVerts_orig); + if (BLI_BITMAP_TEST(indexar_used, i_orig)) { + hook_co_apply(&hd, i, dvert ? &dvert[i] : NULL); } } + MEM_freeN(indexar_used); } else { /* missing mesh or ORIGINDEX */ - for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { - if (*index_pt < numVerts) { - hook_co_apply(&hd, *index_pt); + if ((em != NULL) && (hd.defgrp_index != -1)) { + BLI_assert(em->bm->totvert == numVerts); + BLI_bitmap *indexar_used = hook_index_array_to_bitmap(hmd, numVerts); + BMIter iter; + BMVert *v; + BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) { + if (BLI_BITMAP_TEST(indexar_used, i)) { + const MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_offset); + hook_co_apply(&hd, i, dv); + } + } + MEM_freeN(indexar_used); + } + else { + for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { + const int j = *index_pt; + if (j < numVerts) { + hook_co_apply(&hd, j, dvert ? &dvert[j] : NULL); + } } } } } - else if (hd.dvert) { /* vertex group hook */ - for (i = 0; i < numVerts; i++) { - hook_co_apply(&hd, i); + else if (hd.defgrp_index != -1) { /* vertex group hook */ + if (em != NULL) { + BLI_assert(em->bm->totvert == numVerts); + BMIter iter; + BMVert *v; + BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) { + const MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_offset); + hook_co_apply(&hd, i, dv); + } + } + else { + BLI_assert(dvert != NULL); + for (i = 0; i < numVerts; i++) { + hook_co_apply(&hd, i, &dvert[i]); + } } } } @@ -376,7 +436,7 @@ static void deformVerts(struct ModifierData *md, HookModifierData *hmd = (HookModifierData *)md; Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false); - deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts); + deformVerts_do(hmd, ctx, ctx->object, mesh_src, NULL, vertexCos, numVerts); if (!ELEM(mesh_src, NULL, mesh)) { BKE_id_free(NULL, mesh_src); @@ -391,14 +451,8 @@ static void deformVertsEM(struct ModifierData *md, int numVerts) { HookModifierData *hmd = (HookModifierData *)md; - Mesh *mesh_src = MOD_deform_mesh_eval_get( - ctx->object, editData, mesh, NULL, numVerts, false, false); - - deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts); - if (!ELEM(mesh_src, NULL, mesh)) { - BKE_id_free(NULL, mesh_src); - } + deformVerts_do(hmd, ctx, ctx->object, mesh, mesh ? NULL : editData, vertexCos, numVerts); } static void panel_draw(const bContext *C, Panel *panel) diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index b1a9258ec51..bf891c4938b 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -130,10 +130,15 @@ static void deformVerts(ModifierData *md, static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em, - struct Mesh *UNUSED(mesh), + struct Mesh *mesh, float (*vertexCos)[3], int numVerts) { + if (mesh != NULL) { + deformVerts(md, ctx, mesh, vertexCos, numVerts); + return; + } + LatticeModifierData *lmd = (LatticeModifierData *)md; MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */ diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc index 93fb7749392..7b09d3c470d 100644 --- a/source/blender/modifiers/intern/MOD_mask.cc +++ b/source/blender/modifiers/intern/MOD_mask.cc @@ -44,12 +44,7 @@ #include "BKE_lib_query.h" #include "BKE_mesh.h" #include "BKE_modifier.h" - -/* SpaceType struct has a member called 'new' which obviously conflicts with C++ - * so temporarily redefining the new keyword to make it compile. */ -#define new extern_new #include "BKE_screen.h" -#undef new #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/modifiers/intern/MOD_meshcache_util.h b/source/blender/modifiers/intern/MOD_meshcache_util.h index 0a6c0e73632..74131099e3c 100644 --- a/source/blender/modifiers/intern/MOD_meshcache_util.h +++ b/source/blender/modifiers/intern/MOD_meshcache_util.h @@ -18,8 +18,7 @@ * \ingroup modifiers */ -#ifndef __MOD_MESHCACHE_UTIL_H__ -#define __MOD_MESHCACHE_UTIL_H__ +#pragma once /* MOD_meshcache_mdd.c */ bool MOD_meshcache_read_mdd_index(FILE *fp, @@ -73,5 +72,3 @@ void MOD_meshcache_calc_range(const float frame, float *r_factor); #define FRAME_SNAP_EPS 0.0001f - -#endif /* __MOD_MESHCACHE_UTIL_H__ */ diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index e53de598218..ae031bffb04 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -409,11 +409,12 @@ static void meshdeformModifier_do(ModifierData *md, totcagevert = cagemesh->totvert; if (mmd->totvert != totvert) { - BKE_modifier_set_error(md, "Verts changed from %d to %d", mmd->totvert, totvert); + BKE_modifier_set_error(md, "Vertices changed from %d to %d", mmd->totvert, totvert); goto finally; } else if (mmd->totcagevert != totcagevert) { - BKE_modifier_set_error(md, "Cage verts changed from %d to %d", mmd->totcagevert, totcagevert); + BKE_modifier_set_error( + md, "Cage vertices changed from %d to %d", mmd->totcagevert, totcagevert); goto finally; } else if (mmd->bindcagecos == NULL) { diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index 8f6676dd0b2..5513e6b4971 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -33,6 +33,8 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "MEM_guardedalloc.h" + #include "BKE_cachefile.h" #include "BKE_context.h" #include "BKE_lib_query.h" @@ -65,6 +67,9 @@ static void initData(ModifierData *md) mcmd->cache_file = NULL; mcmd->object_path[0] = '\0'; mcmd->read_flag = MOD_MESHSEQ_READ_ALL; + mcmd->velocity_scale = 1.0f; + mcmd->vertex_velocities = NULL; + mcmd->num_vertices = 0; mcmd->reader = NULL; mcmd->reader_object_path[0] = '\0'; @@ -91,6 +96,10 @@ static void freeData(ModifierData *md) mcmd->reader_object_path[0] = '\0'; BKE_cachefile_reader_free(mcmd->cache_file, &mcmd->reader); } + + if (mcmd->vertex_velocities) { + MEM_freeN(mcmd->vertex_velocities); + } } static bool isDisabled(const struct Scene *UNUSED(scene), @@ -154,6 +163,17 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * Mesh *result = ABC_read_mesh(mcmd->reader, ctx->object, mesh, time, &err_str, mcmd->read_flag); + mcmd->velocity_delta = 1.0f; + if (mcmd->cache_file->velocity_unit == CACHEFILE_VELOCITY_UNIT_SECOND) { + mcmd->velocity_delta /= FPS; + } + + mcmd->last_lookup_time = time; + + if (result != NULL) { + mcmd->num_vertices = result->totvert; + } + if (err_str) { BKE_modifier_set_error(md, "%s", err_str); } @@ -221,6 +241,8 @@ static void panel_draw(const bContext *C, Panel *panel) uiItemR(layout, &ptr, "read_data", UI_ITEM_R_EXPAND, NULL, ICON_NONE); } + uiItemR(layout, &ptr, "velocity_scale", 0, NULL, ICON_NONE); + modifier_panel_end(layout, &ptr); } diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index 53e53315cfe..f091385ff8e 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -75,6 +75,29 @@ static void initData(ModifierData *md) mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS; mmd->quality = 4; mmd->flags |= (eMultiresModifierFlag_UseCrease | eMultiresModifierFlag_ControlEdges); + + /* Open subdivision panels by default. */ + md->ui_expand_flag = (1 << 0) | (1 << 1); +} + +static void requiredDataMask(Object *UNUSED(ob), + ModifierData *md, + CustomData_MeshMasks *r_cddata_masks) +{ + MultiresModifierData *mmd = (MultiresModifierData *)md; + if (mmd->flags & eMultiresModifierFlag_UseCustomNormals) { + r_cddata_masks->lmask |= CD_MASK_NORMAL; + r_cddata_masks->lmask |= CD_MASK_CUSTOMLOOPNORMAL; + } +} + +static bool dependsOnNormals(ModifierData *md) +{ + MultiresModifierData *mmd = (MultiresModifierData *)md; + if (mmd->flags & eMultiresModifierFlag_UseCustomNormals) { + return true; + } + return false; } static void copyData(const ModifierData *md_src, ModifierData *md_dst, const int flag) @@ -205,6 +228,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Happens on bad topology, ut also on empty input mesh. */ return result; } + const bool use_clnors = mmd->flags & eMultiresModifierFlag_UseCustomNormals && + mesh->flag & ME_AUTOSMOOTH && + CustomData_has_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* NOTE: Orco needs final coordinates on CPU side, which are expected to be * accessible via MVert. For this reason we do not evaluate multires to * grids when orco is requested. */ @@ -240,7 +266,22 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * // BKE_subdiv_stats_print(&subdiv->stats); } else { + if (use_clnors) { + /* If custom normals are present and the option is turned on calculate the split + * normals and clear flag so the normals get interpolated to the result mesh. */ + BKE_mesh_calc_normals_split(mesh); + CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + } + result = multires_as_mesh(mmd, ctx, mesh, subdiv); + + if (use_clnors) { + float(*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL); + BLI_assert(lnors != NULL); + BKE_mesh_set_custom_normals(result, lnors); + CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + CustomData_set_layer_flag(&result->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + } // BKE_subdiv_stats_print(&subdiv->stats); if (subdiv != runtime_data->subdiv) { BKE_subdiv_free(subdiv); @@ -287,13 +328,37 @@ static void deformMatrices(ModifierData *md, static void panel_draw(const bContext *C, Panel *panel) { - uiLayout *row, *col, *split, *col2; + uiLayout *col; + uiLayout *layout = panel->layout; + + PointerRNA ptr; + modifier_panel_get_property_pointers(C, panel, NULL, &ptr); + + uiLayoutSetPropSep(layout, true); + + col = uiLayoutColumn(layout, true); + uiItemR(col, &ptr, "levels", 0, IFACE_("Level Viewport"), ICON_NONE); + uiItemR(col, &ptr, "sculpt_levels", 0, IFACE_("Sculpt"), ICON_NONE); + uiItemR(col, &ptr, "render_levels", 0, IFACE_("Render"), ICON_NONE); + + uiItemR(layout, &ptr, "show_only_control_edges", 0, NULL, ICON_NONE); + + modifier_panel_end(layout, &ptr); +} + +static void subdivisions_panel_draw(const bContext *C, Panel *panel) +{ + uiLayout *row; uiLayout *layout = panel->layout; PointerRNA ptr; PointerRNA ob_ptr; modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr); + uiLayoutSetEnabled(layout, RNA_enum_get(&ob_ptr, "mode") != OB_MODE_EDIT); + + MultiresModifierData *mmd = (MultiresModifierData *)ptr.data; + /** * Changing some of the properties can not be done once there is an * actual displacement stored for this multi-resolution modifier. @@ -304,33 +369,9 @@ static void panel_draw(const bContext *C, Panel *panel) * non-zero displacement, but such checks will be too slow to be done * on every redraw. */ - bool has_displacement = RNA_int_get(&ptr, "total_levels") != 0; - MultiresModifierData *mmd = (MultiresModifierData *)ptr.data; - - uiLayoutSetPropSep(layout, true); - - col = uiLayoutColumn(layout, false); - uiLayoutSetEnabled(col, !has_displacement); - uiItemR(col, &ptr, "subdivision_type", 0, NULL, ICON_NONE); - - col = uiLayoutColumn(layout, true); - uiItemR(col, &ptr, "sculpt_levels", 0, IFACE_("Levels Sculpt"), ICON_NONE); - uiItemR(col, &ptr, "levels", 0, IFACE_("Viewport"), ICON_NONE); - uiItemR(col, &ptr, "render_levels", 0, IFACE_("Render"), ICON_NONE); - uiItemR(layout, &ptr, "show_only_control_edges", 0, NULL, ICON_NONE); - uiItemS(layout); - - split = uiLayoutSplit(layout, 0.5f, false); - uiLayoutSetEnabled(split, RNA_enum_get(&ob_ptr, "mode") != OB_MODE_EDIT); - col = uiLayoutColumn(split, false); - col2 = uiLayoutColumn(split, false); - - uiItemO(col, IFACE_("Unsubdivide"), ICON_NONE, "OBJECT_OT_multires_unsubdivide"); - - row = uiLayoutRow(col2, true); PointerRNA op_ptr; - uiItemFullO(row, + uiItemFullO(layout, "OBJECT_OT_multires_subdivide", IFACE_("Subdivide"), ICON_NONE, @@ -340,10 +381,12 @@ static void panel_draw(const bContext *C, Panel *panel) &op_ptr); RNA_enum_set(&op_ptr, "mode", MULTIRES_SUBDIVIDE_CATMULL_CLARK); RNA_string_set(&op_ptr, "modifier", ((ModifierData *)mmd)->name); + + row = uiLayoutRow(layout, false); uiItemFullO(row, "OBJECT_OT_multires_subdivide", IFACE_("Simple"), - ICON_NONE, /* TODO: Needs icon, remove text */ + ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, @@ -353,7 +396,7 @@ static void panel_draw(const bContext *C, Panel *panel) uiItemFullO(row, "OBJECT_OT_multires_subdivide", IFACE_("Linear"), - ICON_NONE, /* TODO: Needs icon, remove text */ + ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, @@ -361,13 +404,41 @@ static void panel_draw(const bContext *C, Panel *panel) RNA_enum_set(&op_ptr, "mode", MULTIRES_SUBDIVIDE_LINEAR); RNA_string_set(&op_ptr, "modifier", ((ModifierData *)mmd)->name); - uiItemL(col, "", ICON_NONE); - uiItemO(col2, IFACE_("Delete Higher"), ICON_NONE, "OBJECT_OT_multires_higher_levels_delete"); + uiItemS(layout); - uiItemO(col, IFACE_("Reshape"), ICON_NONE, "OBJECT_OT_multires_reshape"); - uiItemO(col2, IFACE_("Apply Base"), ICON_NONE, "OBJECT_OT_multires_base_apply"); + uiItemO(layout, IFACE_("Unsubdivide"), ICON_NONE, "OBJECT_OT_multires_unsubdivide"); - uiItemS(layout); + row = uiLayoutRow(layout, false); + uiItemL(row, "", ICON_NONE); + uiItemO(row, IFACE_("Delete Higher"), ICON_NONE, "OBJECT_OT_multires_higher_levels_delete"); +} + +static void shape_panel_draw(const bContext *C, Panel *panel) +{ + uiLayout *row; + uiLayout *layout = panel->layout; + + PointerRNA ptr; + PointerRNA ob_ptr; + modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr); + + uiLayoutSetEnabled(layout, RNA_enum_get(&ob_ptr, "mode") != OB_MODE_EDIT); + + row = uiLayoutRow(layout, false); + uiItemO(row, IFACE_("Reshape"), ICON_NONE, "OBJECT_OT_multires_reshape"); + uiItemO(row, IFACE_("Apply Base"), ICON_NONE, "OBJECT_OT_multires_base_apply"); +} + +static void generate_panel_draw(const bContext *C, Panel *panel) +{ + uiLayout *col, *row; + uiLayout *layout = panel->layout; + + PointerRNA ptr; + modifier_panel_get_property_pointers(C, panel, NULL, &ptr); + MultiresModifierData *mmd = (MultiresModifierData *)ptr.data; + + bool is_external = RNA_boolean_get(&ptr, "is_external"); if (mmd->totlvl == 0) { uiItemO( @@ -376,16 +447,15 @@ static void panel_draw(const bContext *C, Panel *panel) col = uiLayoutColumn(layout, false); row = uiLayoutRow(col, false); - if (RNA_boolean_get(&ptr, "is_external")) { + if (is_external) { uiItemO(row, IFACE_("Pack External"), ICON_NONE, "OBJECT_OT_multires_external_pack"); + uiLayoutSetPropSep(col, true); row = uiLayoutRow(col, false); - uiItemR(row, &ptr, "filepath", 0, "", ICON_NONE); + uiItemR(row, &ptr, "filepath", 0, NULL, ICON_NONE); } else { uiItemO(col, IFACE_("Save External..."), ICON_NONE, "OBJECT_OT_multires_external_save"); } - - modifier_panel_end(layout, &ptr); } static void advanced_panel_draw(const bContext *C, Panel *panel) @@ -400,21 +470,28 @@ static void advanced_panel_draw(const bContext *C, Panel *panel) uiLayoutSetPropSep(layout, true); - col = uiLayoutColumn(layout, false); - uiLayoutSetEnabled(col, !has_displacement); - uiItemR(col, &ptr, "quality", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(layout, !has_displacement); - uiItemR(layout, &ptr, "uv_smooth", 0, NULL, ICON_NONE); + uiItemR(layout, &ptr, "subdivision_type", 0, NULL, ICON_NONE); + uiItemR(layout, &ptr, "quality", 0, NULL, ICON_NONE); col = uiLayoutColumn(layout, false); - uiLayoutSetEnabled(col, !has_displacement); - uiItemR(col, &ptr, "use_creases", 0, NULL, ICON_NONE); + uiLayoutSetEnabled(col, true); + uiItemR(col, &ptr, "uv_smooth", 0, NULL, ICON_NONE); + + uiItemR(layout, &ptr, "use_creases", 0, NULL, ICON_NONE); + uiItemR(layout, &ptr, "use_custom_normals", 0, NULL, ICON_NONE); } static void panelRegister(ARegionType *region_type) { PanelType *panel_type = modifier_panel_register(region_type, eModifierType_Multires, panel_draw); modifier_subpanel_register( + region_type, "subdivide", "Subdivions", NULL, subdivisions_panel_draw, panel_type); + modifier_subpanel_register(region_type, "shape", "Shape", NULL, shape_panel_draw, panel_type); + modifier_subpanel_register( + region_type, "generate", "Generate", NULL, generate_panel_draw, panel_type); + modifier_subpanel_register( region_type, "advanced", "Advanced", NULL, advanced_panel_draw, panel_type); } @@ -438,12 +515,12 @@ ModifierTypeInfo modifierType_Multires = { /* modifyVolume */ NULL, /* initData */ initData, - /* requiredDataMask */ NULL, + /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, /* isDisabled */ NULL, /* updateDepsgraph */ NULL, /* dependsOnTime */ NULL, - /* dependsOnNormals */ NULL, + /* dependsOnNormals */ dependsOnNormals, /* foreachObjectLink */ NULL, /* foreachIDLink */ NULL, /* foreachTexLink */ NULL, diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index cb5c67087c4..7b31886a220 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -59,7 +59,7 @@ #include "MOD_ui_common.h" #ifdef WITH_OCEANSIM -static void init_cache_data(Object *ob, struct OceanModifierData *omd) +static void init_cache_data(Object *ob, struct OceanModifierData *omd, const int resolution) { const char *relbase = BKE_modifier_path_relbase_from_global(ob); @@ -71,7 +71,7 @@ static void init_cache_data(Object *ob, struct OceanModifierData *omd) omd->chop_amount, omd->foam_coverage, omd->foam_fade, - omd->resolution); + resolution); } static void simulate_ocean_modifier(struct OceanModifierData *omd) @@ -87,7 +87,11 @@ static void initData(ModifierData *md) #ifdef WITH_OCEANSIM OceanModifierData *omd = (OceanModifierData *)md; + /* Render resolution */ omd->resolution = 7; + /* Display resolution for the non-render case */ + omd->viewport_resolution = 7; + omd->spatial_size = 50; omd->wave_alignment = 0.0; @@ -126,7 +130,7 @@ static void initData(ModifierData *md) omd->spraylayername[0] = '\0'; /* layer name empty by default */ omd->ocean = BKE_ocean_add(); - BKE_ocean_init_from_modifier(omd->ocean, omd); + BKE_ocean_init_from_modifier(omd->ocean, omd, omd->viewport_resolution); simulate_ocean_modifier(omd); #else /* WITH_OCEANSIM */ /* unused */ @@ -164,7 +168,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla tomd->oceancache = NULL; tomd->ocean = BKE_ocean_add(); - BKE_ocean_init_from_modifier(tomd->ocean, tomd); + BKE_ocean_init_from_modifier(tomd->ocean, tomd, tomd->viewport_resolution); simulate_ocean_modifier(tomd); #else /* WITH_OCEANSIM */ /* unused */ @@ -288,7 +292,7 @@ static void generate_ocean_geometry_uvs(void *__restrict userdata, } } -static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig) +static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, const int resolution) { Mesh *result; @@ -297,10 +301,10 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig) int num_verts; int num_polys; - const bool use_threading = omd->resolution > 4; + const bool use_threading = resolution > 4; - gogd.rx = omd->resolution * omd->resolution; - gogd.ry = omd->resolution * omd->resolution; + gogd.rx = resolution * resolution; + gogd.ry = resolution * resolution; gogd.res_x = gogd.rx * omd->repeat_x; gogd.res_y = gogd.ry * omd->repeat_y; @@ -362,6 +366,9 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes Mesh *result = NULL; OceanResult ocr; + const int resolution = (ctx->flag & MOD_APPLY_RENDER) ? omd->resolution : + omd->viewport_resolution; + MVert *mverts; int cfra_for_cache; @@ -383,7 +390,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes /* do ocean simulation */ if (omd->cached == true) { if (!omd->oceancache) { - init_cache_data(ob, omd); + init_cache_data(ob, omd, resolution); } BKE_ocean_simulate_cache(omd->oceancache, cfra_scene); } @@ -393,12 +400,12 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes * This function is only called on an original object when applying the modifier * using the 'Apply Modifier' button, and thus it is not called frequently for * simulation. */ - allocated_ocean |= BKE_ocean_ensure(omd); + allocated_ocean |= BKE_ocean_ensure(omd, resolution); simulate_ocean_modifier(omd); } if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) { - result = generate_ocean_geometry(omd, mesh); + result = generate_ocean_geometry(omd, mesh, resolution); BKE_mesh_ensure_normals(result); } else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) { @@ -558,7 +565,10 @@ static void panel_draw(const bContext *C, Panel *panel) uiItemR(sub, &ptr, "repeat_x", 0, IFACE_("Repeat X"), ICON_NONE); uiItemR(sub, &ptr, "repeat_y", 0, IFACE_("Y"), ICON_NONE); } - uiItemR(col, &ptr, "resolution", 0, NULL, ICON_NONE); + + sub = uiLayoutColumn(col, true); + uiItemR(sub, &ptr, "viewport_resolution", 0, IFACE_("Resolution Viewport"), ICON_NONE); + uiItemR(sub, &ptr, "resolution", 0, IFACE_("Render"), ICON_NONE); uiItemR(col, &ptr, "time", 0, NULL, ICON_NONE); @@ -598,7 +608,7 @@ static void waves_panel_draw(const bContext *C, Panel *panel) uiItemS(layout); col = uiLayoutColumn(layout, false); - uiItemR(col, &ptr, "wave_alignment", 0, IFACE_("Alignment"), ICON_NONE); + uiItemR(col, &ptr, "wave_alignment", UI_ITEM_R_SLIDER, IFACE_("Alignment"), ICON_NONE); sub = uiLayoutColumn(col, false); uiLayoutSetActive(sub, RNA_float_get(&ptr, "wave_alignment") > 0.0f); uiItemR(sub, &ptr, "wave_direction", 0, IFACE_("Direction"), ICON_NONE); @@ -657,7 +667,7 @@ static void spray_panel_draw(const bContext *C, Panel *panel) modifier_panel_get_property_pointers(C, panel, NULL, &ptr); bool use_foam = RNA_boolean_get(&ptr, "use_foam"); - bool use_spray = RNA_boolean_get(&ptr, "use_spray") && use_foam; + bool use_spray = RNA_boolean_get(&ptr, "use_spray"); uiLayoutSetPropSep(layout, true); @@ -682,7 +692,7 @@ static void spectrum_panel_draw(const bContext *C, Panel *panel) col = uiLayoutColumn(layout, false); uiItemR(col, &ptr, "spectrum", 0, NULL, ICON_NONE); if (ELEM(spectrum, MOD_OCEAN_SPECTRUM_TEXEL_MARSEN_ARSLOE, MOD_OCEAN_SPECTRUM_JONSWAP)) { - uiItemR(col, &ptr, "sharpen_peak_jonswap", 0, NULL, ICON_NONE); + uiItemR(col, &ptr, "sharpen_peak_jonswap", UI_ITEM_R_SLIDER, NULL, ICON_NONE); uiItemR(col, &ptr, "fetch_jonswap", 0, NULL, ICON_NONE); } } diff --git a/source/blender/modifiers/intern/MOD_simulation.cc b/source/blender/modifiers/intern/MOD_simulation.cc index 85eb66cd826..92ad02ae34a 100644 --- a/source/blender/modifiers/intern/MOD_simulation.cc +++ b/source/blender/modifiers/intern/MOD_simulation.cc @@ -29,6 +29,7 @@ #include "BLI_float3.hh" #include "BLI_listbase.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "DNA_mesh_types.h" @@ -45,13 +46,10 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_pointcloud.h" +#include "BKE_screen.h" #include "BKE_simulation.h" -/* SpaceType struct has a member called 'new' which obviously conflicts with C++ - * so temporarily redefining the new keyword to make it compile. */ -#define new extern_new -#include "BKE_screen.h" -#undef new +#include "BLO_read_write.h" #include "UI_interface.h" #include "UI_resources.h" @@ -90,15 +88,8 @@ static bool isDisabled(const struct Scene *UNUSED(scene), static const ParticleSimulationState *find_particle_state(SimulationModifierData *smd) { - if (smd->simulation == nullptr) { - return nullptr; - } - LISTBASE_FOREACH (const SimulationState *, state, &smd->simulation->states) { - if (state->type == SIM_STATE_TYPE_PARTICLES) { - return (ParticleSimulationState *)state; - } - } - return nullptr; + return (const ParticleSimulationState *)BKE_simulation_state_try_find_by_name_and_type( + smd->simulation, smd->data_path, SIM_TYPE_NAME_PARTICLE_SIMULATION); } static PointCloud *modifyPointCloud(ModifierData *md, @@ -117,11 +108,13 @@ static PointCloud *modifyPointCloud(ModifierData *md, } const float3 *positions = (const float3 *)CustomData_get_layer_named( - &state->attributes, CD_LOCATION, "Position"); + &state->attributes, CD_PROP_FLOAT3, "Position"); + const float *radii = (const float *)CustomData_get_layer_named( + &state->attributes, CD_PROP_FLOAT, "Radius"); memcpy(pointcloud->co, positions, sizeof(float3) * state->tot_particles); for (int i = 0; i < state->tot_particles; i++) { - pointcloud->radius[i] = 0.05f; + pointcloud->radius[i] = radii[i]; } return pointcloud; @@ -135,6 +128,9 @@ static void panel_draw(const bContext *C, Panel *panel) PointerRNA ob_ptr; modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr); + uiLayoutSetPropSep(layout, true); + uiLayoutSetPropDecorate(layout, false); + uiItemR(layout, &ptr, "simulation", 0, NULL, ICON_NONE); uiItemR(layout, &ptr, "data_path", 0, NULL, ICON_NONE); @@ -146,6 +142,37 @@ static void panelRegister(ARegionType *region_type) modifier_panel_register(region_type, eModifierType_Simulation, panel_draw); } +static void blendWrite(BlendWriter *writer, const ModifierData *md) +{ + const SimulationModifierData *smd = (const SimulationModifierData *)md; + BLO_write_string(writer, smd->data_path); +} + +static void blendRead(BlendDataReader *reader, ModifierData *md) +{ + SimulationModifierData *smd = (SimulationModifierData *)md; + BLO_read_data_address(reader, &smd->data_path); +} + +static void copyData(const ModifierData *md, ModifierData *target, const int flag) +{ + const SimulationModifierData *smd = (const SimulationModifierData *)md; + SimulationModifierData *tsmd = (SimulationModifierData *)target; + + BKE_modifier_copydata_generic(md, target, flag); + if (smd->data_path != nullptr) { + tsmd->data_path = BLI_strdup(smd->data_path); + } +} + +static void freeData(ModifierData *md) +{ + SimulationModifierData *smd = (SimulationModifierData *)md; + if (smd->data_path) { + MEM_freeN(smd->data_path); + } +} + ModifierTypeInfo modifierType_Simulation = { /* name */ "Simulation", /* structName */ "SimulationModifierData", @@ -153,7 +180,7 @@ ModifierTypeInfo modifierType_Simulation = { /* type */ eModifierTypeType_None, /* flags */ (ModifierTypeFlag)0, - /* copyData */ BKE_modifier_copydata_generic, + /* copyData */ copyData, /* deformVerts */ NULL, /* deformMatrices */ NULL, @@ -166,7 +193,7 @@ ModifierTypeInfo modifierType_Simulation = { /* initData */ NULL, /* requiredDataMask */ NULL, - /* freeData */ NULL, + /* freeData */ freeData, /* isDisabled */ isDisabled, /* updateDepsgraph */ updateDepsgraph, /* dependsOnTime */ NULL, @@ -176,6 +203,6 @@ ModifierTypeInfo modifierType_Simulation = { /* foreachTexLink */ NULL, /* freeRuntimeData */ NULL, /* panelRegister */ panelRegister, - /* blendWrite */ NULL, - /* blendRead */ NULL, + /* blendWrite */ blendWrite, + /* blendRead */ blendRead, }; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index b03b949c946..deece2b999b 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -147,7 +147,7 @@ static void smoothModifier_do( MDeformVert *dv = dvert; for (int i = 0; i < numVerts; i++, dv++) { float *vco_orig = vertexCos[i]; - if (num_accumulated_vecs[0] > 0) { + if (num_accumulated_vecs[i] > 0) { mul_v3_fl(accumulated_vecs[i], 1.0f / (float)num_accumulated_vecs[i]); } float *vco_new = accumulated_vecs[i]; @@ -174,7 +174,7 @@ static void smoothModifier_do( else { /* no vertex group */ for (int i = 0; i < numVerts; i++) { float *vco_orig = vertexCos[i]; - if (num_accumulated_vecs[0] > 0) { + if (num_accumulated_vecs[i] > 0) { mul_v3_fl(accumulated_vecs[i], 1.0f / (float)num_accumulated_vecs[i]); } float *vco_new = accumulated_vecs[i]; diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c index a56194354f8..7e5e4ecd9d3 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.c +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c @@ -284,7 +284,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex new_edge_arr = MEM_malloc_arrayN(((numEdges * 2) + numVerts), sizeof(*new_edge_arr), __func__); edge_users = MEM_malloc_arrayN(numEdges, sizeof(*edge_users), "solid_mod edges"); - edge_order = MEM_malloc_arrayN(numEdges, sizeof(*edge_order), "solid_mod eorder"); + edge_order = MEM_malloc_arrayN(numEdges, sizeof(*edge_order), "solid_mod order"); /* save doing 2 loops here... */ #if 0 diff --git a/source/blender/modifiers/intern/MOD_solidify_util.h b/source/blender/modifiers/intern/MOD_solidify_util.h index 6ab4734c451..e9f0709f7ea 100644 --- a/source/blender/modifiers/intern/MOD_solidify_util.h +++ b/source/blender/modifiers/intern/MOD_solidify_util.h @@ -18,8 +18,7 @@ * \ingroup modifiers */ -#ifndef __MOD_SOLIDIFY_UTIL_H__ -#define __MOD_SOLIDIFY_UTIL_H__ +#pragma once /* MOD_solidify_extrude.c */ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, @@ -30,5 +29,3 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh); - -#endif /* __MOD_SOLIDIFY_UTIL_H__ */ diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index d5ff31bd3b1..8424b549f85 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -36,6 +36,7 @@ #include "DNA_screen_types.h" #include "BKE_context.h" +#include "BKE_mesh.h" #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_subdiv.h" @@ -77,6 +78,26 @@ static void initData(ModifierData *md) smd->flags |= (eSubsurfModifierFlag_UseCrease | eSubsurfModifierFlag_ControlEdges); } +static void requiredDataMask(Object *UNUSED(ob), + ModifierData *md, + CustomData_MeshMasks *r_cddata_masks) +{ + SubsurfModifierData *smd = (SubsurfModifierData *)md; + if (smd->flags & eSubsurfModifierFlag_UseCustomNormals) { + r_cddata_masks->lmask |= CD_MASK_NORMAL; + r_cddata_masks->lmask |= CD_MASK_CUSTOMLOOPNORMAL; + } +} + +static bool dependsOnNormals(ModifierData *md) +{ + SubsurfModifierData *smd = (SubsurfModifierData *)md; + if (smd->flags & eSubsurfModifierFlag_UseCustomNormals) { + return true; + } + return false; +} + static void copyData(const ModifierData *md, ModifierData *target, const int flag) { #if 0 @@ -242,6 +263,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Happens on bad topology, but also on empty input mesh. */ return result; } + const bool use_clnors = (smd->flags & eSubsurfModifierFlag_UseCustomNormals) && + (mesh->flag & ME_AUTOSMOOTH) && + CustomData_has_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); + if (use_clnors) { + /* If custom normals are present and the option is turned on calculate the split + * normals and clear flag so the normals get interpolated to the result mesh. */ + BKE_mesh_calc_normals_split(mesh); + CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + } /* TODO(sergey): Decide whether we ever want to use CCG for subsurf, * maybe when it is a last modifier in the stack? */ if (true) { @@ -250,6 +280,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * else { result = subdiv_as_ccg(smd, ctx, mesh, subdiv); } + + if (use_clnors) { + float(*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL); + BLI_assert(lnors != NULL); + BKE_mesh_set_custom_normals(result, lnors); + CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + CustomData_set_layer_flag(&result->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); + } // BKE_subdiv_stats_print(&subdiv->stats); if (subdiv != runtime_data->subdiv) { BKE_subdiv_free(subdiv); @@ -416,6 +454,7 @@ static void advanced_panel_draw(const bContext *C, Panel *panel) uiItemR(layout, &ptr, "quality", 0, NULL, ICON_NONE); uiItemR(layout, &ptr, "uv_smooth", 0, NULL, ICON_NONE); uiItemR(layout, &ptr, "use_creases", 0, NULL, ICON_NONE); + uiItemR(layout, &ptr, "use_custom_normals", 0, NULL, ICON_NONE); } static void panelRegister(ARegionType *region_type) @@ -453,12 +492,12 @@ ModifierTypeInfo modifierType_Subsurf = { /* modifyVolume */ NULL, /* initData */ initData, - /* requiredDataMask */ NULL, + /* requiredDataMask */ requiredDataMask, /* freeData */ freeData, /* isDisabled */ isDisabled, /* updateDepsgraph */ NULL, /* dependsOnTime */ NULL, - /* dependsOnNormals */ NULL, + /* dependsOnNormals */ dependsOnNormals, /* foreachObjectLink */ NULL, /* foreachIDLink */ NULL, /* foreachTexLink */ NULL, diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index fc41afb6613..6a0e82a686b 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -1130,7 +1130,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd_orig, freeData((ModifierData *)smd_orig); } else if (data.success == MOD_SDEF_BIND_RESULT_OVERLAP_ERR) { - BKE_modifier_set_error((ModifierData *)smd_eval, "Target contains overlapping verts"); + BKE_modifier_set_error((ModifierData *)smd_eval, "Target contains overlapping vertices"); freeData((ModifierData *)smd_orig); } else if (data.success == MOD_SDEF_BIND_RESULT_GENERIC_ERR) { @@ -1280,7 +1280,7 @@ static void surfacedeformModifier_do(ModifierData *md, /* Poly count checks */ if (smd->numverts != numverts) { - BKE_modifier_set_error(md, "Verts changed from %u to %u", smd->numverts, numverts); + BKE_modifier_set_error(md, "Vertices changed from %u to %u", smd->numverts, numverts); return; } else if (smd->numpoly != tnumpoly) { diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c index 2f0e70d1bee..01b9e972086 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.c +++ b/source/blender/modifiers/intern/MOD_ui_common.c @@ -33,7 +33,6 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" -#include "DNA_space_types.h" #include "ED_object.h" @@ -50,24 +49,13 @@ #include "MOD_modifiertypes.h" #include "MOD_ui_common.h" /* Self include */ -static Object *get_modifier_object(const bContext *C) -{ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - if (sbuts != NULL && (sbuts->pinid != NULL) && GS(sbuts->pinid->name) == ID_OB) { - return (Object *)sbuts->pinid; - } - else { - return CTX_data_active_object(C); - } -} - /** * Poll function so these modifier panels don't show for other object types with modifiers (only * grease pencil currently). */ static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt)) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); return (ob != NULL) && (ob->type != OB_GPENCIL); } @@ -81,7 +69,7 @@ static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt)) */ static void modifier_reorder(bContext *C, Panel *panel, int new_index) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); PointerRNA props_ptr; @@ -95,14 +83,14 @@ static void modifier_reorder(bContext *C, Panel *panel, int new_index) static short get_modifier_expand_flag(const bContext *C, Panel *panel) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); return md->ui_expand_flag; } static void set_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); md->ui_expand_flag = expand_flag; } @@ -135,7 +123,7 @@ void modifier_panel_get_property_pointers(const bContext *C, PointerRNA *r_ob_ptr, PointerRNA *r_md_ptr) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); @@ -228,7 +216,7 @@ static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) ModifierData *md = (ModifierData *)md_v; PointerRNA ptr; - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); uiLayoutSetContextPointer(layout, "modifier", &ptr); uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); @@ -243,12 +231,19 @@ static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) /* Apply as shapekey. */ if (BKE_modifier_is_same_topology(md) && !BKE_modifier_is_non_geometrical(md)) { - uiItemEnumO(layout, - "OBJECT_OT_modifier_apply", - CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply As Shapekey"), - ICON_SHAPEKEY_DATA, - "apply_as", - MODIFIER_APPLY_SHAPE); + uiItemBooleanO(layout, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply As Shapekey"), + ICON_SHAPEKEY_DATA, + "OBJECT_OT_modifier_apply_as_shapekey", + "keep_modifier", + false); + + uiItemBooleanO(layout, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Save As Shapekey"), + ICON_SHAPEKEY_DATA, + "OBJECT_OT_modifier_apply_as_shapekey", + "keep_modifier", + true); } /* Duplicate. */ @@ -303,7 +298,7 @@ static void modifier_panel_header(const bContext *C, Panel *panel) uiLayout *layout = panel->layout; PointerRNA ptr; - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); /* Don't use #modifier_panel_get_property_pointers, we don't want to lock the header. */ ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); diff --git a/source/blender/modifiers/intern/MOD_ui_common.h b/source/blender/modifiers/intern/MOD_ui_common.h index 59c0fe1c413..cac8806a2bf 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.h +++ b/source/blender/modifiers/intern/MOD_ui_common.h @@ -18,8 +18,7 @@ * \ingroup modifiers */ -#ifndef __MOD_UI_COMMON_H__ -#define __MOD_UI_COMMON_H__ +#pragma once /* so modifier types match their defines */ #include "MOD_modifiertypes.h" @@ -66,5 +65,3 @@ struct PanelType *modifier_subpanel_register(struct ARegionType *region_type, #ifdef __cplusplus } #endif - -#endif /* __MOD_UI_COMMON_H__ */ diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h index a05e25d204c..05a24b92242 100644 --- a/source/blender/modifiers/intern/MOD_util.h +++ b/source/blender/modifiers/intern/MOD_util.h @@ -18,8 +18,7 @@ * \ingroup modifiers */ -#ifndef __MOD_UTIL_H__ -#define __MOD_UTIL_H__ +#pragma once /* so modifier types match their defines */ #include "MOD_modifiertypes.h" @@ -60,4 +59,3 @@ void MOD_depsgraph_update_object_bone_relation(struct DepsNodeHandle *node, struct Object *object, const char *bonename, const char *description); -#endif /* __MOD_UTIL_H__ */ diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index cbe774e91da..2657e3d894a 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -236,7 +236,7 @@ static void warpModifier_do(WarpModifierData *wmd, } if (wmd->curfalloff) { - BKE_curvemapping_initialize(wmd->curfalloff); + BKE_curvemapping_init(wmd->curfalloff); } invert_m4_m4(obinv, ob->obmat); diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index 54d3aa46344..4ee1f9f669a 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -83,7 +83,7 @@ void weightvg_do_map( } if (cmap && falloff_type == MOD_WVG_MAPPING_CURVE) { - BKE_curvemapping_initialize(cmap); + BKE_curvemapping_init(cmap); } /* Map each weight (vertex) to its new value, accordingly to the chosen mode. */ @@ -382,4 +382,4 @@ void weightvg_ui_common(const bContext *C, PointerRNA *ob_ptr, PointerRNA *ptr, } } } -}
\ No newline at end of file +} diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h index 725574dc0a5..c00acd27d38 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.h +++ b/source/blender/modifiers/intern/MOD_weightvg_util.h @@ -21,8 +21,7 @@ * \ingroup modifiers */ -#ifndef __MOD_WEIGHTVG_UTIL_H__ -#define __MOD_WEIGHTVG_UTIL_H__ +#pragma once struct CurveMapping; struct MDeformVert; @@ -92,4 +91,3 @@ void weightvg_update_vg(struct MDeformVert *dvert, const bool do_normalize); void weightvg_ui_common(const bContext *C, PointerRNA *ob_ptr, PointerRNA *ptr, uiLayout *layout); -#endif /* __MOD_WEIGHTVG_UTIL_H__ */ diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index 8039856172a..6bb4f3dc1b5 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -72,7 +72,7 @@ static void initData(ModifierData *md) wmd->default_weight = 0.0f; wmd->cmap_curve = BKE_curvemapping_add(1, 0.0, 0.0, 1.0, 1.0); - BKE_curvemapping_initialize(wmd->cmap_curve); + BKE_curvemapping_init(wmd->cmap_curve); wmd->rem_threshold = 0.01f; wmd->add_threshold = 0.01f; |