Hi,

I don't think there's a function that does exactly what you want.

However, doing it yourself is not that hard. The steps are:

1) Create a new face structure with indices for position, texcoords, and 
normals, ala:

struct my_face_t
{
    int positions[3]; int texcoords[3]; int normals[3];
};

This is simple a matter of copying the data from Lib3dsFace.index to 
positions and texcoords.
We'll fill normals later..

2) Remove duplicate position vertices.  In the 3ds format, vertices with the 
same position, but different
 texcoords are duplicated. You need to find these duplicates, create a new 
vertex list, and update the
 positions indices in the my_face_t struct.  Optionally you can skip this, 
but you will get discontinuities in
 lighting across texture coordinate seams.

3) Compute vertex normals.  Use lib3ds_mesh_calculate_normals to calculate 
normals. Fill normals in
my_face_t (very simple, just 0,1,2 then 3,4,5 and so on).  Then do step 2 
again, but this time on the normals.
This is not really optimal, it would be better to fix 
lib3ds_mesh_calculate_normals to compute shared vertex
normals directly.

4) Optionally do the same for the texture coordinate. You can usually skip 
this..

5) Now you have your faces and three lists (positions, texcoords, and 
normals), but of different length.
The next step is sometimes called "consolidation".  Basically you need to 
find unique vertices.

In pseudo C++:

struct vertex_t { int position; int texcoords; int normal; };
std::map<vertex_t,int> vertices;
std::vector<int3> vbo_indices;
std::vector<float3> vbo_positions;
std::vector<float2> vbo_texcoords;
std::vector<float3> vbo_normals;
for each face f
    int3 idx
    for each vertex index v 0...2
        vertex_t x;
        x.position = faces[f].positions[v]
        x.texcoord = faces[f].texcoords[v]
        x.normal = faces[f].normals[v]

        //check if we already found this vertex..
        if vertices.find(v)
            idx[v] = vertices[v]
        else
            vbo_positions.push_back(positions[x.position])
            vbo_texcoords.push_back(texcoords[x.texcoord])
            vbo_normals.push_back(normals[x.normal])
            idx[v] = vbo_positions.size() - 1
            vertices.insert(make_pair(x,idx[v]))

    vbo_indices.push_back(idx)

5) Now you have everything exactly as you want it for VBOs.

HTH

-- wang

"Raúl Huertas" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]
Hello lib3ds developers!

I want to make lib3ds work with OpenGL and VBOs. But, I have a doubt. In 
OpenGL the nomber of vertex in an rray buffer must be equal to the nomber of 
texcoordinates, and equal to the nomber of ormals. So:

anymesh.points==anymesh.texels==(number of normals)   right?

But... the function "lib3ds_mesh_calculate_normals" give me 
3*sizeof(Lib3dsVector)*mesh->faces normals!, not 
3*sizeof(Lib3dsVector)*mesh->points. Do you have any other function more 
appropiated for OpenGL VBOs and normals?.



Get news, entertainment and everything you care about at Live.com. Check it 
out!



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/



_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel

Reply via email to