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/loader/shader-manager.h>
34 #include <dali-scene3d/public-api/model-components/model-node.h>
45 * @brief Interface to report (const) resource ids to.
48 class DALI_SCENE3D_API IResourceReceiver
51 virtual ~IResourceReceiver() = default;
53 virtual void Register(ResourceType::Value type, Index id) = 0;
57 * @brief Interface to report modifiable resource ids to.
59 * @note These are supposed to be transient. Obviously, the references collected
60 * this way must not outlive the objects that they came from.
62 class DALI_SCENE3D_API IResourceReflector
65 virtual ~IResourceReflector() = default;
67 virtual void Reflect(ResourceType::Value type, Index& id) = 0;
71 * @brief Intermediate representation for a constraint that shall be
72 * set up after the Actors were created. The target of the constraint
73 * is the node definition that carries it.
76 struct DALI_SCENE3D_API ConstraintDefinition
78 std::string mProperty; ///< name of the property to constrain.
79 Index mSourceIdx; ///< index of the node to serve as the source of the constraint.
81 bool operator<(const ConstraintDefinition& other) const
83 return mProperty < other.mProperty;
86 bool operator==(const ConstraintDefinition& other) const
88 return mSourceIdx == other.mSourceIdx && mProperty == other.mProperty;
91 bool operator!=(const ConstraintDefinition& other) const
93 return !operator==(other);
97 struct DALI_SCENE3D_API Transforms
99 MatrixStack modelStack;
100 const ViewProjection& viewProjection;
104 * @brief Information about a skeleton and the shader that needs to be configured with it.
106 * @note Multiple skeletons shalt not share the same shader.
108 struct DALI_SCENE3D_API SkinningShaderConfigurationRequest
112 ModelPrimitive mPrimitive;
114 bool operator<(const SkinningShaderConfigurationRequest& other) const
116 return mShader < other.mShader || (mShader == other.mShader && mPrimitive < other.mPrimitive);
121 * @brief Needed to configure blend shape properties.
124 struct DALI_SCENE3D_API BlendshapeShaderConfigurationRequest
126 std::string mNodeName;
129 ModelPrimitive mPrimitive;
131 bool operator<(const BlendshapeShaderConfigurationRequest& other) const
133 return mShader < other.mShader || (mShader == other.mShader && mPrimitive < other.mPrimitive);
138 * @brief Request for creating a constraint, output from NodeDefinition::OnCreate.
141 struct DALI_SCENE3D_API ConstraintRequest
143 const ConstraintDefinition* const mConstraint; ///< Definition of the constraint to create.
144 Actor mTarget; ///< Target of the constraint.
148 * @brief Defines a node, consisting of a name, a transform, a size, a list of child nodes,
149 * and slots for customization and rendering logic, which are mutually exclusive in the
150 * current implementation.
153 struct DALI_SCENE3D_API NodeDefinition
156 using Vector = std::vector<NodeDefinition>;
161 ResourceBundle& mResources;
163 Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager;
166 std::vector<ConstraintRequest> mConstrainables;
167 std::vector<SkinningShaderConfigurationRequest> mSkinnables;
168 std::vector<BlendshapeShaderConfigurationRequest> mBlendshapeRequests;
171 class DALI_SCENE3D_API Renderable
174 Index mShaderIdx = INVALID_INDEX;
177 virtual ~Renderable() = default;
179 virtual bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
180 virtual void RegisterResources(IResourceReceiver& receiver) const;
181 virtual void ReflectResources(IResourceReflector& reflector);
182 virtual void OnCreate(const NodeDefinition& nodeDefinition, CreateParams& params, ModelNode& node) const;
185 struct CustomizationDefinition
189 Index GetChildId(const Customization::Choices& choices, const NodeDefinition& node)
191 auto choice = choices.Get(mTag);
192 return std::min(choice != Customization::NONE ? choice : 0,
193 static_cast<Index>(node.mChildren.size() - 1));
200 virtual void Start(NodeDefinition& n) = 0;
201 virtual void Finish(NodeDefinition& n) = 0;
204 ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
210 virtual void Start(const NodeDefinition& n) = 0;
211 virtual void Finish(const NodeDefinition& n) = 0;
214 ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
220 Property::Value mValue;
222 bool operator<(const Extra& other) const
224 return mKey < other.mKey;
230 * @brief Creates a ModelNode from this definition only.
232 * @note Not recursive.
234 ModelNode CreateModelNode(CreateParams& params);
237 * @brief Gets local space matrix of this node
239 * @return Matrix of local space.
241 Matrix GetLocalSpace() const;
244 * @brief Retrieves minimum and maximum position of this node in local space.
246 * @param[in] resources ResourceBundle that contains mesh information of this node.
247 * @param[out] min Minimum position of the mesh of this node.
248 * @param[out] max Maximum position of the mesh of this node.
249 * @return true If the node has mesh.
251 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const;
254 * @brief Retrieves Scale Factor uniform name.
256 * This uniform name can be used to change scale factor for ibl.
258 * @return std::string_view of the scale factor uniform name.
260 static std::string_view GetIblScaleFactorUniformName();
263 * @brief Retrieves ibl Ydirection uniform name.
265 * This uniform name can be used to flip y direction of ibl in shader.
267 * @return std::string_view of the YDirection uniform name.
269 static std::string_view GetIblYDirectionUniformName();
272 * @brief Retrieves ibl MaxLod uniform name.
274 * This uniform name can be used to set max lod of ibl in shader.
276 * @return std::string_view of the Max Lod uniform name.
278 static std::string_view GetIblMaxLodUniformName();
281 static const char* ORIGINAL_MATRIX_PROPERTY_NAME;
284 uint32_t mNodeId = INVALID_INDEX;
286 Vector3 mPosition = Vector3::ZERO;
287 Quaternion mOrientation = Quaternion::IDENTITY;
288 Vector3 mScale = Vector3::ONE;
289 Vector3 mSize = Vector3::ONE;
291 bool mIsVisible = true;
293 std::vector<std::unique_ptr<Renderable>> mRenderables;
294 std::unique_ptr<CustomizationDefinition> mCustomization;
295 std::vector<Extra> mExtras;
296 std::vector<ConstraintDefinition> mConstraints;
298 std::vector<Index> mChildren;
299 Index mParentIdx = INVALID_INDEX;
302 class DALI_SCENE3D_API ModelRenderable : public NodeDefinition::Renderable
305 Vector4 mColor = Color::WHITE;
306 Index mMeshIdx = INVALID_INDEX;
307 Index mMaterialIdx = INVALID_INDEX;
310 bool GetExtents(const ResourceBundle& resources, Vector3& min, Vector3& max) const override;
311 void RegisterResources(IResourceReceiver& receiver) const override;
312 void ReflectResources(IResourceReflector& reflector) override;
313 void OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const override;
317 * @brief Parameters for an Arc node.
320 class DALI_SCENE3D_API ArcRenderable : public ModelRenderable
323 bool mAntiAliasing = true;
325 float mStartAngleDegrees = .0f;
326 float mEndAngleDegrees = .0f;
330 static void GetEndVectorWithDiffAngle(float startAngle, float endAngle, Vector2& endVector);
332 void OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const override;
335 } // namespace Loader
336 } // namespace Scene3D
339 #endif // DALI_SCENE3D_LOADER_NODE_DEFINITION_H_