1 #ifndef DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <dali/public-api/common/intrusive-ptr.h>
27 #include <dali-toolkit/public-api/visuals/mesh-visual-properties.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
41 typedef IntrusivePtr< MeshVisual > MeshVisualPtr;
44 * The visual which renders a 3D object to the control's quad
46 * The following Property::Map keys are required to create a MeshVisual
48 * | %Property Name | Type | Representing |
49 * |-----------------|-------------|-----------------------------------------------------------------------|
50 * | objectUrl | STRING | A URL to the .obj file |
51 * | materialUrl | STRING | A URL to the .mtl file |
52 * | texturesPath | STRING | A URL of the path to the texture images |
53 * | shadingMode | STRING | An enum of shading modes |
54 * | useMipmapping | BOOLEAN | If true, use mipmaps for textures. Default true. |
55 * | useSoftNormals | BOOLEAN | If true, average normals at points for smooth textures. Default true. |
56 * | lightPosition | VECTOR3 | The position (on stage) of the light |
58 class MeshVisual: public Visual::Base
63 * @brief Create a new mesh visual.
65 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
66 * @return A smart-pointer to the newly allocated visual.
68 static MeshVisualPtr New( VisualFactoryCache& factoryCache );
70 public: // from Visual
73 * @copydoc Visual::Base::SetSize
75 virtual void SetSize( const Vector2& size );
78 * @copydoc Visual::Base::CreatePropertyMap
80 virtual void DoCreatePropertyMap( Property::Map& map ) const;
83 * @copydoc Visual::Base::DoSetProperty
85 virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
88 * @copydoc Visual::Base::DoGetProperty
90 virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
97 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
99 MeshVisual( VisualFactoryCache& factoryCache );
102 * @brief A reference counted object may only be deleted by calling Unreference().
104 virtual ~MeshVisual();
107 * @copydoc Visual::Base::DoSetProperties
109 virtual void DoSetProperties( const Property::Map& propertyMap );
112 * @copydoc Visual::Base::DoSetOnStage
114 virtual void DoSetOnStage( Actor& actor );
119 * Declare whether a texture map should be used for the object, if it's present. Defaults to true.
120 * @param[in] useTexture boolean declaration.
122 void SetUseTexture( bool useTexture );
125 * Declare whether a normal map should be used for the object, if it's present. Defaults to true.
126 * @param[in] useNormalMap boolean declaration.
128 void SetUseNormalMap( bool useNormalMap );
133 * @brief Provide an empty geometry for the visual to use.
134 * @details For use in error cases where the initialisation has failed for varying reasons.
136 void SupplyEmptyGeometry();
139 * @brief Initialize the visual with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
141 void InitializeRenderer();
144 * @brief Create a shader for the object to use.
149 * @brief Update shader related info, uniforms, etc. for the new shader.
151 void UpdateShaderUniforms();
154 * @brief Use the object URL stored in the mesh visual to load and create the geometry of the object.
155 * @return Boolean of success of operation.
157 bool CreateGeometry();
160 * @brief Use the object URL stored in the visual to load the geometry of the object.
161 * @return Boolean of success of operation.
166 * @brief Use the material URL stored in the mesh visual to load the material of the object.
167 * @return Boolean of success of operation.
172 * @brief Use the image and texture URL components to load the different types of texture.
173 * @return Boolean of success of operation. Returns false if any texture fails to load from a url.
180 MeshVisual( const MeshVisual& meshVisual );
183 MeshVisual& operator=( const MeshVisual& meshVisual );
187 std::string mObjectUrl;
188 std::string mMaterialUrl;
190 std::string mDiffuseTextureUrl;
191 std::string mNormalTextureUrl;
192 std::string mGlossTextureUrl;
193 std::string mTexturesPath;
197 TextureSet mTextureSet;
199 ObjLoader mObjLoader;
200 Vector3 mSceneCenter;
203 Vector3 mLightPosition;
204 Toolkit::MeshVisual::ShadingMode::Value mShadingMode;
208 bool mUseSoftNormals;
211 } // namespace Internal
213 } // namespace Toolkit
217 #endif /* DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H */