SFTtech / openage

Free (as in freedom) open source clone of the Age of Empires II engine 🚀
http://openage.dev
Other
12.63k stars 1.11k forks source link

Convert PNG Sprite Sheet to Frames In Correct Order #1209

Closed gregstein closed 4 years ago

gregstein commented 4 years ago

Hello,

I'm new here but notably impressed with this fantastic library such great work tbh. I just have a question if some of you could help.

I extracted the png file out of smx (AoE2 DE): python3 -m openage convert-file --player-palette-file ~/games/aoe2de/Data/playercolor_blue.pal --palette-file ~/games/aoe2de/Data/b_west.pal u_elite_eagle.smx /tmp/rofl.png

Example: rofl

Now I'm scratching my head to how to convert this spritesheet into frames so I can edit them one by one.

Thank you,

heinezen commented 4 years ago

Hey Greg, glad you found us!

Our converter puts the frames into a spritesheet by design. If you want to extract every frame individually, you can start editing here:

https://github.com/SFTtech/openage/blob/7ca1723d486799d9922f36b07d50a920fdc02317/openage/convert/texture.py#L127-L132

This normally puts the frames in a list for packing, but you can replace frames.append(subtex) in line 132 with self.save(self, targetdir, filename, meta_formats=None) (choose parameters accprding to your needs). This should output each frame one by one.

gregstein commented 4 years ago

Hey Greg, glad you found us!

Our converter puts the frames into a spritesheet by design. If you want to extract every frame individually, you can start editing here:

https://github.com/SFTtech/openage/blob/7ca1723d486799d9922f36b07d50a920fdc02317/openage/convert/texture.py#L127-L132

This normally puts the frames in a list for packing, but you can replace frames.append(subtex) in line 132 with self.save(self, targetdir, filename, meta_formats=None) (choose parameters accprding to your needs). This should output each frame one by one.

Heinezen.. Thank you so much I couldn't be more satisfied with your beautiful answer

TheJJ commented 4 years ago

So i guess we can close this. If not, please report back :)

gregstein commented 4 years ago

Hello again,

So i'm struggling with the parameters and how I should run them..

I have tried:

python3 -m openage convert-file --player-palette-file /home/greg/games/aoe2de/Data/playercolor_blue.pal --palette-file /home/greg/games/aoe2de/Data/b_west.pal /home/greg/games /home/greg/rofl.png

Sorry for being a burden on this one as I am still learning python and making progress day in day out.

Thank you so much

heinezen commented 4 years ago

The solution is a bit hacky, but it should work. Replace the lines I quoted with this block of code, replace the placeholders for the Directory path and compile the project again.

frame_ctr = 0
for frame in input_data.main_frames: 
    for subtex in self._smp_to_subtextures(frame, 
                                           main_palette, 
                                           player_palette, 
                                           custom_cutter): 
        self.image_data = subtex
        frame_name = "frame_%s" % (frame_ctr)
        frame_ctr += 1
        self.save(Directory("/folder/on/your/system/").root, frame_name)
        frames.append(subtex) 
gregstein commented 4 years ago

I did exactly as you have suggested but im getting "ValueError: Texture image must be created from PIL Image or numpy array, not '<class 'openage.convert.texture.TextureImage'>'"

texture

This is the command used: python3 -m openage convert-file --player-palette-file /home/greg/game/playercolor_blue.pal --palette-file /home/greg/game/b_west.pal /home/greg/game/u_vil_male_villager_idleA_x1.smx /home/greg/game/rofl.png

And is it necessary to rebuild as in deleting the project then make it again? Because I only used make command to rebuild.

heinezen commented 4 years ago

I updated the line with self.image_data = subtex in my comment above so that it hopefully works now (sorry for the guesswork, I can't test the code myself atm). Using make to rebuild is fine and the only thing necessary.

gregstein commented 4 years ago

That fixed but now I see a new error in your last code edit:

NameError: name 'Directory' is not defined directory

I think if this is fixed your code will work. Here's how my code look like:

            frame_ctr = 0
            for frame in input_data.main_frames: 
                for subtex in self._smp_to_subtextures(frame, 
                                           main_palette, 
                                           player_palette, 
                                           custom_cutter): 
                    self.image_data = subtex
                    frame_name = "frame_%s" % (frame_ctr)
                    frame_name += "1.png"
                    self.save(Directory(Path("/home/greg/frames/").parent).root, frame_name)
heinezen commented 4 years ago

Try importing this at the start of the file

from ..util.fslike.directory import Directory
gregstein commented 4 years ago

After importing the line i get

raise Exception("incompatible type for path: %s" % type(path_))
Exception: incompatible type for path: <class 'openage.util.fslike.path.Path'>

imcompatible

Please note that I had to change frame_name += 1 to frame_name += "1" because it returned frame_name must be str.

heinezen commented 4 years ago

Removing the Path(..).parent expression around the string "/home/greg/frames/" might help.

and it should be frame_ctr += 1 not frame_name += 1

heinezen commented 4 years ago

Hmm.. Look in your folder :D

It should have converted the frames individually. The last exception occurs because the frames weren't put in a list at the end. You can fix that by adding frames.append(subtex) after self.save(..) again.

gregstein commented 4 years ago

You are one hell of a Genius! Though I got an error that 'can't create texture with empty input frame' Still the frames were extracted successfully.

Look at this beauty: myframes Fuck Yeah!!

I'm really sorry for all the trouble you went through to help me out with this.

You made my day really!!! Thank you so fucking much

Have an awesome day brother <3

gregstein commented 4 years ago

Hmm.. Look in your folder :D

It should have converted the frames individually. The last exception occurs because the frames weren't put in a list at the end. You can fix that by adding frames.append(subtex) after self.save(..) again.

How did you know that? LOL... That's insane really you guys are fucking python geniuses and I think studying this library will help me come even little bit closer to being a python mother fucker.