3D Demo for PyGamer Arduino and Adafruit Arcada

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
quarterturn
 
Posts: 76
Joined: Mon Mar 23, 2015 11:05 pm

3D Demo for PyGamer Arduino and Adafruit Arcada

Post by quarterturn »

Here's a simple demo of doing 3D graphics on a PyGamer (SAMD51, ST7735 LCD, joystick) with the Adafruit Arcada library:
https://github.com/quarterturn/pygamer- ... /README.md

This is a re-write of https://github.com/michaelerule/Uno9341TFT, removing all the hacky stuff specific to squeezing reasonable performance out of an Arduino Uno. For simplicity's sake, the 3D code is just a library of functions and isn't a class.

You use the joystick to rotate the 3D object. It renders fast and smooth thanks to the use of an offscreen framebuffer and DMA blitting to the screen. The object is pesudo-shaded via face normals - this is cheap and fast and give the appearance of a light source. The hardware is probably capable of Gouraud or Phong shading and this may be explored later.

You may change the rendering method to vertex points or wireframe by commenting/uncommenting the method you want in model().

At some point I'd like to try implementing hidden-line removal as shown here: https://github.com/osresearch/papercraf ... ddenwire.c
This involves making a copy of the vertexes as they will be pruned and edited depending on if lines are fully or partially occulded, so free RAM may be an issue on larger objects.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: 3D Demo for PyGamer Arduino and Adafruit Arcada

Post by adafruit_support_mike »

Interesting.. thanks for posting the code!

User avatar
quarterturn
 
Posts: 76
Joined: Mon Mar 23, 2015 11:05 pm

Re: 3D Demo for PyGamer Arduino and Adafruit Arcada

Post by quarterturn »

You're welcome. I've updated the repo with the .stl conveter found in the original library and modified it to remove the uint8 limitation so that larger objects can be used. The Utah Teapot on wikimedia renders well when scaled down to 1024 triangles using MeshLab. You can just about see stepping as you rotate so to me that's about 25-30 FPS. There isn't enough flash to handle the full size, but it's silly to do that on a 160x128 screen.

Gouraud shading (linear interpolation) of triangles will greatly improve the look of low-poly objects. I'm going to try modding my local copy of Adafruit_GFX and add that based on the existing filled triangle code. It should be an easy mod since you just pass three vertex colors. I'm trying to keep things simple with regards to passing the pointer to the canvas and it would be nice to keep it to the level of the shadeFaces function in the same way it's done for fillFaces. 3D pros will want perspective-correct shading, but that's beyond my current skill level.

User avatar
quarterturn
 
Posts: 76
Joined: Mon Mar 23, 2015 11:05 pm

Re: 3D Demo for PyGamer Arduino and Adafruit Arcada

Post by quarterturn »

I'll add:
void Adafruit_GFX::shadeTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color0, uint16_t color1, uint16_t color2)
to perform linear interpolated shading of a triangle via 565 vertex color values.

and helper function:
uint16_t Adafruit_GFX::interpolate(uint16_t color0, uint16_t color1, uint16_t alpha)
to get an interpolated 565 value for the above function

If it works I'll submit a merge request to the Adafruit_GFX repo.

User avatar
quarterturn
 
Posts: 76
Joined: Mon Mar 23, 2015 11:05 pm

Re: 3D Demo for PyGamer Arduino and Adafruit Arcada

Post by quarterturn »

vlcsnap-2021-07-02-11h58m02s565.png
vlcsnap-2021-07-02-11h58m02s565.png (324.21 KiB) Viewed 87 times
Vertex shading is now working. It's rather hacky in that at the moment, the color interpolation routine works in an 8-bit mono space and conversion to 565 color happens as each pixel is written to the offscreen buffer. This certainly can be improved upon.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”