Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
StdSkeletons.h
Go to the documentation of this file.
1/* Copyright (C) 2025 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 <cstddef>
22#include <string>
23#include <memory>
24
25/*
26
27Rough skeleton concept:
28
29Different modelling/animation programs use different skeleton structures for
30conceptually similar situations (e.g. humanoid bipeds). We'd like the game to
31handle combinations of models and animations from different programs, so the
32exported data must use a standard skeleton structure.
33
34Rather than requiring awkward reconfiguration of those programs, we use an
35XML file which defines a small set of standard skeletons (e.g. "biped") and
36also a number of modelling-program-specific skeleton structures (e.g. "3ds Max
37biped"). The non-standard ones define which bones we should expect to find,
38and what standard bone they should get mapped onto. Sometimes multiple bones
39will be mapped onto the same one (e.g. a series of fingers would all get mapped
40onto a single hand bone), so the conversion is slightly lossy.
41
42It is possible to have multiple independent standard skeletons - they just need
43to be identified by using different bone names in the modelling program. The
44game doesn't check that you're using models and animations with the same standard
45skeleton, so that's up to the artists to take care of.
46
47*/
48
49struct Skeleton_impl;
50
52{
53public:
54 /** Default constructor - don't use; use FindSkeleton instead. */
55 Skeleton();
56 ~Skeleton();
57
58 /**
59 * Returns the number of bones in the standard-skeleton which this current
60 * skeleton is mapped onto.
61 */
62 int GetBoneCount() const;
63
64 /**
65 * Returns the ID number of the standard-skeleton bone, which corresponds
66 * to the named nonstandard-skeleton bone. Returns -1 if none is found.
67 * Can return the same value for multiple bones.
68 */
69 int GetBoneID(const std::string& name) const;
70
71 /**
72 * Similar to GetBoneID, but only returns a value for the most important (first)
73 * nonstandard-skeleton bone for each standard bone; returns -1 in other cases.
74 * This is necessary when deciding which nonstandard-skeleton-bone's animation
75 * should be saved. (TODO: think of a better name.)
76 */
77 int GetRealBoneID(const std::string& name) const;
78
79 /**
80 * Tries to find a skeleton that matches the given root bone name.
81 * Returns NULL if there is no match.
82 */
83 static const Skeleton* FindSkeleton(const std::string& rootBoneName);
84
85 /**
86 * Initialises the global state with skeleton data loaded from the
87 * given XML data.
88 * @todo Stop using global state.
89 * @param xmlData
90 * @param xmlLength
91 * @param xmlErrors output - XML parser error messages; will be non-empty
92 * on failure (and failure will always throw)
93 * @throws ColladaException on failure
94 */
95 static void LoadSkeletonDataFromXml(const char* xmlData, size_t xmlLength, std::string& xmlErrors);
96
97 std::unique_ptr<Skeleton_impl> m;
98private:
100};
101
102#endif // INCLUDED_STDSKELETONS
Definition: StdSkeletons.h:52
int GetBoneCount() const
Returns the number of bones in the standard-skeleton which this current skeleton is mapped onto.
Definition: StdSkeletons.cpp:86
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:70
static const Skeleton * FindSkeleton(const std::string &rootBoneName)
Tries to find a skeleton that matches the given root bone name.
Definition: StdSkeletons.cpp:65
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:78
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:198
std::unique_ptr< Skeleton_impl > m
Definition: StdSkeletons.h:97
~Skeleton()
Definition: StdSkeletons.cpp:63
Skeleton()
Default constructor - don't use; use FindSkeleton instead.
Definition: StdSkeletons.cpp:62
Definition: StdSkeletons.cpp:56