Modifier depending on other object doesn't reset its geometry

Hi,

I’m developing a modifier which depends on another object (axis object).

The issue I have is the following: when I rotate the axis object, the modifier deforms the object it is applied to, but when the escape key is used during the rotation, the deformed object does not come back to its original geometry. The geometry seems to be “one step before” the escape key is hit and I need for instance to fake a grab (grab then escape) on axis object to retrieve the original geometry.

The modifier is eModifierTypeType_DeformOrConstruct and implements the following: copyData, applyModifier, initData, updateDepgraph, updateDepsgraph, foreachObjectLink.

The derived mesh is created with:

DerivedMesh *result = CDDM_from_template(derivedMesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);

What are the possible causes of this issue?

This is an issue where the dependencies on the other objects are not set up correctly. You can look at updateDepsgraph and foreachObjectLink for other modifiers that reference another object, for example MOD_boolean.c.

@brecht, thanks.

Here is what I’ve written, without knowing exactly what it means, but similarly as other modifiers.

I may miss something as the issue is still there with:

static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
{
	FanModifierData *fanModifierData = (FanModifierData *)md;

	walk(userData, ob, &fanModifierData->pivot, IDWALK_CB_NOP);
}

static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
	FanModifierData *fanModifierData = (FanModifierData *)md;

	if (fanModifierData->pivot != NULL)
	{
		DagNode *curNode = dag_get_node(ctx->forest, fanModifierData->pivot);

		dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Fan Modifier");
	}
}

static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
	FanModifierData *fanModifierData = (FanModifierData *)md;

	if (fanModifierData->pivot != NULL) 
	{
		DEG_add_object_relation(ctx->node, fanModifierData->pivot, DEG_OB_COMP_TRANSFORM, "Fan Modifier Pivot");
		DEG_add_object_relation(ctx->node, fanModifierData->pivot, DEG_OB_COMP_GEOMETRY, "Fan Modifier Pivot");
	}
	DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Fan Modifier Pivot");
}

And the structure is:

ModifierTypeInfo modifierType_Fan = {
	/* name */              "Fan",
	/* structName */        "FanModifierData",
	/* structSize */        sizeof(FanModifierData),
	/* type */              eModifierTypeType_DeformOrConstruct,
	/* flags */             eModifierTypeFlag_AcceptsMesh |
							/*eModifierTypeFlag_AcceptsCVs |*/
							eModifierTypeFlag_SupportsMapping |
							eModifierTypeFlag_SupportsEditmode |
							eModifierTypeFlag_EnableInEditmode,

	/* copyData */          copyData,
	/* deformVerts */       NULL,
	/* deformMatrices */    NULL,
	/* deformVertsEM */     NULL,
	/* deformMatricesEM */  NULL,
	/* applyModifier */     applyModifier,
	/* applyModifierEM */   NULL,
	/* initData */          initData,
	/* requiredDataMask */  NULL,
	/* freeData */          NULL,
	/* isDisabled */        NULL,
	/* updateDepgraph */    updateDepgraph,
	/* updateDepsgraph */   updateDepsgraph,
	/* dependsOnTime */     NULL,
	/* dependsOnNormals */	NULL,
	/* foreachObjectLink */ foreachObjectLink,
	/* foreachIDLink */     NULL,
	/* foreachTexLink */    NULL,
};

I’m not an expert at this but that looks ok to me, so I’m not sure what is going on.

Maybe you have a dependency loop, is the axis object a child of the object with the modifier perhaps? That kind of relation could create this problem.

You can run space bar > type “Dependency Relations” and it will print some info to the console about the dependencies.

@brecht, thanks for your time. But nope, no circular relation. I’ve coded other modifiers in the same principle concerning dependencies and they don’t have this issue.

Is there some “release/validate/update” or something to call at the end of the ‘applyModifier’ function when a modifier is generative (as the others I’ve done are not)?

There is nothing like that I can think of.

Maybe you are editing some data besides the DerivedMesh like object transforms, which modifiers shouldn’t do?

I don’t really have a good guess without seeing the full code.

@brecht,

I hope I don’t waste your time…

Here’s the main file:
http://pasteall.org/919180/c

And another one with some helper functions in it (in that one line 145 dm_extend may be candidate for the issue?):
http://pasteall.org/919179/c

Edit: I’ve just noticed another symptom: if the modifier depends on another object (axis object), the rendering (in 3D view) is not good with Blender Render (like if this object was moved or rotated, but it is not). It is ok with Cycles thought.