Thread: reading a .3ds in OpenGL?

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428

    reading a .3ds in OpenGL?

    Solved: Thanks for the help

    Hi guys. I've been playing around in OpenGL lately and downloaded the trial of 3d max. I'm thinking about purchasing the product for a full liscense, but want to make really sure I would be happy with the program. I have about 15 days left on the trial and I have made a complete 3d chess board. I would like to use an old chess engine I wrote and make it 3d. Does anyone know of a library or tutorial (free) that covers .3ds files in OpenGL? I tried asking on the autodesk community site but a majority of the members there seem to be designers and not programmers. I know you guys seem to provide the best answers I've seen around. Thanks.
    Last edited by Lesshardtofind; 09-11-2010 at 01:21 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Normally you write an exporter that exports the data in the modelling program to a file format of your choosing. Your code/engine or what have you can then load this information into the system and will render the data similar to what is rendered in the modelling program.

  4. #4
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    lol sarcasm appreciated or more specificly

    Tutorials:3ds Loader - Spacesimulator.net

    I originally posted because I was frustrated that most the links I went to kept sending me back to the same sites that wanted me to pay... Got frustrated hoped someone here already had some experience and suggestions... thnx anyways

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What do you want?
    Clues on how to proceed or spoon-fed answers?

    Sooner or later, there ARE no tutorials for what you want to do and you have to figure it out yourself the hard way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I have never really been rude to anyone on this board. I have always tried to work through any questions beforehand. Throughout life I learned one simple thing. Learning from more experienced people will save me time in mistakes. If none of us did this 90% of us would still be sitting in a field trying to figure out how to start a fire. Second thing I will always make mistakes... aka bad posts apparently.

    If you actually learned everything you know without a book or lesson from someone else I am sincerely impressed. If not then I am sincerely curious what makes you so intolerant of my desire to start a conversation about how 3ds objects are loaded in OpenGL with experienced programmers in order to gain a better understanding before I go about writing stuff that doesn't work figure out why ... write something else that doesn't work figure out why? Very understandably that would be a good tactic if no one else has done what I am working on before, but I'm trying to learn a program that has been around for years and programmed around for years. Why would I not learn from others with experience?

    3rd I wonder why at all you are involved in a forum about game programming if
    1. You don't need tutorials or help and 2. You would prefer to flame someone who asks a question that you know the answer to? I apologize to the rest of the board for this out of character post.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    3ds objects are loaded in OpenGL
    It's simple. You don't. 3DS is a proprietary file format and it's format will probably not be available on the internet. Even if it were the file format probably has a lot of bloat in it so the modeller can load the data into the system correctly. You would not need all of this extra stuff to simply load the data and it's associated scene graph, key frames, etc. As I said the usual practice is for studios to make an exporter for 3D Studio Max or Maya or whatever tool they are using. The exporter takes the data that is in memory and exports that data to a file with a format the engine code can read. 3DS and Maya both come with SDKs that allow you to write plug-ins for them for this exact purpose. Blender, to some extent, has plug-in support but it is through Python which more or less sucks and is not nearly as robust as supporting a C++ plug-in architecture. It is so simple to support such an architecture I have no idea why more programs don't do it.

    If you are looking for a free solution you could try out the now defunct Caligari TrueSpace 7.6 which also has an SDK and supports C++ plug-ins and also has very good professional level documentation.

    Other free solutions are not that great and sadly I've found that most open-source modellers are sorely lacking in documentation when it comes to plug-ins and writing exporters. Another one you may be interested in is Milkshape. It is not free but it is a good basic 3D modelling program and it also supports C++ plug-ins.

    A good open-source scenegraph solution is OpenSceneGraph. Supposedly this is gaining momentum and is supported by a lot of the major 3D modelling software packages. It is limited to OpenGL but that is what you said you were using so this should be a plus for you.

    Take a look at some of the files in the games you have bought for your PC. You will find that nearly every engine uses a proprietary custom format that has little or nothing to do with the modelling software that was used to design the files. Gamebryo games use the .NIF format wherein the scenegraph and other data reside. They also rely on some other files for keyframe animations and other data.

    Sooner or later, there ARE no tutorials for what you want to do and you have to figure it out yourself the hard way.
    You really need to take heed to what Salem is saying here. All the good 'secrets' are just that...secrets. No site is going to tell you everything you need to know to export and load in retail quality assets. And the truth is there isn't one tool that gives you this kind of quality. Studios nearly always rely on several different tools to create the assets and it is no small task. It is also not a small task to export all this data to a file format the engine can read and it is no small task to be able to render the object in your system as the artist created it in the modelling software. However, that is really what needs to happen or it needs to be very close. If you ever go down the path of hiring out your asset creation you will soon find they are creating beautifully rendered objects in their tools but you can't render those with your code so the effort is in vain. The key is being able to load and render those beautiful assets the artists so painstakingly created. There aren't any tutorials for this on the internet. And to get to that point you will need to design a fairly robust and complex system in the first place. I recommend you buy tons of books that address the issues you are encountering. Even then you will find that 80% of the books fall into the beginner to intermediate level and even the so-called 'advanced' ones are not all that advanced.

    One good place to learn how to do some of this or the design processes involved in asset creation and asset loading is at www.gamasutra.com. They have many very good articles on this and tons more on other topics.
    Last edited by VirtualAce; 09-11-2010 at 01:22 AM.

  8. #8
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Thank you for the information Bubba I found a website about how the data is stored and they don't mention anything about scripting an exporter. I can see a huge advantage to being able to design the 3ds max format that is output. After I get a working load function written in my engine I will definitely look into how I can make the format more usable for my program.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I have a friend at work that has done exporters for Maya. Unfortunately since 3DS Max is extremely expensive I do not personally know anyone that has written exporters for it. A friend of mine just paid nearly $2700 to do the same things you are talking about here and that is just for the software. After you get into hiring out the art and asset creation that number grows quickly. And that doesn't guarantee you will have great assets or if you do it still does not guarantee you will ever have a game worth playing.

    Keep in mind the danger of using 3DS is that if the file format ever changes in future versions (and it will) your code will be broken. It is probably not a good idea to rely on a file format when you have no control over the versioning of it. You are tying your code and your system directly into something that is beyond your control. It is much better to build an exporter that you can update later and yet still have your engine load your own file format that the exporter exports. This way you control the versioning of the asset file and when 3DS changes formats you simply write a new exporter or alter the existing one. File format versioning can become a real nightmare.

    Also remember the devil is in the details. Very often I find sites that claim they can load this or that format but skip over tons of information in the file that they either do not understand or for some reason think it is not important.
    Last edited by VirtualAce; 09-11-2010 at 01:30 AM.

  10. #10
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Quote Originally Posted by Bubba View Post
    Also remember the devil is in the details. Very often I find sites that claim they can load this or that format but skip over tons of information in the file that they either do not understand or for some reason think it is not important.
    Yes that is the very reason I come to this board. Alot of tutorials teach you to do only their objective and lack a broad explanation of what certain functions do. Which at times has led me to a bad understanding of certain programming concepts.

    I usually can find one good peice of information and then drive it to a full understanding such as.. in the liink above there is a reference to

    http://www.quantumg.net/3ds-info.txt

    Has alot of information on the .3ds file structure and how to read it. I will be spending a couple months trying to fully understand that I'm sure.

    And spending more money does not at all sound appealing considering if I decide to purchase the full liscense I will be knocking out most of my current savings.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    And spending more money does not at all sound appealing considering if I decide to purchase the full liscense I will be knocking out most of my current savings.
    Yes I'm not suggesting you go out and spend that kind of money but I was pointing out that information and convenience can be extremely expensive.

    I honestly would check out Caligari TrueSpace 7.6. It supports plug-ins and has a nice architecture. Microsoft had to shutter the studio or at least re-directed the studio so they are no longer in business as it pertains to that specific product.
    3D Modeling Software - trueSpace
    trueSpace Downloads

    It is not often you can get a $300 to $600 package for free complete with an SDK. I have downloaded this and am working on plug-ins for it as well. I would download this, along with the training videos, the SDK, etc. and burn them to a DVD so you have them. The expiration date for that site is way back in August of last year but it is still up. Not sure what Microsoft is planning to do with the site so I would hurry over there and snatch up what you can while you can.

  12. #12
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Thank you. You are full of tons of good information lol. I am downloading that now, but after hours of running through the text file I linked above I started to realize I need to go back to my openGL understanding and get it a little more solid before I just run around importing 3d files from 3d programs. For some reason I was initially an idiot and thought that the data would be stored in an already usable displayable format, rather than copying the data points of vertices over to a class I had previously defined.

    I was using mostly QUADS for my objects and I'm now reading that this is slower and more inefficient. Though I'm not currently aware why. Logicly a quad defined as two triangles is still going to have the same number of vertices (4) and they will share 2 of those vertices with each other, but why would rendering two surfaces be more efficient than rendering 1 surface? Especially when I jump to a cube now instead of 6 QUAD planes I have 12 Triangle surfaces even thoug it can still be defined as 8 shared vertices. I can see how this would allow for more complex texture maps though.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Triangles are more efficient because that is what the hardware needs. Again geometrically triangles are the only primitive that make sense since any 3 points in space are guaranteed to be co-planar. Thus a triangle will have 3 vertices, 3 edges, and 1 normal. You can overcome the vertex inefficiencies by sharing vertices via an index buffer. The index buffer essentially tells the hardware how to connect the vertices.

    A quad with a clockwise winding order without an index buffer in Direct3D would be:

    v0: -1.0f,1.0f,0.0f
    v1: 1.0f,1.0f,0.0f
    v2 -1.0f,-1.0f,0.0f

    v3: 1.0f,1.0f,0.0f
    v4: 1.0f,-1.0f,0.0f
    v5: -1.0f,-1.0f,0.0f

    Now notice there are some repeats. So an index buffer allows you to use the 4 unique vertices in the group and share them among triangles.

    The vertices would be:
    v0: -1.0f,1.0f,0.0f
    v1: 1.0f,1.0f,0.0f
    v2 -1.0f,-1.0f,0.0f
    v3: 1.0f,-1.0f,0.0f

    The indices would be:
    0,1,2
    1,3,2

    Index buffers are also optimal b/c it allows for efficient vertex caching on the video card. You might think sending in extra data would clog the bandwidth but it is actually more efficient to use vertex buffers with index buffers b/c of the caching scheme employed on today's video cards. It also reduces the number of vertices you must send down the pipeline.

    Even more efficient is to use triangle strips or triangle fans. A triangle strip requires 2 starting vertices and then 1 vertex after that for each new triangle. A triangle fan requires 2 vertices to start with and 1 for every triangle after that with the exception that the starting location of all triangles is the first vertex. Triangle fans are often used in terrain engines to give real-time level of detail. It simply comes down to which parts of the fan to draw and which parts to omit. This can also be done with a clever use of an index buffer. Index buffers can also be used to reduce the number of polygons in a mesh in real-time. Direct3D9 employs a mesh reduction algorithm that uses the index buffer in a clever way and the result is a mesh with pretty much the same shape of the original mesh but with far fewer triangles. The algorithm was invented by Hugues Hoppe - http://research.microsoft.com/en-us/um/people/hoppe/ (click on the link for Progressive meshes).

    When it comes to rendering the smarter the better. What you do not render is far more important than what you do render. There are thousands of algorithms out there that will squeeze every ounce of horsepower from the hardware simply by being smart with what is and is not rendered.
    Last edited by VirtualAce; 09-11-2010 at 11:29 PM.

  14. #14
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    goto; TresCom - the place for Trespasser fans

    Scroll down the page until you see the import/export max scripts. The two gentlemen who wrote these scripts did so for the game Trespasser. It exports a 3ds model from max (scripts also work for GMax) into a file format we call tpm (which is used to import models into the game (they created the format to work with a model import program (GeomAdd)).

    Unfortunately, both Andres and Remdul (they wrote the scripts) are mia, so you couldn't ask them Qs directly, but perhaps looking over the scripts could help you some.

    Oops. Solved? Nevermind then!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opengl and WM_PAINT
    By Kosei Inoue in forum Game Programming
    Replies: 1
    Last Post: 10-20-2009, 10:33 AM
  2. Multithread pthread with OpenGL
    By parad0x13 in forum C++ Programming
    Replies: 8
    Last Post: 07-24-2008, 03:04 PM
  3. first opengl game, problems.
    By n3v in forum Game Programming
    Replies: 1
    Last Post: 07-11-2006, 08:22 PM
  4. What is it with OpenGL tutorials?
    By Eibro in forum Game Programming
    Replies: 22
    Last Post: 01-12-2003, 04:49 PM
  5. OpenGL 2 or DirectX ?
    By alex6852 in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-02-2003, 02:31 PM