Skip to content

Kevman323/tomomaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

TomoMaker

TomoMaker is a set of python scripts that allow images to be converted into controls and played back on a Raspberry Pi to draw them out in Tomodachi Life: Living the Dream.

dcdemo.mp4

Disclaimer

I am by no means a Python, or even a Programming expert. I've cobbled these scripts together to the best of my ability using many online resources. I'm sure I've made mistakes, or overcomplicated things in places. I'm open to feedback or recommendations.

Performance

This script is able to make ~33 inputs per second, either moving or drawing.

A Full-sized 256x256 image at 10 colors takes anywhere from 50-60 minutes

A Full-sized 256x256 image at 20 colors takes anywhere from 65-80 minutes

I recommend trying out several color amounts, and picking one that is a good trade-off between quality and time. I usually stick within the 15-20 color range, but some images that are mostly made of the same colors look fine closer to 10. This sample image from the video above was only 12 colors and took 62 minutes to draw. Demoncore-12c

Requirements

  • A Raspberry Pi (tested with a Raspberry Pi 4B)

  • A Powered USB hub (Highly Recommended)

  • A USB cable to connect the Raspberry Pi USB C port to the Hub/Switch

Setup

I'm running Ubuntu Server 24.04.04 LTS 64-bit on a Raspberry Pi 4B. Other Distributions or models of Pi may cause issues.

First, you must enable USB gadget mode on the Raspberry Pi. Run these commands:

 echo "dwc2" | sudo tee -a /etc/modules
 echo "libcomposite" | sudo tee -a /etc/modules

 reboot

I may further explain the installation process in the future, but for now you need the following installed for tomoreplay.py:

  • Python 3.10+

And for tomoreplay.py, which does not necessarily have to be run on the Pi itself, you also need:

  • Pillow
  • scikit-learn
  • numpy

Usage

There are two separate Python scripts with separate purposes:

tomomaker.py

  python tomomaker.py input_image [colors] [resize]
  
  input_image - Path to an input image. Both PNG and JPG work
  colors      - Number of colors to reduce final image to. -1 to disable color reduction. DEFAULT: 20
  resize      - Whether to resize the image to 256x256 (tomodachi life canvas size) DEFAULT: True

This script takes an input image, and generates a .txt file filled with commands that can be replayed with tomoreplay.py

It will save a preview of the final image, and a .txt file containing the replay commands in the output folder.

tomoreplay.py

    python tomoreplay.py commands.txt
    
    commands.txt - A list of controller button inputs to be replayed. Generated by tomomaker.py

This script takes a file generated from tomomaker.py, and replays the inputs while connected to the switch to draw the image.

Before running, it necessary to set up the HID interface for USB Gadget mode. This must be run every time the Pi reboots.

    sudo ./makegadget.sh

How to Use

  1. Generate a list of commands using tomomaker.py
  2. Connect the Raspberry Pi to a powered USB hub connected to the switch
    • A powered hub is highly recommended because otherwise the Raspberry Pi may experience undervoltage, or reboot when connected directly to the Switch
  3. In the Switch's system settings, make sure Controllers and Accessories -> Pro Controller Wired Communication is ENABLED
  4. Open Tomodachi Life, and go to anywhere you can draw, such as the palette house, or Mii editor
  5. Select the drawing pen, and select the smallest pen size.
  6. Position the pen in the upper lefthand conrer pixel of the canvas
    • Make sure the canvas is fully zoomed out, otherwise the pen may leave the canvas and desync
  7. Run tomoreplay.py with your selected command script. The switch will detect the Raspberry Pi as a controller, and after a short delay, begin drawing!
    • If you encounter an error when starting, close the script, put your switch into sleep mode, and wake it up, then try again
    • Also remember that you have to run makegadget.sh every time the Pi reboots!

Drawing Theory

This is a general summary of how tomomaker.py generates its draw path

  1. First the image is resized, and its colors are reduced to the selected amount.
  2. The image is split into colors, and each color layer is split into separated components
  3. The colors are drawn largest -> smallest. To optimize things, two options are tested:
    • Just draw the current color's components
    • Combine all undrawn areas into a new mask, separate components, and draw/fill any components that contain the current color. This results in a very large speedup in the first few layers.
  4. Components are drawn one by one. The border pixels are drawn, and then the fill tool is selected and interior areas are filled.
    • This is a large opportunity for a pretty good speedup. Right now, a greedy nearest approach is used for pathing to components, pathing to the next border pixel, and pathing to the next interior fill area. A more complicated solution could reduce a lot of slow extra pathing, but I wasn't about to get into the traveling salesman problem just yet!

Special Thanks

Thank you so much to these projects. Without them, there's no chance I would have figured out the Pro Controller Protocol on my own.

https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering - Fantastic resource of Switch Controller procotol

https://github.com/mzyy94/nscon - Basic foundation of Rpi Gadget Mode

https://github.com/omakoto/raspberry-switch-control - Extra help in configuring the Rpi to work with USB Gadget mode

https://github.com/Lucas7yoshi/TomodachiDrawer - Figuring out how to correctly map the in-game HSV color selector

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors