diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-09-11 12:10:46 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-09-19 12:51:25 +0300 |
commit | 74d27bb0efaddbd5f49eb58ff2ce1cfde2a53804 (patch) | |
tree | 6ee075842fa1e6a60c9ef1119b7f724269b39d2d /source/blender/modifiers/intern | |
parent | 65d8c771c7b7c0b0e3416222cf81c8aee97e0ed3 (diff) |
Subdiv: Add vertex deformation callback to multires/subsurf
Currently unused but the intention is to use this to hook up these
modifiers to a generic deformed PBVH to make it easier to sculpt or
paint on a subdivided mesh.
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r-- | source/blender/modifiers/intern/MOD_multires.c | 33 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_subsurf.c | 32 |
2 files changed, 63 insertions, 2 deletions
diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index dd7c001931c..53bb579128a 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -38,6 +38,7 @@ #include "BKE_paint.h" #include "BKE_subdiv.h" #include "BKE_subdiv_ccg.h" +#include "BKE_subdiv_deform.h" #include "BKE_subdiv_mesh.h" #include "BKE_subsurf.h" @@ -227,6 +228,36 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes return result; } +static void deformVerts(ModifierData *md, + const ModifierEvalContext *UNUSED(ctx), + Mesh *mesh, + float (*vertex_cos)[3], + int num_verts) +{ +#if !defined(WITH_OPENSUBDIV) + modifier_setError(md, "Disabled, built without OpenSubdiv"); + return; +#endif + MultiresModifierData *mmd = (MultiresModifierData *)md; + SubdivSettings subdiv_settings; + BKE_multires_subdiv_settings_init(&subdiv_settings, mmd); + if (subdiv_settings.level == 0) { + return; + } + BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh); + MultiresRuntimeData *runtime_data = multires_ensure_runtime(mmd); + Subdiv *subdiv = subdiv_descriptor_ensure(mmd, &subdiv_settings, mesh); + if (subdiv == NULL) { + /* Happens on bad topology, ut also on empty input mesh. */ + return; + } + BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd); + BKE_subdiv_deform_coarse_vertices(subdiv, mesh, vertex_cos, num_verts); + if (subdiv != runtime_data->subdiv) { + BKE_subdiv_free(subdiv); + } +} + ModifierTypeInfo modifierType_Multires = { /* name */ "Multires", /* structName */ "MultiresModifierData", @@ -237,7 +268,7 @@ ModifierTypeInfo modifierType_Multires = { /* copyData */ copyData, - /* deformVerts */ NULL, + /* deformVerts */ deformVerts, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 08a884fa879..55df1b5ddda 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -35,6 +35,7 @@ #include "BKE_scene.h" #include "BKE_subdiv.h" #include "BKE_subdiv_ccg.h" +#include "BKE_subdiv_deform.h" #include "BKE_subdiv_mesh.h" #include "BKE_subsurf.h" @@ -240,6 +241,35 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes return result; } +static void deformVerts(ModifierData *md, + const ModifierEvalContext *UNUSED(ctx), + Mesh *mesh, + float (*vertex_cos)[3], + int num_verts) +{ +#if !defined(WITH_OPENSUBDIV) + modifier_setError(md, "Disabled, built without OpenSubdiv"); + return; +#endif + SubsurfModifierData *smd = (SubsurfModifierData *)md; + SubdivSettings subdiv_settings; + subdiv_settings_init(&subdiv_settings, smd); + if (subdiv_settings.level == 0) { + return; + } + BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh); + SubsurfRuntimeData *runtime_data = subsurf_ensure_runtime(smd); + Subdiv *subdiv = subdiv_descriptor_ensure(smd, &subdiv_settings, mesh); + if (subdiv == NULL) { + /* Happens on bad topology, but also on empty input mesh. */ + return; + } + BKE_subdiv_deform_coarse_vertices(subdiv, mesh, vertex_cos, num_verts); + if (subdiv != runtime_data->subdiv) { + BKE_subdiv_free(subdiv); + } +} + ModifierTypeInfo modifierType_Subsurf = { /* name */ "Subdivision", /* structName */ "SubsurfModifierData", @@ -251,7 +281,7 @@ ModifierTypeInfo modifierType_Subsurf = { /* copyData */ copyData, - /* deformVerts */ NULL, + /* deformVerts */ deformVerts, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, |