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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added model_recalculate_bounds_exact() #578

Merged
merged 3 commits into from
Jan 21, 2023

Conversation

paulmelis
Copy link
Contributor

This computes a model bound based on (transformed) vertices, instead of using per-mesh AABBs. Main reason for this is to have a much tighter bound, especially for interaction volumes, at the cost of a longer time needed to compute bounds for models with many vertices.

Note that I haven't tested this from the C# side, but the C code does compile on Linux 馃槃

bound based on (transformed) vertices, instead of using per-mesh
AABBs. Main reason for this is to have a much tighter bound,
especially for interaction volumes.
@paulmelis
Copy link
Contributor Author

paulmelis commented Jan 20, 2023

Btw, model_recalculate_bounds_exact() isn't called in any way, except when forced through Model.RecalculateBoundsExact(). Perhaps that call can even be offloaded to a thread/async, in order not to lock up the app.

@paulmelis
Copy link
Contributor Author

paulmelis commented Jan 20, 2023

Comparison on a model file where I noticed the (still) quite loose bounds. This is a GLB file that has a few different transforms (e.g. -90 rotation in X, -11 degree in Z) above several pieces of geometry.

Current: center [-0, 0.26, 0], dimensions [12.43, 0.52, 11.94]

image

Exact: center [-0, 0.26, -0], dimensions [9.28, 0.52, 8.5]

image

Edit: fixed wrong pasted bbox values

@maluoi
Copy link
Collaborator

maluoi commented Jan 20, 2023

This is a pretty neat feature! Do you know what level of "slower" this might be? I imagine it's probably not so bad that it'd really need to be async, but I'm curious!

I've also taken to using some of the DirectXMath functions directly for bounds stuff, I think its likely to have some good speed benefits in this loop! XMVectorMin/Max in particular, in case the compiler isn't auto-vectorizing that already. It'd be nice if you could add that here! Might also be worth hoisting the XMMATRIX conversion out to a higher scope like here, but I'm less certain about that.

I'm not genuinely concerned about micro-optimization here, just wanted to shout out that there may be some low hanging fruit :) I'll take it either way if you're not keen on that right now!

bounds computation. On a large unoptimized GLB file
with 5.4M vertices and 5.4M indices exact bound
computation goes from 99ms to 33ms. Tested with the
C API on Linux.
@paulmelis
Copy link
Contributor Author

Good suggestion on the DirectXMath functions. Just updated the patch and exact bounds computation time went from 99ms to 33ms. This is with the C API and a large unoptimized (85 visuals, 5.4M vertices and 5.4M indices) GLB file.

@maluoi
Copy link
Collaborator

maluoi commented Jan 21, 2023

Wooh, that's a hefty model! Yeah, okay, I can see why that might be a good candidate for async still, I'll keep that in mind for later :) Though I'm glad to know the DXM functions helped that much!

@maluoi maluoi merged commit dc0f69e into StereoKit:develop Jan 21, 2023
@maluoi maluoi added this to the v0.3.7 milestone Jan 21, 2023
@paulmelis
Copy link
Contributor Author

I only now noticed that this model (one of a set I've been using for months) consists of unconnected triangles 馃槅 "Blame" it on modern hardware (GTX3090) and lean software like SK to make that hardly noticeable.

maluoi added a commit that referenced this pull request Feb 5, 2023
This is a small update that includes a couple of PRs, some fixes and feedback, and improvements related to the maui template!

- Added `Tex.SetMemory`, thanks Austin!. #574
- Added `Model.RecalculateBoundsExact`, thanks Paul! #578
- Added overload for `UI.ButtonBehavior` that takes a depth and activation depth.
- Added image overloads for `UI.Radio`, and added `UI.RadioAt`. #571
- Added `UI.LastElementHandActive` and `UI.LastElementHandFocused`.
- Deprecated `UI.LastElementHandUsed`.
- Fix for custom GLX loader issue with Monado, thanks Moshi! #581
- Fixed a Maui hack related to UWP library references. #586
@maluoi maluoi mentioned this pull request Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants