OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMesh.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 #ifndef INC_StdMesh
18 #define INC_StdMesh
19 
21 #include "lib/StdMeshMaterial.h"
22 #include "lib/StdMeshMath.h"
23 
25 {
26  friend class StdMeshSkeleton;
27  friend class StdMeshSkeletonLoader;
28  friend class StdMeshXML;
29 public:
30  StdMeshBone() = default;
31 
32  unsigned int Index; // Index in master bone table
33  int ID; // Bone ID
34  StdCopyStrBuf Name; // Bone name
35 
36  // Bone transformation
37  StdMeshTransformation Transformation;
38  // Inverse transformation
39  StdMeshTransformation InverseTransformation;
40 
41  const StdMeshBone* GetParent() const { return Parent; }
42 
43 private:
44  StdMeshBone* Parent; // Parent bone
45  std::vector<StdMeshBone*> Children; // Children. Not owned.
46 
47  StdMeshBone(const StdMeshBone&) = delete;
48  StdMeshBone& operator=(const StdMeshBone&) = delete;
49 };
50 
52 {
53 public:
54  unsigned int BoneIndex;
55  float Weight;
56 };
57 
59 {
60 public:
61  unsigned int Vertices[3];
62 };
63 
64 // Keyframe, specifies transformation for one bone in a particular frame
66 {
67 public:
68  StdMeshTransformation Transformation;
69 };
70 
71 // Animation track, specifies transformation for one bone for each keyframe
73 {
74  friend class StdMeshSkeleton;
75  friend class StdMeshSkeletonLoader;
76 public:
77  StdMeshTransformation GetTransformAt(float time, float length) const;
78 
79 private:
80  std::map<float, StdMeshKeyFrame> Frames;
81 };
82 
83 // Animation, consists of one Track for each animated Bone
85 {
86  friend class StdMeshSkeleton;
87  friend class StdMeshSkeletonLoader;
88  friend class StdMeshInstance;
90 public:
91  StdMeshAnimation() = default;
92  StdMeshAnimation(const StdMeshAnimation& other);
94 
96 
98  float Length;
99 
100 private:
101  std::vector<StdMeshTrack*> Tracks; // bone-indexed
102  const class StdMeshSkeleton* OriginSkeleton; // saves, where the animation came from
103 };
104 
106 {
107  friend class StdMeshSkeletonLoader;
108  friend class StdMeshXML;
109  friend class StdMesh;
111 
112  StdMeshSkeleton();
113 public:
115 
116  const StdMeshBone& GetBone(size_t i) const { return *Bones[i]; }
117  size_t GetNumBones() const { return Bones.size(); }
118  const StdMeshBone* GetBoneByName(const StdStrBuf& name) const;
119 
120  const StdMeshAnimation* GetAnimationByName(const StdStrBuf& name) const;
121  bool IsAnimated() const { return !Animations.empty(); }
122 
123  // TODO: This code should maybe better be placed in StdMeshLoader...
124  void MirrorAnimation(const StdMeshAnimation& animation);
125  void InsertAnimation(const StdMeshAnimation& animation);
126  void InsertAnimation(const StdMeshSkeleton& source, const StdMeshAnimation& animation);
127  void PostInit();
128 
129  std::vector<int> GetMatchingBones(const StdMeshSkeleton& skeleton) const;
130 
131  std::vector<const StdMeshAnimation*> GetAnimations() const;
132 
133 private:
134  void AddMasterBone(StdMeshBone* bone);
135 
136  StdMeshSkeleton(const StdMeshSkeleton& other) = delete;
137  StdMeshSkeleton& operator=(const StdMeshSkeleton& other) = delete;
138 
139  std::vector<StdMeshBone*> Bones; // Master Bone Table
140 
141  std::map<StdCopyStrBuf, StdMeshAnimation> Animations;
142 };
143 
145 {
146  float x1, y1, z1;
147  float x2, y2, z2;
148 
150  {
151  return StdMeshVector{ (x2 + x1) / 2.0f, (y2 + y1) / 2.0f, (z2 + z1) / 2.0f };
152  }
153 };
154 
156 {
157  friend class StdMesh;
158  friend class StdMeshLoader;
159  friend class StdMeshMaterialUpdate;
160 public:
162 
163  const std::vector<Vertex>& GetVertices() const { return Vertices; }
164  const Vertex& GetVertex(size_t i) const { return Vertices[i]; }
165  size_t GetNumVertices() const { return Vertices.size(); }
166 
167  const StdMeshFace& GetFace(size_t i) const { return Faces[i]; }
168  size_t GetNumFaces() const { return Faces.size(); }
169 
170  const StdMeshMaterial& GetMaterial() const { return *Material; }
171 
172  // Return the offset into the backing vertex buffer where this SubMesh's data starts
173  size_t GetOffsetInVBO() const { return vertex_buffer_offset; }
174  size_t GetOffsetInIBO() const { return index_buffer_offset; }
175 
176 private:
177  StdSubMesh() = default;
178 
179  std::vector<Vertex> Vertices; // Empty if we use shared vertices
180  std::vector<StdMeshFace> Faces;
181  size_t vertex_buffer_offset{0};
182  size_t index_buffer_offset{0};
183 
184  const StdMeshMaterial* Material{nullptr};
185 };
186 
187 class StdMesh
188 {
189  friend class StdMeshLoader;
190  friend class StdMeshMaterialUpdate;
191 
192  StdMesh();
193 public:
194  ~StdMesh();
195 
197 
198  const StdSubMesh& GetSubMesh(size_t i) const { return SubMeshes[i]; }
199  size_t GetNumSubMeshes() const { return SubMeshes.size(); }
200 
201  const std::vector<Vertex>& GetSharedVertices() const { return SharedVertices; }
202 
203  const StdMeshSkeleton& GetSkeleton() const { return *Skeleton; }
204  StdMeshSkeleton& GetSkeleton() { return *Skeleton; }
205 
206  const StdMeshBox& GetBoundingBox() const { return BoundingBox; }
207  float GetBoundingRadius() const { return BoundingRadius; }
208 
209  void PostInit();
210 
211 #ifndef USE_CONSOLE
212  GLuint GetVBO() const { return vbo; }
213  GLuint GetIBO() const { return ibo; }
214  unsigned int GetVAOID() const { return vaoid; }
215 #endif
216 
217  void SetLabel(const std::string &label) { Label = label; }
218 
219 private:
220 #ifndef USE_CONSOLE
221  GLuint vbo{0};
222  GLuint ibo{0};
223  unsigned int vaoid{0};
224  void UpdateVBO();
225  void UpdateIBO();
226 #endif
227 
228  StdMesh(const StdMesh& other) = delete;
229  StdMesh& operator=(const StdMesh& other) = delete;
230 
231  std::vector<Vertex> SharedVertices;
232 
233  std::vector<StdSubMesh> SubMeshes;
234  std::shared_ptr<StdMeshSkeleton> Skeleton; // Skeleton
235 
236  std::string Label;
237 
238  StdMeshBox BoundingBox;
239  float BoundingRadius;
240 };
241 
243 {
244  friend class StdMeshInstance;
245  friend class StdMeshMaterialUpdate;
246 public:
247 
249  {
250  FO_Fixed, // don't reorder, keep faces as in mesh
252  FO_NearestToFarthest
253  };
254 
255  StdSubMeshInstance(class StdMeshInstance& instance, const StdSubMesh& submesh, float completion);
256  void LoadFacesForCompletion(class StdMeshInstance& instance, const StdSubMesh& submesh, float completion);
257 
258  void CompileFunc(StdCompiler* pComp);
259 
260  // Get face of instance. The instance faces are the same as the mesh faces,
261  // with the exception that they are differently ordered, depending on the
262  // current FaceOrdering. See FaceOrdering in StdMeshInstance.
263  const StdMeshFace* GetFaces() const { return Faces.size() > 0 ? &Faces[0] : nullptr; }
264  size_t GetNumFaces() const { return Faces.size(); }
265  const StdSubMesh &GetSubMesh() const { return *base; }
266 
267  unsigned int GetTexturePhase(size_t pass, size_t texunit) const { return PassData[pass].TexUnits[texunit].Phase; }
268  double GetTexturePosition(size_t pass, size_t texunit) const { return PassData[pass].TexUnits[texunit].Position; }
269 
270  const StdMeshMaterial& GetMaterial() const { return *Material; }
271 
272  FaceOrdering GetFaceOrdering() const { return CurrentFaceOrdering; }
273 protected:
274  void SetMaterial(const StdMeshMaterial& material);
275  void SetFaceOrdering(class StdMeshInstance& instance, const StdSubMesh& submesh, FaceOrdering ordering);
276  void SetFaceOrderingForClrModulation(class StdMeshInstance& instance, const StdSubMesh& submesh, uint32_t clrmod);
277 
278  const StdSubMesh *base;
279  // Faces sorted according to current face ordering
280  std::vector<StdMeshFace> Faces;
281 
283 
284  struct TexUnit // Runtime texunit data
285  {
286  // Frame animation
287  float PhaseDelay;
288  unsigned int Phase;
289 
290  // Coordinate transformation animation
291  // This is never reset so use double to make sure we have enough precision
292  double Position;
293  };
294 
295  struct Pass // Runtime pass data
296  {
297  std::vector<TexUnit> TexUnits;
298  };
299 
300  std::vector<Pass> PassData;
302 
303  // TODO: GLuint texenv_list; // NoSave, texture environment setup could be stored in a display list (w/ and w/o ClrMod). What about PlayerColor?
304 
305 private:
306  StdSubMeshInstance(const StdSubMeshInstance& other) = delete;
307  StdSubMeshInstance& operator=(const StdSubMeshInstance& other) = delete;
308 };
309 
310 
311 // Provider for animation position or weight.
313 {
314 public:
316  virtual ~StdMeshInstanceValueProvider() = default;
317 
318  // Return false if the corresponding node is to be removed or true
319  // otherwise.
320  virtual bool Execute() = 0;
321 
322  C4Real Value; // Current provider value
323 };
324 
325 // A node in the animation tree
326 // Can be either a leaf node, or interpolation between two other nodes
328 {
329  friend class StdMeshInstance;
330  friend class StdMeshUpdate;
332 public:
335  enum NodeType { LeafNode, CustomNode, LinearInterpolationNode };
336 
338  StdMeshInstanceAnimationNode(const StdMeshAnimation* animation, ValueProvider* position);
339  StdMeshInstanceAnimationNode(const StdMeshBone* bone, const StdMeshTransformation& trans);
340  StdMeshInstanceAnimationNode(AnimationNode* child_left, AnimationNode* child_right, ValueProvider* weight);
342 
343  bool GetBoneTransform(unsigned int bone, StdMeshTransformation& transformation);
344 
345  int GetSlot() const { return Slot; }
346  unsigned int GetNumber() const { return Number; }
347  NodeType GetType() const { return Type; }
348  AnimationNode* GetParent() { return Parent; }
349 
350  const StdMeshAnimation* GetAnimation() const { assert(Type == LeafNode); return Leaf.Animation; }
351  ValueProvider* GetPositionProvider() { assert(Type == LeafNode); return Leaf.Position; }
352  C4Real GetPosition() const { assert(Type == LeafNode); return Leaf.Position->Value; }
353 
354  AnimationNode* GetLeftChild() { assert(Type == LinearInterpolationNode); return LinearInterpolation.ChildLeft; }
355  AnimationNode* GetRightChild() { assert(Type == LinearInterpolationNode); return LinearInterpolation.ChildRight; }
356  ValueProvider* GetWeightProvider() { assert(Type == LinearInterpolationNode); return LinearInterpolation.Weight; }
357  C4Real GetWeight() const { assert(Type == LinearInterpolationNode); return LinearInterpolation.Weight->Value; }
358 
359  void CompileFunc(StdCompiler* pComp, const StdMesh *Mesh);
360  void DenumeratePointers();
361  void ClearPointers(class C4Object* pObj);
362 
363 protected:
364  int Slot;
365  unsigned int Number;
366  NodeType Type{LeafNode};
367  AnimationNode* Parent{nullptr}; // NoSave
368 
369  union
370  {
371  struct
372  {
373  const StdMeshAnimation* Animation;
374  ValueProvider* Position;
375  } Leaf;
376 
377  struct
378  {
379  unsigned int BoneIndex;
380  StdMeshTransformation* Transformation;
381  } Custom;
382 
383  struct
384  {
385  AnimationNode* ChildLeft;
386  AnimationNode* ChildRight;
387  ValueProvider* Weight;
388  } LinearInterpolation;
389  };
390 };
391 
392 
394 {
395  friend class StdMeshMaterialUpdate;
397  friend class StdMeshUpdate;
398 public:
400  StdMeshInstance(const StdMesh& mesh, float completion = 1.0f);
401  ~StdMeshInstance();
402 
404 
406  AM_None = 0,
407  AM_DrawBefore = 1 << 0,
408  AM_MatchSkeleton = 1 << 1
409  };
410 
412 
413  // Serializable value providers need to be registered with SerializeableValueProvider::Register.
414  // They also need to implement a default constructor and a compile func
415  class SerializableValueProvider: public ValueProvider
416  {
417  public:
418  struct IDBase;
419 
420  private:
421  // Pointer for deterministic initialization
422  static std::vector<IDBase*>* IDs;
423 
424  public:
425  struct IDBase
426  {
427  typedef SerializableValueProvider*(*NewFunc)();
428  protected:
429  IDBase(const char* name, const std::type_info& type, NewFunc newfunc):
430  name(name), type(type), newfunc(newfunc)
431  {
432  if(!IDs) IDs = new std::vector<IDBase*>;
433  IDs->push_back(this);
434  }
435 
436  virtual ~IDBase()
437  {
438  assert(IDs);
439  IDs->erase(std::find(IDs->begin(), IDs->end(), this));
440  if (!IDs->size()) { delete IDs; IDs = nullptr; }
441  }
442 
443  public:
444  const char* name;
445  const std::type_info& type;
446  NewFunc newfunc;
447  };
448 
449  template<typename T>
450  struct ID: IDBase
451  {
452  private:
453  static SerializableValueProvider* CreateFunc() { return new T; }
454 
455  public:
456  ID(const char* name):
457  IDBase(name, typeid(T), CreateFunc) {}
458  };
459 
460  static const IDBase* Lookup(const char* name)
461  {
462  if(!IDs) return nullptr;
463  for(auto & ID : *IDs)
464  if(strcmp(ID->name, name) == 0)
465  return ID;
466  return nullptr;
467  }
468 
469  static const IDBase* Lookup(const std::type_info& type)
470  {
471  if(!IDs) return nullptr;
472  for(auto & ID : *IDs)
473  if(ID->type == type)
474  return ID;
475  return nullptr;
476  }
477 
478  virtual void CompileFunc(StdCompiler* pComp);
479  virtual void DenumeratePointers() {}
480  virtual void ClearPointers(class C4Object* pObj) {}
481  };
482 
484  {
485  friend class StdMeshInstance;
486  friend class StdMeshUpdate;
487  public:
488  // The job of this class is to help serialize the Child and OwnChild members of AttachedMesh
490  {
491  public:
492  virtual ~Denumerator() = default;
493 
494  virtual void CompileFunc(StdCompiler* pComp, AttachedMesh* attach) = 0;
495  virtual void DenumeratePointers(AttachedMesh* attach) {}
496  virtual bool ClearPointers(class C4Object* pObj) { return true; }
497  };
498 
499  typedef Denumerator*(*DenumeratorFactoryFunc)();
500 
501  template<typename T>
502  static Denumerator* DenumeratorFactory() { return new T; }
503 
504  AttachedMesh();
505  AttachedMesh(unsigned int number, StdMeshInstance* parent, StdMeshInstance* child, bool own_child, Denumerator* denumerator,
506  unsigned int parent_bone, unsigned int child_bone, const StdMeshMatrix& transform, uint32_t flags);
507  ~AttachedMesh();
508 
509  uint32_t Number{0};
510  StdMeshInstance* Parent{nullptr}; // NoSave (set by parent)
511  StdMeshInstance* Child{nullptr};
512  bool OwnChild{true}; // NoSave
513  Denumerator* ChildDenumerator{nullptr};
514 
515  bool SetParentBone(const StdStrBuf& bone);
516  bool SetChildBone(const StdStrBuf& bone);
517  void SetAttachTransformation(const StdMeshMatrix& transformation);
518  const StdMeshMatrix& GetFinalTransformation() const { return FinalTrans; }
519  uint32_t GetFlags() const { return Flags; }
520 
521  void CompileFunc(StdCompiler* pComp, DenumeratorFactoryFunc Factory);
522  void DenumeratePointers();
523  bool ClearPointers(class C4Object* pObj);
524 
525  unsigned int GetParentBone() const { return ParentBone; }
526  unsigned int GetChildBone() const { return ChildBone; }
527 
528  private:
529  unsigned int ParentBone{0};
530  unsigned int ChildBone{0};
531  StdMeshMatrix AttachTrans;
532  uint32_t Flags;
533 
534  // Cache final attach transformation, updated in UpdateBoneTransform
535  StdMeshMatrix FinalTrans; // NoSave
536  bool FinalTransformDirty{false}; // NoSave; Whether FinalTrans is up to date or not
537 
538  std::vector<int> MatchedBoneInParentSkeleton; // Only filled if AM_MatchSkeleton is set
539 
540  void MapBonesOfChildToParent(const StdMeshSkeleton& parent_skeleton, const StdMeshSkeleton& child_skeleton);
541  };
542 
543  typedef std::vector<AttachedMesh*> AttachedMeshList;
544  typedef AttachedMeshList::const_iterator AttachedMeshIter;
545 
546  void SetFaceOrdering(FaceOrdering ordering);
547  void SetFaceOrderingForClrModulation(uint32_t clrmod);
548 
549  const std::vector<StdMeshVertex>& GetSharedVertices() const { return Mesh->GetSharedVertices(); }
550  size_t GetNumSharedVertices() const { return GetSharedVertices().size(); }
551 
552  // Set completion of the mesh. For incompleted meshes not all faces will be available.
553  void SetCompletion(float completion);
554  float GetCompletion() const { return Completion; }
555 
556  AnimationNode* PlayAnimation(const StdStrBuf& animation_name, int slot, AnimationNode* sibling, ValueProvider* position, ValueProvider* weight, bool stop_previous_animation);
557  AnimationNode* PlayAnimation(const StdMeshAnimation& animation, int slot, AnimationNode* sibling, ValueProvider* position, ValueProvider* weight, bool stop_previous_animation);
558  AnimationNode* PlayAnimation(const StdMeshBone* bone, const StdMeshTransformation& trans, int slot, AnimationNode* sibling, ValueProvider* weight, bool stop_previous_animation);
559  void StopAnimation(AnimationNode* node);
560 
561  AnimationNode* GetAnimationNodeByNumber(unsigned int number);
562  AnimationNode* GetRootAnimationForSlot(int slot);
563  // child bone transforms are dirty (saves matrix inversion for unanimated attach children).
564  // Set new value providers for a node's position or weight - cannot be in
565  // class AnimationNode since we need to mark BoneTransforms dirty.
566  void SetAnimationPosition(AnimationNode* node, ValueProvider* position);
567  void SetAnimationBoneTransform(AnimationNode* node, const StdMeshTransformation& trans);
568  void SetAnimationWeight(AnimationNode* node, ValueProvider* weight);
569 
570  // Update animations; call once a frame
571  // dt is used for texture animation, skeleton animation is updated via value providers
572  void ExecuteAnimation(float dt);
573 
574  // Create a new instance and attach it to this mesh. Takes ownership of denumerator
575  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);
576  // Attach an instance to this instance. Takes ownership of denumerator. If own_child is true deletes instance on detach.
577  AttachedMesh* 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);
578  // Removes attachment with given number
579  bool DetachMesh(unsigned int number);
580  // Returns attached mesh with given number
581  AttachedMesh* GetAttachedMeshByNumber(unsigned int number) const;
582 
583  // To iterate through attachments
584  AttachedMeshIter AttachedMeshesBegin() const { return AttachChildren.begin(); }
585  AttachedMeshIter AttachedMeshesEnd() const { return AttachChildren.end(); }
586  AttachedMesh* GetAttachParent() const { return AttachParent; }
587 
588  size_t GetNumSubMeshes() const { return SubMeshInstances.size(); }
589  StdSubMeshInstance& GetSubMesh(size_t i) { return *SubMeshInstances[i]; }
590  const StdSubMeshInstance& GetSubMesh(size_t i) const { return *SubMeshInstances[i]; }
591  const StdSubMeshInstance& GetSubMeshOrdered(size_t i) const { return *SubMeshInstancesOrdered[i]; }
592 
593  // Set material of submesh i.
594  void SetMaterial(size_t i, const StdMeshMaterial& material);
595 
596  const StdMeshMatrix& GetBoneTransform(size_t i) const;
597  size_t GetBoneCount() const;
598 
599  // Update bone transformation matrices, vertex positions and final attach transformations of attached children.
600  // This is called recursively for attached children, so there is no need to call it on attached children only
601  // which would also not update its attach transformation. Call this once before rendering. Returns true if the
602  // mesh was deformed since the last execution, or false otherwise.
603  bool UpdateBoneTransforms();
604 
605  // Orders faces according to current face ordering. Clal this once before rendering if one of the following is true:
606  //
607  // a) the call to UpdateBoneTransforms returns true
608  // b) a submesh's material was changed
609  // c) the global transformation changed since previous call to ReorderFaces()
610  // d) some other obscure state change occurred (?)
611  //
612  // global_trans is a global transformation that is applied when rendering the mesh, and this is used
613  // to correctly do face ordering.
614  //
615  // TODO: Should maybe introduce a FaceOrderingDirty flag
616  void ReorderFaces(StdMeshMatrix* global_trans);
617 
618  void CompileFunc(StdCompiler* pComp, AttachedMesh::DenumeratorFactoryFunc Factory);
619  void DenumeratePointers();
620  void ClearPointers(class C4Object* pObj);
621 
622  const StdMesh& GetMesh() const { return *Mesh; }
623 
624 #ifndef USE_CONSOLE
625  GLuint GetIBO() const { return ibo ? ibo : Mesh->GetIBO(); }
626  unsigned int GetVAOID() const { return vaoid ? vaoid : Mesh->GetVAOID(); }
627 #endif
628 
629 protected:
630 #ifndef USE_CONSOLE
631  void UpdateIBO();
632 #endif
633 
634  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);
635 
636  template<typename IteratorType, typename FuncObj>
637  static bool ScanAttachTree(IteratorType begin, IteratorType end, const FuncObj& obj);
638 
639  typedef std::vector<AnimationNode*> AnimationNodeList;
640 
641  AnimationNodeList::iterator GetStackIterForSlot(int slot, bool create);
642  void InsertAnimationNode(AnimationNode* node, int slot, AnimationNode* sibling, ValueProvider* weight, bool stop_previous_animation);
643  bool ExecuteAnimationNode(AnimationNode* node);
644  void ApplyBoneTransformToVertices(const std::vector<StdSubMesh::Vertex>& mesh_vertices, std::vector<StdMeshVertex>& instance_vertices);
645  void SetBoneTransformsDirty(bool value);
646 
647  const StdMesh *Mesh;
648 
649  float Completion; // NoSave
650 
651  AnimationNodeList AnimationNodes; // for simple lookup of animation nodes by their unique number
652  AnimationNodeList AnimationStack; // contains top level nodes only, ordered by slot number
653  std::vector<StdMeshMatrix> BoneTransforms;
654 
655  std::vector<StdSubMeshInstance*> SubMeshInstances;
656  std::vector<StdSubMeshInstance*> SubMeshInstancesOrdered; // ordered by opacity, in case materials were changed
657 
658  // Not asymptotically efficient, but we do not expect many attached meshes anyway.
659  // In theory map would fit better, but it's probably not worth the extra overhead.
660  std::vector<AttachedMesh*> AttachChildren;
662 
664 
665 #ifndef USE_CONSOLE
666  // private instance index buffer, and a VAO that is bound to it
667  // instead of the mesh's. We use a private IBO when we use custom
668  // face ordering. Otherwise, when we use the default face ordering,
669  // these members are 0 and we use the mesh's IBO and VAO instead.
670  GLuint ibo;
671  unsigned int vaoid;
672 #endif
673 private:
674  StdMeshInstance(const StdMeshInstance& other) = delete;
675  StdMeshInstance& operator=(const StdMeshInstance& other) = delete;
676 };
677 
679 {
680  std::unique_ptr<StdMeshInstance::SerializableValueProvider> temp(rID.newfunc());
681  pComp->Value(*temp);
682  pStruct = temp.release();
683 }
684 
685 #endif
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:301
float y2
Definition: StdMesh.h:147
const StdMeshFace * GetFaces() const
Definition: StdMesh.h:263
std::vector< StdSubMeshInstance * > SubMeshInstancesOrdered
Definition: StdMesh.h:656
float GetBoundingRadius() const
Definition: StdMesh.h:207
const StdMeshMaterial & GetMaterial() const
Definition: StdMesh.h:170
AnimationNodeList AnimationStack
Definition: StdMesh.h:652
StdMeshInstanceValueProvider ValueProvider
Definition: StdMesh.h:411
const StdSubMesh & GetSubMesh() const
Definition: StdMesh.h:265
unsigned int GetChildBone() const
Definition: StdMesh.h:526
size_t GetNumFaces() const
Definition: StdMesh.h:264
int ID
Definition: StdMesh.h:33
AttachedMesh * GetAttachParent() const
Definition: StdMesh.h:586
bool BoneTransformsDirty
Definition: StdMesh.h:663
const StdMeshMaterial * Material
Definition: StdMesh.h:282
virtual bool ClearPointers(class C4Object *pObj)
Definition: StdMesh.h:496
const StdMeshMaterial & GetMaterial() const
Definition: StdMesh.h:270
static Denumerator * DenumeratorFactory()
Definition: StdMesh.h:502
NodeType GetType() const
Definition: StdMesh.h:347
const StdSubMeshInstance & GetSubMeshOrdered(size_t i) const
Definition: StdMesh.h:591
const std::vector< StdMeshVertex > & GetSharedVertices() const
Definition: StdMesh.h:549
std::vector< AttachedMesh * > AttachedMeshList
Definition: StdMesh.h:543
unsigned int vaoid
Definition: StdMesh.h:671
GLuint ibo
Definition: StdMesh.h:670
float x2
Definition: StdMesh.h:147
size_t GetNumFaces() const
Definition: StdMesh.h:168
StdCopyStrBuf Name
Definition: StdMesh.h:97
float z1
Definition: StdMesh.h:146
StdMeshTransformation Transformation
Definition: StdMesh.h:37
std::vector< TexUnit > TexUnits
Definition: StdMesh.h:297
void PostInit()
Definition: StdMesh.cpp:505
friend class StdMeshXML
Definition: StdMesh.h:108
virtual void DenumeratePointers(AttachedMesh *attach)
Definition: StdMesh.h:495
GLuint GetVBO() const
Definition: StdMesh.h:212
const StdMeshSkeleton & GetSkeleton() const
Definition: StdMesh.h:203
ValueProvider * GetWeightProvider()
Definition: StdMesh.h:356
float z2
Definition: StdMesh.h:147
unsigned int GetParentBone() const
Definition: StdMesh.h:525
unsigned int GetVAOID() const
Definition: StdMesh.h:626
StdMeshAnimation()=default
size_t GetNumSubMeshes() const
Definition: StdMesh.h:588
size_t GetNumSubMeshes() const
Definition: StdMesh.h:199
unsigned int Vertices[3]
Definition: StdMesh.h:61
StdSubMeshInstance & GetSubMesh(size_t i)
Definition: StdMesh.h:589
Definition: C4Real.h:58
void MirrorAnimation(const StdMeshAnimation &animation)
Definition: StdMesh.cpp:413
const Vertex & GetVertex(size_t i) const
Definition: StdMesh.h:164
StdMeshVector GetCenter() const
Definition: StdMesh.h:149
GLuint GetIBO() const
Definition: StdMesh.h:213
void InsertAnimation(const StdMeshAnimation &animation)
Definition: StdMesh.cpp:471
unsigned int GetNumber() const
Definition: StdMesh.h:346
StdSubMeshInstance::FaceOrdering FaceOrdering
Definition: StdMesh.h:403
const StdMeshFace & GetFace(size_t i) const
Definition: StdMesh.h:167
AttachedMeshIter AttachedMeshesBegin() const
Definition: StdMesh.h:584
C4Real GetWeight() const
Definition: StdMesh.h:357
const StdMeshBone & GetBone(size_t i) const
Definition: StdMesh.h:116
bool IsAnimated() const
Definition: StdMesh.h:121
StdMeshBone()=default
ValueProvider * GetPositionProvider()
Definition: StdMesh.h:351
AnimationNode * GetRightChild()
Definition: StdMesh.h:355
float y1
Definition: StdMesh.h:146
size_t GetNumVertices() const
Definition: StdMesh.h:165
static const IDBase * Lookup(const std::type_info &type)
Definition: StdMesh.h:469
virtual void ClearPointers(class C4Object *pObj)
Definition: StdMesh.h:480
std::vector< Pass > PassData
Definition: StdMesh.h:300
const StdSubMesh * base
Definition: StdMesh.h:278
const std::vector< Vertex > & GetSharedVertices() const
Definition: StdMesh.h:201
const StdMeshAnimation * GetAnimationByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:396
const StdSubMesh & GetSubMesh(size_t i) const
Definition: StdMesh.h:198
size_t GetOffsetInIBO() const
Definition: StdMesh.h:174
GLuint GetIBO() const
Definition: StdMesh.h:625
AnimationNode * GetParent()
Definition: StdMesh.h:348
uint32_t GetFlags() const
Definition: StdMesh.h:519
const StdMesh * Mesh
Definition: StdMesh.h:647
void Value(const T &rStruct)
Definition: StdCompiler.h:161
std::vector< AnimationNode * > AnimationNodeList
Definition: StdMesh.h:639
StdMeshSkeleton & GetSkeleton()
Definition: StdMesh.h:204
FaceOrdering GetFaceOrdering() const
Definition: StdMesh.h:272
StdMeshInstanceValueProvider ValueProvider
Definition: StdMesh.h:334
void SetLabel(const std::string &label)
Definition: StdMesh.h:217
AttachedMeshList::const_iterator AttachedMeshIter
Definition: StdMesh.h:544
unsigned int BoneIndex
Definition: StdMesh.h:54
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:399
const StdMeshBone * GetBoneByName(const StdStrBuf &name) const
Definition: StdMesh.cpp:386
const std::vector< Vertex > & GetVertices() const
Definition: StdMesh.h:163
float GetCompletion() const
Definition: StdMesh.h:554
IDBase(const char *name, const std::type_info &type, NewFunc newfunc)
Definition: StdMesh.h:429
unsigned int GetVAOID() const
Definition: StdMesh.h:214
float Completion
Definition: StdMesh.h:649
size_t GetNumSharedVertices() const
Definition: StdMesh.h:550
std::vector< const StdMeshAnimation * > GetAnimations() const
Definition: StdMesh.cpp:404
StdCopyStrBuf Name
Definition: StdMesh.h:34
const StdSubMeshInstance & GetSubMesh(size_t i) const
Definition: StdMesh.h:590
AttachedMesh * AttachParent
Definition: StdMesh.h:661
double GetTexturePosition(size_t pass, size_t texunit) const
Definition: StdMesh.h:268
StdMeshTransformation GetTransformAt(float time, float length) const
Definition: StdMesh.cpp:289
void CompileNewFuncCtx(StdMeshInstance::SerializableValueProvider *&pStruct, StdCompiler *pComp, const StdMeshInstance::SerializableValueProvider::IDBase &rID)
Definition: StdMesh.h:678
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:280
float x1
Definition: StdMesh.h:146
StdMeshTransformation InverseTransformation
Definition: StdMesh.h:39
unsigned int Index
Definition: StdMesh.h:32
std::vector< StdMeshMatrix > BoneTransforms
Definition: StdMesh.h:653
size_t GetOffsetInVBO() const
Definition: StdMesh.h:173
C4Real GetPosition() const
Definition: StdMesh.h:352
const StdMeshAnimation * GetAnimation() const
Definition: StdMesh.h:350
AnimationNodeList AnimationNodes
Definition: StdMesh.h:651
AnimationNode * GetLeftChild()
Definition: StdMesh.h:354
StdSubMesh::Vertex Vertex
Definition: StdMesh.h:196
StdMeshInstanceAnimationNode AnimationNode
Definition: StdMesh.h:333
StdMeshAnimation & operator=(const StdMeshAnimation &other)
Definition: StdMesh.cpp:351
const StdMeshMatrix & GetFinalTransformation() const
Definition: StdMesh.h:518
std::vector< AttachedMesh * > AttachChildren
Definition: StdMesh.h:660
friend class StdMeshXML
Definition: StdMesh.h:28
const StdMesh & GetMesh() const
Definition: StdMesh.h:622
StdMeshVertex Vertex
Definition: StdMesh.h:161
unsigned int GetTexturePhase(size_t pass, size_t texunit) const
Definition: StdMesh.h:267
float Length
Definition: StdMesh.h:98
std::vector< int > GetMatchingBones(const StdMeshSkeleton &skeleton) const
Definition: StdMesh.cpp:519
static const IDBase * Lookup(const char *name)
Definition: StdMesh.h:460
const StdMeshBox & GetBoundingBox() const
Definition: StdMesh.h:206
size_t GetNumBones() const
Definition: StdMesh.h:117
void CompileFunc(C4Real &rValue, StdCompiler *pComp)
Definition: C4Real.cpp:9033
StdMeshTransformation Transformation
Definition: StdMesh.h:68
const C4Real Fix0
Definition: C4Real.h:312
const StdMeshBone * GetParent() const
Definition: StdMesh.h:41
std::vector< StdSubMeshInstance * > SubMeshInstances
Definition: StdMesh.h:655
AttachedMeshIter AttachedMeshesEnd() const
Definition: StdMesh.h:585