Sauerworld Forum

How to generate 3D geometry based on a heightmap image

Salatiel

  • ***
  • 103
  • +24/-1
    • Projects by Salatiel
How to generate 3D geometry based on a heightmap image
« on: September 18, 2019, 08:08:47 pm »
Hello, a few months ago I posted here a tool called IMTOC ( http://sauerworld.org/forum/index.php?topic=556.0 ), which lets you convert images into .cfg files and run them ingame, and recently I tried to create "3D" images using the pixel brightness to determine the height of the cube, and it ended up working very well:






This is really simple to do, as long as you have the movesel command installed on your client, below are the steps you can follow:

First you need to modify your client with a new function (movesel), and then add another common script to your autoexec.cfg (autodraw.cfg).

Things you only need to do once:
1- add the movesel command to your sauerbraten/src/engine/octaedit.cpp file
Link: https://gist.github.com/SalatielSauer/d0c3f7676d7962c8451eb701fc1220f3#gistcomment-2956010

2- run the autodraw.cfg script: https://raw.githubusercontent.com/SalatielSauer/IMTOC-Converter/master/scripts/autodraw.cfg (you can paste it on your autoexec or something like that).

Things you need to do for each image:
1- resize your (heightmap) image to a less exaggerated size, if your image resolution is too good, the process can take minutes, and you don't want it. I usually use 100 pixels (100 cubes).

2- upload your image to IMTOC
Link: https://salatielsauer.github.io/IMTOC-Converter/



3- once the conversion is complete, download the .cfg file that IMTOC sent you, and place it in your sauerbraten root folder.

4- ingame, run your image's cfg file /exec imagename.cfg

5- go to the middle of the map, or an area that you think your image will fit, and run the command /autodraw.



And that's it, your "3D image" will start to be drawn. The autodraw command has 2 extra arguments to turn alpha on/off and to define which color will be considered alpha.

/autodraw <bool> <string>
for example: /autodraw 1 "0xFF0000", the red color will be ignored.


This is all possible thanks to the movesel command, be sure to ask eihrul to add this function (movesel) to sauerbraten's SVN, so in the future we won't need to modify the client to achieve this result.  ::)
http://sauerworld.org/forum/index.php?topic=574.0

I know this would be extremely faster to do using some other C++ function and some magical lib for image processing, but I have no experience to put this into practice, so I am sharing the alternative and simpler way to do it.

Have fun and let me know what you think!
« Last Edit: September 18, 2019, 08:18:31 pm by Salatiel »
@Salatiel#5274