CColladaMeshWriter and Custom Mesh
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
CColladaMeshWriter and Custom Mesh
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
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
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
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 :
Anton
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
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
Hybrid
I do not fully understand what you mean in your last reply. I have now generated the following code :
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
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);
:
:
:
<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
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am
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 :
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
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;
}
Thanks
Anton
-
- Posts: 81
- Joined: Thu Oct 16, 2008 6:50 am