OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
 
StdMeshTransformation * Transformation
 
   } 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

Member Enumeration Documentation

Constructor & Destructor Documentation

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( )

Definition at line 785 of file StdMesh.cpp.

786 {
787  Leaf.Animation = nullptr;
788  Leaf.Position = nullptr;
789 }
StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshAnimation animation,
ValueProvider position 
)

Definition at line 791 of file StdMesh.cpp.

792 {
793  Leaf.Animation = animation;
794  Leaf.Position = position;
795 }
StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshBone bone,
const StdMeshTransformation &  trans 
)

Definition at line 797 of file StdMesh.cpp.

References StdMeshBone::Index.

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

Definition at line 804 of file StdMesh.cpp.

804  :
806 {
807  LinearInterpolation.ChildLeft = child_left;
808  LinearInterpolation.ChildRight = child_right;
809  LinearInterpolation.Weight = weight;
810 }
AnimationNode * Parent
Definition: StdMesh.h:367
StdMeshInstanceAnimationNode::~StdMeshInstanceAnimationNode ( )

Definition at line 812 of file StdMesh.cpp.

References CustomNode, LeafNode, LinearInterpolationNode, and Type.

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

Member Function Documentation

void StdMeshInstanceAnimationNode::ClearPointers ( class C4Object pObj)

Definition at line 951 of file StdMesh.cpp.

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

Referenced by StdMeshInstance::ClearPointers().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 862 of file StdMesh.cpp.

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().

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

Here is the call graph for this function:

void StdMeshInstanceAnimationNode::DenumeratePointers ( )

Definition at line 931 of file StdMesh.cpp.

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

Referenced by StdMeshInstance::DenumeratePointers().

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

Here is the call graph for this function:

Here is the caller graph for this function:

const StdMeshAnimation* StdMeshInstanceAnimationNode::GetAnimation ( ) const
inline

Definition at line 350 of file StdMesh.h.

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

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

Here is the caller graph for this function:

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

Definition at line 830 of file StdMesh.cpp.

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

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

Here is the call graph for this function:

AnimationNode* StdMeshInstanceAnimationNode::GetLeftChild ( )
inline

Definition at line 354 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

unsigned int StdMeshInstanceAnimationNode::GetNumber ( ) const
inline

Definition at line 346 of file StdMesh.h.

346 { return Number; }
AnimationNode* StdMeshInstanceAnimationNode::GetParent ( )
inline

Definition at line 348 of file StdMesh.h.

348 { return Parent; }
AnimationNode * Parent
Definition: StdMesh.h:367
C4Real StdMeshInstanceAnimationNode::GetPosition ( ) const
inline

Definition at line 352 of file StdMesh.h.

352 { assert(Type == LeafNode); return Leaf.Position->Value; }
ValueProvider* StdMeshInstanceAnimationNode::GetPositionProvider ( )
inline

Definition at line 351 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

AnimationNode* StdMeshInstanceAnimationNode::GetRightChild ( )
inline

Definition at line 355 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

int StdMeshInstanceAnimationNode::GetSlot ( ) const
inline

Definition at line 345 of file StdMesh.h.

345 { return Slot; }
NodeType StdMeshInstanceAnimationNode::GetType ( ) const
inline

Definition at line 347 of file StdMesh.h.

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

347 { return Type; }

Here is the caller graph for this function:

C4Real StdMeshInstanceAnimationNode::GetWeight ( ) const
inline

Definition at line 357 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

ValueProvider* StdMeshInstanceAnimationNode::GetWeightProvider ( )
inline

Definition at line 356 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class StdMeshAnimationUpdate
friend

Definition at line 331 of file StdMesh.h.

friend class StdMeshInstance
friend

Definition at line 329 of file StdMesh.h.

friend class StdMeshUpdate
friend

Definition at line 330 of file StdMesh.h.

Member Data Documentation

union { ... }
unsigned int StdMeshInstanceAnimationNode::Number
protected
AnimationNode* StdMeshInstanceAnimationNode::Parent {nullptr}
protected
int StdMeshInstanceAnimationNode::Slot
protected

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