Homebrew [N00b Question] How are the vertices lists generated in 3ds examples?

NotImpLife

Active Member
OP
Newcomer
Joined
Mar 9, 2021
Messages
41
Trophies
0
Website
github.com
XP
487
Country
Romania
Hi! I just wanna display a 3d model on a 3DS and I have no clue where to start from. I studied the examples/3ds that come with devkitPro and found these things:

Extract from lenny\...\lenny.c:
Code:
const vertex vertex_list[3345] =
{
{ -0.48246, 0.00967688, -0.179352, 0, -1.85661e-012, -1, },
{ -0.48245, -0.0384802, -0.179352, 0, -1.85661e-012, -1, },
{ -0.483443, -0.0141747, -0.179352, 0, -1.85661e-012, -1, },
......

Extract from toon_shading\...\teapot.c:
Code:
const float vertex_array[7752] =
{
-0.508714, 0.682112, 0.071712, -0.901883, 0.415418, 0.118168,
-0.517593, 0.664661, 0.063813, -0.905637, 0.407056, 0.118656,
-0.499882, 0.682112, 0.139122, -0.877041, 0.418744, 0.235298,
.....

I guess no human being in the world would be capable to manually type that huge amount of numbers (jk)
So, can someone please explain what those vertex arrays mean and how exactly are they generated?
 

iMackshun

Member
Newcomer
Joined
Mar 3, 2021
Messages
10
Trophies
0
Age
26
Location
United States
Website
imackshun.wixsite.com
XP
87
Country
United States
I'm not entirely sure how the file was generated. I'm sure there's probably some program was used to convert the model into those .c files, as it wouldn't take that much effort.

Vertex arrays are exactly what the name implies. An array of vertices. The C3D_AttrInfo is used to define the attributes present within a single vertex. In the case of the lenny example, each vertex has a position and normal. Both attributes consist of three floats each, so

Code:
{ -0.48246, 0.00967688, -0.179352, 0, -1.85661e-012, -1, }

Corresponds to a vertex positioned at (-0.48246, 0.00967688, -0.179352) with a normal value of (0, -1.85661e-012, -1).

C3D_BufInfos are associated with vertex arrays, and must be "bound" so to speak in order to prepare the vertices to be drawn to the screen. In this case, I say bind loosely, but it must be set to be active before drawing, so that it is clear what vertex data you are sending to the GPU to be processed. It contains info about the size of each vertex, and the attributes to enable when processing each vertex.

C3D_DrawArrays is called to draw the model using the active C3D_AttrInfo and C3D_BufInfo. There are various drawing modes, with the simplest being GPU_TRIANGLES. For every 3 vertices, a triangle is drawn.

When it comes to learning how to draw a model on the 3DS, the best place to start would probably be learning OpenGL first. I would recommend this site. (https://learnopengl.com/) Ultimately, models can come in many formats, all of which have their own pros and cons. Some are plain text and easy to read, such as .obj. Others are binary, and you need to use a SDK to parse them, such as .fbx. In the case of those c files, they are convenient to use because the array can be accessed directly without any parsing necessary. However, you could extract data from any model file and store it in an array. An .obj file is easy to understand, so with a little code, you can parse it to put it into a vertex array, which can then be drawn to the screen. Before attempting to draw a model with Citro3D, I would recommend learning how to draw a model with OpenGL. Once you are comfortable with doing that, a lot of the code in the GPU examples are pretty straightforward.

This is a very rough description of the process, and I'm sure I simplified things a bit. But that's the gist of it, happy coding! I learned OpenGL about 2 years ago(Using that site, Youtube videos, and just trying things out), and just recently started using Citro3D again.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: S3X