9#include "Components/ActorComponent.h"
10#include "Components/SkeletalMeshComponent.h"
15# pragma clang diagnostic push
16# pragma clang diagnostic ignored "-Wdeprecated-register"
17# pragma clang diagnostic ignored "-Wmisleading-indentation"
18# pragma clang diagnostic ignored "-Wint-in-bool-context"
19# pragma clang diagnostic ignored "-Wdeprecated-declarations"
20# pragma clang diagnostic ignored "-Wshadow"
23#include <Eigen/Cholesky>
24#include <Eigen/Eigenvalues>
26# pragma clang diagnostic pop
29#include "SpringBasedVegetationComponent.generated.h"
41 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Skeleton Bone")
43 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
45 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
46 FVector CenterOfMass = FVector(0,0,0);
54 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category =
"Skeleton Bone")
56 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
58 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
60 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
61 bool bIsStatic = false;
62 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
63 TArray<
int> ChildrenIds;
64 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
66 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
67 FRotator RestingAngles;
68 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
70 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
71 float SpringStrength = 1000.f;
72 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
73 FRotator AngularVelocity = FRotator(0,0,0);
74 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
75 FRotator AngularAcceleration = FRotator(0,0,0);
76 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
77 FTransform GlobalTransform;
78 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
79 FTransform GolbalInverseTransform;
80 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
82 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
83 FVector ExternalForces = FVector(0,0,0);
84 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
85 float CollisionForceProportionalFactor = 1.0f;
104 Eigen::Vector3d
Force = Eigen::Vector3d::Zero();
107 Eigen::Vector3d
Torque = Eigen::Vector3d::Zero();
119 Eigen::Vector3d AngularVelocity = Eigen::Vector3d::Zero();
126USTRUCT(BlueprintType)
131 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Skeleton Bone")
133 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
134 TArray<
int> EndJoints;
135 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
136 TArray<
int> EndToRootOrder;
137 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Skeleton Bone")
138 TArray<
int> RootToEndOrder;
141 void ComputeChildrenJointsAndBones();
142 void ComputeEndJoints();
143 void AddForce(const FString& BoneName, const FVector& Force);
144 void ClearExternalForces();
148UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
149class CARLA_API USpringBasedVegetationComponent :
public UActorComponent
155 USpringBasedVegetationComponent(const FObjectInitializer& ObjectInitializer);
159 void EndPlay(const EEndPlayReason::Type EndPlayReason)
override;
161 void TickComponent(
float DeltaTime,
162 enum ELevelTick TickType,
163 FActorComponentTickFunction * ThisTickFunction)
override;
165 void UpdateSkeletalMesh();
167 void UpdateGlobalTransform();
169 void GenerateCollisionCapsules();
171 void ResetComponent();
173 UFUNCTION(CallInEditor, Category = "Spring Based Vegetation Component")
174 void ComputeSpringStrengthForBranches();
177 void OnCollisionEvent(
181 FVector NormalImpulse,
182 const FHitResult& Hit);
185 void OnBeginOverlapEvent(
189 int32 OtherBodyIndex,
191 const FHitResult& SweepResult);
194 void OnEndOverlapEvent(
198 int32 OtherBodyIndex);
200 UFUNCTION(CallInEditor, Category = "Spring Based Vegetation Component")
201 void GenerateSkeletonHierarchy();
207 UFUNCTION(BlueprintCallable)
208 void AddForce(const FString& BoneName, const FVector& Force)
210 Skeleton.AddForce(BoneName, Force);
212 UPROPERTY(EditAnywhere, Category =
"Spring Based Vegetation Component")
213 TArray<FString> FixedJointsList = {
"joint1"};
215 UPROPERTY(EditAnywhere, Category =
"Spring Based Vegetation Component")
216 TArray<FString> DebugJointsToSimulate = {};
220 void ComputePerJointProperties(
221 std::vector<FJointProperties>& JointLocalPropertiesList,
222 std::vector<FJointProperties>& JointPropertiesList);
223 void ComputeCompositeBodyContribution(
224 std::vector<FJointProperties>& JointLocalPropertiesList,
225 std::vector<FJointProperties>& JointPropertiesList);
226 void ComputeFictitiousForces(
227 std::vector<FJointProperties>& JointLocalPropertiesList,
228 std::vector<FJointProperties>& JointPropertiesList);
229 void ResolveContactsAndCollisions(
230 std::vector<FJointProperties>& JointLocalPropertiesList,
231 std::vector<FJointProperties>& JointPropertiesList);
232 void SolveEquationOfMotion(std::vector<FJointProperties>& JointPropertiesList,
float DeltaTime);
234 std::vector<FJointCollision> JointCollisionList;
237 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Spring Based Vegetation Component")
238 USkeletalMeshComponent* SkeletalMesh;
240 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
243 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
246 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
249 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
252 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
253 FVector Gravity = FVector(0,0,-1);
255 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
256 float BaseSpringStrength = 10000.f;
258 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
259 float MinSpringStrength = 2000.f;
261 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
262 float HorizontalFallof = 0.1f;
264 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
265 float VerticalFallof = 0.1f;
267 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
268 float RestFactor = 0.5f;
270 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
271 float DeltaTimeOverride = -1.f;
273 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
274 float CollisionForceParameter = 10.f;
276 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
277 float CollisionForceMinVel = 1.f;
279 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
280 float ForceDistanceFalloffExponent = 1.f;
281 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
282 float ForceMaxDistance = 180.f;
283 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
284 float MinForceFactor = 0.01;
285 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
286 float LineTraceMaxDistance = 180.f;
287 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
288 float CapsuleRadius = 6.0f;
289 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
290 float MinBoneLength = 10.f;
291 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
292 FVector SpringStrengthMulFactor = FVector(1,1,1);
293 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
294 float VehicleCenterZOffset = 120.f;
299 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
302 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spring Based Vegetation Component")
303 bool DebugEnableVisualization {
false };
305 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Spring Based Vegetation Component")
306 bool DebugEnableAllCollisions {
false };
308 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"Spring Based Vegetation Component")
309 bool bAutoComputeStrength =
true;
Eigen::Vector3d LocalAngularAcceleration
Eigen::Matrix3d InertiaTensor
Eigen::Vector3d LinearVelocity
Eigen::Matrix3d JointToGlobalMatrix
Eigen::Vector3d LinearAcceleration
Eigen::Vector3d FictitiousTorque
Eigen::Vector3d AngularAcceleration
Eigen::Vector3d CenterOfMass