BsMorphShapes.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Animation/BsMorphShapes.h"
  4. #include "RTTI/BsMorphShapesRTTI.h"
  5. namespace bs
  6. {
  7. MorphShape::MorphShape()
  8. { }
  9. MorphShape::MorphShape(const String& name, float weight, const Vector<MorphVertex>& vertices)
  10. :mName(name), mWeight(weight), mVertices(vertices)
  11. { }
  12. /** Creates a new morph shape from the provided set of vertices. */
  13. SPtr<MorphShape> MorphShape::create(const String& name, float weight, const Vector<MorphVertex>& vertices)
  14. {
  15. return bs_shared_ptr_new<MorphShape>(name, weight, vertices);
  16. }
  17. RTTITypeBase* MorphShape::getRTTIStatic()
  18. {
  19. return MorphShapeRTTI::instance();
  20. }
  21. RTTITypeBase* MorphShape::getRTTI() const
  22. {
  23. return getRTTIStatic();
  24. }
  25. MorphChannel::MorphChannel()
  26. { }
  27. MorphChannel::MorphChannel(const String& name, const Vector<SPtr<MorphShape>>& shapes)
  28. :mName(name), mShapes(shapes)
  29. {
  30. std::sort(mShapes.begin(), mShapes.end(),
  31. [](auto& x, auto& y)
  32. {
  33. return x->getWeight() < y->getWeight();
  34. });
  35. }
  36. SPtr<MorphChannel> MorphChannel::create(const String& name, const Vector<SPtr<MorphShape>>& shapes)
  37. {
  38. MorphChannel* raw = new (bs_alloc<MorphChannel>()) MorphChannel(name, shapes);
  39. return bs_shared_ptr(raw);
  40. }
  41. SPtr<MorphChannel> MorphChannel::createEmpty()
  42. {
  43. MorphChannel* raw = new (bs_alloc<MorphChannel>()) MorphChannel();
  44. return bs_shared_ptr(raw);
  45. }
  46. RTTITypeBase* MorphChannel::getRTTIStatic()
  47. {
  48. return MorphChannelRTTI::instance();
  49. }
  50. RTTITypeBase* MorphChannel::getRTTI() const
  51. {
  52. return getRTTIStatic();
  53. }
  54. MorphShapes::MorphShapes()
  55. { }
  56. MorphShapes::MorphShapes(const Vector<SPtr<MorphChannel>>& channels, UINT32 numVertices)
  57. :mChannels(channels), mNumVertices(numVertices)
  58. {
  59. }
  60. SPtr<MorphShapes> MorphShapes::create(const Vector<SPtr<MorphChannel>>& channels, UINT32 numVertices)
  61. {
  62. MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes(channels, numVertices);
  63. return bs_shared_ptr(raw);
  64. }
  65. SPtr<MorphShapes> MorphShapes::createEmpty()
  66. {
  67. MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes();
  68. return bs_shared_ptr(raw);
  69. }
  70. RTTITypeBase* MorphShapes::getRTTIStatic()
  71. {
  72. return MorphShapesRTTI::instance();
  73. }
  74. RTTITypeBase* MorphShapes::getRTTI() const
  75. {
  76. return getRTTIStatic();
  77. }
  78. }