// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/UnrealString.h" #include "Containers/Array.h" #include "Math/MathFwd.h" #include "GeometryCollection/ManagedArrayAccessor.h" #include "GeometryCollection/ManagedArrayCollection.h" #include "GeometryCollection/Facades/CollectionSelectionFacade.h" #include "Chaos/Triangle.h" namespace GeometryCollection::Facades { /** * FRenderingFacade * * Defines common API for storing rendering data. * */ class FRenderingFacade { public: typedef FGeometryCollectionSection FTriangleSection; typedef TMap FStringIntMap; /** * FRenderingFacade Constuctor * @param VertexDependencyGroup : GroupName the index attribute is dependent on. */ CHAOS_API FRenderingFacade(FManagedArrayCollection& InSelf); CHAOS_API FRenderingFacade(const FManagedArrayCollection& InSelf); /**Create the facade.*/ CHAOS_API void DefineSchema(); /** Is the facade defined constant. */ bool IsConst() const { return Collection==nullptr; } /**Is the Facade defined on the collection?*/ CHAOS_API bool IsValid() const; /**Does it support rendering surfaces.*/ CHAOS_API bool CanRenderSurface() const; // // Facade API // /**Number of triangles to render.*/ CHAOS_API int32 NumTriangles() const; /**Add a point to the rendering view.*/ CHAOS_API void AddPoint(const FVector3f& InPoint); /**Add point cloud to the rendering view.*/ CHAOS_API void AddPoints(TArray&& InPoints); /**Add a triangle to the rendering view.*/ CHAOS_API void AddTriangle(const Chaos::FTriangle& InTriangle); /** Given a list of triangles, expand them to faces with face-normals */ CHAOS_API void AddFaces(const TArray& InVertices, TArray& InIndices, TArray& InColors); /**Add a box to the rendering view.*/ CHAOS_API void AddBox(const FBox& InBox); CHAOS_API void AddBox(const FVector3f& InMinVertex, const FVector3f& InMaxVertex); /**Add boxes to the rendering view.*/ CHAOS_API void AddBoxes(const TArray& InBoxes); /**Add a sphere to the rendering view.*/ CHAOS_API void AddSphere(const FSphere& InSphere, const FLinearColor& InColor); CHAOS_API void AddSphere(const FVector3f& InCenter, const float InRadius, const FLinearColor& InColor); /**Add spheres to the rendering view.*/ CHAOS_API void AddSpheres(const TArray& InSpheres, const FLinearColor& InColor); /** Add a capsule to the rendering view */ CHAOS_API void AddCapsule(const float Length, const float Radius, FLinearColor Color = FLinearColor::White, int32 Sides = 8); /** Add a surface to the rendering view.*/ CHAOS_API void AddSurface(TArray&& InVertices, TArray&& InIndices, TArray&& InNormals, TArray&& InColors); /** Add a surface with UV layers, Material IDs and material paths to the rendering view.*/ CHAOS_API void AddSurface(TArray&& InVertices, TArray&& InIndices, TArray&& InNormals, TArray&& InColors, TArray>&& InUVs, TArray&& InMaterialIDs, TArray&& MaterialPaths); /** Add surface bone weights and indices to the rendering view - AddSurface must have been called before .*/ CHAOS_API void AddSurfaceBoneWeightsAndIndices(TArray>&& InBoneWeights, TArray>&& InBoneIndices); /**Add a tetrahedron to the rendering view.*/ CHAOS_API void AddTetrahedron(const TArray& InVertices, const FIntVector4& InIndices); /**Add a tetrahedrons to the rendering view.*/ CHAOS_API void AddTetrahedrons(TArray&& InVertices, TArray&& InIndices); /** GetIndices */ const TManagedArray< FIntVector >& GetIndices() const { return IndicesAttribute.Get(); } /** GetMaterialID */ const TManagedArray< int32 >& GetMaterialID() const { return MaterialIDAttribute.Get(); } /** GetTriangleSections */ const TManagedArray< FTriangleSection >& GetTriangleSections() const { return TriangleSectionAttribute.Get(); } /** BuildMeshSections */ CHAOS_API TArray BuildMeshSections(const TArray& Indices, TArray BaseMeshOriginalIndicesIndex, TArray& RetIndices) const; // // Vertices // /** GetVertices */ const TManagedArray< FVector3f >& GetVertices() const { return VertexAttribute.Get(); } TManagedArray< FVector3f >& ModifyVertices() { check(!IsConst()); return VertexAttribute.Modify(); } /** GetNormals */ const TManagedArray< FVector3f >& GetNormals() const { return VertexNormalAttribute.Get(); } TManagedArray< FVector3f >& ModifyNormals() { check(!IsConst()); return VertexNormalAttribute.Modify(); } /** GetVertexSelectionAttribute */ const TManagedArray< int32 >& GetVertexSelection() const { return VertexSelectionAttribute.Get(); } TManagedArray< int32 >& ModifyVertexSelection() { check(!IsConst()); return VertexSelectionAttribute.Modify(); } /** GetVertexToGeometryIndexAttribute */ const TManagedArray< int32 >& GetVertexToGeometryIndex() const { return VertexToGeometryIndexAttribute.Get(); } TManagedArray< int32 >& ModifyVertexToGeometryIndex() { check(!IsConst()); return VertexToGeometryIndexAttribute.Modify(); } /** HitProxyIDAttribute */ const TManagedArray< int32 >& GetVertexHitProxyIndex() const { return VertexHitProxyIndexAttribute.Get(); } TManagedArray< int32 >& ModifyVertexHitProxyIndex() { check(!IsConst()); return VertexHitProxyIndexAttribute.Modify(); } /** NumVertices */ int32 NumVertices() const { return VertexAttribute.Num(); } /** GetVertexColorAttribute */ const TManagedArray& GetVertexColor() const { return VertexColorAttribute.Get(); } TManagedArray& ModifyVertexColor() { check(!IsConst()); return VertexColorAttribute.Modify(); } /** GetVertexUVAttribute */ const TManagedArray>& GetVertexUV() const { return VertexUVAttribute.Get(); } TManagedArray>& ModifyVertexUV() { check(!IsConst()); return VertexUVAttribute.Modify(); } // optional per vertex bone attributes const TManagedArray>* FindBoneWeights() const { return BoneWeightsAttribute.Find(); } const TManagedArray>* FindBoneIndices() const { return BoneIndicesAttribute.Find(); } // // Geometry Group Attributes // /** Geometry Group Start : */ CHAOS_API int32 StartGeometryGroup(FString InName, const FTransform& InTm = FTransform::Identity); /** Geometry Group End : */ CHAOS_API void EndGeometryGroup(int32 InGeometryGroupIndex); /** Modify the transform of a pre-declared group */ CHAOS_API void SetGroupTransform(int32 InGeometryGroupIndex, const FTransform& InTm); int32 NumGeometry() const { return GeometryNameAttribute.Num(); } /** GeometryNameAttribute */ const TManagedArray< FString >& GetGeometryName() const { return GeometryNameAttribute.Get(); } /** GeometryTransformAttribute */ const TManagedArray& GetGeometryTransform() const { return GeometryTransformAttribute.Get(); } /** HitProxyIDAttribute */ const TManagedArray< int32 >& GetGeometryHitProxyIndex() const { return GeometryHitProxyIndexAttribute.Get(); } TManagedArray< int32 >& ModifyGeometryHitProxyIndex() {check(!IsConst());return GeometryHitProxyIndexAttribute.Modify(); } /** VertexStartAttribute */ const TManagedArray< int32 >& GetVertexStart() const { return VertexStartAttribute.Get(); } /** VertexCountAttribute */ const TManagedArray< int32 >& GetVertexCount() const { return VertexCountAttribute.Get(); } /** IndicesStartAttribute */ const TManagedArray< int32 >& GetIndicesStart() const { return IndicesStartAttribute.Get(); } /** IndicesCountAttribute */ const TManagedArray< int32 >& GetIndicesCount() const { return IndicesCountAttribute.Get(); } /** SelectionState */ const TManagedArray< int32 >& GetSelectionState() const { return GeometrySelectionAttribute.Get(); } TManagedArray< int32 >& ModifySelectionState() { check(!IsConst()); return GeometrySelectionAttribute.Modify(); } /** NumVerticesOnSelectedGeometry */ CHAOS_API int32 NumVerticesOnSelectedGeometry() const; /** GetGeometryNameToIndexMap */ CHAOS_API FStringIntMap GetGeometryNameToIndexMap() const; /** GetMaterialPathAttribute */ const TManagedArray& GetMaterialPaths() const { return MaterialPathAttribute.Get(); } /** GetMaterialStart */ const TManagedArray< int32 >& GetMaterialStart() const { return MaterialStartAttribute.Get(); } /** GetMaterialCount */ const TManagedArray< int32 >& GetMaterialCount() const { return MaterialCountAttribute.Get(); } /** Total NumMaterials */ int32 NumMaterials() const { return MaterialPathAttribute.Num(); } private : const FManagedArrayCollection& ConstCollection; FManagedArrayCollection* Collection = nullptr; TManagedArrayAccessor VertexAttribute; TManagedArrayAccessor VertexToGeometryIndexAttribute; TManagedArrayAccessor VertexSelectionAttribute; TManagedArrayAccessor VertexHitProxyIndexAttribute; TManagedArrayAccessor VertexNormalAttribute; TManagedArrayAccessor VertexColorAttribute; TManagedArrayAccessor> VertexUVAttribute; TManagedArrayAccessor IndicesAttribute; TManagedArrayAccessor MaterialIDAttribute; TManagedArrayAccessor TriangleSectionAttribute; TManagedArrayAccessor MaterialPathAttribute; TManagedArrayAccessor GeometryNameAttribute; TManagedArrayAccessor GeometryTransformAttribute; TManagedArrayAccessor GeometryHitProxyIndexAttribute; TManagedArrayAccessor VertexStartAttribute; TManagedArrayAccessor VertexCountAttribute; TManagedArrayAccessor IndicesStartAttribute; TManagedArrayAccessor IndicesCountAttribute; TManagedArrayAccessor MaterialStartAttribute; TManagedArrayAccessor MaterialCountAttribute; TManagedArrayAccessor GeometrySelectionAttribute; TManagedArrayAccessor> BoneWeightsAttribute; TManagedArrayAccessor> BoneIndicesAttribute; }; }