Created
October 14, 2018 08:53
-
-
Save erikdubbelboer/cd674cd29399bc9bddb9c9c8a6bd7886 to your computer and use it in GitHub Desktop.
Unreal Engine 4 DistributionVectorUniformParam Particle Distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DistributionVectorUniformParam.h" | |
#include "Particles/ParticleSystemComponent.h" | |
UDistributionVectorUniformParam::UDistributionVectorUniformParam(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{ | |
} | |
FVector UDistributionVectorUniformParam::GetValue(float F, UObject* Data, int32 Extreme, struct FRandomStream* InRandomStream) const | |
{ | |
FVector LocalMax = DefaultMax; | |
FVector LocalMin = DefaultMin; | |
FVector ParamMax; | |
bool bFoundParam = GetParamValue(Data, MaxParameterName, ParamMax); | |
if (bFoundParam) | |
{ | |
LocalMax = ParamMax; | |
} | |
FVector ParamMin; | |
bFoundParam = GetParamValue(Data, MinParameterName, ParamMin); | |
if (bFoundParam) | |
{ | |
LocalMin = ParamMin; | |
} | |
float fX = LocalMin.X + (LocalMax.X - LocalMin.X) * DIST_GET_RANDOM_VALUE(InRandomStream); | |
float fY = LocalMin.Y + (LocalMax.Y - LocalMin.Y) * DIST_GET_RANDOM_VALUE(InRandomStream); | |
float fZ = LocalMin.Z + (LocalMax.Z - LocalMin.Z) * DIST_GET_RANDOM_VALUE(InRandomStream); | |
return FVector(fX, fY, fZ); | |
} | |
bool UDistributionVectorUniformParam::GetParamValue(UObject* Data, FName ParamName, FVector& OutVector) const | |
{ | |
bool bFoundParam = false; | |
UParticleSystemComponent* ParticleComp = Cast<UParticleSystemComponent>(Data); | |
if (ParticleComp) | |
{ | |
bFoundParam = ParticleComp->GetAnyVectorParameter(ParamName, OutVector); | |
} | |
return bFoundParam; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "CoreMinimal.h" | |
#include "Distributions/DistributionVector.h" | |
#include "DistributionVectorUniformParam.generated.h" | |
UCLASS(collapsecategories, hidecategories = Object, editinlinenew) | |
class PROJECT_API UDistributionVectorUniformParam : public UDistributionVector | |
{ | |
GENERATED_UCLASS_BODY() | |
UPROPERTY(EditAnywhere) | |
FName MaxParameterName; | |
UPROPERTY(EditAnywhere) | |
FName MinParameterName; | |
UPROPERTY(EditAnywhere) | |
FVector DefaultMax; | |
UPROPERTY(EditAnywhere) | |
FVector DefaultMin; | |
virtual FVector GetValue(float F = 0.f, UObject* Data = NULL, int32 LastExtreme = 0, struct FRandomStream* InRandomStream = NULL) const override; | |
virtual bool CanBeBaked() const override { return false; } | |
virtual bool IsPostLoadThreadSafe() const override { return true; }; | |
public: | |
UDistributionVectorUniformParam(); | |
private: | |
bool GetParamValue(UObject* Data, FName ParamName, FVector& OutVector) const; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@script526 of course, everyone is free to use it. Cool looking project, and especially nice that it's open source!