Skip to content

Commit

Permalink
Merge pull request #32 from nkinta/master
Browse files Browse the repository at this point in the history
カーブアセットを作らなくても、カーブでのパラメーター編集ができるように。
  • Loading branch information
pafuhana1213 authored Apr 11, 2022
2 parents b9e0f63 + 8514fa2 commit 2d8006a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,49 +355,49 @@ void FAnimNode_KawaiiPhysics::UpdatePhysicsSettingsOfModifyBones()

// Damping
Bone.PhysicsSettings.Damping = PhysicsSettings.Damping;
if (TotalBoneLength > 0 && DampingCurve && DampingCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !DampingCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.Damping *= DampingCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.Damping *= DampingCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.Damping = FMath::Clamp<float>(Bone.PhysicsSettings.Damping, 0.0f, 1.0f);

// WorldLocationDamping
Bone.PhysicsSettings.WorldDampingLocation = PhysicsSettings.WorldDampingLocation;
if (TotalBoneLength > 0 && WorldDampingLocationCurve && WorldDampingLocationCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !WorldDampingLocationCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.WorldDampingLocation *= WorldDampingLocationCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.WorldDampingLocation *= WorldDampingLocationCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.WorldDampingLocation = FMath::Clamp<float>(Bone.PhysicsSettings.WorldDampingLocation, 0.0f, 1.0f);

// WorldRotationDamping
Bone.PhysicsSettings.WorldDampingRotation = PhysicsSettings.WorldDampingRotation;
if (TotalBoneLength > 0 && WorldDampingRotationCurve && WorldDampingRotationCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !WorldDampingRotationCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.WorldDampingRotation *= WorldDampingRotationCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.WorldDampingRotation *= WorldDampingRotationCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.WorldDampingRotation = FMath::Clamp<float>(Bone.PhysicsSettings.WorldDampingRotation, 0.0f, 1.0f);

// Stiffness
Bone.PhysicsSettings.Stiffness = PhysicsSettings.Stiffness;
if (TotalBoneLength > 0 && StiffnessCurve && StiffnessCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !StiffnessCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.Stiffness *= StiffnessCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.Stiffness *= StiffnessCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.Stiffness = FMath::Clamp<float>(Bone.PhysicsSettings.Stiffness, 0.0f, 1.0f);

// Radius
Bone.PhysicsSettings.Radius = PhysicsSettings.Radius;
if (TotalBoneLength > 0 && RadiusCurve && RadiusCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !RadiusCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.Radius *= RadiusCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.Radius *= RadiusCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.Radius = FMath::Max<float>(Bone.PhysicsSettings.Radius, 0.0f);

// LimitAngle
Bone.PhysicsSettings.LimitAngle = PhysicsSettings.LimitAngle;
if (TotalBoneLength > 0 && LimitAngleCurve && LimitAngleCurve->GetCurves().Num() > 0)
if (TotalBoneLength > 0 && !LimitAngleCurveData.GetRichCurve()->IsEmpty())
{
Bone.PhysicsSettings.LimitAngle *= LimitAngleCurve->GetFloatValue(LengthRate);
Bone.PhysicsSettings.LimitAngle *= LimitAngleCurveData.GetRichCurve()->Eval(LengthRate);
}
Bone.PhysicsSettings.LimitAngle = FMath::Max<float>(Bone.PhysicsSettings.LimitAngle, 0.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,54 @@ struct KAWAIIPHYSICS_API FAnimNode_KawaiiPhysics : public FAnimNode_SkeletalCont
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
FKawaiiPhysicsSettings PhysicsSettings;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* DampingCurve_DEPRECATED = nullptr;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* WorldDampingLocationCurve_DEPRECATED = nullptr;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* WorldDampingRotationCurve_DEPRECATED = nullptr;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* StiffnessCurve_DEPRECATED = nullptr;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* RadiusCurve_DEPRECATED = nullptr;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY()
UCurveFloat* LimitAngleCurve_DEPRECATED = nullptr;

// START SKYBLUE MOD
/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* DampingCurve = nullptr;
FRuntimeFloatCurve DampingCurveData;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* WorldDampingLocationCurve = nullptr;
FRuntimeFloatCurve WorldDampingLocationCurveData;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* WorldDampingRotationCurve = nullptr;
FRuntimeFloatCurve WorldDampingRotationCurveData;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* StiffnessCurve = nullptr;
FRuntimeFloatCurve StiffnessCurveData;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* RadiusCurve = nullptr;
FRuntimeFloatCurve RadiusCurveData;

/** Curve for adjusting the set value of physical behavior. Use rate of bone length from Root */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Settings", meta = (PinHiddenByDefault))
UCurveFloat* LimitAngleCurve = nullptr;
FRuntimeFloatCurve LimitAngleCurveData;

/** Flag to update each frame physical parameter. Disable to improve performance */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Advanced Physics Settings", meta = (PinHiddenByDefault))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,45 @@ void UAnimGraphNode_KawaiiPhysics::ValidateAnimNodePostCompile(FCompilerResultsL

}

struct FKawaiiPhysicsVersion
{
enum Type
{
BeforeCustomVersionWasAdded,
UseRuntimeFloatCurve,
// -----<new versions can be added above this line>-------------------------------------------------
VersionPlusOne,
LatestVersion = VersionPlusOne - 1
};

// The GUID for this custom version number
const static FGuid GUID;

private:
FKawaiiPhysicsVersion() {};
};

const FGuid FKawaiiPhysicsVersion::GUID(0x4B2D3E25, 0xCD681D29, 0x2DB298D7, 0xAD3E55FA);

const FCustomVersionRegistration GRegisterKawaiiPhysCustomVersion(FKawaiiPhysicsVersion::GUID, FKawaiiPhysicsVersion::LatestVersion, TEXT("Kawaii-Phys"));

void UAnimGraphNode_KawaiiPhysics::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);

Ar.UsingCustomVersion(FKawaiiPhysicsVersion::GUID);

if (Ar.CustomVer(FKawaiiPhysicsVersion::GUID) < FKawaiiPhysicsVersion::UseRuntimeFloatCurve)
{
Node.DampingCurveData.ExternalCurve = Node.DampingCurve_DEPRECATED;
Node.WorldDampingLocationCurveData.ExternalCurve = Node.WorldDampingLocationCurve_DEPRECATED;
Node.WorldDampingRotationCurveData.ExternalCurve = Node.WorldDampingRotationCurve_DEPRECATED;
Node.StiffnessCurveData.ExternalCurve = Node.StiffnessCurve_DEPRECATED;
Node.RadiusCurveData.ExternalCurve = Node.RadiusCurve_DEPRECATED;
Node.LimitAngleCurveData.ExternalCurve = Node.LimitAngleCurve_DEPRECATED;
}


}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class UAnimGraphNode_KawaiiPhysics : public UAnimGraphNode_SkeletalControlBase
virtual void Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent* SkelMeshComp) const override;
// End of UAnimGraphNode_SkeletalControlBase interface

// UObject interface
virtual void Serialize(FArchive& Ar) override;
// End of UObject interface

private:
/** Constructing FText strings can be costly, so we cache the node's title */
FNodeTitleTextTable CachedNodeTitles;
Expand Down

0 comments on commit 2d8006a

Please sign in to comment.