BsScriptMesh.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 TScriptResource<ScriptMesh, Mesh>
  55. {
  56. public:
  57. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Mesh")
  58. private:
  59. friend class ScriptResourceManager;
  60. ScriptMesh(MonoObject* instance, const HMesh& mesh);
  61. /**
  62. * @brief Converts the C# MeshTopology enum to DrawOperationType enum
  63. * used by engine internals.
  64. */
  65. static DrawOperationType meshTopologyToDrawOp(MeshTopology topology);
  66. /**
  67. * @brief Converts the DrawOperationType enum used by engine
  68. * internals to C# MeshTopology enum.
  69. */
  70. static MeshTopology drawOpToMeshTopology(DrawOperationType drawOp);
  71. /**
  72. * @brief Converts a managed array of SubMeshData%es into an array
  73. * of SubMesh%es used by engine internals.
  74. */
  75. static Vector<SubMesh> monoToNativeSubMeshes(MonoArray* subMeshes);
  76. /************************************************************************/
  77. /* CLR HOOKS */
  78. /************************************************************************/
  79. static void internal_CreateInstance(MonoObject* instance, int numVertices,
  80. int numIndices, MonoArray* subMeshes, MeshUsage usage, VertexLayout vertex, ScriptIndexType index);
  81. static void internal_CreateInstanceMeshData(MonoObject* instance, ScriptMeshData* data, MonoArray* subMeshes,
  82. MeshUsage usage);
  83. static MonoArray* internal_GetSubMeshes(ScriptMesh* thisPtr);
  84. static UINT32 internal_GetSubMeshCount(ScriptMesh* thisPtr);
  85. static void internal_GetBounds(ScriptMesh* thisPtr, AABox* box, Sphere* sphere);
  86. static MonoObject* internal_GetMeshData(ScriptMesh* thisPtr);
  87. static void internal_SetMeshData(ScriptMesh* thisPtr, ScriptMeshData* value);
  88. };
  89. }