Bepu2 multiple objects sleeping at the same time.
Posted: Wed May 22, 2019 10:19 pm
Hello currently I'm testing the latest version of bepu 2, my test consist of creating a big floor, and ring of stacked cubes (4k in total). After doing a simulation.Timestep I update the position of the internal transform. The problem is that the fps is constant and all the objects sleep at the same time creating a spike of 1.2seconds. Using bepu1 the objects slowly sleep lowering fps reliable.
I use the following code
IndexComponent is a dictionary with the indexhandle and a component helper that updates the position and rotation of the internal transform, used for the renderer.
Is there a list of objects or index that where moved, or an event that an object was moved by the physics?
Also the user can manually move objects, which is the best way to wake up a sleeping object?
I use the following code
Code: Select all
protected internal override void Step()
{
Simulation.Timestep(dt, ThreadDispatcher);
Bepu2ComponentHelper.UpdatePositions();
}
internal static void UpdatePositions()
{
for (var i = 0; i < Simulation.Bodies.Sets.Length; ++i)
{
ref var set = ref Simulation.Bodies.Sets[i];
if (!set.Allocated)
{
continue;
}
for (var bodyIndex = 0; bodyIndex < set.Count; ++bodyIndex)
{
UpdatePose(i, bodyIndex);
}
}
}
static void UpdatePose(int setIndex, int indexInSet)
{
ref var set = ref Simulation.Bodies.Sets[setIndex];
var handle = set.IndexToHandle[indexInSet];
if (setIndex == 0)
{
if (set.Activity [indexInSet].SleepCandidate)
{
return;
}
if (IndexComponent.TryGetValue(handle, out var component))
{
component.PositionChanged();
}
}
}
public void PositionChanged()
{
_preventPositionUpdate = true;
transform.SetPositionOrientation(_bodyReference.Pose.Position.ToSdk(), _bodyReference.Pose.Orientation.ToSdk());
_preventPositionUpdate = false;
}
Is there a list of objects or index that where moved, or an event that an object was moved by the physics?
Also the user can manually move objects, which is the best way to wake up a sleeping object?