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