MMD for esp32

Source code is available at github.

MMD for esp32, M5Stack, (WiFiBoy32 page)

Resolution:320x240

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, ...)
136*300=40800
13.6%
Vertex buffer
4*4=16
16*3337=5339217.7%
Z buffer
2(2 byte)*window_width*DRAW_NLINES=25600256008.5%
Draw buffers
2*window_width*DRAW_NLINES=2560025600*2=5120017.1%
Bone matrixes64(Matrix)*4+4+4*3=272
272*92=25024
8.3%
Animation position,
rotation, frame
(3+4+1)*4*2=6464*92=58882.0%
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.