- fbx: pre-filter animated property we don't support as early as possible.
parent
51d84dcfc0
commit
5bc573edb8
|
@ -98,14 +98,76 @@ AnimationCurve::~AnimationCurve()
|
|||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
||||
AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc,
|
||||
const char* const * target_prop_whitelist /*= NULL*/, size_t whitelist_size /*= 0*/)
|
||||
: Object(id, element, name)
|
||||
, target()
|
||||
, doc(doc)
|
||||
{
|
||||
const Scope& sc = GetRequiredScope(element);
|
||||
props = GetPropertyTable(doc,"AnimationCurveNode.FbxAnimCurveNode",element,sc,false);
|
||||
|
||||
// find target node
|
||||
const char* whitelist[] = {"Model","NodeAttribute"};
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsBySourceSequenced(ID(),whitelist,2);
|
||||
|
||||
BOOST_FOREACH(const Connection* con, conns) {
|
||||
|
||||
// link should go for a property
|
||||
if (!con->PropertyName().length()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(target_prop_whitelist) {
|
||||
const char* const s = con->PropertyName().c_str();
|
||||
bool ok = false;
|
||||
for (size_t i = 0; i < whitelist_size; ++i) {
|
||||
if (!strcmp(s, target_prop_whitelist[i])) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
throw std::range_error("AnimationCurveNode target property is not in whitelist");
|
||||
}
|
||||
}
|
||||
|
||||
const Object* const ob = con->DestinationObject();
|
||||
if(!ob) {
|
||||
DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring",&element);
|
||||
continue;
|
||||
}
|
||||
|
||||
// XXX support constraints as DOM class
|
||||
//ai_assert(dynamic_cast<const Model*>(ob) || dynamic_cast<const NodeAttribute*>(ob));
|
||||
target = ob;
|
||||
if(!target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prop = con->PropertyName();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!target) {
|
||||
DOMWarning("failed to resolve target Model/NodeAttribute/Constraint for AnimationCurveNode",&element);
|
||||
}
|
||||
|
||||
props = GetPropertyTable(doc,"AnimationCurveNode.FbxAnimCurveNode",element,sc,false);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationCurveNode::~AnimationCurveNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const AnimationCurveMap& AnimationCurveNode::Curves() const
|
||||
{
|
||||
if(curves.empty()) {
|
||||
// resolve attached animation curves
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"AnimationCurve");
|
||||
|
||||
|
@ -130,58 +192,36 @@ AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, cons
|
|||
|
||||
curves[con->PropertyName()] = anim;
|
||||
}
|
||||
|
||||
}{
|
||||
|
||||
// find target node
|
||||
const char* whitelist[] = {"Model","NodeAttribute"};
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsBySourceSequenced(ID(),whitelist,2);
|
||||
|
||||
BOOST_FOREACH(const Connection* con, conns) {
|
||||
|
||||
// link should go for a property
|
||||
if (!con->PropertyName().length()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Object* const ob = con->DestinationObject();
|
||||
if(!ob) {
|
||||
DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring",&element);
|
||||
continue;
|
||||
}
|
||||
|
||||
// XXX support constraints as DOM class
|
||||
//ai_assert(dynamic_cast<const Model*>(ob) || dynamic_cast<const NodeAttribute*>(ob));
|
||||
target = ob;
|
||||
if(!target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prop = con->PropertyName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!target) {
|
||||
DOMWarning("failed to resolve target Model/NodeAttribute/Constraint for AnimationCurveNode",&element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationCurveNode::~AnimationCurveNode()
|
||||
{
|
||||
|
||||
return curves;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationLayer::AnimationLayer(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
||||
: Object(id, element, name)
|
||||
, doc(doc)
|
||||
{
|
||||
const Scope& sc = GetRequiredScope(element);
|
||||
|
||||
// note: the props table here bears little importance and is usually absent
|
||||
props = GetPropertyTable(doc,"AnimationLayer.FbxAnimLayer",element,sc, true);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationLayer::~AnimationLayer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationCurveNodeList AnimationLayer::Nodes(const char* const * target_prop_whitelist /*= NULL*/,
|
||||
size_t whitelist_size /*= 0*/) const
|
||||
{
|
||||
AnimationCurveNodeList nodes;
|
||||
|
||||
// resolve attached animation nodes
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"AnimationCurveNode");
|
||||
|
@ -205,15 +245,24 @@ AnimationLayer::AnimationLayer(uint64_t id, const Element& element, const std::s
|
|||
DOMWarning("source object for ->AnimationLayer link is not an AnimationCurveNode",&element);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(target_prop_whitelist) {
|
||||
const char* s = anim->TargetProperty().c_str();
|
||||
bool ok = false;
|
||||
for (size_t i = 0; i < whitelist_size; ++i) {
|
||||
if (!strcmp(s, target_prop_whitelist[i])) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!ok) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
nodes.push_back(anim);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AnimationLayer::~AnimationLayer()
|
||||
{
|
||||
|
||||
return nodes; // pray for NRVO
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -1746,10 +1746,16 @@ private:
|
|||
// the FBX DOM for it.
|
||||
LayerMap layer_map;
|
||||
|
||||
const char* prop_whitelist[] = {
|
||||
"Lcl Scaling",
|
||||
"Lcl Rotation",
|
||||
"Lcl Translation"
|
||||
};
|
||||
|
||||
BOOST_FOREACH(const AnimationLayer* layer, layers) {
|
||||
ai_assert(layer);
|
||||
|
||||
const AnimationCurveNodeList& nodes = layer->Nodes();
|
||||
const AnimationCurveNodeList& nodes = layer->Nodes(prop_whitelist, 3);
|
||||
BOOST_FOREACH(const AnimationCurveNode* node, nodes) {
|
||||
ai_assert(node);
|
||||
|
||||
|
|
|
@ -845,7 +845,12 @@ class AnimationCurveNode : public Object
|
|||
{
|
||||
public:
|
||||
|
||||
AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
||||
/* the optional whitelist specifies a list of property names for which the caller
|
||||
wants animations for. If the curve node does not match one of these, std::range_error
|
||||
will be thrown. */
|
||||
AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc,
|
||||
const char* const * target_prop_whitelist = NULL, size_t whitelist_size = 0);
|
||||
|
||||
~AnimationCurveNode();
|
||||
|
||||
public:
|
||||
|
@ -856,9 +861,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
const AnimationCurveMap Curves() const {
|
||||
return curves;
|
||||
}
|
||||
const AnimationCurveMap& Curves() const;
|
||||
|
||||
/** Object the curve is assigned to, this can be NULL if the
|
||||
* target object has no DOM representation or could not
|
||||
|
@ -884,9 +887,10 @@ private:
|
|||
|
||||
const Object* target;
|
||||
boost::shared_ptr<const PropertyTable> props;
|
||||
AnimationCurveMap curves;
|
||||
mutable AnimationCurveMap curves;
|
||||
|
||||
std::string prop;
|
||||
const Document& doc;
|
||||
};
|
||||
|
||||
typedef std::vector<const AnimationCurveNode*> AnimationCurveNodeList;
|
||||
|
@ -897,6 +901,7 @@ class AnimationLayer : public Object
|
|||
{
|
||||
public:
|
||||
|
||||
|
||||
AnimationLayer(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
||||
~AnimationLayer();
|
||||
|
||||
|
@ -907,14 +912,15 @@ public:
|
|||
return *props.get();
|
||||
}
|
||||
|
||||
const AnimationCurveNodeList& Nodes() const {
|
||||
return nodes;
|
||||
}
|
||||
/* the optional whitelist specifies a list of property names for which the caller
|
||||
wants animations for. Curves not matching this list will not be added to the
|
||||
animation layer. */
|
||||
AnimationCurveNodeList Nodes(const char* const * target_prop_whitelist = NULL, size_t whitelist_size = 0) const;
|
||||
|
||||
private:
|
||||
|
||||
boost::shared_ptr<const PropertyTable> props;
|
||||
AnimationCurveNodeList nodes;
|
||||
const Document& doc;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue