RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
1.01k stars 175 forks source link

Created flexbody debug view + GUI #2925

Closed ohlidalp closed 1 year ago

ohlidalp commented 2 years ago

This tool lets you inspect individual vertices and their generated bindings. Just hover mouse pointer over a vertex and see. Click the vertex to toggle persistent visibility. Closes #2923. obrazek Vehicle on display: https://forum.rigsofrods.org/resources/honda-accord.281/

ohlidalp commented 2 years ago

While looking at the debug view I created, I figured an optimization. Most often, many vertices bind to the same REF/VX/VY nodes, so for optimal CPU cache usage, they should be processed together. However, currently they are processed in the order of vertices in the mesh, which is random, depending on the modelling tool and exporter. I wanted to actually see it, so I created a visualization: obrazek

Next step - defragment the memory! Meaning: reorder vertices in the mesh (it's possible on runtime, I've already done it once) to match the nodes. The result will be visible in this diagram.

ohlidalp commented 2 years ago

I implemented the "defragmentation" of flexbody vertex locators. Figuring out a sensible sorting algorithm was a challenge, and I'm still not happy with the result. Figuring out how to fix the mesh for the reordered vertices was another challenge, and coding it was extremely hard because I kept mixing things together. Don't touch the "Invert index lookup" checkbox! 😄

In the image below, the vertex locators are reordered but texcoords aren't (checkbox is off), resulting in an artistic effect. obrazek Vehicle on display: Ford Tudor Army https://forum.rigsofrods.org/resources/1949-ford.283/

Zentro commented 1 year ago

No crashes or errors to report.

A minor thing, but when inspecting vertices and picking some with your mouse you can immediately deselect them. However, when unchecking the "Vertices" box after selecting a few vertices, the vertices can no longer be unselected (after rechecking the "Vertices" box) without browsing through the vertex locator table and unselecting them there. image

The defragmentation tool works without issue with the defaults, unselecting any or all of the 3 optimizations results in some interesting effects as you've noted in your previous reply. Not sure if this is intended or not. image

ohlidalp commented 1 year ago

Purpose: To visually explain how flexbodies work and help modders diagnose them.

Estimate: 1 man day. It all works.

CuriousMike56 commented 1 year ago

Is the "hide others" option meant to show only the selected flexbody? if so it doesn't work: image Upon testing to see if it works with nodes2, I found an extreme use case: the high poly count of the 1971 DI Banger Brambler Package causes the frame rate to plummet when activating the debug views: image This most likely can't be "fixed" but could be an easy way to test further optimization.

Otherwise it seems to work fine. The per-material wireframe mode is neat.

ohlidalp commented 1 year ago

@CuriousMike Is the "hide others" option meant to show only the selected flexbody? if so it doesn't work: (Desperado buggy)

It actually works perfectly, but what you're looking at aren't flexbodies but props :smile: But I admit it's confusing, so I added props to the list, too: image Yes, there's a glitch - props outside of props (like wheel rims) aren't accounted for, but I'll fix that after this PR.

@CuriousMike56 the high poly count ... causes the frame rate to plummet when activating the debug views

That's because I'm drawing all those as circles using DearIMGUI (circa 6 triangles each, antialiased). Using raw vertex buffer would be much faster and would look pretty much equivalent in this case. But presently all our debug views work like this, I'll deal with this in the future if it troubles users.

@CuriousMike56 Anyway, thanks for the thorough testing!

CuriousMike56 commented 1 year ago

Still can't get the hide others option to work, tried multiple vehicles with plenty of flexbodies 😕 image image

ohlidalp commented 1 year ago

@CuriousMike56 Looks like it doesn't work at all for you... very strange. Try disabling PSSM, Envmap, and setting all visuals to lowest levels.

CuriousMike56 commented 1 year ago

@only-a-ptr Turns out realtime reflections breaks it, works fine with it disabled: image

ohlidalp commented 1 year ago

@CuriousMike56 Turns out realtime reflections breaks it, works fine with it disabled

Makes sense, all meshes must be hidden when rendering the reflections, otherwise they would obscure the view for the reflection-cameras. I fixed it by pausing reflections while "Hide all" is active, test once more please.

CuriousMike56 commented 1 year ago

Now enabling "hide other" on the first entry on the list causes all flexbodies to disappear, leaving only the props: image image All other flexbodies appear as normal: image Occurs with reflections enabled or disabled.

CuriousMike56 commented 1 year ago

First flexbody not appearing still persists (showing N/B view as the vehicle becomes completely invisible) image

ohlidalp commented 1 year ago

@CuriousMike56 First flexbody not appearing still persists

Fixed.