Sign in to follow this  
Mr Smith

OpenGL Collada file loading?

Recommended Posts

Hi everyone, We are busy with programming a graphics engine in OpenGL, but we face a little problem (rather a big one, if you aks me). We want to load Collada files in our engine. We have been looking for a way to do that, but until now we've only found FCollada and Collada DOM. But both libraries don't have much documentation. Could someone provide us with an in depth tutorial or example how to use one of these libraries? Thanks in advance. Mr Smith. [Edited by - Mr Smith on August 14, 2009 2:04:06 PM]

Share this post


Link to post
Share on other sites
What I did was I wrote a program in C# using the .Net XML classes to pull all the data I needed out of the collada file and write it out to my own text based format that my c++ program could easily parse. It may not help you any but I thought I'd share.

[Edited by - santonel on August 15, 2009 12:29:52 AM]

Share this post


Link to post
Share on other sites
I've had the same problem for something like a year now. Eventually I just abandoned collada. NeHe's got a good Milkshape3d loader, and you can derive a class for any other model type you'd need from the one it provides. MS3D is not a bad format anyway, so you may not need more than it provides. It'll take some specification studying to expand the one NeHe has, but at least you'll be making progress and not searching endlessly like I had to do for quite some time.

Share this post


Link to post
Share on other sites
Look at the specification. The Collada DOM has a 1-1 correspondence with the spec and that is how I implemented my loader. Download the example collada files from here and try to first load the vertices, then the faces,material etc. It is true that Collada hasn't got much documentation online.
Also there is ASSIMP(though I haven't used it).

Hope this helps.

Share this post


Link to post
Share on other sites
I've used Assimp, and I can tell that in the recent versions it loads most Collada files correctly. I'm also the maintainer of the Assimp Collada loader, so if you have files that fail the import or look weird when coming out of the loader, please send them to me. Preferrably small ones which clearly reproduce the issue :) Contact details are given at the page.

Share this post


Link to post
Share on other sites
I don't know any good tutorials, but I'll share my own COLLADA loading code from my game engine. It converts .dae to my custom model format.
http://users.utu.fi/tmwire/aether3d/files/convert_dae.cpp
http://users.utu.fi/tmwire/aether3d/files/common.h

Share this post


Link to post
Share on other sites
Thank you for all the replies.

@EngineCoder Thank you for the source code of your loader. I'm a beginner with file loading.
Is it possible that your loader doesn't handle animations?

@Schrompf I also thought of Assimp, but as I told you before I'm only a beginner. I've not found
a way to use Assimp in my engine.

I would like to make a loader that loads geometry, materials, animations and lights

Thanks for your help already.

Mr. Smith

Share this post


Link to post
Share on other sites
Check out Assimp, put the directory in the same directory as your VisualStudio solution, load the solution, click "Add -> add existing project" in the context menu of your solution, choose the correct visual studio project, compile. you're done. Now you only need to include the assimp headers relative to your own headers and link against it.

[edit] Just to be more specific: this is one of the methods to integrate a third-party library into your projects. This is not specific to Assimp. Sooner or later you have to learn how to use third-party libs. But until then you can also try to write your own loader or adapt an existing one. It's just... according to my experiences, the Collada format specification is a bitch to load, full of over-engineered needless complexity. That's why you rarely find an implementation which is able to load most files and provides all the features a game needs. The Assimp loader is one of those, albeit not perfect. It supports scene graphs, instancing, meshes, skinning and bones, animations, materials, textures, lights, cameras. That's why I recommend it, even if the process of integrating and using a third-party library seems to be complicated when you're doing it the first time.

Share this post


Link to post
Share on other sites
Sorry for the late reply, but I was on vacation.

@Schrompf I think I will use Assimp for my file loading.
Can you give me a tutorial how to load a file (Collada)?

[Edited by - Mr Smith on August 19, 2009 7:46:54 AM]

Share this post


Link to post
Share on other sites
I used COLLADA DOM for my project. There is a book you can buy that has some examples in:

COLLADA: sailing the gulf of 3D digital content creation

I only got as far as geometry loading because the aim of the project was to wrap C# around the C++ but this may be worth investigating further. I did this project about 2 years ago and im quite suprised COLLADA hasn't taken off since...

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr Smith
@Schrompf I think I will use Assimp for my file loading.
Can you give me a tutorial how to load a file (Collada)?


Did you look into the lib's documentation? There's a little chapter in there which says the following:


#include <assimp.hpp> // C++ importer interface
#include <aiScene.h> // Output data structures
#include <aiPostProcess.h> // Post processing flags


bool DoTheImportThing( const std::string& pFile)
{
// Create an instance of the Importer class
Assimp::Importer importer;

// And have it read the given file with some example postprocessing
// Usually - if speed is not the most important aspect for you - you'll
// propably to request more postprocessing than we do in this example.
unsigned int flags = aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices;
const aiScene* scene = importer.ReadFile( pFile, flags);

// If the import failed, report it
if( !scene)
{
DoTheErrorLogging( importer.GetErrorString());
return false;
}

// Now we can access the file's contents.
DoTheSceneProcessing( scene);

// We're done. Everything will be cleaned up by the importer destructor
return true;
}



From there you need to simply copy the imported data into your own structures or buffers. If you already have simple rendering working, you can plug in the imported data. If not, you better get the rendering working first.

Bye, Thomas

Share this post


Link to post
Share on other sites
Hi Schrompf,

I am also working on OpenGL ES 2.0 framework,that can load
Collada and .3ds file.But i am facing problem in Animatiom.
So what i have decided i will use only loader source code
from Assimp and put into my own framework.So just wanted to
ask that any dependency is there in code.Can i only extract the collada and .3ds loader from Assimp and feed the data into my own framewok.
Regards,
parmar.

Share this post


Link to post
Share on other sites
You can probably get some pointers from the source, but copypaste it into your source won't work without hassle. a) I'm depending on the Assimp math classes alot, b) we use irrXml where we fixed several bugs to get it reliable and c) at the end the loader emits raw scenes. I rely on Assimp's post processing alot, for example to get indexed meshes, generate tangents/bitangents, coordinate space conversion, and several more.

If that doesn't stop you, feel free to try. The lib is under BSD license, you can use it freely for whatever you need. But it might be quicker to just use Assimp directly, and maybe add all the AI_NO_XYZ_LOADER defines to reduce it's size.

Share this post


Link to post
Share on other sites

Thanks for your help.

How I can use Assimp directly in my OpenGL ES 2.0 framework,
so that no need to change anything.I just debuged Assimp i found that you people are using DirectX for rendering.
Regards,
Parmar.

Share this post


Link to post
Share on other sites
Read the documentation. The Assimp library is a plattform-abstract library for loading 3D scenes from various file formats. It does not render anything in any way, it does not use the operating system except for memory allocation and file access. What you probably meant is AssimpView which has been developed in parallel. This viewer application is a little tool which uses the Assimp library to show all sorts of 3D files like maybe IrfanView does for pictures. But you don't need it, the core library works independently of the viewer. We should maybe change the name of it to avoid this confusion.

Share this post


Link to post
Share on other sites
Is there someone who wants to give me some personal
support trough chat, because I've still got some
problems with Assimp. Please send me a PM.

(edit) I've problems with "DoTheErrorLogging" and "DoTheSceneProcessing".
I don't know how I must declare these functions.

Mr Smith.

[Edited by - Mr Smith on August 21, 2009 1:55:53 PM]

Share this post


Link to post
Share on other sites
Quote:

(edit) I've problems with "DoTheErrorLogging" and "DoTheSceneProcessing".
I don't know how I must declare these functions.


That's correct. The names of the functions alone should tell you that these are placeholders where you put your own code. Nobody knows what data you engine expects and which structures you use to store them. That's why you have to write your own code there to translate Assimp data to your engine's data. Most of the time this will be a simple copy, but we can't tell that from the lib's side.

Share this post


Link to post
Share on other sites
Yep, your post sounds pretty familiar to me as we had a similar search last year for a .net reader/writer solution...We just hate marshaling in the COLLADA DOM objects and things just got more messy when we actually started manipulating the objects.

After doing a lot of digging on the web, we never found anything that seemed to do what we needed so we ended up writing our own...It works pretty good and is being used in our commercial products.

Our COLLADA.net would be considered a viable alternative to the other solutions you previously mentioned.

Here's the link if you are interested:
http://www.mogware.com/index.php?page=collada.NET

Share this post


Link to post
Share on other sites
Yep, your post sounds pretty familiar to me as we had a similar search last year for a .NET reader/writer solution...We just hate marshaling in the COLLADA DOM objects and things just tend to get more messy when you actually start manipulating the objects.

After doing a lot of digging on the web, we never found anything that seemed to do what we needed so we ended up writing our own...It works pretty good and is being used in our commercial products.

Our COLLADA.net would be considered a viable alternative to the other solutions you previously mentioned because you also get the source code making it more extensible.

Here's the link if you are interested:
http://www.mogware.com/index.php?page=collada.NET

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627733
    • Total Posts
      2978839
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now