// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "GraphicsDefs.h" #include "Helper/DataUtil.h" #include #include #include #include struct CoreMesh; typedef std::shared_ptr CoreMeshPtr; class MeshDetails; typedef std::shared_ptr MeshDetailsPtr; class MeshDetails_Tri; class TEXTUREGRAPHENGINE_API MeshInfo { protected: typedef std::unordered_map MeshDetailsPtrLookup; CoreMeshPtr _cmesh; /// The core mesh data structure that should've been loaded by now CHashPtr _hash; /// The hash for the mesh mutable FCriticalSection _detailsMutex; /// Mutex for details MeshDetailsPtrLookup _details; /// Details lookup public: MeshInfo(CoreMeshPtr cmesh); ~MeshInfo(); size_t NumVertices() const; size_t NumTriangles() const; std::array Vertices(int32 i0, int32 i1, int32 i2) const; int32 GetMaterialIndex(); void InitBounds(FVector min, FVector max); void UpdateBounds(const FVector& vert); ////////////////////////////////////////////////////////////////////////// MeshDetails_Tri* d_Tri(); template T_Details* GetAttribute(const char* name, bool create = true) { FScopeLock lock(&_detailsMutex); { auto iter = _details.find(name); /// If the details already exists if (iter != _details.end()) return static_cast(iter->second.get()); if (!create) return nullptr; auto detail = std::make_shared(this); _details[name] = std::static_pointer_cast(detail); return detail.get(); } } ////////////////////////////////////////////////////////////////////////// /// Inline functions ////////////////////////////////////////////////////////////////////////// FORCEINLINE CoreMeshPtr CMesh() const { return _cmesh; } FORCEINLINE CHashPtr Hash() const { return _hash; } }; typedef std::shared_ptr MeshInfoPtr;