Patch MuJoCo plugin #50

Merged
evanvyktori merged 6 commits from ft-pre-post-substep-delegates into main 2025-04-30 14:22:04 +00:00
2 changed files with 30 additions and 0 deletions
Showing only changes of commit d311284050 - Show all commits

View File

@ -109,6 +109,12 @@ template <typename ComponentType> void AMujocoVolumeActor::AssignComponentsToArr
}
}
template <typename UserClass>
void AMujocoVolumeActor::BindPostPhysicDelegate(UserClass* Object, void(UserClass::* Func)(float))
{
PostPhysicUpdateDelegate.BindUObject(Object, Func);
}
void AMujocoVolumeActor::InitializeMujoco()
{
if (!Options)
@ -391,11 +397,17 @@ void AMujocoVolumeActor::Tick(float DeltaTime)
{
if (MujocoData)
{
// TODO rename FrameSkip -> SimStepsPerGameFrame - Min 1 - Default 16
// TODO timestep default .001 (1ms)
// TODO mj_step only inside the for loop
mj_step(MujocoModel.Get(), MujocoData.Get());
PostPhysicUpdateDelegate.ExecuteIfBound(MujocoData->time);
for (int32 Frame = 0; Frame < FrameSkip; ++Frame)
{
mj_step(MujocoModel.Get(), MujocoData.Get());
PostPhysicUpdateDelegate.ExecuteIfBound(MujocoData->time);
}
for (int32 i = 1; i < BodyComponents.Num(); ++i)

View File

@ -21,6 +21,10 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnMujocoCompileBegin);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMujocoCompileError, FString, Error);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnMujocoCompileSuccess);
// To be called after mj_step
DECLARE_DELEGATE_OneParam(FPostPhysicUpdate, float);
UCLASS(Blueprintable, BlueprintType)
class LUCKYMUJOCO_API AMujocoVolumeActor : public AActor
{
@ -76,6 +80,20 @@ public:
UPROPERTY(BlueprintAssignable, Category = "Mujoco | Events")
FOnMujocoCompileSuccess OnMujocoCompileSuccess;
// ---------------------------
// ------- POST UPDATE -------
// ---------------------------
private:
FPostPhysicUpdate PostPhysicUpdateDelegate;
public:
/**
* @description Register a delegate to be executed after mj_step
* @param Object
*/
template<typename UserClass>
void BindPostPhysicDelegate(UserClass* Object, void (UserClass::*Func)(float));
UFUNCTION(BlueprintCallable, Category = "Mujoco")
void SetActuatorValue(const FString& ActuatorName, double Value);