1 #ifndef DALI_SCENE3D_LOADER_NODE_DEFINITION_H_
2 #define DALI_SCENE3D_LOADER_NODE_DEFINITION_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/customization.h"
22 #include "dali-scene3d/public-api/loader/matrix-stack.h"
23 #include "dali-scene3d/public-api/loader/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"
43 * @brief Interface to report (const) resource ids to.
45 class DALI_SCENE3D_API IResourceReceiver
48 virtual ~IResourceReceiver() = default;
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_SCENE3D_API IResourceReflector
61 virtual ~IResourceReflector() = default;
63 virtual void Reflect(ResourceType::Value type, Index& id) = 0;
67 * @brief Intermediate representation for a constraint that shall be
68 * set up after the Actors were created. The target of the constraint
69 * is the node definition that carries it.
71 struct DALI_SCENE3D_API ConstraintDefinition
73 std::string mProperty; ///< name of the property to constrain.
74 Index mSourceIdx; ///< index of the node to serve as the source of the constraint.
76 bool operator<(const ConstraintDefinition& other) const
78 return mProperty < other.mProperty;
81 bool operator==(const ConstraintDefinition& other) const
83 return mSourceIdx == other.mSourceIdx && mProperty == other.mProperty;
86 bool operator!=(const ConstraintDefinition& other) const
88 return !operator==(other);
92 struct DALI_SCENE3D_API Transforms
94 MatrixStack modelStack;
95 const ViewProjection& viewProjection;
99 * @brief Information about a skeleton and the shader that needs to be configured with it.
100 * @note Multiple skeletons shalt not share the same shader.
102 struct DALI_SCENE3D_API SkinningShaderConfigurationRequest
107 bool operator<(const SkinningShaderConfigurationRequest& other) const
109 return mShader < other.mShader;
114 * @brief Needed to configure blend shape properties.
116 struct DALI_SCENE3D_API BlendshapeShaderConfigurationRequest
118 std::string mNodeName;
122 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
124 return mShader < other.mShader;
129 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
131 struct DALI_SCENE3D_API ConstraintRequest
133 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
134 Actor mTarget; ///< Target of the constraint.
138 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
139 * and slots for customization and rendering logic, which are mutually exclusive in the
140 * current implementation.
142 struct DALI_SCENE3D_API NodeDefinition
145 using Vector = std::vector<NodeDefinition>;
150 const ResourceBundle& mResources;
154 std::vector<ConstraintRequest> mConstrainables;
155 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
156 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
159 class DALI_SCENE3D_API Renderable
162 Index mShaderIdx = INVALID_INDEX;
165 virtual ~Renderable() = default;
167 virtual bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
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;
192 ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
198 virtual void Start(const NodeDefinition& n) = 0;
199 virtual void Finish(const NodeDefinition& n) = 0;
202 ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
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);
224 * @brief Gets local space matrix of this node
225 * @return Matrix of local space.
227 Matrix GetLocalSpace() const;
230 * @brief Retrieves minimum and maximum position of this node in local space.
231 * @param[in] resources ResourceBundle that contains mesh information of this node.
232 * @param[out] min Minimum position of the mesh of this node.
233 * @param[out] max Maximum position of the mesh of this node.
234 * @return true If the node has mesh.
236 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
239 * @brief Retrieves Scale Factor uniform name.
240 * This uniform name can be used to change scale factor for ibl.
241 * @return std::string_view of the scale factor uniform name.
243 static std::string_view GetIblScaleFactorUniformName();
246 * @brief Retrieves ibl Ydirection uniform name.
247 * This uniform name can be used to flip y direction of ibl in shader.
248 * @return std::string_view of the YDirection uniform name.
250 static std::string_view GetIblYDirectionUniformName();
253 static const char* ORIGINAL_MATRIX_PROPERTY_NAME;
256 uint32_t mNodeId = INVALID_INDEX;
258 Vector3 mPosition = Vector3::ZERO;
259 Quaternion mOrientation = Quaternion::IDENTITY;
260 Vector3 mScale = Vector3::ONE;
261 Vector3 mSize = Vector3::ONE;
263 bool mIsVisible = true;
265 std::vector<std::unique_ptr<Renderable>> mRenderables;
266 std::unique_ptr<CustomizationDefinition> mCustomization;
267 std::vector<Extra> mExtras;
268 std::vector<ConstraintDefinition> mConstraints;
270 std::vector<Index> mChildren;
271 Index mParentIdx = INVALID_INDEX;
274 class DALI_SCENE3D_API ModelRenderable : public NodeDefinition::Renderable
277 Vector4 mColor = Color::WHITE;
278 Index mMeshIdx = INVALID_INDEX;
279 Index mMaterialIdx = INVALID_INDEX;
282 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const override;
283 void RegisterResources(IResourceReceiver& receiver) const override;
284 void ReflectResources(IResourceReflector& reflector) override;
285 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
289 * @brief Parameters for an Arc node.
291 class DALI_SCENE3D_API ArcRenderable : public ModelRenderable
294 bool mAntiAliasing = true;
296 float mStartAngleDegrees = .0f;
297 float mEndAngleDegrees = .0f;
301 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
303 void OnCreate(const NodeDefinition& node, NodeDefinition::CreateParams& params, Actor& actor) const override;
306 } // namespace Loader
307 } // namespace Scene3D
310 #endif // DALI_SCENE3D_LOADER_NODE_DEFINITION_H_