RuntimeMeshComponent.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. // Copyright 2016 Chris Conway (Koderz). All Rights Reserved.
  2. #pragma once
  3. #include "Components/MeshComponent.h"
  4. #include "RuntimeMeshCore.h"
  5. #include "RuntimeMeshSection.h"
  6. #include "RuntimeMeshGenericVertex.h"
  7. #include "RuntimeMeshBuilder.h"
  8. #include "PhysicsEngine/ConvexElem.h"
  9. #include "RuntimeMeshComponent.generated.h"
  10. // This set of macros is only meant for argument validation as it will return out of whatever scope.
  11. #if WITH_EDITOR
  12. #define RMC_CHECKINGAME_LOGINEDITOR(Condition, Message, RetVal) \
  13. { if (!(Condition)) \
  14. { \
  15. Log(TEXT(Message), true); \
  16. return RetVal; \
  17. } }
  18. #else
  19. #define RMC_CHECKINGAME_LOGINEDITOR(Condition, Message, RetVal) \
  20. check(Condition && Message);
  21. #endif
  22. #define RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, RetVal) \
  23. RMC_CHECKINGAME_LOGINEDITOR((SectionIndex >= 0), "SectionIndex cannot be negative.", RetVal); \
  24. RMC_CHECKINGAME_LOGINEDITOR((Vertices.Num() > 0), "Vertices length must not be 0.", RetVal); \
  25. RMC_CHECKINGAME_LOGINEDITOR((Triangles.Num() > 0), "Triangles length must not be 0", RetVal);
  26. #define RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, Vertices, Triangles, Positions, RetVal) \
  27. RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, RetVal) \
  28. RMC_CHECKINGAME_LOGINEDITOR((Positions.Num() == Vertices.Num()), "Positions must be the same length as Vertices", RetVal);
  29. #define RMC_VALIDATE_BOUNDINGBOX(BoundingBox, RetVal) \
  30. RMC_CHECKINGAME_LOGINEDITOR(BoundingBox.IsValid, "BoundingBox must be valid.", RetVal);
  31. #define RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
  32. RMC_CHECKINGAME_LOGINEDITOR((SectionIndex >= 0), "SectionIndex cannot be negative.", RetVal); \
  33. RMC_CHECKINGAME_LOGINEDITOR((SectionIndex < MeshSections.Num() && MeshSections[SectionIndex].IsValid()), "Invalid SectionIndex.", RetVal);
  34. #define RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex, RetVal) \
  35. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
  36. RMC_CHECKINGAME_LOGINEDITOR((MeshSections[SectionIndex]->bIsLegacySectionType), "Section is not of legacy type.", RetVal);
  37. #define RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, RetVal) \
  38. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
  39. RMC_CHECKINGAME_LOGINEDITOR((MeshSections[SectionIndex]->IsDualBufferSection()), "Section is not dual buffer.", RetVal);
  40. /*
  41. * This tick function is used to drive the collision cooker. It is enabled for one frame when we need to update collision.
  42. * This keeps from cooking on each individual create/update section as the original PMC did
  43. */
  44. USTRUCT()
  45. struct RUNTIMEMESHCOMPONENT_API FRuntimeMeshComponentPrePhysicsTickFunction : public FTickFunction
  46. {
  47. GENERATED_USTRUCT_BODY()
  48. /* Target RMC to tick */
  49. class URuntimeMeshComponent* Target;
  50. virtual void ExecuteTick(float DeltaTime, ELevelTick TickType, ENamedThreads::Type CurrentThread,
  51. const FGraphEventRef& MyCompletionGraphEvent) override;
  52. virtual FString DiagnosticMessage() override;
  53. };
  54. template<>
  55. #if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION <= 15
  56. struct TStructOpsTypeTraits<FRuntimeMeshComponentPrePhysicsTickFunction> : public TStructOpsTypeTraitsBase
  57. #else
  58. struct TStructOpsTypeTraits<FRuntimeMeshComponentPrePhysicsTickFunction> : public TStructOpsTypeTraitsBase2<FRuntimeMeshComponentPrePhysicsTickFunction>
  59. #endif
  60. {
  61. enum
  62. {
  63. WithCopy = false
  64. };
  65. };
  66. /**
  67. * Component that allows you to specify custom triangle mesh geometry for rendering and collision.
  68. */
  69. UCLASS(HideCategories = (Object, LOD), Meta = (BlueprintSpawnableComponent))
  70. class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, public IInterface_CollisionDataProvider
  71. {
  72. GENERATED_BODY()
  73. private:
  74. /* Creates an mesh section of a specified type at the specified index. */
  75. template<typename SectionType>
  76. TSharedPtr<SectionType> CreateOrResetSection(int32 SectionIndex, bool bWantsSeparatePositionBuffer, bool bInIsLegacySectionType = false)
  77. {
  78. // Ensure sections array is long enough
  79. if (SectionIndex >= MeshSections.Num())
  80. {
  81. MeshSections.SetNum(SectionIndex + 1, false);
  82. }
  83. // Create new section
  84. TSharedPtr<SectionType> NewSection = MakeShareable(new SectionType(bWantsSeparatePositionBuffer));
  85. NewSection->bIsLegacySectionType = bInIsLegacySectionType;
  86. // Store section at index
  87. MeshSections[SectionIndex] = NewSection;
  88. return NewSection;
  89. }
  90. /* Creates a mesh section of an internal type meant for the generic vertex and the old PMC style API */
  91. TSharedPtr<FRuntimeMeshSectionInterface> CreateOrResetSectionLegacyType(int32 SectionIndex, int32 NumUVChannels);
  92. /* Gets the material for a section or the default material if one's not provided. */
  93. UMaterialInterface* GetSectionMaterial(int32 Index)
  94. {
  95. auto Material = GetMaterial(Index);
  96. return Material ? Material : UMaterial::GetDefaultMaterial(MD_Surface);
  97. }
  98. /* Finishes creating a section, including entering it for batch updating, or updating the RT directly */
  99. void CreateSectionInternal(int32 SectionIndex, ESectionUpdateFlags UpdateFlags);
  100. /* Finishes updating a section, including entering it for batch updating, or updating the RT directly */
  101. void UpdateSectionInternal(int32 SectionIndex, bool bHadVertexPositionsUpdate, bool bHadVertexUpdates, bool bHadIndexUpdates, bool bNeedsBoundsUpdate, ESectionUpdateFlags UpdateFlags);
  102. /* Finishes updating a sections positions (Only used if section is dual vertex buffer), including entering it for batch updating, or updating the RT directly */
  103. void UpdateSectionVertexPositionsInternal(int32 SectionIndex, bool bNeedsBoundsUpdate);
  104. /* Finishes updating a sections properties, like visible/casts shadow, a*/
  105. void UpdateSectionPropertiesInternal(int32 SectionIndex, bool bUpdateRequiresProxyRecreateIfStatic);
  106. /* Internal log helper for the templates to be able to use the internal logger */
  107. static void Log(FString Text, bool bIsError = false)
  108. {
  109. if (bIsError)
  110. {
  111. UE_LOG(RuntimeMeshLog, Error, TEXT("%s"), *Text);
  112. }
  113. else
  114. {
  115. UE_LOG(RuntimeMeshLog, Warning, TEXT("%s"), *Text);
  116. }
  117. }
  118. public:
  119. URuntimeMeshComponent(const FObjectInitializer& ObjectInitializer);
  120. /**
  121. * Create/replace a section.
  122. * @param SectionIndex Index of the section to create or replace.
  123. * @param Vertices Vertex buffer all vertex data for this section.
  124. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  125. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  126. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  127. * @param UpdateFlags Flags pertaining to this particular update.
  128. */
  129. template<typename VertexType>
  130. void CreateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, TArray<int32>& Triangles, bool bCreateCollision = false,
  131. EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  132. {
  133. // It is only safe to call these functions from the game thread.
  134. check(IsInGameThread());
  135. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection_VertexType);
  136. // Validate all creation parameters
  137. RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
  138. // Create the section
  139. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, false);
  140. // Set the vertex and index buffers
  141. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  142. Section->UpdateVertexBuffer(Vertices, nullptr, bShouldUseMove);
  143. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  144. // Track collision status and update collision information if necessary
  145. Section->CollisionEnabled = bCreateCollision;
  146. Section->UpdateFrequency = UpdateFrequency;
  147. // Finalize section.
  148. CreateSectionInternal(SectionIndex, UpdateFlags);
  149. }
  150. /**
  151. * Create/replace a section.
  152. * @param SectionIndex Index of the section to create or replace.
  153. * @param Vertices Vertex buffer all vertex data for this section.
  154. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  155. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  156. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  157. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  158. * @param UpdateFlags Flags pertaining to this particular update.
  159. */
  160. template<typename VertexType>
  161. void CreateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, TArray<int32>& Triangles, const FBox& BoundingBox, bool bCreateCollision = false,
  162. EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  163. {
  164. // It is only safe to call these functions from the game thread.
  165. check(IsInGameThread());
  166. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection_VertexType_WithBoundingBox);
  167. // Validate all creation parameters
  168. RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
  169. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  170. // Create the section
  171. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, false);
  172. // Set the vertex and index buffers
  173. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  174. Section->UpdateVertexBuffer(Vertices, &BoundingBox, bShouldUseMove);
  175. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  176. // Track collision status and update collision information if necessary
  177. Section->CollisionEnabled = bCreateCollision;
  178. Section->UpdateFrequency = UpdateFrequency;
  179. // Finalize section.
  180. CreateSectionInternal(SectionIndex, UpdateFlags);
  181. }
  182. /**
  183. * Create/replace a section using 2 vertex buffers. One contains positions only, the other contains all other data. This allows for very efficient updates of the positions of a mesh.
  184. * @param SectionIndex Index of the section to create or replace.
  185. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  186. * @param VertexData Vertex buffer containing everything except position for each vertex.
  187. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  188. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  189. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  190. * @param UpdateFlags Flags pertaining to this particular update.
  191. */
  192. template<typename VertexType>
  193. void CreateMeshSectionDualBuffer(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, TArray<int32>& Triangles, bool bCreateCollision = false,
  194. EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  195. {
  196. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSectionDualBuffer_VertexType);
  197. // Validate all creation parameters
  198. RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions, /*VoidReturn*/);
  199. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, true);
  200. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  201. Section->UpdateVertexPositionBuffer(VertexPositions, nullptr, bShouldUseMove);
  202. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  203. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  204. // Track collision status and update collision information if necessary
  205. Section->CollisionEnabled = bCreateCollision;
  206. Section->UpdateFrequency = UpdateFrequency;
  207. // Finalize section.
  208. CreateSectionInternal(SectionIndex, UpdateFlags);
  209. }
  210. /**
  211. * Create/replace a section using 2 vertex buffers. One contains positions only, the other contains all other data. This allows for very efficient updates of the positions of a mesh.
  212. * @param SectionIndex Index of the section to create or replace.
  213. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  214. * @param VertexData Vertex buffer containing everything except position for each vertex.
  215. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  216. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  217. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  218. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  219. * @param UpdateFlags Flags pertaining to this particular update.
  220. */
  221. template<typename VertexType>
  222. void CreateMeshSectionDualBuffer(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, TArray<int32>& Triangles, const FBox& BoundingBox,
  223. bool bCreateCollision = false, EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  224. {
  225. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSectionDualBuffer_VertexType_WithBoundingBox);
  226. // Validate all creation parameters
  227. RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions, /*VoidReturn*/);
  228. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  229. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, true);
  230. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  231. Section->UpdateVertexPositionBuffer(VertexPositions, &BoundingBox, bShouldUseMove);
  232. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  233. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  234. // Track collision status and update collision information if necessary
  235. Section->CollisionEnabled = bCreateCollision;
  236. Section->UpdateFrequency = UpdateFrequency;
  237. // Finalize section.
  238. CreateSectionInternal(SectionIndex, UpdateFlags);
  239. }
  240. /**
  241. * Updates a section. This is faster than CreateMeshSection. If this is a dual buffer section, you cannot change the length of the vertices.
  242. * @param SectionIndex Index of the section to update.
  243. * @param Vertices Vertex buffer all vertex data for this section, or in the case of dual buffer section it contains everything but position.
  244. * @param UpdateFlags Flags pertaining to this particular update.
  245. */
  246. template<typename VertexType>
  247. void UpdateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  248. {
  249. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType);
  250. // Validate all update parameters
  251. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  252. // Validate section type
  253. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  254. // Cast section to correct type
  255. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  256. // Check dual buffer section status
  257. if (Section->IsDualBufferSection() && Vertices.Num() != Section->VertexBuffer.Num())
  258. {
  259. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  260. return;
  261. }
  262. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  263. bool bNeedsBoundsUpdate = false;
  264. // Update vertices if supplied
  265. bool bUpdatedVertices = false;
  266. if (Vertices.Num() > 0)
  267. {
  268. bNeedsBoundsUpdate = Section->UpdateVertexBuffer(Vertices, nullptr, bShouldUseMove);
  269. bUpdatedVertices = true;
  270. }
  271. else
  272. {
  273. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  274. }
  275. // Finalize section update if we have anything to apply
  276. if (bUpdatedVertices)
  277. {
  278. UpdateSectionInternal(SectionIndex, false, bUpdatedVertices, false, bNeedsBoundsUpdate, UpdateFlags);
  279. }
  280. }
  281. /**
  282. * Updates a section. This is faster than CreateMeshSection. If this is a dual buffer section, you cannot change the length of the vertices.
  283. * @param SectionIndex Index of the section to update.
  284. * @param Vertices Vertex buffer all vertex data for this section, or in the case of dual buffer section it contains everything but position.
  285. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  286. * @param UpdateFlags Flags pertaining to this particular update.
  287. */
  288. template<typename VertexType>
  289. void UpdateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  290. {
  291. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithBoundingBox);
  292. // Validate all update parameters
  293. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  294. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  295. // Validate section type
  296. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  297. // Cast section to correct type
  298. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  299. // Check dual buffer section status
  300. if (Section->IsDualBufferSection() && Vertices.Num() != Section->VertexBuffer.Num())
  301. {
  302. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  303. return;
  304. }
  305. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  306. bool bNeedsBoundsUpdate = false;
  307. // Update vertices if supplied
  308. bool bUpdatedVertices = false;
  309. if (Vertices.Num() > 0)
  310. {
  311. bNeedsBoundsUpdate = Section->UpdateVertexBuffer(Vertices, &BoundingBox, bShouldUseMove);
  312. bUpdatedVertices = true;
  313. }
  314. else
  315. {
  316. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  317. }
  318. // Finalize section update if we have anything to apply
  319. if (bUpdatedVertices)
  320. {
  321. UpdateSectionInternal(SectionIndex, false, bUpdatedVertices, false, bNeedsBoundsUpdate, UpdateFlags);
  322. }
  323. }
  324. /**
  325. * Updates a section. This is faster than CreateMeshSection. If this is a dual buffer section, you cannot change the length of the vertices.
  326. * @param SectionIndex Index of the section to update.
  327. * @param Vertices Vertex buffer all vertex data for this section, or in the case of dual buffer section it contains everything but position.
  328. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  329. * @param UpdateFlags Flags pertaining to this particular update.
  330. */
  331. template<typename VertexType>
  332. void UpdateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, TArray<int32>& Triangles, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  333. {
  334. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithTriangles);
  335. // Validate all update parameters
  336. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  337. // Validate section type
  338. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  339. // Cast section to correct type
  340. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  341. // Check dual buffer section status
  342. if (Section->IsDualBufferSection() && Vertices.Num() != Section->VertexBuffer.Num())
  343. {
  344. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  345. return;
  346. }
  347. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  348. bool bNeedsBoundsUpdate = false;
  349. // Update vertices if supplied
  350. bool bUpdatedVertices = false;
  351. if (Vertices.Num() > 0)
  352. {
  353. bNeedsBoundsUpdate = Section->UpdateVertexBuffer(Vertices, nullptr, bShouldUseMove);
  354. bUpdatedVertices = true;
  355. }
  356. else
  357. {
  358. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  359. }
  360. // Update triangles if supplied
  361. bool bUpdatedIndices = false;
  362. if (Triangles.Num() > 0)
  363. {
  364. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  365. bUpdatedIndices = true;
  366. }
  367. else
  368. {
  369. Log(TEXT("UpdateMeshSection() - Triangles empty. They will not be updated."));
  370. }
  371. // Finalize section update if we have anything to apply
  372. if (bUpdatedVertices || bUpdatedIndices)
  373. {
  374. UpdateSectionInternal(SectionIndex, false, bUpdatedVertices, bUpdatedIndices, bNeedsBoundsUpdate, UpdateFlags);
  375. }
  376. }
  377. /**
  378. * Updates a section. This is faster than CreateMeshSection. If this is a dual buffer section, you cannot change the length of the vertices.
  379. * @param SectionIndex Index of the section to update.
  380. * @param Vertices Vertex buffer all vertex data for this section, or in the case of dual buffer section it contains everything but position.
  381. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  382. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  383. * @param UpdateFlags Flags pertaining to this particular update.
  384. */
  385. template<typename VertexType>
  386. void UpdateMeshSection(int32 SectionIndex, TArray<VertexType>& Vertices, TArray<int32>& Triangles, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  387. {
  388. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithTrianglesAndBoundinBox);
  389. // Validate all update parameters
  390. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  391. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  392. // Validate section type
  393. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  394. // Cast section to correct type
  395. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  396. // Check dual buffer section status
  397. if (Section->IsDualBufferSection() && Vertices.Num() != Section->VertexBuffer.Num())
  398. {
  399. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  400. return;
  401. }
  402. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  403. bool bNeedsBoundsUpdate = false;
  404. // Update vertices if supplied
  405. bool bUpdatedVertices = false;
  406. if (Vertices.Num() > 0)
  407. {
  408. bNeedsBoundsUpdate = Section->UpdateVertexBuffer(Vertices, &BoundingBox, bShouldUseMove);
  409. bUpdatedVertices = true;
  410. }
  411. else
  412. {
  413. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  414. }
  415. // Update indices if supplied
  416. bool bUpdatedIndices = false;
  417. if (Triangles.Num() > 0)
  418. {
  419. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  420. bUpdatedIndices = true;
  421. }
  422. else
  423. {
  424. Log(TEXT("UpdateMeshSection() - Triangles empty. They will not be updated."));
  425. }
  426. // Finalize section update if we have anything to apply
  427. if (bUpdatedVertices || bUpdatedIndices)
  428. {
  429. UpdateSectionInternal(SectionIndex, false, bUpdatedVertices, bUpdatedIndices, bNeedsBoundsUpdate, UpdateFlags);
  430. }
  431. }
  432. /**
  433. * Updates a section. This is faster than CreateMeshSection. This is only for dual buffer sections. You cannot change the length of positions or vertex data unless you specify both together.
  434. * @param SectionIndex Index of the section to update.
  435. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  436. * @param VertexData Vertex buffer containing everything except position for each vertex.
  437. * @param UpdateFlags Flags pertaining to this particular update.
  438. */
  439. template<typename VertexType>
  440. void UpdateMeshSection(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  441. {
  442. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType);
  443. // Validate all update parameters
  444. RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
  445. // Validate section type
  446. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  447. // Cast section to correct type
  448. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  449. // Check dual buffer section status
  450. if (Section->IsDualBufferSection() &&
  451. VertexData.Num() != Section->VertexBuffer.Num() &&
  452. VertexPositions.Num() != VertexData.Num())
  453. {
  454. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  455. return;
  456. }
  457. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  458. bool bNeedsBoundsUpdate = false;
  459. // Update vertex positions if supplied
  460. bool bUpdatedVertexPositions = false;
  461. if (VertexPositions.Num() > 0)
  462. {
  463. bNeedsBoundsUpdate = Section->UpdateVertexPositionBuffer(VertexPositions, nullptr, bShouldUseMove);
  464. bUpdatedVertexPositions = true;
  465. }
  466. else
  467. {
  468. Log(TEXT("UpdatemeshSection() - Vertex positions empty. They will not be updated."));
  469. }
  470. // Update vertices if supplied
  471. bool bUpdatedVertices = false;
  472. if (VertexData.Num() > 0)
  473. {
  474. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  475. bUpdatedVertices = true;
  476. }
  477. else
  478. {
  479. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  480. }
  481. // Finalize section update if we have anything to apply
  482. if (bUpdatedVertexPositions || bUpdatedVertices)
  483. {
  484. UpdateSectionInternal(SectionIndex, bUpdatedVertexPositions, bUpdatedVertices, false, bNeedsBoundsUpdate, UpdateFlags);
  485. }
  486. }
  487. /**
  488. * Updates a section. This is faster than CreateMeshSection. This is only for dual buffer sections. You cannot change the length of positions or vertex data unless you specify both together.
  489. * @param SectionIndex Index of the section to update.
  490. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  491. * @param VertexData Vertex buffer containing everything except position for each vertex.
  492. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  493. * @param UpdateFlags Flags pertaining to this particular update.
  494. */
  495. template<typename VertexType>
  496. void UpdateMeshSection(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  497. {
  498. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithBoundingBox);
  499. // Validate all update parameters
  500. RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
  501. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  502. // Validate section type
  503. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  504. // Cast section to correct type
  505. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  506. // Check dual buffer section status
  507. if (Section->IsDualBufferSection() &&
  508. VertexData.Num() != Section->VertexBuffer.Num() &&
  509. VertexPositions.Num() != VertexData.Num())
  510. {
  511. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  512. return;
  513. }
  514. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  515. bool bNeedsBoundsUpdate = false;
  516. // Update vertex positions if supplied
  517. bool bUpdatedVertexPositions = false;
  518. if (VertexPositions.Num() > 0)
  519. {
  520. bNeedsBoundsUpdate = Section->UpdateVertexPositionBuffer(VertexPositions, &BoundingBox, bShouldUseMove);
  521. bUpdatedVertexPositions = true;
  522. }
  523. else
  524. {
  525. Log(TEXT("UpdatemeshSection() - Vertex positions empty. They will not be updated."));
  526. }
  527. // Update vertices if supplied
  528. bool bUpdatedVertices = false;
  529. if (VertexData.Num() > 0)
  530. {
  531. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  532. bUpdatedVertices = true;
  533. }
  534. else
  535. {
  536. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  537. }
  538. // Finalize section update if we have anything to apply
  539. if (bUpdatedVertexPositions || bUpdatedVertices)
  540. {
  541. UpdateSectionInternal(SectionIndex, bUpdatedVertexPositions, bUpdatedVertices, false, bNeedsBoundsUpdate, UpdateFlags);
  542. }
  543. }
  544. /**
  545. * Updates a section. This is faster than CreateMeshSection. This is only for dual buffer sections. You cannot change the length of positions or vertex data unless you specify both together.
  546. * @param SectionIndex Index of the section to update.
  547. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  548. * @param VertexData Vertex buffer containing everything except position for each vertex.
  549. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  550. * @param UpdateFlags Flags pertaining to this particular update.
  551. */
  552. template<typename VertexType>
  553. void UpdateMeshSection(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, TArray<int32>& Triangles, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  554. {
  555. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithTriangles);
  556. // Validate all update parameters
  557. RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
  558. // Validate section type
  559. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  560. // Cast section to correct type
  561. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  562. // Check dual buffer section status
  563. if (Section->IsDualBufferSection() &&
  564. VertexData.Num() != Section->VertexBuffer.Num() &&
  565. VertexPositions.Num() != VertexData.Num())
  566. {
  567. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  568. return;
  569. }
  570. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  571. bool bNeedsBoundsUpdate = false;
  572. // Update vertex positions if supplied
  573. bool bUpdatedVertexPositions = false;
  574. if (VertexPositions.Num() > 0)
  575. {
  576. bNeedsBoundsUpdate = Section->UpdateVertexPositionBuffer(VertexPositions, nullptr, bShouldUseMove);
  577. bUpdatedVertexPositions = true;
  578. }
  579. else
  580. {
  581. Log(TEXT("UpdatemeshSection() - Vertex positions empty. They will not be updated."));
  582. }
  583. // Update vertices if supplied
  584. bool bUpdatedVertices = false;
  585. if (VertexData.Num() > 0)
  586. {
  587. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  588. bUpdatedVertices = true;
  589. }
  590. else
  591. {
  592. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  593. }
  594. // Update triangles if supplied
  595. bool bUpdatedIndices = false;
  596. if (Triangles.Num() > 0)
  597. {
  598. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  599. bUpdatedIndices = true;
  600. }
  601. else
  602. {
  603. Log(TEXT("UpdateMeshSection() - Triangles empty. They will not be updated."));
  604. }
  605. // Finalize section update if we have anything to apply
  606. if (bUpdatedVertexPositions || bUpdatedVertices || bUpdatedIndices)
  607. {
  608. UpdateSectionInternal(SectionIndex, bUpdatedVertexPositions, bUpdatedVertices, bUpdatedIndices, bNeedsBoundsUpdate, UpdateFlags);
  609. }
  610. }
  611. /**
  612. * Updates a section. This is faster than CreateMeshSection. This is only for dual buffer sections. You cannot change the length of positions or vertex data unless you specify both together.
  613. * @param SectionIndex Index of the section to update.
  614. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  615. * @param VertexData Vertex buffer containing everything except position for each vertex.
  616. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  617. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  618. * @param UpdateFlags Flags pertaining to this particular update.
  619. */
  620. template<typename VertexType>
  621. void UpdateMeshSection(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, TArray<int32>& Triangles, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None)
  622. {
  623. SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithTrianglesAndBoundinBox);
  624. // Validate all update parameters
  625. RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
  626. RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
  627. // Validate section type
  628. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  629. // Cast section to correct type
  630. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  631. // Check dual buffer section status
  632. if (Section->IsDualBufferSection() &&
  633. VertexData.Num() != Section->VertexBuffer.Num() &&
  634. VertexPositions.Num() != VertexData.Num())
  635. {
  636. Log(TEXT("UpdateMeshSection() - Vertices cannot change length unless the positions are updated as well."), true);
  637. return;
  638. }
  639. bool bShouldUseMove = (UpdateFlags & ESectionUpdateFlags::MoveArrays) != ESectionUpdateFlags::None;
  640. bool bNeedsBoundsUpdate = false;
  641. // Update vertex positions if supplied
  642. bool bUpdatedVertexPositions = false;
  643. if (VertexPositions.Num() > 0)
  644. {
  645. bNeedsBoundsUpdate = Section->UpdateVertexPositionBuffer(VertexPositions, &BoundingBox, bShouldUseMove);
  646. bUpdatedVertexPositions = true;
  647. }
  648. else
  649. {
  650. Log(TEXT("UpdatemeshSection() - Vertex positions empty. They will not be updated."));
  651. }
  652. // Update vertices if supplied
  653. bool bUpdatedVertices = false;
  654. if (VertexData.Num() > 0)
  655. {
  656. Section->UpdateVertexBuffer(VertexData, nullptr, bShouldUseMove);
  657. bUpdatedVertices = true;
  658. }
  659. else
  660. {
  661. Log(TEXT("UpdateMeshSection() - Vertices empty. They will not be updated."));
  662. }
  663. // Update indices if supplied
  664. bool bUpdatedIndices = false;
  665. if (Triangles.Num() > 0)
  666. {
  667. Section->UpdateIndexBuffer(Triangles, bShouldUseMove);
  668. bUpdatedIndices = true;
  669. }
  670. else
  671. {
  672. Log(TEXT("UpdateMeshSection() - Triangles empty. They will not be updated."));
  673. }
  674. // Finalize section update if we have anything to apply
  675. if (bUpdatedVertexPositions || bUpdatedVertices || bUpdatedIndices)
  676. {
  677. UpdateSectionInternal(SectionIndex, bUpdatedVertexPositions, bUpdatedVertices, bUpdatedIndices, bNeedsBoundsUpdate, UpdateFlags);
  678. }
  679. }
  680. /**
  681. * Updates a sections position buffer only. This cannot be used on a non-dual buffer section. You cannot change the length of the vertex position buffer with this function.
  682. * @param SectionIndex Index of the section to update.
  683. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  684. * @param UpdateFlags Flags pertaining to this particular update.
  685. */
  686. void UpdateMeshSectionPositionsImmediate(int32 SectionIndex, TArray<FVector>& VertexPositions, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  687. /**
  688. * Updates a sections position buffer only. This cannot be used on a non-dual buffer section. You cannot change the length of the vertex position buffer with this function.
  689. * @param SectionIndex Index of the section to update.
  690. * @param VertexPositions Vertex buffer containing only the position information for each vertex.
  691. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  692. * @param UpdateFlags Flags pertaining to this particular update.
  693. */
  694. void UpdateMeshSectionPositionsImmediate(int32 SectionIndex, TArray<FVector>& VertexPositions, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  695. /**
  696. * Starts an in place update of vertex positions.
  697. * @param SectionIndex Index of the section to update.
  698. */
  699. TArray<FVector>* BeginMeshSectionPositionUpdate(int32 SectionIndex);
  700. /**
  701. * Finishes an in place update of vertex positions.
  702. * This will push the update to the GPU and calculate the new Bounding Box
  703. * @param SectionIndex Index of the section to update.
  704. */
  705. void EndMeshSectionPositionUpdate(int32 SectionIndex);
  706. /**
  707. * Finishes an in place update of vertex positions.
  708. * This will push the update to the GPU
  709. * @param SectionIndex Index of the section to update.
  710. * @param BoundingBox The bounds of this section. Faster than the RMC automatically calculating it.
  711. */
  712. void EndMeshSectionPositionUpdate(int32 SectionIndex, const FBox& BoundingBox);
  713. template<typename VertexType>
  714. void BeginMeshSectionUpdate(int32 SectionIndex, TArray<VertexType>*& Vertices)
  715. {
  716. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  717. // Validate section type
  718. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  719. // Cast section to correct type
  720. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  721. Vertices = &Section->VertexBuffer;
  722. }
  723. template<typename VertexType>
  724. void BeginMeshSectionUpdate(int32 SectionIndex, TArray<VertexType>*& Vertices, TArray<int32>*& Triangles)
  725. {
  726. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  727. // Validate section type
  728. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  729. // Cast section to correct type
  730. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  731. Vertices = &Section->VertexBuffer;
  732. Triangles = &Section->IndexBuffer;
  733. }
  734. template<typename VertexType>
  735. void BeginMeshSectionUpdate(int32 SectionIndex, TArray<FVector>*& Positions, TArray<VertexType>*& Vertices)
  736. {
  737. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  738. // Validate section type
  739. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  740. // Cast section to correct type
  741. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  742. Positions = &Section->PositionVertexBuffer;
  743. Vertices = &Section->VertexBuffer;
  744. }
  745. template<typename VertexType>
  746. void BeginMeshSectionUpdate(int32 SectionIndex, TArray<FVector>*& Positions, TArray<VertexType>*& Vertices, TArray<int32>*& Triangles)
  747. {
  748. RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
  749. // Validate section type
  750. MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
  751. // Cast section to correct type
  752. TSharedPtr<FRuntimeMeshSection<VertexType>> Section = StaticCastSharedPtr<FRuntimeMeshSection<VertexType>>(MeshSections[SectionIndex]);
  753. Positions = &Section->PositionVertexBuffer;
  754. Vertices = &Section->VertexBuffer;
  755. Triangles = &Section->IndexBuffer;
  756. }
  757. void BeginMeshSectionUpdate(int32 SectionIndex, IRuntimeMeshVerticesBuilder*& Vertices, FRuntimeMeshIndicesBuilder*& Indices);
  758. void EndMeshSectionUpdate(int32 SectionIndex, ERuntimeMeshBuffer UpdatedBuffers, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  759. void EndMeshSectionUpdate(int32 SectionIndex, ERuntimeMeshBuffer UpdatedBuffers, const FBox& BoundingBox, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  760. /*
  761. * Gets a readonly pointer to the sections mesh data.
  762. * To be able to edit the section data use BegineMeshSectionUpdate()
  763. */
  764. void GetSectionMesh(int32 SectionIndex, const IRuntimeMeshVerticesBuilder*& Vertices, const FRuntimeMeshIndicesBuilder*& Indices);
  765. /**
  766. * Create/replace a section.
  767. * @param SectionIndex Index of the section to create or replace.
  768. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  769. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  770. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  771. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  772. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  773. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  774. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  775. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  776. */
  777. void CreateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  778. const TArray<FVector2D>& UV0, const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents, bool bCreateCollision = false,
  779. EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  780. /**
  781. * Create/replace a section.
  782. * @param SectionIndex Index of the section to create or replace.
  783. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  784. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  785. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  786. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  787. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  788. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  789. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  790. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  791. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  792. */
  793. void CreateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  794. const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents,
  795. bool bCreateCollision = false, EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  796. /**
  797. * Updates a section. This is faster than CreateMeshSection.
  798. * @param SectionIndex Index of the section to update.
  799. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  800. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  801. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  802. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  803. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  804. */
  805. void UpdateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0,
  806. const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  807. /**
  808. * Updates a section. This is faster than CreateMeshSection.
  809. * @param SectionIndex Index of the section to update.
  810. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  811. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  812. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  813. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  814. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  815. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  816. */
  817. void UpdateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0,
  818. const TArray<FVector2D>& UV1, const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  819. /**
  820. * Updates a section. This is faster than CreateMeshSection.
  821. * @param SectionIndex Index of the section to update.
  822. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  823. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  824. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  825. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  826. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  827. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  828. */
  829. void UpdateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  830. const TArray<FVector2D>& UV0, const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  831. /**
  832. * Updates a section. This is faster than CreateMeshSection.
  833. * @param SectionIndex Index of the section to update.
  834. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  835. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  836. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  837. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  838. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  839. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  840. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  841. */
  842. void UpdateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  843. const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FColor>& Colors, const TArray<FRuntimeMeshTangent>& Tangents, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  844. /**
  845. * Create/replace a section.
  846. * @param SectionIndex Index of the section to create or replace.
  847. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  848. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  849. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  850. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  851. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  852. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  853. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  854. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  855. * @param bCalculateNormalTangent Indicates whether normal/tangent information should be calculated automatically. This can add significant cost.
  856. * @param bGenerateTessellationTriangles Indicates whether tessellation supporting triangles should be calculated. This can add significant cost.
  857. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  858. */
  859. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh", meta = (DisplayName = "Create Mesh Section", AutoCreateRefTerm = "Normals,Tangents,UV0,UV1,Colors"))
  860. void CreateMeshSection_Blueprint(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  861. const TArray<FRuntimeMeshTangent>& Tangents, const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FLinearColor>& Colors,
  862. bool bCreateCollision, bool bCalculateNormalTangent, bool bGenerateTessellationTriangles, EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average);
  863. /**
  864. * Updates a section. This is faster than CreateMeshSection. If you change the vertices count, you must update the other components.
  865. * @param SectionIndex Index of the section to update.
  866. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
  867. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  868. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
  869. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
  870. * @param UV0 Optional array of texture co-ordinates for each vertex (UV Channel 0). If supplied, must be same length as Vertices array.
  871. * @param UV1 Optional array of texture co-ordinates for each vertex (UV Channel 1). If supplied, must be same length as Vertices array.
  872. * @param Colors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
  873. * @param bCalculateNormalTangent Indicates whether normal/tangent information should be calculated automatically. This can add significant cost.
  874. * @param bGenerateTessellationTriangles Indicates whether tessellation supporting triangles should be calculated. This can add significant cost.
  875. */
  876. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh", meta = (DisplayName = "Update Mesh Section", AutoCreateRefTerm = "Triangles,Normals,Tangents,UV0,UV1,Colors"))
  877. void UpdateMeshSection_Blueprint(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
  878. const TArray<FRuntimeMeshTangent>& Tangents, const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FLinearColor>& Colors, bool bCalculateNormalTangent, bool bGenerateTessellationTriangles);
  879. /**
  880. * Create/replace a section.
  881. * @param SectionIndex Index of the section to create or replace.
  882. * @param Vertices Vertex buffer all vertex data for this section.
  883. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  884. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
  885. * @param UpdateFrequency Indicates how frequently the section will be updated. Allows the RMC to optimize itself to a particular use.
  886. * @param UpdateFlags Flags pertaining to this particular update.
  887. */
  888. void CreateMeshSection(int32 SectionIndex, IRuntimeMeshVerticesBuilder& Vertices, FRuntimeMeshIndicesBuilder& Indices, bool bCreateCollision = false,
  889. EUpdateFrequency UpdateFrequency = EUpdateFrequency::Average, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  890. /**
  891. * Updates a section. This is faster than CreateMeshSection. If this is a dual buffer section, you cannot change the length of the vertices.
  892. * @param SectionIndex Index of the section to update.
  893. * @param Vertices Vertex buffer all vertex data for this section, or in the case of dual buffer section it contains everything but position.
  894. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
  895. * @param UpdateFlags Flags pertaining to this particular update.
  896. */
  897. void UpdateMeshSection(int32 SectionIndex, IRuntimeMeshVerticesBuilder& Vertices, FRuntimeMeshIndicesBuilder& Indices, ESectionUpdateFlags UpdateFlags = ESectionUpdateFlags::None);
  898. /** Clear a section of the procedural mesh. */
  899. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  900. void ClearMeshSection(int32 SectionIndex);
  901. /** Clear all mesh sections and reset to empty state */
  902. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  903. void ClearAllMeshSections();
  904. /** Sets the tessellation triangles needed to correctly support tessellation on a section. */
  905. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  906. void SetSectionTessellationTriangles(int32 SectionIndex, const TArray<int32>& TessellationTriangles, bool bShouldMoveArray = false);
  907. /** Gets the bounding box of a specific section */
  908. bool GetSectionBoundingBox(int32 SectionIndex, FBox& OutBoundingBox);
  909. /** Control visibility of a particular section */
  910. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  911. void SetMeshSectionVisible(int32 SectionIndex, bool bNewVisibility);
  912. /** Returns whether a particular section is currently visible */
  913. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  914. bool IsMeshSectionVisible(int32 SectionIndex) const;
  915. /** Control whether a particular section casts a shadow */
  916. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  917. void SetMeshSectionCastsShadow(int32 SectionIndex, bool bNewCastsShadow);
  918. /** Returns whether a particular section is currently casting shadows */
  919. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  920. bool IsMeshSectionCastingShadows(int32 SectionIndex) const;
  921. /** Control whether a particular section has collision */
  922. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  923. void SetMeshSectionCollisionEnabled(int32 SectionIndex, bool bNewCollisionEnabled);
  924. /** Returns whether a particular section has collision */
  925. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  926. bool IsMeshSectionCollisionEnabled(int32 SectionIndex);
  927. /** Returns number of sections currently created for this component */
  928. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  929. int32 GetNumSections() const;
  930. /** Returns whether a particular section currently exists */
  931. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  932. bool DoesSectionExist(int32 SectionIndex) const;
  933. /** Returns first available section index */
  934. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  935. int32 FirstAvailableMeshSectionIndex() const;
  936. /** Returns the last in use section index */
  937. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  938. int32 GetLastSectionIndex() const;
  939. /** Sets the geometry for a collision only section */
  940. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  941. void SetMeshCollisionSection(int32 CollisionSectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles);
  942. /** Clears the geometry for a collision only section */
  943. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  944. void ClearMeshCollisionSection(int32 CollisionSectionIndex);
  945. /** Clears the geometry for ALL collision only sections */
  946. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  947. void ClearAllMeshCollisionSections();
  948. /** Add simple collision convex to this component */
  949. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  950. void AddCollisionConvexMesh(TArray<FVector> ConvexVerts);
  951. /** Add simple collision convex to this component */
  952. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  953. void ClearCollisionConvexMeshes();
  954. /** Function to replace _all_ simple collision in one go */
  955. void SetCollisionConvexMeshes(const TArray< TArray<FVector> >& ConvexMeshes);
  956. /** Begins a batch of updates, delays updates until you call EndBatchUpdates() */
  957. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  958. void BeginBatchUpdates()
  959. {
  960. BatchState.StartBatch();
  961. }
  962. /** Ends a batch of updates started with BeginBatchUpdates() */
  963. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  964. void EndBatchUpdates();
  965. /** Runs any pending collision cook (Not required to call this. This is only if you need to make sure all changes are cooked before doing something)*/
  966. UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
  967. void CookCollisionNow();
  968. /**
  969. * Controls whether the complex (Per poly) geometry should be treated as 'simple' collision.
  970. * Should be set to false if this component is going to be given simple collision and simulated.
  971. */
  972. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "RuntimeMesh")
  973. bool bUseComplexAsSimpleCollision;
  974. /**
  975. * Controls whether the mesh data should be serialized with the component.
  976. */
  977. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "RuntimeMesh")
  978. bool bShouldSerializeMeshData;
  979. /*
  980. * The current mode of the collision cooker
  981. * WARNING: This feature will only work in engine version 4.14 or above!
  982. */
  983. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RuntimeMesh")
  984. ERuntimeMeshCollisionCookingMode CollisionMode;
  985. /** Collision data */
  986. UPROPERTY(Instanced)
  987. class UBodySetup* BodySetup;
  988. /* Serialize the entire RMC to the supplied archive. */
  989. void SerializeRMC(FArchive& Ar);
  990. /* Serialize the designated section into the supplied archive. */
  991. void SerializeRMCSection(FArchive& Ar, int32 SectionIndex);
  992. private:
  993. //~ Begin Interface_CollisionDataProvider Interface
  994. virtual bool GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) override;
  995. virtual bool ContainsPhysicsTriMeshData(bool InUseAllTriData) const override;
  996. virtual bool WantsNegXTriMesh() override { return false; }
  997. //~ End Interface_CollisionDataProvider Interface
  998. //~ Begin USceneComponent Interface.
  999. virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
  1000. virtual bool IsSupportedForNetworking() const override
  1001. {
  1002. return true;
  1003. }
  1004. //~ Begin USceneComponent Interface.
  1005. //~ Begin UPrimitiveComponent Interface.
  1006. virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
  1007. virtual class UBodySetup* GetBodySetup() override;
  1008. //~ End UPrimitiveComponent Interface.
  1009. //~ Begin UMeshComponent Interface.
  1010. virtual int32 GetNumMaterials() const override;
  1011. //~ End UMeshComponent Interface.
  1012. /** Update LocalBounds member from the local box of each section */
  1013. void UpdateLocalBounds(bool bMarkRenderTransform = true);
  1014. /** Ensure ProcMeshBodySetup is allocated and configured */
  1015. void EnsureBodySetupCreated();
  1016. /** Mark collision data as dirty, and re-create on instance if necessary */
  1017. void UpdateCollision();
  1018. /* Marks the collision for an end of frame update */
  1019. void MarkCollisionDirty();
  1020. /* Cooks the new collision mesh updating the body */
  1021. void BakeCollision();
  1022. void UpdateNavigation();
  1023. /* Serializes this component */
  1024. virtual void Serialize(FArchive& Ar) override;
  1025. void SerializeInternal(FArchive& Ar, bool bForceSaveAll = false);
  1026. void SerializeLegacy(FArchive& Ar);
  1027. /* Does post load fixups */
  1028. virtual void PostLoad() override;
  1029. /* Registers the pre-physics tick function used to cook new meshes when necessary */
  1030. virtual void RegisterComponentTickFunctions(bool bRegister) override;
  1031. /* Current state of a batch update. */
  1032. FRuntimeMeshBatchUpdateState BatchState;
  1033. /* Is the collision in need of a recook? */
  1034. bool bCollisionDirty;
  1035. /** Array of sections of mesh */
  1036. TArray<RuntimeMeshSectionPtr> MeshSections;
  1037. /* Array of collision only mesh sections*/
  1038. UPROPERTY(Transient)
  1039. TArray<FRuntimeMeshCollisionSection> MeshCollisionSections;
  1040. /** Convex shapes used for simple collision */
  1041. UPROPERTY(Transient)
  1042. TArray<FRuntimeConvexCollisionSection> ConvexCollisionSections;
  1043. /** Local space bounds of mesh */
  1044. UPROPERTY(Transient)
  1045. FBoxSphereBounds LocalBounds;
  1046. /* Tick function used to cook collision when needed*/
  1047. UPROPERTY(Transient)
  1048. FRuntimeMeshComponentPrePhysicsTickFunction PrePhysicsTick;
  1049. friend class FRuntimeMeshSceneProxy;
  1050. friend struct FRuntimeMeshComponentPrePhysicsTickFunction;
  1051. };