/* * @Author: namidame * @Description: A Heatmap Generate Plugin, Supports Heightmap, Texture Coordinate Points And Geographic Location Data. * @Date: 2023/03/24 */ #pragma once #include "CoreMinimal.h" #include "ProceduralMeshComponent.h" #include "GameFramework/Actor.h" #include "Materials/MaterialInstanceDynamic.h" #include "Curves/CurveFloat.h" #include "Engine/Texture2D.h" #include "HeatMapActor.generated.h" UENUM(BlueprintType) enum class E_HeatMapType : uint8 { NONE, HEIGHT_MAP, POINT_HEIGHT_DATA, GEO_DATA, }; UCLASS() class HEATMAP_API AHeatMapActor : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AHeatMapActor(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) UProceduralMeshComponent* MapMesh; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) UMaterialInterface* HeatMapActorMaterial; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) UTexture2D* HeightMapTexture; UFUNCTION(BlueprintCallable, Category=HeatMap) void CreateMapMesh(FVector2D mapSize); UFUNCTION(BlueprintCallable, Category=HeatMap) void CreateWithHeightMap(UTexture2D* texture, FVector2D mapSize); UFUNCTION(BlueprintCallable, Category=HeatMap) void CreateWithData(const TArray& colorArr, FVector2D textureSize, FVector2D mapSize); UFUNCTION(BlueprintCallable, Category=HeatMap) void setMaterialLerpScale(float scale); UFUNCTION(BlueprintCallable, Category=HeatMap) void setMaterialHeightScale(float scale); UFUNCTION(BlueprintCallable, Category=HeatMap) void setMaterialOpacity(float opacity); static TArray GetColorDataFromTexture(UTexture2D* texture, FVector2D textureSize); TArray GetColorDataFromPointHeightMap(const TMap &map, FVector2D texture_size, int32 influenceSize); UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) FVector2D TextureSize; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) FVector2D MapSize; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) FVector2D MapSecment; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) float LerpScale; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) float HeightScale; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) float Opacity; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) int32 InfluenceSize; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=HeatMap) UCurveFloat* InfluenceCurve; UFUNCTION(BlueprintCallable, Category=HeatMap) void setMapSecment(FVector2D secment); UFUNCTION(BlueprintCallable, Category=HeatMap) void setMapSize(FVector2D size); UFUNCTION(BlueprintCallable, Category=HeatMap) void CreateWithPointHeightValue(const TMap &map, FVector2D texture_size, FVector2D map_size, bool isGeoData); UFUNCTION(BlueprintCallable, Category=HeatMap) void CreateWithGeoInfoMap(const TMap &map); UFUNCTION(BlueprintCallable, Category=HeatMap) void AddPointHeightValue(const FVector2D &pos, float value); UFUNCTION(BlueprintCallable, Category=HeatMap) void DeletePointHeightValue(const FVector2D& pos); UFUNCTION(BlueprintCallable, Category=HeatMap) void setPointInfluenceSize(int32 size); UFUNCTION(BlueprintCallable, Category=HeatMap) void ReGenerateMapAndMaterial(); UFUNCTION(BlueprintCallable, Category=HeatMap) void setMapGeoLocation(FVector loc); UFUNCTION(BlueprintCallable, Category=HeatMap) TMap ConvertGeoValueMapToUnrealValueMap(const TMap& map); protected: UPROPERTY(BlueprintReadWrite, Category=HeatMap) UMaterialInstanceDynamic* Material; // 高度图点集数据 UPROPERTY(BlueprintReadWrite, Category=HeatMap) TMap PointHeightValueMap; // 地理点数据 UPROPERTY(BlueprintReadWrite, Category=HeatMap) TMap GeoInfoMap; UPROPERTY(BlueprintReadWrite, Category=HeatMap) E_HeatMapType m_type; UFUNCTION(BlueprintCallable, Category=HeatMap) FVector ConvertGeoGraphicToEngine(FVector location); };