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
 
AnimationNodeParent
 
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 329 of file StdMesh.h.

Member Typedef Documentation

Member Enumeration Documentation

Constructor & Destructor Documentation

StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( )

Definition at line 795 of file StdMesh.cpp.

795  :
796  Type(LeafNode), Parent(nullptr)
797 {
798  Leaf.Animation = nullptr;
799  Leaf.Position = nullptr;
800 }
AnimationNode * Parent
Definition: StdMesh.h:369
StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshAnimation animation,
ValueProvider position 
)

Definition at line 802 of file StdMesh.cpp.

802  :
803  Type(LeafNode), Parent(nullptr)
804 {
805  Leaf.Animation = animation;
806  Leaf.Position = position;
807 }
AnimationNode * Parent
Definition: StdMesh.h:369
StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( const StdMeshBone bone,
const StdMeshTransformation &  trans 
)

Definition at line 809 of file StdMesh.cpp.

References StdMeshBone::Index.

809  :
810  Type(CustomNode), Parent(nullptr)
811 {
812  Custom.BoneIndex = bone->Index;
813  Custom.Transformation = new StdMeshTransformation(trans);
814 }
AnimationNode * Parent
Definition: StdMesh.h:369
unsigned int Index
Definition: StdMesh.h:34
StdMeshInstanceAnimationNode::StdMeshInstanceAnimationNode ( AnimationNode child_left,
AnimationNode child_right,
ValueProvider weight 
)

Definition at line 816 of file StdMesh.cpp.

816  :
818 {
819  LinearInterpolation.ChildLeft = child_left;
820  LinearInterpolation.ChildRight = child_right;
821  LinearInterpolation.Weight = weight;
822 }
AnimationNode * Parent
Definition: StdMesh.h:369
StdMeshInstanceAnimationNode::~StdMeshInstanceAnimationNode ( )

Definition at line 824 of file StdMesh.cpp.

References CustomNode, LeafNode, LinearInterpolationNode, and Type.

825 {
826  switch (Type)
827  {
828  case LeafNode:
829  delete Leaf.Position;
830  break;
831  case CustomNode:
832  delete Custom.Transformation;
833  break;
835  delete LinearInterpolation.ChildLeft;
836  delete LinearInterpolation.ChildRight;
837  delete LinearInterpolation.Weight;
838  break;
839  }
840 }

Member Function Documentation

void StdMeshInstanceAnimationNode::ClearPointers ( class C4Object pObj)

Definition at line 963 of file StdMesh.cpp.

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

964 {
965  StdMeshInstance::SerializableValueProvider* value_provider = nullptr;
966  switch(Type)
967  {
968  case LeafNode:
969  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(Leaf.Position);
970  break;
971  case CustomNode:
972  value_provider = nullptr;
973  break;
975  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(LinearInterpolation.Weight);
976  // non-recursive, StdMeshInstance::ClearPointers walks over all nodes
977  break;
978  }
979 
980  if(value_provider) value_provider->ClearPointers(pObj);
981 }
virtual void ClearPointers(class C4Object *pObj)
Definition: StdMesh.h:482

Here is the call graph for this function:

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

Definition at line 874 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().

875 {
876  static const StdEnumEntry<NodeType> NodeTypes[] =
877  {
878  { "Leaf", LeafNode },
879  { "Custom", CustomNode },
880  { "LinearInterpolation", LinearInterpolationNode },
881 
882  { nullptr, static_cast<NodeType>(0) }
883  };
884 
885  pComp->Value(mkNamingAdapt(Slot, "Slot"));
886  pComp->Value(mkNamingAdapt(Number, "Number"));
887  pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(Type, NodeTypes), "Type"));
888 
889  switch(Type)
890  {
891  case LeafNode:
892  if(pComp->isDeserializer())
893  {
894  StdCopyStrBuf anim_name;
895  pComp->Value(mkNamingAdapt(toC4CStrBuf(anim_name), "Animation"));
896  Leaf.Animation = Mesh->GetSkeleton().GetAnimationByName(anim_name);
897  if(!Leaf.Animation) pComp->excCorrupt("No such animation: \"%s\"", anim_name.getData());
898  }
899  else
900  {
901  pComp->Value(mkNamingAdapt(mkParAdapt(mkDecompileAdapt(Leaf.Animation->Name), StdCompiler::RCT_All), "Animation"));
902  }
903 
904  pComp->Value(mkNamingAdapt(mkValueProviderAdapt(&Leaf.Position), "Position"));
905  break;
906  case CustomNode:
907  if(pComp->isDeserializer())
908  {
909  StdCopyStrBuf bone_name;
910  pComp->Value(mkNamingAdapt(toC4CStrBuf(bone_name), "Bone"));
911  const StdMeshBone* bone = Mesh->GetSkeleton().GetBoneByName(bone_name);
912  if(!bone) pComp->excCorrupt("No such bone: \"%s\"", bone_name.getData());
913  Custom.BoneIndex = bone->Index;
914  Custom.Transformation = new StdMeshTransformation;
915  }
916  else
917  {
918  pComp->Value(mkNamingAdapt(mkParAdapt(mkDecompileAdapt(Mesh->GetSkeleton().GetBone(Custom.BoneIndex).Name), StdCompiler::RCT_All), "Bone"));
919  }
920 
921  pComp->Value(mkNamingAdapt(mkTransformAdapt(*Custom.Transformation), "Transformation"));
922  break;
924  pComp->Value(mkParAdapt(mkNamingPtrAdapt(LinearInterpolation.ChildLeft, "ChildLeft"), Mesh));
925  pComp->Value(mkParAdapt(mkNamingPtrAdapt(LinearInterpolation.ChildRight, "ChildRight"), Mesh));
926  pComp->Value(mkNamingAdapt(mkValueProviderAdapt(&LinearInterpolation.Weight), "Weight"));
927  if(pComp->isDeserializer())
928  {
929  if(LinearInterpolation.ChildLeft->Slot != Slot)
930  pComp->excCorrupt("Slot of left child does not match parent slot");
931  if(LinearInterpolation.ChildRight->Slot != Slot)
932  pComp->excCorrupt("Slof of right child does not match parent slot");
933  LinearInterpolation.ChildLeft->Parent = this;
934  LinearInterpolation.ChildRight->Parent = this;
935  }
936  break;
937  default:
938  pComp->excCorrupt("Invalid animation node type");
939  break;
940  }
941 }
const char * getData() const
Definition: StdBuf.h:450
Definition: StdAdaptors.h:763
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
const StdMeshBone & GetBone(size_t i) const
Definition: StdMesh.h:118
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
const StdMeshAnimation * GetAnimationByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:398
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
const StdMeshBone * GetBoneByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:388
StdCopyStrBuf Name
Definition: StdMesh.h:36
unsigned int Index
Definition: StdMesh.h:34
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:459
StdPtrAdapt< T > mkNamingPtrAdapt(T *&rpObj, const char *szNaming)
Definition: StdAdaptors.h:605
#define toC4CStrBuf(rBuf)
Definition: StdAdaptors.h:26

Here is the call graph for this function:

void StdMeshInstanceAnimationNode::DenumeratePointers ( )

Definition at line 943 of file StdMesh.cpp.

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

944 {
945  StdMeshInstance::SerializableValueProvider* value_provider = nullptr;
946  switch(Type)
947  {
948  case LeafNode:
949  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(Leaf.Position);
950  break;
951  case CustomNode:
952  value_provider = nullptr;
953  break;
955  value_provider = dynamic_cast<StdMeshInstance::SerializableValueProvider*>(LinearInterpolation.Weight);
956  // non-recursive, StdMeshInstance::DenumeratePointers walks over all nodes
957  break;
958  }
959 
960  if(value_provider) value_provider->DenumeratePointers();
961 }

Here is the call graph for this function:

const StdMeshAnimation* StdMeshInstanceAnimationNode::GetAnimation ( ) const
inline

Definition at line 352 of file StdMesh.h.

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

352 { 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 842 of file StdMesh.cpp.

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

843 {
844  StdMeshTransformation combine_with;
845  StdMeshTrack* track;
846 
847  switch (Type)
848  {
849  case LeafNode:
850  track = Leaf.Animation->Tracks[bone];
851  if (!track) return false;
852  transformation = track->GetTransformAt(fixtof(Leaf.Position->Value), Leaf.Animation->Length);
853  return true;
854  case CustomNode:
855  if(bone == Custom.BoneIndex)
856  transformation = *Custom.Transformation;
857  else
858  return false;
859  return true;
861  if (!LinearInterpolation.ChildLeft->GetBoneTransform(bone, transformation))
862  return LinearInterpolation.ChildRight->GetBoneTransform(bone, transformation);
863  if (!LinearInterpolation.ChildRight->GetBoneTransform(bone, combine_with))
864  return true; // First Child affects bone
865 
866  transformation = StdMeshTransformation::Nlerp(transformation, combine_with, fixtof(LinearInterpolation.Weight->Value));
867  return true;
868  default:
869  assert(false);
870  return false;
871  }
872 }
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 356 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

unsigned int StdMeshInstanceAnimationNode::GetNumber ( ) const
inline

Definition at line 348 of file StdMesh.h.

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

Definition at line 350 of file StdMesh.h.

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

Definition at line 354 of file StdMesh.h.

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

Definition at line 353 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

AnimationNode* StdMeshInstanceAnimationNode::GetRightChild ( )
inline

Definition at line 357 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

int StdMeshInstanceAnimationNode::GetSlot ( ) const
inline

Definition at line 347 of file StdMesh.h.

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

Definition at line 349 of file StdMesh.h.

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

349 { return Type; }

Here is the caller graph for this function:

C4Real StdMeshInstanceAnimationNode::GetWeight ( ) const
inline

Definition at line 359 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

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

Here is the caller graph for this function:

ValueProvider* StdMeshInstanceAnimationNode::GetWeightProvider ( )
inline

Definition at line 358 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimationNode().

358 { 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 333 of file StdMesh.h.

friend class StdMeshInstance
friend

Definition at line 331 of file StdMesh.h.

friend class StdMeshUpdate
friend

Definition at line 332 of file StdMesh.h.

Member Data Documentation

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

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