1 #ifndef DALI_SCENE_LOADER_NODE_DEFINITION_H_
2 #define DALI_SCENE_LOADER_NODE_DEFINITION_H_
4 * Copyright (c) 2021 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"
29 #include "dali/public-api/actors/actor.h"
30 #include "dali/public-api/math/matrix.h"
31 #include "dali/public-api/math/quaternion.h"
32 #include "dali/public-api/math/vector4.h"
41 * @brief Interface to report (const) resource ids to.
43 class DALI_SCENE_LOADER_API IResourceReceiver
46 virtual ~IResourceReceiver() = default;
48 virtual void Register(ResourceType::Value type, Index id) = 0;
52 * @brief Interface to report modifiable resource ids to.
53 * @note These are supposed to be transient. Obviously, the references collected
54 * this way must not outlive the objects that they came from.
56 class DALI_SCENE_LOADER_API IResourceReflector
59 virtual ~IResourceReflector() = default;
61 virtual void Reflect(ResourceType::Value type, Index& id) = 0;
65 * @brief Intermediate representation for a constraint that shall be
66 * set up after the Actors were created. The target of the constraint
67 * is the node definition that carries it.
69 struct DALI_SCENE_LOADER_API ConstraintDefinition
71 std::string mProperty; ///< name of the property to constrain.
72 Index mSourceIdx; ///< index of the node to serve as the source of the constraint.
74 bool operator<(const ConstraintDefinition& other) const
76 return mProperty < other.mProperty;
79 bool operator==(const ConstraintDefinition& other) const
81 return mSourceIdx == other.mSourceIdx && mProperty == other.mProperty;
84 bool operator!=(const ConstraintDefinition& other) const
86 return !operator==(other);
90 struct DALI_SCENE_LOADER_API Transforms
92 MatrixStack modelStack;
93 const ViewProjection& viewProjection;
97 * @brief Information about a skeleton and the shader that needs to be configured with it.
98 * @note Multiple skeletons shalt not share the same shader.
100 struct DALI_SCENE_LOADER_API SkinningShaderConfigurationRequest
105 bool operator<(const SkinningShaderConfigurationRequest& other) const
107 return mShader < other.mShader;
112 * @brief Needed to configure blend shape properties.
114 struct DALI_SCENE_LOADER_API BlendshapeShaderConfigurationRequest
116 std::string mNodeName;
120 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
122 return mShader < other.mShader;
127 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
129 struct DALI_SCENE_LOADER_API ConstraintRequest
131 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
132 Actor mTarget; ///< Target of the constraint.
136 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
137 * and slots for customization and rendering logic, which are mutually exclusive in the
138 * current implementation.
140 struct DALI_SCENE_LOADER_API NodeDefinition
143 using Vector = std::vector<NodeDefinition>;
148 const ResourceBundle& mResources;
152 std::vector<ConstraintRequest> mConstrainables;
153 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
154 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
157 class DALI_SCENE_LOADER_API Renderable
160 Index mShaderIdx = INVALID_INDEX;
163 virtual ~Renderable() = default;
165 virtual void RegisterResources(IResourceReceiver& receiver) const;
166 virtual void ReflectResources(IResourceReflector& reflector);
167 virtual void OnCreate(const NodeDefinition& node, CreateParams& params, Actor& actor) const;
170 struct CustomizationDefinition
174 Index GetChildId(const Customization::Choices& choices, const NodeDefinition& node)
176 auto choice = choices.Get(mTag);
177 return std::min(choice != Customization::NONE ? choice : 0,
178 static_cast<Index>(node.mChildren.size() - 1));
185 virtual void Start(NodeDefinition& n) = 0;
186 virtual void Finish(NodeDefinition& n) = 0;
189 ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
195 virtual void Start(const NodeDefinition& n) = 0;
196 virtual void Finish(const NodeDefinition& n) = 0;
199 ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
205 Property::Value mValue;
207 bool operator<(const Extra& other) const
209 return mKey < other.mKey;
215 * @brief Creates a DALi Actor from this definition only.
216 * @note Not recursive.
218 Actor CreateActor(CreateParams& params) const;
220 Matrix GetLocalSpace() const;
223 static const std::string ORIGINAL_MATRIX_PROPERTY_NAME;
227 Vector3 mPosition = Vector3::ZERO;
228 Quaternion mOrientation = Quaternion::IDENTITY;
229 Vector3 mScale = Vector3::ONE;
230 Vector3 mSize = Vector3::ONE;
232 bool mIsVisible = true;
234 std::unique_ptr<Renderable> mRenderable;
235 std::unique_ptr<CustomizationDefinition> mCustomization;
236 std::vector<Extra> mExtras;
237 std::vector<ConstraintDefinition> mConstraints;
239 std::vector<Index> mChildren;
240 Index mParentIdx = INVALID_INDEX;
243 class DALI_SCENE_LOADER_API ModelNode : public NodeDefinition::Renderable
246 Vector4 mColor = Color::WHITE;
247 Index mMeshIdx = INVALID_INDEX;
248 Index mMaterialIdx = INVALID_INDEX;
251 void RegisterResources(IResourceReceiver& receiver) const override;
252 void ReflectResources(IResourceReflector& reflector) override;
253 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
257 * @brief Parameters for an Arc node.
259 class DALI_SCENE_LOADER_API ArcNode : public ModelNode
262 bool mAntiAliasing = true;
264 float mStartAngleDegrees = .0f;
265 float mEndAngleDegrees = .0f;
269 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
271 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
274 } // namespace SceneLoader
277 #endif //DALI_SCENE_LOADER_NODE_DEFINITION_H_