Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different optimization level for a height range?

klauskobald opened this issue · comments

I would like to have the mesh (terrain) being detailed at a certain elevation level say -1 to +2 meters. This would create a better beach. On the other side I would like to have a highly optimised mesh in higher elevations, because it would always be in the distance since my game is happening at ocean level.

Question is, where I would to have to dig into to not have vertices at a given y range being optimised.

Hi @klauskobald, sorry for not getting back to you faster. I have been in the process of moving and have not had access to a computer for a few days.

The way I see it, you have two options:

  1. Implement logic of ignoring edges containing vertices at a specific elevation range in RemoveVertexPass around here.
  2. Implement logic for calculating the error of an edge differently in CalculateError here.

There is unfortunately no built-in support for what you are trying to achieve. So it will require changes to the code.
Have in mind that ignoring edges will lead to no optimizations at all, so the calculation of the error would be the best way to implement a sort of prioritization of optimizations. I would recommend you to test different approaches and see what works best for you.

In short the optimization works by optimizing the edges with the lowest errors, and work it's way up until it has reached the desired triangle count, or there's nothing left to optimize (essentially if the rest of the edges are ignored). So increasing the error when the vertices are closer to your specific elevation should lead to those edges being collapsed later, hopefully leaving them mostly untouched.

I hope this helps. Let me know how this works out for you!

Thank you! That does not sound too complicated. I will check it out in a few days!

I tried it out and it works. But then I came across the SimplificationOptions! (Did not see them before). Actually it seems to be sufficient to preserverCurvature. :-)