Plasma Engine  2.0
Loading...
Searching...
No Matches
JoltMeshResource.h
1#pragma once
2
3#include <Core/ResourceManager/Resource.h>
4#include <Foundation/Math/BoundingBoxSphere.h>
5#include <JoltPlugin/JoltPluginDLL.h>
6
10
12class plJoltMaterial;
13
14namespace JPH
15{
16 class MeshShape;
17 class ConvexHullShape;
18 class Shape;
19} // namespace JPH
20
21struct PL_JOLTPLUGIN_DLL plJoltMeshResourceDescriptor
22{
23 // empty, these types of resources must be loaded from file
24};
25
26class PL_JOLTPLUGIN_DLL plJoltMeshResource : public plResource
27{
28 PL_ADD_DYNAMIC_REFLECTION(plJoltMeshResource, plResource);
29 PL_RESOURCE_DECLARE_COMMON_CODE(plJoltMeshResource);
30 PL_RESOURCE_DECLARE_CREATEABLE(plJoltMeshResource, plJoltMeshResourceDescriptor);
31
32public:
35
37 const plBoundingBoxSphere& GetBounds() const { return m_Bounds; }
38
43 const plDynamicArray<plSurfaceResourceHandle>& GetSurfaces() const { return m_Surfaces; }
44
46 bool HasTriangleMesh() const { return m_pTriangleMeshInstance != nullptr || !m_TriangleMeshData.IsEmpty(); }
47
49 JPH::Shape* InstantiateTriangleMesh(plUInt64 uiUserData, const plDynamicArray<const plJoltMaterial*>& materials) const;
50
52 plUInt32 GetNumConvexParts() const { return !m_ConvexMeshInstances.IsEmpty() ? m_ConvexMeshInstances.GetCount() : m_ConvexMeshesData.GetCount(); }
53
55 JPH::Shape* InstantiateConvexPart(plUInt32 uiPartIdx, plUInt64 uiUserData, const plJoltMaterial* pMaterial, float fDensity) const;
56
58 plCpuMeshResourceHandle ConvertToCpuMesh() const;
59
60 plUInt32 GetNumTriangles() const { return m_uiNumTriangles; }
61 plUInt32 GetNumVertices() const { return m_uiNumVertices; }
62
63private:
64 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
65 virtual plResourceLoadDesc UpdateContent(plStreamReader* Stream) override;
66 virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
67
68private:
69 plBoundingBoxSphere m_Bounds;
71 mutable plHybridArray<plDataBuffer*, 1> m_ConvexMeshesData;
72 mutable plDataBuffer m_TriangleMeshData;
73 mutable JPH::Shape* m_pTriangleMeshInstance = nullptr;
74 mutable plHybridArray<JPH::Shape*, 1> m_ConvexMeshInstances;
75
76 plUInt32 m_uiNumVertices = 0;
77 plUInt32 m_uiNumTriangles = 0;
78};
Definition DynamicArray.h:81
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition JoltMaterial.h:7
Definition JoltMeshResource.h:27
bool HasTriangleMesh() const
Returns whether the mesh resource contains a triangle mesh. Triangle meshes and convex meshes are mut...
Definition JoltMeshResource.h:46
const plBoundingBoxSphere & GetBounds() const
Returns the bounds of the collision mesh.
Definition JoltMeshResource.h:37
plUInt32 GetNumConvexParts() const
Returns the number of convex meshes. Triangle meshes and convex meshes are mutually exclusive.
Definition JoltMeshResource.h:52
const plDynamicArray< plSurfaceResourceHandle > & GetSurfaces() const
Returns the array of default surfaces to be used with this mesh.
Definition JoltMeshResource.h:43
The base class for all resources.
Definition Resource.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
Definition JoltMeshResource.h:22
Sent by plWorldGeoExtractionUtil to gather geometry information about objects in a world.
Definition WorldGeoExtractionUtil.h:56
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition Declarations.h:102