forked from bartvdbraak/blender
Fix #27930: many modifiers crashed when used on a lattice with a vertex group.
This commit is contained in:
parent
7dfe34864e
commit
9fb2e5dde7
@ -177,10 +177,7 @@ static void sphere_do(
|
|||||||
|
|
||||||
/* 3) if we were given a vertex group name,
|
/* 3) if we were given a vertex group name,
|
||||||
* only those vertices should be affected */
|
* only those vertices should be affected */
|
||||||
defgrp_index = defgroup_name_index(ob, cmd->defgrp_name);
|
modifier_get_vgroup(ob, dm, cmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if ((ob->type == OB_MESH) && dm && defgrp_index >= 0)
|
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
if(flag & MOD_CAST_SIZE_FROM_RADIUS) {
|
if(flag & MOD_CAST_SIZE_FROM_RADIUS) {
|
||||||
len = cmd->radius;
|
len = cmd->radius;
|
||||||
@ -335,10 +332,7 @@ static void cuboid_do(
|
|||||||
|
|
||||||
/* 3) if we were given a vertex group name,
|
/* 3) if we were given a vertex group name,
|
||||||
* only those vertices should be affected */
|
* only those vertices should be affected */
|
||||||
defgrp_index = defgroup_name_index(ob, cmd->defgrp_name);
|
modifier_get_vgroup(ob, dm, cmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if ((ob->type == OB_MESH) && dm && defgrp_index >= 0)
|
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
if (ctrl_ob) {
|
if (ctrl_ob) {
|
||||||
if(flag & MOD_CAST_USE_OB_TRANSFORM) {
|
if(flag & MOD_CAST_USE_OB_TRANSFORM) {
|
||||||
|
@ -169,7 +169,7 @@ static void displaceModifier_do(
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
MVert *mvert;
|
MVert *mvert;
|
||||||
MDeformVert *dvert = NULL;
|
MDeformVert *dvert;
|
||||||
int defgrp_index;
|
int defgrp_index;
|
||||||
float (*tex_co)[3];
|
float (*tex_co)[3];
|
||||||
float weight= 1.0f; /* init value unused but some compilers may complain */
|
float weight= 1.0f; /* init value unused but some compilers may complain */
|
||||||
@ -177,11 +177,8 @@ static void displaceModifier_do(
|
|||||||
if(!dmd->texture) return;
|
if(!dmd->texture) return;
|
||||||
if(dmd->strength == 0.0f) return;
|
if(dmd->strength == 0.0f) return;
|
||||||
|
|
||||||
defgrp_index = defgroup_name_index(ob, dmd->defgrp_name);
|
|
||||||
|
|
||||||
mvert = CDDM_get_verts(dm);
|
mvert = CDDM_get_verts(dm);
|
||||||
if(defgrp_index >= 0)
|
modifier_get_vgroup(ob, dm, dmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
tex_co = MEM_callocN(sizeof(*tex_co) * numVerts,
|
tex_co = MEM_callocN(sizeof(*tex_co) * numVerts,
|
||||||
"displaceModifier_do tex_co");
|
"displaceModifier_do tex_co");
|
||||||
|
@ -157,9 +157,8 @@ static void deformVerts(ModifierData *md, Object *ob,
|
|||||||
int i, *index_pt;
|
int i, *index_pt;
|
||||||
const float falloff_squared= hmd->falloff * hmd->falloff; /* for faster comparisons */
|
const float falloff_squared= hmd->falloff * hmd->falloff; /* for faster comparisons */
|
||||||
|
|
||||||
int max_dvert= 0;
|
MDeformVert *dvert;
|
||||||
MDeformVert *dvert= NULL;
|
int defgrp_index, max_dvert;
|
||||||
int defgrp_index = -1;
|
|
||||||
|
|
||||||
/* get world-space matrix of target, corrected for the space the verts are in */
|
/* get world-space matrix of target, corrected for the space the verts are in */
|
||||||
if (hmd->subtarget[0] && pchan) {
|
if (hmd->subtarget[0] && pchan) {
|
||||||
@ -174,21 +173,8 @@ static void deformVerts(ModifierData *md, Object *ob,
|
|||||||
mul_serie_m4(mat, ob->imat, dmat, hmd->parentinv,
|
mul_serie_m4(mat, ob->imat, dmat, hmd->parentinv,
|
||||||
NULL, NULL, NULL, NULL, NULL);
|
NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
if((defgrp_index= defgroup_name_index(ob, hmd->name)) != -1) {
|
modifier_get_vgroup(ob, dm, hmd->name, &dvert, &defgrp_index);
|
||||||
Mesh *me = ob->data;
|
max_dvert = (dvert)? numVerts: 0;
|
||||||
if(dm) {
|
|
||||||
dvert= dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
if(dvert) {
|
|
||||||
max_dvert = numVerts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(me->dvert) {
|
|
||||||
dvert= me->dvert;
|
|
||||||
if(dvert) {
|
|
||||||
max_dvert = me->totvert;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Regarding index range checking below.
|
/* Regarding index range checking below.
|
||||||
*
|
*
|
||||||
|
@ -284,10 +284,7 @@ static void meshdeformModifier_do(
|
|||||||
copy_v3_v3(dco[a], co);
|
copy_v3_v3(dco[a], co);
|
||||||
}
|
}
|
||||||
|
|
||||||
defgrp_index = defgroup_name_index(ob, mmd->defgrp_name);
|
modifier_get_vgroup(ob, dm, mmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if(dm && defgrp_index >= 0)
|
|
||||||
dvert= dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
/* do deformation */
|
/* do deformation */
|
||||||
fac= 1.0f;
|
fac= 1.0f;
|
||||||
|
@ -162,8 +162,8 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
|
|||||||
float smd_limit[2], smd_factor;
|
float smd_limit[2], smd_factor;
|
||||||
SpaceTransform *transf = NULL, tmp_transf;
|
SpaceTransform *transf = NULL, tmp_transf;
|
||||||
void (*simpleDeform_callback)(const float factor, const float dcut[3], float *co) = NULL; //Mode callback
|
void (*simpleDeform_callback)(const float factor, const float dcut[3], float *co) = NULL; //Mode callback
|
||||||
int vgroup = defgroup_name_index(ob, smd->vgroup_name);
|
int vgroup;
|
||||||
MDeformVert *dvert = NULL;
|
MDeformVert *dvert;
|
||||||
|
|
||||||
//Safe-check
|
//Safe-check
|
||||||
if(smd->origin == ob) smd->origin = NULL; //No self references
|
if(smd->origin == ob) smd->origin = NULL; //No self references
|
||||||
@ -216,17 +216,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
|
|||||||
smd_factor = smd->factor / MAX2(FLT_EPSILON, smd_limit[1]-smd_limit[0]);
|
smd_factor = smd->factor / MAX2(FLT_EPSILON, smd_limit[1]-smd_limit[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier_get_vgroup(ob, dm, smd->vgroup_name, &dvert, &vgroup);
|
||||||
if(dm)
|
|
||||||
{
|
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
}
|
|
||||||
else if(ob->type == OB_LATTICE)
|
|
||||||
{
|
|
||||||
dvert = lattice_get_deform_verts(ob);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch(smd->mode)
|
switch(smd->mode)
|
||||||
{
|
{
|
||||||
|
@ -123,10 +123,7 @@ static void smoothModifier_do(
|
|||||||
medges = dm->getEdgeArray(dm);
|
medges = dm->getEdgeArray(dm);
|
||||||
numDMEdges = dm->getNumEdges(dm);
|
numDMEdges = dm->getNumEdges(dm);
|
||||||
|
|
||||||
defgrp_index = defgroup_name_index(ob, smd->defgrp_name);
|
modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if (defgrp_index >= 0)
|
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
/* NOTICE: this can be optimized a little bit by moving the
|
/* NOTICE: this can be optimized a little bit by moving the
|
||||||
* if (dvert) out of the loop, if needed */
|
* if (dvert) out of the loop, if needed */
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "MOD_modifiertypes.h"
|
#include "MOD_modifiertypes.h"
|
||||||
|
#include "MOD_util.h"
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
@ -235,12 +236,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
|||||||
float const ofs_new= smd->offset - (((-smd->offset_fac + 1.0f) * 0.5f) * smd->offset);
|
float const ofs_new= smd->offset - (((-smd->offset_fac + 1.0f) * 0.5f) * smd->offset);
|
||||||
|
|
||||||
/* weights */
|
/* weights */
|
||||||
MDeformVert *dvert= NULL, *dv= NULL;
|
MDeformVert *dvert, *dv= NULL;
|
||||||
const int defgrp_invert = ((smd->flag & MOD_SOLIDIFY_VGROUP_INV) != 0);
|
const int defgrp_invert = ((smd->flag & MOD_SOLIDIFY_VGROUP_INV) != 0);
|
||||||
const int defgrp_index= defgroup_name_index(ob, smd->defgrp_name);
|
int defgrp_index;
|
||||||
|
|
||||||
if (defgrp_index >= 0)
|
modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index);
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
|
|
||||||
orig_mface = dm->getFaceArray(dm);
|
orig_mface = dm->getFaceArray(dm);
|
||||||
orig_medge = dm->getEdgeArray(dm);
|
orig_medge = dm->getEdgeArray(dm);
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "DNA_lattice_types.h"
|
||||||
#include "DNA_modifier_types.h"
|
#include "DNA_modifier_types.h"
|
||||||
#include "DNA_object_types.h"
|
#include "DNA_object_types.h"
|
||||||
#include "DNA_curve_types.h"
|
#include "DNA_curve_types.h"
|
||||||
@ -47,6 +48,8 @@
|
|||||||
#include "BLI_math_matrix.h"
|
#include "BLI_math_matrix.h"
|
||||||
|
|
||||||
#include "BKE_cdderivedmesh.h"
|
#include "BKE_cdderivedmesh.h"
|
||||||
|
#include "BKE_deform.h"
|
||||||
|
#include "BKE_lattice.h"
|
||||||
#include "BKE_mesh.h"
|
#include "BKE_mesh.h"
|
||||||
#include "BKE_displist.h"
|
#include "BKE_displist.h"
|
||||||
|
|
||||||
@ -239,6 +242,19 @@ DerivedMesh *get_dm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*ve
|
|||||||
return dm;
|
return dm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformVert **dvert, int *defgrp_index)
|
||||||
|
{
|
||||||
|
*defgrp_index = defgroup_name_index(ob, name);
|
||||||
|
*dvert = NULL;
|
||||||
|
|
||||||
|
if(*defgrp_index >= 0) {
|
||||||
|
if(ob->type == OB_LATTICE)
|
||||||
|
*dvert = lattice_get_deform_verts(ob);
|
||||||
|
else if(dm)
|
||||||
|
*dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* only called by BKE_modifier.h/modifier.c */
|
/* only called by BKE_modifier.h/modifier.c */
|
||||||
void modifier_type_init(ModifierTypeInfo *types[])
|
void modifier_type_init(ModifierTypeInfo *types[])
|
||||||
{
|
{
|
||||||
|
@ -36,14 +36,15 @@
|
|||||||
/* so modifier types match their defines */
|
/* so modifier types match their defines */
|
||||||
#include "MOD_modifiertypes.h"
|
#include "MOD_modifiertypes.h"
|
||||||
|
|
||||||
struct Tex;
|
|
||||||
struct TexResult;
|
|
||||||
struct CustomData;
|
struct CustomData;
|
||||||
struct DerivedMesh;
|
struct DerivedMesh;
|
||||||
|
struct EditMesh;
|
||||||
|
struct MDeformVert;
|
||||||
|
struct ModifierData;
|
||||||
struct Object;
|
struct Object;
|
||||||
struct Scene;
|
struct Scene;
|
||||||
struct EditMesh;
|
struct Tex;
|
||||||
struct ModifierData;
|
struct TexResult;
|
||||||
|
|
||||||
void get_texture_value(struct Tex *texture, float *tex_co, struct TexResult *texres);
|
void get_texture_value(struct Tex *texture, float *tex_co, struct TexResult *texres);
|
||||||
void get_texture_coords(struct MappingInfoModifierData *dmd, struct Object *ob, struct DerivedMesh *dm, float (*co)[3], float (*texco)[3], int numVerts);
|
void get_texture_coords(struct MappingInfoModifierData *dmd, struct Object *ob, struct DerivedMesh *dm, float (*co)[3], float (*texco)[3], int numVerts);
|
||||||
@ -51,5 +52,6 @@ void modifier_vgroup_cache(struct ModifierData *md, float (*vertexCos)[3]);
|
|||||||
void validate_layer_name(const struct CustomData *data, int type, char *name, char *outname);
|
void validate_layer_name(const struct CustomData *data, int type, char *name, char *outname);
|
||||||
struct DerivedMesh *get_cddm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3]);
|
struct DerivedMesh *get_cddm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3]);
|
||||||
struct DerivedMesh *get_dm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3], int orco);
|
struct DerivedMesh *get_dm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3], int orco);
|
||||||
|
void modifier_get_vgroup(struct Object *ob, DerivedMesh *dm, const char *name, struct MDeformVert **dvert, int *defgrp_index);
|
||||||
|
|
||||||
#endif /* MOD_UTIL_H */
|
#endif /* MOD_UTIL_H */
|
||||||
|
@ -85,8 +85,8 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
|||||||
CustomDataMask dataMask = 0;
|
CustomDataMask dataMask = 0;
|
||||||
|
|
||||||
/* ask for vertexgroups if we need them */
|
/* ask for vertexgroups if we need them */
|
||||||
if(wmd->defgrp_name[0]) dataMask |= (1 << CD_MDEFORMVERT);
|
if(wmd->defgrp_name[0]) dataMask |= (CD_MASK_MDEFORMVERT);
|
||||||
dataMask |= (1 << CD_MDEFORMVERT);
|
dataMask |= (CD_MASK_MDEFORMVERT);
|
||||||
|
|
||||||
/* ask for UV coordinates if we need them */
|
/* ask for UV coordinates if we need them */
|
||||||
if(wmd->texmapping == MOD_DISP_MAP_UV) dataMask |= (1 << CD_MTFACE);
|
if(wmd->texmapping == MOD_DISP_MAP_UV) dataMask |= (1 << CD_MTFACE);
|
||||||
@ -174,14 +174,16 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
|
|||||||
float strength = wmd->strength;
|
float strength = wmd->strength;
|
||||||
float fac = 1.0f, weight;
|
float fac = 1.0f, weight;
|
||||||
int i;
|
int i;
|
||||||
int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
|
int defgrp_index;
|
||||||
MDeformVert *dv= NULL;
|
MDeformVert *dvert, *dv= NULL;
|
||||||
|
|
||||||
float (*tex_co)[3]= NULL;
|
float (*tex_co)[3]= NULL;
|
||||||
|
|
||||||
if(!(wmd->object_from && wmd->object_to))
|
if(!(wmd->object_from && wmd->object_to))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if(wmd->curfalloff==NULL) /* should never happen, but bad lib linking could cause it */
|
if(wmd->curfalloff==NULL) /* should never happen, but bad lib linking could cause it */
|
||||||
wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
@ -221,8 +223,8 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
|
|||||||
((fac=len_v3v3(co, mat_from[3])) < wmd->falloff_radius && (fac=(wmd->falloff_radius-fac)/wmd->falloff_radius)) ) {
|
((fac=len_v3v3(co, mat_from[3])) < wmd->falloff_radius && (fac=(wmd->falloff_radius-fac)/wmd->falloff_radius)) ) {
|
||||||
|
|
||||||
/* skip if no vert group found */
|
/* skip if no vert group found */
|
||||||
if(defgrp_index >= 0) {
|
if(dvert && defgrp_index >= 0) {
|
||||||
dv = dm->getVertData(dm, i, CD_MDEFORMVERT);
|
dv = &dvert[i];
|
||||||
|
|
||||||
if(dv) {
|
if(dv) {
|
||||||
weight = defvert_find_weight(dv, defgrp_index) * wmd->strength;
|
weight = defvert_find_weight(dv, defgrp_index) * wmd->strength;
|
||||||
|
@ -256,7 +256,7 @@ static void waveModifier_do(WaveModifierData *md,
|
|||||||
{
|
{
|
||||||
WaveModifierData *wmd = (WaveModifierData*) md;
|
WaveModifierData *wmd = (WaveModifierData*) md;
|
||||||
MVert *mvert = NULL;
|
MVert *mvert = NULL;
|
||||||
MDeformVert *dvert = NULL;
|
MDeformVert *dvert;
|
||||||
int defgrp_index;
|
int defgrp_index;
|
||||||
float ctime = BKE_curframe(scene);
|
float ctime = BKE_curframe(scene);
|
||||||
float minfac =
|
float minfac =
|
||||||
@ -281,11 +281,7 @@ static void waveModifier_do(WaveModifierData *md,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get the index of the deform group */
|
/* get the index of the deform group */
|
||||||
defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
|
modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
if(defgrp_index >= 0){
|
|
||||||
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(wmd->damp == 0) wmd->damp = 10.0f;
|
if(wmd->damp == 0) wmd->damp = 10.0f;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user