HeatMapActor.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * @Author: namidame
  3. * @Description: A Heatmap Generate Plugin, Supports Heightmap, Texture Coordinate Points And Geographic Location Data.
  4. * @Date: 2023/03/24
  5. */
  6. #pragma once
  7. #include "CoreMinimal.h"
  8. #include "ProceduralMeshComponent.h"
  9. #include "GameFramework/Actor.h"
  10. #include "Materials/MaterialInstanceDynamic.h"
  11. #include "Curves/CurveFloat.h"
  12. #include "Engine/Texture2D.h"
  13. #include "HeatMapActor.generated.h"
  14. UENUM(BlueprintType)
  15. enum class E_HeatMapType : uint8
  16. {
  17. NONE,
  18. HEIGHT_MAP,
  19. POINT_HEIGHT_DATA,
  20. GEO_DATA,
  21. };
  22. UCLASS()
  23. class HEATMAP_API AHeatMapActor : public AActor
  24. {
  25. GENERATED_BODY()
  26. public:
  27. // Sets default values for this actor's properties
  28. AHeatMapActor();
  29. protected:
  30. // Called when the game starts or when spawned
  31. virtual void BeginPlay() override;
  32. public:
  33. // Called every frame
  34. virtual void Tick(float DeltaTime) override;
  35. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  36. UProceduralMeshComponent* MapMesh;
  37. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  38. UMaterialInterface* HeatMapActorMaterial;
  39. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  40. UTexture2D* HeightMapTexture;
  41. UFUNCTION(BlueprintCallable, Category=HeatMap)
  42. void CreateMapMesh(FVector2D mapSize);
  43. UFUNCTION(BlueprintCallable, Category=HeatMap)
  44. void CreateWithHeightMap(UTexture2D* texture, FVector2D mapSize);
  45. UFUNCTION(BlueprintCallable, Category=HeatMap)
  46. void CreateWithData(const TArray<FColor>& colorArr, FVector2D textureSize, FVector2D mapSize);
  47. UFUNCTION(BlueprintCallable, Category=HeatMap)
  48. void setMaterialLerpScale(float scale);
  49. UFUNCTION(BlueprintCallable, Category=HeatMap)
  50. void setMaterialHeightScale(float scale);
  51. UFUNCTION(BlueprintCallable, Category=HeatMap)
  52. void setMaterialOpacity(float opacity);
  53. static TArray<FColor> GetColorDataFromTexture(UTexture2D* texture, FVector2D textureSize);
  54. TArray<FColor> GetColorDataFromPointHeightMap(const TMap<FVector2D, float> &map, FVector2D texture_size, int32 influenceSize);
  55. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  56. FVector2D TextureSize;
  57. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  58. FVector2D MapSize;
  59. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  60. FVector2D MapSecment;
  61. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  62. float LerpScale;
  63. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  64. float HeightScale;
  65. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  66. float Opacity;
  67. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  68. int32 InfluenceSize;
  69. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap)
  70. UCurveFloat* InfluenceCurve;
  71. UFUNCTION(BlueprintCallable, Category=HeatMap)
  72. void setMapSecment(FVector2D secment);
  73. UFUNCTION(BlueprintCallable, Category=HeatMap)
  74. void setMapSize(FVector2D size);
  75. UFUNCTION(BlueprintCallable, Category=HeatMap)
  76. void CreateWithPointHeightValue(const TMap<FVector2D, float> &map, FVector2D texture_size, FVector2D map_size, bool isGeoData);
  77. UFUNCTION(BlueprintCallable, Category=HeatMap)
  78. void CreateWithGeoInfoMap(const TMap<FVector, float> &map);
  79. UFUNCTION(BlueprintCallable, Category=HeatMap)
  80. void AddPointHeightValue(const FVector2D &pos, float value);
  81. UFUNCTION(BlueprintCallable, Category=HeatMap)
  82. void DeletePointHeightValue(const FVector2D& pos);
  83. UFUNCTION(BlueprintCallable, Category=HeatMap)
  84. void setPointInfluenceSize(int32 size);
  85. UFUNCTION(BlueprintCallable, Category=HeatMap)
  86. void ReGenerateMapAndMaterial();
  87. UFUNCTION(BlueprintCallable, Category=HeatMap)
  88. void setMapGeoLocation(FVector loc);
  89. UFUNCTION(BlueprintCallable, Category=HeatMap)
  90. TMap<FVector2D, float> ConvertGeoValueMapToUnrealValueMap(const TMap<FVector, float>& map);
  91. protected:
  92. UPROPERTY(BlueprintReadWrite, Category=HeatMap)
  93. UMaterialInstanceDynamic* Material;
  94. // 高度图点集数据
  95. UPROPERTY(BlueprintReadWrite, Category=HeatMap)
  96. TMap<FVector2D, float> PointHeightValueMap;
  97. // 地理点数据
  98. UPROPERTY(BlueprintReadWrite, Category=HeatMap)
  99. TMap<FVector, float> GeoInfoMap;
  100. UPROPERTY(BlueprintReadWrite, Category=HeatMap)
  101. E_HeatMapType m_type;
  102. UFUNCTION(BlueprintCallable, Category=HeatMap)
  103. FVector ConvertGeoGraphicToEngine(FVector location);
  104. };