BlasterN
08-08-2006 20:51:23
I'm developing now a Mesh to ConvexShape.
The first goal was to extract the Edges for the mesh. I use getMeshInformation(...) from
http://www.ogre3d.org/wiki/index.php/RetrieveVertexData , the second one.
that function return:
- all vertices
- all indexes (triangles)
with a little code a get edges like that:
(I'm not worry about the memory leak yet)
So with that code applied to a cube give you a vector with 32 points (16 edges) that's correct, but when create the ConvexShape Crash (no assertions) :S
So, someone have a Mesh -> ConvexShape vector.
The first goal was to extract the Edges for the mesh. I use getMeshInformation(...) from
http://www.ogre3d.org/wiki/index.php/RetrieveVertexData , the second one.
that function return:
- all vertices
- all indexes (triangles)
with a little code a get edges like that:
bool notRepeated(std::vector<Ogre::Vector3>* verts, Ogre::Vector3& A1, Ogre::Vector3& A2)
{
for(int i=0; i<verts->size(); i+=2)
{
if (
( (*verts)[i] == A1 && (*verts)[i+1] == A2 )
||
( (*verts)[i] == A2 && (*verts)[i+1] == A1 )
)
{
OgreLog(Ogre::String("REPEATED"));
return false;
}
}
return true;
}
std::vector<Ogre::Vector3>& getMeshEdges(Ogre::Mesh* mesh)
{
size_t vertex_count,index_count;
Ogre::Vector3* vertices;
unsigned long* indices;
getMeshInformation(mesh,vertex_count,vertices,index_count,indices,
Ogre::Vector3::ZERO,Ogre::Quaternion::IDENTITY,
Ogre::Vector3(1,1,1));
std::vector<Ogre::Vector3>* out=new std::vector<Ogre::Vector3>();
OgreLog(Ogre::StringConverter::toString(index_count));
OgreLog(Ogre::StringConverter::toString(vertex_count));
for(size_t i=0; i<index_count; i+=3)
{
if(notRepeated(out,vertices[indices[i]],vertices[indices[i+1]]))
{
out->push_back(vertices[indices[i]]);
out->push_back(vertices[indices[i+1]]);
}
if(notRepeated(out,vertices[indices[i]],vertices[indices[i+2]]))
{
out->push_back(vertices[indices[i]]);
out->push_back(vertices[indices[i+2]]);
}
if(notRepeated(out,vertices[indices[i+1]],vertices[indices[i+2]]))
{
out->push_back(vertices[indices[i+1]]);
out->push_back(vertices[indices[i+2]]);
}
}
delete[] vertices;
delete[] indices;
return *out;
}
(I'm not worry about the memory leak yet)
So with that code applied to a cube give you a vector with 32 points (16 edges) that's correct, but when create the ConvexShape Crash (no assertions) :S
So, someone have a Mesh -> ConvexShape vector.