本文整理汇总了C++中ogre::MeshPtr::getSubMeshes方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::getSubMeshes方法的具体用法?C++ MeshPtr::getSubMeshes怎么用?C++ MeshPtr::getSubMeshes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::getSubMeshes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/*
Get the mesh information for the given mesh in v2 Ogre3D format. This is a really useful function that can be used by many
different systems. e.g. physics mesh, navmesh, occlusion geometry etc...
Original Code - Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
Most Code courtesy of al2950( thanks m8 :)), but then edited by Jayce Young & Hannah Young at Aurasoft UK (Skyline Game Engine)
to work with Items in the scene.
*/
void getMesh2Information( const Ogre::MeshPtr mesh,
size_t &vertex_count, Ogre::Vector3* &vertices,
size_t &index_count, Ogre::uint32* &indices,
const Ogre::Vector3 &position, const Ogre::Quaternion &orient,
const Ogre::Vector3 &scale )
{
//First, we compute the total number of vertices and indices and init the buffers.
unsigned int numVertices = 0;
unsigned int numIndices = 0;
Ogre::Mesh::SubMeshVec::const_iterator subMeshIterator = mesh->getSubMeshes().begin();
while ( subMeshIterator != mesh->getSubMeshes().end() )
{
Ogre::SubMesh *subMesh = *subMeshIterator;
numVertices += subMesh->mVao[0][0]->getVertexBuffers()[0]->getNumElements();
numIndices += subMesh->mVao[0][0]->getIndexBuffer()->getNumElements();
subMeshIterator++;
}
vertices = new Ogre::Vector3[numVertices];
indices = new Ogre::uint32[numIndices];
vertex_count = numVertices;
index_count = numIndices;
unsigned int addedVertices = 0;
unsigned int addedIndices = 0;
unsigned int index_offset = 0;
unsigned int subMeshOffset = 0;
// Read Submeshes
subMeshIterator = mesh->getSubMeshes().begin();
while ( subMeshIterator != mesh->getSubMeshes().end() )
{
Ogre::SubMesh *subMesh = *subMeshIterator;
Ogre::VertexArrayObjectArray vaos = subMesh->mVao[0];
if ( !vaos.empty() )
{
//Get the first LOD level
Ogre::VertexArrayObject *vao = vaos[0];
bool indices32 = ( vao->getIndexBuffer()->getIndexType() == Ogre::IndexBufferPacked::IT_32BIT );
const Ogre::VertexBufferPackedVec &vertexBuffers = vao->getVertexBuffers();
Ogre::IndexBufferPacked *indexBuffer = vao->getIndexBuffer();
//request async read from buffer
Ogre::VertexArrayObject::ReadRequestsArray requests;
requests.push_back( Ogre::VertexArrayObject::ReadRequests( Ogre::VES_POSITION ) );
vao->readRequests( requests );
vao->mapAsyncTickets( requests );
unsigned int subMeshVerticiesNum = requests[0].vertexBuffer->getNumElements();
if ( requests[0].type == Ogre::VET_HALF4 )
{
for ( size_t i = 0; i < subMeshVerticiesNum; ++i )
{
const Ogre::uint16* pos = reinterpret_cast<const Ogre::uint16*>( requests[0].data );
Ogre::Vector3 vec;
vec.x = Ogre::Bitwise::halfToFloat( pos[0] );
vec.y = Ogre::Bitwise::halfToFloat( pos[1] );
vec.z = Ogre::Bitwise::halfToFloat( pos[2] );
requests[0].data += requests[0].vertexBuffer->getBytesPerElement();
vertices[i + subMeshOffset] = ( orient * ( vec * scale ) ) + position;
}
}
else if ( requests[0].type == Ogre::VET_FLOAT3 )
{
for ( size_t i = 0; i < subMeshVerticiesNum; ++i )
{
const float* pos = reinterpret_cast<const float*>( requests[0].data );
Ogre::Vector3 vec;
vec.x = *pos++;
vec.y = *pos++;
vec.z = *pos++;
requests[0].data += requests[0].vertexBuffer->getBytesPerElement();
vertices[i + subMeshOffset] = ( orient * ( vec * scale ) ) + position;
}
}
else
{
ENGINE_EXCEPT( "Unknown vertex buffer format" );
}
subMeshOffset += subMeshVerticiesNum;
vao->unmapAsyncTickets( requests );
////Read index data
if ( indexBuffer )
{
//.........这里部分代码省略.........