MOD_curve: do not compute mesh when not needed.
This modifier only uses mesh to get vgroup, which is only needed in case modified object is indeed a mesh! Building a mesh from curve here is not only useless and time-consuming, it will also easily fail the assert about same number of vertices! Also, use MOD_get_vgroup() helper in modifier code itself and pass reluting MDeformVert & index to BKE_curve's curve_deform_verts(), this is simpler and avoids duplicating vgroup handling code. Also fixes crash when used on lattice. Related to T57972.
This commit is contained in:
parent
8cd5edf850
commit
ede994c314
|
@ -63,9 +63,8 @@ bool object_deform_mball(struct Object *ob, struct ListBase *dispbase);
|
||||||
void outside_lattice(struct Lattice *lt);
|
void outside_lattice(struct Lattice *lt);
|
||||||
|
|
||||||
void curve_deform_verts(
|
void curve_deform_verts(
|
||||||
struct Object *cuOb, struct Object *target,
|
struct Object *cuOb, struct Object *target, float (*vertexCos)[3],
|
||||||
struct Mesh *mesh, float (*vertexCos)[3],
|
int numVerts, struct MDeformVert *dvert, const int defgrp_index, short defaxis);
|
||||||
int numVerts, const char *vgroup, short defaxis);
|
|
||||||
void curve_deform_vector(
|
void curve_deform_vector(
|
||||||
struct Object *cuOb, struct Object *target,
|
struct Object *cuOb, struct Object *target,
|
||||||
float orco[3], float vec[3], float mat[3][3], int no_rot_axis);
|
float orco[3], float vec[3], float mat[3][3], int no_rot_axis);
|
||||||
|
|
|
@ -704,14 +704,12 @@ static bool calc_curve_deform(Object *par, float co[3],
|
||||||
}
|
}
|
||||||
|
|
||||||
void curve_deform_verts(
|
void curve_deform_verts(
|
||||||
Object *cuOb, Object *target, Mesh *mesh, float (*vertexCos)[3],
|
Object *cuOb, Object *target, float (*vertexCos)[3],
|
||||||
int numVerts, const char *vgroup, short defaxis)
|
int numVerts, MDeformVert *dvert, const int defgrp_index, short defaxis)
|
||||||
{
|
{
|
||||||
Curve *cu;
|
Curve *cu;
|
||||||
int a;
|
int a;
|
||||||
CurveDeform cd;
|
CurveDeform cd;
|
||||||
MDeformVert *dvert = NULL;
|
|
||||||
int defgrp_index = -1;
|
|
||||||
const bool is_neg_axis = (defaxis > 2);
|
const bool is_neg_axis = (defaxis > 2);
|
||||||
|
|
||||||
if (cuOb->type != OB_CURVE)
|
if (cuOb->type != OB_CURVE)
|
||||||
|
@ -732,26 +730,6 @@ void curve_deform_verts(
|
||||||
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f;
|
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether to use vertex groups (only possible if target is a Mesh or Lattice).
|
|
||||||
* We want either a Mesh/Lattice with no derived data, or derived data with deformverts.
|
|
||||||
*/
|
|
||||||
if (vgroup && vgroup[0] && ELEM(target->type, OB_MESH, OB_LATTICE)) {
|
|
||||||
defgrp_index = defgroup_name_index(target, vgroup);
|
|
||||||
|
|
||||||
if (defgrp_index != -1) {
|
|
||||||
/* if there's derived data without deformverts, don't use vgroups */
|
|
||||||
if (mesh) {
|
|
||||||
dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
|
|
||||||
}
|
|
||||||
else if (target->type == OB_LATTICE) {
|
|
||||||
dvert = ((Lattice *)target->data)->dvert;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dvert = ((Mesh *)target->data)->dvert;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dvert) {
|
if (dvert) {
|
||||||
MDeformVert *dvert_iter;
|
MDeformVert *dvert_iter;
|
||||||
float vec[3];
|
float vec[3];
|
||||||
|
|
|
@ -112,15 +112,23 @@ static void deformVerts(
|
||||||
int numVerts)
|
int numVerts)
|
||||||
{
|
{
|
||||||
CurveModifierData *cmd = (CurveModifierData *) md;
|
CurveModifierData *cmd = (CurveModifierData *) md;
|
||||||
Mesh *mesh_src = MOD_get_mesh_eval(ctx->object, NULL, mesh, NULL, false, false);
|
Mesh *mesh_src = NULL;
|
||||||
|
|
||||||
BLI_assert(mesh_src->totvert == numVerts);
|
if (ctx->object->type == OB_MESH) {
|
||||||
|
/* mesh_src is only needed for vgroups. */
|
||||||
|
mesh_src = MOD_get_mesh_eval(ctx->object, NULL, mesh, NULL, false, false);
|
||||||
|
BLI_assert(mesh_src->totvert == numVerts);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MDeformVert *dvert = NULL;
|
||||||
|
int defgrp_index = -1;
|
||||||
|
MOD_get_vgroup(ctx->object, mesh_src, cmd->name, &dvert, &defgrp_index);
|
||||||
|
|
||||||
/* silly that defaxis and curve_deform_verts are off by 1
|
/* silly that defaxis and curve_deform_verts are off by 1
|
||||||
* but leave for now to save having to call do_versions */
|
* but leave for now to save having to call do_versions */
|
||||||
curve_deform_verts(cmd->object, ctx->object, mesh_src, vertexCos, numVerts, cmd->name, cmd->defaxis - 1);
|
curve_deform_verts(cmd->object, ctx->object, vertexCos, numVerts, dvert, defgrp_index, cmd->defaxis - 1);
|
||||||
|
|
||||||
if (mesh_src != mesh) {
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||||
BKE_id_free(NULL, mesh_src);
|
BKE_id_free(NULL, mesh_src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue