Extents Modifier 和 Bounds Modifier这两个节点看起来很像,都是修改Point的Bouding Box,查看一下源代码,简单看一下它们的区别
两个节点的代码对比
Bounds Modifier
源代码
switch (Mode)
{
case EPCGBoundsModifierMode::Intersect:
ProcessPoints(Context, Inputs, Outputs, [&Bounds, bAffectSteepness, Steepness](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetLocalBounds(InPoint.GetLocalBounds().Overlap(Bounds));
if (bAffectSteepness)
{
OutPoint.Steepness = FMath::Min(InPoint.Steepness, Steepness);
}
return true;
});
break;
case EPCGBoundsModifierMode::Include:
ProcessPoints(Context, Inputs, Outputs, [&Bounds, bAffectSteepness, Steepness](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetLocalBounds(InPoint.GetLocalBounds() + Bounds);
if (bAffectSteepness)
{
OutPoint.Steepness = FMath::Max(InPoint.Steepness, Steepness);
}
return true;
});
break;
case EPCGBoundsModifierMode::Translate:
ProcessPoints(Context, Inputs, Outputs, [&BoundsMin, &BoundsMax, bAffectSteepness, Steepness](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.BoundsMin += BoundsMin;
OutPoint.BoundsMax += BoundsMax;
if (bAffectSteepness)
{
OutPoint.Steepness = FMath::Clamp(InPoint.Steepness + Steepness, 0.0f, 1.0f);
}
return true;
});
break;
case EPCGBoundsModifierMode::Scale:
ProcessPoints(Context, Inputs, Outputs, [&BoundsMin, &BoundsMax, bAffectSteepness, Steepness](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.BoundsMin *= BoundsMin;
OutPoint.BoundsMax *= BoundsMax;
if (bAffectSteepness)
{
OutPoint.Steepness = FMath::Clamp(InPoint.Steepness * Steepness, 0.0f, 1.0f);
}
return true;
});
break;
case EPCGBoundsModifierMode::Set:
ProcessPoints(Context, Inputs, Outputs, [&Bounds, bAffectSteepness, Steepness](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetLocalBounds(Bounds);
if (bAffectSteepness)
{
OutPoint.Steepness = Steepness;
}
return true;
});
break;
}
Bounds Modifier
源代码
switch (Mode)
{
case EPCGPointExtentsModifierMode::Minimum:
ProcessPoints(Context, Inputs, Outputs, [Extents](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetExtents(FVector::Min(Extents, InPoint.GetExtents()));
return true;
});
break;
case EPCGPointExtentsModifierMode::Maximum:
ProcessPoints(Context, Inputs, Outputs, [Extents](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetExtents(FVector::Max(Extents, InPoint.GetExtents()));
return true;
});
break;
case EPCGPointExtentsModifierMode::Add:
ProcessPoints(Context, Inputs, Outputs, [Extents](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetExtents(Extents + InPoint.GetExtents());
return true;
});
break;
case EPCGPointExtentsModifierMode::Multiply:
ProcessPoints(Context, Inputs, Outputs, [Extents](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetExtents(Extents * InPoint.GetExtents());
return true;
});
break;
case EPCGPointExtentsModifierMode::Set:
ProcessPoints(Context, Inputs, Outputs, [Extents](const FPCGPoint& InPoint, FPCGPoint& OutPoint){
OutPoint = InPoint;
OutPoint.SetExtents(Extents);
return true;
});
break;
}
从代码上看,除了运算模式的区别,和它们的名字一样Bounds Modifier操作的目标是Point的Bounds而Extents Modifier 操作的目标是Point的Extents,并且Bounds Modifier可以选择性地影响Steepness,而Extents Modifier没有这个选项。所以问题的关键就是Bounds和Extents的区别。下面我们看一下PCGPoint的代码:
USTRUCT(BlueprintType)
struct PCG_API FPCGPoint
{
GENERATED_BODY()
public:
FPCGPoint() = default;
FPCGPoint(const FTransform& InTransform, float InDensity, int32 InSeed);
FBox GetLocalBounds() const;
FBox GetLocalDensityBounds() const;
void SetLocalBounds(const FBox& InBounds);
FBoxSphereBounds GetDensityBounds() const;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FTransform Transform;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
float Density = 1.0f;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FVector BoundsMin = -FVector::One();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FVector BoundsMax = FVector::One();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FVector4 Color = FVector4::One();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties, meta = (ClampMin = "0", ClampMax = "1"))
float Steepness = 0.5f;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
int32 Seed = 0;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Properties|Metadata")
int64 MetadataEntry = -1;
FVector GetExtents() const { return (BoundsMax - BoundsMin) / 2.0; }
void SetExtents(const FVector& InExtents)
{
const FVector Center = GetLocalCenter();
BoundsMin = Center - InExtents;
BoundsMax = Center + InExtents;
}
FVector GetScaledExtents() const { return GetExtents() * Transform.GetScale3D(); }
FVector GetLocalCenter() const { return (BoundsMax + BoundsMin) / 2.0; }
void SetLocalCenter(const FVector& InCenter)
{
const FVector Delta = InCenter - GetLocalCenter();
BoundsMin += Delta;
BoundsMax += Delta;
}
using PointCustomPropertyGetter = TFunction<bool(const FPCGPoint&, void*)>;
using PointCustomPropertySetter = TFunction<bool(FPCGPoint&, const void*)>;
static bool HasCustomPropertyGetterSetter(FName Name);
static TUniquePtr<IPCGAttributeAccessor> CreateCustomPropertyAccessor(FName Name);
};
在Point中并没有Extents这个成员变量,而只有BoundsMin和BoundsMax这两个Vector3的成员变量
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FVector BoundsMin = -FVector::One();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Properties)
FVector BoundsMax = FVector::One();
Extents和Bounds之间的关系:
FVector GetExtents() const { return (BoundsMax - BoundsMin) / 2.0; }
void SetExtents(const FVector& InExtents)
{
const FVector Center = GetLocalCenter();
BoundsMin = Center - InExtents;
BoundsMax = Center + InExtents;
}
小结
Extents Modifier 和 Bounds Modifier的本质并没有区别