[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / model-motion / motion-index / blend-shape-index-impl.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-scene3d/internal/model-motion/motion-index/blend-shape-index-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/loader/blend-shape-details.h> ///< For BlendShapes::WEIGHTS_UNIFORM
27
28 namespace Dali
29 {
30 namespace Scene3D
31 {
32 namespace Internal
33 {
34 namespace
35 {
36 /**
37  * Creates control through type registry
38  */
39 BaseHandle Create()
40 {
41   return Scene3D::BlendShapeIndex::New();
42 }
43
44 // Setup properties, signals and actions using the type-registry.
45 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::BlendShapeIndex, Dali::BaseHandle, Create);
46 DALI_TYPE_REGISTRATION_END()
47
48 std::string GetBlendShapePropertyNameFromIndex(int index)
49 {
50   if(index >= 0)
51   {
52     char weightNameBuffer[32];
53
54     // Get return value of snprintf to avoid SVACE.
55     [[maybe_unused]] auto prefixSize = snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s[%d]", Loader::BlendShapes::WEIGHTS_UNIFORM, index);
56
57     return weightNameBuffer;
58   }
59   return "";
60 }
61
62 } // namespace
63
64 BlendShapeIndexPtr BlendShapeIndex::New()
65 {
66   BlendShapeIndexPtr blendShapeIndex = new BlendShapeIndex();
67
68   blendShapeIndex->Initialize();
69
70   return blendShapeIndex;
71 }
72
73 BlendShapeIndex::BlendShapeIndex()
74 {
75 }
76
77 BlendShapeIndex::~BlendShapeIndex()
78 {
79 }
80
81 void BlendShapeIndex::Initialize()
82 {
83 }
84
85 void BlendShapeIndex::SetBlendShapeId(Property::Key blendShapeId)
86 {
87   mBlendShapeId = blendShapeId;
88 }
89
90 Property::Key BlendShapeIndex::GetBlendShapeId() const
91 {
92   return mBlendShapeId;
93 }
94
95 std::string BlendShapeIndex::GetPropertyName(Scene3D::ModelNode node)
96 {
97   if(mBlendShapeId.type == Property::Key::Type::INDEX)
98   {
99     if(mBlendShapeId.indexKey != Property::INVALID_INDEX)
100     {
101       return GetBlendShapePropertyNameFromIndex(mBlendShapeId.indexKey);
102     }
103   }
104   else if(mBlendShapeId.type == Property::Key::Type::STRING)
105   {
106     if(node)
107     {
108       auto index = node.GetBlendShapeIndexByName(mBlendShapeId.stringKey);
109       if(index != Scene3D::Loader::BlendShapes::INVALID_INDEX)
110       {
111         return GetBlendShapePropertyNameFromIndex(index);
112       }
113     }
114   }
115   return "";
116 }
117
118 Property::Index BlendShapeIndex::GetPropertyIndex(Scene3D::ModelNode node)
119 {
120   // Not surport now
121   return Property::INVALID_INDEX;
122 }
123
124 } // namespace Internal
125
126 } // namespace Scene3D
127
128 } // namespace Dali