7#include "game/nodes/SpatialNode.h"
8#include "math/GLMath.hpp"
9#include "render/general/resources/GpuResource.h"
10#include "shader/general/resources/ShaderResource.h"
11#include "shader/general/resources/cpuwrite/ShaderCpuWriteResourceUniquePtr.h"
12#include "shader/general/resources/texture/ShaderTextureResourceUniquePtr.h"
13#include "shader/VulkanAlignmentConstants.hpp"
14#include "misc/shapes/AABB.h"
15#include "material/Material.h"
17#include "MeshNode.generated.h"
19namespace ne RNAMESPACE() {
58 bool operator==(const
MeshVertex& other) const;
63 glm::vec3
position = glm::vec3(0.0f, 0.0f, 0.0f);
66 glm::vec3
normal = glm::vec3(0.0f, 0.0f, 0.0f);
69 glm::vec2
uv = glm::vec2(0.0f, 0.0f);
123 std::vector<std::vector<
meshindex_t>>* getIndices();
140 ne_MeshData_GENERATED
162 alignas(iVkMat4Alignment) glm::mat4x4 worldMatrix = glm::identity<glm::mat4x4>();
169 alignas(iVkMat4Alignment) glm::mat4x4 normalMatrix = glm::identity<glm::mat4x4>();
223 MeshNode(
const std::string& sNodeName);
239 void setMaterial(std::unique_ptr<Material> pMaterial,
size_t iMaterialSlot = 0);
248 void setMeshData(
const MeshData& meshData);
257 void setMeshData(
MeshData&& meshData);
260 void onMeshDataChanged();
267 void setIsVisible(
bool bVisible);
279 Material* getMaterial(
size_t iMaterialSlot = 0);
287 size_t getAvailableMaterialSlotCount();
304 inline std::pair<std::recursive_mutex*, MeshData*>
getMeshData() {
305 return std::make_pair(&mtxMeshData, &meshData);
314 return &mtxGpuResources;
326 return &mtxShaderMeshDataConstants;
341 bool isVisible()
const;
351 virtual void onAfterDeserialized()
override;
363 virtual void onSpawning()
override;
374 virtual void onDespawning()
override;
382 virtual void onWorldLocationRotationScaleChanged()
override;
411 void setShaderCpuWriteResourceBindingData(
412 const std::string& sShaderResourceName,
413 size_t iResourceSizeInBytes,
414 const std::function<
void*()>& onStartedUpdatingResource,
415 const std::function<
void()>& onFinishedUpdatingResource);
428 void setShaderTextureResourceBindingData(
429 const std::string& sShaderResourceName,
const std::string& sPathToTextureResourceRelativeRes);
450 void markShaderCpuWriteResourceToBeCopiedToGpu(
const std::string& sShaderResourceName);
458 static std::unique_ptr<Material> getDefaultMaterial();
465 void allocateShaderResources();
468 void allocateGeometryBuffers();
471 void deallocateShaderResources();
474 void deallocateGeometryBuffers();
481 void* onStartedUpdatingShaderMeshConstants();
484 void onFinishedUpdatingShaderMeshConstants();
496 void updateShaderResourcesToUseChangedMaterialPipelines();
508 std::pair<GpuResource*, unsigned int> getIndexBufferInfoForMaterialSlot(
size_t iMaterialSlot);
524 RPROPERTY(
Serialize(FST_AS_EXTERNAL_BINARY_FILE))
531 std::recursive_mutex mtxMeshData;
540 bool bIsVisible = true;
543 static inline const auto sMeshShaderConstantBufferName = "meshData";
545 ne_MeshNode_GENERATED
549File_MeshNode_GENERATED
Definition: GuidProperty.h:30
Definition: Material.h:84
Definition: MeshNode.h:80
MeshData(const MeshData &)=default
MeshData & operator=(const MeshData &)=default
unsigned int meshindex_t
Definition: MeshNode.h:83
MeshData(MeshData &&) noexcept=default
Definition: MeshNode.h:148
std::pair< std::recursive_mutex *, MeshData * > getMeshData()
Definition: MeshNode.h:304
std::pair< std::recursive_mutex, GpuResources > * getMeshGpuResources()
Definition: MeshNode.h:313
AABB * getAABB()
Definition: MeshNode.h:334
std::pair< std::recursive_mutex, MeshShaderConstants > * getMeshShaderConstants()
Definition: MeshNode.h:325
static const char * getMeshShaderConstantBufferName()
Definition: MeshNode.h:214
Definition: Serializable.h:113
Definition: SerializeProperty.h:42
Definition: SpatialNode.h:12
Definition: MeshNode.h:177
std::unique_ptr< GpuResource > pVertexBuffer
Definition: MeshNode.h:181
std::vector< std::unique_ptr< GpuResource > > vIndexBuffers
Definition: MeshNode.h:184
Definition: MeshNode.h:188
std::unordered_map< std::string, ShaderTextureResourceUniquePtr > shaderTextureResources
Definition: MeshNode.h:199
std::unordered_map< std::string, ShaderCpuWriteResourceUniquePtr > shaderCpuWriteResources
Definition: MeshNode.h:196
Definition: MeshNode.h:173
Mesh mesh
Definition: MeshNode.h:203
ShaderResources shaderResources
Definition: MeshNode.h:206
Definition: MeshNode.h:158
Definition: MeshNode.h:27
glm::vec3 normal
Definition: MeshNode.h:66
glm::vec2 uv
Definition: MeshNode.h:69
MeshVertex(MeshVertex &&) noexcept=default
MeshVertex & operator=(const MeshVertex &)=default
glm::vec3 position
Definition: MeshNode.h:63
MeshVertex(const MeshVertex &)=default