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 84 of file StdMeshUpdate.cpp.

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

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

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

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

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: