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) : this(cPtr, cMemoryOwn, cMemoryOwn)
50 internal Material(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
55 /// Create an initialized Material.
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public Material() : this(Interop.Material.MaterialNew(), true)
60 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// <param name="material">Source object to copy.</param>
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 public Material(Material material) : this(Interop.Material.NewMaterial(Material.getCPtr(material)), true, false)
70 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 /// Assignment operator.
76 /// <param name="material">Source object to be assigned.</param>
77 /// <returns>Reference to this.</returns>
78 internal Material Assign(Material material)
80 Material ret = new Material(Interop.Material.MaterialAssign(SwigCPtr, Material.getCPtr(material)), false);
81 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86 /// The name of the Material.
89 /// This Name property is for setting the name of Material. The name can be used to identify the Material.
91 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
92 [EditorBrowsable(EditorBrowsableState.Never)]
97 var temp = new Tizen.NUI.PropertyValue(value);
98 SetProperty(Interop.Material.PropertyNameIndexGet(), temp);
104 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNameIndexGet());
105 pValue.Get(out temp);
112 /// Property for the URL of the base color texture.
115 /// This texture represents the base color of the material.
117 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public string BaseColorUrl
123 var temp = new Tizen.NUI.PropertyValue(value);
124 SetProperty(Interop.Material.PropertyBaseColorUrlIndexGet(), temp);
130 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyBaseColorUrlIndexGet());
131 pValue.Get(out temp);
138 /// Property for the base color factor of the material.
141 /// This factor is multiplied with the base color of the material.
143 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public Vector4 BaseColorFactor
149 var temp = new Tizen.NUI.PropertyValue(value);
150 SetProperty(Interop.Material.PropertyBaseColorFactorIndexGet(), temp);
155 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
156 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyBaseColorFactorIndexGet());
164 /// Property for the URL of the metallic roughness texture.
167 /// This texture represents the metallicness and roughness of the material.
169 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public string MetallicRoughnessUrl
175 var temp = new Tizen.NUI.PropertyValue(value);
176 SetProperty(Interop.Material.PropertyMetallicRoughnessUrlIndexGet(), temp);
182 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyMetallicRoughnessUrlIndexGet());
183 pValue.Get(out temp);
190 /// Property for the metallic factor of the material.
193 /// This factor is multiplied with the metallicness of the material.
195 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public float MetallicFactor
201 var temp = new Tizen.NUI.PropertyValue(value);
202 SetProperty(Interop.Material.PropertyMetallicFactorIndexGet(), temp);
208 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyMetallicFactorIndexGet());
209 pValue.Get(out temp);
216 /// Property for the roughness factor of the material.
219 /// This factor is multiplied with the roughness of the material.
221 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public float RoughnessFactor
227 var temp = new Tizen.NUI.PropertyValue(value);
228 SetProperty(Interop.Material.PropertyRoughnessFactorIndexGet(), temp);
234 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyRoughnessFactorIndexGet());
235 pValue.Get(out temp);
242 /// Property for the URL of the normal texture.
244 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public string NormalUrl
250 var temp = new Tizen.NUI.PropertyValue(value);
251 SetProperty(Interop.Material.PropertyNormalUrlIndexGet(), temp);
257 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNormalUrlIndexGet());
258 pValue.Get(out temp);
265 /// Property for the scale of the normal texture.
267 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public float NormalScale
273 var temp = new Tizen.NUI.PropertyValue(value);
274 SetProperty(Interop.Material.PropertyNormalScaleIndexGet(), temp);
280 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyNormalScaleIndexGet());
281 pValue.Get(out temp);
288 /// Property for the URL of the occlusion texture.
290 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
291 [EditorBrowsable(EditorBrowsableState.Never)]
292 public string OcclusionUrl
296 var temp = new Tizen.NUI.PropertyValue(value);
297 SetProperty(Interop.Material.PropertyOcclusionUrlIndexGet(), temp);
303 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyOcclusionUrlIndexGet());
304 pValue.Get(out temp);
311 /// Property for the strength of the occlusion texture.
313 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
314 [EditorBrowsable(EditorBrowsableState.Never)]
315 public float OcclusionStrength
319 var temp = new Tizen.NUI.PropertyValue(value);
320 SetProperty(Interop.Material.PropertyOcclusionStrengthIndexGet(), temp);
326 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyOcclusionStrengthIndexGet());
327 pValue.Get(out temp);
334 /// Property for the URL of the emissive texture.
336 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public string EmissiveUrl
342 var temp = new Tizen.NUI.PropertyValue(value);
343 SetProperty(Interop.Material.PropertyEmissiveUrlIndexGet(), temp);
349 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyEmissiveUrlIndexGet());
350 pValue.Get(out temp);
357 /// Property for the emissive factor of the material.
359 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
360 [EditorBrowsable(EditorBrowsableState.Never)]
361 public Vector3 EmissiveFactor
365 var temp = new Tizen.NUI.PropertyValue(value);
366 SetProperty(Interop.Material.PropertyEmissiveFactorIndexGet(), temp);
371 Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
372 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyEmissiveFactorIndexGet());
380 /// Property for the alpha blending mode of the material.
382 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 public MaterialAlphaModeType AlphaMode
388 var temp = new Tizen.NUI.PropertyValue((int)value);
389 SetProperty(Interop.Material.PropertyAlphaModeIndexGet(), temp);
395 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyAlphaModeIndexGet());
396 pValue.Get(out temp);
398 return (MaterialAlphaModeType)temp;
403 /// Property for the alpha cutoff value of the material.
405 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
406 [EditorBrowsable(EditorBrowsableState.Never)]
407 public float AlphaCutoff
411 var temp = new Tizen.NUI.PropertyValue(value);
412 SetProperty(Interop.Material.PropertyAlphaCutOffIndexGet(), temp);
418 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyAlphaCutOffIndexGet());
419 pValue.Get(out temp);
426 /// Property for the double sided material flag.
428 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
429 [EditorBrowsable(EditorBrowsableState.Never)]
430 public bool DoubleSided
434 var temp = new Tizen.NUI.PropertyValue(value);
435 SetProperty(Interop.Material.PropertyDoubleSidedIndexGet(), temp);
441 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyDoubleSidedIndexGet());
442 pValue.Get(out temp);
449 /// Property for the index of refraction of the material.
451 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
452 [EditorBrowsable(EditorBrowsableState.Never)]
457 var temp = new Tizen.NUI.PropertyValue(value);
458 SetProperty(Interop.Material.PropertyIorIndexGet(), temp);
464 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyIorIndexGet());
465 pValue.Get(out temp);
472 /// Property for the URL of the specular texture.
474 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
475 [EditorBrowsable(EditorBrowsableState.Never)]
476 public string SpecularUrl
480 var temp = new Tizen.NUI.PropertyValue(value);
481 SetProperty(Interop.Material.PropertySpecularUrlIndexGet(), temp);
487 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularUrlIndexGet());
488 pValue.Get(out temp);
498 /// Property for the specular factor of the material.
500 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
501 [EditorBrowsable(EditorBrowsableState.Never)]
502 public float SpecularFactor
506 var temp = new Tizen.NUI.PropertyValue(value);
507 SetProperty(Interop.Material.PropertySpecularFactorIndexGet(), temp);
513 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularFactorIndexGet());
514 pValue.Get(out temp);
521 /// Property for the URL of the specular color texture.
523 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
524 [EditorBrowsable(EditorBrowsableState.Never)]
525 public string SpecularColorUrl
529 var temp = new Tizen.NUI.PropertyValue(value);
530 SetProperty(Interop.Material.PropertySpecularColorUrlIndexGet(), temp);
536 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularColorUrlIndexGet());
537 pValue.Get(out temp);
544 /// Property for the specular color factor of the material.
546 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
547 [EditorBrowsable(EditorBrowsableState.Never)]
548 public Vector3 SpecularColorFactor
552 var temp = new Tizen.NUI.PropertyValue(value);
553 SetProperty(Interop.Material.PropertySpecularColorFactorIndexGet(), temp);
558 Vector3 temp = new Vector3(0.0f, 0.0f, 0.0f);
559 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertySpecularColorFactorIndexGet());
567 /// Property to define rendering order.
570 /// Depth index is used to defind rendering order. Basically,
571 /// a Renderer that has smaller depth index is rendered earlier.
572 /// In the ordinary DALI UI components has 0 as depth index by default.
573 /// (For the case of Toolkit::Control, its renderer has depth index
574 /// value between [-20, 20] as fallowing the renderer's purpose)
576 /// In the Scene3D cases, the rendering order of each Renderer may need
577 /// to be manually defined to match scene developer's intent.
578 /// Scene3D::DepthIndex::Ranges could be used to adjust rendering order
579 /// between 3D Scene content.
580 /// Or it also could be used to manage UI component in 3D Scene independently.
582 /// Changing the depth index only affects the rendering order, and does not
583 /// mean that objects drawn later will be drawn on top. To compute final
584 /// rendering order, whether the object is opaque or non-opaque takes precedence
585 /// over the depth index. Changing the rendering order among translucent objects
586 /// has a significant impact on the rendering results.
588 /// The predefined depth index range is definded in <see cref="MaterialDepthIndexRange"/>.
590 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
591 [EditorBrowsable(EditorBrowsableState.Never)]
592 public int DepthIndex
596 var temp = new Tizen.NUI.PropertyValue(value);
597 SetProperty(Interop.Material.PropertyDepthIndexIndexGet(), temp);
603 Tizen.NUI.PropertyValue pValue = GetProperty(Interop.Material.PropertyDepthIndexIndexGet());
604 pValue.Get(out temp);
611 /// Sets the texture of the ModelNode object for the specified texture type.
613 /// <param name="textureType">The TextureType of the texture to set.</param>
614 /// <param name="texture">The Texture object to set.</param>
615 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
616 [EditorBrowsable(EditorBrowsableState.Never)]
617 public void SetTexture(MaterialTextureType textureType, Texture texture)
619 Interop.Material.SetTexture(SwigCPtr, (int)textureType, Texture.getCPtr(texture));
620 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
624 /// Gets the texture of the ModelNode object for the specified texture type.
626 /// <param name="textureType">The TextureType of the texture to get.</param>
627 /// <returns>The Texture object of the ModelNode object for the specified texture type.</returns>
628 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
629 [EditorBrowsable(EditorBrowsableState.Never)]
630 public Texture GetTexture(MaterialTextureType textureType)
632 IntPtr cPtr = Interop.Material.GetTexture(SwigCPtr, (int)textureType);
633 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
634 Texture ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture;
639 /// Sets the sampler of the ModelNode object for the specified texture type.
641 /// <param name="textureType">The TextureType of the sampler to set.</param>
642 /// <param name="sampler">The Sampler object to set.</param>
643 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
644 [EditorBrowsable(EditorBrowsableState.Never)]
645 public void SetSampler(MaterialTextureType textureType, Sampler sampler)
647 Interop.Material.SetSampler(SwigCPtr, (int)textureType, Sampler.getCPtr(sampler));
648 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
652 /// Gets the sampler of the ModelNode object for the specified texture type.
654 /// <param name="textureType">The TextureType of the sampler to get.</param>
655 /// <returns>The Sampler object of the ModelNode object for the specified texture type.</returns>
656 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
657 [EditorBrowsable(EditorBrowsableState.Never)]
658 public Sampler GetSampler(MaterialTextureType textureType)
660 IntPtr cPtr = Interop.Material.GetSampler(SwigCPtr, (int)textureType);
661 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
662 Sampler ret = (cPtr == IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Sampler;
667 /// Sets the value of an existing property.
669 /// <param name="index">The index of the property.</param>
670 /// <param name="propertyValue">The new value of the property.</param>
671 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
672 [EditorBrowsable(EditorBrowsableState.Never)]
673 private void SetProperty(int index, PropertyValue propertyValue)
675 global::System.Runtime.InteropServices.HandleRef handle = SwigCPtr;
676 if (handle.Handle == global::System.IntPtr.Zero)
678 throw new global::System.InvalidOperationException("Error! NUI's native dali object is already disposed. OR the native dali object handle of NUI becomes null!");
681 Interop.Material.SetProperty(handle, index, PropertyValue.getCPtr(propertyValue));
682 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
686 /// Retrieves a property value.
688 /// <param name="index">The index of the property.</param>
689 /// <returns>The property value.</returns>
690 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
691 [EditorBrowsable(EditorBrowsableState.Never)]
692 private PropertyValue GetProperty(int index)
694 global::System.Runtime.InteropServices.HandleRef handle = SwigCPtr;
695 if (handle.Handle == global::System.IntPtr.Zero)
697 throw new global::System.InvalidOperationException("Error! NUI's native dali object is already disposed. OR the native dali object handle of NUI becomes null!");
700 PropertyValue ret = new PropertyValue(Interop.Material.GetProperty(handle, index), true);
701 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
706 /// Release swigCPtr.
708 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
709 [EditorBrowsable(EditorBrowsableState.Never)]
710 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
712 Interop.Material.DeleteMaterial(swigCPtr);