bbdocAntiDupe - Removing Duplicate Images

Discussion in 'Technical Discussion' started by trudnai, May 8, 2016.

  1. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,234
    Likes Received:
    696
    What's up Guys,

    I have created a tool to optimize bbdoc files by removing duplicate images. What you will achieve with this tool is smaller bbdoc and smaller game binaries. It does not make it faster, just makes it smaller...

    Ok, first things first, SAFETY!
    • Use this tool for your OWN RISK!
    • This is NOT an official tool from BuildBox, this is a HACK!
    • I have created this tool for BB 1.3.6 -- I have no idea how it behaves on BB 2 or other versions! DO NOT USE ON BB2 unless you know what you are doing!
    • This was designed for Mac, might be an easy effort to port it to Windows, but will not run by default and might do some unexpected behavior, do DO NOT RUN ON WINDOWS!
    • If you do not know how to open a command line on a Mac, DO NOT USE THIS TOOL!
    • If you do not know how to user Perl script, DO NOT USE THIS TOOL!
      • Call your friend who does!
      • Call your IT specialist!
      • Call your developer!
      • Hire someone! Just DO NOT DO THIS BY YOURSELF if you have never heard of Perl...
    • This tool although attempts to make backups, MAKE RELIABLE BACKP for yourself!
    • This is destructive, and I CANNOT RECOVER your files!
    • You are adult, please do not cry for mommy, DO YOUR RELIABLE BACKUP instead! :)
    Ok, so what this tool does is to analyze bbdoc, checks for duplicate images, and removes the ones that are duplicated. It then makes necessary modifications in the source file so every reference to the images will be corrected. It also deletes Atlases as well, so when you open your bbdoc with BuildBox it will be automatically re-generated from the existing images.

    You also need a little manual sanitization. After using this bbdocAntiDupe you need to open the bbdoc file and go to View -> Atlases, then click on Optimize button, and then Optimize Atlases button.

    An example:
    I have this simple demo with a sprite animation. My character blinks from time to time, otherwise just repeating the very same image all over again. Waste of space...
    Screen Shot 2016-05-08 at 12.05.33 AM.png
    Then I run bbdocAntiDupe:
    Screen Shot 2016-05-08 at 12.07.14 AM.png

    As you can see it removes lots of images, even though this project was a tiny little one. From the backup you can see that bbdoc shrinks to half. But in a real life you might not be able to achieve 50% size reduction, plus this is not fair as atlases are also removed... So do not take as this tool reduce bbdoc size by half because I do not claim that.

    Anyways, then open bbdoc, and when you open View -> Atlases, you will see some weird stuff on the Atlas:
    Screen Shot 2016-05-08 at 12.08.26 AM.png
    There are only 3 images left from the animation, but there are still references left - I might modify the tool later to remove these, right now you need to click on Optimize button, then you will see this:
    Screen Shot 2016-05-08 at 12.08.41 AM.png
    References are gone! You might also want to click on Optimize Atlases for best results...

    See attachment...
    Enjoy!
     

    Attached Files:

    Last edited: May 8, 2016
  2. playsgames6666

    playsgames6666 Miniboss Boxer

    Joined:
    Nov 13, 2015
    Messages:
    1,168
    Likes Received:
    745
    Man thats really cool.
    But i personally have not had any problems with duplicated images.
    I just use the BB tool- optimize atlases and all duplicates are gone.
    But still a cool tool that you have shared for all.
     
  3. heathclose

    heathclose Miniboss Boxer

    Joined:
    Jan 28, 2016
    Messages:
    1,810
    Likes Received:
    1,024
    but it's mother's day :rolleyes:
     
    trudnai likes this.
  4. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,234
    Likes Received:
    696
    you crack me up :)
     
    heathclose likes this.
  5. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,234
    Likes Received:
    696
    Thanks man!
    I am not sure about BB2, I am still using BB1, but when I add several objects, actions and characters with the same image, or as in my example using sprite animation, then these duplicates are not being removed. Each objects, action, characters and animation frames has their own version of the very same image. Even after clicking on all possible Optimization buttons:

    Screen Shot 2016-05-08 at 7.30.17 AM.png

    Those optimizations are only use when you have unused images or sprites.
    Is BB2 doing better job on this?
     
    playsgames6666 likes this.
  6. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,808
    Likes Received:
    2,309
    Great to see scripts and workarounds coming up. Thanks trudnai.

    Question:
    If a sprite animation has 10 seconds of a still image at the end (repeating itself), your script would only leave one image and the animation would still run 10 seconds? How is it possible that your script recognize that the image is the same? Because if it is with the name it won't work at all since all sprite animation PNGs have different names.

    Also, for different objects with the same image I do this the manual way right after importing. Just select the object, then go to the default animation, then click on edit, then on the image on edit again and in the Sprite editor you choose the same image from the previously imported object. This way it never will repeat itself. I understand that your script does exactly that but automatically?
     
  7. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,234
    Likes Received:
    696
    Thanks, I hope some day these ideas will be implemented in BB or will have a plugin system where we officially can create helper tools.

    Correct

    Internally BB does not use names, use reference IDs. This tool compares images and if they are the same removes the duplicates and then adjusts references in the source code. This will be the results:

    [Animation Frame 1] --> [PNG 1]
    [Animation Frame 2] --> [PNG 2]
    [Animation Frame 3] --> [PNG 3]
    [Animation Frame 4] --> [PNG 4]
    [Animation Frame 5] --> [PNG 5]
    [Animation Frame 6] --> [PNG 6]

    [Animation Frame 1] --> [PNG 1]
    [Animation Frame 2] --> [PNG 1]
    [Animation Frame 3] --> [PNG 1]
    [Animation Frame 4] --> [PNG 1]
    [Animation Frame 5] --> [PNG 1]
    [Animation Frame 6] --> [PNG 1]


    Correct -- But you cannot do that manually for animation frames...
     
    Christoph likes this.
  8. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,808
    Likes Received:
    2,309
    This indeed is incredibly awesome!!!! It opens up some new stuff which wasn't possible before. Like fade out a trail and keep 20 seconds of transparency without taking up more atlas space. Will give it a try for sure even though I have no idea how the command line tool works and what a Perl script is. :D Thanks again!
     
    trudnai likes this.
  9. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,234
    Likes Received:
    696
    Indeed! I needed this because character animation took so much space in the Atlases.

    I can't stress enough to make backup before you apply this tool! Also this should be a last time optimization effort as it removes images from your source file and that is irreversible... Let me know how it worked!
     

Share This Page