Miku Miku Dance for esp32 (just 300KB RAM)

Tiny 3D rendering and skeletal animation using esp32.

Public Chat
Similar projects worth following
This project including 3D rendering and skeletal animation for esp32. M5Stack is also supported. This project features fast scan line method and skeletal animation to dance a MMD model. It renders 七葉1052式 which is a MMD model, which has 2450 triangles at about 24fps. scan line method is used. Split triangles and render 40 vertical lines at the same time. Skeletal-animation, inverse kinematics and forward kinematics and linear interpolation is also used.

MMD for esp32

Source code is available at github.

MMD for esp32, M5Stack, (WiFiBoy32 page)

---------- more ----------


FPS: 22~26fps

RAM: about 300KB

Triangles: 2450

Vertexes: 3337

Bones: 92

Thread: 2 (barrier sync)

Memory usage (estimates):

Memory usage
for each element [byte]
total [byte]
Triangle buffer
136(shape, count, UV, ...)
Vertex buffer
Z buffer
2(2 byte)*window_width*DRAW_NLINES=25600256008.5%
Draw buffers
Bone matrixes64(Matrix)*4+4+4*3=272
Animation position,
rotation, frame
Vertex matrixes6464*150=96003.2%

Others (stack, threads, or used in os) are excluded in the table.

DRAW_NLINES is const variable how many horizontal lines is send to the LCD at the same time. The Larger the number of horizontal lines, the faster and smooth animation, but It takes lot of RAM.

Double buffering method is used and  CPU task which draw the 3D model and send to LCD is executed simultaneously.

Triangles which is spanning two DRAW_NLINES area is stored in the Triangle buffer.(Red triangle in the picture below)

Drawing method.
Drawing method.

Triangle which behinds the camera Z-clip.

Pattern 1, 2 vertexes are behind the camera. move two vertixes to the ZNEAR

Pattern2, 1 vertex is behind the camera. Then, split one triangle into two triangles.

triangle ① and ② will draw.

==TODO list==
- refactor (especially skeletal animation source code)
- multiple models to show stage, other 3D models and so on.

  • 1 × M5Stack or esp32 and LCD(ILI9341)

  • 1
    how to build

    PC (tested at Ubuntu, SDL2 is required):

    $ g++ *.cpp *.c -lSDL2 -DPC


    Flash (using

    $ python --chip esp32 --port <your usb device> --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 bootloader.bin 0x10000 spi_master.bin 0x8000 partitions.bin

    Flash (Windows):

    how to flash on windows

    how to flash on windows

    Build and flash:

    $ make flash monitor

View all instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates