Use ModelNode / ModelPrimitive / Material instead of Actor / Renderer
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / model-components / material.h
1 #ifndef DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H
2 #define DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/object/property-index-ranges.h>
25 #include <dali/public-api/object/property-value.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/rendering/sampler.h>
28 #include <dali/public-api/rendering/texture.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-scene3d/public-api/api.h>
32
33 namespace Dali
34 {
35 namespace Scene3D
36 {
37 // Forward declarations.
38 namespace Internal
39 {
40 class Material;
41 } // namespace Internal
42
43 /**
44  * @addtogroup dali_scene3d_model_components_material
45  * @{
46  */
47
48 /**
49  * @brief Class for setting Material properties of 3D models
50  *
51  * @SINCE_2_2.99
52  *
53  * @note This Material class is for setting Material properties of 3D models.
54  * This Material supports properties and textures for PBR.
55  * Also, Material can be shared with multiple ModelPrimitives and if the value is modified,
56  * the rendering results of all ModelPrimitives using this Material will be changed.
57  *
58  * @code
59  * Material material = Material::New();
60  * ModelPrimitive modelPrimitive = ModelPrimitive::New();
61  * modelPrimitive.SetMaterial(material);
62  * material.SetProperty(PropertyIndex, PropertyValue);
63  * @endcode
64  */
65 class DALI_SCENE3D_API Material : public Dali::BaseHandle
66 {
67 public:
68   /**
69    * @brief Enumeration for the start and end property ranges for material.
70    * @SINCE_2_2.99
71    */
72   enum PropertyRange
73   {
74     PROPERTY_START_INDEX          = PROPERTY_REGISTRATION_START_INDEX,    ///< Start index is used by the property registration macro. @SINCE_2_2.99
75     MATERIAL_PROPERTY_START_INDEX = PROPERTY_START_INDEX,                 ///< Start index of Control properties. @SINCE_2_2.99
76     MATERIAL_PROPERTY_END_INDEX   = MATERIAL_PROPERTY_START_INDEX + 1000, ///< Reserving 1000 property indices. @SINCE_2_2.99
77
78     ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,        ///< @SINCE_2_2.99
79     ANIMATABLE_PROPERTY_END_INDEX   = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000, ///< Reserve animatable property indices, @SINCE_2_2.99
80   };
81
82   /**
83    * @brief Enumeration for the instance of properties belonging to the Material class.
84    * @SINCE_2_2.99
85    */
86   struct Property
87   {
88     enum
89     {
90       /**
91        * @brief Name of material.
92        * @details type Property::STRING.
93        * @SINCE_2_2.99
94        */
95       NAME = MATERIAL_PROPERTY_START_INDEX,
96
97       /**
98        * @brief Property for the URL of the base color texture.
99        * @details Type Property::STRING.
100        * @SINCE_2_2.99
101        */
102       BASE_COLOR_URL,
103
104       /**
105        * @brief Property for the base color factor of the material surface.
106        * @details Type Property::VECTOR4.
107        * @SINCE_2_2.99
108        */
109       BASE_COLOR_FACTOR,
110
111       /**
112        * @brief Property for the URL of the metallic-roughness texture.
113        * @details Type Property::STRING.
114        * @SINCE_2_2.99
115        */
116       METALLIC_ROUGHNESS_URL,
117
118       /**
119        * @brief Property for the metallic factor of the material surface.
120        * @details Type Property::FLOAT.
121        * @SINCE_2_2.99
122        */
123       METALLIC_FACTOR,
124
125       /**
126        * @brief Property for the roughness factor of the material surface.
127        * @details Type Property::FLOAT.
128        * @SINCE_2_2.99
129        */
130       ROUGHNESS_FACTOR,
131
132       /**
133        * @brief Property for the URL of the normal texture.
134        * @details Type Property::STRING.
135        * @SINCE_2_2.99
136        */
137       NORMAL_URL,
138
139       /**
140        * @brief Property for the scale factor applied to normal vectors.
141        * @details Type Property::FLOAT.
142        * @SINCE_2_2.99
143        */
144       NORMAL_SCALE,
145
146       /**
147        * @brief Property for the URL of the occlusion texture.
148        * @details Type Property::STRING.
149        * @SINCE_2_2.99
150        */
151       OCCLUSION_URL,
152
153       /**
154        * @brief Property for the occlusion strength of the material surface.
155        * @details Type Property::FLOAT.
156        * @SINCE_2_2.99
157        */
158       OCCLUSION_STRENGTH,
159
160       /**
161        * @brief Property for the URL of the emissive texture.
162        * @details Type Property::STRING.
163        * @SINCE_2_2.99
164        */
165       EMISSIVE_URL,
166
167       /**
168        * @brief Emissive factor Property.
169        * @details type Property::VECTOR3.
170        * @SINCE_2_2.99
171        */
172       EMISSIVE_FACTOR,
173
174       /**
175        * @brief Alpha mode Property.
176        * @details type Property::INTEGER.
177        * @SINCE_2_2.99
178        */
179       ALPHA_MODE,
180
181       /**
182        * @brief Alpha cutoff Property.
183        * @details type Property::FLOAT.
184        * @SINCE_2_2.99
185        */
186       ALPHA_CUTOFF,
187
188       /**
189        * @brief Double sided Property.
190        * @details type Property::BOOLEAN.
191        * @SINCE_2_2.99
192        */
193       DOUBLE_SIDED,
194
195       /**
196        *@brief Index of refraction (IOR) of the material surface
197        *@details type Property::FLOAT
198        * @SINCE_2_2.99
199        */
200       IOR,
201
202       /**
203        * @brief Property for the URL of the specular texture.
204        * @details Type Property::STRING.
205        * @SINCE_2_2.99
206        */
207       SPECULAR_URL,
208
209       /**
210        *@brief Property for the specular factor of the material surface.
211        *@details Type Property::FLOAT.
212        * @SINCE_2_2.99
213        */
214       SPECULAR_FACTOR,
215
216       /**
217        * @brief Property for the URL of the specular color texture.
218        * @details Type Property::STRING.
219        * @SINCE_2_2.99
220        */
221       SPECULAR_COLOR_URL,
222
223       /**
224        *@brief Property for the specular color factor of the material surface.
225        *@details Type Property::VECTOR3.
226        * @SINCE_2_2.99
227        */
228       SPECULAR_COLOR_FACTOR,
229     };
230   };
231
232   enum TextureType
233   {
234     /**
235      * @brief Base Color Texture Property.
236      * @SINCE_2_2.99
237      * @note This texture represents the base color of the material. In most cases, this will be the diffuse color of the material.
238      */
239     BASE_COLOR,
240
241     /**
242      * @brief Metallic Roughness Texture Property.
243      * @SINCE_2_2.99
244      * @note This texture represents the metallicness and roughness of the material. This texture can be used to make the material look more metallic or rough.
245      */
246     METALLIC_ROUGHNESS,
247
248     /**
249      * @brief Normal Texture Property.
250      * @SINCE_2_2.99
251      * @note This texture represents the surface of the material. This texture can be used to make the surface of the material look smooth or rough.
252      */
253     NORMAL,
254
255     /**
256      * @brief Occlusion Texture Property.
257      * @SINCE_2_2.99
258      * @note This texture represents the depth of the material. This texture can be used to make the material look more three-dimensional.
259      */
260     OCCLUSION,
261
262     /**
263      * @brief Emissive Texture Property.
264      * @SINCE_2_2.99
265      * @note This texture makes the material look like it's emitting light. This texture can be used to make the material look like it's glowing.
266      */
267     EMISSIVE,
268
269     /**
270      * @brief Specular Texture Property.
271      * @SINCE_2_2.99
272      * @note This texture represents the specular reflection of the material. This texture can be used to make the material look more reflective.
273      */
274     SPECULAR,
275
276     /**
277      * @brief Specular Color Texture Property.
278      * @SINCE_2_2.99
279      * @note This texture represents the color of the specular reflection of the material. This texture can be used to set the color of the specular reflection of the material.
280      */
281     SPECULAR_COLOR,
282   };
283
284   enum AlphaModeType
285   {
286     /**
287      * @brief This indicates that the material is fully opaque and that the alpha value should be ignored.
288      * @SINCE_2_2.99
289      */
290     OPAQUE,
291
292     /**
293      * @brief This indicates that the material is either fully opaque or fully transparent depending on the alpha value. The alpha value is used to mask out areas of the material that should be transparent.
294      * @SINCE_2_2.99
295      */
296     MASK,
297
298     /**
299      * @brief This indicates that the material is transparent and that the alpha value should be used to blend the material with the background.
300      * @SINCE_2_2.99
301      */
302     BLEND,
303   };
304
305 public: // Creation & Destruction
306   /**
307    * @brief Create an initialized Material.
308    *
309    * @SINCE_2_2.99
310    * @return A handle to a newly allocated Dali resource
311    */
312   static Material New();
313
314   /**
315    * @brief Creates an uninitialized Material.
316    *
317    * Only derived versions can be instantiated. Calling member
318    * functions with an uninitialized Dali::Object is not allowed.
319    *
320    * @SINCE_2_2.99
321    */
322   Material();
323
324   /**
325    * @brief Destructor.
326    *
327    * This is non-virtual since derived Handle types must not contain data or virtual methods.
328    *
329    * @SINCE_2_2.99
330    */
331   ~Material();
332
333   /**
334    * @brief Copy constructor.
335    *
336    * @SINCE_2_2.99
337    * @param[in] material Handle to an object
338    */
339   Material(const Material& material);
340
341   /**
342    * @brief Move constructor
343    *
344    * @SINCE_2_2.99
345    * @param[in] rhs A reference to the moved handle
346    */
347   Material(Material&& rhs) noexcept;
348
349   /**
350    * @brief Assignment operator.
351    *
352    * @SINCE_2_2.99
353    * @param[in] material Handle to an object
354    * @return reference to this
355    */
356   Material& operator=(const Material& material);
357
358   /**
359    * @brief Move assignment
360    *
361    * @SINCE_2_2.99
362    * @param[in] rhs A reference to the moved handle
363    * @return A reference to this
364    */
365   Material& operator=(Material&& rhs) noexcept;
366
367   /**
368    * @brief Downcasts an Object handle to Material.
369    *
370    * If handle points to a Material, the downcast produces valid handle.
371    * If not, the returned handle is left uninitialized.
372    *
373    * @SINCE_2_2.99
374    * @param[in] handle Handle to an object
375    * @return Handle to a Material or an uninitialized handle
376    */
377   static Material DownCast(BaseHandle handle);
378
379 public: // Public Method
380   /**
381    * @brief Sets the value of an existing property.
382    * @note BaseHandle is not subclass of Handle. So this API is not use Handle.SetProperty
383    *
384    * @SINCE_2_2.99
385    * @param[in] index The index of the property
386    * @param[in] propertyValue The new value of the property
387    */
388   void SetProperty(Dali::Property::Index index, Dali::Property::Value propertyValue);
389
390   /**
391    * @brief Retrieves a property value.
392    * @note BaseHandle is not subclass of Handle. So this API is not use Handle.SetProperty
393    *
394    * @SINCE_2_2.99
395    * @param[in] index The index of the property
396    * @return The property value
397    * @note This returns the value set by SetProperty() or the animation target value if it is being animated.
398    */
399   Dali::Property::Value GetProperty(Dali::Property::Index index) const;
400
401   /**
402    * @brief Convenience function for obtaining a property of a known type.
403    *
404    * @SINCE_2_2.99
405    * @param[in] index The index of the property
406    * @return The property value
407    * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
408    * @see GetProperty()
409    */
410   template<typename T>
411   T GetProperty(Dali::Property::Index index) const
412   {
413     Dali::Property::Value value = GetProperty(index);
414
415     return T(value.Get<T>());
416   }
417
418   /**
419    * @brief Sets the texture for a given texture type.
420    *
421    * @SINCE_2_2.99
422    * @param[in] index The texture type index
423    * @param[in] texture The texture to set.
424    */
425   void SetTexture(Scene3D::Material::TextureType index, Dali::Texture texture);
426
427   /**
428    * @brief Gets the texture for a given texture type.
429    *
430    * @SINCE_2_2.99
431    * @param[in] index The texture type index
432    * @return The texture at the given index.
433    */
434   Dali::Texture GetTexture(Scene3D::Material::TextureType index);
435
436   /**
437    * @brief Sets the sampler for a given texture type.
438    *
439    * @SINCE_2_2.99
440    * @param[in] index The texture type index
441    * @param[in] sampler The sampler to use for this texture type
442    */
443   void SetSampler(Scene3D::Material::TextureType index, Dali::Sampler sampler);
444
445   /**
446    * @brief Gets the sampler for a given texture type.
447    *
448    * @SINCE_2_2.99
449    * @param[in] index The texture type index
450    * @return The sampler used for this texture type
451    */
452   Dali::Sampler GetSampler(Scene3D::Material::TextureType index);
453
454 public: // Not intended for application developers
455   /// @cond internal
456   /**
457    * @brief Creates a handle using the Scene3D::Internal implementation.
458    *
459    * @param[in] implementation The Material implementation
460    */
461   DALI_INTERNAL Material(Dali::Scene3D::Internal::Material* implementation);
462   /// @endcond
463 };
464
465 /**
466  * @}
467  */
468
469 } // namespace Scene3D
470
471 } // namespace Dali
472
473 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H