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.
This commit is contained in:
parent
65d8c771c7
commit
74d27bb0ef
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue