BsScriptMesh.h 3.4 KB

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