OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshUpdate Class Reference

#include <StdMeshUpdate.h>

Public Member Functions

 StdMeshUpdate (const StdMesh &old_mesh)
 
void Update (StdMeshInstance *instance, const StdMesh &new_mesh) const
 
const StdMeshGetOldMesh () const
 

Detailed Description

Definition at line 48 of file StdMeshUpdate.h.

Constructor & Destructor Documentation

StdMeshUpdate::StdMeshUpdate ( const StdMesh old_mesh)

Definition at line 83 of file StdMeshUpdate.cpp.

References StdMeshSkeleton::GetBone(), StdMeshSkeleton::GetNumBones(), StdMesh::GetSkeleton(), and StdMeshBone::Name.

83  :
84  OldMesh(&old_mesh), BoneNamesByIndex(OldMesh->GetSkeleton().GetNumBones())
85 {
86  for (unsigned int i = 0; i < OldMesh->GetSkeleton().GetNumBones(); ++i)
87  BoneNamesByIndex[i] = OldMesh->GetSkeleton().GetBone(i).Name;
88 }
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
const StdMeshBone & GetBone(size_t i) const
Definition: StdMesh.h:118
StdCopyStrBuf Name
Definition: StdMesh.h:36
size_t GetNumBones() const
Definition: StdMesh.h:119

Here is the call graph for this function:

Member Function Documentation

const StdMesh& StdMeshUpdate::GetOldMesh ( ) const
inline

Definition at line 56 of file StdMeshUpdate.h.

Referenced by C4DefGraphicsPtrBackupEntry::AssignRemoval(), and C4DefGraphicsPtrBackupEntry::AssignUpdate().

56 { return *OldMesh; }

Here is the caller graph for this function:

void StdMeshUpdate::Update ( StdMeshInstance instance,
const StdMesh new_mesh 
) const

Definition at line 90 of file StdMeshUpdate.cpp.

References StdMeshInstance::AnimationStack, StdMeshInstance::AttachedMeshesBegin(), StdMeshInstance::AttachedMeshesEnd(), StdMeshInstance::AttachParent, StdMeshInstance::BoneTransforms, StdMeshInstance::BoneTransformsDirty, StdMeshInstance::DetachMesh(), StdMeshInstance::GetCompletion(), StdMeshInstance::GetMesh(), StdMeshSkeleton::GetNumBones(), StdMesh::GetNumSubMeshes(), StdMesh::GetSkeleton(), StdMesh::GetSubMesh(), StdMeshInstance::Mesh, StdMeshInstance::AttachedMesh::Number, StdMeshInstance::AttachedMesh::OwnChild, StdMeshInstance::AttachedMesh::Parent, StdMeshInstance::AttachedMesh::SetChildBone(), StdMeshInstance::StopAnimation(), StdMeshInstance::SubMeshInstances, and StdMeshInstance::SubMeshInstancesOrdered.

Referenced by C4DefGraphicsPtrBackupEntry::AssignUpdate().

91 {
92  assert(&instance->GetMesh() == OldMesh);
93 
94  // Update instance to represent new mesh
95  instance->Mesh = &new_mesh;
96  instance->BoneTransforms = std::vector<StdMeshMatrix>(new_mesh.GetSkeleton().GetNumBones(), StdMeshMatrix::Identity());
97  instance->BoneTransformsDirty = true;
98 
99  for (unsigned int i = 0; i < instance->SubMeshInstances.size(); ++i)
100  delete instance->SubMeshInstances[i];
101  instance->SubMeshInstances.resize(new_mesh.GetNumSubMeshes());
102  for (unsigned int i = 0; i < instance->SubMeshInstances.size(); ++i)
103  {
104  instance->SubMeshInstances[i] = new StdSubMeshInstance(*instance, new_mesh.GetSubMesh(i), instance->GetCompletion());
105 
106  // Submeshes are reset to their default material,
107  // so the submesh order is unaltered
108  instance->SubMeshInstancesOrdered = instance->SubMeshInstances;
109 
110  // TODO: We might try to restore the previous mesh material here, using global material manager, maybe iff the number of submesh instances is unchanged.
111  }
112 
113  // Update child bone of attach parent. If the bone does not exist anymore
114  // in the updated mesh, then detach the mesh from its parent
115  if(instance->AttachParent)
116  {
117  if(!instance->AttachParent->SetChildBone(BoneNamesByIndex[instance->AttachParent->ChildBone]))
118  {
119  bool OwnChild = instance->AttachParent->OwnChild;
120  instance->AttachParent->Parent->DetachMesh(instance->AttachParent->Number);
121 
122  // If the attachment owned the child instance then detach procedure
123  // deleted the child instance. In that case we do not want to proceed
124  // with the mesh update procedure.
125  if(OwnChild) return;
126  }
127  }
128 
129  // Update parent bones of attach children. If a bone does not exist in the
130  // updated mesh then detach the mesh from its parent.
131  std::vector<unsigned int> Removal;
132  for(StdMeshInstance::AttachedMeshIter iter = instance->AttachedMeshesBegin(); iter != instance->AttachedMeshesEnd(); ++iter)
133  {
134  if(!(*iter)->SetParentBone(BoneNamesByIndex[(*iter)->ParentBone]))
135  {
136  // Do not detach the mesh right here so we can finish iterating over
137  // all attached meshes first.
138  Removal.push_back((*iter)->Number);
139  }
140  }
141 
142  for(unsigned int i = 0; i < Removal.size(); ++i)
143  instance->DetachMesh(Removal[i]);
144 
145  // Update custom nodes in the animation tree. Leaf nodes which refer to an animation that
146  // does not exist anymore are removed.
147  for (unsigned int i = instance->AnimationStack.size(); i > 0; --i)
148  if(!UpdateAnimationNode(instance, instance->AnimationStack[i-1]))
149  instance->StopAnimation(instance->AnimationStack[i-1]);
150 }
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:658
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
bool BoneTransformsDirty
Definition: StdMesh.h:665
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
bool SetChildBone(const StdStrBuf &bone)
Definition: StdMesh.cpp:1014
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
AttachedMeshIter AttachedMeshesBegin() const
Definition: StdMesh.h:586
void StopAnimation(AnimationNode *node)
Definition: StdMesh.cpp:1203
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:200
const StdMesh * Mesh
Definition: StdMesh.h:649
AttachedMeshList::const_iterator AttachedMeshIter
Definition: StdMesh.h:546
bool DetachMesh(unsigned int number)
Definition: StdMesh.cpp:1408
float GetCompletion() const
Definition: StdMesh.h:556
AttachedMesh * AttachParent
Definition: StdMesh.h:663
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:655
const StdMesh & GetMesh() const
Definition: StdMesh.h:624
size_t GetNumBones() const
Definition: StdMesh.h:119
StdMeshInstance * Parent
Definition: StdMesh.h:512
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657
AttachedMeshIter AttachedMeshesEnd() const
Definition: StdMesh.h:587

Here is the call graph for this function:

Here is the caller graph for this function:


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