Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / software 3d engine ponderings Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 02, 2005, 02:37 PM

I'm currently in the beginning phase of a software engine. I always have problems coming up with a good 3d-structure eg. structures for vertex/texturecoords/faceindecies/meshes/worlds. Anyone have any good solutions of how to structure your data? The usual thing to do is to have several lists for each triangular mesh, say vertexlist, rotated_vertexlist, uvlist, facelist, or just pack everything in a list of polygons (containing vertexcoords, texturecoordinates, normals etc.). But isnīt there some better way of doing this?

I'm also abstracting the renderer in some ways. Do you think one should have the whole pipeline in the derieved software_renderer or hardware_renderer?

Vander Nunes

March 02, 2005, 07:57 PM

I usually store object information using two structs, one containing a vertex list (with texture coordinates, color, etc) and one containing a polygon list (with vertex index and some extra properties if needed). The vertex list has a clone for the post-transformation stage.

This is very simplistic but works for most cases. If I start a new engine from scratch from now, though, I'll put a list of shaders and store the shader index in the polygon list, removing the texture coordinates from the vertex list, though.

Most people are using classes for everything now, including myself, but I think structs are still reasonable and effective.

My $0.02.


March 02, 2005, 09:31 PM

"Most people are using classes for everything now, including myself, but I think structs are still reasonable and effective."

Structs and classes are exactly the same, except structs default to public and classes default to private =)

Erik Faye-Lund

March 03, 2005, 01:58 PM

I use something like this for my software-rendering-needs:

class Triangle {
unsigned verts[3];
unsigned norms[3];
unsigned uvs[3];

class Mesh {
std::vector verts;
std::vector tverts;
std::vector norms;
std::vector uvs;
std::vector triangles;

It's simple, and it works. I can't really see any good reason to store it otherwise.


March 03, 2005, 03:18 PM

Yeah :) That's what I decided last night too ;) Thanks for the replies.

Peter Bone

March 04, 2005, 09:16 AM

Here's my software renderer code you can look at - written in delphi.
Look at the Model3D and World3D classes in particular to see the structure.

The best way is to have a separate vertex array and then the corners of the faces index a position in the vertex array. This means that when you come to rotate or move an object you don't transform the same vertex more than once.
Like Vander Nunes said, you need another vertex array for the view-space coordinates and another for the screen space coordinates (or just use a structure to store them in the same array like I did).

Peter Bone

Rui Martins

March 04, 2005, 10:14 AM

Well, your triangle class doesn't allow for more than 1 texture to be applyed to the same Triangle, but using different uv coords.

Also, you have no reference to the texture associated with the Triangle or Mesh!

Are you assuming one Mesh one Texture ?
Or besides that you reuse the Mesh, and change the texture for each pass ?

This thread contains 7 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.