Plasma Engine  2.0
Loading...
Searching...
No Matches
EditableSkeleton.h
1#pragma once
2
3#include <RendererCore/RendererCoreDLL.h>
4
5#include <Foundation/Reflection/Reflection.h>
6#include <Foundation/Strings/HashedString.h>
7#include <Foundation/Types/VariantTypeRegistry.h>
8#include <RendererCore/AnimationSystem/Declarations.h>
9
11class plSkeleton;
12
13namespace ozz::animation
14{
15 class Skeleton;
16
17 namespace offline
18 {
19 struct RawSkeleton;
20 }
21} // namespace ozz::animation
22
23PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plSkeletonJointGeometryType);
24
25struct PL_RENDERERCORE_DLL plEditableSkeletonBoneShape : public plReflectedClass
26{
27 PL_ADD_DYNAMIC_REFLECTION(plEditableSkeletonBoneShape, plReflectedClass);
28
30
31 plVec3 m_vOffset = plVec3::MakeZero();
32 plQuat m_qRotation = plQuat::MakeIdentity();
33
34 float m_fLength = 0; // Box, Capsule; 0 means parent joint to this joint (auto mode)
35 float m_fWidth = 0; // Box
36 float m_fThickness = 0; // Sphere radius, Capsule radius
37};
38
39struct PL_RENDERERCORE_DLL plEditableSkeletonBoneCollider : public plReflectedClass
40{
41 PL_ADD_DYNAMIC_REFLECTION(plEditableSkeletonBoneCollider, plReflectedClass);
42
43 plString m_sIdentifier;
44 plDynamicArray<plVec3> m_VertexPositions;
45 plDynamicArray<plUInt8> m_TriangleIndices;
46};
47
48class PL_RENDERERCORE_DLL plEditableSkeletonJoint : public plReflectedClass
49{
50 PL_ADD_DYNAMIC_REFLECTION(plEditableSkeletonJoint, plReflectedClass);
51
52public:
55
56 const char* GetName() const;
57 void SetName(const char* szSz);
58
59 void ClearJoints();
60
61 // copies the properties for geometry etc. from another joint
62 // does NOT copy the name, the transform or the children
63 void CopyPropertiesFrom(const plEditableSkeletonJoint* pJoint);
64
65 plHashedString m_sName;
66 plTransform m_LocalTransform = plTransform::MakeIdentity();
67
69
70 float m_fStiffness = 0.0f;
71
72 plAngle m_TwistLimitHalfAngle;
73 plAngle m_TwistLimitCenterAngle;
74 plAngle m_SwingLimitY;
75 plAngle m_SwingLimitZ;
76
77 plVec3 m_vGizmoOffsetPositionRO = plVec3::MakeZero();
78 plQuat m_qGizmoOffsetRotationRO = plQuat::MakeIdentity();
79
80 plQuat m_qLocalJointRotation = plQuat::MakeIdentity();
81
85
86 bool m_bOverrideSurface = false;
87 bool m_bOverrideCollisionLayer = false;
88 plString m_sSurfaceOverride;
89 plUInt8 m_uiCollisionLayerOverride;
90};
91
92class PL_RENDERERCORE_DLL plEditableSkeleton : public plReflectedClass
93{
94 PL_ADD_DYNAMIC_REFLECTION(plEditableSkeleton, plReflectedClass);
95
96public:
99
100 void ClearJoints();
101 void FillResourceDescriptor(plSkeletonResourceDescriptor& ref_desc) const;
102 void GenerateRawOzzSkeleton(ozz::animation::offline::RawSkeleton& out_skeleton) const;
103 void GenerateOzzSkeleton(ozz::animation::Skeleton& out_skeleton) const;
104 void CreateJointsRecursive(plSkeletonBuilder& ref_sb, plSkeletonResourceDescriptor& ref_desc, const plEditableSkeletonJoint* pParentJoint, const plEditableSkeletonJoint* pThisJoint, plUInt16 uiThisJointIdx, const plQuat& qParentAccuRot, const plMat4& mRootTransform) const;
105
106 plString m_sSourceFile;
107 plString m_sPreviewMesh;
108
109 plString m_sSurfaceFile;
110 plUInt8 m_uiCollisionLayer = 0;
111
112 float m_fUniformScaling = 1.0f;
113 float m_fMaxImpulse = 100.0f;
114
115 plEnum<plBasisAxis> m_RightDir;
116 plEnum<plBasisAxis> m_UpDir;
117 bool m_bFlipForwardDir = false;
118 plEnum<plBasisAxis> m_BoneDirection;
119
121};
122
123struct PL_RENDERERCORE_DLL plExposedBone
124{
125 plString m_sName;
126 plString m_sParent;
127 plTransform m_Transform;
128 // when adding new values, the hash function below has to be adjusted
129};
130
131PL_DECLARE_CUSTOM_VARIANT_TYPE(plExposedBone);
132
133PL_RENDERERCORE_DLL void operator<<(plStreamWriter& inout_stream, const plExposedBone& bone);
134PL_RENDERERCORE_DLL void operator>>(plStreamReader& inout_stream, plExposedBone& ref_bone);
135PL_RENDERERCORE_DLL bool operator==(const plExposedBone& lhs, const plExposedBone& rhs);
136
137template <>
139{
140 PL_ALWAYS_INLINE static plUInt32 Hash(const plExposedBone& value)
141 {
142 return plHashingUtils::xxHash32String(value.m_sName) + plHashingUtils::xxHash32String(value.m_sParent) + plHashingUtils::xxHash32(&value, sizeof(plTransform));
143 }
144
145 PL_ALWAYS_INLINE static bool Equal(const plExposedBone& a, const plExposedBone& b) { return a == b; }
146};
147
148PL_DECLARE_REFLECTABLE_TYPE(PL_RENDERERCORE_DLL, plExposedBone);
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
Definition DynamicArray.h:81
Definition EditableSkeleton.h:93
Definition EditableSkeleton.h:49
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
static plUInt32 xxHash32(const void *pKey, size_t uiSizeInByte, plUInt32 uiSeed=0)
Calculates the 32bit xxHash of the given key.
Definition HashingUtils.cpp:209
static constexpr plUInt32 xxHash32String(const char(&str)[N], plUInt32 uiSeed=0)
Calculates the 32bit xxHash of the given string literal at compile time.
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
static const plQuatTemplate< float > MakeIdentity()
Definition Quat_inl.h:29
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
The skeleton builder class provides the means to build skeleton instances from scratch....
Definition SkeletonBuilder.h:10
The skeleton class encapsulates the information about the joint structure for a model.
Definition Skeleton.h:75
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
static plTransformTemplate< float > MakeIdentity()
Definition Transform_inl.h:25
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
Definition EditableSkeleton.h:40
Definition EditableSkeleton.h:26
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition EditableSkeleton.h:124
Helper struct to calculate the Hash of different types.
Definition HashingUtils.h:75
What shape is used to approximate a bone's geometry.
Definition Declarations.h:26
Definition SkeletonResource.h:24