CColladaMeshWriter and Custom Mesh

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.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

CColladaMeshWriter and Custom Mesh

Post by asparagusx »

Hallo

I have a custom mesh (derived from ISceneNode). How would I create a COLLADA export file? It seems to use IMesh as an interface? Sorry, but this is probably a silly question, but any advice will be appreciated.

Thanks

Anton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you don't provide a IMesh from your custom geometry, there's no way to write a mesh file from it with the existing writer method.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

I am really stuck with this.

My custom mesh is derived from ISceneNode which obviously does not support getMesh - which will be needed to provide a IMesh * to enable writing. I have looked through the documentation and there does not appear to be any samples on writing files (maybe I am not looking for the correct terms). Should I derive my custom mesh from IMeshSceneNode and then override getMesh (and others)? Internally my mesh does use a derived class from SMeshBuffer to provide custom buffer handling and I can provide this to a calling function.

Here is my current thinking to create a structure to export my data. I have many ISceneNode derived objects in my scene manager, each which can contain many mesh buffers (different vertex types). A solution might be to create a single SMesh and add all the SMeshBuffers from all my scene nodes and then passing that to the writeMesh function :

Code: Select all

	IMeshWriter *writer = Device.pDevice->getSceneManager()->createMeshWriter(EMWT_COLLADA);
	IWriteFile *write = NULL; // create the file here
	SMesh Mesh;
	SMeshBuffer *Buffer = NULL;
	
                // in a loop collect SMeshBuffer data and use addMeshBuffer
                :
	Mesh.addMeshBuffer(Buffer);
                :
                // end of loop
	writer->writeMesh(write,&Mesh);
                // clean-up
Anton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, if you have an IMesh internally (which would be simple when working with SMeshBuffer internally) you can just derive from IMeshSceneNode and provide that Mesh via getMesh functions.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

If I derive my custom scene node from IMeshSceneNode, rather than ISceneNode, will this still behave the same e.g. I still implement my own draw code - will the scene manager not want to access my 'internal' meshes via getMesh and getMeshBuffers during rendering?

Anton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, these functions are just provided for the user to acess the mesh. Rendering will always be defined in render()
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

How would I go about saving a whole 'scene' e.g. all the children of my current scene manager to a single export file? I can see how to create a single mesh output (with multiple mesh buffers attached to IMesh), but not all the nodes in my scene.

Thanks

Anton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can simply create a serialization method for your scene node, and call the scene saving method from Irrlicht. You'll need a scene node factory for this to work properly, otherwise there's no way for the loading app to know about your custom mesh, though.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Hybrid

I do not fully understand what you mean in your last reply. I have now generated the following code :

Code: Select all

	IMeshWriter *writer = pCD->DwgSmgr->createMeshWriter(EMWT_COLLADA);
	IWriteFile *out = Device.ifs->createAndWriteFile("C:\\TEST.DAE");
		
	pCD->DwgSmgr->saveScene(out);		
which certainly does produce some output, including accessing my custom mesh. I do not understand the 'scene factory' bit at all. Here is a small extract from the collada file I produced, showing some of my custom mesh attributes, including the material definitions. My custom mesh is now derived from IMeshSceneNode and I have implemented the various virtual functions required e.g. getMesh. However it never gets called :
:
:
:
<attributes>
<string name="Name" value="Cube" />
<int name="Id" value="197250824" />
<vector3d name="Position" value="0.000000, 0.000000, 0.000000" />
<vector3d name="Rotation" value="0.000000, 0.000000, 0.000000" />
<vector3d name="Scale" value="1.000000, 1.000000, 1.000000" />
<bool name="Visible" value="true" />
<enum name="AutomaticCulling" value="box" />
<int name="DebugDataVisible" value="0" />
<bool name="IsDebugObject" value="false" />
</attributes>

<materials>
<attributes>
<enum name="Type" value="solid" />
<color name="Ambient" value="ffff0000" />

:
:
:

Other functions in my custom mesh e.g. getMaterial is called during saveScene.

Anton
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

I am really stuck with this and can do with some advise :oops:
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Sorry to bump this, but I have not been able to resolve this at all - anybody else having problems creating Collada files?

Thanks

Anton
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Hallo

I am now ready to look at this function again. Can somebody please see if they can comment on this.

Much appreciated.

Anton
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So do you have a custom scene node? Please show the code and the output from the Collada writer fo this node.
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Hybrid

That is the problem! I do have a 'scene' made up of many custom scene nodes. I have now moved this on slightly, by using a SMesh and then adding all the mesh buffers from my custom meshes into this single SMesh and the exporting that to a DAE file. My code looks as follows :

Code: Select all

int CDrawing::SaveAsDAE(LPCTSTR Filename)
	{
	SMesh mesh;
	POSITION Pos;
	patp pat;
	IMeshBuffer *mb = 0;
	UINT i,j;
	
	for (Pos = FP(); Pos; )
		{
		pat = GetNextPattern(Pos);
		if (pat->IsVisible() && pat->DCELList.size())
			{
			for (i = 0; i != pat->DCELList.size(); ++i)
				{
				for (j = 0; j != pat->DCELList[i]->MFaces.size(); ++j)
					mesh.addMeshBuffer(pat->DCELList[i]->MFaces[j]->Mesh->Buffer());
				}
			}
		}
	IMeshWriter *writer = DwgSmgr->createMeshWriter(EMWT_COLLADA);
	IWriteFile *out = Device->ifs->createAndWriteFile(Filename);
	
	writer->writeMesh(out,&mesh);	
	return CSystem::GEN_ALL_OK;
	}
This appears to export the geometry, but materials (e.g. diffuse colours) etc does not work - or at least it does not show up while using Irrlicht MeshViewer. I am not sure that creating a single SMesh is the best way of doing this.

Thanks

Anton
asparagusx
Posts: 81
Joined: Thu Oct 16, 2008 6:50 am

Post by asparagusx »

Any furtehr information on this????
Post Reply