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() = default;
49 virtual void Register(ResourceType::Value type, Index id) = 0;
53 * @brief Interface to report modifiable resource ids to.
54 * @note These are supposed to be transient. Obviously, the references collected
55 * this way must not outlive the objects that they came from.
57 class DALI_SCENE_LOADER_API IResourceReflector
60 virtual ~IResourceReflector() = default;
62 virtual void Reflect(ResourceType::Value type, Index& id) = 0;
66 * @brief Intermediate representation for a constraint that shall be
67 * set up after the Actors were created. The target of the constraint
68 * is the node definition that carries it.
70 struct DALI_SCENE_LOADER_API ConstraintDefinition
72 std::string mProperty; ///< name of the property to constrain.
73 Index mSourceIdx; ///< index of the node to serve as the source of the constraint.
75 bool operator<(const ConstraintDefinition& other) const
77 return mProperty < other.mProperty;
80 bool operator==(const ConstraintDefinition& other) const
82 return mSourceIdx == other.mSourceIdx && mProperty == other.mProperty;
85 bool operator!=(const ConstraintDefinition& other) const
87 return !operator==(other);
91 struct DALI_SCENE_LOADER_API Transforms
93 MatrixStack modelStack;
94 const ViewProjection& viewProjection;
98 * @brief Information about a skeleton and the shader that needs to be configured with it.
99 * @note Multiple skeletons shalt not share the same shader.
101 struct DALI_SCENE_LOADER_API SkinningShaderConfigurationRequest
106 bool operator<(const SkinningShaderConfigurationRequest& other) const
108 return mShader < other.mShader;
113 * @brief Needed to configure blend shape properties.
115 struct DALI_SCENE_LOADER_API BlendshapeShaderConfigurationRequest
117 std::string mNodeName;
121 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
123 return mShader < other.mShader;
128 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
130 struct DALI_SCENE_LOADER_API ConstraintRequest
132 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
133 Actor mTarget; ///< Target of the constraint.
137 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
138 * and slots for customization and rendering logic, which are mutually exclusive in the
139 * current implementation.
141 struct DALI_SCENE_LOADER_API NodeDefinition
144 using Vector = std::vector<NodeDefinition>;
149 const ResourceBundle& mResources;
153 std::vector<ConstraintRequest> mConstrainables;
154 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
155 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
158 class DALI_SCENE_LOADER_API Renderable
161 Index mShaderIdx = INVALID_INDEX;
164 virtual ~Renderable() = default;
166 virtual void RegisterResources(IResourceReceiver& receiver) const;
167 virtual void ReflectResources(IResourceReflector& reflector);
168 virtual void OnCreate(const NodeDefinition& node, CreateParams& params, Actor& actor) const;
171 struct CustomizationDefinition
175 Index GetChildId(const Customization::Choices& choices, const NodeDefinition& node)
177 auto choice = choices.Get(mTag);
178 return std::min(choice != Customization::NONE ? choice : 0,
179 static_cast<Index>(node.mChildren.size() - 1));
186 virtual void Start(NodeDefinition& n) = 0;
187 virtual void Finish(NodeDefinition& n) = 0;
190 ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
196 virtual void Start(const NodeDefinition& n) = 0;
197 virtual void Finish(const NodeDefinition& n) = 0;
200 ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
206 Property::Value mValue;
208 bool operator<(const Extra& other) const
210 return mKey < other.mKey;
216 * @brief Creates a DALi Actor from this definition only.
217 * @note Not recursive.
219 Actor CreateActor(CreateParams& params) const;
221 Matrix GetLocalSpace() const;
224 static const std::string ORIGINAL_MATRIX_PROPERTY_NAME;
228 Vector3 mPosition = Vector3::ZERO;
229 Quaternion mOrientation = Quaternion::IDENTITY;
230 Vector3 mScale = Vector3::ONE;
231 Vector3 mSize = Vector3::ONE;
233 bool mIsVisible = true;
235 std::unique_ptr<Renderable> mRenderable;
236 std::unique_ptr<CustomizationDefinition> mCustomization;
237 std::vector<Extra> mExtras;
238 std::vector<ConstraintDefinition> mConstraints;
240 std::vector<Index> mChildren;
241 Index mParentIdx = INVALID_INDEX;
244 class DALI_SCENE_LOADER_API ModelNode : public NodeDefinition::Renderable
247 Vector4 mColor = Color::WHITE;
248 Index mMeshIdx = INVALID_INDEX;
249 Index mMaterialIdx = INVALID_INDEX;
252 void RegisterResources(IResourceReceiver& receiver) const override;
253 void ReflectResources(IResourceReflector& reflector) override;
254 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
258 * @brief Parameters for an Arc node.
260 class DALI_SCENE_LOADER_API ArcNode : public ModelNode
263 bool mAntiAliasing = true;
265 float mStartAngleDegrees = .0f;
266 float mEndAngleDegrees = .0f;
270 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
272 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
278 #endif //DALI_SCENE_LOADER_NODE_DEFINITION_H_