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

#include <StdMesh.h>

Collaboration diagram for StdMeshInstance:
[legend]

Classes

class  AttachedMesh
 
class  SerializableValueProvider
 

Public Types

enum  AttachMeshFlags { AM_None = 0, AM_DrawBefore = 1 << 0, AM_MatchSkeleton = 1 << 1 }
 
typedef
StdMeshInstanceAnimationNode 
AnimationNode
 
typedef
StdSubMeshInstance::FaceOrdering 
FaceOrdering
 
typedef
StdMeshInstanceValueProvider 
ValueProvider
 
typedef std::vector
< AttachedMesh * > 
AttachedMeshList
 
typedef
AttachedMeshList::const_iterator 
AttachedMeshIter
 

Public Member Functions

 StdMeshInstance (const StdMesh &mesh, float completion=1.0f)
 
 ~StdMeshInstance ()
 
void SetFaceOrdering (FaceOrdering ordering)
 
void SetFaceOrderingForClrModulation (uint32_t clrmod)
 
const std::vector
< StdMeshVertex > & 
GetSharedVertices () const
 
size_t GetNumSharedVertices () const
 
void SetCompletion (float completion)
 
float GetCompletion () const
 
AnimationNodePlayAnimation (const StdStrBuf &animation_name, int slot, AnimationNode *sibling, ValueProvider *position, ValueProvider *weight, bool stop_previous_animation)
 
AnimationNodePlayAnimation (const StdMeshAnimation &animation, int slot, AnimationNode *sibling, ValueProvider *position, ValueProvider *weight, bool stop_previous_animation)
 
AnimationNodePlayAnimation (const StdMeshBone *bone, const StdMeshTransformation &trans, int slot, AnimationNode *sibling, ValueProvider *weight, bool stop_previous_animation)
 
void StopAnimation (AnimationNode *node)
 
AnimationNodeGetAnimationNodeByNumber (unsigned int number)
 
AnimationNodeGetRootAnimationForSlot (int slot)
 
void SetAnimationPosition (AnimationNode *node, ValueProvider *position)
 
void SetAnimationBoneTransform (AnimationNode *node, const StdMeshTransformation &trans)
 
void SetAnimationWeight (AnimationNode *node, ValueProvider *weight)
 
void ExecuteAnimation (float dt)
 
AttachedMeshAttachMesh (const StdMesh &mesh, AttachedMesh::Denumerator *denumerator, const StdStrBuf &parent_bone, const StdStrBuf &child_bone, const StdMeshMatrix &transformation=StdMeshMatrix::Identity(), uint32_t flags=AM_None, unsigned int attach_number=0)
 
AttachedMeshAttachMesh (StdMeshInstance &instance, AttachedMesh::Denumerator *denumerator, const StdStrBuf &parent_bone, const StdStrBuf &child_bone, const StdMeshMatrix &transformation=StdMeshMatrix::Identity(), uint32_t flags=AM_None, bool own_child=false, unsigned int attach_number=0)
 
bool DetachMesh (unsigned int number)
 
AttachedMeshGetAttachedMeshByNumber (unsigned int number) const
 
AttachedMeshIter AttachedMeshesBegin () const
 
AttachedMeshIter AttachedMeshesEnd () const
 
AttachedMeshGetAttachParent () const
 
size_t GetNumSubMeshes () const
 
StdSubMeshInstanceGetSubMesh (size_t i)
 
const StdSubMeshInstanceGetSubMesh (size_t i) const
 
const StdSubMeshInstanceGetSubMeshOrdered (size_t i) const
 
void SetMaterial (size_t i, const StdMeshMaterial &material)
 
const StdMeshMatrix & GetBoneTransform (size_t i) const
 
size_t GetBoneCount () const
 
bool UpdateBoneTransforms ()
 
void ReorderFaces (StdMeshMatrix *global_trans)
 
void CompileFunc (StdCompiler *pComp, AttachedMesh::DenumeratorFactoryFunc Factory)
 
void DenumeratePointers ()
 
void ClearPointers (class C4Object *pObj)
 
const StdMeshGetMesh () const
 
GLuint GetIBO () const
 
unsigned int GetVAOID () const
 

Protected Types

typedef std::vector
< AnimationNode * > 
AnimationNodeList
 

Protected Member Functions

void UpdateIBO ()
 
AttachedMeshAttachMeshImpl (StdMeshInstance &instance, AttachedMesh::Denumerator *denumerator, const StdStrBuf &parent_bone, const StdStrBuf &child_bone, const StdMeshMatrix &transformation, uint32_t flags, bool own_child, unsigned int new_attach_number)
 
AnimationNodeList::iterator GetStackIterForSlot (int slot, bool create)
 
void InsertAnimationNode (AnimationNode *node, int slot, AnimationNode *sibling, ValueProvider *weight, bool stop_previous_animation)
 
bool ExecuteAnimationNode (AnimationNode *node)
 
void ApplyBoneTransformToVertices (const std::vector< StdSubMesh::Vertex > &mesh_vertices, std::vector< StdMeshVertex > &instance_vertices)
 
void SetBoneTransformsDirty (bool value)
 

Static Protected Member Functions

template<typename IteratorType , typename FuncObj >
static bool ScanAttachTree (IteratorType begin, IteratorType end, const FuncObj &obj)
 

Protected Attributes

const StdMeshMesh
 
float Completion
 
AnimationNodeList AnimationNodes
 
AnimationNodeList AnimationStack
 
std::vector< StdMeshMatrix > BoneTransforms
 
std::vector< StdSubMeshInstance * > SubMeshInstances
 
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
 
std::vector< AttachedMesh * > AttachChildren
 
AttachedMeshAttachParent
 
bool BoneTransformsDirty
 
GLuint ibo
 
unsigned int vaoid
 

Friends

class StdMeshMaterialUpdate
 
class StdMeshAnimationUpdate
 
class StdMeshUpdate
 

Detailed Description

Definition at line 395 of file StdMesh.h.

Member Typedef Documentation

typedef std::vector<AnimationNode*> StdMeshInstance::AnimationNodeList
protected

Definition at line 641 of file StdMesh.h.

typedef AttachedMeshList::const_iterator StdMeshInstance::AttachedMeshIter

Definition at line 546 of file StdMesh.h.

Definition at line 545 of file StdMesh.h.

Member Enumeration Documentation

Enumerator
AM_None 
AM_DrawBefore 
AM_MatchSkeleton 

Definition at line 407 of file StdMesh.h.

Constructor & Destructor Documentation

StdMeshInstance::StdMeshInstance ( const StdMesh mesh,
float  completion = 1.0f 
)

Definition at line 1085 of file StdMesh.cpp.

References StdMesh::GetNumSubMeshes(), StdMesh::GetSubMesh(), SubMeshInstances, and SubMeshInstancesOrdered.

Referenced by AttachMesh().

1085  :
1086  Mesh(&mesh), Completion(completion),
1087  BoneTransforms(Mesh->GetSkeleton().GetNumBones(), StdMeshMatrix::Identity()),
1089  BoneTransformsDirty(false)
1090 #ifndef USE_CONSOLE
1091  , ibo(0), vaoid(0)
1092 #endif
1093 {
1094  // Create submesh instances
1095  for (unsigned int i = 0; i < Mesh->GetNumSubMeshes(); ++i)
1096  {
1097  const StdSubMesh& submesh = Mesh->GetSubMesh(i);
1098  SubMeshInstances[i] = new StdSubMeshInstance(*this, submesh, completion);
1099  }
1100 
1101  // copy, order is fine at the moment since only default materials are used.
1103 }
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:658
bool BoneTransformsDirty
Definition: StdMesh.h:665
unsigned int vaoid
Definition: StdMesh.h:673
GLuint ibo
Definition: StdMesh.h:672
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:200
const StdMesh * Mesh
Definition: StdMesh.h:649
float Completion
Definition: StdMesh.h:651
AttachedMesh * AttachParent
Definition: StdMesh.h:663
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:655
size_t GetNumBones() const
Definition: StdMesh.h:119
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

StdMeshInstance::~StdMeshInstance ( )

Definition at line 1105 of file StdMesh.cpp.

References AnimationNodes, AnimationStack, AttachChildren, AttachParent, DetachMesh(), CStdGL::FreeVAOID(), ibo, StdMeshInstance::AttachedMesh::Number, StdMeshInstance::AttachedMesh::Parent, pGL, StopAnimation(), SubMeshInstances, and vaoid.

1106 {
1107 #ifndef USE_CONSOLE
1108  if (ibo) glDeleteBuffers(1, &ibo);
1109  if (vaoid) pGL->FreeVAOID(vaoid);
1110 #endif
1111 
1112  // If we are attached then detach from parent
1113  if (AttachParent)
1115 
1116  // Remove all attach children
1117  while (!AttachChildren.empty())
1118  DetachMesh(AttachChildren.back()->Number);
1119 
1120  while (!AnimationStack.empty())
1121  StopAnimation(AnimationStack.front());
1122  assert(AnimationNodes.empty());
1123 
1124  // Delete submeshes
1125  for (unsigned int i = 0; i < SubMeshInstances.size(); ++i)
1126  {
1127  delete SubMeshInstances[i];
1128  }
1129 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
unsigned int vaoid
Definition: StdMesh.h:673
GLuint ibo
Definition: StdMesh.h:672
void FreeVAOID(unsigned int vaoid)
Definition: C4DrawGL.cpp:976
void StopAnimation(AnimationNode *node)
Definition: StdMesh.cpp:1203
bool DetachMesh(unsigned int number)
Definition: StdMesh.cpp:1408
AttachedMesh * AttachParent
Definition: StdMesh.h:663
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
CStdGL * pGL
Definition: C4DrawGL.cpp:914
StdMeshInstance * Parent
Definition: StdMesh.h:512
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Member Function Documentation

void StdMeshInstance::ApplyBoneTransformToVertices ( const std::vector< StdSubMesh::Vertex > &  mesh_vertices,
std::vector< StdMeshVertex > &  instance_vertices 
)
protected
AttachedMeshIter StdMeshInstance::AttachedMeshesBegin ( ) const
inline

Definition at line 586 of file StdMesh.h.

Referenced by StdMeshUpdate::Update().

586 { return AttachChildren.begin(); }
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662

Here is the caller graph for this function:

AttachedMeshIter StdMeshInstance::AttachedMeshesEnd ( ) const
inline

Definition at line 587 of file StdMesh.h.

Referenced by StdMeshUpdate::Update().

587 { return AttachChildren.end(); }
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662

Here is the caller graph for this function:

StdMeshInstance::AttachedMesh * StdMeshInstance::AttachMesh ( const StdMesh mesh,
AttachedMesh::Denumerator denumerator,
const StdStrBuf parent_bone,
const StdStrBuf child_bone,
const StdMeshMatrix &  transformation = StdMeshMatrix::Identity(),
uint32_t  flags = AM_None,
unsigned int  attach_number = 0 
)

Definition at line 1346 of file StdMesh.cpp.

References StdMeshInstance().

1347 {
1348  std::unique_ptr<AttachedMesh::Denumerator> auto_denumerator(denumerator);
1349 
1350  StdMeshInstance* instance = new StdMeshInstance(mesh, 1.0f);
1351  AttachedMesh* attach = AttachMesh(*instance, auto_denumerator.release(), parent_bone, child_bone, transformation, flags, true, attach_number);
1352  if (!attach) { delete instance; return nullptr; }
1353  return attach;
1354 }
StdMeshInstance(const StdMesh &mesh, float completion=1.0f)
Definition: StdMesh.cpp:1085
AttachedMesh * AttachMesh(const StdMesh &mesh, AttachedMesh::Denumerator *denumerator, const StdStrBuf &parent_bone, const StdStrBuf &child_bone, const StdMeshMatrix &transformation=StdMeshMatrix::Identity(), uint32_t flags=AM_None, unsigned int attach_number=0)
Definition: StdMesh.cpp:1346

Here is the call graph for this function:

StdMeshInstance::AttachedMesh * StdMeshInstance::AttachMesh ( StdMeshInstance instance,
AttachedMesh::Denumerator denumerator,
const StdStrBuf parent_bone,
const StdStrBuf child_bone,
const StdMeshMatrix &  transformation = StdMeshMatrix::Identity(),
uint32_t  flags = AM_None,
bool  own_child = false,
unsigned int  attach_number = 0 
)

Definition at line 1356 of file StdMesh.cpp.

References AttachChildren, AttachMeshImpl(), AttachParent, StdMeshInstance::AttachedMesh::Child, GetAttachedMeshByNumber(), StdMeshInstance::AttachedMesh::OwnChild, and ScanAttachTree().

1357 {
1358  std::unique_ptr<AttachedMesh::Denumerator> auto_denumerator(denumerator);
1359 
1360  // Owned attach children must be set via the topmost instance, to ensure
1361  // attach number uniqueness.
1362  if (AttachParent && AttachParent->OwnChild) return nullptr;
1363 
1364  // Find free index.
1365  unsigned int number = 0;
1366  ScanAttachTree(AttachChildren.begin(), AttachChildren.end(), [&number](AttachedMeshList::const_iterator iter) { number = std::max(number, (*iter)->Number); return true; });
1367  number += 1; // One above highest
1368 
1369  StdMeshInstance* direct_parent = this;
1370  if (attach_number != 0)
1371  {
1372  AttachedMesh* attach = GetAttachedMeshByNumber(attach_number);
1373  if (attach == nullptr) return nullptr;
1374  direct_parent = attach->Child;
1375  }
1376 
1377  return direct_parent->AttachMeshImpl(instance, auto_denumerator.release(), parent_bone, child_bone, transformation, flags, own_child, number);
1378 }
AttachedMesh * GetAttachedMeshByNumber(unsigned int number) const
Definition: StdMesh.cpp:1432
AttachedMesh * AttachMeshImpl(StdMeshInstance &instance, AttachedMesh::Denumerator *denumerator, const StdStrBuf &parent_bone, const StdStrBuf &child_bone, const StdMeshMatrix &transformation, uint32_t flags, bool own_child, unsigned int new_attach_number)
Definition: StdMesh.cpp:1380
AttachedMesh * AttachParent
Definition: StdMesh.h:663
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
static bool ScanAttachTree(IteratorType begin, IteratorType end, const FuncObj &obj)
Definition: StdMesh.cpp:1713

Here is the call graph for this function:

StdMeshInstance::AttachedMesh * StdMeshInstance::AttachMeshImpl ( StdMeshInstance instance,
AttachedMesh::Denumerator denumerator,
const StdStrBuf parent_bone,
const StdStrBuf child_bone,
const StdMeshMatrix &  transformation,
uint32_t  flags,
bool  own_child,
unsigned int  new_attach_number 
)
protected

Definition at line 1380 of file StdMesh.cpp.

References AM_DrawBefore, AttachChildren, AttachParent, StdMeshSkeleton::GetBoneByName(), StdMesh::GetSkeleton(), StdMeshBone::Index, Mesh, and StdMeshInstance::AttachedMesh::Parent.

Referenced by AttachMesh().

1381 {
1382  std::unique_ptr<AttachedMesh::Denumerator> auto_denumerator(denumerator);
1383 
1384  // We don't allow an instance to be attached to multiple parent instances for now
1385  if (instance.AttachParent) return nullptr;
1386 
1387  // Make sure there are no cyclic attachments
1388  for (StdMeshInstance* Parent = this; Parent->AttachParent != nullptr; Parent = Parent->AttachParent->Parent)
1389  if (Parent == &instance)
1390  return nullptr;
1391 
1392  const StdMeshBone* parent_bone_obj = Mesh->GetSkeleton().GetBoneByName(parent_bone);
1393  const StdMeshBone* child_bone_obj = instance.Mesh->GetSkeleton().GetBoneByName(child_bone);
1394  if (!parent_bone_obj || !child_bone_obj) return nullptr;
1395 
1396  AttachedMesh* attach = new AttachedMesh(new_attach_number, this, &instance, own_child, auto_denumerator.release(), parent_bone_obj->Index, child_bone_obj->Index, transformation, flags);
1397  instance.AttachParent = attach;
1398 
1399  // If DrawInFront is set then sort before others so that drawing order is easy
1400  if(flags & AM_DrawBefore)
1401  AttachChildren.insert(AttachChildren.begin(), attach);
1402  else
1403  AttachChildren.insert(AttachChildren.end(), attach);
1404 
1405  return attach;
1406 }
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
const StdMesh * Mesh
Definition: StdMesh.h:649
const StdMeshBone * GetBoneByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:388
AttachedMesh * AttachParent
Definition: StdMesh.h:663
unsigned int Index
Definition: StdMesh.h:34
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
StdMeshInstance * Parent
Definition: StdMesh.h:512

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::ClearPointers ( class C4Object pObj)

Definition at line 1697 of file StdMesh.cpp.

References AnimationNodes, AttachChildren, and DetachMesh().

Referenced by C4Object::ClearPointers().

1698 {
1699  for(unsigned int i = 0; i < AnimationNodes.size(); ++i)
1700  if(AnimationNodes[i])
1701  AnimationNodes[i]->ClearPointers(pObj);
1702 
1703  std::vector<unsigned int> Removal;
1704  for(unsigned int i = 0; i < AttachChildren.size(); ++i)
1705  if(!AttachChildren[i]->ClearPointers(pObj))
1706  Removal.push_back(AttachChildren[i]->Number);
1707 
1708  for(unsigned int i = 0; i < Removal.size(); ++i)
1709  DetachMesh(Removal[i]);
1710 }
void ClearPointers(class C4Object *pObj)
Definition: StdMesh.cpp:1697
bool DetachMesh(unsigned int number)
Definition: StdMesh.cpp:1408
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::CompileFunc ( StdCompiler pComp,
AttachedMesh::DenumeratorFactoryFunc  Factory 
)

Definition at line 1592 of file StdMesh.cpp.

References AnimationNodes, AnimationStack, AttachChildren, AttachParent, StdCompiler::excCorrupt(), GetStackIterForSlot(), StdCompiler::isDeserializer(), StdMeshInstanceAnimationNode::LinearInterpolationNode, mkNamingAdapt(), mkNamingCountAdapt(), mkNamingPtrAdapt(), mkParAdapt(), StdMeshInstanceAnimationNode::Number, StdMeshInstance::AttachedMesh::Parent, SetBoneTransformsDirty(), StdMeshInstanceAnimationNode::Slot, SubMeshInstances, SubMeshInstancesOrdered, StdMeshInstanceAnimationNode::Type, and StdCompiler::Value().

1593 {
1594  if(pComp->isDeserializer())
1595  {
1596  // Only initially created instances can be compiled
1597  assert(!AttachParent);
1598  assert(AttachChildren.empty());
1599  assert(AnimationStack.empty());
1600  SetBoneTransformsDirty(true);
1601 
1602  bool valid;
1603  pComp->Value(mkNamingAdapt(valid, "Valid"));
1604  if(!valid) pComp->excCorrupt("Mesh instance is invalid");
1605 
1606  int32_t iSubMeshCnt;
1607  pComp->Value(mkNamingCountAdapt(iSubMeshCnt, "SubMesh"));
1608  if(static_cast<uint32_t>(iSubMeshCnt) != SubMeshInstances.size())
1609  pComp->excCorrupt("Invalid number of submeshes");
1610  for(int32_t i = 0; i < iSubMeshCnt; ++i)
1611  pComp->Value(mkNamingAdapt(*SubMeshInstances[i], "SubMesh"));
1612  std::stable_sort(SubMeshInstancesOrdered.begin(), SubMeshInstancesOrdered.end(), StdMeshSubMeshInstanceVisibilityCmpPred());
1613 
1614  int32_t iAnimCnt = AnimationStack.size();
1615  pComp->Value(mkNamingCountAdapt(iAnimCnt, "AnimationNode"));
1616 
1617  for(int32_t i = 0; i < iAnimCnt; ++i)
1618  {
1619  AnimationNode* node = nullptr;
1620  pComp->Value(mkParAdapt(mkNamingPtrAdapt(node, "AnimationNode"), Mesh));
1621  AnimationNodeList::iterator iter = GetStackIterForSlot(node->Slot, true);
1622  if(*iter != nullptr) { delete node; pComp->excCorrupt("Duplicate animation slot index"); }
1623  *iter = node;
1624 
1625  // Add nodes into lookup table
1626  std::vector<AnimationNode*> nodes(1, node);
1627  while(!nodes.empty())
1628  {
1629  node = nodes.back();
1630  nodes.erase(nodes.end()-1);
1631 
1632  if (AnimationNodes.size() <= node->Number)
1633  AnimationNodes.resize(node->Number+1);
1634  if(AnimationNodes[node->Number] != nullptr) pComp->excCorrupt("Duplicate animation node number");
1635  AnimationNodes[node->Number] = node;
1636 
1637  if(node->Type == AnimationNode::LinearInterpolationNode)
1638  {
1639  nodes.push_back(node->LinearInterpolation.ChildLeft);
1640  nodes.push_back(node->LinearInterpolation.ChildRight);
1641  }
1642  }
1643  }
1644 
1645  int32_t iAttachedCnt;
1646  pComp->Value(mkNamingCountAdapt(iAttachedCnt, "Attached"));
1647 
1648  for(int32_t i = 0; i < iAttachedCnt; ++i)
1649  {
1650  AttachChildren.push_back(new AttachedMesh);
1651  AttachedMesh* attach = AttachChildren.back();
1652 
1653  attach->Parent = this;
1654  pComp->Value(mkNamingAdapt(mkParAdapt(*attach, Factory), "Attached"));
1655  }
1656  }
1657  else
1658  {
1659  // Write something to make sure that the parent
1660  // named section ([Mesh] or [ChildInstance]) is written.
1661  // StdCompilerIni does not make a difference between
1662  // non-existing and empty named sections.
1663  bool valid = true;
1664  pComp->Value(mkNamingAdapt(valid, "Valid"));
1665 
1666  int32_t iSubMeshCnt = SubMeshInstances.size();
1667  pComp->Value(mkNamingCountAdapt(iSubMeshCnt, "SubMesh"));
1668  for(int32_t i = 0; i < iSubMeshCnt; ++i)
1669  pComp->Value(mkNamingAdapt(*SubMeshInstances[i], "SubMesh"));
1670 
1671  int32_t iAnimCnt = AnimationStack.size();
1672  pComp->Value(mkNamingCountAdapt(iAnimCnt, "AnimationNode"));
1673 
1674  for(AnimationNodeList::iterator iter = AnimationStack.begin(); iter != AnimationStack.end(); ++iter)
1675  pComp->Value(mkParAdapt(mkNamingPtrAdapt(*iter, "AnimationNode"), Mesh));
1676 
1677  int32_t iAttachedCnt = AttachChildren.size();
1678  pComp->Value(mkNamingCountAdapt(iAttachedCnt, "Attached"));
1679 
1680  for(unsigned int i = 0; i < AttachChildren.size(); ++i)
1681  pComp->Value(mkNamingAdapt(mkParAdapt(*AttachChildren[i], Factory), "Attached"));
1682  }
1683 }
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:658
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:977
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
const StdMesh * Mesh
Definition: StdMesh.h:649
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:401
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
AttachedMesh * AttachParent
Definition: StdMesh.h:663
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:459
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
AnimationNodeList::iterator GetStackIterForSlot(int slot, bool create)
Definition: StdMesh.cpp:1729
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
StdPtrAdapt< T > mkNamingPtrAdapt(T *&rpObj, const char *szNaming)
Definition: StdAdaptors.h:605
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

void StdMeshInstance::DenumeratePointers ( )

Definition at line 1685 of file StdMesh.cpp.

References AnimationNodes, and AttachChildren.

Referenced by C4Object::Denumerate().

1686 {
1687  for(unsigned int i = 0; i < AnimationNodes.size(); ++i)
1688  if(AnimationNodes[i])
1689  AnimationNodes[i]->DenumeratePointers();
1690 
1691  for(unsigned int i = 0; i < AttachChildren.size(); ++i)
1692  {
1693  AttachChildren[i]->DenumeratePointers();
1694  }
1695 }
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662

Here is the caller graph for this function:

bool StdMeshInstance::DetachMesh ( unsigned int  number)

Definition at line 1408 of file StdMesh.cpp.

References AttachChildren, AttachParent, StdMeshInstance::AttachedMesh::Child, StdMeshInstance::AttachedMesh::Parent, and ScanAttachTree().

Referenced by ClearPointers(), StdMeshUpdate::Update(), C4Object::UpdateGraphics(), and ~StdMeshInstance().

1409 {
1410  return !ScanAttachTree(AttachChildren.begin(), AttachChildren.end(), [this, number](AttachedMeshList::iterator iter)
1411  {
1412  if ((*iter)->Number == number)
1413  {
1414  AttachedMesh* attached = *iter;
1415 
1416  // Reset attach parent of child so it does not try
1417  // to detach itself on destruction.
1418  attached->Child->AttachParent = nullptr;
1419  attached->Parent->AttachChildren.erase(iter);
1420 
1421  delete attached;
1422 
1423  // Finish scan
1424  return false;
1425  }
1426 
1427  // Continue scan
1428  return true;
1429  });
1430 }
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
static bool ScanAttachTree(IteratorType begin, IteratorType end, const FuncObj &obj)
Definition: StdMesh.cpp:1713

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::ExecuteAnimation ( float  dt)

Definition at line 1301 of file StdMesh.cpp.

References AnimationStack, AttachChildren, StdMeshMaterial::BestTechniqueIndex, StdMeshMaterialTextureUnit::Duration, ExecuteAnimationNode(), StdSubMeshInstance::GetMaterial(), StdMeshMaterialTextureUnit::GetNumTextures(), StdMeshMaterialTextureUnit::HasFrameAnimation(), StdMeshMaterialTextureUnit::HasTexCoordAnimation(), StdSubMeshInstance::PassData, StdMeshMaterialTechnique::Passes, StdSubMeshInstance::TexUnit::Phase, StdSubMeshInstance::TexUnit::PhaseDelay, StdSubMeshInstance::TexUnit::Position, StopAnimation(), SubMeshInstances, StdMeshMaterial::Techniques, and StdSubMeshInstance::Pass::TexUnits.

Referenced by C4Object::Execute().

1302 {
1303  // Iterate from the back since slots might be removed
1304  for (unsigned int i = AnimationStack.size(); i > 0; --i)
1307 
1308 #ifndef USE_CONSOLE
1309  // Update animated textures
1310  for (unsigned int i = 0; i < SubMeshInstances.size(); ++i)
1311  {
1312  StdSubMeshInstance& submesh = *SubMeshInstances[i];
1313  const StdMeshMaterial& material = submesh.GetMaterial();
1314  const StdMeshMaterialTechnique& technique = material.Techniques[material.BestTechniqueIndex];
1315  for (unsigned int j = 0; j < submesh.PassData.size(); ++j)
1316  {
1317  StdSubMeshInstance::Pass& pass = submesh.PassData[j];
1318  for (unsigned int k = 0; k < pass.TexUnits.size(); ++k)
1319  {
1320  const StdMeshMaterialTextureUnit& texunit = technique.Passes[j].TextureUnits[k];
1321  StdSubMeshInstance::TexUnit& texunit_instance = submesh.PassData[j].TexUnits[k];
1322  if (texunit.HasFrameAnimation())
1323  {
1324  const unsigned int NumPhases = texunit.GetNumTextures();
1325  const float PhaseDuration = texunit.Duration / NumPhases;
1326 
1327  const float Position = texunit_instance.PhaseDelay + dt;
1328  const unsigned int AddPhases = static_cast<unsigned int>(Position / PhaseDuration);
1329 
1330  texunit_instance.Phase = (texunit_instance.Phase + AddPhases) % NumPhases;
1331  texunit_instance.PhaseDelay = Position - AddPhases * PhaseDuration;
1332  }
1333 
1334  if (texunit.HasTexCoordAnimation())
1335  texunit_instance.Position += dt;
1336  }
1337  }
1338  }
1339 #endif
1340 
1341  // Update animation for attached meshes
1342  for (AttachedMeshList::iterator iter = AttachChildren.begin(); iter != AttachChildren.end(); ++iter)
1343  (*iter)->Child->ExecuteAnimation(dt);
1344 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
const StdMeshMaterial & GetMaterial() const
Definition: StdMesh.h:272
std::vector< TexUnit > TexUnits
Definition: StdMesh.h:299
size_t GetNumTextures() const
void StopAnimation(AnimationNode *node)
Definition: StdMesh.cpp:1203
std::vector< Pass > PassData
Definition: StdMesh.h:302
bool HasTexCoordAnimation() const
bool ExecuteAnimationNode(AnimationNode *node)
Definition: StdMesh.cpp:1827
std::vector< StdMeshMaterialPass > Passes
std::vector< StdMeshMaterialTechnique > Techniques
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshInstance::ExecuteAnimationNode ( AnimationNode node)
protected

Definition at line 1827 of file StdMesh.cpp.

References Clamp(), StdMeshInstanceAnimationNode::CustomNode, StdMeshInstanceValueProvider::Execute(), Fix0, ftofix(), StdMeshInstanceAnimationNode::GetAnimation(), StdMeshInstanceAnimationNode::GetLeftChild(), StdMeshInstanceAnimationNode::GetPositionProvider(), StdMeshInstanceAnimationNode::GetRightChild(), StdMeshInstanceAnimationNode::GetType(), StdMeshInstanceAnimationNode::GetWeight(), StdMeshInstanceAnimationNode::GetWeightProvider(), itofix(), StdMeshInstanceAnimationNode::LeafNode, StdMeshAnimation::Length, StdMeshInstanceAnimationNode::LinearInterpolationNode, SetBoneTransformsDirty(), StopAnimation(), and StdMeshInstanceValueProvider::Value.

Referenced by ExecuteAnimation().

1828 {
1829  ValueProvider* provider = nullptr;
1830  C4Real min;
1831  C4Real max;
1832 
1833  switch (node->GetType())
1834  {
1836  provider = node->GetPositionProvider();
1837  min = Fix0;
1838  max = ftofix(node->GetAnimation()->Length);
1839  break;
1841  // No execution necessary
1842  return true;
1844  provider = node->GetWeightProvider();
1845  min = Fix0;
1846  max = itofix(1);
1847  break;
1848  default:
1849  assert(false);
1850  break;
1851  }
1852 
1853  assert(provider);
1854  const C4Real old_value = provider->Value;
1855 
1856  if (!provider->Execute())
1857  {
1858  if (node->GetType() == AnimationNode::LeafNode) return false;
1859 
1860  // Remove the child with less weight (normally weight reaches 0.0 or 1.0)
1861  if (node->GetWeight() > itofix(1, 2))
1862  {
1863  // Remove both children (by parent) if other wants to be deleted as well
1864  if (!ExecuteAnimationNode(node->GetRightChild())) return false;
1865  // Remove left child as it has less weight
1866  StopAnimation(node->LinearInterpolation.ChildLeft);
1867  }
1868  else
1869  {
1870  // Remove both children (by parent) if other wants to be deleted as well
1871  if (!ExecuteAnimationNode(node->GetLeftChild())) return false;
1872  // Remove right child as it has less weight
1873  StopAnimation(node->LinearInterpolation.ChildRight);
1874  }
1875  }
1876  else
1877  {
1878  if (provider->Value != old_value)
1879  {
1880  provider->Value = Clamp(provider->Value, min, max);
1881  SetBoneTransformsDirty(true);
1882  }
1883 
1884  if (node->GetType() == AnimationNode::LinearInterpolationNode)
1885  {
1886  const bool left_result = ExecuteAnimationNode(node->GetLeftChild());
1887  const bool right_result = ExecuteAnimationNode(node->GetRightChild());
1888 
1889  // Remove this node completely
1890  if (!left_result && !right_result)
1891  return false;
1892 
1893  // Note that either of this also removes node
1894  if (!left_result)
1895  StopAnimation(node->GetLeftChild());
1896  if (!right_result)
1897  StopAnimation(node->GetRightChild());
1898  }
1899  }
1900 
1901  return true;
1902 }
StdMeshInstanceValueProvider ValueProvider
Definition: StdMesh.h:413
Definition: C4Real.h:58
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
void StopAnimation(AnimationNode *node)
Definition: StdMesh.cpp:1203
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4Fixed ftofix(float x)
Definition: C4Real.h:258
bool ExecuteAnimationNode(AnimationNode *node)
Definition: StdMesh.cpp:1827
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

StdMeshInstance::AnimationNode * StdMeshInstance::GetAnimationNodeByNumber ( unsigned int  number)

Definition at line 1260 of file StdMesh.cpp.

References AnimationNodes.

1261 {
1262  if (number >= AnimationNodes.size()) return nullptr;
1263  return AnimationNodes[number];
1264 }
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
StdMeshInstance::AttachedMesh * StdMeshInstance::GetAttachedMeshByNumber ( unsigned int  number) const

Definition at line 1432 of file StdMesh.cpp.

References AttachChildren, and ScanAttachTree().

Referenced by AttachMesh().

1433 {
1434  StdMeshInstance::AttachedMesh* result = nullptr;
1435 
1436  ScanAttachTree(AttachChildren.begin(), AttachChildren.end(), [number, &result](AttachedMeshList::const_iterator iter)
1437  {
1438  if ((*iter)->Number == number)
1439  {
1440  result = *iter;
1441  return false;
1442  }
1443 
1444  return true;
1445  });
1446 
1447  return result;
1448 }
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
static bool ScanAttachTree(IteratorType begin, IteratorType end, const FuncObj &obj)
Definition: StdMesh.cpp:1713

Here is the call graph for this function:

Here is the caller graph for this function:

AttachedMesh* StdMeshInstance::GetAttachParent ( ) const
inline

Definition at line 588 of file StdMesh.h.

Referenced by C4Object::Execute(), and C4Object::UpdateGraphics().

588 { return AttachParent; }
AttachedMesh * AttachParent
Definition: StdMesh.h:663

Here is the caller graph for this function:

size_t StdMeshInstance::GetBoneCount ( ) const

Definition at line 1476 of file StdMesh.cpp.

References AM_MatchSkeleton, AttachParent, BoneTransforms, and StdMeshInstance::AttachedMesh::GetFlags().

1477 {
1478  if ((AttachParent != nullptr) && (AttachParent->GetFlags() & AM_MatchSkeleton))
1479  return AttachParent->MatchedBoneInParentSkeleton.size();
1480  else
1481  return BoneTransforms.size();
1482 }
uint32_t GetFlags() const
Definition: StdMesh.h:521
AttachedMesh * AttachParent
Definition: StdMesh.h:663
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:655

Here is the call graph for this function:

const StdMeshMatrix & StdMeshInstance::GetBoneTransform ( size_t  i) const

Definition at line 1459 of file StdMesh.cpp.

References AM_MatchSkeleton, AttachParent, BoneTransforms, StdMeshInstance::AttachedMesh::GetFlags(), and StdMeshInstance::AttachedMesh::Parent.

Referenced by UpdateBoneTransforms().

1460 {
1461  if ((AttachParent != nullptr) && (AttachParent->GetFlags() & AM_MatchSkeleton))
1462  {
1463  assert(i < AttachParent->MatchedBoneInParentSkeleton.size());
1464 
1465  int parent_bone_index = AttachParent->MatchedBoneInParentSkeleton[i];
1466 
1467  if (parent_bone_index > -1)
1468  {
1469  return AttachParent->Parent->BoneTransforms[i];
1470  }
1471  }
1472 
1473  return BoneTransforms[i];
1474 }
uint32_t GetFlags() const
Definition: StdMesh.h:521
AttachedMesh * AttachParent
Definition: StdMesh.h:663
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:655
StdMeshInstance * Parent
Definition: StdMesh.h:512

Here is the call graph for this function:

Here is the caller graph for this function:

float StdMeshInstance::GetCompletion ( ) const
inline

Definition at line 556 of file StdMesh.h.

Referenced by StdSubMeshInstance::SetFaceOrdering(), and StdMeshUpdate::Update().

556 { return Completion; }
float Completion
Definition: StdMesh.h:651

Here is the caller graph for this function:

GLuint StdMeshInstance::GetIBO ( ) const
inline

Definition at line 627 of file StdMesh.h.

627 { return ibo ? ibo : Mesh->GetIBO(); }
GLuint ibo
Definition: StdMesh.h:672
GLuint GetIBO() const
Definition: StdMesh.h:215
const StdMesh * Mesh
Definition: StdMesh.h:649
const StdMesh& StdMeshInstance::GetMesh ( ) const
inline

Definition at line 624 of file StdMesh.h.

Referenced by StdMeshInstance::AttachedMesh::AttachedMesh(), C4Object::DrawFaceImpl(), CStdGL::PerformMesh(), StdMeshMaterialUpdate::Update(), StdMeshUpdate::Update(), and C4Object::UpdateGraphics().

624 { return *Mesh; }
const StdMesh * Mesh
Definition: StdMesh.h:649

Here is the caller graph for this function:

size_t StdMeshInstance::GetNumSharedVertices ( ) const
inline

Definition at line 552 of file StdMesh.h.

552 { return GetSharedVertices().size(); }
const std::vector< StdMeshVertex > & GetSharedVertices() const
Definition: StdMesh.h:551
size_t StdMeshInstance::GetNumSubMeshes ( ) const
inline

Definition at line 590 of file StdMesh.h.

590 { return SubMeshInstances.size(); }
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657
StdMeshInstance::AnimationNode * StdMeshInstance::GetRootAnimationForSlot ( int  slot)

Definition at line 1266 of file StdMesh.cpp.

References AnimationStack, and GetStackIterForSlot().

Referenced by C4Object::CompileFunc(), and InsertAnimationNode().

1267 {
1268  AnimationNodeList::iterator iter = GetStackIterForSlot(slot, false);
1269  if (iter == AnimationStack.end()) return nullptr;
1270  return *iter;
1271 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
AnimationNodeList::iterator GetStackIterForSlot(int slot, bool create)
Definition: StdMesh.cpp:1729

Here is the call graph for this function:

Here is the caller graph for this function:

const std::vector<StdMeshVertex>& StdMeshInstance::GetSharedVertices ( ) const
inline

Definition at line 551 of file StdMesh.h.

Referenced by StdSubMeshInstance::LoadFacesForCompletion(), and ReorderFaces().

551 { return Mesh->GetSharedVertices(); }
const std::vector< Vertex > & GetSharedVertices() const
Definition: StdMesh.h:203
const StdMesh * Mesh
Definition: StdMesh.h:649

Here is the caller graph for this function:

StdMeshInstance::AnimationNodeList::iterator StdMeshInstance::GetStackIterForSlot ( int  slot,
bool  create 
)
protected

Definition at line 1729 of file StdMesh.cpp.

References AnimationStack.

Referenced by CompileFunc(), GetRootAnimationForSlot(), InsertAnimationNode(), and StopAnimation().

1730 {
1731  // TODO: bsearch
1732  for (AnimationNodeList::iterator iter = AnimationStack.begin(); iter != AnimationStack.end(); ++iter)
1733  {
1734  if ((*iter)->Slot == slot)
1735  {
1736  return iter;
1737  }
1738  else if ((*iter)->Slot > slot)
1739  {
1740  if (!create)
1741  return AnimationStack.end();
1742  else
1743  return AnimationStack.insert(iter, nullptr);
1744  }
1745  }
1746 
1747  if (!create)
1748  return AnimationStack.end();
1749  else
1750  return AnimationStack.insert(AnimationStack.end(), nullptr);
1751 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654

Here is the caller graph for this function:

StdSubMeshInstance& StdMeshInstance::GetSubMesh ( size_t  i)
inline

Definition at line 591 of file StdMesh.h.

591 { return *SubMeshInstances[i]; }
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657
const StdSubMeshInstance& StdMeshInstance::GetSubMesh ( size_t  i) const
inline

Definition at line 592 of file StdMesh.h.

592 { return *SubMeshInstances[i]; }
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657
const StdSubMeshInstance& StdMeshInstance::GetSubMeshOrdered ( size_t  i) const
inline

Definition at line 593 of file StdMesh.h.

593 { return *SubMeshInstancesOrdered[i]; }
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:658
unsigned int StdMeshInstance::GetVAOID ( ) const
inline

Definition at line 628 of file StdMesh.h.

628 { return vaoid ? vaoid : Mesh->GetVAOID(); }
unsigned int vaoid
Definition: StdMesh.h:673
const StdMesh * Mesh
Definition: StdMesh.h:649
unsigned int GetVAOID() const
Definition: StdMesh.h:216
void StdMeshInstance::InsertAnimationNode ( AnimationNode node,
int  slot,
AnimationNode sibling,
ValueProvider weight,
bool  stop_previous_animation 
)
protected

Definition at line 1753 of file StdMesh.cpp.

References AnimationNodes, AnimationStack, Clamp(), Fix0, GetRootAnimationForSlot(), GetStackIterForSlot(), itofix(), StdMeshInstanceAnimationNode::Number, StdMeshInstanceAnimationNode::Parent, SetBoneTransformsDirty(), StdMeshInstanceAnimationNode::Slot, StopAnimation(), and StdMeshInstanceValueProvider::Value.

Referenced by PlayAnimation().

1754 {
1755  assert(!sibling || !stop_previous_animation);
1756  // Default
1757  if (!sibling) sibling = GetRootAnimationForSlot(slot);
1758  assert(!sibling || sibling->Slot == slot);
1759 
1760  // Stop any animation already running in this slot?
1761  if (sibling && stop_previous_animation)
1762  {
1763  StopAnimation(sibling);
1764  sibling = nullptr;
1765  }
1766 
1767  // Find two subsequent numbers in case we need to create two nodes, so
1768  // script can deduce the second node.
1769  unsigned int Number1, Number2;
1770  for (Number1 = 0; Number1 < AnimationNodes.size(); ++Number1)
1771  if (AnimationNodes[Number1] == nullptr && (!sibling || Number1+1 == AnimationNodes.size() || AnimationNodes[Number1+1] == nullptr))
1772  break;
1773  /* for(Number2 = Number1+1; Number2 < AnimationNodes.size(); ++Number2)
1774  if(AnimationNodes[Number2] == nullptr)
1775  break;*/
1776  Number2 = Number1 + 1;
1777 
1778  weight->Value = Clamp(weight->Value, Fix0, itofix(1));
1779 
1780  if (Number1 == AnimationNodes.size()) AnimationNodes.push_back( (StdMeshInstance::AnimationNode*) nullptr);
1781  if (sibling && Number2 == AnimationNodes.size()) AnimationNodes.push_back( (StdMeshInstance::AnimationNode*) nullptr);
1782 
1783  AnimationNodes[Number1] = node;
1784  node->Number = Number1;
1785  node->Slot = slot;
1786 
1787  if (sibling)
1788  {
1789  AnimationNode* parent = new AnimationNode(node, sibling, weight);
1790  AnimationNodes[Number2] = parent;
1791  parent->Number = Number2;
1792  parent->Slot = slot;
1793 
1794  node->Parent = parent;
1795  parent->Parent = sibling->Parent;
1796  parent->LinearInterpolation.ChildLeft = sibling;
1797  parent->LinearInterpolation.ChildRight = node;
1798  if (sibling->Parent)
1799  {
1800  if (sibling->Parent->LinearInterpolation.ChildLeft == sibling)
1801  sibling->Parent->LinearInterpolation.ChildLeft = parent;
1802  else
1803  sibling->Parent->LinearInterpolation.ChildRight = parent;
1804  }
1805  else
1806  {
1807  // set new parent
1808  AnimationNodeList::iterator iter = GetStackIterForSlot(slot, false);
1809  // slot must not be empty, since sibling uses same slot
1810  assert(iter != AnimationStack.end() && *iter != nullptr);
1811  *iter = parent;
1812  }
1813 
1814  sibling->Parent = parent;
1815  }
1816  else
1817  {
1818  delete weight;
1819  AnimationNodeList::iterator iter = GetStackIterForSlot(slot, true);
1820  assert(!*iter); // we have a sibling if slot is not empty
1821  *iter = node;
1822  }
1823 
1824  SetBoneTransformsDirty(true);
1825 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
AnimationNode * GetRootAnimationForSlot(int slot)
Definition: StdMesh.cpp:1266
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
void StopAnimation(AnimationNode *node)
Definition: StdMesh.cpp:1203
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:401
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
AnimationNodeList::iterator GetStackIterForSlot(int slot, bool create)
Definition: StdMesh.cpp:1729
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

Here is the caller graph for this function:

StdMeshInstance::AnimationNode * StdMeshInstance::PlayAnimation ( const StdStrBuf animation_name,
int  slot,
AnimationNode sibling,
ValueProvider position,
ValueProvider weight,
bool  stop_previous_animation 
)

Definition at line 1180 of file StdMesh.cpp.

References StdMeshSkeleton::GetAnimationByName(), and StdMesh::GetSkeleton().

Referenced by C4Object::SetAction(), and C4GraphicsOverlay::UpdateFacet().

1181 {
1182  const StdMeshAnimation* animation = Mesh->GetSkeleton().GetAnimationByName(animation_name);
1183  if (!animation) { delete position; delete weight; return nullptr; }
1184 
1185  return PlayAnimation(*animation, slot, sibling, position, weight, stop_previous_animation);
1186 }
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
AnimationNode * PlayAnimation(const StdStrBuf &animation_name, int slot, AnimationNode *sibling, ValueProvider *position, ValueProvider *weight, bool stop_previous_animation)
Definition: StdMesh.cpp:1180
const StdMeshAnimation * GetAnimationByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:398
const StdMesh * Mesh
Definition: StdMesh.h:649

Here is the call graph for this function:

Here is the caller graph for this function:

StdMeshInstance::AnimationNode * StdMeshInstance::PlayAnimation ( const StdMeshAnimation animation,
int  slot,
AnimationNode sibling,
ValueProvider position,
ValueProvider weight,
bool  stop_previous_animation 
)

Definition at line 1188 of file StdMesh.cpp.

References Clamp(), Fix0, ftofix(), InsertAnimationNode(), StdMeshAnimation::Length, and StdMeshInstanceValueProvider::Value.

1189 {
1190  position->Value = Clamp(position->Value, Fix0, ftofix(animation.Length));
1191  AnimationNode* child = new AnimationNode(&animation, position);
1192  InsertAnimationNode(child, slot, sibling, weight, stop_previous_animation);
1193  return child;
1194 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
void InsertAnimationNode(AnimationNode *node, int slot, AnimationNode *sibling, ValueProvider *weight, bool stop_previous_animation)
Definition: StdMesh.cpp:1753
C4Fixed ftofix(float x)
Definition: C4Real.h:258
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:401
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

StdMeshInstance::AnimationNode * StdMeshInstance::PlayAnimation ( const StdMeshBone bone,
const StdMeshTransformation &  trans,
int  slot,
AnimationNode sibling,
ValueProvider weight,
bool  stop_previous_animation 
)

Definition at line 1196 of file StdMesh.cpp.

References InsertAnimationNode().

1197 {
1198  AnimationNode* child = new AnimationNode(bone, trans);
1199  InsertAnimationNode(child, slot, sibling, weight, stop_previous_animation);
1200  return child;
1201 }
void InsertAnimationNode(AnimationNode *node, int slot, AnimationNode *sibling, ValueProvider *weight, bool stop_previous_animation)
Definition: StdMesh.cpp:1753
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:401

Here is the call graph for this function:

void StdMeshInstance::ReorderFaces ( StdMeshMatrix *  global_trans)

Definition at line 1566 of file StdMesh.cpp.

References StdSubMeshInstance::CurrentFaceOrdering, StdSubMeshInstance::Faces, StdSubMeshInstance::FO_Fixed, StdSubMesh::GetNumVertices(), GetSharedVertices(), StdSubMeshInstance::GetSubMesh(), StdSubMesh::GetVertices(), SubMeshInstances, and UpdateIBO().

Referenced by C4Draw::RenderMesh().

1567 {
1568 #ifndef USE_CONSOLE
1569  for (unsigned int i = 0; i < SubMeshInstances.size(); ++i)
1570  {
1572  assert((inst.Faces.size() > 0) && "StdMeshInstance sub-mesh instance has zero faces");
1573 
1574  if(inst.Faces.size() > 0 && inst.CurrentFaceOrdering != StdSubMeshInstance::FO_Fixed)
1575  {
1576  const StdMeshVertex* vertices;
1577  if(inst.GetSubMesh().GetNumVertices() > 0)
1578  vertices = &inst.GetSubMesh().GetVertices()[0];
1579  else
1580  vertices = &GetSharedVertices()[0];
1581  SortFacesArray(vertices, inst.Faces, inst.CurrentFaceOrdering, global_trans ? *global_trans : StdMeshMatrix::Identity());
1582  }
1583  }
1584 
1585  // TODO: Also reorder submeshes, attached meshes and include AttachTransformation for attached meshes...
1586 
1587  // Faces have been reordered: upload new order to GPU
1588  UpdateIBO();
1589 #endif
1590 }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:303
const StdSubMesh & GetSubMesh() const
Definition: StdMesh.h:267
const std::vector< StdMeshVertex > & GetSharedVertices() const
Definition: StdMesh.h:551
size_t GetNumVertices() const
Definition: StdMesh.h:167
const std::vector< Vertex > & GetVertices() const
Definition: StdMesh.h:165
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:282
void UpdateIBO()
Definition: StdMesh.cpp:1925
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename IteratorType , typename FuncObj >
bool StdMeshInstance::ScanAttachTree ( IteratorType  begin,
IteratorType  end,
const FuncObj &  obj 
)
staticprotected

Definition at line 1713 of file StdMesh.cpp.

Referenced by AttachMesh(), DetachMesh(), and GetAttachedMeshByNumber().

1714 {
1715  for (IteratorType iter = begin; iter != end; ++iter)
1716  {
1717  if (!obj(iter)) return false;
1718 
1719  // Scan attached tree of own children. For non-owned children,
1720  // we can't guarantee unique attach numbers.
1721  if( (*iter)->OwnChild)
1722  if (!ScanAttachTree((*iter)->Child->AttachChildren.begin(), (*iter)->Child->AttachChildren.end(), obj))
1723  return false;
1724  }
1725 
1726  return true;
1727 }
static bool ScanAttachTree(IteratorType begin, IteratorType end, const FuncObj &obj)
Definition: StdMesh.cpp:1713

Here is the caller graph for this function:

void StdMeshInstance::SetAnimationBoneTransform ( AnimationNode node,
const StdMeshTransformation &  trans 
)

Definition at line 1284 of file StdMesh.cpp.

References StdMeshInstanceAnimationNode::CustomNode, StdMeshInstanceAnimationNode::GetType(), and SetBoneTransformsDirty().

1285 {
1286  assert(node->GetType() == AnimationNode::CustomNode);
1287  *node->Custom.Transformation = trans;
1288  SetBoneTransformsDirty(true);
1289 }
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904

Here is the call graph for this function:

void StdMeshInstance::SetAnimationPosition ( AnimationNode node,
ValueProvider position 
)

Definition at line 1273 of file StdMesh.cpp.

References Clamp(), Fix0, ftofix(), StdMeshInstanceAnimationNode::GetType(), StdMeshInstanceAnimationNode::LeafNode, SetBoneTransformsDirty(), and StdMeshInstanceValueProvider::Value.

1274 {
1275  assert(node->GetType() == AnimationNode::LeafNode);
1276  delete node->Leaf.Position;
1277  node->Leaf.Position = position;
1278 
1279  position->Value = Clamp(position->Value, Fix0, ftofix(node->Leaf.Animation->Length));
1280 
1281  SetBoneTransformsDirty(true);
1282 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
C4Fixed ftofix(float x)
Definition: C4Real.h:258
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

void StdMeshInstance::SetAnimationWeight ( AnimationNode node,
ValueProvider weight 
)

Definition at line 1291 of file StdMesh.cpp.

References Clamp(), Fix0, StdMeshInstanceAnimationNode::GetType(), itofix(), StdMeshInstanceAnimationNode::LinearInterpolationNode, SetBoneTransformsDirty(), and StdMeshInstanceValueProvider::Value.

1292 {
1293  assert(node->GetType() == AnimationNode::LinearInterpolationNode);
1294  delete node->LinearInterpolation.Weight; node->LinearInterpolation.Weight = weight;
1295 
1296  weight->Value = Clamp(weight->Value, Fix0, itofix(1));
1297 
1298  SetBoneTransformsDirty(true);
1299 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
const C4Real Fix0
Definition: C4Real.h:312

Here is the call graph for this function:

void StdMeshInstance::SetBoneTransformsDirty ( bool  value)
protected

Definition at line 1904 of file StdMesh.cpp.

References AM_MatchSkeleton, AttachChildren, BoneTransformsDirty, StdMeshInstance::AttachedMesh::Child, StdMeshInstance::AttachedMesh::GetFlags(), and SetBoneTransformsDirty().

Referenced by CompileFunc(), ExecuteAnimationNode(), InsertAnimationNode(), SetAnimationBoneTransform(), SetAnimationPosition(), SetAnimationWeight(), SetBoneTransformsDirty(), StopAnimation(), and UpdateBoneTransforms().

1905 {
1906  BoneTransformsDirty = value;
1907 
1908  // only if the value is true, so that updates happen
1909  if (value)
1910  {
1911  // Update attachment's attach transformations. Note this is done recursively.
1912  for (AttachedMeshList::iterator iter = AttachChildren.begin(); iter != AttachChildren.end(); ++iter)
1913  {
1914  AttachedMesh* attach = *iter;
1915 
1916  if (attach->GetFlags() & AM_MatchSkeleton)
1917  {
1918  attach->Child->SetBoneTransformsDirty(value);
1919  }
1920  }
1921  }
1922 }
bool BoneTransformsDirty
Definition: StdMesh.h:665
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::SetCompletion ( float  completion)

Definition at line 1165 of file StdMesh.cpp.

References Completion, StdMesh::GetNumSubMeshes(), StdMesh::GetSubMesh(), SubMeshInstances, and UpdateIBO().

Referenced by C4Object::DoCon().

1166 {
1167  Completion = completion;
1168 
1169 #ifndef USE_CONSOLE
1170  // TODO: Load all submesh faces and then determine the ones to use from the
1171  // full pool.
1172  for(unsigned int i = 0; i < Mesh->GetNumSubMeshes(); ++i)
1173  SubMeshInstances[i]->LoadFacesForCompletion(*this, Mesh->GetSubMesh(i), completion);
1174 
1175  // Faces have been reordered: upload new order to GPU
1176  UpdateIBO();
1177 #endif
1178 }
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:200
const StdMesh * Mesh
Definition: StdMesh.h:649
float Completion
Definition: StdMesh.h:651
void UpdateIBO()
Definition: StdMesh.cpp:1925
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::SetFaceOrdering ( FaceOrdering  ordering)

Definition at line 1131 of file StdMesh.cpp.

References AttachChildren, StdMesh::GetNumSubMeshes(), StdMesh::GetSubMesh(), SubMeshInstances, and UpdateIBO().

Referenced by C4EditCursor::DrawObject().

1132 {
1133 #ifndef USE_CONSOLE
1134  for (unsigned int i = 0; i < Mesh->GetNumSubMeshes(); ++i)
1135  SubMeshInstances[i]->SetFaceOrdering(*this, Mesh->GetSubMesh(i), ordering);
1136 
1137  // Faces have been reordered: upload new order to GPU
1138  UpdateIBO();
1139 
1140  // Update attachments (only own meshes for now... others might be displayed both attached and non-attached...)
1141  // still not optimal.
1142  for (AttachedMeshIter iter = AttachChildren.begin(); iter != AttachChildren.end(); ++iter)
1143  if ((*iter)->OwnChild)
1144  (*iter)->Child->SetFaceOrdering(ordering);
1145 #endif
1146 }
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
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
void SetFaceOrdering(FaceOrdering ordering)
Definition: StdMesh.cpp:1131
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
void UpdateIBO()
Definition: StdMesh.cpp:1925
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::SetFaceOrderingForClrModulation ( uint32_t  clrmod)

Definition at line 1148 of file StdMesh.cpp.

References AttachChildren, StdMesh::GetNumSubMeshes(), StdMesh::GetSubMesh(), SubMeshInstances, and UpdateIBO().

Referenced by C4Object::CompileFunc(), C4GraphicsOverlay::Draw(), C4EditCursor::DrawObject(), C4GraphicsOverlay::DrawPicture(), C4Object::Init(), and C4Object::UpdateGraphics().

1149 {
1150 #ifndef USE_CONSOLE
1151  for (unsigned int i = 0; i < Mesh->GetNumSubMeshes(); ++i)
1153 
1154  // Faces have been reordered: upload new order to GPU
1155  UpdateIBO();
1156 
1157  // Update attachments (only own meshes for now... others might be displayed both attached and non-attached...)
1158  // still not optimal.
1159  for (AttachedMeshIter iter = AttachChildren.begin(); iter != AttachChildren.end(); ++iter)
1160  if ((*iter)->OwnChild)
1161  (*iter)->Child->SetFaceOrderingForClrModulation(clrmod);
1162 #endif
1163 }
void SetFaceOrderingForClrModulation(uint32_t clrmod)
Definition: StdMesh.cpp:1148
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
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
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
void UpdateIBO()
Definition: StdMesh.cpp:1925
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::SetMaterial ( size_t  i,
const StdMeshMaterial material 
)

Definition at line 1450 of file StdMesh.cpp.

References SubMeshInstances, and SubMeshInstancesOrdered.

1451 {
1452  assert(i < SubMeshInstances.size());
1453  SubMeshInstances[i]->SetMaterial(material);
1454 #ifndef USE_CONSOLE
1455  std::stable_sort(SubMeshInstancesOrdered.begin(), SubMeshInstancesOrdered.end(), StdMeshSubMeshInstanceVisibilityCmpPred());
1456 #endif
1457 }
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:658
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657
void StdMeshInstance::StopAnimation ( AnimationNode node)

Definition at line 1203 of file StdMesh.cpp.

References AnimationNodes, AnimationStack, GetStackIterForSlot(), StdMeshInstanceAnimationNode::LinearInterpolationNode, StdMeshInstanceAnimationNode::Number, StdMeshInstanceAnimationNode::Parent, SetBoneTransformsDirty(), StdMeshInstanceAnimationNode::Slot, and StdMeshInstanceAnimationNode::Type.

Referenced by ExecuteAnimation(), ExecuteAnimationNode(), InsertAnimationNode(), C4Object::SetAction(), StdMeshUpdate::Update(), StdMeshAnimationUpdate::Update(), and ~StdMeshInstance().

1204 {
1205  ClearAnimationListRecursively(AnimationNodes, node);
1206 
1207  AnimationNode* parent = node->Parent;
1208  if (parent == nullptr)
1209  {
1210  AnimationNodeList::iterator iter = GetStackIterForSlot(node->Slot, false);
1211  assert(iter != AnimationStack.end() && *iter == node);
1212  AnimationStack.erase(iter);
1213  delete node;
1214  }
1215  else
1216  {
1217  assert(parent->Type == AnimationNode::LinearInterpolationNode);
1218 
1219  // Remove parent interpolation node and re-link
1220  AnimationNode* other_child;
1221  if (parent->LinearInterpolation.ChildLeft == node)
1222  {
1223  other_child = parent->LinearInterpolation.ChildRight;
1224  parent->LinearInterpolation.ChildRight = nullptr;
1225  }
1226  else
1227  {
1228  other_child = parent->LinearInterpolation.ChildLeft;
1229  parent->LinearInterpolation.ChildLeft = nullptr;
1230  }
1231 
1232  if (parent->Parent)
1233  {
1234  assert(parent->Parent->Type == AnimationNode::LinearInterpolationNode);
1235  if (parent->Parent->LinearInterpolation.ChildLeft == parent)
1236  parent->Parent->LinearInterpolation.ChildLeft = other_child;
1237  else
1238  parent->Parent->LinearInterpolation.ChildRight = other_child;
1239  other_child->Parent = parent->Parent;
1240  }
1241  else
1242  {
1243  AnimationNodeList::iterator iter = GetStackIterForSlot(node->Slot, false);
1244  assert(iter != AnimationStack.end() && *iter == parent);
1245  *iter = other_child;
1246 
1247  other_child->Parent = nullptr;
1248  }
1249 
1250  AnimationNodes[parent->Number] = nullptr;
1251  // Recursively deletes parent and its descendants
1252  delete parent;
1253  }
1254 
1255  while (!AnimationNodes.empty() && AnimationNodes.back() == nullptr)
1256  AnimationNodes.erase(AnimationNodes.end()-1);
1257  SetBoneTransformsDirty(true);
1258 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
AnimationNode * Parent
Definition: StdMesh.h:369
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:401
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
AnimationNodeList AnimationNodes
Definition: StdMesh.h:653
AnimationNodeList::iterator GetStackIterForSlot(int slot, bool create)
Definition: StdMesh.cpp:1729

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshInstance::UpdateBoneTransforms ( )

Definition at line 1484 of file StdMesh.cpp.

References AnimationStack, AttachChildren, BoneTransforms, BoneTransformsDirty, StdMeshInstance::AttachedMesh::Child, StdMeshSkeleton::GetBone(), GetBoneTransform(), StdMeshBone::GetParent(), StdMesh::GetSkeleton(), StdMeshBone::Index, StdMeshBone::InverseTransformation, Mesh, SetBoneTransformsDirty(), StdMeshBone::Transformation, and UpdateBoneTransforms().

Referenced by C4Draw::RenderMesh(), and UpdateBoneTransforms().

1485 {
1486  bool was_dirty = BoneTransformsDirty;
1487 
1488  // Nothing changed since last time
1489  if (BoneTransformsDirty)
1490  {
1491  // Compute transformation matrix for each bone.
1492  for (unsigned int i = 0; i < BoneTransforms.size(); ++i)
1493  {
1494  StdMeshTransformation Transformation;
1495 
1496  const StdMeshBone& bone = Mesh->GetSkeleton().GetBone(i);
1497  const StdMeshBone* parent = bone.GetParent();
1498  assert(!parent || parent->Index < i);
1499 
1500  bool have_transform = false;
1501  for (unsigned int j = 0; j < AnimationStack.size(); ++j)
1502  {
1503  if (have_transform)
1504  {
1505  StdMeshTransformation other;
1506  if (AnimationStack[j]->GetBoneTransform(i, other))
1507  Transformation = StdMeshTransformation::Nlerp(Transformation, other, 1.0f); // TODO: Allow custom weighing for slot combination
1508  }
1509  else
1510  {
1511  have_transform = AnimationStack[j]->GetBoneTransform(i, Transformation);
1512  }
1513  }
1514 
1515  if (!have_transform)
1516  {
1517  if (parent)
1518  BoneTransforms[i] = BoneTransforms[parent->Index];
1519  else
1520  BoneTransforms[i] = StdMeshMatrix::Identity();
1521  }
1522  else
1523  {
1524  BoneTransforms[i] = StdMeshMatrix::Transform(bone.Transformation * Transformation * bone.InverseTransformation);
1525  if (parent) BoneTransforms[i] = BoneTransforms[parent->Index] * BoneTransforms[i];
1526  }
1527  }
1528  }
1529 
1530  // Update attachment's attach transformations. Note this is done recursively.
1531  for (AttachedMeshList::iterator iter = AttachChildren.begin(); iter != AttachChildren.end(); ++iter)
1532  {
1533  AttachedMesh* attach = *iter;
1534  const bool ChildBoneTransformsDirty = attach->Child->BoneTransformsDirty;
1535  attach->Child->UpdateBoneTransforms();
1536 
1537  if (BoneTransformsDirty || ChildBoneTransformsDirty || attach->FinalTransformDirty)
1538  {
1539  was_dirty = true;
1540 
1541  // Compute matrix to change the coordinate system to the one of the attached bone:
1542  // The idea is that a vertex at the child bone's position transforms to the parent bone's position.
1543  // Therefore (read from right to left) we first apply the inverse of the child bone transformation,
1544  // then an optional scaling matrix, and finally the parent bone transformation
1545 
1546  // TODO: we can cache the three matrices in the middle since they don't change over time,
1547  // reducing this to two matrix multiplications instead of four each frame.
1548  // Might even be worth to compute the complete transformation directly when rendering then
1549  // (saves per-instance memory, but requires recomputation if the animation does not change).
1550  // TODO: We might also be able to cache child inverse, and only recomupte it if
1551  // child bone transforms are dirty (saves matrix inversion for unanimated attach children).
1552  attach->FinalTrans = GetBoneTransform(attach->ParentBone)
1553  * StdMeshMatrix::Transform(Mesh->GetSkeleton().GetBone(attach->ParentBone).Transformation)
1554  * attach->AttachTrans
1555  * StdMeshMatrix::Transform(attach->Child->Mesh->GetSkeleton().GetBone(attach->ChildBone).InverseTransformation)
1556  * StdMeshMatrix::Inverse(attach->Child->GetBoneTransform(attach->ChildBone));
1557 
1558  attach->FinalTransformDirty = false;
1559  }
1560  }
1561 
1562  SetBoneTransformsDirty(false);
1563  return was_dirty;
1564 }
AnimationNodeList AnimationStack
Definition: StdMesh.h:654
bool BoneTransformsDirty
Definition: StdMesh.h:665
StdMeshTransformation Transformation
Definition: StdMesh.h:39
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:205
const StdMeshMatrix & GetBoneTransform(size_t i) const
Definition: StdMesh.cpp:1459
const StdMeshBone & GetBone(size_t i) const
Definition: StdMesh.h:118
const StdMesh * Mesh
Definition: StdMesh.h:649
void SetBoneTransformsDirty(bool value)
Definition: StdMesh.cpp:1904
StdMeshTransformation InverseTransformation
Definition: StdMesh.h:41
unsigned int Index
Definition: StdMesh.h:34
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:655
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:662
const StdMeshBone * GetParent() const
Definition: StdMesh.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshInstance::UpdateIBO ( )
protected

Definition at line 1925 of file StdMesh.cpp.

References StdSubMeshInstance::FO_Fixed, CStdGL::FreeVAOID(), CStdGL::GenVAOID(), StdSubMesh::GetNumFaces(), StdMesh::GetNumSubMeshes(), StdMesh::GetSubMesh(), ibo, pGL, SubMeshInstances, and vaoid.

Referenced by ReorderFaces(), SetCompletion(), SetFaceOrdering(), and SetFaceOrderingForClrModulation().

1926 {
1927  // First, find out whether we have fixed face ordering or not
1928  bool all_submeshes_fixed = true;
1929  for (StdSubMeshInstance* inst : SubMeshInstances)
1930  {
1931  all_submeshes_fixed = (inst->GetFaceOrdering() == StdSubMeshInstance::FO_Fixed);
1932  if (!all_submeshes_fixed) break;
1933 
1934  // If true, submesh is 100% complete
1935  all_submeshes_fixed = inst->GetNumFaces() == inst->GetSubMesh().GetNumFaces();
1936  if (!all_submeshes_fixed) break;
1937  }
1938 
1939  // If the face ordering is fixed, then we don't need a custom
1940  // IBO. This is typically the case for all meshes without transparency
1941  // and 100% completion.
1942  if (all_submeshes_fixed)
1943  {
1944  if (ibo) glDeleteBuffers(1, &ibo);
1945  if (vaoid) pGL->FreeVAOID(vaoid);
1946  ibo = 0; vaoid = 0;
1947  }
1948  else
1949  {
1950  // We have a custom face ordering, or we render only a subset
1951  // of our faces. Create a custom IBO and upload the index
1952  // data.
1953  if (ibo == 0)
1954  {
1955  // This is required, because the IBO binding is part
1956  // of the VAO state. If we create a new IBO we cannot
1957  // keep using any old VAO. But we always create and
1958  // destroy them together, so we can assert here.
1959  assert(vaoid == 0);
1960 
1961  size_t total_faces = 0;
1962  for (unsigned int i = 0; i < Mesh->GetNumSubMeshes(); ++i)
1963  total_faces += Mesh->GetSubMesh(i).GetNumFaces();
1964 
1965  glGenBuffers(1, &ibo);
1966  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
1967 
1968  // TODO: Optimize mode. In many cases this is still fairly static.
1969  glBufferData(GL_ELEMENT_ARRAY_BUFFER, total_faces * 3 * sizeof(GLuint), nullptr, GL_STREAM_DRAW);
1970  }
1971  else
1972  {
1973  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
1974  }
1975 
1976  for (StdSubMeshInstance* inst : SubMeshInstances)
1977  {
1978  assert(inst->GetNumFaces() <= inst->GetSubMesh().GetNumFaces());
1979  glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, inst->GetSubMesh().GetOffsetInIBO(), inst->GetNumFaces() * 3 * sizeof(GLuint), &inst->Faces[0]);
1980  }
1981 
1982  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1983 
1984  if (vaoid == 0)
1985  vaoid = pGL->GenVAOID();
1986  }
1987 }
unsigned int vaoid
Definition: StdMesh.h:673
GLuint ibo
Definition: StdMesh.h:672
size_t GetNumFaces() const
Definition: StdMesh.h:170
void FreeVAOID(unsigned int vaoid)
Definition: C4DrawGL.cpp:976
size_t GetNumSubMeshes() const
Definition: StdMesh.h:201
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:200
const StdMesh * Mesh
Definition: StdMesh.h:649
unsigned int GenVAOID()
Definition: C4DrawGL.cpp:934
CStdGL * pGL
Definition: C4DrawGL.cpp:914
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:657

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class StdMeshAnimationUpdate
friend

Definition at line 398 of file StdMesh.h.

friend class StdMeshMaterialUpdate
friend

Definition at line 397 of file StdMesh.h.

friend class StdMeshUpdate
friend

Definition at line 399 of file StdMesh.h.

Member Data Documentation

AnimationNodeList StdMeshInstance::AnimationNodes
protected
AttachedMesh* StdMeshInstance::AttachParent
protected
std::vector<StdMeshMatrix> StdMeshInstance::BoneTransforms
protected
bool StdMeshInstance::BoneTransformsDirty
protected

Definition at line 665 of file StdMesh.h.

Referenced by SetBoneTransformsDirty(), StdMeshUpdate::Update(), and UpdateBoneTransforms().

float StdMeshInstance::Completion
protected

Definition at line 651 of file StdMesh.h.

Referenced by SetCompletion().

GLuint StdMeshInstance::ibo
protected

Definition at line 672 of file StdMesh.h.

Referenced by UpdateIBO(), and ~StdMeshInstance().

const StdMesh* StdMeshInstance::Mesh
protected

Definition at line 649 of file StdMesh.h.

Referenced by AttachMeshImpl(), StdMeshUpdate::Update(), and UpdateBoneTransforms().

std::vector<StdSubMeshInstance*> StdMeshInstance::SubMeshInstancesOrdered
protected

Definition at line 658 of file StdMesh.h.

Referenced by CompileFunc(), SetMaterial(), StdMeshInstance(), and StdMeshUpdate::Update().

unsigned int StdMeshInstance::vaoid
protected

Definition at line 673 of file StdMesh.h.

Referenced by UpdateIBO(), and ~StdMeshInstance().


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