1 #ifndef DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
5 * Copyright (c) 2019 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 * @param[in] properties A Property::Map containing settings for this visual
67 * @return A smart-pointer to the newly allocated visual.
69 static MeshVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
71 public: // from Visual
74 * @copydoc Visual::Base::CreatePropertyMap
76 void DoCreatePropertyMap( Property::Map& map ) const override;
79 * @copydoc Visual::Base::CreateInstancePropertyMap
81 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
88 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
90 MeshVisual( VisualFactoryCache& factoryCache );
93 * @brief A reference counted object may only be deleted by calling Unreference().
95 virtual ~MeshVisual();
98 * @copydoc Visual::Base::DoSetProperties
100 void DoSetProperties( const Property::Map& propertyMap ) override;
103 * @copydoc Visual::Base::OnSetTransform
105 void OnSetTransform() override;
108 * @copydoc Visual::Base::DoSetOnScene
110 void DoSetOnScene( Actor& actor ) override;
115 * @brief Provide an empty geometry for the visual to use.
116 * @details For use in error cases where the initialisation has failed for varying reasons.
118 void SupplyEmptyGeometry();
121 * @brief Initialize the visual with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
123 void InitializeRenderer();
126 * @brief Create a shader for the object to use.
131 * @brief Update shader related info, uniforms, etc. for the new shader.
133 void UpdateShaderUniforms();
136 * @brief Use the object URL stored in the mesh visual to load and create the geometry of the object.
137 * @return Boolean of success of operation.
139 bool CreateGeometry();
142 * @brief Use the object URL stored in the visual to load the geometry of the object.
143 * @return Boolean of success of operation.
148 * @brief Use the material URL stored in the mesh visual to load the material of the object.
149 * @return Boolean of success of operation.
154 * @brief Use the image and texture URL components to load the different types of texture.
155 * @return Boolean of success of operation. Returns false if any texture fails to load from a url.
160 * Helper method to set individual values by index key.
161 * @param[in] index The index key of the value
162 * @param[in] value The value
164 void DoSetProperty( Property::Index index, const Property::Value& value );
169 MeshVisual( const MeshVisual& meshVisual );
172 MeshVisual& operator=( const MeshVisual& meshVisual );
176 std::string mObjectUrl;
177 std::string mMaterialUrl;
179 std::string mDiffuseTextureUrl;
180 std::string mNormalTextureUrl;
181 std::string mGlossTextureUrl;
182 std::string mTexturesPath;
186 TextureSet mTextureSet;
188 ObjLoader mObjLoader;
189 Vector3 mSceneCenter;
192 Vector3 mLightPosition;
193 Toolkit::MeshVisual::ShadingMode::Value mShadingMode;
197 bool mUseSoftNormals;
200 } // namespace Internal
202 } // namespace Toolkit
206 #endif /* DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H */