BsScriptMesh.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptResource.h"
  6. #include "BsScriptMeshData.h"
  7. #include "BsMesh.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Possible mesh toplogy values.
  12. *
  13. * @note Must match C# enum MeshTopology.
  14. */
  15. enum class MeshTopology
  16. {
  17. PointList = 1,
  18. LineList = 2,
  19. LineStrip = 3,
  20. TriangleList = 4,
  21. TriangleStrip = 5,
  22. TriangleFan = 6
  23. };
  24. /**
  25. * @brief Contains data about a portion of a mesh inside MeshData.
  26. */
  27. struct BS_SCR_BE_EXPORT SubMeshData
  28. {
  29. UINT32 indexOffset;
  30. UINT32 indexCount;
  31. MeshTopology topology;
  32. };
  33. /**
  34. * @brief Interop class between C++ & CLR for SubMesh.
  35. */
  36. class BS_SCR_BE_EXPORT ScriptSubMesh : public ScriptObject < ScriptSubMesh >
  37. {
  38. public:
  39. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "SubMesh")
  40. /**
  41. * @brief Unboxes a boxed managed SubMesh struct and returns
  42. * the native version of the structure.
  43. */
  44. static SubMeshData unbox(MonoObject* obj);
  45. /**
  46. * @brief Boxes a native SubMesh struct and returns
  47. * a managed object containing it.
  48. */
  49. static MonoObject* box(const SubMeshData& value);
  50. private:
  51. ScriptSubMesh(MonoObject* instance);
  52. };
  53. /**
  54. * @brief Interop class between C++ & CLR for Mesh.
  55. */
  56. class BS_SCR_BE_EXPORT ScriptMesh : public TScriptResource<ScriptMesh, Mesh>
  57. {
  58. public:
  59. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Mesh")
  60. private:
  61. friend class ScriptResourceManager;
  62. ScriptMesh(MonoObject* instance, const HMesh& mesh);
  63. /**
  64. * @brief Converts the C# MeshTopology enum to DrawOperationType enum
  65. * used by engine internals.
  66. */
  67. static DrawOperationType meshTopologyToDrawOp(MeshTopology topology);
  68. /**
  69. * @brief Converts the DrawOperationType enum used by engine
  70. * internals to C# MeshTopology enum.
  71. */
  72. static MeshTopology drawOpToMeshTopology(DrawOperationType drawOp);
  73. /**
  74. * @brief Converts a managed array of SubMeshData%es into an array
  75. * of SubMesh%es used by engine internals.
  76. */
  77. static Vector<SubMesh> monoToNativeSubMeshes(MonoArray* subMeshes);
  78. /**
  79. * @brief Creates an empty, uninitialized managed instance of the resource interop object.
  80. */
  81. static MonoObject* createInstance();
  82. /************************************************************************/
  83. /* CLR HOOKS */
  84. /************************************************************************/
  85. static void internal_CreateInstance(MonoObject* instance, int numVertices,
  86. int numIndices, MonoArray* subMeshes, MeshUsage usage, VertexLayout vertex, ScriptIndexType index);
  87. static void internal_CreateInstanceMeshData(MonoObject* instance, ScriptMeshData* data, MonoArray* subMeshes,
  88. MeshUsage usage);
  89. static MonoArray* internal_GetSubMeshes(ScriptMesh* thisPtr);
  90. static UINT32 internal_GetSubMeshCount(ScriptMesh* thisPtr);
  91. static void internal_GetBounds(ScriptMesh* thisPtr, AABox* box, Sphere* sphere);
  92. static MonoObject* internal_GetMeshData(ScriptMesh* thisPtr);
  93. static void internal_SetMeshData(ScriptMesh* thisPtr, ScriptMeshData* value);
  94. };
  95. }