FT - Access low level mujoco data from anywhere

+ be careful, this is not const!
This commit is contained in:
Jb win 2025-04-30 15:53:13 +07:00
parent 0143d8d7d7
commit a4dcdb561e
2 changed files with 28 additions and 14 deletions

View File

@ -202,6 +202,12 @@ void AMujocoVolumeActor::InitializeMujoco()
} }
} }
mjData_& AMujocoVolumeActor::GetMujocoData() const
{
check(MujocoData.IsValid());
return *MujocoData.Get();
}
void AMujocoVolumeActor::SetActuatorValue(const FString& ActuatorName, double Value) void AMujocoVolumeActor::SetActuatorValue(const FString& ActuatorName, double Value)
{ {
if (MujocoModel) if (MujocoModel)

View File

@ -60,8 +60,16 @@ class LUCKYMUJOCO_API AMujocoVolumeActor : public AActor
template <typename ComponentType> void AssignComponentsToArray(UWorld* World, TArray<TSoftObjectPtr<ComponentType>>& ComponentArray); template <typename ComponentType> void AssignComponentsToArray(UWorld* World, TArray<TSoftObjectPtr<ComponentType>>& ComponentArray);
public: public:
AMujocoVolumeActor(); AMujocoVolumeActor();
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void PostRegisterAllComponents() override;
virtual void Tick(float DeltaTime) override;
virtual void PostInitializeComponents() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mujoco | Simulation", meta = (Min = 0, Max = 100, ClampMin = 0, ClampMax = 100)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Mujoco | Simulation", meta = (Min = 0, Max = 100, ClampMin = 0, ClampMax = 100))
int32 FrameSkip = 0; int32 FrameSkip = 0;
@ -80,6 +88,12 @@ public:
UPROPERTY(BlueprintAssignable, Category = "Mujoco | Events") UPROPERTY(BlueprintAssignable, Category = "Mujoco | Events")
FOnMujocoCompileSuccess OnMujocoCompileSuccess; FOnMujocoCompileSuccess OnMujocoCompileSuccess;
/**
* @description
* @return mjData_ - Full access to mujoco scene options and data
*/
mjData_& GetMujocoData() const;
// --------------------------- // ---------------------------
// ------- POST UPDATE ------- // ------- POST UPDATE -------
// --------------------------- // ---------------------------
@ -93,7 +107,10 @@ public:
template<typename UserClass> template<typename UserClass>
void BindPostPhysicDelegate(UserClass* Object, void (UserClass::*Func)(float)); void BindPostPhysicDelegate(UserClass* Object, void (UserClass::*Func)(float));
// -------------------------
// ------- ACTUATORS -------
// -------------------------
UFUNCTION(BlueprintCallable, Category = "Mujoco") UFUNCTION(BlueprintCallable, Category = "Mujoco")
void SetActuatorValue(const FString& ActuatorName, double Value); void SetActuatorValue(const FString& ActuatorName, double Value);
@ -112,6 +129,9 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Mujoco") UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Mujoco")
FVector2D GetActuatorRangeByIndex(int32 ActuatorIndex) const; FVector2D GetActuatorRangeByIndex(int32 ActuatorIndex) const;
// ----------------------
// ------- JOINTS -------
// ----------------------
UFUNCTION(BlueprintCallable, Category = "Mujoco") UFUNCTION(BlueprintCallable, Category = "Mujoco")
void SetJointValue(const FString& JointName, double Value); void SetJointValue(const FString& JointName, double Value);
@ -123,16 +143,4 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Mujoco") UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Mujoco")
double GetJointValueByIndex(int32 JointIndex) const; double GetJointValueByIndex(int32 JointIndex) const;
virtual void PostRegisterAllComponents() override;
virtual void Tick(float DeltaTime) override;
virtual void PostInitializeComponents() override;
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
}; };