L3DS library and .3ds files

This is a discussion on L3DS library and .3ds files within the Game Programming forums, part of the General Programming Boards category; Hello to all of you, yet again. I was wondering if anybody here has ever used the L3DS library. It ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    Question L3DS library and .3ds files

    Hello to all of you, yet again.

    I was wondering if anybody here has ever used the L3DS library. It is a C++ library to load .3ds files into memory.

    Over the past little while I have been traversing it, searching it, studying it, etc., so I know the heirarchy of its classes, etc., and how it works.

    I feel I have a pretty good understanding of how it accomplishes things, however, there are a few things that still remain a mystery to me, and so if anyone here has experience with L3DS, their help would be useful.

    Here is my situation.

    I am making a class called MODEL_DTP which is able to handle any .3ds model that is loaded into memory by the L3DS library.

    MODEL_DTP will have the ability to rotate and move meshes, along with texture map them, etc., etc., etc. and so on and so forth.

    Well, I decided to perform a little Experimental Computer Science before I went head deep into creating my MODEL_DTP class.

    So this is what I did. I wanted to try texture mapping my models I was loading in with L3DS. So I decided to take a texture that I already had loaded into memory (it is a grass texture for my terrain), and apply it to the model. So I performed this code:

    Code:
    glBindTexture ( GL_TEXTURE_2D, texture [GRASS] );
    	for (uint i= 0; i<scene.GetMeshCount(); i++)
        {
    		
            LMesh &mesh = scene.GetMesh(i);
    
            glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
            glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
            glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
            glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3, 
                            GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
    
        }
    Finding the results interesting, I then decided to execute the code with a small change. Instead of just using my grass texture, I would use 3 textures: grass, hill, and water. (their id's are 0, 1, and 2).

    So i changed the code to look like this:

    Code:
    for (uint i= 0; i<scene.GetMeshCount(); i++)
        {
    		glBindTexture ( GL_TEXTURE_2D, texture [(i % 3)] );	
            LMesh &mesh = scene.GetMesh(i);
    
            glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
            glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
            glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
            glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3, 
                            GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
    
        }

    This time I was able to see every mesh with a seperate texture on it, so I could tell the difference between meshes throughout the entire model.

    However, throughout both tests, I have received slightly odd results, and I think I know why.

    At the bottom of this post is a picture of my results of the 2nd test. Look at it now, and then come back up here and read the rest of my post.

    Do not pay attention to the hexagonal shaped grass textures on the right of the picture, if you have read any of my previous threads you will know that they are simply just part of the map and have nothing to do with the 3d models.

    Anyways, as you can see, instead of there being a texture applied to the model, there is only a solid color: green is obviously where a grass texture should be, brown where a hill texture should be, and blue where a water texture should be.

    I began to think about this, and then came to the following conclusion: It is doing this becuase it applies each texture to a single triangle and not to a whole mesh. Therefore, I think it is applying that entire grass, or entire hill, or entire water texture, but each triangle is so small that all we are able to see is brown, green, or blue.

    Therefore, if my theory is correct, how could I somehow apply the texture to an entire mesh instead of each single triangle in the mesh. Or if you think my theory is wrong, what is your theory?
    Attached Images Attached Images  
    Last edited by DavidP; 10-29-2003 at 05:23 PM.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21