Skip to content

Basic_3D_optimization_and_ReMeshing

Sergejs edited this page Apr 29, 2023 · 2 revisions

3D mesh optimization

How to intelligently reduce the amount of 3D mesh details to get the best quality HRTF results on available computers within reasonable time.

------------------------------------------------------------ Part of the the Complete Beginner’s tutorial ------------------------------------------------------------
Previous <<< 3D Mesh clean-up and merging last updated in 2022-06-23 Next >>> Project Export

Video version of this tutorial:


Introduction to remeshing / grading

Currently “hrtf_mesh_grading” is the recommended re-mesher to optimize the 3D model for Mesh2HRTF simulation. For maximum efficiency the mesh for simulating Left ear contains fine details only on the left side while the right side is heavily simplified.

The “hrtf_mesh_grading” for Linux and Mac is available at https://github.com/cg-tub/hrtf_mesh_grading, but for Windows it is already compiled and packaged among the Mesh2HRTF tools. This algorithm for the open-source pmp-library is described in detail in the paper by Palm, Koch, Brinkmann & Alexa (2021) "Curvature-adaptive mesh grading for numerical approximation of head-related transfer functions." The key takeaways from the study reported in this paper are:

  1. For Mesh2HRTF simulation the optimal 3D mesh to obtain both very accurate result and low computation time can be generated by “hrtf_mesh_grading” using parameters “-x 0.5 -y 10” (minimum & maximum edge length set to 0.5 & 10 mm which produces about 40000 triangle final mesh).

  2. The optimal “hrtf_mesh_grading” parameters exhibit relative error below just noticeable difference of 6% (compared to full resolution source mesh, which itself may not be 100% accurate towards the reality due to scanning precision and limitations of the simulation).

  3. Because of real-life human body scanning precision constraints and practical sound wavelengths, there is no point in using resolution finer than “-x 0.5”, but experiments with “-y” parameter in the range from 2.3 to 15mm showed that there is also no advantage to increase the resolution of the second parameter beyond the optimal “-y 10”.


Get the "hrtf_mesh_grading"

Linux/Mac: “hrtf_mesh_grading” works great on Windows, Linux and MacOS. Main instructions for installing “hrtf_mesh_grading” on Linux/Mac and Docker are available in the readme of the https://github.com/cg-tub/hrtf_mesh_grading.

  • Note - Some of the shortcuts/tricks mentioned in this tutorial are not implemented in Linux or Mac, but the same actions can still be performed from command line.

Windows: After the main Installation the compiled “hrtf_mesh_grading” is already ready to use in the Mesh2HRTF tools \hrtf_mesh_grading_WindowsExe\ folder.

  • Please confirm that your "hrtf_mesh_grading.exe" was compiled after the latest changes to the source files here: https://github.com/cg-tub/hrtf_mesh_grading. If there are no recently compiled “hrtf_mesh_grading” binary files available, see the [Compiling hrtf_mesh_grading on Windows] tutorial to compile “hrtf_mesh_grading” yourself – it takes some time, but is actually easy.

How to use "hrtf_mesh_grading"

The “hrtf_mesh_grading” algorithm only works as expected on a human head and body geometry centered around ears – exactly the same requirements as for the mesh prepared for Mesh2HRTF simulation - see 3D Mesh clean-up and merging for details.

The workflow for using “hrtf_mesh_grading” for Mesh2HRTF:

  1. Import your full resolution mesh into the "3d_Model_uniform.blend" example Blender file

  2. Rotate and Move your full resolution mesh to match the ear position with the “Reference” in the example Blender file. (some extra illustrated guidance is available here). It can be useful to apply all transformations.

  1. Make sure that the mesh contains** only triangles** (if some editing was done in Blender, it may have created quads or even more complex polygons). The easiest method it to add “Triangulate” modifier to your mesh.

  2. Export the mesh to .stl format. Make sure that you have the correct object selected in Blender and the export settings are correct (“Selection Only”, “Y Forward”, “Z Up”). The default filename is "3Dmesh_orig.stl", but other file naming and formats can be used as well.

  1. When “3Dmesh_orig.stl” file is ready, it needs to be processed by “hrtf_mesh_grading.exe” twice: for the Left and Right ear simulation (because the algorithm removes unnecessary details from the far side to significantly reduce computation time).

    • On Windows, if you have extracted Mesh2HRTF tools then:

      1. Place “3Dmesh_orig.stl” into your ..\mesh2hrtf-tools\hrtf_mesh_grading_WindowsExe\ folder

      2. Double-click “- run_hrtf_mesh_grading.bat” to directly re-mesh your high-quality 3D mesh into both left and right files using default settings (Note that default settings are almost always optimal for the full quality simulation as shown in the research paper. The settings included in the ".bat" file include -g / -h values increased to 0.20 to reduce likelihood of the "opposite ear problem"):

        • hrtf_mesh_grading.exe -x 0.5 -y 10 -v -h 0.20 -s "left" -i 3Dmesh_orig.stl -o 3Dmesh_graded_left.ply

        • hrtf_mesh_grading.exe -x 0.5 -y 10 -v -g 0.20 -s "right" -i 3Dmesh_orig.stl -o 3Dmesh_graded_right.ply

        • To change settings - just edit the commands within “- run_hrtf_mesh_grading.bat” (open as text file).

      3. Ready - Both output files for Left and Right ear will be saved next to the input file. Here is an example of the "3Dmesh_graded_LEFT.ply" file produced from high quality Kemar dummy 3D scan data using default "hrtf_mesh_grading" settings:

  2. Verify the output files by opening them in any 3D software or by using “- view 3Dmesh_graded_left.bat” and “- view 3Dmesh_graded_right.bat”:

  3. Finally import both re-meshed .ply files back into Blender and meshes should already be correctly aligned and there is no need to apply any transformations (if the final alignment is not correct after hrtf_mesh_grading then it is important to correctly aligned input mesh and re-run the hrtf_mesh_grading instead of trying to move the Left and Right graded output meshes). The next steps are in Project Export tutorial

Optional - To read about input options run hrtf_mesh_grading.exe without any input arguments (in Windows, Linux or Mac command line).

Optional - interactive “hrtf_mesh_grading” - Try double-clicking “- view 3Dmesh_orig.bat” to open GUI and see how "hrtf_mesh_grading" code reads the input mesh. Under “Remeshing” button it is possible to try-out some of the hrtf_mesh_grading input parameters, but this GUI does not have Undo, does not have all input options and does not save the results.


Recommended "hrtf_mesh_grading" settings

These settings are recommended based on some testing and the paper by Palm, Koch, Brinkmann & Alexa (2021) "Curvature-adaptive mesh grading for numerical approximation of head-related transfer functions."

Basic logic is: If you can, just use the “General optimal” settings – there is no benefit in using higher mesh resolutions with Mesh2HRTF. If you want to speed up processing then: “-x” parameter should be kept as small as possible, to retain main ear details. “-y” parameter can safely go to 10-15 and it is possible to experiment with even much coarser triangles (if necessary). “-g/h” parameters are interesting for 2 reasons:

  1. in practice they affects how rapidly algorithm transitions from “-x” to “-y” and therefore has great influence on poly-count even while “-x” and “-y” limits stay constant. See table below for all details or just try some of the recommended settings above.

  2. On a basic level -g adjusts the “estimated ear channel entrance left” and ** -h** adjusts “estimated ear channel entrance right”. Which is important if you try to troubleshoot re-meshing artifacts which typically affect the opposite ear. (tweaking these values usaully gives the desired end result)

As re-meshing is very fast – it is easy to try out different settings to find the right compromise for your target polycount.


The default settings - already configured inside “- run_hrtf_mesh_grading.bat” (only the .bat file uses -g / -h values increased to 0.20 to reduce likelihood of the "opposite ear problem"))

Use-Case: final number of triangles in Example head.ply -x (minimum edge length in mm) -y (maximum edge length in mm) -g / -h (gamma scaling factor) g-left / h-right -e (maximum geometrical error in mm)
General optimal settings (32+ GB of RAM) ~40-60k triangles 0.5 10 Default: 0.15 Leave default: same as -x
bin\hrtf_mesh_grading -x 0.5 -y 10 -v -h 0.15 -s "left" -i 3Dmesh_orig.stl -o 3Dmesh_graded_left.ply
bin\hrtf_mesh_grading -x 0.5 -y 10 -v -g 0.15 -s "right" -i 3Dmesh_orig.stl -o 3Dmesh_graded_right.ply

Use-Case: nr. of triangles -x (mm) -y (mm) -g / -h (left / right) -e
Experimental settings (16+ GB of RAM) ~30k triangles 0.5 10 try using 0.30 (0.2 … 0.4) Leave default
bin\hrtf_mesh_grading -x 0.5 -y 10 -v -g 0.30 -h 0.15 -s "left" -i 3Dmesh_orig.stl -o 3Dmesh_graded_left.ply
bin\hrtf_mesh_grading -x 0.5 -y 10 -v -g 0.15 -h 0.30 -s "right" -i 3Dmesh_orig.stl -o 3Dmesh_graded_right.ply

Use-Case: nr. of triangles -x (mm) -y (mm) -g / -h (left / right) -e
Still nice quality (16+ GB of RAM) ~20k triangles 0.5 15 0.7 Leave default
bin\hrtf_mesh_grading -x 0.5 -y 15 -v -g 0.70 -h 0.15 -s "left" -i 3Dmesh_orig.stl -o 3Dmesh_graded_left.ply
bin\hrtf_mesh_grading -x 0.5 -y 15 -v -g 0.15 -h 0.70 -s "right" -i 3Dmesh_orig.stl -o 3Dmesh_graded_right.ply

Use-Case: nr. of triangles -x (mm) -y (mm) -g / -h (left / right) -e
Quick test-run (or very weak PC) <13k triangles 1.5 15 0.7 Leave default
bin\hrtf_mesh_grading -x 1.5 -y 15 -v -g 0.70 -h 0.15 -s "left" -i 3Dmesh_orig.stl -o 3Dmesh_graded_left.ply
bin\hrtf_mesh_grading -x 1.5 -y 15 -v -g 0.15 -h 0.70 -s "right" -i 3Dmesh_orig.stl -o 3Dmesh_graded_right.ply

Table: advanced topic – effects of -g or -h values:

-g or -h value Effects:
0.15 Default value usually results in very close match between actual and estimated ear channel entrance coordinates. For example at 0.15 the estimate can be 67mm instead of actual 65 mm.
0.01 … 0.14 Reduced values result in estimated ear coordinates further away from the head. For example at 0.01 the estimate can be 95mm instead of actual 65 mm.
0.16 … 0.50 Increased values result in estimated ear coordinates closer to the center of the head. For example at 0.35 the estimate can be 30mm instead of actual 65 mm. For example at 0.5 the estimate should be ~1mm – at the center of the head and in the output mesh you should see a clear high
0.51 … 0.70 Very high values push estimated ear coordinates to the negative, opposite side, close to the actual primary ear position. These values can be useful for the most aggressive polycount reduction needs. For example at 0.7 the estimate can be -37mm instead of actual 65 mm.
0.71 … 0.99 Extremely high values become unusable because they result in estimated ear coordinates which are so-negative that they overlap with the actual primary ear position and eliminate mesh details from the important side. For example at 0.99 the estimate can be -93mm instead of actual 65 mm.

Troubleshooting

Opposite ear problem

In case the opposite ear is not being uniformly re-meshed using large triangles (some parts of the ear which will not be simulated has very fine details) the typical fix is to increase parameter “-h” (to fix problems in -s "left") or “-g” (to fix problems on -s "right") up from the default 0.15 to at least 0.18 or 0.20.

  • From the command reference: “the scaling factor to estimate the y-coordinate of the left (g) and right (h) ear channel entrance (gamma on p. 1112 in Palm et al.). The default is 0.15. Use this if the graded mesh contains to large or too small elements in the vicinity of the ear channels. Use the verbose flag to echo the gamma parameters. The estimated positions should have slightly smaller absolute values than the actual ear channel entrances.”

No output or Corrupt mesh problem

If mesh gets corrupt either when exported out of Blender or after "hrtf_mesh_grading" (for example re-meshed model has holes, has large not-re-meshed areas or something crashes during remeshing steps). Then the possible causes are: A – Blender .stl exporter made a mistake. B – the mesh has holes, internal-or overlapping geometry, non-triangular polygons and other defects that need to be cleaned up. Potential fixes:

  1. (not very likely) Check if the .stl file exported from Blender is corrupt - try opening Blender-exported .stl file in several programs ("- view 3Dmesh_orig.bat", Meshmixer, Meshlab, Microsoft 3D Builder, etc.) to see if it appears corrupt in any of the programs. If the file is corrupt, try other file formats and even converting between formats using any of the available software (just make sure that the mesh orientation and measurement units remain correct before the actual grading).

    • Example of a corrupt .ply file saved by Blender and opened in Meshmixer (the mesh was perfectly ready for simulation):
  2. Follow the How to make sure that 3D mesh is ready tutorial.


Next tutorial step >>> Project Export