Sauerworld Forum

How to generate 3D geometry based on a heightmap image

Salatiel

  • ***
  • 114
  • +25/-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

TristamK

  • *
  • 37
  • +3/-0
    • Cube 2 Engine News Group
Re: How to generate 3D geometry based on a heightmap image
« Reply #1 on: November 02, 2019, 09:04:32 AM »
Damn. Pretty interesting thing. But there a few reasons why i can't use it
1) I don't know how to use it for race (pekaface.jpg) . Atleast i  don't have ideas except for something which can me merged with arC's colorful scripts.
2) And? which is more important, i need to compile it and i didn't want to do it. ¯\_(ツ)_/¯  At Least i don't know when i compiled something last time. Isn't there any clients which have this function build in?
Russian news group about Cube 2 Sauerbraten in VK ->vk.com/cube_engine_news
International Sauerbraten Mapping Community