Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Renderer #89

Open
galvesribeiro opened this issue Sep 15, 2024 · 34 comments
Open

Debug Renderer #89

galvesribeiro opened this issue Sep 15, 2024 · 34 comments

Comments

@galvesribeiro
Copy link

Hello!

Is there bindings for the Debug Renderer from Jolt?

If yes, can you point me where is it as I couldn't find the types and overloads for it.

Thank you!

@amerkoleci
Copy link
Owner

Hello,
Not at the moment but on the roadmap, feel free to submit PR.

Thanks!

@galvesribeiro
Copy link
Author

Cool. Are the types exposed on the C API or does it require a PR there as well?

@amerkoleci
Copy link
Owner

They are not exposed on the C API layer

@amerkoleci
Copy link
Owner

Debug Renderer (WIP) just landed in joltc, amerkoleci/joltc@0ab6b36 will add C# stuff soon.

@amerkoleci
Copy link
Owner

Debug Renderer just landed in commit 6236bfc:
Version 2.9.1 contains all this goodies.

Cheers

@galvesribeiro
Copy link
Author

OMG! Thank you! I'll give it a try :D

@galvesribeiro
Copy link
Author

I had a Quick Look here on the DebugRenderer abstract class and overwrite the methods trying to understand/compare with the native examples and I got a few questions:

  • Do you plan to expose the CreateTriangleBatch method?
  • I see the DebugRenderer.NextFrame() method. Who calls it? Is that called by the natives code?

We are using Jolt on the server side. So my goal is to achieve something like PVD on PhysX. We'll create a tool which is listening on a given port like PVD. Then, the server at startup will connect to it. Every call on our DebugRenderer implementation methods, would essentially batch that command into some sort of queue. Then, when a frame is completed, we send the frame commands to the tool over that connection and will start a new batch for the next frame.

I don't see any way we are signaled that a frame was completed on the current DebugRenderer API since we don't have the CreateTriangleBatch. Do you think the best moment to send those batched commands to the tool after the call to PhysicsSystem.Update()?

Again, thanks for our efforts and for quick reply! This DebugRenderer support is very important for using this library.

@captainkidd5
Copy link

tacking onto this, would it be possible to have sorted drawing somehow? For example in the draw settings specify that only bodies with objectlayer.moving should be drawn, for example?

@amerkoleci
Copy link
Owner

tacking onto this, would it be possible to have sorted drawing somehow? For example in the draw settings specify that only bodies with objectlayer.moving should be drawn, for example?

Take look here: https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/DrawSettings.cs#L8

@captainkidd5
Copy link

So I'm not entirely sure how filtering works, I see that for example that DrawSettings has "DrawShape" which is of type Bool8.

Is this a flag thing? For example, how would I specify that I only want to draw shapes in ObjectLayers.Moving from DrawSettings?

@amerkoleci
Copy link
Owner

So I'm not entirely sure how filtering works, I see that for example that DrawSettings has "DrawShape" which is of type Bool8.

Is this a flag thing? For example, how would I specify that I only want to draw shapes in ObjectLayers.Moving from DrawSettings?

Not sure if this is supported by JoltPhysics, @jrouwe?

@jrouwe
Copy link

jrouwe commented Oct 3, 2024

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@jrouwe
Copy link

jrouwe commented Oct 3, 2024

We are using Jolt on the server side. So my goal is to achieve something like PVD on PhysX. We'll create a tool which is listening on a given port like PVD. Then, the server at startup will connect to it. Every call on our DebugRenderer implementation methods, would essentially batch that command into some sort of queue. Then, when a frame is completed, we send the frame commands to the tool over that connection and will start a new batch for the next frame.

This is exactly what the DebugRendererRecorder and DebugRendererPlayback classes do. The recorder has an EndFrame function that you need to call yourself at the end of the frame to flush all draw calls.

@captainkidd5
Copy link

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@amerkoleci would it be possible to create bindings for this?

@amerkoleci
Copy link
Owner

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@amerkoleci would it be possible to create bindings for this?

Just added BodyDrawFilter support, https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyDrawFilter.cs
Grab the new 2.9.5 nuget release

@galvesribeiro
Copy link
Author

Hey guys! Any suggestions about the questions above?

@amerkoleci
Copy link
Owner

This is exactly what the DebugRendererRecorder and DebugRendererPlayback classes do. The recorder has an EndFrame function that you need to call yourself at the end of the frame to flush all draw calls.

The author answered
This is exactly what the DebugRendererRecorder and DebugRendererPlayback classes do. The recorder has an EndFrame function that you need to call yourself at the end of the frame to flush all draw calls.

@galvesribeiro
Copy link
Author

Ah ok, sorry, I miss understood the Recorder part. In PVD recording means the writes to a static file which will later have to played back, got it.

Will try it and report back.

Thanks!

@captainkidd5
Copy link

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@amerkoleci would it be possible to create bindings for this?

Just added BodyDrawFilter support, https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyDrawFilter.cs Grab the new 2.9.5 nuget release

got it thank you. Is there a way to retrieve the ObjectLayer from a specific body? I don't see any way to retrieve it from the body itself, or from the body interface. Should I be associating that data on my own with the userdata?

@amerkoleci
Copy link
Owner

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@amerkoleci would it be possible to create bindings for this?

Just added BodyDrawFilter support, https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyDrawFilter.cs Grab the new 2.9.5 nuget release

got it thank you. Is there a way to retrieve the ObjectLayer from a specific body? I don't see any way to retrieve it from the body itself, or from the body interface. Should I be associating that data on my own with the userdata?

Need to expose this to joltc and C#
https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Body/Body.h#L123

Meanwhile you can use:
https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyInterface.cs#L389

Passing the Body.ID

@captainkidd5
Copy link

Oh I see I guess I overlooked that in BodyInterface. Thanks!!!

@captainkidd5
Copy link

captainkidd5 commented Oct 4, 2024

There's the BodyDrawFilter interface that allows you to specify which bodies you want to draw. You could override ShouldDraw and check the object layer of the body that's being passed in.

@amerkoleci would it be possible to create bindings for this?

Just added BodyDrawFilter support, https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyDrawFilter.cs Grab the new 2.9.5 nuget release

got it thank you. Is there a way to retrieve the ObjectLayer from a specific body? I don't see any way to retrieve it from the body itself, or from the body interface. Should I be associating that data on my own with the userdata?

Need to expose this to joltc and C# https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Body/Body.h#L123

Meanwhile you can use: https://github.com/amerkoleci/JoltPhysicsSharp/blob/main/src/JoltPhysicsSharp/BodyInterface.cs#L389

Passing the Body.ID

So it looks like both my program, as well as the newest release freeze when attempting to read the object layer both during the physics.update contact callbacks, as well as the draw filter as discussed above.

This can be reproduced by using the Sample.cs and attempting to read the layer:

protected virtual void OnContactAdded(PhysicsSystem system, in Body body1, in Body body2, in ContactManifold manifold, in ContactSettings settings) { var layer = System.BodyInterface.GetObjectLayer(body1.ID); Console.WriteLine($"The layer is {layer}"); }

it does not appear to freeze when reading the layer outside of the physics.update loop.

Edit - This is using .Net 8

@jrouwe
Copy link

jrouwe commented Oct 4, 2024

PhysicsSystem::Update is heavily multi threaded. In callbacks you can only access the parameters that are passed to the function. Calling into the BodyInterface will attempt to lock a mutex that is already locked and will cause a deadlock. There is PhysicsSystem::GetBodyInterfaceNoLock to get a non locking version but you need to be extremely careful when using it or you will have race conditions.

@captainkidd5
Copy link

^ Is this still applicable to the Body.ObjectLayer property?

Need to expose this to joltc and C#
https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Body/Body.h#L123

As in, exposing the property on Body is a workaround?

@amerkoleci
Copy link
Owner

^ Is this still applicable to the Body.ObjectLayer property?

Need to expose this to joltc and C#
https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Body/Body.h#L123

As in, exposing the property on Body is a workaround?

I will add it Monday, not working on spare projects during weekend, patience! 😃

@amerkoleci
Copy link
Owner

^ Is this still applicable to the Body.ObjectLayer property?

Need to expose this to joltc and C#
https://github.com/jrouwe/JoltPhysics/blob/master/Jolt/Physics/Body/Body.h#L123

As in, exposing the property on Body is a workaround?

I will add it Monday, not working on spare projects during weekend, patience! 😃

Just added missing methods in e6ec0fe
Version 2.9.6 has been released

@brogan89
Copy link

brogan89 commented Nov 7, 2024

DebugRenderer is working pretty damn well now. I got it rendering in 2.10.2 using Vulkan.

One extra thing that would be cool is having the body ID also passed through as a parameter so you can be more selective of which bodies to show the debug lines. But I see its not even in the core library 🤔 so I'm not sure how only show some debug info, its all or nothing by the looks. It gets pretty expensive, especially once you get hundreds of thousands of vertex positions.

image
image

@jrouwe
Copy link

jrouwe commented Nov 7, 2024

If you want to draw parts of the world then use BodyDrawFilter.

@QQJoyByte
Copy link

it is support Deterministic

@captainkidd5
Copy link

Is it intentional that bodies which are sensors are not drawn?

@captainkidd5
Copy link

captainkidd5 commented Nov 22, 2024

it is support Deterministic

not sure if this was a question, but as per the joltphysics repo:

The simulation runs deterministically. You can replicate a simulation to a remote client by merely replicating the inputs to the simulation. Read the Deterministic Simulation section to understand the limits.

I assume? this probably means the C# bindings version is too

@amerkoleci
Copy link
Owner

Is it intentional that bodies which are sensors are not drawn?

Not sure, will investigate

@amerkoleci
Copy link
Owner

it is support Deterministic

not sure if this was a question, but as per the joltphysics repo:

The simulation runs deterministically. You can replicate a simulation to a remote client by merely replicating the inputs to the simulation. Read the Deterministic Simulation section to understand the limits.

I assume? this probably means the C# bindings version is too

Yes!

@jrouwe
Copy link

jrouwe commented Nov 22, 2024

Is it intentional that bodies which are sensors are not drawn?

Not sure, will investigate

Sensors are drawn in wireframe, perhaps wire frame rendering is not supported yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants