Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Bone.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32/*Code references:
33 http://nolimitsdesigns.com/game-design/open-asset-import-library-animation-loader/
34*/
35
36#pragma once
37#ifndef DVD_BONE_H_
38#define DVD_BONE_H_
39
40namespace Divide {
41
42class Bone : public eastl::enable_shared_from_this<Bone> {
43 PROPERTY_RW(string, name);
44 PROPERTY_RW(I32, boneID, -1);
45 PROPERTY_RW(mat4<F32>, offsetMatrix);
46 PROPERTY_RW(mat4<F32>, localTransform);
47 PROPERTY_RW(mat4<F32>, globalTransform);
48 PROPERTY_RW(mat4<F32>, originalLocalTransform);
49
50public:
51 Bone* _parent = nullptr;
53
54 // index in the current animation's channel array.
55 explicit Bone(const string& name)
56 : _name(name)
57 {
58 }
59
61 {
62 for (Bone* child : _children)
63 {
64 delete child;
65 }
66 }
67
68 [[nodiscard]] size_t hierarchyDepth() const {
69 size_t size = _children.size();
70 for (const auto& child : _children) {
71 size += child->hierarchyDepth();
72 }
73
74 return size;
75 }
76
77 [[nodiscard]] Bone* find(const string& name) {
78 return find(_ID(name.c_str()));
79 }
80
81 [[nodiscard]] Bone* find(const U64 nameKey) {
82 if (_ID(_name.c_str()) == nameKey) {
83 return this;
84 }
85
86 for (const auto& child : _children) {
87 Bone* childNode = child->find(nameKey);
88 if (childNode != nullptr) {
89 return childNode;
90 }
91 }
92
93 return nullptr;
94 }
95
96 void createBoneList(vector<Bone*>& boneList) {
97 boneList.push_back(this);
98 for (Bone* child : _children) {
99 child->createBoneList(boneList);
100 }
101 }
102};
103
104}; // namespace Divide
105
106#endif //DVD_BONE_H_
Bone * _parent
Definition: Bone.h:51
size_t hierarchyDepth() const
Definition: Bone.h:68
Bone * find(const string &name)
Definition: Bone.h:77
PROPERTY_RW(string, name)
PROPERTY_RW(mat4< F32 >, originalLocalTransform)
PROPERTY_RW(I32, boneID, -1)
PROPERTY_RW(mat4< F32 >, localTransform)
Bone * find(const U64 nameKey)
Definition: Bone.h:81
Bone(const string &name)
Definition: Bone.h:55
PROPERTY_RW(mat4< F32 >, offsetMatrix)
PROPERTY_RW(mat4< F32 >, globalTransform)
void createBoneList(vector< Bone * > &boneList)
Definition: Bone.h:96
~Bone()
Definition: Bone.h:60
vector< Bone * > _children
Definition: Bone.h:52
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
eastl::vector< Type > vector
Definition: Vector.h:42
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
uint64_t U64