Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert: Flat terrain textures #985

Closed
heinezen opened this issue Mar 17, 2018 · 13 comments
Closed

Convert: Flat terrain textures #985

heinezen opened this issue Mar 17, 2018 · 13 comments
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers just do it You can start working on this, there should be nothing left to discuss lang: python Done in Python code

Comments

@heinezen
Copy link
Member

heinezen commented Mar 17, 2018

As mentioned in #720, we want to convert the old SLP terrain files to a flat terrain texture. I've implemented a working prototype for that utilizing the dimetric projection algorithm from the openage modding repository. The resulting python script can be found here. It operates on the output of our current converter.

merge() puts the single tiles together into one giant tile. transform() projects the result from dimetric to the desired flat perspective. Here you see the output when converting 15006.slp.png.

15006_flat_t

Textures from SLPs will always have a ratio of 1:1 and a size of 481x481 (compared to 512x512 in HD).

If somebody want to implement a more efficient version of the script and integrate it into the converter, go ahead.

@heinezen heinezen added area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers just do it You can start working on this, there should be nothing left to discuss labels Mar 17, 2018
@zuntrax zuntrax self-assigned this May 7, 2018
@TheJJ TheJJ added the lang: python Done in Python code label Nov 5, 2018
@mikadou
Copy link

mikadou commented Jun 23, 2019

Since terrain textures in HD are 512x512 pixels, I suggest to generate flat terrain textures with the same resolution in the conversion step.

@heinezen
Copy link
Member Author

@mikadou We might not need to anymore, since we agreed on doing 3D terrain. The texture will be independent from the tiling and thus can just be painted on the terrain without the need to scale it.

@mikadou
Copy link

mikadou commented Jun 28, 2019

@heinezen Thanks for confirming the consensus on 3d terrain. I fully agree with going in this direction.
My thought about the 512x512 textures was because a few years ago when I last experimented with OpenGL it was recommended to use textures with sizes power of two. Not sure if this is still relevant though.

@TheJJ
Copy link
Member

TheJJ commented Jul 1, 2019

For the usual on-GPU memory allocation algorithms I think it still is (because the malloc algorithms likely use 2^x bucket sizes). With today's huge memory sizes I think we should ignore this for now and look for optimizations later.

@simonsan
Copy link
Contributor

simonsan commented Jul 3, 2019

Just to save this link:

How to generate 3D terrain from e.g. Google Maps
https://www.youtube.com/watch?v=Bb0HnaYNUx4

@charliergi
Copy link

Anyone is working on it ? I can try to do it.

@heinezen
Copy link
Member Author

@charliergi No, nobody working on it currently. You can do it if you want :)

It would be great if you could translate the code to cython (for extra speed) and integrate the script directly into the converter (openage/convert/ in the repo). You can therefore ignore the output logic from the script linked above and instead take a numpy.ndarry as input for the image data. The array is returned by our media conversion:

return array_data

To output the image, you can use the Texture object in openage/convert/texture.py

class Texture(exportable.Exportable):

If you want, you can also add the option for terrain merging to the singlefile converter:

https://github.com/SFTtech/openage/blob/master/openage/convert/singlefile.py

@charliergi
Copy link

charliergi commented Nov 28, 2019

Thanks for the description. I'm not familiar with Cython but i'll do my best to convert it.
I also have a question for it :

  • How can I test this script ? Do you have any numpy.ndarray of SLP images that I can use to test my script ?

@heinezen
Copy link
Member Author

The best way to test would be adding a terrain option to the singlefile converter. This would then directly output the resulting image if you implemented it.

You can use the normal terrain SLP files of AoC for testing. The conversion from SLP to numpy.ndarray is already implemented in slp.pyx. You would just have to add the additional step that merges the frames and transforms the pixels to a flat texture :)

@charliergi
Copy link

charliergi commented Nov 30, 2019

Hello !
One simple question that comes to my mind when I try to implement it :

  • You said me that I have to use the Texture class as output. As I can see in the constructor (init function) of the Texture class, there's a test that checks if the "input_data" argument is of instance SLP, SMX/SMP, or BlendingMode. Of which instance the "input_data" argument should be ? It seems that there is no purpose here to create an object like an SLP object.

@heinezen
Copy link
Member Author

input_data should be an instance of SLP for terrains. The SLP object reads a .slp file on creation, that's why the init function in the Texture class can access its frames. SLP objects are created from passed files, for example in singlefile.py.

@charliergi
Copy link

charliergi commented Dec 8, 2019

Hello!
I've learned a bit more about Cython this week. I've managed to understand the structure of the project and translate (pure Python for the moment) your script above, and changed some things as suggested :

  • First I created a new method in singlefile.py, that will read a SLP inside a DRS archive (I've only this game version so I can't test more recent versions) and save it as a PNG.

  • Then I call your translated script that will open and read this file, and make the transformations. For the moment, this script returns a PIL Image.

  • Now, as suggested, I would like to use the function determine_rgba_matrix() from the SLP.pyx in order to obtain the pixel numpy.ndarray of this PIL Image and output a Texture from it, but I don't know how to do it. I try to extract the pixel matrix from the PIL image but I don't find a way to do it. Maybe it's because I don't really understand concretly the format of these images.

I know that save a Texture and open it again is completly useless, but I haven't find another way to do it. When I will succeed to convert it properly, i'll optimize the code.

Am I in the good way ? Feel free to correct me :)

@heinezen
Copy link
Member Author

heinezen commented Dec 8, 2019

I suggest you create a PR or Draft for your code, so we can discuss it better. Talking about what you did without seeing it is otherwise a bit of guesswork :D

Now, as suggested, I would like to use the function determine_rgba_matrix() from the SLP.pyx in order to obtain the pixel numpy.ndarray of this PIL Image and output a Texture from it

You should not (and cannot) use the function on the final image. determine_rgba_matrix() does not handle normal RGBA image data, but the special SLP image data. More precisely, the method receives special SLP image data as input and outputs RGBA image data. Instead of outputting the texture first, you should implement the transformation before the final image gets created. Or rather after texture.py fetches the image data from the SLP object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers just do it You can start working on this, there should be nothing left to discuss lang: python Done in Python code
Projects
None yet
Development

No branches or pull requests

6 participants