Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Skeleton.cpp
1/*
2Copyright (C) 2017-2019,2021,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#include <vector>
18#include <cstring>
20#include "aeongames/ProtoBufHelpers.hpp"
21#ifdef _MSC_VER
22#pragma warning( push )
23#pragma warning( disable : PROTOBUF_WARNINGS )
24#endif
25#include "skeleton.pb.h"
26#ifdef _MSC_VER
27#pragma warning( pop )
28#endif
29#include "aeongames/Skeleton.hpp"
30#include "aeongames/Animation.hpp"
32
33namespace AeonGames
34{
35 Skeleton::Joint::Joint ( Joint * aParent, const Transform & aTransform, const Transform & aInvertedTransform, const std::string & aName ) :
36 mParent ( aParent ), mTransform ( aTransform ), mInvertedTransform ( aInvertedTransform ), mName ( aName )
37 {
38 }
39
41 {
42 return mTransform;
43 }
44
46 {
47 return mInvertedTransform;
48 }
49
51 {
52 return mParent;
53 }
54
56 = default;
57 Skeleton::~Skeleton() = default;
58
59 void Skeleton::LoadFromMemory ( const void* aBuffer, size_t aBufferSize )
60 {
61 LoadFromProtoBufObject<Skeleton, SkeletonMsg, "AEONSKL"_mgk> ( *this, aBuffer, aBufferSize );
62 }
63
64 void Skeleton::LoadFromPBMsg ( const SkeletonMsg& aSkeletonMsg )
65 {
66 mJoints.reserve ( aSkeletonMsg.joint_size() );
67 for ( auto& joint : aSkeletonMsg.joint() )
68 {
69 mJoints.emplace_back (
70 ( joint.parentindex() < 0 ) ? nullptr : &mJoints[joint.parentindex()],
72 {
73 Vector3
74 {
75 joint.scale().x(),
76 joint.scale().y(),
77 joint.scale().z()
78 },
80 {
81 joint.rotation().w(),
82 joint.rotation().x(),
83 joint.rotation().y(),
84 joint.rotation().z()
85 },
87 {
88 joint.translation().x(),
89 joint.translation().y(),
90 joint.translation().z()
91 }
92 },
94 {
96 {
97 joint.invertedscale().x(),
98 joint.invertedscale().y(),
99 joint.invertedscale().z()
100 },
102 {
103 joint.invertedrotation().w(),
104 joint.invertedrotation().x(),
105 joint.invertedrotation().y(),
106 joint.invertedrotation().z()
107 },
108 Vector3
109 {
110 joint.invertedtranslation().x(),
111 joint.invertedtranslation().y(),
112 joint.invertedtranslation().z()
113 }
114 },
115 joint.name() );
116 }
117 }
118
120 {
121 mJoints.clear();
122 }
123
124 const std::vector<Skeleton::Joint>& Skeleton::GetJoints() const
125 {
126 return mJoints;
127 }
128}
Header for 4x4 matrix class.
Provides the DLL_PROTOBUF export/import macro for protobuf wrapper classes.
Quaternion class.
A single joint within a skeleton hierarchy.
Definition Skeleton.hpp:34
Joint(Joint *aParent, const Transform &aTransform, const Transform &aInvertedTransform, const std::string &aName)
Construct a joint.
Definition Skeleton.cpp:35
DLL const Transform & GetInvertedTransform() const
Get the inverse bind-pose transform.
Definition Skeleton.cpp:45
DLL const Joint * GetParent() const
Get the parent joint.
Definition Skeleton.cpp:50
DLL const Transform & GetTransform() const
Get the local bind-pose transform.
Definition Skeleton.cpp:40
DLL void LoadFromMemory(const void *aBuffer, size_t aBufferSize) final
Load the skeleton from a memory buffer.
Definition Skeleton.cpp:59
DLL ~Skeleton()
Destructor.
DLL Skeleton()
Construct an empty skeleton.
DLL const std::vector< Joint > & GetJoints() const
Get the joint list.
Definition Skeleton.cpp:124
DLL void LoadFromPBMsg(const SkeletonMsg &aSkeletonMsg)
Load the skeleton from a protobuf message.
Definition Skeleton.cpp:64
DLL void Unload() final
Unload and release skeleton data.
Definition Skeleton.cpp:119
Component class for any object that requires space transformations.
Definition Transform.hpp:34
3D vector class.
Definition Vector3.hpp:32
<- This is here just for the literals
Definition AABB.hpp:31
void LoadFromProtoBufObject(T &aTarget, const void *aBuffer, size_t aBufferSize)
Loads a Protocol Buffer message from a buffer and populates a target object.