Renderable2.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Rendering
  8. * @{
  9. */
  10. /// <summary>
  11. /// Renderable represents any visible object in the scene. It has a mesh, bounds and a set of materials. Renderer will
  12. /// render any Renderable objects visible by a camera.
  13. /// </summary>
  14. [RunInEditor]
  15. public sealed class Renderable2 : Component
  16. {
  17. /// <summary>
  18. /// Mesh to render.
  19. /// </summary>
  20. public Mesh Mesh
  21. {
  22. get { return Internal_GetMesh(mCachedPtr); }
  23. set
  24. {
  25. IntPtr meshPtr = IntPtr.Zero;
  26. if (value != null)
  27. meshPtr = value.GetCachedPtr();
  28. Internal_SetMesh(mCachedPtr, meshPtr);
  29. }
  30. }
  31. /// <summary>
  32. /// Material to use when rendering the mesh. If the mesh contains multiple sub-meshes then you may set individual
  33. /// materials for each sub-mesh.
  34. /// </summary>
  35. public Material Material
  36. {
  37. get { return Internal_GetMaterial(mCachedPtr, 0); }
  38. set
  39. {
  40. IntPtr materialPtr = IntPtr.Zero;
  41. if (value != null)
  42. materialPtr = value.GetCachedPtr();
  43. Internal_SetMaterial(mCachedPtr, materialPtr, 0);
  44. }
  45. }
  46. /// <summary>
  47. /// Materials to use when rendering the mesh.
  48. /// </summary>
  49. public Material[] Materials
  50. {
  51. get { return Internal_GetMaterials(mCachedPtr); }
  52. set { Internal_SetMaterials(mCachedPtr, value); }
  53. }
  54. /// <summary>
  55. /// Returns a material for a specific sub-mesh.
  56. /// </summary>
  57. /// <param name="index">Index of the sub-mesh.</param>
  58. /// <returns>Material used for rendering the sub-mesh at the specified index.</returns>
  59. public Material GetMaterial(int index = 0)
  60. {
  61. return Internal_GetMaterial(mCachedPtr, index);
  62. }
  63. /// <summary>
  64. /// Sets a material for a specific sub-mesh.
  65. /// </summary>
  66. /// <param name="material">Material to use for rendering the sub-mesh at the specified index.</param>
  67. /// <param name="index">Index of the sub-mesh.</param>
  68. public void SetMaterial(Material material, int index = 0)
  69. {
  70. IntPtr materialPtr = IntPtr.Zero;
  71. if (material != null)
  72. materialPtr = material.GetCachedPtr();
  73. Internal_SetMaterial(mCachedPtr, materialPtr, index);
  74. }
  75. /// <summary>
  76. /// Layer bitfield that controls whether a renderable is considered visible in a specific camera. Renderable layer
  77. /// must match camera layer in order for the camera to render the component.
  78. /// </summary>
  79. public UInt64 Layers
  80. {
  81. get { return Internal_GetLayers(mCachedPtr); }
  82. set { Internal_SetLayers(mCachedPtr, value); }
  83. }
  84. /// <summary>
  85. /// Gets world bounds of the mesh rendered by this object.
  86. /// </summary>
  87. public Bounds Bounds
  88. {
  89. get
  90. {
  91. AABox box;
  92. Sphere sphere;
  93. Internal_GetBounds(mCachedPtr, out box, out sphere);
  94. return new Bounds(box, sphere);
  95. }
  96. }
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern Mesh Internal_GetMesh(IntPtr thisPtr);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_SetMesh(IntPtr thisPtr, IntPtr mesh);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_GetBounds(IntPtr thisPtr, out AABox box, out Sphere sphere);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern UInt64 Internal_GetLayers(IntPtr thisPtr);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_SetLayers(IntPtr thisPtr, UInt64 layers);
  107. [MethodImpl(MethodImplOptions.InternalCall)]
  108. private static extern Material Internal_GetMaterial(IntPtr thisPtr, int index);
  109. [MethodImpl(MethodImplOptions.InternalCall)]
  110. private static extern void Internal_SetMaterial(IntPtr thisPtr, IntPtr material, int index);
  111. [MethodImpl(MethodImplOptions.InternalCall)]
  112. private static extern Material[] Internal_GetMaterials(IntPtr thisPtr);
  113. [MethodImpl(MethodImplOptions.InternalCall)]
  114. private static extern void Internal_SetMaterials(IntPtr thisPtr, Material[] materials);
  115. }
  116. /** @} */
  117. }