1 #ifndef DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
5 * Copyright (c) 2021 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.
22 #include <dali/public-api/common/intrusive-ptr.h>
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>
38 typedef IntrusivePtr<MeshVisual> MeshVisualPtr;
41 * The visual which renders a 3D object to the control's quad
43 * The following Property::Map keys are required to create a MeshVisual
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 |
55 class MeshVisual : public Visual::Base
59 * @brief Create a new mesh visual.
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.
65 static MeshVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
67 public: // from Visual
69 * @copydoc Visual::Base::CreatePropertyMap
71 void DoCreatePropertyMap(Property::Map& map) const override;
74 * @copydoc Visual::Base::CreateInstancePropertyMap
76 void DoCreateInstancePropertyMap(Property::Map& map) const override;
82 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
84 MeshVisual(VisualFactoryCache& factoryCache);
87 * @brief A reference counted object may only be deleted by calling Unreference().
89 virtual ~MeshVisual();
92 * @copydoc Visual::Base::OnInitialize
94 void OnInitialize() override;
97 * @copydoc Visual::Base::DoSetProperties
99 void DoSetProperties(const Property::Map& propertyMap) override;
102 * @copydoc Visual::Base::OnSetTransform
104 void OnSetTransform() override;
107 * @copydoc Visual::Base::DoSetOnScene
109 void DoSetOnScene(Actor& actor) override;
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.
116 void SupplyEmptyGeometry();
119 * @brief Create a shader for the object to use.
124 * @brief Update shader related info, uniforms, etc. for the new shader.
126 void UpdateShaderUniforms();
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.
132 bool CreateGeometry();
135 * @brief Use the object URL stored in the visual to load the geometry of the object.
136 * @return Boolean of success of operation.
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.
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.
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
157 void DoSetProperty(Property::Index index, const Property::Value& value);
161 MeshVisual(const MeshVisual& meshVisual);
164 MeshVisual& operator=(const MeshVisual& meshVisual);
167 std::string mObjectUrl;
168 std::string mMaterialUrl;
170 std::string mDiffuseTextureUrl;
171 std::string mNormalTextureUrl;
172 std::string mGlossTextureUrl;
173 std::string mTexturesPath;
177 TextureSet mTextureSet;
179 ObjLoader mObjLoader;
180 Vector3 mSceneCenter;
183 Vector3 mLightPosition;
184 Toolkit::MeshVisual::ShadingMode::Value mShadingMode;
188 bool mUseSoftNormals;
191 } // namespace Internal
193 } // namespace Toolkit
197 #endif /* DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H */