May Flour or ways can generate a arbitra cloth mesh?[SOLVED]

harr999y

24-07-2010 14:52:54

Hi,there :)
I want to generate a cloth mesh,but the flour 0.4 or NxOgre::MeshGenerator::makePlane/makeBox can't make it true.And if I use the way of PhysX,I don't know how to put it into NxOgre::ClothDescription.Can you help? Thanks~~~
Harry.

betajaen

24-07-2010 15:41:51

Have a look at the ManualMesh it works in the same way that Ogre's ManualObject.

harr999y

26-07-2010 10:50:25

Have a look at the ManualMesh it works in the same way that Ogre's ManualObject.
Thanks,betajaen.From the ManualMesh I get it. :D
As some limits from protected variable,I don't use ManualMesh directly.
I add a static function in the class MeshGenerator:
Mesh* MeshGenerator::makeClothFromFlower(const Path& saveTo,const Path & flowerPath)
{
Resource * res = ResourceSystem::getSingleton()->open(flowerPath, NxOgre::Enums::ResourceAccess_ReadOnly);
NxOgre::MeshData * mesh = new MeshData;

/************************************************************************/
/* Comes from NxOgreFlower.cpp */
/************************************************************************/
buffer<char> lineBuffer;

while(res->atEnd() == false)
{
NxOgre::Strings::getLine(res, lineBuffer);

if (lineBuffer.size() == 1) // (0 characters + 1 byte null)
continue; // Skip empty lines

if (lineBuffer[0] == '#')
continue; // Skip full comment lines.

std::string line(lineBuffer.first());

Strings::slice_to_first_of(line, '#');
Strings::trim(line);

buffer<float> buf;
// vertices
if (Strings::starts_insensitive(line, "Vertices"))
{
Strings::slice(line, 8);
//Strings::split<float>(line, mesh, ",");
Strings::split<float>(line,buf,",");
mesh->mVertices.push_back(buf[0]);
mesh->mVertices.push_back(buf[1]);
mesh->mVertices.push_back(buf[2]);
continue;
}

// indices
if (Strings::starts_insensitive(line, "indices"))
{
Strings::slice(line,7);
//Strings::split<unsigned int>(line, mesh->mIndexes, ",");
Strings::split<float>(line,buf,",");
mesh->mIndexes.push_back(buf[0]);
mesh->mIndexes.push_back(buf[1]);
mesh->mIndexes.push_back(buf[2]);
continue;
}

// normals
if (Strings::starts_insensitive(line, "normals"))
{
Strings::slice(line, 7);
//Strings::split<float>(line, mesh->mNormals, ",");
Strings::split<float>(line,buf,",");
mesh->mNormals.push_back(buf[0]);
mesh->mNormals.push_back(buf[0]);
mesh->mNormals.push_back(buf[0]);
continue;
}

// texture coordinates
if (Strings::starts_insensitive(line, "texturecoords"))
{
Strings::slice(line, 14);
//Strings::split<float>(line, mesh->mTextureCoordinates, ",");
Strings::split<float>(line,buf,",");
mesh->mTextureCoordinates.push_back(buf[0]);
mesh->mTextureCoordinates.push_back(buf[1]);
continue;
}
}

Resource * resource = ResourceSystem::getSingleton()->open(saveTo,NxOgre::Enums::ResourceAccess_ReadAndWrite);
mesh->mType = Enums::MeshType_Cloth;
mesh->cook(resource);
Mesh * me = MeshManager::getSingleton()->load(resource);
return me;
}

And modify the flower_blender_export.py for blender to get the textureCoords or normals:
for vert in mesh.verts:
#if (len(vert.uvco) == 2)
out.write( 'texturecoords %f, %f \n' % (vert.uvco.x, vert.uvco.y ) )
for vert in mesh.verts:
#if (len(vert.no) == 3)
out.write( 'normals %f, %f ,%f \n' % (vert.no.x, vert.no.y, vert.no.z ) )

Then use it in the sandBox just as:
//Here can't use OgreReasource.
Mesh * me = MeshGenerator::makeClothFromFlower(Path("file://../media/PhysX/3.xcl"),Path("file://../media/PhysX/1.flower"));

Ok,it can convert any .flower file to .xcl. :)