[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / mesh / mesh-visual.h
index 43e604e..d4765e9 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_MESH_VISUAL_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // EXTERNAL INCLUDES
-#include <fstream>
+#include <dali/public-api/common/intrusive-ptr.h>
 #include <string.h>
+#include <fstream>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-impl.h>
 #include <dali-toolkit/internal/controls/model3d-view/obj-loader.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/public-api/visuals/mesh-visual-properties.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal
 {
+class MeshVisual;
+typedef IntrusivePtr<MeshVisual> MeshVisualPtr;
 
 /**
- * The renderer which renders a 3D object to the control's quad
+ * The visual which renders a 3D object to the control's quad
  *
- * The following Property::Map keys are required to create a MeshRender
+ * The following Property::Map keys are required to create a MeshVisual
  *
  * | %Property Name  | Type        | Representing                                                          |
  * |-----------------|-------------|-----------------------------------------------------------------------|
  * | objectUrl       | STRING      | A URL to the .obj file                                                |
  * | materialUrl     | STRING      | A URL to the .mtl file                                                |
  * | texturesPath    | STRING      | A URL of the path to the texture images                               |
- * | shaderType      | STRING      | An enum of shader types                                               |
+ * | shadingMode     | STRING      | An enum of shading modes                                              |
  * | useMipmapping   | BOOLEAN     | If true, use mipmaps for textures. Default true.                      |
  * | useSoftNormals  | BOOLEAN     | If true, average normals at points for smooth textures. Default true. |
  * | lightPosition   | VECTOR3     | The position (on stage) of the light                                  |
  */
-class MeshVisual: public Visual
+class MeshVisual : public Visual::Base
 {
 public:
-
   /**
-   * @brief Constructor.
+   * @brief Create a new mesh visual.
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] properties A Property::Map containing settings for this visual
+   * @return A smart-pointer to the newly allocated visual.
    */
-  MeshVisual( VisualFactoryCache& factoryCache );
-
-  /**
-   * @brief A reference counted object may only be deleted by calling Unreference().
-   */
-  virtual ~MeshVisual();
-
-public:  // from Visual
+  static MeshVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
 
+public: // from Visual
   /**
-   * @copydoc Visual::SetSize
+   * @copydoc Visual::Base::CreatePropertyMap
    */
-  virtual void SetSize( const Vector2& size );
+  void DoCreatePropertyMap(Property::Map& map) const override;
 
   /**
-   * @copydoc Visual::SetClipRect
+   * @copydoc Visual::Base::CreateInstancePropertyMap
    */
-  virtual void SetClipRect( const Rect<int>& clipRect );
+  void DoCreateInstancePropertyMap(Property::Map& map) const override;
 
+protected:
   /**
-   * @copydoc Visual::SetOffset
+   * @brief Constructor.
+   *
+   * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    */
-  virtual void SetOffset( const Vector2& offset );
+  MeshVisual(VisualFactoryCache& factoryCache);
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @brief A reference counted object may only be deleted by calling Unreference().
    */
-  virtual void DoCreatePropertyMap( Property::Map& map ) const;
-
-protected:
+  virtual ~MeshVisual();
 
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::OnInitialize
    */
-  virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
+  void OnInitialize() override;
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetProperties
    */
-  virtual void DoSetOnStage( Actor& actor );
-
-public:
+  void DoSetProperties(const Property::Map& propertyMap) override;
 
   /**
-   * Declare whether a texture map should be used for the object, if it's present. Defaults to true.
-   * @param[in] useTexture boolean declaration.
+   * @copydoc Visual::Base::OnSetTransform
    */
-  void SetUseTexture( bool useTexture );
+  void OnSetTransform() override;
 
   /**
-   * Declare whether a normal map should be used for the object, if it's present. Defaults to true.
-   * @param[in] useNormalMap boolean declaration.
+   * @copydoc Visual::Base::DoSetOnScene
    */
-  void SetUseNormalMap( bool useNormalMap );
+  void DoSetOnScene(Actor& actor) override;
 
 private:
-
-  //Corresponds to the shader that will be used by the mesh renderer.
-  enum ShaderType
-  {
-    TEXTURELESS,
-    DIFFUSE_TEXTURE,
-    ALL_TEXTURES
-  };
-
   /**
-   * @brief Provide an empty geometry for the renderer to use.
+   * @brief Provide an empty geometry for the visual to use.
    * @details For use in error cases where the initialisation has failed for varying reasons.
    */
   void SupplyEmptyGeometry();
 
   /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
-   */
-  void InitializeRenderer();
-
-  /**
    * @brief Create a shader for the object to use.
    */
   void CreateShader();
@@ -146,19 +126,19 @@ private:
   void UpdateShaderUniforms();
 
   /**
-   * @brief Use the object URL stored in the renderer to load and create the geometry of the object.
+   * @brief Use the object URL stored in the mesh visual to load and create the geometry of the object.
    * @return Boolean of success of operation.
    */
   bool CreateGeometry();
 
   /**
-   * @brief Use the object URL stored in the renderer to load the geometry of the object.
+   * @brief Use the object URL stored in the visual to load the geometry of the object.
    * @return Boolean of success of operation.
    */
   bool LoadGeometry();
 
   /**
-   * @brief Use the material URL stored in the renderer to load the material of the object.
+   * @brief Use the material URL stored in the mesh visual to load the material of the object.
    * @return Boolean of success of operation.
    */
   bool LoadMaterial();
@@ -169,16 +149,21 @@ private:
    */
   bool LoadTextures();
 
-private:
+  /**
+   * Helper method to set individual values by index key.
+   * @param[in] index The index key of the value
+   * @param[in] value The value
+   */
+  void DoSetProperty(Property::Index index, const Property::Value& value);
 
+private:
   // Undefined
-  MeshVisual( const MeshVisual& meshRenderer );
+  MeshVisual(const MeshVisual& meshVisual);
 
   // Undefined
-  MeshVisual& operator=( const MeshVisual& meshRenderer );
+  MeshVisual& operator=(const MeshVisual& meshVisual);
 
 private:
-
   std::string mObjectUrl;
   std::string mMaterialUrl;
 
@@ -187,16 +172,16 @@ private:
   std::string mGlossTextureUrl;
   std::string mTexturesPath;
 
-  Shader mShader;
-  Geometry mGeometry;
+  Shader     mShader;
+  Geometry   mGeometry;
   TextureSet mTextureSet;
 
   ObjLoader mObjLoader;
-  Vector3 mSceneCenter;
-  Vector3 mSceneSize;
+  Vector3   mSceneCenter;
+  Vector3   mSceneSize;
 
-  Vector3 mLightPosition;
-  ShaderType mShaderType;
+  Vector3                                 mLightPosition;
+  Toolkit::MeshVisual::ShadingMode::Value mShadingMode;
 
   bool mUseTexture;
   bool mUseMipmapping;