Remove direct displist creation from curve deform
This solves threading conflict which happens when having multiple objects using Curve Deform modifier with the same curve datablock. This conflict was caused by the fact that curve_deform_verts() used to temporary override curve's flags to make it path is there. Actually, it was setting CU_FOLLOW flag temporary which was only used where_on_path() (only in terms that this temporary assignment only affected this function) but it is now commented out for a while, so no reason to set this flag temporary, If it's ever to be done, we'll need to pass flags as an additional function argument. For the path creation i've extended DegNode structure which now holds extra bits which indicates what additional data depending on the graph topology is to be evaluated. Currently this is only used to indicate that curve needs path to be evaluated regardless to cu->flag state. This is so Curve Deform modifier is always happy. In the future this flag might also be used to indicate whether bmesh verts are to update (see recent commit to 3-vertex parent crash fix) or to indicate that the object is the motherball etc.
This commit is contained in:
@@ -60,6 +60,15 @@ typedef struct EvaluationContext {
|
||||
keep at false if update shall happen for the viewport. */
|
||||
} EvaluationContext;
|
||||
|
||||
/* DagNode->eval_flags */
|
||||
enum {
|
||||
/* Regardless to curve->path animation flag path is to be evaluated anyway,
|
||||
* to meet dependencies with such a things as curve modifier and other guys
|
||||
* who're using curve deform, where_on_path and so.
|
||||
*/
|
||||
DAG_EVAL_NEED_CURVE_PATH = 1,
|
||||
};
|
||||
|
||||
/* Global initialization/deinitialization */
|
||||
void DAG_init(void);
|
||||
void DAG_exit(void);
|
||||
@@ -149,6 +158,7 @@ void DAG_print_dependencies(struct Main *bmain, struct Scene *scene, struct Obje
|
||||
|
||||
struct Object *DAG_get_node_object(void *node_v);
|
||||
const char *DAG_get_node_name(void *node_v);
|
||||
short DAG_get_eval_flags_for_object(struct Scene *scene, void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ void end_latt_deform(struct LatticeDeformData *lattice_deform_data);
|
||||
int object_deform_mball(struct Object *ob, struct ListBase *dispbase);
|
||||
void outside_lattice(struct Lattice *lt);
|
||||
|
||||
void curve_deform_verts(struct Scene *scene, struct Object *cuOb, struct Object *target,
|
||||
void curve_deform_verts(struct Object *cuOb, struct Object *target,
|
||||
struct DerivedMesh *dm, float (*vertexCos)[3],
|
||||
int numVerts, const char *vgroup, short defaxis);
|
||||
void curve_deform_vector(struct Scene *scene, struct Object *cuOb, struct Object *target,
|
||||
void curve_deform_vector(struct Object *cuOb, struct Object *target,
|
||||
float orco[3], float vec[3], float mat[3][3], int no_rot_axis);
|
||||
|
||||
void lattice_deform_verts(struct Object *laOb, struct Object *target,
|
||||
|
||||
@@ -100,6 +100,13 @@ typedef struct DagNode {
|
||||
* updated aready.
|
||||
*/
|
||||
bool scheduled;
|
||||
|
||||
/* Runtime flags mainly used to determine which extra data is to be evaluated
|
||||
* during object_handle_update(). Such an extra data is what depends on the
|
||||
* DAG topology, meaning this flags indicates the data evaluation of which
|
||||
* depends on the node dependencies.
|
||||
*/
|
||||
short eval_flags;
|
||||
} DagNode;
|
||||
|
||||
typedef struct DagNodeQueueElem {
|
||||
@@ -124,7 +131,6 @@ typedef struct DagForest {
|
||||
int time; /* for flushing/tagging, compare with node->lasttime */
|
||||
} DagForest;
|
||||
|
||||
|
||||
// queue operations
|
||||
DagNodeQueue *queue_create(int slots);
|
||||
void queue_raz(DagNodeQueue *queue);
|
||||
|
||||
@@ -654,7 +654,12 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
|
||||
p2 = pp + s2;
|
||||
p3 = pp + s3;
|
||||
|
||||
/* note, commented out for follow constraint */
|
||||
/* NOTE: commented out for follow constraint
|
||||
*
|
||||
* If it's ever be uncommented watch out for curve_deform_verts()
|
||||
* which used to temporary set CU_FOLLOW flag for the curve and no
|
||||
* longer does it (because of threading issues of such a thing.
|
||||
*/
|
||||
//if (cu->flag & CU_FOLLOW) {
|
||||
|
||||
key_curve_tangent_weights(1.0f - fac, data, KEY_BSPLINE);
|
||||
|
||||
@@ -2310,7 +2310,7 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha
|
||||
if (strcmp(pchan->name, amod->channel) == 0) {
|
||||
float mat4[4][4], mat3[3][3];
|
||||
|
||||
curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis);
|
||||
curve_deform_vector(amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis);
|
||||
copy_m4_m4(mat4, pchan->pose_mat);
|
||||
mul_m4_m3m4(pchan->pose_mat, mat3, mat4);
|
||||
|
||||
|
||||
@@ -2844,3 +2844,10 @@ const char *DAG_get_node_name(void *node_v)
|
||||
|
||||
return dag_node_name(node);
|
||||
}
|
||||
|
||||
short DAG_get_eval_flags_for_object(struct Scene *scene, void *object)
|
||||
{
|
||||
DagNode *node = dag_get_node(scene->theDag, object);
|
||||
return node->eval_flags;
|
||||
}
|
||||
|
||||
|
||||
@@ -1566,8 +1566,13 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
|
||||
curve_to_filledpoly(cu, &nubase, dispbase);
|
||||
}
|
||||
|
||||
if ((cu->flag & CU_PATH) && !forOrco)
|
||||
calc_curvepath(ob, &nubase);
|
||||
if (!forOrco) {
|
||||
if ((cu->flag & CU_PATH) ||
|
||||
DAG_get_eval_flags_for_object(scene, ob) & DAG_EVAL_NEED_CURVE_PATH)
|
||||
{
|
||||
calc_curvepath(ob, &nubase);
|
||||
}
|
||||
}
|
||||
|
||||
if (!forOrco)
|
||||
curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal, forRender, renderResolution);
|
||||
|
||||
@@ -614,7 +614,7 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir
|
||||
/* co: local coord, result local too */
|
||||
/* returns quaternion for rotation, using cd->no_rot_axis */
|
||||
/* axis is using another define!!! */
|
||||
static int calc_curve_deform(Scene *scene, Object *par, float co[3],
|
||||
static int calc_curve_deform(Object *par, float co[3],
|
||||
const short axis, CurveDeform *cd, float quat_r[4])
|
||||
{
|
||||
Curve *cu = par->data;
|
||||
@@ -623,9 +623,8 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
|
||||
const int is_neg_axis = (axis > 2);
|
||||
|
||||
/* to be sure, mostly after file load */
|
||||
if (ELEM(NULL, par->curve_cache, par->curve_cache->path)) {
|
||||
BKE_displist_make_curveTypes(scene, par, 0);
|
||||
if (par->curve_cache->path == NULL) return 0; // happens on append...
|
||||
if (par->curve_cache->path == NULL) {
|
||||
return 0; // happens on append...
|
||||
}
|
||||
|
||||
/* options */
|
||||
@@ -705,12 +704,11 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
|
||||
return 0;
|
||||
}
|
||||
|
||||
void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
DerivedMesh *dm, float (*vertexCos)[3],
|
||||
void curve_deform_verts(Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
|
||||
int numVerts, const char *vgroup, short defaxis)
|
||||
{
|
||||
Curve *cu;
|
||||
int a, flag;
|
||||
int a;
|
||||
CurveDeform cd;
|
||||
int use_vgroups;
|
||||
const int is_neg_axis = (defaxis > 2);
|
||||
@@ -719,8 +717,6 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
return;
|
||||
|
||||
cu = cuOb->data;
|
||||
flag = cu->flag;
|
||||
cu->flag |= (CU_PATH | CU_FOLLOW); // needed for path & bevlist
|
||||
|
||||
init_curve_deform(cuOb, target, &cd);
|
||||
|
||||
@@ -772,7 +768,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
if (weight > 0.0f) {
|
||||
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
||||
copy_v3_v3(vec, vertexCos[a]);
|
||||
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
|
||||
calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
|
||||
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
|
||||
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
||||
}
|
||||
@@ -800,7 +796,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
if (weight > 0.0f) {
|
||||
/* already in 'cd.curvespace', prev for loop */
|
||||
copy_v3_v3(vec, vertexCos[a]);
|
||||
calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
|
||||
calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
|
||||
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
|
||||
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
||||
}
|
||||
@@ -812,7 +808,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
|
||||
for (a = 0; a < numVerts; a++) {
|
||||
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
||||
calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
|
||||
calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
|
||||
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
||||
}
|
||||
}
|
||||
@@ -827,18 +823,17 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target,
|
||||
|
||||
for (a = 0; a < numVerts; a++) {
|
||||
/* already in 'cd.curvespace', prev for loop */
|
||||
calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
|
||||
calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
|
||||
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
cu->flag = flag;
|
||||
}
|
||||
|
||||
/* input vec and orco = local coord in armature space */
|
||||
/* orco is original not-animated or deformed reference point */
|
||||
/* result written in vec and mat */
|
||||
void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
|
||||
void curve_deform_vector(Object *cuOb, Object *target,
|
||||
float orco[3], float vec[3], float mat[3][3], int no_rot_axis)
|
||||
{
|
||||
CurveDeform cd;
|
||||
@@ -857,7 +852,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
|
||||
|
||||
mul_m4_v3(cd.curvespace, vec);
|
||||
|
||||
if (calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) {
|
||||
if (calc_curve_deform(cuOb, vec, target->trackflag, &cd, quat)) {
|
||||
float qmat[3][3];
|
||||
|
||||
quat_to_mat3(qmat, quat);
|
||||
|
||||
@@ -103,6 +103,7 @@ static void updateDepgraph(ModifierData *md, DagForest *forest,
|
||||
|
||||
if (cmd->object) {
|
||||
DagNode *curNode = dag_get_node(forest, cmd->object);
|
||||
curNode->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
|
||||
|
||||
dag_add_relation(forest, curNode, obNode,
|
||||
DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Modifier");
|
||||
@@ -119,7 +120,7 @@ static void deformVerts(ModifierData *md, Object *ob,
|
||||
|
||||
/* silly that defaxis and curve_deform_verts are off by 1
|
||||
* but leave for now to save having to call do_versions */
|
||||
curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts,
|
||||
curve_deform_verts(cmd->object, ob, derivedData, vertexCos, numVerts,
|
||||
cmd->name, cmd->defaxis - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user