51729fd74cf91d0f9493926910359609c51b2008
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / MeshVisual.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// A class encapsulating the property map of the mesh visual.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class MeshVisual : VisualMap
25     {
26         private string _objectURL = null;
27         private string _materialtURL = null;
28         private string _texturesPath = null;
29         private MeshVisualShadingModeValue? _shadingMode = null;
30         private bool? _useMipmapping = null;
31         private bool? _useSoftNormals = null;
32         private Vector3 _lightPosition = null;
33
34         /// <summary>
35         /// Constructor.
36         /// </summary>
37         /// <since_tizen> 3 </since_tizen>
38         public MeshVisual() : base()
39         {
40         }
41
42         /// <summary>
43         /// Gets or sets the location of the ".obj" file.<br />
44         /// Mandatory.
45         /// </summary>
46         /// <since_tizen> 3 </since_tizen>
47         public string ObjectURL
48         {
49             get
50             {
51                 return _objectURL;
52             }
53             set
54             {
55                 _objectURL = value;
56                 UpdateVisual();
57             }
58         }
59
60         /// <summary>
61         /// Gets or sets the location of the ".mtl" file.<br />
62         /// If not specified, then a textureless object is assumed.<br />
63         /// Optional.
64         /// </summary>
65         /// <since_tizen> 3 </since_tizen>
66         public string MaterialtURL
67         {
68             get
69             {
70                 return _materialtURL;
71             }
72             set
73             {
74                 _materialtURL = value;
75                 UpdateVisual();
76             }
77         }
78
79         /// <summary>
80         /// Gets or sets the path to the directory the textures (including gloss and normal) are stored in.<br />
81         /// Mandatory if using material.<br />
82         /// </summary>
83         /// <since_tizen> 3 </since_tizen>
84         public string TexturesPath
85         {
86             get
87             {
88                 return _texturesPath;
89             }
90             set
91             {
92                 _texturesPath = value;
93                 UpdateVisual();
94             }
95         }
96
97         /// <summary>
98         /// Gets or sets the type of shading mode that the mesh will use.<br />
99         /// If anything the specified shading mode requires is missing, a simpler mode that can be handled with what has been supplied will be used instead.<br />
100         /// If not specified, it will use the best it can support (will try MeshVisualShadingModeValue.TexturedWithDetailedSpecularLighting first).<br />
101         /// Optional.
102         /// </summary>
103         /// <since_tizen> 3 </since_tizen>
104         public MeshVisualShadingModeValue ShadingMode
105         {
106             get
107             {
108                 return _shadingMode ?? (MeshVisualShadingModeValue.TexturedWithDetailedSpecularLighting);
109             }
110             set
111             {
112                 _shadingMode = value;
113                 UpdateVisual();
114             }
115         }
116
117         /// <summary>
118         /// Gets or sets whether to use mipmaps for textures or not.<br />
119         /// If not specified, the default is true.<br />
120         /// Optional.
121         /// </summary>
122         /// <since_tizen> 3 </since_tizen>
123         public bool UseMipmapping
124         {
125             get
126             {
127                 return _useMipmapping ?? (true);
128             }
129             set
130             {
131                 _useMipmapping = value;
132                 UpdateVisual();
133             }
134         }
135
136         /// <summary>
137         /// Gets or sets whether to average normals at each point to smooth textures or not.<br />
138         /// If not specified, the default is true.<br />
139         /// Optional.
140         /// </summary>
141         /// <since_tizen> 3 </since_tizen>
142         public bool UseSoftNormals
143         {
144             get
145             {
146                 return _useSoftNormals ?? (true);
147             }
148             set
149             {
150                 _useSoftNormals = value;
151                 UpdateVisual();
152             }
153         }
154
155         /// <summary>
156         /// Gets or sets the position, in the stage space, of the point light that applies lighting to the model.<br />
157         /// This is based off the stage's dimensions, so using the width and the height of the stage halved will correspond to the center,
158         /// and using all zeroes will place the light at the top-left corner.<br />
159         /// If not specified, the default is an offset outwards from the center of the screen.<br />
160         /// Optional.
161         /// </summary>
162         /// <since_tizen> 3 </since_tizen>
163         public Vector3 LightPosition
164         {
165             get
166             {
167                 return _lightPosition;
168             }
169             set
170             {
171                 _lightPosition = value;
172                 UpdateVisual();
173             }
174         }
175
176         /// <summary>
177         /// Compose the out visual map.
178         /// </summary>
179         /// <since_tizen> 3 </since_tizen>
180         protected override void ComposingPropertyMap()
181         {
182             if (_objectURL != null)
183             {
184                 _outputVisualMap = new PropertyMap();
185                 _outputVisualMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Mesh));
186                 _outputVisualMap.Add(MeshVisualProperty.ObjectURL, new PropertyValue(_objectURL));
187                 if (_materialtURL != null) { _outputVisualMap.Add(MeshVisualProperty.MaterialtURL, new PropertyValue(_materialtURL)); }
188                 if (_texturesPath != null) { _outputVisualMap.Add(MeshVisualProperty.TexturesPath, new PropertyValue(_texturesPath)); }
189                 if (_shadingMode != null) { _outputVisualMap.Add(MeshVisualProperty.ShadingMode, new PropertyValue((int)_shadingMode)); }
190                 if (_useMipmapping != null) { _outputVisualMap.Add(MeshVisualProperty.UseMipmapping, new PropertyValue((bool)_useMipmapping)); }
191                 if (_useSoftNormals != null) { _outputVisualMap.Add(MeshVisualProperty.UseSoftNormals, new PropertyValue((bool)_useSoftNormals)); }
192                 base.ComposingPropertyMap();
193             }
194         }
195     }
196 }