Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Procedural animations #176

Open
rezydent opened this issue Jan 21, 2018 · 2 comments
Open

Procedural animations #176

rezydent opened this issue Jan 21, 2018 · 2 comments

Comments

@rezydent
Copy link

Is there a proper way of programatically controlling animations at runtime for bones and constraints, that would also allow for blending with other, regular animations?
So far I managed to do it for bones by modifying animation state timeline, but it's more of a hack, so I'm wondering if I'm doing this the hard way, or there really isn't any support for that.

@akdcl
Copy link
Member

akdcl commented Feb 6, 2018

@rezydent
Copy link
Author

rezydent commented Feb 8, 2018

Thanks! Unfortunately it doesn't mix with animation states, because it's just an additive transform, but I figured out a correction for this. Here is a quick draft in case someone will need it. I'm not sure if this covers blending by groups.

void dbSetPose(dragonBones::Bone *bone, dragonBones::Transform trf, std::string animation) {
	float weight = 1.0f;
	auto states = bone->getArmature()->getAnimation()->getStates();
	int baseLayer = bone->getArmature()->getAnimation()->getState(animation)->layer;
	bool beforeBaseAnimation = true; // Priority is layer first, and then order in state list

	for (auto state : states) {
		if (state->layer < baseLayer) {
			continue;
		}
		if (state->layer == baseLayer && beforeBaseAnimation) {
			continue;
		}

		if (state->getName().compare(animation) == 0) {
			weight = min(weight, state->_weightResult);
			beforeBaseAnimation = false;
		}
		else if (state->containsBoneMask(bone->getName())) {
			weight = min(weight, 1.0 - state->_weightResult); // Apply overlaid weights
		}
	}

	trf.x *= weight;
	trf.y *= weight;
	trf.rotation *= weight;
	bone->offset = trf;
	bone->invalidUpdate();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants