IrrAssimp (mesh import/export)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

IrrAssimp (mesh import/export)

Postby JLouisB » Sat May 02, 2015 5:44 pm

Hi,
During the last weeks, I have integrated the Assimp library (http://assimp.sourceforge.net/) in an Irrlicht project.
Assimp is a library actively developed and maintained made to import/export 3D models in a lot of file fomats.
Assimp supports a lot of imports formats (more than 40), and it's useful in particular for animated meshes because Irrlicht doesn't support the most popular formats for that, like FBX or Collada.
Assimp can also export in 4 formats and only static mesh yet (like Irrlicht : Collada, obj, stl, ply), but more formats are available in the trunk version (3DS, Assimp format(binary/XML), DirectX (.x))

To use it :
- Download Assimp and add it to your project.
- Add the content of the IrrAssimp folder in your projet
- And the usage is very simple :
cpp Code: Select all
// The assimp loader is in a separate system and not directly implemented as a meshLoader to give the choice to use Irrlicht or Assimp for mesh loading to the user, in function of the format for example
IrrAssimp assimp(smgr);
IAnimatedMesh* mesh = assimp.getMesh("Media/dwarf.x");
if(!mesh)
{
    std::cout << assimp.getError().c_str() << std::endl;
    device->drop();
    return 1;
}
assimp.exportMesh(mesh, "obj", "Media/export.obj");


If you use a trunk version of Assimp, note that animated meshes support is not yet implemented in the exporter, I will add this.

The code is on Github.
JLouisB
 
Posts: 51
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: IrrAssimp (mesh import/export)

Postby Ovan » Sat May 02, 2015 8:15 pm

uhm just a question for other
why your class isn't derived from IMeshLoader/IMeshWriter then passed to the video driver ?

http://irrlicht.sourceforge.net/docu/cl ... oader.html
http://irrlicht.sourceforge.net/docu/cl ... riter.html

permit to use the default interface from IVideoDriver can be more simple ...
User avatar
Ovan
 
Posts: 67
Joined: Thu Dec 18, 2008 12:41 am

Re: IrrAssimp (mesh import/export)

Postby JLouisB » Sat May 02, 2015 9:29 pm

Yes it can be more simple with IMeshLoader/IMeshWriter.

If I have chosen to not create the class as a MeshLoader, it's because there are a lot of formats that Irrlicht and Assimp can load quite both.
So for this formats, I want to have the choice between use Irrlicht loaders or Assimp loaders for each mesh, in function of the format for example.
Maybe some specific formats/files can give a better result with Assimp, maybe with Irrlicht.
If I add the class as a mesh loader, Irrlicht's loaders will be automatically overrided by Assimp, I prefer have a clear difference between the 2 loaders.

So it's not the most simple, but maybe more flexible and it doesn't complicate a lot the things for the same result :
cpp Code: Select all
scene::IAnimatedMesh* getMesh(core::stringc path)
{
    IrrAssimp assimp (Smgr);
    if (assimp.isLoadable(path))
        return assimp.getMesh(path);
    else
        return Smgr.getMesh(path);
}


Otherwise, you can easily change the code to use directly IrrAssimpImport as a mesh loader and IrrAssimpExport as mesh writer (but I'm open to suggestions, if many people think that it's a bad design I can change it).
JLouisB
 
Posts: 51
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: IrrAssimp (mesh import/export)

Postby AReichl » Sun May 03, 2015 10:46 am

Yeeehaa - something i have waited for a long time.
I think CopperCube (=IrrEdit) also uses Assimp internally.
MAYBE we should go this way - get rid of the buildin loaders (except maybe .irr, .irrmesh)
so the developers can concentrate on MORE IMPORTANT things. Other engines also do it so.
Then JLouisB "only" has to maintain the wrapper.
I know i know - one dependency you would have to install besides Irrlicht, but think about
the advantage ...
AReichl
 
Posts: 239
Joined: Wed Jul 13, 2011 2:34 pm

Re: IrrAssimp (mesh import/export)

Postby Nadro » Sun May 03, 2015 11:10 am

Hi,

This is really useful stuff, thanks a lot for that :)

Cheers,
Nadro
 
Posts: 1647
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: IrrAssimp (mesh import/export)

Postby airc » Sun May 03, 2015 5:07 pm

looks good , but irrlicht already has plenty of mesh loaders , so why another mesh loader?
airc
 
Posts: 25
Joined: Wed Jan 08, 2014 8:17 am

Re: IrrAssimp (mesh import/export)

Postby thanhle » Sun May 03, 2015 6:14 pm

I like this : ).
But I don't like the use of boost in Assimp.

Cheers
thanh
thanhle
 
Posts: 324
Joined: Wed Jun 12, 2013 8:09 am

Re: IrrAssimp (mesh import/export)

Postby JLouisB » Sun May 03, 2015 9:01 pm

It's good know that it's can be useful for some people :)


@airc : Irrlicht has a planty of mesh loaders, but some very useful formats are missing in Irrlicht.
In particular if you want import an animated model in Irrlicht, Irrlicht supports only some old and not very popular file formats.
Currently, most of the 3D softwares/modern game engine use formats like FBX or Collada, they are the current standards to transfer 3D models between the applications, and Irrlicht doesn't support them (there is a Collada loader, but for static mesh only).

The export feature is recent in Assimp, but I hope that in the futur, Assimp will be able to export animated mesh in popular formats like FBX.
Currently the only way to export an animated mesh in Irrlicht is with the recently added B3D exporter, it's good to have at least one exporter to do this, but it's not the best format to transfer 3D models with the other applications.


@thanhle : Look at here, Assimp can be built without Boost.
JLouisB
 
Posts: 51
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: IrrAssimp (mesh import/export)

Postby CuteAlien » Sun May 03, 2015 10:05 pm

Very cool - several people already asked about assimp and Irrlicht. Great I can finally link them here :-)
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8515
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: IrrAssimp (mesh import/export)

Postby sunqian » Mon May 04, 2015 12:58 am

Very useful. Just tried it, now we can load fbx animation. Thanks for your great work!
sunqian
 
Posts: 2
Joined: Wed Apr 08, 2015 11:42 am

Re: IrrAssimp (mesh import/export)

Postby christianclavet » Mon May 04, 2015 5:40 pm

Wow! FBX too?!! This is incredible! Now that Irrlicht can save animated meshes (B3D) and with this ability to load all theses format Irrlicht will be more accessible than ever! Great job!
User avatar
christianclavet
 
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA

Re: IrrAssimp (mesh import/export)

Postby JLouisB » Wed May 06, 2015 10:32 pm

Thanks for your enthusiasm about this :)

Christian, yes, FBX is supported by Assimp, but I have just noticed that it's not written on their website, the "features" page of Assimp is probably not up to date.
JLouisB
 
Posts: 51
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: IrrAssimp (mesh import/export)

Postby christianclavet » Sun Aug 07, 2016 10:27 pm

Used it, and it work now. (Used FBX) I will have to see why my exports from MAX seem to have axis inverted. My swordman is lying on the ground and the sword and buckle inverted (wrong hand, so there is a axis flip)

EDIT:
I fixed it, changed the line 133 in IrrAssimpImport.cpp:
From
cpp Code: Select all
AssimpScene = Importer.ReadFile(to_char_string(FilePath).c_str(), aiProcess_Triangulate |  aiProcess_GenSmoothNormals | aiProcess_FlipUVs);

to
cpp Code: Select all
AssimpScene = Importer.ReadFile(to_char_string(FilePath).c_str(), aiProcess_Triangulate | aiProcess_MakeLeftHanded | aiProcess_GenSmoothNormals | aiProcess_FlipWindingOrder | aiProcess_FlipUVs);

Now my FBX models that come from 3D Studio Max are the same in the application. The buckle and sword appear in the proper hand, no more X axis flipping.
User avatar
christianclavet
 
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest