1 #ifndef DALI_SCENE_LOADER_NODE_DEFINITION_H_
2 #define DALI_SCENE_LOADER_NODE_DEFINITION_H_
4 * Copyright (c) 2020 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-scene-loader/public-api/customization.h"
22 #include "dali-scene-loader/public-api/matrix-stack.h"
23 #include "dali-scene-loader/public-api/resource-bundle.h"
26 #include "dali/public-api/math/quaternion.h"
27 #include "dali/public-api/math/matrix.h"
28 #include "dali/public-api/math/vector4.h"
29 #include "dali/public-api/actors/actor.h"
42 * @brief Interface to report (const) resource ids to.
44 class DALI_SCENE_LOADER_API IResourceReceiver
47 virtual ~IResourceReceiver()
50 virtual void Register(ResourceType::Value type, Index id) = 0;
54 * @brief Interface to report modifiable resource ids to.
55 * @note These are supposed to be transient. Obviously, the references collected
56 * this way must not outlive the objects that they came from.
58 class DALI_SCENE_LOADER_API IResourceReflector
61 virtual ~IResourceReflector()
64 virtual void Reflect(ResourceType::Value type, Index& id) = 0;
68 * @brief Intermediate representation for a constraint that shall be
69 * set up after the Actors were created. The target of the constraint
70 * is the node definition that carries it.
72 struct DALI_SCENE_LOADER_API ConstraintDefinition
74 std::string mProperty; ///< name of the property to constrain.
75 Index mSourceIdx; ///< index of the node to serve as the source of the constraint.
77 bool operator<(const ConstraintDefinition& other) const
79 return mProperty < other.mProperty;
82 bool operator==(const ConstraintDefinition& other) const
84 return mSourceIdx == other.mSourceIdx && mProperty == other.mProperty;
87 bool operator!=(const ConstraintDefinition& other) const
89 return !operator==(other);
93 struct DALI_SCENE_LOADER_API Transforms
95 MatrixStack modelStack;
96 const ViewProjection& viewProjection;
100 * @brief Information about a skeleton and the shader that needs to be configured with it.
101 * @note Multiple skeletons shalt not share the same shader.
103 struct DALI_SCENE_LOADER_API SkinningShaderConfigurationRequest
108 bool operator<(const SkinningShaderConfigurationRequest& other) const
110 return mShader < other.mShader;
115 * @brief Needed to configure blend shape properties.
117 struct DALI_SCENE_LOADER_API BlendshapeShaderConfigurationRequest
119 std::string mNodeName;
123 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
125 return mShader < other.mShader;
130 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
132 struct DALI_SCENE_LOADER_API ConstraintRequest
134 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
135 Actor mTarget; ///< Target of the constraint.
139 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
140 * and slots for customization and rendering logic, which are mutually exclusive in the
141 * current implementation.
143 struct DALI_SCENE_LOADER_API NodeDefinition
146 using Vector = std::vector<NodeDefinition>;
151 const ResourceBundle& mResources;
155 std::vector<ConstraintRequest> mConstrainables;
156 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
157 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
160 class DALI_SCENE_LOADER_API Renderable
163 Index mShaderIdx = INVALID_INDEX;
166 virtual ~Renderable() {}
168 virtual void RegisterResources(IResourceReceiver& receiver) const;
169 virtual void ReflectResources(IResourceReflector& reflector);
170 virtual void OnCreate(const NodeDefinition& node, CreateParams& params, Actor& actor) const;
173 struct CustomizationDefinition
177 Index GetChildId(const Customization::Choices& choices, const NodeDefinition& node)
179 auto choice = choices.Get(mTag);
180 return std::min(choice != Customization::NONE ? choice : 0,
181 static_cast<Index>(node.mChildren.size() - 1));
188 virtual void Start(NodeDefinition& n) = 0;
189 virtual void Finish(NodeDefinition& n) = 0;
198 virtual void Start(const NodeDefinition& n) = 0;
199 virtual void Finish(const NodeDefinition& n) = 0;
208 Property::Value mValue;
210 bool operator<(const Extra& other) const
212 return mKey < other.mKey;
218 * @brief Creates a DALi Actor from this definition only.
219 * @note Not recursive.
221 Actor CreateActor(CreateParams& params) const;
223 Matrix GetLocalSpace() const;
226 static const std::string ORIGINAL_MATRIX_PROPERTY_NAME;
230 Vector3 mPosition = Vector3::ZERO;
231 Quaternion mOrientation = Quaternion::IDENTITY;
232 Vector3 mScale = Vector3::ONE;
233 Vector3 mSize = Vector3::ONE;
235 bool mIsVisible = true;
237 std::unique_ptr<Renderable> mRenderable;
238 std::unique_ptr<CustomizationDefinition> mCustomization;
239 std::vector<Extra> mExtras;
240 std::vector<ConstraintDefinition> mConstraints;
242 std::vector<Index> mChildren;
243 Index mParentIdx = INVALID_INDEX;
246 class DALI_SCENE_LOADER_API ModelNode : public NodeDefinition::Renderable
249 Vector4 mColor = Color::WHITE;
250 Index mMeshIdx = INVALID_INDEX;
251 Index mMaterialIdx = INVALID_INDEX;
254 void RegisterResources(IResourceReceiver& receiver) const override;
255 void ReflectResources(IResourceReflector& reflector) override;
256 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
260 * @brief Parameters for an Arc node.
262 class DALI_SCENE_LOADER_API ArcNode : public ModelNode
265 bool mAntiAliasing = true;
267 float mStartAngleDegrees = .0f;
268 float mEndAngleDegrees = .0f;
272 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
274 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
280 #endif //DALI_SCENE_LOADER_NODE_DEFINITION_H_