Decimate To Target
In 3D data preparation, it can be required to reach a specific polycount to properly display a 3D model on a particular device (e.g. a maximum of 100 000 triangles is advised for HoloLens).
There are many possibilites to achieve that with Pixyz Studio, but the most direct way is by decimating meshes, using the "Decimate To Target" function.
"Decimate To Target" reduces meshes density until a targeted polycount is reached.
The function is available from the "Optimize Mesh" menu.
Parameters
The function is mainly controlled by a "Triangle Count" criterion (or "Triangle ratio"), which is the number of triangles left after the decimation.
More control over the reduction and its quality can be achieved using the weights and parameters available in the "Advanced" tab.
They are meant to preserve specific geometric attributes (hard edges, UVs...), avoid smoothing artifacts (normals) or topological irregularities:
- Boundary Weight: This weight defines how important the edges defining the mesh boundaries (free edges) are during the decimation process, to preserve them from distortion
- Normal Weight: This weight defines how important vertex normals are during the decimation process, to preserve the smoothing (also called shading) of the mesh from being damaged
- UV Weight: This weight defines how important UVs (texture coordinates) are during the decimation process, to preserve them from being distorted (along with the textures using the UVs)
- Sharp Normal Weight: This weight defines how important sharp edges (or hard edges, like a table angle for example) are during the decimation process, to preserve them from being distorted
- UV Seam Weight: This weight defines how important UV seams (UV islands contours) are during the decimation process, to preserve them from being distorted or stretched (along with the textures using the UVs)
- Forbid UV Overlaps: This parameter forbids UVs to fold over and overlap each other during the decimation
- Protect Topology: If False, important topologyical singularities of the mesh (like holes for example) can change and some edges can become non-manifold. But the visual quality will be better on model with complex topology
How to set the parameters value?
- Use the proposed presets (Low, Normal, Important, Custom...) to change the importance of a weight
- Default presets will give a good enough result in most cases. If necessary, use the weights to fine-tune the decimation accordingly to your model's specificities
- It is not necessary to set a weight at a very high value (like the "Very Important" preset) to protect a specific attribute. In some cases it might even slower the algorithm, and even prevent it from delivering the best result.
If an attribute is more important than all the others, simply set its value one level above the others.
General behavior
The "Decimate To Target" function takes the whole scene (or the whole list of occurrences defined as input) into consideration: although this algorithm operates at Part level (on the meshes), it is based on the whole set of Parts (given as function input) to evaluate the target polycount.
It means that calling the function with a list of 10 Parts is different from calling 10 times the function with a single Part each time. In the first case, the target will be reached for the whole set of mesh, while it will be reached for each mesh individually in the second case.
For AEC usecases (buildings, houses...), it is advised to call the function a single time with a list of all of the Parts, so that meshes made of a very few triangles such as walls or windows are kept intact while the decimation focuses on denser meshes.
About the algorithm
The algorithm behind the "Decimate to Target" function is based on the Quadric error metric method, that reduces the density of a mesh by collapsing its edges:
First, the algorithm calculates a new vertex placing, and then computes a misplacement error score for each edge. The score is calculated by adding different geometrical deviations (boundaries, normals and UVs).
Then, it removes in priority the edges generating the less errors until it reaches the targeted polycount.
As explained above in the Parameters section, the user can influence the computed score by modifying the input weights: the score will be multiplied with the corresponding parameter.
For example, if the usecase requires to preserve the model from UV distortion (e.g. with a textured game asset), the "UV Weight" can be set to a higher value. For each edge, the UV error will be multiplied by this value. The global edge error for the edges displacing UVs will get higher error scores than the others, and thus will be deleted last.
Examples
Here are simple examples explaining how to setup the "Decimate To Target" function:
Game model
With the Game asset below, here is how parameters should be set in order to obtain a beautifully decimated model:
- Repair mesh: as explained here, it is better to repair a mesh before decimating in order to reconnect edges and avoid gaps
- Target Strategy: Here the model is already quite low poly for a character (~35k triangles), so the target should not be too low, but it mostly depends on how far from the camera the decimated model will be. Let's try the default 10 000 triangles value (~30%).
- Setting other parameters:
Parameter |
Parameter value |
Explaination |
Boundary Weight |
Low |
The meshes have no visible important open boundaries that need to be preserved (except for the contour of the eye sockets, but the result is acceptable with a "Low" value) |
Normal Weight |
Normal |
Normals should be preserved, because we want to prevent shading artefacts or broken normals from appearing on the surface of the panda. |
UV Weight |
Normal |
UVs need to be preserved, because our model has textures applied. These textures play a great role at making it look good. We do not want them to be too distorted |
Sharp Normal Weight |
Low |
This model has no hard/sharp edges, so Sharp Normals should not be preserved |
UV Seam Weight |
Normal |
UV seams, or borders, are important attributes. Indeed, if they are not taken into accout, the decimation might stretch the textures where these seams are located |
Forbid UV Overlaps |
True |
Set it to "True" to as UVs need to be preserved as much as possible |
Protect Topology |
True |
Set it to "True" in order to preserve panda's topological singularities (e.g. the eye sockets) as much as possible |
Here is the result of the decimation, that reduced the model and preserved the required attributes:
NOTE With this animated model, skins, bones and animation were also properly preserved during the decimation process!
CAD model
With the CAD / Hard surface model below, which is a car door, here is how parameters should be set in order to obtain a beautifully decimated model:
- Repair mesh: as explained here, it is better to repair a mesh before decimating in order to reconnect edges and avoid gaps
- Target Strategy: Here the model is quite dense (~18k triangles), so there is room for a good reduction. Let's try keeping 10%.
- Setting other parameters:
Parameter |
Parameter value |
Explaination |
Boundary Weight |
Low |
Here the model is a closed volume with a thickness (not an open shell), which means it has no boundaries that need to be preserved |
Normal Weight |
Important |
This is the most important weight, because light will be bouncing strongly on the door as its material is metallic/shinny |
UV Weight |
Low |
This model, like most CAD model has no UVs (they can of course be added afterwards if necessary): "Low" is a good value. As explained here, it can be interesting to check if the model has UVs that might prevent the decimation to reduce as strongly as required, and remove them. |
Sharp Normal Weight |
Normal |
This particular CAD model only has a few hard edges and not very visible, so "Normal" is a good value here |
UV Seam Weight |
Low |
This model, like most CAD model has no UVs (they can of course be added afterwards if necessary) |
Forbid UV Overlaps |
False |
No UVs here, so it can be set to "False" (leaving it to "True" will not affect the result though) |
Protect Topology |
True |
As the door panel has a rather simple topology, it is preferable to set this parameter to "True" and try to keep its topological singularities like the small holes at the bottom |
Here is the result of the decimation, that reduced the model and preserved the required attributes:
Known limitations
Run on large models (several millions triangles), the "Decimate To Target" function consumes a lot of memory (that is because static meshes are converted to dynamic meshes in the process, which is demanding in RAM).
Make sure you have sufficient memory, or your CPU might swap and slow down your computer dramatically.
API function parameters
Check the API documentation page to learn how to use this function in Python code:
Related topics