Animation system in progress
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40174
This commit is contained in:
@@ -89,3 +89,13 @@ KRAnimation *KRAnimation::Load(KRContext &context, const std::string &name, KRDa
|
|||||||
return new_animation;
|
return new_animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::map<std::string, KRAnimationLayer *> &KRAnimation::getLayers()
|
||||||
|
{
|
||||||
|
return m_layers;
|
||||||
|
}
|
||||||
|
|
||||||
|
KRAnimationLayer *KRAnimation::getLayer(const char *szName)
|
||||||
|
{
|
||||||
|
return m_layers[szName];
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ public:
|
|||||||
static KRAnimation *Load(KRContext &context, const std::string &name, KRDataBlock *data);
|
static KRAnimation *Load(KRContext &context, const std::string &name, KRDataBlock *data);
|
||||||
|
|
||||||
void addLayer(KRAnimationLayer *layer);
|
void addLayer(KRAnimationLayer *layer);
|
||||||
|
std::map<std::string, KRAnimationLayer *> &getLayers();
|
||||||
|
KRAnimationLayer *getLayer(const char *szName);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, KRAnimationLayer *> m_layers;
|
std::map<std::string, KRAnimationLayer *> m_layers;
|
||||||
|
|||||||
@@ -47,10 +47,48 @@ tinyxml2::XMLElement *KRAnimationAttribute::saveXML( tinyxml2::XMLNode *parent)
|
|||||||
tinyxml2::XMLDocument *doc = parent->GetDocument();
|
tinyxml2::XMLDocument *doc = parent->GetDocument();
|
||||||
tinyxml2::XMLElement *e = doc->NewElement("attribute");
|
tinyxml2::XMLElement *e = doc->NewElement("attribute");
|
||||||
tinyxml2::XMLNode *n = parent->InsertEndChild(e);
|
tinyxml2::XMLNode *n = parent->InsertEndChild(e);
|
||||||
|
e->SetAttribute("curve", m_curve_name.c_str());
|
||||||
|
e->SetAttribute("target", m_target_name.c_str());
|
||||||
|
e->SetAttribute("attribute", m_target_attribute_name.c_str());
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAnimationAttribute::loadXML(tinyxml2::XMLElement *e)
|
void KRAnimationAttribute::loadXML(tinyxml2::XMLElement *e)
|
||||||
{
|
{
|
||||||
|
m_curve_name = e->Attribute("curve");
|
||||||
|
m_target_name = e->Attribute("target");
|
||||||
|
m_target_attribute_name = e->Attribute("attribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string KRAnimationAttribute::getTargetName() const
|
||||||
|
{
|
||||||
|
return m_target_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAnimationAttribute::setTargetName(const std::string &target_name)
|
||||||
|
{
|
||||||
|
m_target_name = target_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string KRAnimationAttribute::getTargetAttributeName() const
|
||||||
|
{
|
||||||
|
return m_target_attribute_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAnimationAttribute::setTargetAttributeName(const std::string &target_attribute_name)
|
||||||
|
{
|
||||||
|
m_target_attribute_name = target_attribute_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string KRAnimationAttribute::getCurveName() const
|
||||||
|
{
|
||||||
|
return m_curve_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAnimationAttribute::setCurveName(const std::string &curve_name)
|
||||||
|
{
|
||||||
|
m_curve_name = curve_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,11 +44,19 @@ public:
|
|||||||
tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||||
void loadXML(tinyxml2::XMLElement *e);
|
void loadXML(tinyxml2::XMLElement *e);
|
||||||
|
|
||||||
|
std::string getCurveName() const;
|
||||||
|
void setCurveName(const std::string &curve_name);
|
||||||
|
|
||||||
std::string getTargetName() const;
|
std::string getTargetName() const;
|
||||||
void setTargetName(const std::string &target_name);
|
void setTargetName(const std::string &target_name);
|
||||||
|
|
||||||
|
std::string getTargetAttributeName() const;
|
||||||
|
void setTargetAttributeName(const std::string &target_attribute_name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_target_name;
|
std::string m_target_name;
|
||||||
|
std::string m_curve_name;
|
||||||
|
std::string m_target_attribute_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -59,7 +59,12 @@ KRAnimation *KRAnimationManager::getAnimation(const char *szName) {
|
|||||||
return m_animations[szName];
|
return m_animations[szName];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, KRAnimation *> KRAnimationManager::getAnimations() {
|
std::map<std::string, KRAnimation *> &KRAnimationManager::getAnimations() {
|
||||||
return m_animations;
|
return m_animations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRAnimationManager::addAnimation(KRAnimation *new_animation)
|
||||||
|
{
|
||||||
|
m_animations[new_animation->getName()] = new_animation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public:
|
|||||||
|
|
||||||
KRAnimation *loadAnimation(const char *szName, KRDataBlock *data);
|
KRAnimation *loadAnimation(const char *szName, KRDataBlock *data);
|
||||||
KRAnimation *getAnimation(const char *szName);
|
KRAnimation *getAnimation(const char *szName);
|
||||||
std::map<std::string, KRAnimation *> getAnimations();
|
void addAnimation(KRAnimation *new_animation);
|
||||||
|
std::map<std::string, KRAnimation *> &getAnimations();
|
||||||
|
|
||||||
void startFrame();
|
void startFrame();
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void DestroySdkObjects(KFbxSdkManager* pSdkManager);
|
|||||||
bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename);
|
bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename);
|
||||||
KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack);
|
KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack);
|
||||||
KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer);
|
KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer);
|
||||||
void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
||||||
//void BakeNode(KFbxNode* pNode);
|
//void BakeNode(KFbxNode* pNode);
|
||||||
KRNode *LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
KRNode *LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
||||||
KRNode *LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
|
KRNode *LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
|
||||||
@@ -83,6 +83,8 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
int animation_count = pFbxScene->GetSrcObjectCount(FBX_TYPE(FbxAnimStack));
|
int animation_count = pFbxScene->GetSrcObjectCount(FBX_TYPE(FbxAnimStack));
|
||||||
for(int i = 0; i < animation_count; i++) {
|
for(int i = 0; i < animation_count; i++) {
|
||||||
// FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(pFbxScene->GetSrcObject(FBX_TYPE(FbxAnimStack), i));
|
// FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(pFbxScene->GetSrcObject(FBX_TYPE(FbxAnimStack), i));
|
||||||
|
KRAnimation *new_animation = LoadAnimation(context, pFbxScene->GetSrcObject<FbxAnimStack>(i));
|
||||||
|
context.getAnimationManager()->addAnimation(new_animation);
|
||||||
resources.push_back(LoadAnimation(context, pFbxScene->GetSrcObject<FbxAnimStack>(i)));
|
resources.push_back(LoadAnimation(context, pFbxScene->GetSrcObject<FbxAnimStack>(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < pNode->GetChildCount(); i++)
|
for(int i = 0; i < pNode->GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
LoadNode(pScene->getRootNode(), resources, pGeometryConverter, pNode->GetChild(i));
|
LoadNode(pFbxScene, pScene->getRootNode(), resources, pGeometryConverter, pNode->GetChild(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,12 +447,104 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
||||||
KFbxVector4 lTmpVector;
|
KFbxVector4 lTmpVector;
|
||||||
pNode->UpdatePropertiesFromPivotsAndLimits();
|
pNode->UpdatePropertiesFromPivotsAndLimits();
|
||||||
// Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp)
|
// Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp)
|
||||||
|
|
||||||
|
// Import animated properties
|
||||||
|
int animation_count = pFbxScene->GetSrcObjectCount<FbxAnimStack>();
|
||||||
|
for(int i = 0; i < animation_count; i++) {
|
||||||
|
// FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(pFbxScene->GetSrcObject(FBX_TYPE(FbxAnimStack), i));
|
||||||
|
FbxAnimStack* pAnimStack = pFbxScene->GetSrcObject<FbxAnimStack>(i);
|
||||||
|
KRAnimation *pAnimation = parent_node->getContext().getAnimationManager()->getAnimation(pAnimStack->GetName());
|
||||||
|
int cLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
|
||||||
|
for(int iLayer=0; iLayer < cLayers; iLayer++) {
|
||||||
|
FbxAnimLayer *pFbxAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(iLayer);
|
||||||
|
KRAnimationLayer *pAnimationLayer = pAnimation->getLayer(pFbxAnimLayer->GetName());
|
||||||
|
|
||||||
|
FbxAnimCurve *pAnimCurve = pNode->LclRotation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("rotate_x");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclRotation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("rotate_y");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclRotation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("rotate_z");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclTranslation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("translate_x");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclTranslation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("translate_y");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclTranslation.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("translate_z");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclScaling.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("scale_x");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclScaling.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("scale_y");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
pAnimCurve = pNode->LclScaling.GetCurve(pFbxAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z);
|
||||||
|
if(pAnimCurve) {
|
||||||
|
KRAnimationAttribute *new_attribute = new KRAnimationAttribute(parent_node->getContext());
|
||||||
|
new_attribute->setCurveName(pAnimCurve->GetName());
|
||||||
|
new_attribute->setTargetName(pNode->GetName());
|
||||||
|
new_attribute->setTargetAttributeName("scale_z");
|
||||||
|
pAnimationLayer->addAttribute(new_attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot);
|
fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot);
|
||||||
fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot);
|
fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot);
|
||||||
@@ -481,18 +575,9 @@ void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeom
|
|||||||
assert(geometric_translation == lZero);
|
assert(geometric_translation == lZero);
|
||||||
assert(geometric_scaling == lOne);
|
assert(geometric_scaling == lOne);
|
||||||
assert(rotation_order == eEulerXYZ);
|
assert(rotation_order == eEulerXYZ);
|
||||||
//
|
|
||||||
// bool rotation_active = pNode->RotationActive.Get();
|
|
||||||
|
|
||||||
// KRVector3 node_translation = KRVector3(local_translation[0] + rotation_offset[0] + rotation_pivot[0], local_translation[1] + rotation_offset[1] + rotation_pivot[1], local_translation[2] + rotation_offset[2] + rotation_pivot[2]); // T * Roff * Rp
|
|
||||||
KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp
|
KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp
|
||||||
|
|
||||||
// KRVector3 node_rotation = KRQuaternion(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI).euler(); // R
|
|
||||||
KRVector3 node_rotation = KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI;
|
KRVector3 node_rotation = KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI;
|
||||||
// if(rotation_active) {
|
|
||||||
// node_rotation = (KRQuaternion(KRVector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI) * KRQuaternion(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI) * KRQuaternion(KRVector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI)).euler(); // Rpre * R * Rpost
|
|
||||||
// }
|
|
||||||
|
|
||||||
KRVector3 node_scale = KRVector3(local_scale[0], local_scale[1], local_scale[2]);
|
KRVector3 node_scale = KRVector3(local_scale[0], local_scale[1], local_scale[2]);
|
||||||
|
|
||||||
// printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]);
|
// printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]);
|
||||||
@@ -529,7 +614,7 @@ void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeom
|
|||||||
// Load child nodes
|
// Load child nodes
|
||||||
for(int i = 0; i < pNode->GetChildCount(); i++)
|
for(int i = 0; i < pNode->GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
LoadNode(new_node, resources, pGeometryConverter, pNode->GetChild(i));
|
LoadNode(pFbxScene, new_node, resources, pGeometryConverter, pNode->GetChild(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user