Merge "Add log for font load validation" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / blend-shape-details.cpp
1
2 /*
3 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 // FILE HEADER
20 #include <dali-scene3d/public-api/loader/blend-shape-details.h>
21
22 // EXTERNAL INCLUDES
23 #include <dali/public-api/animation/constraints.h>
24 #include <dali/public-api/object/property.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-scene3d/public-api/loader/resource-bundle.h>
28
29 namespace Dali
30 {
31 namespace Scene3D
32 {
33 namespace Loader
34 {
35 const std::string BlendShapes::NUMBER_OF_BLEND_SHAPES("uNumberOfBlendShapes");
36 const std::string BlendShapes::UNNORMALIZE_FACTOR("uBlendShapeUnnormalizeFactor");
37 const std::string BlendShapes::COMPONENT_SIZE("uBlendShapeComponentSize");
38
39 const std::string BlendShapes::COMPONENTS("blendShapeComponents");
40
41 const std::string BlendShapes::WEIGHTS_UNIFORM("uBlendShapeWeight");
42
43 void BlendShapes::ConfigureProperties(const std::pair<MeshDefinition, MeshGeometry>& mesh, Shader shader, Actor actor)
44 {
45   unsigned int index = 0u;
46
47   char        weightNameBuffer[32];
48   char        unnormalizeFactorNameBuffer[64];
49   char* const pWeightName = weightNameBuffer + snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s", WEIGHTS_UNIFORM.c_str());
50   char* const pFactorName = unnormalizeFactorNameBuffer + snprintf(unnormalizeFactorNameBuffer, sizeof(unnormalizeFactorNameBuffer), "%s", UNNORMALIZE_FACTOR.c_str());
51   for(const auto& blendShape : mesh.first.mBlendShapes)
52   {
53     snprintf(pWeightName, sizeof(weightNameBuffer) - (pWeightName - weightNameBuffer), "[%d]", index);
54     std::string weightName{weightNameBuffer};
55     actor.RegisterProperty(weightName, blendShape.weight);
56
57     if(shader && mesh.first.mBlendShapeVersion == Version::VERSION_1_0)
58     {
59       snprintf(pFactorName, sizeof(unnormalizeFactorNameBuffer) - (pFactorName - unnormalizeFactorNameBuffer), "[%d]", index);
60       std::string factorName{unnormalizeFactorNameBuffer};
61       shader.RegisterProperty(factorName, mesh.second.blendShapeUnnormalizeFactor[index]);
62     }
63
64     ++index;
65   }
66
67   if(shader)
68   {
69     if(Version::VERSION_2_0 == mesh.first.mBlendShapeVersion)
70     {
71       shader.RegisterProperty(UNNORMALIZE_FACTOR, mesh.second.blendShapeUnnormalizeFactor[0u]);
72     }
73
74     shader.RegisterProperty(NUMBER_OF_BLEND_SHAPES, Property::Value(static_cast<float>(index)));
75     shader.RegisterProperty(COMPONENT_SIZE, Property::Value(static_cast<float>(mesh.second.blendShapeBufferOffset)));
76
77     // Create a read only property to preserve the components of the blend shape.
78     int32_t components = 0x0;
79     for(auto& bs : mesh.first.mBlendShapes)
80     {
81       components |= (bs.deltas.IsDefined() * Component::POSITIONS) |
82                     (bs.normals.IsDefined() * Component::NORMALS) | (bs.tangents.IsDefined() * Component::TANGENTS);
83     }
84     shader.RegisterProperty(COMPONENTS, components, Property::AccessMode::READ_ONLY);
85   }
86 }
87
88 } // namespace Loader
89 } // namespace Scene3D
90 } // namespace Dali