1 #ifndef DALI_SCENE3D_LOADER_JSON_UTIL_H_
2 #define DALI_SCENE3D_LOADER_JSON_UTIL_H_
4 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "dali-scene3d/public-api/loader/index.h"
24 #include "dali-toolkit/devel-api/builder/tree-node.h"
25 #include "dali/public-api/animation/time-period.h"
26 #include "dali/public-api/common/vector-wrapper.h"
27 #include "dali/public-api/math/vector4.h"
28 #include "dali/public-api/object/property.h"
36 bool ReadBool(const Toolkit::TreeNode* node, bool& num);
38 bool ReadInt(const Toolkit::TreeNode* node, int& num);
40 bool ReadFloat(const Toolkit::TreeNode* node, float& num);
42 bool ReadIndex(const Toolkit::TreeNode* node, Index& num);
44 bool ReadBlob(const Toolkit::TreeNode* node, unsigned int& offset, unsigned int& length);
47 * @brief Gets the number of numerical element of a JSON array;
48 * @return 0 if not an array, otherwise the number of float or integer elements
49 * at the front of the array.
51 size_t GetNumericalArraySize(const Toolkit::TreeNode* node);
53 bool ReadVector(const Toolkit::TreeNode* node, float* num, unsigned int size);
55 bool ReadVector(const Toolkit::TreeNode* node, int* num, unsigned int size);
58 * @brief Reads a color.
60 * The node contents could be a vector of 4 floats [r,g,b,a].
62 * @param[in] node The tree node with the color.
63 * @param[out] color The RGBA color.
65 * @return true if succedded to read the color.
67 bool ReadColor(const Toolkit::TreeNode* node, Vector4& color);
69 bool ReadTimePeriod(const Toolkit::TreeNode* node, TimePeriod& timePeriod);
71 bool ReadString(const Toolkit::TreeNode* node, std::string& strValue);
73 bool ReadStringVector(const Toolkit::TreeNode* node, std::vector<std::string>& strvector);
76 * @brief Attempts to read a property of the given type from the given JSON node.
77 * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
78 * @note Currently only numerical types are supported (including boolean).
80 Property::Value ReadPropertyValue(const Property::Type& propType, const Toolkit::TreeNode& tn);
83 * @brief Attempts to read a property, whose type it will attempt to determine from the given
85 * @return The property value that it could interpret. If unsuccessful, its type will be NONE.
86 * @note Currently only numerical types are supported (including boolean).
87 * @note Supports a disambiguation syntax, whereby the type can be specified explicitly:
88 * { "type": "rotation", "value": [...] } .
89 * @note: rotation / rectangle / extents type properties must be disambiguated in all circumstances.
91 Property::Value ReadPropertyValue(const Toolkit::TreeNode& tn);
94 } // namespace Scene3D
97 #endif //DALI_SCENE3D_LOADER_JSON_UTIL_H_