Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / mesh / mesh-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
3
4 /*
5  * Copyright (c) 2021 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/intrusive-ptr.h>
23 #include <string.h>
24 #include <fstream>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/public-api/visuals/mesh-visual-properties.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 class MeshVisual;
38 typedef IntrusivePtr<MeshVisual> MeshVisualPtr;
39
40 /**
41  * The visual which renders a 3D object to the control's quad
42  *
43  * The following Property::Map keys are required to create a MeshVisual
44  *
45  * | %Property Name  | Type        | Representing                                                          |
46  * |-----------------|-------------|-----------------------------------------------------------------------|
47  * | objectUrl       | STRING      | A URL to the .obj file                                                |
48  * | materialUrl     | STRING      | A URL to the .mtl file                                                |
49  * | texturesPath    | STRING      | A URL of the path to the texture images                               |
50  * | shadingMode     | STRING      | An enum of shading modes                                              |
51  * | useMipmapping   | BOOLEAN     | If true, use mipmaps for textures. Default true.                      |
52  * | useSoftNormals  | BOOLEAN     | If true, average normals at points for smooth textures. Default true. |
53  * | lightPosition   | VECTOR3     | The position (on stage) of the light                                  |
54  */
55 class MeshVisual : public Visual::Base
56 {
57 public:
58   /**
59    * @brief Create a new mesh visual.
60    *
61    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
62    * @param[in] properties A Property::Map containing settings for this visual
63    * @return A smart-pointer to the newly allocated visual.
64    */
65   static MeshVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
66
67 public: // from Visual
68   /**
69    * @copydoc Visual::Base::CreatePropertyMap
70    */
71   void DoCreatePropertyMap(Property::Map& map) const override;
72
73   /**
74    * @copydoc Visual::Base::CreateInstancePropertyMap
75    */
76   void DoCreateInstancePropertyMap(Property::Map& map) const override;
77
78 protected:
79   /**
80    * @brief Constructor.
81    *
82    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
83    */
84   MeshVisual(VisualFactoryCache& factoryCache);
85
86   /**
87    * @brief A reference counted object may only be deleted by calling Unreference().
88    */
89   virtual ~MeshVisual();
90
91   /**
92    * @copydoc Visual::Base::OnInitialize
93    */
94   void OnInitialize() override;
95
96   /**
97    * @copydoc Visual::Base::DoSetProperties
98    */
99   void DoSetProperties(const Property::Map& propertyMap) override;
100
101   /**
102    * @copydoc Visual::Base::OnSetTransform
103    */
104   void OnSetTransform() override;
105
106   /**
107    * @copydoc Visual::Base::DoSetOnScene
108    */
109   void DoSetOnScene(Actor& actor) override;
110
111 private:
112   /**
113    * @brief Provide an empty geometry for the visual to use.
114    * @details For use in error cases where the initialisation has failed for varying reasons.
115    */
116   void SupplyEmptyGeometry();
117
118   /**
119    * @brief Create a shader for the object to use.
120    */
121   void CreateShader();
122
123   /**
124    * @brief Update shader related info, uniforms, etc. for the new shader.
125    */
126   void UpdateShaderUniforms();
127
128   /**
129    * @brief Use the object URL stored in the mesh visual to load and create the geometry of the object.
130    * @return Boolean of success of operation.
131    */
132   bool CreateGeometry();
133
134   /**
135    * @brief Use the object URL stored in the visual to load the geometry of the object.
136    * @return Boolean of success of operation.
137    */
138   bool LoadGeometry();
139
140   /**
141    * @brief Use the material URL stored in the mesh visual to load the material of the object.
142    * @return Boolean of success of operation.
143    */
144   bool LoadMaterial();
145
146   /**
147    * @brief Use the image and texture URL components to load the different types of texture.
148    * @return Boolean of success of operation. Returns false if any texture fails to load from a url.
149    */
150   bool LoadTextures();
151
152   /**
153    * Helper method to set individual values by index key.
154    * @param[in] index The index key of the value
155    * @param[in] value The value
156    */
157   void DoSetProperty(Property::Index index, const Property::Value& value);
158
159 private:
160   // Undefined
161   MeshVisual(const MeshVisual& meshVisual);
162
163   // Undefined
164   MeshVisual& operator=(const MeshVisual& meshVisual);
165
166 private:
167   std::string mObjectUrl;
168   std::string mMaterialUrl;
169
170   std::string mDiffuseTextureUrl;
171   std::string mNormalTextureUrl;
172   std::string mGlossTextureUrl;
173   std::string mTexturesPath;
174
175   Shader     mShader;
176   Geometry   mGeometry;
177   TextureSet mTextureSet;
178
179   ObjLoader mObjLoader;
180   Vector3   mSceneCenter;
181   Vector3   mSceneSize;
182
183   Vector3                                 mLightPosition;
184   Toolkit::MeshVisual::ShadingMode::Value mShadingMode;
185
186   bool mUseTexture;
187   bool mUseMipmapping;
188   bool mUseSoftNormals;
189 };
190
191 } // namespace Internal
192
193 } // namespace Toolkit
194
195 } // namespace Dali
196
197 #endif /* DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H */