Write mesh seems to write the original version of the mesh.
For example if I apply a new texture to the existing mesh then export the mesh using OBJ file writer.
The file export is the original file with the original texture. Is the file export using the cached mesh rather than the current mesh?
Is there anyway to update so the mesh pointing to the new texture?
//Updated [solved!]
CuteAlien has kindly added this feature in trunk.
Below is one example of using it correctly.
Since obj writer write the current vertice poistion of the node, which means that the vertices values (tangent, normal etc) to changed. This somehow causes the texture to incorrectly positioned. So the best way to preserve the scale and position is to set the node to 0's pos and rotation, save, then move the node back to the original position.
Note: If you want to save the terrain or other scene node type to obj then you might have to cast is to the correct type before save. You might want to update the function for your intention.
Also you might save it in a different buffer, so you might want to change the function to your needs.
Regards
thanh
Code: Select all
private: void ExportObjFile(ISceneNode *m_node, const irr::io::path &outPath)
{
irr::io::IWriteFile *file = smgr->getFileSystem()->createAndWriteFile(outPath, false);
irr::scene::IMeshWriter *writer = smgr->createMeshWriter(irr::scene::EMWT_OBJ);
vector3df nodePos = m_node->getPosition();
vector3df nodeRot = m_node->getRotation();
m_node->setPosition(vector3df(0)); //Reposition the scenenode at 0.
m_node->setRotation(vector3df(0)); //Resetrotation the scenenode at 0.
m_node->updateAbsolutePosition();
if (m_node->getType() != irr::scene::ESCENE_NODE_TYPE::ESNT_ANIMATED_MESH)
{
IMeshSceneNode *node = (IMeshSceneNode *)m_node;
writer->writeMesh(file, node->getMesh());
}
else
{
IAnimatedMeshSceneNode *node = (IAnimatedMeshSceneNode *)m_node;
f32 x, y, x2, y2;
node->getMesh()->getMeshBuffer(0)->getMaterial().getTextureMatrix(0).getTextureScale(x, y);
node->getMesh()->getMeshBuffer(0)->getMaterial().getTextureMatrix(0).getTextureTranslate(x2, y2);
writer->writeMesh(file, node->getMesh());
}
writer->drop();
file->drop();
m_node->setRotation(nodeRot); //Reposition the scenenode to original pos.
m_node->setPosition(nodePos); //Reset rotation of the scenenode to original rotation.
m_node->updateAbsolutePosition();
}
Thanks
thanh