Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / model3d-view / model3d-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_MODEL3D_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_MODEL3D_VIEW_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/rendering/renderer.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/model3d-view/model3d-view.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 class Model3dView;
34
35 namespace Internal
36 {
37 /**
38  * @brief Impl class for Model3dView.
39  *
40  * All the geometry loaded with the control is automatically centered and scaled to fit
41  * the size of all the other controls. So the max is (0.5,0.5) and the min is (-0.5,-0.5)
42 */
43 class Model3dView : public Control
44 {
45 public:
46   /**
47    * @brief Create a new Model3dView.
48    *
49    * @return A public handle to the newly allocated Model3dView.
50    */
51   static Toolkit::Model3dView New();
52
53   // Properties
54
55   /**
56    * @brief Called when a property of an object of this type is set.
57    *
58    * @param[in] object The object whose property is set.
59    * @param[in] index The property index.
60    * @param[in] value The new property value.
61    */
62   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
63
64   /**
65    * @brief Called to retrieve a property of an object of this type.
66    *
67    * @param[in] object The object whose property is to be retrieved.
68    * @param[in] index The property index.
69    * @return The current value of the property.
70    */
71   static Property::Value GetProperty(BaseObject* object, Property::Index index);
72
73   /**
74    * @copydoc Control::OnRelayout
75    */
76   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
77
78   /**
79    * @brief Called to load both geometry (.obj) and material (.mtl) files
80    *
81    */
82   void Load();
83
84 protected:
85   /**
86    * @brief Construct a new Model3dView.
87    */
88   Model3dView();
89
90   /**
91    * A reference counted object may only be deleted by calling Unreference()
92    */
93   virtual ~Model3dView();
94
95 private:
96   /**
97    * @copydoc Toolkit::Control::OnInitialize()
98    */
99   void OnInitialize() override;
100
101   /**
102    * @copydoc CustomActorImpl::OnSceneConnection()
103    */
104   void OnSceneConnection(int depth) override;
105
106 private:
107   /**
108    * @brief Load geometry (.obj) from file
109    */
110   void LoadGeometry();
111
112   /**
113    * @brief Load material (.mtl) from file
114    */
115   void LoadMaterial();
116
117   /**
118    * @brief Create Geometry class from the loaded geometry
119    */
120   void CreateGeometry();
121
122   /**
123    * @brief Create Material and Shader classes from the loaded material
124    */
125   void CreateMaterial();
126
127   /**
128    * @brief Load samplers and add them to Material
129    */
130   void LoadTextures();
131
132   /**
133    * @brief Set matrix to shader to orientate geometry
134    */
135   void UpdateView();
136
137   /**
138    * @brief Update shader uniforms
139    */
140   void UpdateShaderUniforms();
141
142   /*
143    * @brief Given a specific shader type, find out which properties are necessary for it.
144    *
145    * @param[in] illuminationType The type of shader we intend to use.
146    * @return A bitmask of the properties we require to be loaded to use the given shader.
147    */
148   int GetShaderProperties(Toolkit::Model3dView::IlluminationType illuminationType);
149
150   ObjLoader mObjLoader;
151
152   //Properties
153   std::string                            mObjUrl;
154   std::string                            mTextureSetUrl;
155   std::string                            mImagesUrl;
156   std::string                            mTexture0Url;
157   std::string                            mTexture1Url;
158   std::string                            mTexture2Url;
159   Vector3                                mLightPosition;
160   float                                  mCameraFOV;
161   Toolkit::Model3dView::IlluminationType mIlluminationType;
162
163   //Size
164   Vector2 mControlSize;
165   Vector3 mSceneCenter;
166   Vector3 mSceneSize;
167
168   //Render members
169   Shader     mShader;
170   TextureSet mTextureSet;
171   Geometry   mMesh;
172   Renderer   mRenderer;
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178 inline Toolkit::Internal::Model3dView& GetImpl(Toolkit::Model3dView& obj)
179 {
180   DALI_ASSERT_ALWAYS(obj);
181   Dali::RefObject& handle = obj.GetImplementation();
182   return static_cast<Toolkit::Internal::Model3dView&>(handle);
183 }
184
185 inline const Toolkit::Internal::Model3dView& GetImpl(const Toolkit::Model3dView& obj)
186 {
187   DALI_ASSERT_ALWAYS(obj);
188   const Dali::RefObject& handle = obj.GetImplementation();
189   return static_cast<const Toolkit::Internal::Model3dView&>(handle);
190 }
191
192 } // namespace Toolkit
193
194 } // namespace Dali
195
196 #endif // DALI_TOOLKIT_INTERNAL_MODEL_VIEW_H