本文整理汇总了C++中ogre::HardwareIndexBufferSharedPtr类的典型用法代码示例。如果您正苦于以下问题:C++ HardwareIndexBufferSharedPtr类的具体用法?C++ HardwareIndexBufferSharedPtr怎么用?C++ HardwareIndexBufferSharedPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HardwareIndexBufferSharedPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddFromIndexData
void IndexBuffer::AddFromIndexData(Ogre::IndexData* indexData, const unsigned int offset)
{
// Get vertex count
const unsigned int addedCount = indexData->indexCount;
if(_reserved < _size + addedCount)
{
Reserve(_size + addedCount);
}
Ogre::HardwareIndexBufferSharedPtr hardwareBuffer = indexData->indexBuffer;
const bool use32bitindexes = (hardwareBuffer->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
if (use32bitindexes)
{
const unsigned int* curIndex = static_cast<unsigned int*>
(hardwareBuffer->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
for(unsigned int k = 0; k < addedCount; ++k)
{
_buffer.push_back(offset + (*curIndex++));
}
}
else
{
const unsigned short* curIndex = static_cast<unsigned short*>
(hardwareBuffer->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
for(unsigned int k = 0; k < addedCount; ++k)
{
_buffer.push_back(offset + static_cast<unsigned int>(*curIndex++));
}
}
_size = _buffer.size();
hardwareBuffer->unlock();
}
示例2: createFakeEntity
void ESKOgre::createFakeEntity(Ogre::SceneManager *mSceneMgr) {
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual(name + "_skeleton", XENOVIEWER_RESOURCE_GROUP);
msh->setSkeletonName(name);
Ogre::SubMesh* sub = msh->createSubMesh();
const size_t nVertices = 3;
const size_t nVertCount = 3;
const size_t vbufCount = nVertCount*nVertices;
float *vertices = (float *)malloc(sizeof(float)*vbufCount);
for (size_t i = 0; i < nVertices; i++) {
vertices[i*nVertCount] = 0.0;
vertices[i*nVertCount + 1] = 0.0;
vertices[i*nVertCount + 2] = 0.0;
}
const size_t ibufCount = 3;
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i < ibufCount; i++) {
faces[i] = i;
}
msh->sharedVertexData = new Ogre::VertexData();
msh->sharedVertexData->vertexCount = nVertices;
Ogre::VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offset, msh->sharedVertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
msh->_setBounds(Ogre::AxisAlignedBox(-100, -100, -100, 100, 100, 100));
msh->_setBoundingSphereRadius(100);
msh->load();
free(faces);
free(vertices);
skeleton_entity = mSceneMgr->createEntity(name + "_skeleton");
skeleton_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
skeleton_node->attachObject(skeleton_entity);
skeleton_node->setVisible(false);
}
示例3: processIndexData
void processIndexData(IndexData* indexData)
{
if (!mFlipVertexWinding)
{
// Nothing to do.
return;
}
if (indexData->indexCount % 3 != 0)
{
printf("Index number is not a multiple of 3, no vertex winding flipping possible. Skipped.");
return;
}
//print("Flipping index order for vertex winding flipping.", V_HIGH);
Ogre::HardwareIndexBufferSharedPtr buffer = indexData->indexBuffer;
unsigned char* data = static_cast<unsigned char*>(buffer->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
if(buffer->getType() == Ogre::HardwareIndexBuffer::IT_16BIT)
{
// 16 bit
//print("using 16bit indices", V_HIGH);
for (size_t i = 0; i < indexData->indexCount; i+=3)
{
Ogre::uint16 * i0 = (Ogre::uint16*)(data+0 * buffer->getIndexSize());
Ogre::uint16* i2 = (Ogre::uint16*)(data+2 * buffer->getIndexSize());
// flip
Ogre::uint16 tmp = *i0;
*i0 = *i2;
*i2 = tmp;
data += 3 * buffer->getIndexSize();
}
}
else
{
// 32 bit
//print("using 32bit indices", V_HIGH);
for (size_t i = 0; i < indexData->indexCount; i+=3)
{
Ogre::uint32* i0 = (Ogre::uint32*)(data+0 * buffer->getIndexSize());
Ogre::uint32* i2 = (Ogre::uint32*)(data+2 * buffer->getIndexSize());
// flip
Ogre::uint32 tmp = *i0;
*i0 = *i2;
*i2 = tmp;
data += 3 * buffer->getIndexSize();
}
}
buffer->unlock();
}
示例4:
Ogre::SubMesh *EMDOgre::createOgreSubmesh(EMDTriangles *triangles, Ogre::MeshPtr mesh) {
Ogre::SubMesh *sub = mesh->createSubMesh();
const size_t ibufCount = triangles->faces.size();
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i<ibufCount; i++) {
faces[i] = triangles->faces[i];
}
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
free(faces);
return sub;
}
示例5: addIndexData
//------------------------------------------------------------------------------------------------
void VertexIndexToShape::addIndexData(Ogre::IndexData *data, const unsigned int offset)
{
const unsigned int prev_size = mIndexCount;
mIndexCount += (unsigned int)data->indexCount;
unsigned int* tmp_ind = new unsigned int[mIndexCount];
if (mIndexBuffer)
{
memcpy (tmp_ind, mIndexBuffer, sizeof(unsigned int) * prev_size);
delete[] mIndexBuffer;
}
mIndexBuffer = tmp_ind;
const unsigned int numTris = (unsigned int) data->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = data->indexBuffer;
const bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
unsigned int index_offset = prev_size;
if (use32bitindexes)
{
const unsigned int* pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
for(unsigned int k = 0; k < numTris; ++k)
{
mIndexBuffer[index_offset ++] = offset + *pInt++;
mIndexBuffer[index_offset ++] = offset + *pInt++;
mIndexBuffer[index_offset ++] = offset + *pInt++;
}
ibuf->unlock();
}
else
{
const unsigned short* pShort = static_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
for(unsigned int k = 0; k < numTris; ++k)
{
mIndexBuffer[index_offset ++] = offset + static_cast<unsigned int> (*pShort++);
mIndexBuffer[index_offset ++] = offset + static_cast<unsigned int> (*pShort++);
mIndexBuffer[index_offset ++] = offset + static_cast<unsigned int> (*pShort++);
}
ibuf->unlock();
}
}
示例6: createVertexDataForVertexShaderOnly
void GPUBillboardSet::createVertexDataForVertexShaderOnly(const std::vector<PhotoSynth::Vertex>& vertices)
{
// Setup render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.vertexData = OGRE_NEW Ogre::VertexData();
mRenderOp.vertexData->vertexCount = vertices.size() * 4;
mRenderOp.vertexData->vertexStart = 0;
mRenderOp.useIndexes = true;
mRenderOp.indexData = OGRE_NEW Ogre::IndexData();
mRenderOp.indexData->indexCount = vertices.size() * 6;
mRenderOp.indexData->indexStart = 0;
// Vertex format declaration
unsigned short sourceBufferIdx = 0;
Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
size_t currOffset = 0;
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
decl->addElement(sourceBufferIdx, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
// Create vertex buffer
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize(sourceBufferIdx),
mRenderOp.vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Bind vertex buffer
Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
bind->setBinding(sourceBufferIdx, vbuf);
// Fill vertex buffer (see http://www.ogre3d.org/docs/manual/manual_59.html#SEC287)
Ogre::RenderSystem* renderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem();
unsigned char* pVert = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::Real* pReal;
Ogre::RGBA* pRGBA;
Ogre::VertexDeclaration::VertexElementList elems = decl->findElementsBySource(sourceBufferIdx);
Ogre::VertexDeclaration::VertexElementList::iterator itr;
const Ogre::Vector2 uvs[4] = { Ogre::Vector2( -1.f, 1.f ),
Ogre::Vector2( -1.f, -1.f ),
Ogre::Vector2( 1.f, -1.f ),
Ogre::Vector2( 1.f, 1.f ) };
for (unsigned int i=0; i<vertices.size(); ++i )
{
const PhotoSynth::Vertex& vertex = vertices[i];
for ( unsigned int j=0; j<4; j++ )
{
for (itr=elems.begin(); itr!=elems.end(); ++itr)
{
Ogre::VertexElement& elem = *itr;
if (elem.getSemantic() == Ogre::VES_POSITION)
{
elem.baseVertexPointerToElement(pVert, &pReal);
*pReal = vertex.position.x; *pReal++;
*pReal = vertex.position.y; *pReal++;
*pReal = vertex.position.z; *pReal++;
}
else if (elem.getSemantic() == Ogre::VES_DIFFUSE)
{
elem.baseVertexPointerToElement(pVert, &pRGBA);
renderSystem->convertColourValue(vertex.color, pRGBA);
}
else if (elem.getSemantic() == Ogre::VES_TEXTURE_COORDINATES && elem.getIndex() == 0)
{
elem.baseVertexPointerToElement(pVert, &pReal);
*pReal = uvs[j].x; *pReal++;
*pReal = uvs[j].y; *pReal++;
}
}
// Go to next vertex
pVert += vbuf->getVertexSize();
}
}
vbuf->unlock();
// Create index buffer
if (mRenderOp.indexData->indexCount>=65536)
{
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
mRenderOp.indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
mRenderOp.indexData->indexBuffer = ibuf;
Ogre::uint32* indices = static_cast<Ogre::uint32*>(ibuf->lock( Ogre::HardwareBuffer::HBL_DISCARD));
Ogre::uint32 indexFirstVertex = 0;
const Ogre::uint32 inds[6] = { 0, 1, 2, 3, 0, 2 };
for (unsigned int i=0; i<vertices.size(); ++i)
{
for (unsigned int j=0; j<6; ++j)
{
*indices = indexFirstVertex + inds[j];
indices++;
}
indexFirstVertex +=4;
}
//.........这里部分代码省略.........
示例7: allocateBuffers
bool ShaderParticleRenderer::allocateBuffers(size_t iNumParticles)
{
// prepare vertex declaration
if (mVertexData->vertexDeclaration->getElementCount() == 0) {
VertexDeclaration* pDecl = mVertexData->vertexDeclaration;
size_t ofs = 0;
ofs += pDecl->addElement(0, ofs, VET_FLOAT4, VES_POSITION).getSize(); // position
if (mVertexFormatColour)
ofs += pDecl->addElement(0, ofs, VET_FLOAT4, VES_DIFFUSE).getSize(); // diffuse colour
// other data are stored in vertex as texture coordinates
ushort ix = 0;
if (mVertexFormatTexture)
ofs += pDecl->addElement(0, ofs, VET_FLOAT2, VES_TEXTURE_COORDINATES, ix++).getSize(); // general texture coord
if (mVertexFormatSize)
ofs += pDecl->addElement(0, ofs, VET_FLOAT2, VES_TEXTURE_COORDINATES, ix++).getSize(); // particle size
if (mVertexFormatRotation || mVertexFormatRotationSpeed) {
if (mVertexFormatRotation && mVertexFormatRotationSpeed)
ofs += pDecl->addElement(0, ofs, VET_FLOAT2, VES_TEXTURE_COORDINATES, ix++).getSize(); // current rotation and rotation speed
else
ofs += pDecl->addElement(0, ofs, VET_FLOAT1, VES_TEXTURE_COORDINATES, ix++).getSize(); // current rotation or rotation speed
}
if (mVertexFormatDirection)
ofs += pDecl->addElement(0, ofs, VET_FLOAT3, VES_TEXTURE_COORDINATES, ix++).getSize(); // particle direction (as speed)
// add packed times
size_t iNumTimes = 0;
if (mVertexFormatTTL) iNumTimes++;
if (mVertexFormatTotalTTL) iNumTimes++;
if (mVertexFormatTimeFragment) iNumTimes++;
if (mVertexFormatTimeFragmentInv) iNumTimes++;
switch(iNumTimes) {
case 1:
ofs += pDecl->addElement(0, ofs, VET_FLOAT1, VES_TEXTURE_COORDINATES, ix++).getSize();
break;
case 2:
ofs += pDecl->addElement(0, ofs, VET_FLOAT2, VES_TEXTURE_COORDINATES, ix++).getSize();
break;
case 3:
ofs += pDecl->addElement(0, ofs, VET_FLOAT3, VES_TEXTURE_COORDINATES, ix++).getSize();
break;
case 4:
ofs += pDecl->addElement(0, ofs, VET_FLOAT4, VES_TEXTURE_COORDINATES, ix++).getSize();
break;
}
// add custom parameters
ofs += pDecl->addElement(0, ofs, VET_FLOAT4, VES_TEXTURE_COORDINATES, ix++).getSize();
assert(ix <= 8);
// cache vertex size
mVertexSize = pDecl->getVertexSize(0);
}
Ogre::HardwareVertexBufferSharedPtr pVB;
if (mVertexData->vertexBufferBinding->isBufferBound(0))
pVB = mVertexData->vertexBufferBinding->getBuffer(0);
// prepare vertex buffer
if (pVB.isNull() || pVB->getNumVertices() < iNumParticles * 4) {
assert(iNumParticles * 4 < 65536); // we are using 16bit index buffer
pVB = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(mVertexSize, 4 * iNumParticles, Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
if (pVB.isNull())
return false;
mVertexData->vertexBufferBinding->setBinding(0, pVB);
}
// prepare index buffer
Ogre::HardwareIndexBufferSharedPtr pIB = mIndexData->indexBuffer;
if (pIB.isNull() || pIB->getNumIndexes() < iNumParticles * 6) {
pIB = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, iNumParticles * 6, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
if (pIB.isNull())
return false;
mIndexData->indexBuffer = pIB;
// fill
Ogre::uint16* pDataIB = reinterpret_cast<Ogre::uint16*>(pIB->lock(Ogre::HardwareBuffer::HBL_NORMAL));
for (Ogre::uint16 k=0; k<static_cast<Ogre::uint16>(iNumParticles); ++k) {
pDataIB[0] = k*4 + 0;
pDataIB[1] = k*4 + 1;
pDataIB[2] = k*4 + 2;
pDataIB[3] = k*4 + 0;
pDataIB[4] = k*4 + 2;
pDataIB[5] = k*4 + 3;
pDataIB += 6;
}
pIB->unlock();
}
return true;
}
示例8: FindClosestPolygon
void Renderer::FindClosestPolygon(Ogre::Entity* entity, float& closestDistance,
Ogre::Vector3& position, Ogre::Vector3& normal)
{
closestDistance = std::numeric_limits<float>::max(); // default value (means
// nothing detected)
// Get transformation
Ogre::SceneNode* parentNode = entity->getParentSceneNode();
Ogre::Vector3 parentPos;
Ogre::Quaternion parentOrientation;
Ogre::Vector3 parentScale;
if (parentNode)
{
parentPos = parentNode->_getDerivedPosition();
parentOrientation = parentNode->_getDerivedOrientation();
parentScale = parentNode->_getDerivedScale();
}
else
{
parentPos = Ogre::Vector3::ZERO;
parentOrientation = Ogre::Quaternion::IDENTITY;
parentScale = Ogre::Vector3::UNIT_SCALE;
}
// Handle animated entities
bool isAnimated = entity->hasSkeleton();
if (isAnimated)
{
entity->addSoftwareAnimationRequest(false);
entity->_updateAnimation();
}
// Loop through each submesh
Ogre::MeshPtr mesh = entity->getMesh();
for (uint i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* subMesh = mesh->getSubMesh(i);
// Ignore anything that isn't a triangle List
if (subMesh->operationType != Ogre::RenderOperation::OT_TRIANGLE_LIST)
continue;
// Get the vertex data
Ogre::VertexData* vertexData;
if (subMesh->useSharedVertices)
{
if (isAnimated)
vertexData = entity->_getSkelAnimVertexData();
else
vertexData = mesh->sharedVertexData;
}
else
{
if (isAnimated)
vertexData = entity->getSubEntity(i)->_getSkelAnimVertexData();
else
vertexData = subMesh->vertexData;
}
// Get the size of one vertex
const Ogre::VertexElement* posEl =
vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vBuff =
vertexData->vertexBufferBinding->getBuffer(posEl->getSource());
uint vertexSize = vBuff->getVertexSize();
// Save pointer to first vertex
short* pVertex = (short*)vBuff->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
short* pStartVertex = pVertex;
// Get the index buffer
// If it is null then skip as it must be a point cloud
Ogre::HardwareIndexBufferSharedPtr iBuff = subMesh->indexData->indexBuffer;
if (iBuff.isNull())
continue;
uint* pLong = (uint*)iBuff->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
uint16_t* pShort = (uint16_t*)pLong;
// Look through each vertex and check each triangle with the ray
Ogre::Vector3 vertexPos;
Ogre::Vector3 vertex1;
Ogre::Vector3 vertex2;
float* pReal;
uint index;
for (uint k = 0; k < subMesh->indexData->indexCount; k++)
{
// Read index value
if (iBuff->getType() == Ogre::HardwareIndexBuffer::IT_32BIT) // if 32bit indexes
{
index = (uint)pLong[k];
}
else
{
index = (uint)pShort[k];
}
// Read referenced vertex
pVertex = pStartVertex + (vertexSize * index); // calculate pointer
//.........这里部分代码省略.........
示例9: GetMeshInformation
// Get the mesh information for the given mesh.
// Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
void CollisionTools::GetMeshInformation(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)
{
bool added_shared = false;
size_t current_offset = 0;
size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 0;
vertex_count = index_count = 0;
// Calculate how many vertices and indices we're going to need
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh( i );
// We only need to add the shared vertices once
if(submesh->useSharedVertices)
{
if( !added_shared )
{
vertex_count += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else
{
vertex_count += submesh->vertexData->vertexCount;
}
// Add the indices
index_count += submesh->indexData->indexCount;
}
// Allocate space for the vertices and indices
vertices = new Ogre::Vector3[vertex_count];
indices = new Ogre::uint32[index_count];
added_shared = false;
// Run through the submeshes again, adding the data into the arrays
for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
{
if(submesh->useSharedVertices)
{
added_shared = true;
shared_offset = current_offset;
}
const Ogre::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));
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Ogre::Real* pOgre::Real;
float* pReal;
for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
vertices[current_offset + j] = (orient * (pt * scale)) + position;
}
vbuf->unlock();
next_offset += vertex_data->vertexCount;
}
Ogre::IndexData* index_data = submesh->indexData;
size_t numTris = index_data->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
Ogre::uint32* pLong = static_cast<Ogre::uint32*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
//.........这里部分代码省略.........
示例10: createSubMesh
//.........这里部分代码省略.........
Ogre::Matrix4 mat4 = shape->getWorldTransform();
for(size_t i = 0;i < srcVerts.size();i++)
{
Ogre::Vector4 vec4(srcVerts[i].x, srcVerts[i].y, srcVerts[i].z, 1.0f);
vec4 = mat4*vec4;
srcVerts[i] = Ogre::Vector3(&vec4[0]);
}
for(size_t i = 0;i < srcNorms.size();i++)
{
Ogre::Vector4 vec4(srcNorms[i].x, srcNorms[i].y, srcNorms[i].z, 0.0f);
vec4 = mat4*vec4;
srcNorms[i] = Ogre::Vector3(&vec4[0]);
}
}
}
// Set the bounding box first
BoundsFinder bounds;
bounds.add(&srcVerts[0][0], srcVerts.size());
if(!bounds.isValid())
{
float v[3] = { 0.0f, 0.0f, 0.0f };
bounds.add(&v[0], 1);
}
mesh->_setBounds(Ogre::AxisAlignedBox(bounds.minX()-0.5f, bounds.minY()-0.5f, bounds.minZ()-0.5f,
bounds.maxX()+0.5f, bounds.maxY()+0.5f, bounds.maxZ()+0.5f));
mesh->_setBoundingSphereRadius(bounds.getRadius());
// This function is just one long stream of Ogre-barf, but it works
// great.
Ogre::HardwareBufferManager *hwBufMgr = Ogre::HardwareBufferManager::getSingletonPtr();
Ogre::HardwareVertexBufferSharedPtr vbuf;
Ogre::HardwareIndexBufferSharedPtr ibuf;
Ogre::VertexBufferBinding *bind;
Ogre::VertexDeclaration *decl;
int nextBuf = 0;
Ogre::SubMesh *sub = mesh->createSubMesh();
// Add vertices
sub->useSharedVertices = false;
sub->vertexData = new Ogre::VertexData();
sub->vertexData->vertexStart = 0;
sub->vertexData->vertexCount = srcVerts.size();
decl = sub->vertexData->vertexDeclaration;
bind = sub->vertexData->vertexBufferBinding;
if(srcVerts.size())
{
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3),
srcVerts.size(), vertUsage, vertShadowBuffer);
vbuf->writeData(0, vbuf->getSizeInBytes(), &srcVerts[0][0], true);
decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
bind->setBinding(nextBuf++, vbuf);
}
// Vertex normals
if(srcNorms.size())
{
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3),
srcNorms.size(), vertUsage, vertShadowBuffer);
vbuf->writeData(0, vbuf->getSizeInBytes(), &srcNorms[0][0], true);
decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
示例11: GetMeshInformation
void Utils::GetMeshInformation(
const Ogre::MeshPtr mesh,
size_t &vertexCount,
Ogre::Vector3* &vertices,
size_t &indexCount,
unsigned* &indices)
{
bool addShared = false;
size_t currentOffset = 0;
size_t shared_offset = 0;
size_t nextOffset = 0;
size_t indexOffset = 0;
vertexCount = indexCount = 0;
for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
if(submesh->useSharedVertices) {
if( !addShared ) {
vertexCount += mesh->sharedVertexData->vertexCount;
addShared = true;
}
}
else {
vertexCount += submesh->vertexData->vertexCount;
}
indexCount += submesh->indexData->indexCount;
}
vertices = new Ogre::Vector3[vertexCount];
indices = new unsigned[indexCount];
addShared = false;
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::VertexData* vertexData = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !addShared)) {
if(submesh->useSharedVertices) {
addShared = true;
shared_offset = currentOffset;
}
const Ogre::VertexElement* posElem =
vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf =
vertexData->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 < vertexData->vertexCount; ++j, vertex += vbuf->getVertexSize()) {
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
vertices[currentOffset + j] = pt;
}
vbuf->unlock();
nextOffset += vertexData->vertexCount;
}
Ogre::IndexData* indexData = submesh->indexData;
size_t numTris = indexData->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = indexData->indexBuffer;
bool use32bitindexes = (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 : currentOffset;
if ( use32bitindexes ) {
for ( size_t k = 0; k < numTris*3; ++k) {
indices[indexOffset++] = pLong[k] + static_cast<unsigned long>(offset);
}
}
else {
for ( size_t k = 0; k < numTris*3; ++k) {
indices[indexOffset++] = static_cast<unsigned long>(pShort[k]) +
static_cast<unsigned long>(offset);
}
}
ibuf->unlock();
currentOffset = nextOffset;
}
}
示例12: TOSTRING
//.........这里部分代码省略.........
size_t offset = 0;
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);
// Create and bind vertex buffer
mesh->sharedVertexData->vertexCount = 14;
Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
mesh->sharedVertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
// Vertex data
static const float vertexData[] = {
// Position Texture coordinates // Index
0.0, 2.0, -1.0, 1.0, 1.0, // 0
0.0, 1.0, -1.0, -1.0, 1.0, // 1
1.0, 2.0, -1.0, 1.0, -1.0, // 2
1.0, 1.0, -1.0, -1.0, -1.0, // 3
2.0, 2.0, 1.0, 1.0, -1.0, // 4
2.0, 1.0, 1.0, -1.0, -1.0, // 5
3.0, 2.0, 1.0, 1.0, 1.0, // 6
3.0, 1.0, 1.0, -1.0, 1.0, // 7
4.0, 2.0, -1.0, 1.0, 1.0, // 8
4.0, 1.0, -1.0, -1.0, 1.0, // 9
1.0, 3.0, -1.0, 1.0, 1.0, // 10
2.0, 3.0, 1.0, 1.0, 1.0, // 11
1.0, 0.0, -1.0, -1.0, 1.0, // 12
2.0, 0.0, 1.0, -1.0, 1.0, // 13
};
// Fill vertex buffer
float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
{
// Position
*pData++ = position.x + scale * vertexData[i++];
*pData++ = position.y + scale * vertexData[i++];
*pData++ = 0.0;
// Texture coordinates
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
}
vertexBuffer->unlock();
// Create index buffer
sub->indexData->indexCount = 36;
Ogre::HardwareIndexBufferSharedPtr indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
sub->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
sub->indexData->indexBuffer = indexBuffer;
// Index data
static const Ogre::uint16 indexData[] = {
// Indices // Face
0, 1, 2, // 0
2, 1, 3, // 1
2, 3, 4, // 2
4, 3, 5, // 3
4, 5, 6, // 4
6, 5, 7, // 5
6, 7, 8, // 6
8, 7, 9, // 7
10, 2, 11, // 8
11, 2, 4, // 9
3, 12, 5, // 10
5, 12, 13, // 11
};
// Fill index buffer
indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData, true);
mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE);
mesh->_setBoundingSphereRadius(10);
mesh->load();
Ogre::Entity* e = gEnv->sceneManager->createEntity(mesh->getName());
e->setCastShadows(false);
e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
e->setVisible(true);
e->setMaterialName("tracks/EnvMapDebug");
Ogre::SceneNode* mDebugSceneNode = new Ogre::SceneNode(gEnv->sceneManager);
mDebugSceneNode->attachObject(e);
mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5));
mDebugSceneNode->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
mDebugSceneNode->setVisible(true);
mDebugSceneNode->_update(true, true);
mDebugSceneNode->_updateBounds();
overlay->add3D(mDebugSceneNode);
overlay->show();
}
}
}
示例13: destoryGeometry
void
TerrainTileEditable::createGeometry(TerrainData* data, int xbase, int zbase, int xsize, int zsize)
{
destoryGeometry();
// build the material backet map
MaterialBucketMap materialBucketMap;
buildMaterialBucketMap(materialBucketMap);
// Build renderables
for (MaterialBucketMap::const_iterator im = materialBucketMap.begin(); im != materialBucketMap.end(); ++im)
{
const MaterialBucket* mb = &im->second;
TerrainTileEditableRenderable* renderable = new TerrainTileEditableRenderable(this, mb->layerIndex);
mRenderables.push_back(renderable);
size_t numQuads = mb->grids.size();
size_t indexCount = numQuads * 6;
renderable->mMaterial = mb->material;
Ogre::HardwareIndexBufferSharedPtr indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
Ogre::IndexData* indexData = new Ogre::IndexData;
indexData->indexBuffer = indexBuffer;
indexData->indexStart = 0;
indexData->indexCount = indexCount;
renderable->mRenderOp.indexData = indexData;
renderable->mRenderOp.vertexData = mVertexDatas[mb->layerIndex];
renderable->mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
renderable->mRenderOp.useIndexes = true;
ushort* pIndices = static_cast<ushort*>(indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (GridIdList::const_iterator igrid = mb->grids.begin(); igrid != mb->grids.end(); ++igrid)
{
size_t grid = *igrid;
const TerrainData::GridInfo& gridInfo = data->mGridInfos[grid];
const TerrainData::Corner* corners = gridInfo.getCorners();
int x = grid % data->mXSize - xbase;
int z = grid / data->mXSize - zbase;
assert(x < xsize && z < zsize);
size_t index = (z*xsize + x) * 4;
*pIndices++ = index + corners[1];
*pIndices++ = index + corners[0];
*pIndices++ = index + corners[2];
*pIndices++ = index + corners[1];
*pIndices++ = index + corners[2];
*pIndices++ = index + corners[3];
}
indexBuffer->unlock();
}
for (size_t layerIndex = 0; layerIndex < 2; ++layerIndex)
{
fillLayerBuffer(layerIndex, mVertexDatas.back()->vertexBufferBinding->getBuffer(layerIndex+1));
}
mGeometryOutOfDate = false;
}
示例14: generateSphericDome
void GeometryFactory::generateSphericDome (const Ogre::String &name, int segments, DomeType type) {
// Return now if already exists
if (Ogre::MeshManager::getSingleton ().resourceExists (name)) {
return;
}
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: Creating " + name + " sphere mesh resource...");
// Use the mesh manager to create the mesh
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton ().createManual (name, RESOURCE_GROUP_NAME);
// Create a submesh
Ogre::SubMesh *sub = msh->createSubMesh ();
// Create the shared vertex data
Ogre::VertexData *vertexData = new Ogre::VertexData ();
msh->sharedVertexData = vertexData;
// Define the vertices' format
Ogre::VertexDeclaration *vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// Position
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Normal
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Texture coordinates
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT2);
// Allocate the vertex buffer
switch (type) {
case DT_GRADIENTS:
vertexData->vertexCount = segments * (segments - 1) + 2;
break;
case DT_STARFIELD:
vertexData->vertexCount = (segments + 1) * (segments + 1);
break;
};
Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton ().createVertexBuffer (vertexDecl->getVertexSize (0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::VertexBufferBinding *binding = vertexData->vertexBufferBinding;
binding->setBinding (0, vBuf);
float *pVertex = static_cast<float *>(vBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Allocate the index buffer
switch (type) {
case DT_GRADIENTS:
sub->indexData->indexCount = 2 * segments * (segments - 1) * 3;
break;
case DT_STARFIELD:
sub->indexData->indexCount = 2 * (segments - 1) * segments * 3;
break;
};
sub->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton ().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_16BIT, sub->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::HardwareIndexBufferSharedPtr iBuf = sub->indexData->indexBuffer;
unsigned short *pIndices = static_cast<unsigned short *>(iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Fill the buffers
switch (type) {
case DT_GRADIENTS:
fillGradientsDomeBuffers (pVertex, pIndices, segments);
break;
case DT_STARFIELD:
fillStarfieldDomeBuffers (pVertex, pIndices, segments);
break;
};
// Close the vertex buffer
vBuf->unlock ();
// Close the index buffer
iBuf->unlock ();
// Finishing it...
sub->useSharedVertices = true;
msh->_setBounds (Ogre::AxisAlignedBox (-1, -1, -1, 1, 1, 1), false);
msh->_setBoundingSphereRadius (1);
msh->load ();
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: generateSphericDome DONE");
}
示例15: GrassParticleField
GrassPatch::GrassPatch(int nb_blades, int nb_blade_segments, float width, float height, Ogre::SceneManager* ScnMgr)
{
int i, nb_particles;
// Create the particle field
nb_particles = nb_blades * (nb_blade_segments + 1);
m_Particles = new GrassParticleField(nb_particles, 1);
// Allocate the blade list
m_Blades = new Blade *[nb_blades];
m_NbBlades = nb_blades;
Ogre::Radian *angle = new Ogre::Radian(Ogre::Math::PI * ((rand()%1000) / 1000.0f));
// Create the blades of grass
for (i = 0; i < nb_blades; i++)
{
m_Blades[i] = new Blade(m_Particles,
i * (nb_blade_segments + 1),
nb_blade_segments,
4 + ((rand()%1000) / 1000.0f)*0.5f,
0.3f + ((rand()%1000) / 1000.0f)*0.1f,
width / 2 - ((rand()%1000) / 500.0f) * width,
height / 2 - ((rand()%1000) / 500.0f) * height,
*angle);
m_Blades[i]->moving = true;
m_Blades[i]->timeout = 0;
}
m_VertexCount = nb_blades * m_Blades[0]->GetStrippedVertexCount();
m_TriangleCount = ((nb_blade_segments - 1) << 1) + 1;
mvertexData = new Ogre::VertexData ();
// Vertex declaration
Ogre::VertexDeclaration* decl = mvertexData->vertexDeclaration;
Ogre::VertexBufferBinding* binding = mvertexData->vertexBufferBinding;
size_t offset = 0;
//position
decl->addElement (POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// normal here
decl->addElement(POSITION_BINDING, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// Diffuse Color
decl->addElement(POSITION_BINDING, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
// texture here
decl->addElement(POSITION_BINDING, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
//position updated each frame
Ogre::HardwareVertexBufferSharedPtr vbuf1 =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer (offset, // size of one whole vertex
m_VertexCount, // number of vertices
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, // usage
false); // no shadow buffer
binding->setBinding(POSITION_BINDING, vbuf1);
Ogre::HardwareVertexBufferSharedPtr vVertices = binding->getBuffer(POSITION_BINDING);
Ogre::Real *pVertices = static_cast<Ogre::Real*>( vVertices->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
// Colour up the blades
for (i = 0; i < m_NbBlades; i++)
m_Blades[i]->Paint (i, pVertices);
vVertices->unlock();
// Index buffer to handle triangle strip vertex buffer as triangle list
// Create index buffer
int nIndexes = m_TriangleCount*3*m_NbBlades;
Ogre::HardwareIndexBufferSharedPtr iBuf =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_32BIT,
nIndexes,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY,
false);
// Fill index buffer
unsigned int* pIdx = static_cast<unsigned int*> (iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
unsigned int j = 0;
for (i = 0; i < m_NbBlades; i++)
m_Blades[i]->UpdateIndexBuffer(&j, i, pIdx);
iBuf->unlock ();
mRenderOp.vertexData = mvertexData;
// mRenderOp.vertexData->vertexCount = m_VertexCount;
mRenderOp.vertexData->vertexCount= nIndexes;
mRenderOp.vertexData->vertexStart = 0;
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
//.........这里部分代码省略.........