BsMorphShapes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsVector3.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Animation-Internal
  10. * @{
  11. */
  12. /** A single vertex used for morph target animation. Contains a difference between base and target shape. */
  13. struct BS_CORE_EXPORT MorphVertex
  14. {
  15. MorphVertex() { }
  16. MorphVertex(const Vector3& deltaPosition, const Vector3& deltaNormal, UINT32 sourceIdx)
  17. :deltaPosition(deltaPosition), deltaNormal(deltaNormal), sourceIdx(sourceIdx)
  18. { }
  19. Vector3 deltaPosition;
  20. Vector3 deltaNormal;
  21. UINT32 sourceIdx;
  22. };
  23. /**
  24. * A set of vertices representing a single shape in a morph target animation. Vertices are represented as a difference
  25. * between base and target shape.
  26. */
  27. class BS_CORE_EXPORT MorphShape : public IReflectable
  28. {
  29. public:
  30. MorphShape(const String& name, const Vector<MorphVertex>& vertices);
  31. /** Returns the name of the shape. */
  32. const String& getName() const { return mName; }
  33. /** Returns a reference to all of the shape's vertices. Contains only vertices that differ from the base. */
  34. const Vector<MorphVertex>& getVertices() const { return mVertices; }
  35. /** Creates a new morph shape from the provided set of vertices. */
  36. static SPtr<MorphShape> create(const String& name, const Vector<MorphVertex>& vertices);
  37. private:
  38. String mName;
  39. Vector<MorphVertex> mVertices;
  40. /************************************************************************/
  41. /* SERIALIZATION */
  42. /************************************************************************/
  43. public:
  44. friend class MorphShapeRTTI;
  45. static RTTITypeBase* getRTTIStatic();
  46. RTTITypeBase* getRTTI() const override;
  47. MorphShape(); // Serialization only
  48. };
  49. /**
  50. * Contains a set of morph shapes, used for morph target animation. Each morph shape contains a single possible shape
  51. * that can be added on top of the base shape in order to create the animation.
  52. */
  53. class BS_CORE_EXPORT MorphShapes : public IReflectable // Note: Must be immutable in order to be usable on multiple threads
  54. {
  55. public:
  56. /** Returns the number of available morph shapes. */
  57. UINT32 getNumShapes() const { return (UINT32)mShapes.size(); }
  58. /** Returns the morph shape at the specified index. */
  59. SPtr<MorphShape> getShape(UINT32 idx) const { return mShapes[idx]; }
  60. /** Returns the number of vertices per morph shape. */
  61. UINT32 getNumVertices() const { return mNumVertices; }
  62. /** Creates a new set of morph shapes. */
  63. static SPtr<MorphShapes> create(const Vector<SPtr<MorphShape>>& shapes, UINT32 numVertices);
  64. private:
  65. MorphShapes();
  66. MorphShapes(const Vector<SPtr<MorphShape>>& shapes, UINT32 numVertices);
  67. Vector<SPtr<MorphShape>> mShapes;
  68. UINT32 mNumVertices;
  69. /************************************************************************/
  70. /* SERIALIZATION */
  71. /************************************************************************/
  72. public:
  73. friend class MorphShapesRTTI;
  74. static RTTITypeBase* getRTTIStatic();
  75. RTTITypeBase* getRTTI() const override;
  76. /**
  77. * Creates MorphShapes with no data. You must populate its data manually.
  78. *
  79. * @note For serialization use only.
  80. */
  81. static SPtr<MorphShapes> createEmpty();
  82. };
  83. /** @} */
  84. }