From 4416c05bb54307f79bb12118f87b4a8d07f6fb33 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 11 Nov 2018 11:14:49 +0800 Subject: [PATCH] Export translation to FBX --- src/fbxfile.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/src/fbxfile.cpp b/src/fbxfile.cpp index da473460..939ba071 100644 --- a/src/fbxfile.cpp +++ b/src/fbxfile.cpp @@ -2449,6 +2449,126 @@ FbxFileWriter::FbxFileWriter(Outcome &outcome, } } + for (const auto &jointIndex: translatedJoints) { + int64_t animationCurveIds[3]; + std::vector ktimes; + std::vector values[3]; + for (int curveIndex = 0; curveIndex < 3; ++curveIndex) { + animationCurveIds[curveIndex] = m_next64Id++; + } + double timePoint = 0; + for (int frame = 0; frame < (int)motion.second.size(); frame++) { + const auto &keyframe = motion.second[frame]; + const auto &translation = keyframe.second.nodes()[jointIndex].translation; + double x = translation.x(); + double y = translation.y(); + double z = translation.z(); + + values[0].push_back(x); + values[1].push_back(y); + values[2].push_back(z); + ktimes.push_back(secondsToKtime(timePoint)); + timePoint += keyframe.first; + + FBXNode animationCurveNode("AnimationCurveNode"); + int64_t animationCurveNodeId = m_next64Id++; + animationCurveNode.addProperty(animationCurveNodeId); + animationCurveNode.addProperty(std::vector({'T',0,1,'A','n','i','m','C','u','r','v','e','N','o','d','e'}), 'S'); + animationCurveNode.addProperty(""); + { + FBXNode properties("Properties70"); + { + FBXNode p("P"); + p.addProperty("d|X"); + p.addProperty("Number"); + p.addProperty(""); + p.addProperty("A"); + p.addProperty((double)x); + properties.addChild(p); + } + { + FBXNode p("P"); + p.addProperty("d|Y"); + p.addProperty("Number"); + p.addProperty(""); + p.addProperty("A"); + p.addProperty((double)y); + properties.addChild(p); + } + { + FBXNode p("P"); + p.addProperty("d|Z"); + p.addProperty("Number"); + p.addProperty(""); + p.addProperty("A"); + p.addProperty((double)z); + properties.addChild(p); + } + properties.addChild(FBXNode()); + animationCurveNode.addChild(properties); + } + animationCurveNode.addChild(FBXNode()); + animationCurveNodes.push_back(animationCurveNode); + + { + FBXNode p("C"); + p.addProperty("OO"); + p.addProperty(animationCurveNodeId); + p.addProperty(animationLayerId); + connections.addChild(p); + } + { + FBXNode p("C"); + p.addProperty("OP"); + p.addProperty(animationCurveNodeId); + p.addProperty(limbNodeIds[1 + jointIndex]); + p.addProperty("Lcl Translation"); + connections.addChild(p); + } + { + FBXNode p("C"); + p.addProperty("OP"); + p.addProperty(animationCurveIds[0]); + p.addProperty(animationCurveNodeId); + p.addProperty("d|X"); + connections.addChild(p); + } + { + FBXNode p("C"); + p.addProperty("OP"); + p.addProperty(animationCurveIds[1]); + p.addProperty(animationCurveNodeId); + p.addProperty("d|Y"); + connections.addChild(p); + } + { + FBXNode p("C"); + p.addProperty("OP"); + p.addProperty(animationCurveIds[2]); + p.addProperty(animationCurveNodeId); + p.addProperty("d|Z"); + connections.addChild(p); + } + } + + for (int curveIndex = 0; curveIndex < 3; ++curveIndex) + { + FBXNode animationCurve("AnimationCurve"); + animationCurve.addProperty(animationCurveIds[curveIndex]); + animationCurve.addProperty(std::vector({'C','u','r','v','e',(uint8_t)('1'+curveIndex),0,1,'A','n','i','m','C','u','r','v','e'}), 'S'); + animationCurve.addProperty(""); + animationCurve.addPropertyNode("Default", (double)0.000000); + animationCurve.addPropertyNode("KeyVer", (int32_t)4008); + animationCurve.addPropertyNode("KeyTime", ktimes); + animationCurve.addPropertyNode("KeyValueFloat", values[curveIndex]); + animationCurve.addPropertyNode("KeyAttrFlags", std::vector(1, 24836)); + animationCurve.addPropertyNode("KeyAttrDataFloat", std::vector(4, 0.000000)); + animationCurve.addPropertyNode("KeyAttrRefCount", std::vector(1, ktimes.size())); + animationCurve.addChild(FBXNode()); + animationCurves.push_back(animationCurve); + } + } + for (const auto &jointIndex: rotatedJoints) { int64_t animationCurveIds[3]; std::vector ktimes;