dima634 / baby_shark

Geometry processing library in pure rust
MIT License
67 stars 7 forks source link

Question towards difference in error types for mesh simplification #31

Closed Nevsden closed 6 months ago

Nevsden commented 6 months ago

First of all: Great library. Really appreciate the effort! Kudos!

What is the difference between the ConstantErrorDecimationCriteria and the BoundingSphereDecimationCriteria.

dima634 commented 6 months ago

ConstantErrorDecimationCriteria: Seems to be a simple threshold. Condition the error of the best edge against the used defined error.

You are correct.

BoundingSphereDecimationCriteria: As far as I would understand it, I would guess that the sphere is a bounded error in the 3d-space with the origin being placed at the center of an edge to be collapsed and it is looked, if the error produced by the edge collapse is inside or outside of the sphere. Somewhat correct? Why are there multiple radii in the criterion though?

It is basically the same as a constant error but the threshold depends on the distance from the edge to origin. So each sphere has its own max error. That is also the reason why there are multiple radii error values. Each value represents one sphere. image

pub struct BoundingSphereDecimationCriteria<TMesh: Mesh> {
    origin: Vec3<TMesh::ScalarType>,
    radii_sq_error_map: Vec<(TMesh::ScalarType, TMesh::ScalarType)>,
}
Nevsden commented 6 months ago

So if I wanted to simplify the mesh as much as possible whilst keeping the simplification within a fixed error normal to the original edge I would go with constant error right?

As for the bounded sphere criterion: could you give me an example? So far it sounds like I would have a hard time to look for use cases for that.

Thank you!

dima634 commented 6 months ago

So if I wanted to simplify the mesh as much as possible whilst keeping the simplification within a fixed error normal to the original edge I would go with constant error right?

You are completely right. In most cases, this is what you need.

As for the bounded sphere criterion: could you give me an example? So far it sounds like I would have a hard time to look for use cases for that.

It can be used to generate LOD mesh. Imagine creating a terrain scene, consider that the camera will remain within a specific area. You can simplify the mesh in this area with 0.0 error, while using higher detail for the rest of the mesh, as the camera is not expected to go there. This approach optimizes the mesh size so rendering will be chipper.

Nevsden commented 6 months ago

@dima634 wow, oh. Totally makes sense for the given use case! I learnt something. You can close the issue.

And again. Great library. Thank you for the effort!