1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Animation/BsMorphShapes.h"
4#include "Private/RTTI/BsMorphShapesRTTI.h"
5
6namespace bs
7{
8 MorphShape::MorphShape(const String& name, float weight, const Vector<MorphVertex>& vertices)
9 :mName(name), mWeight(weight), mVertices(vertices)
10 { }
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
18 RTTITypeBase* MorphShape::getRTTIStatic()
19 {
20 return MorphShapeRTTI::instance();
21 }
22
23 RTTITypeBase* MorphShape::getRTTI() const
24 {
25 return getRTTIStatic();
26 }
27
28 MorphChannel::MorphChannel(const String& name, const Vector<SPtr<MorphShape>>& shapes)
29 :mName(name), mShapes(shapes)
30 {
31 std::sort(mShapes.begin(), mShapes.end(),
32 [](auto& x, auto& y)
33 {
34 return x->getWeight() < y->getWeight();
35 });
36 }
37
38 SPtr<MorphChannel> MorphChannel::create(const String& name, const Vector<SPtr<MorphShape>>& shapes)
39 {
40 MorphChannel* raw = new (bs_alloc<MorphChannel>()) MorphChannel(name, shapes);
41 return bs_shared_ptr(raw);
42 }
43
44 SPtr<MorphChannel> MorphChannel::createEmpty()
45 {
46 MorphChannel* raw = new (bs_alloc<MorphChannel>()) MorphChannel();
47 return bs_shared_ptr(raw);
48 }
49
50 RTTITypeBase* MorphChannel::getRTTIStatic()
51 {
52 return MorphChannelRTTI::instance();
53 }
54
55 RTTITypeBase* MorphChannel::getRTTI() const
56 {
57 return getRTTIStatic();
58 }
59
60 MorphShapes::MorphShapes(const Vector<SPtr<MorphChannel>>& channels, UINT32 numVertices)
61 :mChannels(channels), mNumVertices(numVertices)
62 {
63
64 }
65
66 SPtr<MorphShapes> MorphShapes::create(const Vector<SPtr<MorphChannel>>& channels, UINT32 numVertices)
67 {
68 MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes(channels, numVertices);
69 return bs_shared_ptr(raw);
70 }
71
72 SPtr<MorphShapes> MorphShapes::createEmpty()
73 {
74 MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes();
75 return bs_shared_ptr(raw);
76 }
77
78 RTTITypeBase* MorphShapes::getRTTIStatic()
79 {
80 return MorphShapesRTTI::instance();
81 }
82
83 RTTITypeBase* MorphShapes::getRTTI() const
84 {
85 return getRTTIStatic();
86 }
87}