- Home /
Runtime mesh decimation
Hi everyone I'm currently trying to develop a c# script for unity for my thesis at university that aims to decimate the mesh of a model at runtime (namely in game) when the FPS count is a bit over the 60fps
what I wonder is if it really is possible to do such a thing I tried a few ways to decimate the meshes but none of them worked
does anyone have any suggestion? thanks in advance for the help
There are many things not clear in your question. First of all what do you mean by "decimate"? A $$anonymous$$esh simply consists of vertices and triangle definitions between those. If you aim for lowering the triangle / vertex count for arbitrary meshes that's not possible. This is generally called "retopo" but usually requires user steps in order to produce any useable output.
Second as mentioned already, what kind of meshes do we talk about? Even if you find some automatic way to reduce the poly count it won't work for an arbitrary mesh. If you remove / reduce certain parts of a mesh it will no longer look right. A good example is the Utah $$anonymous$$pot (i made this one). The Utah $$anonymous$$pot however is 100% procedurally generated from nurbs surfaces (you can see the control points when you enable "control"). If you set the U and V resolution to the $$anonymous$$imum the lid handle would basically disappear. Also the spout as well as the handle would be just a flat surface.
Finally you haven't mentioned what the overall goal is. What does the framerate has to do with this? Reducing the triangle count doesn't really increase performance. The number of drawcalls / setpass calls usually has a much greater impact. Since Unity is limited to 16 bit index buffers a mesh is limited to 65k vertices.
The question is way too unspecific. You should edit / improve your question to make it more clear what you actually want to do. UnityAnswers is for concrete technical questions about the Unity engine and development with the Unity engine. Yes you can manipulate a mesh at runtime in Unity. The rest of your question seems to be related to an algorithm which you didn't specify.
thank you for the answer, what I am trying to do is indeed a retopo of a mesh; unfortunately I am not very expert with unity and I don't know of a good algorithm that is able to do so. I tried to ask here hoping that someone could give me an advice
the final goal is to verify if it is a valuable possibility other than using the LOD system
Creating a retopo automatically isn't an easy task and doesn't necessarily work for arbitrary meshes as it's difficult to tell what general shape the mesh has and what would be important to preserve the overall shape. Some modelling tools offer an auto retopo feature but i don't know any artist who has ever used it. Our artist created the models in 3ds $$anonymous$$ax and refined it in z-brush. Finally he created a retopo manually in 3ds $$anonymous$$ax (by specifying new low poly edges on the surface) and created a normal map from the high poly model to perserve the details. So in the game we just used the low poly model with the normal map.
An algorithm is nothing that is specific to Unity. A mesh consists of vertices and triangles. Unity's $$anonymous$$esh class gives you access to those. Everything beyond that isn't really related to Unity. Creating a retopo is probably more complex than finding the convex hull of an arbitrary object. Finding the convex hull is also a quite complex problem and also doesn't have a simple solution. Doing a retopo would actually be slightly related to finding the convex hull with a lower number of vertices. Just that the result shouldn't always be convex which makes the problem even harder.
Since it's a thesis you should have thought about how it might be accomplished beforehand. $$anonymous$$eep in $$anonymous$$d that every thesis can either be proven or disproved. Of course it's not good when the reason you can't proof it is that you failed to implement an algorithm that does what your thesis relies on.
So in short, no i don't have an algorithm that does what you want.
So if someone comes up with an answer for you then you are committing Plagiarism and can get you kicked off your course and Arrested! Sorry to tell you this.
In my humble opinion what you are trying to achieve defeats the purpose : $$anonymous$$esh manipulation is pretty intensive given the work required. To perform this as a cycle-saver surely would not work as a result.
You will need to perform Decimation in advance (Blender makes this easy) and save the models ready for use. Its then a simple case of enabling and disabling GameObjects to swap out. I know this is not what you're after but this is how its done in AAA. Good luck in your endeavours.
Answer by ZnCroXD · Jan 25, 2018 at 03:34 PM
That is currently on exist, is called LOD (Level of Details), this works with the distance at the camara render the objects (if is too far, will be more decimate) may be u can use teh API to make the LOD system Decimate the mesh with the Time.framerate variable.
The LOD system in Unity does not reduce the mesh automatically. YOU have to provide the different levels of detail. The LOD system just helps you to select the appropriate level depending on how large the object would appear on screen.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
TextMesh/3DText modify shape 0 Answers
How to make mesh ripples fade c# 1 Answer
What is the best way to update array in runtime? 3 Answers
Splitting Procedurally Generated Mesh, Based On Height 0 Answers