From d5c05c7d8427aa459cf8a72456cccfc7551d0fd8 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Thu, 26 Jul 2012 03:58:42 +0200 Subject: [PATCH] - fbx: NodeAttribute can now be target for AnimCurveNode. - fbx: rename Camera -> CameraSwitcher. --- code/FBXAnimation.cpp | 10 ++++++---- code/FBXConverter.cpp | 10 +++++++--- code/FBXDocument.cpp | 5 +++++ code/FBXDocument.h | 23 ++++++++++++++++------- code/FBXNodeAttribute.cpp | 4 ++-- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/code/FBXAnimation.cpp b/code/FBXAnimation.cpp index 678f4c59d..0f98ad411 100644 --- a/code/FBXAnimation.cpp +++ b/code/FBXAnimation.cpp @@ -134,7 +134,8 @@ AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, cons }{ // find target node - const std::vector& conns = doc.GetConnectionsBySourceSequenced(ID(),"Model"); + const char* whitelist[] = {"Model","NodeAttribute"}; + const std::vector& conns = doc.GetConnectionsBySourceSequenced(ID(),whitelist,2); BOOST_FOREACH(const Connection* con, conns) { @@ -143,13 +144,14 @@ AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, cons continue; } - const Object* ob = con->DestinationObject(); + const Object* const ob = con->DestinationObject(); if(!ob) { DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring",&element); continue; } - target = dynamic_cast(ob); + ai_assert(dynamic_cast(ob) || dynamic_cast(ob)); + target = ob; if(!target) { continue; } @@ -159,7 +161,7 @@ AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, cons } } if(!target) { - DOMError("failed to resolve target model for animation node",&element); + DOMError("failed to resolve target Model/NodeAttribute for AnimationCurveNode",&element); } } diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index aa03d4c18..63c2a5dd2 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -944,8 +944,11 @@ private: BOOST_FOREACH(const AnimationCurveNode* node, nodes) { ai_assert(node); - const Model* model = node->TargetNode(); - ai_assert(model); + const Model* const model = dynamic_cast(node->Target()); + // this can happen - it could also be a NodeAttribute (i.e. for camera animations) + if(!model) { + continue; + } const std::string& name = FixNodeName(model->Name()); node_map[name].push_back(node); @@ -1006,7 +1009,8 @@ private: na->mNodeName.Set(kv.first); - const PropertyTable& props = curve_node->TargetNode()->Props(); + ai_assert(curve_node->TargetAsModel()); + const PropertyTable& props = curve_node->TargetAsModel()->Props(); // if a particular transformation is not given, grab it from // the corresponding node to meet the semantics of aiNodeAnim, diff --git a/code/FBXDocument.cpp b/code/FBXDocument.cpp index d29d525a7..0f3390157 100644 --- a/code/FBXDocument.cpp +++ b/code/FBXDocument.cpp @@ -467,6 +467,11 @@ const Object* LazyObject::Get(bool dieOnError) object.reset(new MeshGeometry(id,element,name,doc)); } } + else if (!strncmp(obtype,"NodeAttribute",length)) { + if (!strcmp(classtag.c_str(),"CameraSwitcher")) { + object.reset(new CameraSwitcher(id,element,doc,name)); + } + } else if (!strncmp(obtype,"Model",length)) { object.reset(new Model(id,element,doc,name)); } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index 1843064b9..75efe71c1 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -172,12 +172,12 @@ private: /** DOM base class for FBX camera settings attached to a node */ -class Camera : public NodeAttribute +class CameraSwitcher : public NodeAttribute { public: - Camera(uint64_t id, const Element& element, const Document& doc, const std::string& name); - ~Camera(); + CameraSwitcher(uint64_t id, const Element& element, const Document& doc, const std::string& name); + ~CameraSwitcher(); public: @@ -554,19 +554,28 @@ public: return curves; } - /** Model instance the curve is assigned to, this is always non-NULL */ - const Model* TargetNode() const { + /** Model or NodeAttribute the curve is assigned to, this is always non-NULL + * and never an objects not deriving one of the two aforementioned classes.*/ + const Object* Target() const { return target; } - /** Property of TargetNode() that is being animated*/ + const Model* TargetAsModel() const { + return dynamic_cast(target); + } + + const NodeAttribute* TargetAsNodeAttribute() const { + return dynamic_cast(target); + } + + /** Property of Target() that is being animated*/ const std::string& TargetProperty() const { return prop; } private: - const Model* target; + const Object* target; boost::shared_ptr props; AnimationCurveMap curves; diff --git a/code/FBXNodeAttribute.cpp b/code/FBXNodeAttribute.cpp index 76ec8dfe4..508fed6de 100644 --- a/code/FBXNodeAttribute.cpp +++ b/code/FBXNodeAttribute.cpp @@ -76,7 +76,7 @@ NodeAttribute::~NodeAttribute() // ------------------------------------------------------------------------------------------------ -Camera::Camera(uint64_t id, const Element& element, const Document& doc, const std::string& name) +CameraSwitcher::CameraSwitcher(uint64_t id, const Element& element, const Document& doc, const std::string& name) : NodeAttribute(id,element,doc,name) { const Scope& sc = GetRequiredScope(element); @@ -99,7 +99,7 @@ Camera::Camera(uint64_t id, const Element& element, const Document& doc, const s // ------------------------------------------------------------------------------------------------ -Camera::~Camera() +CameraSwitcher::~CameraSwitcher() { }