20 #include "libxml/parser.h"
21 #include "libxml/xmlerror.h"
27 #include "FUtils/FUXmlParser.h"
33 struct SkeletonMap :
public std::map<std::string, const Skeleton*>
37 for (iterator it = begin(); it != end(); ++it)
71 for (
size_t i = 0; i <
m->bones.size(); ++i)
72 if (
m->bones[i].name == name)
73 return m->bones[i].targetId;
79 for (
size_t i = 0; i <
m->bones.size(); ++i)
80 if (
m->bones[i].name == name)
81 return m->bones[i].realTargetId;
87 return (
int)
m->target->m->bones.size();
94 for (
size_t i = 0; i < bones.size(); ++i)
95 if (bones[i].targetId == targetId)
103 xmlNodeList boneNodes;
104 FUXmlParser::FindChildrenByType(parent,
"bone", boneNodes);
105 for (xmlNodeList::iterator boneNode = boneNodes.begin(); boneNode != boneNodes.end(); ++boneNode)
107 std::string name (FUXmlParser::ReadNodeProperty(*boneNode,
"name"));
112 std::string newTargetName = targetName;
116 xmlNode* targetNode = FUXmlParser::FindChildByType(*boneNode,
"target");
118 newTargetName = FUXmlParser::ReadNodeContentFull(targetNode);
122 REQUIRE(b.
targetId != -1,
"skeleton bone target matches some standard_skeleton bone name");
145 xmlNodeList skeletonNodes;
146 FUXmlParser::FindChildrenByType(root,
"standard_skeleton", skeletonNodes);
147 FUXmlParser::FindChildrenByType(root,
"skeleton", skeletonNodes);
148 for (xmlNodeList::iterator skeletonNode = skeletonNodes.begin();
149 skeletonNode != skeletonNodes.end(); ++skeletonNode)
151 std::auto_ptr<Skeleton> skeleton (
new Skeleton());
153 std::string title (FUXmlParser::ReadNodeProperty(*skeletonNode,
"title"));
155 skeleton->m->title = title;
157 if (IsEquivalent((*skeletonNode)->name,
"standard_skeleton"))
159 skeleton->m->target = NULL;
163 std::string id (FUXmlParser::ReadNodeProperty(*skeletonNode,
"id"));
164 REQUIRE(!
id.empty(),
"standard_skeleton has id");
173 std::string target (FUXmlParser::ReadNodeProperty(*skeletonNode,
"target"));
175 REQUIRE(targetSkeleton != NULL,
"skeleton target matches some standard_skeleton id");
177 skeleton->m->target = targetSkeleton;
183 xmlNode* identifier = FUXmlParser::FindChildByType(*skeletonNode,
"identifier");
184 REQUIRE(identifier != NULL,
"skeleton has <identifier>");
185 xmlNode* identRoot = FUXmlParser::FindChildByType(identifier,
"root");
186 REQUIRE(identRoot != NULL,
"skeleton identifier has <root>");
187 std::string identRootName (FUXmlParser::ReadNodeContentFull(identRoot));
203 doc = xmlParseMemory(xmlData, (
int)xmlLength);
206 xmlNode* root = xmlDocGetRootElement(doc);
211 xmlSetGenericErrorFunc(NULL, NULL);
217 xmlSetGenericErrorFunc(NULL, NULL);
221 if (! xmlErrors.empty())
static const Skeleton * FindSkeleton(const std::string &rootBoneName)
Tries to find a skeleton that matches the given root bone name.
#define REQUIRE(value, message)
Throws a ColladaException unless the value is true.
std::vector< Bone > bones
bool AlreadyUsedTargetBone(const std::vector< Bone > &bones, int targetId)
std::auto_ptr< Skeleton_impl > m
void LoadSkeletonBones(xmlNode *parent, std::vector< Bone > &bones, const Skeleton *targetSkeleton, const std::string &targetName)
int GetBoneCount() const
Returns the number of bones in the standard-skeleton which this current skeleton is mapped onto...
SkeletonMap g_StandardSkeletons
int GetRealBoneID(const std::string &name) const
Similar to GetBoneID, but only returns a value for the most important (first) nonstandard-skeleton bo...
static void LoadSkeletonDataFromXml(const char *xmlData, size_t xmlLength, std::string &xmlErrors)
Initialises the global state with skeleton data loaded from the given XML data.
void errorHandler(void *ctx, const char *msg,...)
Error handler for libxml2.
void LoadSkeletonData(xmlNode *root)
SkeletonMap g_MappedSkeletons
Skeleton()
Default constructor - don't use; use FindSkeleton instead.
int GetBoneID(const std::string &name) const
Returns the ID number of the standard-skeleton bone, which corresponds to the named nonstandard-skele...