OpenClonk
StdMeshInstanceAnimationNode Class Reference

#include <StdMesh.h>

Collaboration diagram for StdMeshInstanceAnimationNode:
[legend]

Public Types

enum  NodeType { LeafNode , CustomNode , LinearInterpolationNode }
 
typedef StdMeshInstanceAnimationNode AnimationNode
 
typedef StdMeshInstanceValueProvider ValueProvider
 

Public Member Functions

 StdMeshInstanceAnimationNode ()
 
 StdMeshInstanceAnimationNode (const StdMeshAnimation *animation, ValueProvider *position)
 
 StdMeshInstanceAnimationNode (const StdMeshBone *bone, const StdMeshTransformation &trans)
 
 StdMeshInstanceAnimationNode (AnimationNode *child_left, AnimationNode *child_right, ValueProvider *weight)
 
 ~StdMeshInstanceAnimationNode ()
 
bool GetBoneTransform (unsigned int bone, StdMeshTransformation &transformation)
 
int GetSlot () const
 
unsigned int GetNumber () const
 
NodeType GetType () const
 
AnimationNodeGetParent ()
 
const StdMeshAnimationGetAnimation () const
 
ValueProviderGetPositionProvider ()
 
C4Real GetPosition () const
 
AnimationNodeGetLeftChild ()
 
AnimationNodeGetRightChild ()
 
ValueProviderGetWeightProvider ()
 
C4Real GetWeight () const
 
void CompileFunc (StdCompiler *pComp, const StdMesh *Mesh)
 
void DenumeratePointers ()
 
void ClearPointers (class C4Object *pObj)
 

Protected Attributes

int Slot
 
unsigned int Number
 
NodeType Type {LeafNode}
 
AnimationNodeParent {nullptr}
 
union {
   struct {
const StdMeshAnimationAnimation
 
ValueProviderPosition
 
   } Leaf
 
   struct {
unsigned int BoneIndex
 
StdMeshTransformationTransformation
 
   } Custom
 
   struct {
AnimationNodeChildLeft
 
AnimationNodeChildRight
 
ValueProviderWeight
 
   } LinearInterpolation
 
}; 
 

Friends

class StdMeshInstance
 
class StdMeshUpdate
 
class StdMeshAnimationUpdate
 

Detailed Description

Definition at line 327 of file StdMesh.h.

Member Typedef Documentation

◆ AnimationNode

◆ ValueProvider

Member Enumeration Documentation

◆ NodeType

Enumerator
LeafNode 
CustomNode 
LinearInterpolationNode 

Definition at line 335 of file StdMesh.h.

Constructor & Destructor Documentation

◆ StdMeshInstanceAnimationNode() [1/4]

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( )

Definition at line 787 of file StdMesh.cpp.

788 {
789  Leaf.Animation = nullptr;
790  Leaf.Position = nullptr;
791 }

◆ StdMeshInstanceAnimationNode() [2/4]

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshAnimation animation,
ValueProvider position 
)

Definition at line 793 of file StdMesh.cpp.

794 {
795  Leaf.Animation = animation;
796  Leaf.Position = position;
797 }

◆ StdMeshInstanceAnimationNode() [3/4]

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshBone bone,
const StdMeshTransformation trans 
)

Definition at line 799 of file StdMesh.cpp.

799  :
800  Type(CustomNode), Parent(nullptr)
801 {
802  Custom.BoneIndex = bone->Index;
803  Custom.Transformation = new StdMeshTransformation(trans);
804 }
unsigned int Index
Definition: StdMesh.h:32
AnimationNode * Parent
Definition: StdMesh.h:367

References StdMeshBone::Index.

◆ StdMeshInstanceAnimationNode() [4/4]

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( AnimationNode child_left,
AnimationNode child_right,
ValueProvider weight 
)

Definition at line 806 of file StdMesh.cpp.

806  :
808 {
809  LinearInterpolation.ChildLeft = child_left;
810  LinearInterpolation.ChildRight = child_right;
811  LinearInterpolation.Weight = weight;
812 }

◆ ~StdMeshInstanceAnimationNode()

StdMeshInstanceAnimationNode::~StdMeshInstanceAnimationNode ( )

Definition at line 814 of file StdMesh.cpp.

815 {
816  switch (Type)
817  {
818  case LeafNode:
819  delete Leaf.Position;
820  break;
821  case CustomNode:
822  delete Custom.Transformation;
823  break;
825  delete LinearInterpolation.ChildLeft;
826  delete LinearInterpolation.ChildRight;
827  delete LinearInterpolation.Weight;
828  break;
829  }
830 }

References CustomNode, LeafNode, LinearInterpolationNode, and Type.

Member Function Documentation

◆ ClearPointers()

void StdMeshInstanceAnimationNode::ClearPointers ( class C4Object pObj)

Definition at line 953 of file StdMesh.cpp.

954 {
955  StdMeshInstance::SerializableValueProvider* value_provider = nullptr;
956  switch(Type)
957  {
958  case LeafNode:
959  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(Leaf.Position);
960  break;
961  case CustomNode:
962  value_provider = nullptr;
963  break;
965  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(LinearInterpolation.Weight);
966  // non-recursive, StdMeshInstance::ClearPointers walks over all nodes
967  break;
968  }
969 
970  if(value_provider) value_provider->ClearPointers(pObj);
971 }
virtual void ClearPointers(class C4Object *pObj)
Definition: StdMesh.h:480

References StdMeshInstance::SerializableValueProvider::ClearPointers(), CustomNode, LeafNode, LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::ClearPointers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void StdMeshInstanceAnimationNode::CompileFunc ( StdCompiler pComp,
const StdMesh Mesh 
)

Definition at line 864 of file StdMesh.cpp.

865 {
866  static const StdEnumEntry<NodeType> NodeTypes[] =
867  {
868  { "Leaf", LeafNode },
869  { "Custom", CustomNode },
870  { "LinearInterpolation", LinearInterpolationNode },
871 
872  { nullptr, static_cast<NodeType>(0) }
873  };
874 
875  pComp->Value(mkNamingAdapt(Slot, "Slot"));
876  pComp->Value(mkNamingAdapt(Number, "Number"));
877  pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(Type, NodeTypes), "Type"));
878 
879  switch(Type)
880  {
881  case LeafNode:
882  if(pComp->isDeserializer())
883  {
884  StdCopyStrBuf anim_name;
885  pComp->Value(mkNamingAdapt(toC4CStrBuf(anim_name), "Animation"));
886  Leaf.Animation = Mesh->GetSkeleton().GetAnimationByName(anim_name);
887  if(!Leaf.Animation) pComp->excCorrupt(R"(No such animation: "%s")", anim_name.getData());
888  }
889  else
890  {
891  pComp->Value(mkNamingAdapt(mkParAdapt(mkDecompileAdapt(Leaf.Animation->Name), StdCompiler::RCT_All), "Animation"));
892  }
893 
894  pComp->Value(mkNamingAdapt(mkValueProviderAdapt(&Leaf.Position), "Position"));
895  break;
896  case CustomNode:
897  if(pComp->isDeserializer())
898  {
899  StdCopyStrBuf bone_name;
900  pComp->Value(mkNamingAdapt(toC4CStrBuf(bone_name), "Bone"));
901  const StdMeshBone* bone = Mesh->GetSkeleton().GetBoneByName(bone_name);
902  if(!bone) pComp->excCorrupt(R"(No such bone: "%s")", bone_name.getData());
903  Custom.BoneIndex = bone->Index;
904  Custom.Transformation = new StdMeshTransformation;
905  }
906  else
907  {
908  pComp->Value(mkNamingAdapt(mkParAdapt(mkDecompileAdapt(Mesh->GetSkeleton().GetBone(Custom.BoneIndex).Name), StdCompiler::RCT_All), "Bone"));
909  }
910 
911  pComp->Value(mkNamingAdapt(mkTransformAdapt(*Custom.Transformation), "Transformation"));
912  break;
914  pComp->Value(mkParAdapt(mkNamingPtrAdapt(LinearInterpolation.ChildLeft, "ChildLeft"), Mesh));
915  pComp->Value(mkParAdapt(mkNamingPtrAdapt(LinearInterpolation.ChildRight, "ChildRight"), Mesh));
916  pComp->Value(mkNamingAdapt(mkValueProviderAdapt(&LinearInterpolation.Weight), "Weight"));
917  if(pComp->isDeserializer())
918  {
919  if(LinearInterpolation.ChildLeft->Slot != Slot)
920  pComp->excCorrupt("Slot of left child does not match parent slot");
921  if(LinearInterpolation.ChildRight->Slot != Slot)
922  pComp->excCorrupt("Slof of right child does not match parent slot");
923  LinearInterpolation.ChildLeft->Parent = this;
924  LinearInterpolation.ChildRight->Parent = this;
925  }
926  break;
927  default:
928  pComp->excCorrupt("Invalid animation node type");
929  break;
930  }
931 }
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153
StdPtrAdapt< T > mkNamingPtrAdapt(T *&rpObj, const char *szNaming)
Definition: StdAdaptors.h:636
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
#define toC4CStrBuf(rBuf)
Definition: StdAdaptors.h:25
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
Definition: StdAdaptors.h:795
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdCopyStrBuf Name
Definition: StdMesh.h:34
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:203
const StdMeshBone * GetBoneByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:388
const StdMeshBone & GetBone(size_t i) const
Definition: StdMesh.h:116
const StdMeshAnimation * GetAnimationByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:398
const char * getData() const
Definition: StdBuf.h:442

References CustomNode, StdCompiler::excCorrupt(), StdMeshSkeleton::GetAnimationByName(), StdMeshSkeleton::GetBone(), StdMeshSkeleton::GetBoneByName(), StdStrBuf::getData(), StdMesh::GetSkeleton(), StdMeshBone::Index, StdCompiler::isDeserializer(), LeafNode, LinearInterpolationNode, mkDecompileAdapt(), mkNamingAdapt(), mkNamingPtrAdapt(), mkParAdapt(), StdMeshBone::Name, Number, StdCompiler::RCT_All, Slot, toC4CStrBuf, Type, and StdCompiler::Value().

Here is the call graph for this function:

◆ DenumeratePointers()

void StdMeshInstanceAnimationNode::DenumeratePointers ( )

Definition at line 933 of file StdMesh.cpp.

934 {
935  StdMeshInstance::SerializableValueProvider* value_provider = nullptr;
936  switch(Type)
937  {
938  case LeafNode:
939  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(Leaf.Position);
940  break;
941  case CustomNode:
942  value_provider = nullptr;
943  break;
945  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(LinearInterpolation.Weight);
946  // non-recursive, StdMeshInstance::DenumeratePointers walks over all nodes
947  break;
948  }
949 
950  if(value_provider) value_provider->DenumeratePointers();
951 }

References CustomNode, StdMeshInstance::SerializableValueProvider::DenumeratePointers(), LeafNode, LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::DenumeratePointers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAnimation()

const StdMeshAnimation* StdMeshInstanceAnimationNode::GetAnimation ( ) const
inline

Definition at line 350 of file StdMesh.h.

350 { assert(Type == LeafNode); return Leaf.Animation; }

References LeafNode, and Type.

Referenced by C4ValueProviderAction::Execute(), and StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

◆ GetBoneTransform()

bool StdMeshInstanceAnimationNode::GetBoneTransform ( unsigned int  bone,
StdMeshTransformation transformation 
)

Definition at line 832 of file StdMesh.cpp.

833 {
834  StdMeshTransformation combine_with;
835  StdMeshTrack* track;
836 
837  switch (Type)
838  {
839  case LeafNode:
840  track = Leaf.Animation->Tracks[bone];
841  if (!track) return false;
842  transformation = track->GetTransformAt(fixtof(Leaf.Position->Value), Leaf.Animation->Length);
843  return true;
844  case CustomNode:
845  if(bone == Custom.BoneIndex)
846  transformation = *Custom.Transformation;
847  else
848  return false;
849  return true;
851  if (!LinearInterpolation.ChildLeft->GetBoneTransform(bone, transformation))
852  return LinearInterpolation.ChildRight->GetBoneTransform(bone, transformation);
853  if (!LinearInterpolation.ChildRight->GetBoneTransform(bone, combine_with))
854  return true; // First Child affects bone
855 
856  transformation = StdMeshTransformation::Nlerp(transformation, combine_with, fixtof(LinearInterpolation.Weight->Value));
857  return true;
858  default:
859  assert(false);
860  return false;
861  }
862 }
float fixtof(const C4Fixed &x)
Definition: C4Real.h:257
StdMeshTransformation GetTransformAt(float time, float length) const
Definition: StdMesh.cpp:291
static StdMeshTransformation Nlerp(const StdMeshTransformation &lhs, const StdMeshTransformation &rhs, float w)

References CustomNode, fixtof(), StdMeshTrack::GetTransformAt(), LeafNode, LinearInterpolationNode, StdMeshTransformation::Nlerp(), and Type.

Here is the call graph for this function:

◆ GetLeftChild()

AnimationNode* StdMeshInstanceAnimationNode::GetLeftChild ( )
inline

Definition at line 354 of file StdMesh.h.

354 { assert(Type == LinearInterpolationNode); return LinearInterpolation.ChildLeft; }

References LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

◆ GetNumber()

unsigned int StdMeshInstanceAnimationNode::GetNumber ( ) const
inline

Definition at line 346 of file StdMesh.h.

346 { return Number; }

References Number.

◆ GetParent()

AnimationNode* StdMeshInstanceAnimationNode::GetParent ( )
inline

Definition at line 348 of file StdMesh.h.

348 { return Parent; }

References Parent.

◆ GetPosition()

C4Real StdMeshInstanceAnimationNode::GetPosition ( ) const
inline

Definition at line 352 of file StdMesh.h.

352 { assert(Type == LeafNode); return Leaf.Position->Value; }

References LeafNode, and Type.

◆ GetPositionProvider()

ValueProvider* StdMeshInstanceAnimationNode::GetPositionProvider ( )
inline

Definition at line 351 of file StdMesh.h.

351 { assert(Type == LeafNode); return Leaf.Position; }

References LeafNode, and Type.

Referenced by StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

◆ GetRightChild()

AnimationNode* StdMeshInstanceAnimationNode::GetRightChild ( )
inline

Definition at line 355 of file StdMesh.h.

355 { assert(Type == LinearInterpolationNode); return LinearInterpolation.ChildRight; }

References LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

◆ GetSlot()

int StdMeshInstanceAnimationNode::GetSlot ( ) const
inline

Definition at line 345 of file StdMesh.h.

345 { return Slot; }

References Slot.

◆ GetType()

NodeType StdMeshInstanceAnimationNode::GetType ( ) const
inline

Definition at line 347 of file StdMesh.h.

347 { return Type; }

References Type.

Referenced by StdMeshInstance::ExecuteAnimationNode(), StdMeshInstance::SetAnimationBoneTransform(), StdMeshInstance::SetAnimationPosition(), and StdMeshInstance::SetAnimationWeight().

Here is the caller graph for this function:

◆ GetWeight()

C4Real StdMeshInstanceAnimationNode::GetWeight ( ) const
inline

Definition at line 357 of file StdMesh.h.

357 { assert(Type == LinearInterpolationNode); return LinearInterpolation.Weight->Value; }

References LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

◆ GetWeightProvider()

ValueProvider* StdMeshInstanceAnimationNode::GetWeightProvider ( )
inline

Definition at line 356 of file StdMesh.h.

356 { assert(Type == LinearInterpolationNode); return LinearInterpolation.Weight; }

References LinearInterpolationNode, and Type.

Referenced by StdMeshInstance::ExecuteAnimationNode().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ StdMeshAnimationUpdate

friend class StdMeshAnimationUpdate
friend

Definition at line 331 of file StdMesh.h.

◆ StdMeshInstance

friend class StdMeshInstance
friend

Definition at line 329 of file StdMesh.h.

◆ StdMeshUpdate

friend class StdMeshUpdate
friend

Definition at line 330 of file StdMesh.h.

Member Data Documentation

◆ 

union { ... }

◆ Number

unsigned int StdMeshInstanceAnimationNode::Number
protected

◆ Parent

AnimationNode* StdMeshInstanceAnimationNode::Parent {nullptr}
protected

◆ Slot

int StdMeshInstanceAnimationNode::Slot
protected

◆ Type


The documentation for this class was generated from the following files: