- fbx: add utility functions to filter connections to other objects by their type.

pull/14/head
Alexander Gessler 2012-07-21 18:02:10 +02:00
parent 4f6dbac919
commit 5db5634494
2 changed files with 74 additions and 5 deletions

View File

@ -734,14 +734,15 @@ LazyObject* Document::GetObject(uint64_t id) const
return it == objects.end() ? NULL : (*it).second;
}
#define MAX_CLASSNAMES 6
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const
{
std::vector<const Connection*> temp;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
ConnectionsBySource().equal_range(source);
conns.equal_range(id);
temp.reserve(std::distance(range.first,range.second));
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
@ -755,24 +756,76 @@ std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const
std::vector<const Connection*> Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns, const char* const* classnames, size_t count) const
{
ai_assert(classnames);
ai_assert(count != 0 && count <= MAX_CLASSNAMES);
size_t lenghts[MAX_CLASSNAMES];
const size_t c = count;
for (size_t i = 0; i < c; ++i) {
lenghts[i] = strlen(classnames[i]);
}
std::vector<const Connection*> temp;
const std::pair<ConnectionMap::const_iterator,ConnectionMap::const_iterator> range =
ConnectionsByDestination().equal_range(dest);
conns.equal_range(id);
temp.reserve(std::distance(range.first,range.second));
for (ConnectionMap::const_iterator it = range.first; it != range.second; ++it) {
const Token& key = (*it).second->LazyDestinationObject().GetElement().KeyToken();
const char* obtype = key.begin();
for (size_t i = 0; i < c; ++i) {
ai_assert(classnames[i]);
if(!strncmp(classnames[i],obtype,lenghts[i])) {
obtype = NULL;
break;
}
}
if(obtype) {
continue;
}
temp.push_back((*it).second);
}
std::sort(temp.begin(), temp.end(), std::mem_fun(&Connection::Compare));
return temp; // NRVO should handle this
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source) const
{
return GetConnectionsSequenced(source, ConnectionsBySource());
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsBySourceSequenced(uint64_t source, const char* const* classnames, size_t count) const
{
return GetConnectionsSequenced(source, ConnectionsBySource(),classnames, count);
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest) const
{
return GetConnectionsSequenced(dest, ConnectionsByDestination());
}
// ------------------------------------------------------------------------------------------------
std::vector<const Connection*> Document::GetConnectionsByDestinationSequenced(uint64_t dest, const char* const* classnames, size_t count) const
{
return GetConnectionsSequenced(dest, ConnectionsByDestination(),classnames, count);
}
// ------------------------------------------------------------------------------------------------
Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc)
: insertionOrder(insertionOrder)

View File

@ -89,6 +89,14 @@ public:
return being_constructed;
}
const Element& GetElement() const {
return element;
}
const Document& GetDocument() const {
return doc;
}
private:
const Document& doc;
@ -669,8 +677,16 @@ public:
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source) const;
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest) const;
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source, const char* const* classnames, size_t count) const;
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest, const char* const* classnames, size_t count) const;
const std::vector<const AnimationStack*>& AnimationStacks() const;
private:
std::vector<const Connection*> GetConnectionsSequenced(uint64_t id, const ConnectionMap&) const;
std::vector<const Connection*> GetConnectionsSequenced(uint64_t id, const ConnectionMap&, const char* const* classnames, size_t count) const;
private:
void ReadHeader();