Page MenuHome

Issue with add_weighted_dq_dq function in BLI_math_rotation.h
Closed, ArchivedPublic

Description

Blender Version
Broken: version: 2.80 (sub 53), branch: master, commit date: 2019-04-04 17:02, hash: rB59d0582a750c
Worked: (optional)

Short description of error
I didn't know where to ask about this, so I'm posting it as a bug.

add_weighted_dq_dq is used for creating a weighted sum of dual quats. However, it handles scale incorrectly when some added quats have scaling and some don't.

If I create a dual quat from a unit matrix, and try to blend it with a scaled dual quat, add_weighted_dq_dq will produce a result with the wrong scaling.

void add_weighted_dq_dq(DualQuat *dqsum, const DualQuat *dq, float weight)
{
	bool flipped = false;

	/* make sure we interpolate quats in the right direction */
	if (dot_qtqt(dq->quat, dqsum->quat) < 0) {
		flipped = true;
		weight = -weight;
	}

	/* interpolate rotation and translation */
	dqsum->quat[0] += weight * dq->quat[0];
	dqsum->quat[1] += weight * dq->quat[1];
	dqsum->quat[2] += weight * dq->quat[2];
	dqsum->quat[3] += weight * dq->quat[3];

	dqsum->trans[0] += weight * dq->trans[0];
	dqsum->trans[1] += weight * dq->trans[1];
	dqsum->trans[2] += weight * dq->trans[2];
	dqsum->trans[3] += weight * dq->trans[3];

	/* interpolate scale - but only if needed */
	if (dq->scale_weight) {
		float wmat[4][4];

		if (flipped) {
			/* we don't want negative weights for scaling */
			weight = -weight;
		}

		copy_m4_m4(wmat, (float(*)[4])dq->scale);
		mul_m4_fl(wmat, weight);
		add_m4_m4m4(dqsum->scale, dqsum->scale, wmat);
		dqsum->scale_weight += weight;
	}
}

For what I assume are performance reasons, the function totally ignores unscaled quats instead of treating them as having unit scale and that is causing the issue.

Is this a bug or am I supposed to work around this issue some way?

Event Timeline

Brecht Van Lommel (brecht) closed this task as Archived.Apr 7 2019, 2:11 AM
Brecht Van Lommel (brecht) claimed this task.

The remaining weight for dual quats without scaling is added in normalize_dq. The API could be improved to clarify that normalize_dq must always be used, but this is not the kind of thing we handle in the bug tracker.

Better use devtalk.blender.org, bf-committers or code reviews for these kinds of questions.