Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
StdSkeletons.h
Go to the documentation of this file.
1/* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_STDSKELETONS
19#define INCLUDED_STDSKELETONS
20
21#include <string>
22#include <memory>
23
24/*
25
26Rough skeleton concept:
27
28Different modelling/animation programs use different skeleton structures for
29conceptually similar situations (e.g. humanoid bipeds). We'd like the game to
30handle combinations of models and animations from different programs, so the
31exported data must use a standard skeleton structure.
32
33Rather than requiring awkward reconfiguration of those programs, we use an
34XML file which defines a small set of standard skeletons (e.g. "biped") and
35also a number of modelling-program-specific skeleton structures (e.g. "3ds Max
36biped"). The non-standard ones define which bones we should expect to find,
37and what standard bone they should get mapped onto. Sometimes multiple bones
38will be mapped onto the same one (e.g. a series of fingers would all get mapped
39onto a single hand bone), so the conversion is slightly lossy.
40
41It is possible to have multiple independent standard skeletons - they just need
42to be identified by using different bone names in the modelling program. The
43game doesn't check that you're using models and animations with the same standard
44skeleton, so that's up to the artists to take care of.
45
46*/
47
48struct Skeleton_impl;
49
51{
52public:
53 /** Default constructor - don't use; use FindSkeleton instead. */
54 Skeleton();
55 ~Skeleton();
56
57 /**
58 * Returns the number of bones in the standard-skeleton which this current
59 * skeleton is mapped onto.
60 */
61 int GetBoneCount() const;
62
63 /**
64 * Returns the ID number of the standard-skeleton bone, which corresponds
65 * to the named nonstandard-skeleton bone. Returns -1 if none is found.
66 * Can return the same value for multiple bones.
67 */
68 int GetBoneID(const std::string& name) const;
69
70 /**
71 * Similar to GetBoneID, but only returns a value for the most important (first)
72 * nonstandard-skeleton bone for each standard bone; returns -1 in other cases.
73 * This is necessary when deciding which nonstandard-skeleton-bone's animation
74 * should be saved. (TODO: think of a better name.)
75 */
76 int GetRealBoneID(const std::string& name) const;
77
78 /**
79 * Tries to find a skeleton that matches the given root bone name.
80 * Returns NULL if there is no match.
81 */
82 static const Skeleton* FindSkeleton(const std::string& rootBoneName);
83
84 /**
85 * Initialises the global state with skeleton data loaded from the
86 * given XML data.
87 * @todo Stop using global state.
88 * @param xmlData
89 * @param xmlLength
90 * @param xmlErrors output - XML parser error messages; will be non-empty
91 * on failure (and failure will always throw)
92 * @throws ColladaException on failure
93 */
94 static void LoadSkeletonDataFromXml(const char* xmlData, size_t xmlLength, std::string& xmlErrors);
95
96 std::unique_ptr<Skeleton_impl> m;
97private:
99};
100
101#endif // INCLUDED_STDSKELETONS
Definition: StdSkeletons.h:51
int GetBoneCount() const
Returns the number of bones in the standard-skeleton which this current skeleton is mapped onto.
Definition: StdSkeletons.cpp:85
int GetBoneID(const std::string &name) const
Returns the ID number of the standard-skeleton bone, which corresponds to the named nonstandard-skele...
Definition: StdSkeletons.cpp:69
static const Skeleton * FindSkeleton(const std::string &rootBoneName)
Tries to find a skeleton that matches the given root bone name.
Definition: StdSkeletons.cpp:64
Skeleton(Skeleton &)
int GetRealBoneID(const std::string &name) const
Similar to GetBoneID, but only returns a value for the most important (first) nonstandard-skeleton bo...
Definition: StdSkeletons.cpp:77
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.
Definition: StdSkeletons.cpp:197
std::unique_ptr< Skeleton_impl > m
Definition: StdSkeletons.h:96
~Skeleton()
Definition: StdSkeletons.cpp:62
Skeleton()
Default constructor - don't use; use FindSkeleton instead.
Definition: StdSkeletons.cpp:61
Definition: StdSkeletons.cpp:55