1 #ifndef DALI_SCENE3D_LOADER_NODE_DEFINITION_H_
2 #define DALI_SCENE3D_LOADER_NODE_DEFINITION_H_
4 * Copyright (c) 2023 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/public-api/actors/actor.h>
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/quaternion.h>
24 #include <dali/public-api/math/vector4.h>
30 #include <dali-scene3d/public-api/loader/customization.h>
31 #include <dali-scene3d/public-api/loader/matrix-stack.h>
32 #include <dali-scene3d/public-api/loader/resource-bundle.h>
33 #include <dali-scene3d/public-api/model-components/model-node.h>
44 * @brief Interface to report (const) resource ids to.
46 class DALI_SCENE3D_API IResourceReceiver
49 virtual ~IResourceReceiver() = default;
51 virtual void Register(ResourceType::Value type, Index id) = 0;
55 * @brief Interface to report modifiable resource ids to.
56 * @note These are supposed to be transient. Obviously, the references collected
57 * this way must not outlive the objects that they came from.
59 class DALI_SCENE3D_API IResourceReflector
62 virtual ~IResourceReflector() = default;
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_SCENE3D_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_SCENE3D_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_SCENE3D_API SkinningShaderConfigurationRequest
107 ModelPrimitive mPrimitive;
109 bool operator<(const SkinningShaderConfigurationRequest& other) const
111 return mShader < other.mShader || (mShader == other.mShader && mPrimitive < other.mPrimitive);
116 * @brief Needed to configure blend shape properties.
118 struct DALI_SCENE3D_API BlendshapeShaderConfigurationRequest
120 std::string mNodeName;
123 ModelPrimitive mPrimitive;
125 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
127 return mShader < other.mShader || (mShader == other.mShader && mPrimitive < other.mPrimitive);
132 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
134 struct DALI_SCENE3D_API ConstraintRequest
136 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
137 Actor mTarget; ///< Target of the constraint.
141 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
142 * and slots for customization and rendering logic, which are mutually exclusive in the
143 * current implementation.
145 struct DALI_SCENE3D_API NodeDefinition
148 using Vector = std::vector<NodeDefinition>;
153 ResourceBundle& mResources;
157 std::vector<ConstraintRequest> mConstrainables;
158 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
159 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
162 class DALI_SCENE3D_API Renderable
165 Index mShaderIdx = INVALID_INDEX;
168 virtual ~Renderable() = default;
170 virtual bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
171 virtual void RegisterResources(IResourceReceiver& receiver) const;
172 virtual void ReflectResources(IResourceReflector& reflector);
173 virtual void OnCreate(const NodeDefinition& nodeDefinition, CreateParams& params, ModelNode& node) const;
176 struct CustomizationDefinition
180 Index GetChildId(const Customization::Choices& choices, const NodeDefinition& node)
182 auto choice = choices.Get(mTag);
183 return std::min(choice != Customization::NONE ? choice : 0,
184 static_cast<Index>(node.mChildren.size() - 1));
191 virtual void Start(NodeDefinition& n) = 0;
192 virtual void Finish(NodeDefinition& n) = 0;
195 ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
201 virtual void Start(const NodeDefinition& n) = 0;
202 virtual void Finish(const NodeDefinition& n) = 0;
205 ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
211 Property::Value mValue;
213 bool operator<(const Extra& other) const
215 return mKey < other.mKey;
221 * @brief Creates a ModelNode from this definition only.
222 * @note Not recursive.
224 ModelNode CreateModelNode(CreateParams& params);
227 * @brief Gets local space matrix of this node
228 * @return Matrix of local space.
230 Matrix GetLocalSpace() const;
233 * @brief Retrieves minimum and maximum position of this node in local space.
234 * @param[in] resources ResourceBundle that contains mesh information of this node.
235 * @param[out] min Minimum position of the mesh of this node.
236 * @param[out] max Maximum position of the mesh of this node.
237 * @return true If the node has mesh.
239 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
242 * @brief Retrieves Scale Factor uniform name.
243 * This uniform name can be used to change scale factor for ibl.
244 * @return std::string_view of the scale factor uniform name.
246 static std::string_view GetIblScaleFactorUniformName();
249 * @brief Retrieves ibl Ydirection uniform name.
250 * This uniform name can be used to flip y direction of ibl in shader.
251 * @return std::string_view of the YDirection uniform name.
253 static std::string_view GetIblYDirectionUniformName();
256 * @brief Retrieves ibl MaxLod uniform name.
257 * This uniform name can be used to set max lod of ibl in shader.
258 * @return std::string_view of the Max Lod uniform name.
260 static std::string_view GetIblMaxLodUniformName();
263 static const char* ORIGINAL_MATRIX_PROPERTY_NAME;
266 uint32_t mNodeId = INVALID_INDEX;
268 Vector3 mPosition = Vector3::ZERO;
269 Quaternion mOrientation = Quaternion::IDENTITY;
270 Vector3 mScale = Vector3::ONE;
271 Vector3 mSize = Vector3::ONE;
273 bool mIsVisible = true;
275 std::vector<std::unique_ptr<Renderable>> mRenderables;
276 std::unique_ptr<CustomizationDefinition> mCustomization;
277 std::vector<Extra> mExtras;
278 std::vector<ConstraintDefinition> mConstraints;
280 std::vector<Index> mChildren;
281 Index mParentIdx = INVALID_INDEX;
284 class DALI_SCENE3D_API ModelRenderable : public NodeDefinition::Renderable
287 Vector4 mColor = Color::WHITE;
288 Index mMeshIdx = INVALID_INDEX;
289 Index mMaterialIdx = INVALID_INDEX;
292 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const override;
293 void RegisterResources(IResourceReceiver& receiver) const override;
294 void ReflectResources(IResourceReflector& reflector) override;
295 void OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const override;
299 * @brief Parameters for an Arc node.
301 class DALI_SCENE3D_API ArcRenderable : public ModelRenderable
304 bool mAntiAliasing = true;
306 float mStartAngleDegrees = .0f;
307 float mEndAngleDegrees = .0f;
311 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
313 void OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const override;
316 } // namespace Loader
317 } // namespace Scene3D
320 #endif // DALI_SCENE3D_LOADER_NODE_DEFINITION_H_