Original Post
okay i've post part of this code b4, now its causing errors and i dont know why:
noe renderSectors is just a strucutre, with a list of snMesh's
//just so you know...
struct snMesh
{
IGameMaterial* material;
std::vector<sFace> faces;
std::vector<unsigned int> indices;
std::vector<Point3> positions;
std::vector<Point2> uvCoords;
std::vector<Point2> uvCoords2; //light maps or what ever
std::vector<Point3> normals;
std::vector<Point3> colors;
};
bool Export::DivideMesh( snMesh* mesh )
{
renderSectorDivision = 3;
int sectorGap = 100; //the gap between sectors
//renderSectorInfo.startValue = -300;
float mapSize = abs( renderSectorInfo.startValue ) * 2;
renderSectorInfo.cellGap = mapSize / renderSectorInfo.cols;
//renderSectorInfo.cols = 2;
/*
fprintf(pFile, "cols: %i\n", renderSectorInfo.cols );
fprintf(pFile, "startValue: %f\n", renderSectorInfo.startValue );
fprintf(pFile, "cellGap: %f\n", renderSectorInfo.cellGap );
*/
//loop through each face
for( int f = 0; f < mesh->indices.size(); f += 3 )
{
//which cell is this vertex in?
Point3 p[3];
int faces[3];
std::set<int> cells;
for( int i = 0; i < 3; ++i )
{
faces[i] = mesh->indices[f + i];
p[i] = mesh->positions[ faces[i] ];
int x = (p[i].x - renderSectorInfo.startValue)/renderSectorInfo.cellGap;
int z = (p[i].z - renderSectorInfo.startValue)/renderSectorInfo.cellGap;
//fprintf( pFile, "vertex: %f %f, cell: %i %i, cell: %i\n", p[i].x, p[i].z, x,z, ((x * renderSectorInfo.cols)+z) );
cells.insert( ((x * renderSectorInfo.cols)+z) );
}
std::set<int>::iterator cIt;
for( cIt = cells.begin(); cIt != cells.end(); cIt++ )
{
for( int t = 0; t < 3; t++ )
{
//fprintf( pFile, "adding to cell: %i\n", (*cIt) );
//now find which mesh to insert this in via texture
std::list<snMesh*>::iterator meshIt;
for( meshIt = renderSectors[ (*cIt) ].meshes.begin(); meshIt != renderSectors[ (*cIt) ].meshes.end(); ++meshIt )
{
if( (*meshIt)->material == mesh->material )
{
/*
(*meshIt)->indices.push_back( (*meshIt)->positions.size() );
//fprintf( pFile, "num uvs: %i, num pos: %i, face: %i\n", mesh->uvCoords.size(), mesh->positions.size(), faces[t]);
if( mesh->uvCoords.size() > 0 )
(*meshIt)->uvCoords.push_back( mesh->uvCoords[ faces[t] ] );
(*meshIt)->positions.push_back( p[t] );
//fprintf( pFile, "size of indices: %i\n", (*meshIt)->indices.size() );
//fprintf(pFile, "adding to cell: %i\n", (*cIt) );*/
break;
}
}
if( meshIt == renderSectors[ (*cIt) ].meshes.end() )
{
//try
//{
snMesh* newMesh = new snMesh;
newMesh->material = mesh->material;
//fprintf(pFile, "adding to cell: %i, but there are: %i cells, cur cell size is: %i\n", (*cIt), renderSectors.size(), renderSectors[ (*cIt) ].meshes.size() );
renderSectors[ (*cIt) ].meshes.push_front( newMesh );
unsigned int size = renderSectors[ (*cIt) ].meshes.front()->positions.size();
snMesh *m = renderSectors[ (*cIt) ].meshes.front();
renderSectors[ (*cIt) ].meshes.front()->indices.push_back( size );
// if( mesh->uvCoords.size() )
// renderSectors[ (*cIt) ].meshes.front()->uvCoords.push_back( mesh->uvCoords[ faces[t] ] );
renderSectors[ (*cIt) ].meshes.front()->positions.push_back( p[t] );
//fprintf( pFile, "n size of indices: %i\n", renderSectors[ (*cIt) ].meshes.front()->indices.size() );
//}
//catch( std::exception e )
//{
// fprintf(pFile, "error: %s\n", e.what );
//}
}
}
}
}
return true;
}
the line causing grief is:
renderSectors[ (*cIt) ].meshes.front()->indices.push_back( size );
it works on some sample data i try exporting, then when i goto export some larger real life data, it kicks the bucket.
now for what it should do:
divide up a snMesh into smaller snMeshes... like a grid cuts through the faces.....
[edited by - supagu on March 11, 2004 4:04:50 AM]
[edited by - supagu on March 11, 2004 4:07:24 AM]