Add synchronisation events to MjScene
This commit is contained in:
@@ -76,6 +76,10 @@ public class MjScene : MonoBehaviour {
|
|||||||
|
|
||||||
private List<MjComponent> _orderedComponents;
|
private List<MjComponent> _orderedComponents;
|
||||||
|
|
||||||
|
public EventHandler preUpdateEvent;
|
||||||
|
public EventHandler<MjStepArgs> ctrlCallback;
|
||||||
|
public EventHandler postUpdateEvent;
|
||||||
|
|
||||||
protected unsafe void Start() {
|
protected unsafe void Start() {
|
||||||
CreateScene();
|
CreateScene();
|
||||||
}
|
}
|
||||||
@@ -85,7 +89,9 @@ public class MjScene : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected unsafe void FixedUpdate() {
|
protected unsafe void FixedUpdate() {
|
||||||
|
preUpdateEvent?.Invoke(this, EventArgs.Empty);
|
||||||
StepScene();
|
StepScene();
|
||||||
|
postUpdateEvent?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SceneRecreationAtLateUpdateRequested = false;
|
public bool SceneRecreationAtLateUpdateRequested = false;
|
||||||
@@ -314,7 +320,14 @@ public class MjScene : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
Profiler.BeginSample("MjStep");
|
Profiler.BeginSample("MjStep");
|
||||||
Profiler.BeginSample("MjStep.mj_step");
|
Profiler.BeginSample("MjStep.mj_step");
|
||||||
MujocoLib.mj_step(Model, Data);
|
if (ctrlCallback != null){
|
||||||
|
MujocoLib.mj_step1(Model, Data);
|
||||||
|
ctrlCallback?.Invoke(this, new MjStepArgs(Model, Data));
|
||||||
|
MujocoLib.mj_step2(Model, Data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MujocoLib.mj_step(Model, Data);
|
||||||
|
}
|
||||||
Profiler.EndSample(); // MjStep.mj_step
|
Profiler.EndSample(); // MjStep.mj_step
|
||||||
CheckForPhysicsException();
|
CheckForPhysicsException();
|
||||||
|
|
||||||
@@ -447,5 +460,18 @@ public class MjScene : MonoBehaviour {
|
|||||||
Debug.LogWarning("Failed to save Xml to a file: " + ex.ToString(), this);
|
Debug.LogWarning("Failed to save Xml to a file: " + ex.ToString(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MjStepArgs : EventArgs
|
||||||
|
{
|
||||||
|
public unsafe MjStepArgs(MujocoLib.mjModel_* model, MujocoLib.mjData_* data){
|
||||||
|
this.model = model;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
public readonly unsafe MujocoLib.mjModel_* model;
|
||||||
|
public readonly unsafe MujocoLib.mjData_* data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user