| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | /** @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<FColor>& 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<FColor> GetColorDataFromTexture(UTexture2D* texture, FVector2D textureSize);	TArray<FColor> GetColorDataFromPointHeightMap(const TMap<FVector2D, float> &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<FVector2D, float> &map, FVector2D texture_size, FVector2D map_size, bool isGeoData);			UFUNCTION(BlueprintCallable, Category=HeatMap)	void CreateWithGeoInfoMap(const TMap<FVector, float> &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<FVector2D, float> ConvertGeoValueMapToUnrealValueMap(const TMap<FVector, float>& map);protected:	UPROPERTY(BlueprintReadWrite, Category=HeatMap)	UMaterialInstanceDynamic* Material;		// 高度图点集数据	UPROPERTY(BlueprintReadWrite, Category=HeatMap)	TMap<FVector2D, float> PointHeightValueMap;	// 地理点数据	UPROPERTY(BlueprintReadWrite, Category=HeatMap)	TMap<FVector, float> GeoInfoMap;		UPROPERTY(BlueprintReadWrite, Category=HeatMap)	E_HeatMapType m_type;	UFUNCTION(BlueprintCallable, Category=HeatMap)	FVector ConvertGeoGraphicToEngine(FVector location);};
 |