3 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "dali-scene-loader/public-api/blend-shape-details.h"
23 #include "dali/public-api/animation/constraints.h"
24 #include "dali/public-api/object/property.h"
27 #include "dali-scene-loader/public-api/resource-bundle.h"
34 const std::string BlendShapes::NUMBER_OF_BLEND_SHAPES("uNumberOfBlendShapes");
35 const std::string BlendShapes::UNNORMALIZE_FACTOR("uBlendShapeUnnormalizeFactor");
36 const std::string BlendShapes::COMPONENT_SIZE("uBlendShapeComponentSize");
38 const std::string BlendShapes::COMPONENTS("blendShapeComponents");
40 const std::string BlendShapes::WEIGHTS_UNIFORM("uBlendShapeWeight");
42 void BlendShapes::ConfigureProperties(const std::pair<MeshDefinition, MeshGeometry>& mesh, Shader shader, Actor actor)
44 unsigned int index = 0u;
46 char weightNameBuffer[32];
47 char unnormalizeFactorNameBuffer[64];
48 char* const pWeightName = weightNameBuffer + snprintf(weightNameBuffer, sizeof(weightNameBuffer), "%s", WEIGHTS_UNIFORM.c_str());
49 char* const pFactorName = unnormalizeFactorNameBuffer + snprintf(unnormalizeFactorNameBuffer, sizeof(unnormalizeFactorNameBuffer), "%s", UNNORMALIZE_FACTOR.c_str());
50 for (const auto& blendShape : mesh.first.mBlendShapes)
52 snprintf(pWeightName, sizeof(weightNameBuffer) - (pWeightName - weightNameBuffer), "[%d]", index);
53 std::string weightName{ weightNameBuffer };
54 actor.RegisterProperty(weightName, blendShape.weight);
56 if (mesh.first.mBlendShapeVersion == Version::VERSION_1_0)
58 snprintf(pFactorName, sizeof(unnormalizeFactorNameBuffer) - (pFactorName - unnormalizeFactorNameBuffer), "[%d]", index);
59 std::string factorName{ unnormalizeFactorNameBuffer };
60 shader.RegisterProperty(factorName, mesh.second.blendShapeUnnormalizeFactor[index]);
66 if (Version::VERSION_2_0 == mesh.first.mBlendShapeVersion)
68 shader.RegisterProperty(UNNORMALIZE_FACTOR, mesh.second.blendShapeUnnormalizeFactor[0u]);
71 shader.RegisterProperty(NUMBER_OF_BLEND_SHAPES, Property::Value(static_cast<int>(index)));
72 shader.RegisterProperty(COMPONENT_SIZE, Property::Value(static_cast<int>(mesh.second.blendShapeBufferOffset)));
74 // Create a read only property to preserve the components of the blend shape.
75 int32_t components = 0x0;
76 for (auto& bs : mesh.first.mBlendShapes)
78 components |= (bs.deltas.IsDefined() * Component::POSITIONS) |
79 (bs.normals.IsDefined() * Component::NORMALS) | (bs.tangents.IsDefined() * Component::TANGENTS);
81 shader.RegisterProperty(COMPONENTS, components, Property::AccessMode::READ_ONLY);