Saving mesh to a file

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Saving mesh to a file

Post by scippie »

Hi, I'm trying to save a generated mesh to a .irr file.
So, I use the IMeshWriter with an IWriteFile.
But how do I create the IWriteFile instance?

If I do it like this, I get a linker error "unresolved external symbol "class irr::io::IWriteFile * __cdecl irr::io::createWriteFile(char const *,bool)" (?createWriteFile@io@irr@@YAPAVIWriteFile@12@PBD_N@Z) referenced in function "public: void __thiscall CApp::SetupTest(void)" (?SetupTest@CApp@@QAEXXZ)"

Code: Select all

IMeshWriter *mw = SCN()->createMeshWriter(EMWT_IRR_MESH);
IWriteFile *wf = irr::io::createWriteFile("man/dressed-man.irr", false);
mw->writeMesh(wf, manmesh);
mw->drop();
wf->drop();
(btw. SCN() returns the ISceneManager)

Anyone?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

are you using the correct namespace for IWriteFile? (not sure what that is)
Image Image Image
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Post by scippie »

JP wrote:are you using the correct namespace for IWriteFile? (not sure what that is)
Are there more than one??

In the beginning of the code I have:

Code: Select all

#include "irrlicht.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
So I guess, irr::io:: is automatically used?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There is simply no such function. Try to use the IFileSystem which is passed to you via the smgr. There are functiosn to create files.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You should know there are more than one as you're using 6 there :lol:

Looks like it's probably covered so that's not the problem, was a wild guess anyway!
Image Image Image
scippie
Posts: 26
Joined: Sat Oct 13, 2007 3:35 pm
Location: Belgium
Contact:

Post by scippie »

hybrid wrote:There is simply no such function. Try to use the IFileSystem which is passed to you via the smgr. There are functiosn to create files.
The device manager that is... thanks!
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

just in case anyone ever searches and wonders... worked pretty straight forward...

Code: Select all

	void writeMeshFile(static core::stringw path,
						scene::EMESH_WRITER_TYPE type,
						scene::CVertexBuffer* outVB,
						scene::CIndexBuffer* outIB)
	{
		scene::CDynamicMeshBuffer* outbuffer = new scene::CDynamicMeshBuffer(outVB->getType(),outIB->getType());
		outbuffer->setVertexBuffer(outVB);
		outbuffer->setIndexBuffer(outIB);

		scene::SMesh* outmesh = new scene::SMesh();
		outmesh->addMeshBuffer(outbuffer);

		scene::IMeshWriter* writer = SceneManager->createMeshWriter(type);
		
		io::IWriteFile* file = SceneManager->getFileSystem()->createAndWriteFile(path);
		writer->writeMesh(file,outmesh);
		
		writer->drop();
		outmesh->drop();
		file->drop();
	}

	scene::CDynamicMeshBuffer* loadMesh(static core::stringw path)
	{
		scene::IMesh* mesh = SceneManager->getMesh(path);
		scene::IMeshBuffer* outbuffer = mesh->getMeshBuffer(0);
		video::S3DVertex* verts = (video::S3DVertex*)outbuffer->getVertices();
		u16* indices = (u16*)outbuffer->getIndices();
		u32 vc =  outbuffer->getVertexCount();
		u32 ic = outbuffer->getIndexCount();

		scene::CDynamicMeshBuffer* dOutbuffer = new scene::CDynamicMeshBuffer(outbuffer->getVertexType(),outbuffer->getIndexType());
		scene::CIndexBuffer* iB = new scene::CIndexBuffer(outbuffer->getIndexType());
		scene::CVertexBuffer* vB = new scene::CVertexBuffer(outbuffer->getVertexType());
		
		for(u32 v=0; v<vc; v++)
			vB->push_back(verts[v]);
		for(u32 i=0; i<ic; i++)
			iB->push_back(indices[i]);

		dOutbuffer->setVertexBuffer(vB);
		dOutbuffer->setIndexBuffer(iB);
		return dOutbuffer;
	}
unfortunately I was not able to read any of the produced files with Maya or again with irrlicht :(

EDIT: I did succeed in saving and successfully loading irrmesh files with those methods. I casted from should be u16* to u32*... :oops: didnt think it would make a difference... I changed that above, so the methods work. Of course loading can be a lot easier if you dont need CDynamicMeshBuffer's but I just like the handling of the lists more...
Post Reply