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