Ogre 获取实体顶点和索引

原创 2012年03月30日 16:57:00

bool added_shared = false;
 size_t current_offset = 0;
 size_t shared_offset = 0;
 size_t next_offset = 0;
 size_t index_offset = 0;
 size_t index_count = 0;
 size_t vertex_count = 0;

 MeshPtr ogreHeadMesh = polacub1->getMesh();
 for(unsigned short i = 0; i< ogreHeadMesh->getNumSubMeshes(); i++)
 {
  SubMesh * submesh = ogreHeadMesh->getSubMesh(i);
  if(submesh->useSharedVertices)
  {
   if(!added_shared)
   {
    vertex_count += ogreHeadMesh->sharedVertexData->vertexCount;
    added_shared = true;
   }
  }
  else
  {
   vertex_count += submesh->vertexData->vertexCount;
  }

  index_count += submesh->indexData->indexCount;
 }

Ogre::Vector3* vertices = new Vector3[vertex_count];
 long* indices = new long[index_count];

 for(unsigned short i = 0; i < ogreHeadMesh->getNumSubMeshes(); i++)
 {
  SubMesh* submesh = ogreHeadMesh->getSubMesh(i);
  VertexData* vertex_data = submesh->useSharedVertices ? ogreHeadMesh->sharedVertexData : submesh->vertexData;
  if((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared))
  {
   if(submesh->useSharedVertices)
   {
    added_shared = true;
    shared_offset = current_offset;
   }
   const VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
   Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
   unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

   float* pReal;
   for(size_t j = 0; j < vertex_data->vertexCount; j++,vertex += vbuf->getVertexSize())
   {
    posElem->baseVertexPointerToElement(vertex,&pReal);
    Vector3 pt(pReal[0],pReal[1],pReal[2]);

    vertices[current_offset+j] = (Quaternion::IDENTITY * (pt * Vector3::UNIT_SCALE)) + Vector3::ZERO;

   }
   vbuf->unlock();

   next_offset += vertex_data->vertexCount;
  }

  IndexData* index_data = submesh->indexData;
  size_t numTris = index_data->indexCount / 3;

  Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
  bool use32bitindexs = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
  unsigned long* pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
  unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);

  size_t offset = (submesh->useSharedVertices) ? shared_offset : current_offset;

  if(use32bitindexs)
  {
   for(size_t k = 0; k < numTris * 3; k++)
   {
    indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset);

   }
  }
  else

  {
   for(size_t k = 0; k < numTris * 3; k++)
   {
    indices[index_offset++] = static_cast<unsigned long>(pShort[k]) + static_cast<unsigned long>(offset);

   }
  }
  ibuf->unlock();
  current_offset = next_offset;

 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

ogre获取Mesh的顶点数组和索引数组

注意:下面getMeshInformation函数的代码应该来自网上的某一位前辈的,找不到出处了,望不要怪我 后面还有个函数做射线和网格的三角形相交测试,可以知道是否相交,也可以得到交点。 voi...
  • ldpxxx
  • ldpxxx
  • 2012-07-25 15:34
  • 1527

Ogre处理顶点/索引数据

原文摘自:http://blog.csdn.net/zhuxiaoyang2000/article/details/6565962 zhuxiaoyang2000的博客。 下面是我的应用: vo...

Ogre 处理顶点/索引数据

处理Maya、3D Max模型时,我们首先需要处理顶点/索引数据。这里分两步进行:(1)得到顶点/索引数据这里可以参考OGRE官网上的代码,需要注意的是官网上参数Mesh为指针类型,而今Mesh已经有...

Ogre中获取mesh顶点数据

void getMeshInfo(Entity* ent) { MeshPtr mesh = ent->getMesh(); bool added_shared = false; ...

OGRE在渲染通路中使用顶点程序和片断程序

3.1.9 在渲染通路中使用顶点程序和片断程序在材质脚本的pass段中,你可以引用.program脚本中定义的顶点程序和/或片断程序(详见3.1.4 顶点程序与片断程序的声明)。这些程序与使用他们的渲...

dx9模型顶点索引缓冲区

  • 2008-03-31 16:50
  • 16KB
  • 下载

Ogre中mesh共享顶点缓存的使用

http://sxoo0305.blog.163.com 这几天在弄这些。学了不少,把这两天的学习成果贴出来:               ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)