2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Scene3D
28 /// Class for setting Material properties of 3D models.
31 /// This Material class is for setting Material properties of 3D models.
32 /// This Material supports properties and textures for PBR. Also, Material
33 /// can be shared with multiple ModelPrimitives and if the value is modified,
34 /// the rendering results of all ModelPrimitives using this Material will be changed.
38 /// Material material = new Material();
39 /// ModelPrimitive modelPrimitive = new ModelPrimitive();
40 /// modelPrimitive.Material = material;
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public class Material : BaseHandle
46 internal Material(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
51 /// Create an initialized Material.
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public Material() : this(Interop.Material.MaterialNew(), true)
56 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62 /// <param name="material">Source object to copy.</param>
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 public Material(Material material) : this(Interop.Material.NewMaterial(Material.getCPtr(material)), true)
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 /// Assignment operator.
72 /// <param name="material">Source object to be assigned.</param>
73 /// <returns>Reference to this.</returns>
74 internal Material Assign(Material material)
76 Material ret = new Material(Interop.Material.MaterialAssign(SwigCPtr, Material.getCPtr(material)), false);
77 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 /// The name of the Material.
85 /// This Name property is for setting the name of Material. The name can be used to identify the Material.
87 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
88 [EditorBrowsable(EditorBrowsableState.Never)]
93 var temp = new Tizen.NUI.PropertyValue(value);
94 SetProperty(Interop.Material.PropertyNameIndexGet(), temp);
100 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNameIndexGet());
101 pValue.Get(out temp);
108 /// Property for the URL of the base color texture.
111 /// This texture represents the base color of the material.
113 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public string BaseColorUrl
119 var temp = new Tizen.NUI.PropertyValue(value);
120 SetProperty(Interop.Material.PropertyBaseColorUrlIndexGet(), temp);
126 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyBaseColorUrlIndexGet());
127 pValue.Get(out temp);
134 /// Property for the base color factor of the material.
137 /// This factor is multiplied with the base color of the material.
139 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public Vector4 BaseColorFactor
145 var temp = new Tizen.NUI.PropertyValue(value);
146 SetProperty(Interop.Material.PropertyBaseColorFactorIndexGet(), temp);
151 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
152 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyBaseColorFactorIndexGet());
160 /// Property for the URL of the metallic roughness texture.
163 /// This texture represents the metallicness and roughness of the material.
165 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public string MetallicRoughnessUrl
171 var temp = new Tizen.NUI.PropertyValue(value);
172 SetProperty(Interop.Material.PropertyMetallicRoughnessUrlIndexGet(), temp);
178 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyMetallicRoughnessUrlIndexGet());
179 pValue.Get(out temp);
186 /// Property for the metallic factor of the material.
189 /// This factor is multiplied with the metallicness of the material.
191 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 public float MetallicFactor
197 var temp = new Tizen.NUI.PropertyValue(value);
198 SetProperty(Interop.Material.PropertyMetallicFactorIndexGet(), temp);
204 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyMetallicFactorIndexGet());
205 pValue.Get(out temp);
212 /// Property for the roughness factor of the material.
215 /// This factor is multiplied with the roughness of the material.
217 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
218 [EditorBrowsable(EditorBrowsableState.Never)]
219 public float RoughnessFactor
223 var temp = new Tizen.NUI.PropertyValue(value);
224 SetProperty(Interop.Material.PropertyRoughnessFactorIndexGet(), temp);
230 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyRoughnessFactorIndexGet());
231 pValue.Get(out temp);
238 /// Property for the URL of the normal texture.
240 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public string NormalUrl
246 var temp = new Tizen.NUI.PropertyValue(value);
247 SetProperty(Interop.Material.PropertyNormalUrlIndexGet(), temp);
253 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNormalUrlIndexGet());
254 pValue.Get(out temp);
261 /// Property for the scale of the normal texture.
263 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public float NormalScale
269 var temp = new Tizen.NUI.PropertyValue(value);
270 SetProperty(Interop.Material.PropertyNormalScaleIndexGet(), temp);
276 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNormalScaleIndexGet());
277 pValue.Get(out temp);
284 /// Property for the URL of the occlusion texture.
286 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public string OcclusionUrl
292 var temp = new Tizen.NUI.PropertyValue(value);
293 SetProperty(Interop.Material.PropertyOcclusionUrlIndexGet(), temp);
299 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyOcclusionUrlIndexGet());
300 pValue.Get(out temp);
307 /// Property for the strength of the occlusion texture.
309 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public float OcclusionStrength
315 var temp = new Tizen.NUI.PropertyValue(value);
316 SetProperty(Interop.Material.PropertyOcclusionStrengthIndexGet(), temp);
322 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyOcclusionStrengthIndexGet());
323 pValue.Get(out temp);
330 /// Property for the URL of the emissive texture.
332 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
333 [EditorBrowsable(EditorBrowsableState.Never)]
334 public string EmissiveUrl
338 var temp = new Tizen.NUI.PropertyValue(value);
339 SetProperty(Interop.Material.PropertyEmissiveUrlIndexGet(), temp);
345 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyEmissiveUrlIndexGet());
346 pValue.Get(out temp);
353 /// Property for the emissive factor of the material.
355 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
356 [EditorBrowsable(EditorBrowsableState.Never)]
357 public Vector3 EmissiveFactor
361 var temp = new Tizen.NUI.PropertyValue(value);
362 SetProperty(Interop.Material.PropertyEmissiveFactorIndexGet(), temp);
367 Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
368 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyEmissiveFactorIndexGet());
376 /// Property for the alpha blending mode of the material.
378 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
379 [EditorBrowsable(EditorBrowsableState.Never)]
380 public MaterialAlphaModeType AlphaMode
384 var temp = new Tizen.NUI.PropertyValue((int)value);
385 SetProperty(Interop.Material.PropertyAlphaModeIndexGet(), temp);
391 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyAlphaModeIndexGet());
392 pValue.Get(out temp);
394 return (MaterialAlphaModeType)temp;
399 /// Property for the alpha cutoff value of the material.
401 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
402 [EditorBrowsable(EditorBrowsableState.Never)]
403 public float AlphaCutoff
407 var temp = new Tizen.NUI.PropertyValue(value);
408 SetProperty(Interop.Material.PropertyAlphaCutOffIndexGet(), temp);
414 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyAlphaCutOffIndexGet());
415 pValue.Get(out temp);
422 /// Property for the double sided material flag.
424 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
425 [EditorBrowsable(EditorBrowsableState.Never)]
426 public bool DoubleSided
430 var temp = new Tizen.NUI.PropertyValue(value);
431 SetProperty(Interop.Material.PropertyDoubleSidedIndexGet(), temp);
437 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyDoubleSidedIndexGet());
438 pValue.Get(out temp);
445 /// Property for the index of refraction of the material.
447 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
448 [EditorBrowsable(EditorBrowsableState.Never)]
453 var temp = new Tizen.NUI.PropertyValue(value);
454 SetProperty(Interop.Material.PropertyIorIndexGet(), temp);
460 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyIorIndexGet());
461 pValue.Get(out temp);
468 /// Property for the URL of the specular texture.
470 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 public string SpecularUrl
476 var temp = new Tizen.NUI.PropertyValue(value);
477 SetProperty(Interop.Material.PropertySpecularUrlIndexGet(), temp);
483 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularUrlIndexGet());
484 pValue.Get(out temp);
494 /// Property for the specular factor of the material.
496 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
497 [EditorBrowsable(EditorBrowsableState.Never)]
498 public float SpecularFactor
502 var temp = new Tizen.NUI.PropertyValue(value);
503 SetProperty(Interop.Material.PropertySpecularFactorIndexGet(), temp);
509 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularFactorIndexGet());
510 pValue.Get(out temp);
517 /// Property for the URL of the specular color texture.
519 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
520 [EditorBrowsable(EditorBrowsableState.Never)]
521 public string SpecularColorUrl
525 var temp = new Tizen.NUI.PropertyValue(value);
526 SetProperty(Interop.Material.PropertySpecularColorUrlIndexGet(), temp);
532 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularColorUrlIndexGet());
533 pValue.Get(out temp);
540 /// Property for the specular color factor of the material.
542 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
543 [EditorBrowsable(EditorBrowsableState.Never)]
544 public Vector3 SpecularColorFactor
548 var temp = new Tizen.NUI.PropertyValue(value);
549 SetProperty(Interop.Material.PropertySpecularColorFactorIndexGet(), temp);
554 Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
555 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularColorFactorIndexGet());
567 /// Sets the texture of the ModelNode object for the specified texture type.
569 /// <param name="textureType">The TextureType of the texture to set.</param>
570 /// <param name="texture">The Texture object to set.</param>
571 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
572 [EditorBrowsable(EditorBrowsableState.Never)]
573 public void SetTexture(MaterialTextureType textureType, Texture texture)
575 Interop.Material.SetTexture(SwigCPtr, (int)textureType, Texture.getCPtr(texture));
576 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
580 /// Gets the texture of the ModelNode object for the specified texture type.
582 /// <param name="textureType">The TextureType of the texture to get.</param>
583 /// <returns>The Texture object of the ModelNode object for the specified texture type.</returns>
584 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
585 [EditorBrowsable(EditorBrowsableState.Never)]
586 public Texture GetTexture(MaterialTextureType textureType)
588 IntPtr cPtr = Interop.Material.GetTexture(SwigCPtr, (int)textureType);
589 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
590 Texture ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture;
595 /// Sets the sampler of the ModelNode object for the specified texture type.
597 /// <param name="textureType">The TextureType of the sampler to set.</param>
598 /// <param name="sampler">The Sampler object to set.</param>
599 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
600 [EditorBrowsable(EditorBrowsableState.Never)]
601 public void SetSampler(MaterialTextureType textureType, Sampler sampler)
603 Interop.Material.SetSampler(SwigCPtr, (int)textureType, Sampler.getCPtr(sampler));
604 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608 /// Gets the sampler of the ModelNode object for the specified texture type.
610 /// <param name="textureType">The TextureType of the sampler to get.</param>
611 /// <returns>The Sampler object of the ModelNode object for the specified texture type.</returns>
612 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
613 [EditorBrowsable(EditorBrowsableState.Never)]
614 public Sampler GetSampler(MaterialTextureType textureType)
616 IntPtr cPtr = Interop.Material.GetSampler(SwigCPtr, (int)textureType);
617 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
618 Sampler ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Sampler;
623 /// Sets the value of an existing property.
625 /// <param name="index">The index of the property.</param>
626 /// <param name="propertyValue">The new value of the property.</param>
627 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
628 [EditorBrowsable(EditorBrowsableState.Never)]
629 private void SetProperty(int index, PropertyValue propertyValue)
631 global::System.Runtime.InteropServices.HandleRef handle = SwigCPtr;
632 if (handle.Handle == global::System.IntPtr.Zero)
634 throw new global::System.InvalidOperationException("Error! NUI's native dali object is already disposed. OR the native dali object handle of NUI becomes null!");
637 Interop.Material.SetProperty(handle, index, PropertyValue.getCPtr(propertyValue));
638 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
642 /// Retrieves a property value.
644 /// <param name="index">The index of the property.</param>
645 /// <returns>The property value.</returns>
646 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
647 [EditorBrowsable(EditorBrowsableState.Never)]
648 private PropertyValue GetProperty(int index)
650 global::System.Runtime.InteropServices.HandleRef handle = SwigCPtr;
651 if (handle.Handle == global::System.IntPtr.Zero)
653 throw new global::System.InvalidOperationException("Error! NUI's native dali object is already disposed. OR the native dali object handle of NUI becomes null!");
656 PropertyValue ret = new PropertyValue(Interop.Material.GetProperty(handle, index), true);
657 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
662 /// Release swigCPtr.
664 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
665 [EditorBrowsable(EditorBrowsableState.Never)]
666 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
668 Interop.Material.DeleteMaterial(swigCPtr);