- fbx: generate inverse nodeanim channels for pivots.

pull/14/head
Alexander Gessler 2012-07-27 15:42:06 +02:00
parent 3c37c8e7da
commit ffd084a7a7
1 changed files with 45 additions and 3 deletions

View File

@ -1435,6 +1435,13 @@ private:
for (size_t i = 0; i < TransformationComp_MAXIMUM; ++i) { for (size_t i = 0; i < TransformationComp_MAXIMUM; ++i) {
const TransformationComp comp = static_cast<TransformationComp>(i); const TransformationComp comp = static_cast<TransformationComp>(i);
// inverse pivots don't exist in the input, we just generate them
if (comp == TransformationComp_RotationPivotInverse || comp == TransformationComp_ScalingPivotInverse) {
chain[i] = node_property_map.end();
continue;
}
chain[i] = node_property_map.find(NameTransformationCompProperty(comp)); chain[i] = node_property_map.find(NameTransformationCompProperty(comp));
if (chain[i] != node_property_map.end()) { if (chain[i] != node_property_map.end()) {
has_any = true; has_any = true;
@ -1507,8 +1514,36 @@ private:
(*chain[i]).second, (*chain[i]).second,
layer_map, layer_map,
max_time, max_time,
min_time min_time);
);
// pivoting requires us to generate an inverse channel to undo the pivot translation
if (comp == TransformationComp_RotationPivot) {
const std::string& invName = NameTransformationChainNode(kv.first, TransformationComp_RotationPivotInverse);
aiNodeAnim* const inv = GenerateTranslationNodeAnim(invName,
target,
(*chain[i]).second,
layer_map,
max_time,
min_time,
true);
ai_assert(inv);
node_anims.push_back(inv);
}
else if (comp == TransformationComp_ScalingPivot) {
const std::string& invName = NameTransformationChainNode(kv.first, TransformationComp_ScalingPivotInverse);
aiNodeAnim* const inv = GenerateTranslationNodeAnim(invName,
target,
(*chain[i]).second,
layer_map,
max_time,
min_time,
true);
ai_assert(inv);
node_anims.push_back(inv);
}
break; break;
case TransformationComp_Scaling: case TransformationComp_Scaling:
@ -1626,13 +1661,20 @@ private:
const std::vector<const AnimationCurveNode*>& curves, const std::vector<const AnimationCurveNode*>& curves,
const LayerMap& layer_map, const LayerMap& layer_map,
double& max_time, double& max_time,
double& min_time) double& min_time,
bool inverse = false)
{ {
ScopeGuard<aiNodeAnim> na(new aiNodeAnim()); ScopeGuard<aiNodeAnim> na(new aiNodeAnim());
na->mNodeName.Set(name); na->mNodeName.Set(name);
ConvertTranslationKeys(na, curves, layer_map, max_time,min_time); ConvertTranslationKeys(na, curves, layer_map, max_time,min_time);
if (inverse) {
for (unsigned int i = 0; i < na->mNumPositionKeys; ++i) {
na->mPositionKeys[i].mValue *= -1.0f;
}
}
// dummy scaling key // dummy scaling key
na->mScalingKeys = new aiVectorKey[1]; na->mScalingKeys = new aiVectorKey[1];
na->mNumScalingKeys = 1; na->mNumScalingKeys = 1;