소스 검색

- fbx: generate inverse nodeanim channels for pivots.

Alexander Gessler 13 년 전
부모
커밋
ffd084a7a7
1개의 변경된 파일45개의 추가작업 그리고 3개의 파일을 삭제
  1. 45 3
      code/FBXConverter.cpp

+ 45 - 3
code/FBXConverter.cpp

@@ -1435,6 +1435,13 @@ private:
 
 				for (size_t i = 0; i < TransformationComp_MAXIMUM; ++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));
 					if (chain[i] != node_property_map.end()) {
 						has_any = true;
@@ -1507,8 +1514,36 @@ private:
 								(*chain[i]).second,
 								layer_map,
 								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;
 
 						case TransformationComp_Scaling:
@@ -1626,13 +1661,20 @@ private:
 		const std::vector<const AnimationCurveNode*>& curves,
 		const LayerMap& layer_map,
 		double& max_time,
-		double& min_time)
+		double& min_time,
+		bool inverse = false)
 	{
 		ScopeGuard<aiNodeAnim> na(new aiNodeAnim());
 		na->mNodeName.Set(name);
 
 		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
 		na->mScalingKeys = new aiVectorKey[1];
 		na->mNumScalingKeys = 1;