本文整理汇总了C++中ogre::HardwareIndexBufferSharedPtr::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwareIndexBufferSharedPtr::getType方法的具体用法?C++ HardwareIndexBufferSharedPtr::getType怎么用?C++ HardwareIndexBufferSharedPtr::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::HardwareIndexBufferSharedPtr
的用法示例。
在下文中一共展示了HardwareIndexBufferSharedPtr::getType方法的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: 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();
}
示例3: 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();
}
}
示例4: pt
//.........这里部分代码省略.........
{
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);
//----------------------------------------------------------------
// GET VERTEXDATA
//----------------------------------------------------------------
Ogre::VertexData* vertex_data;
//When there is animation:
if(useSoftwareBlendingVertices)
vertex_data = submesh->useSharedVertices ? entity->_getSkelAnimVertexData() : entity->getSubEntity(i)->_getSkelAnimVertexData();
else
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::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Real* pReal;
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);
void* hwBuf = ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;
size_t index_start = index_data->indexStart;
size_t last_index = numTris*3 + index_start;
if (use32bitindexes) {
Ogre::uint32* hwBuf32 = static_cast<Ogre::uint32*>(hwBuf);
for (size_t k = index_start; k < last_index; ++k)
{
indices[index_offset++] = hwBuf32[k] + static_cast<Ogre::uint32>( offset );
}
} else {
Ogre::uint16* hwBuf16 = static_cast<Ogre::uint16*>(hwBuf);
for (size_t k = index_start; k < last_index; ++k)
{
indices[ index_offset++ ] = static_cast<Ogre::uint32>( hwBuf16[k] ) +
static_cast<Ogre::uint32>( offset );
}
}
ibuf->unlock();
current_offset = next_offset;
}
}
示例5: 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));
//.........这里部分代码省略.........
示例6: GetMeshInformation
void OgreMeshRay::GetMeshInformation(const Ogre::ManualObject* manual,
size_t& vertex_count, Ogre::Vector3*& vertices, size_t& index_count,
unsigned long*& indices, const Ogre::Vector3& position,
const Ogre::Quaternion& orient, const Ogre::Vector3& scale) {
std::vector<Ogre::Vector3> returnVertices;
std::vector<unsigned long> returnIndices;
unsigned long thisSectionStart = 0;
for (unsigned int i = 0, size = manual->getNumSections(); i < size; ++i) {
Ogre::ManualObject::ManualObjectSection* section = manual->getSection(
i);
Ogre::RenderOperation* renderOp = section->getRenderOperation();
std::vector<Ogre::Vector3> pushVertices;
//Collect the vertices
{
const Ogre::VertexElement* vertexElement =
renderOp->vertexData->vertexDeclaration->findElementBySemantic(
Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
renderOp->vertexData->vertexBufferBinding->getBuffer(
vertexElement->getSource());
char* verticesBuffer = static_cast<char*>(vertexBuffer->lock(
Ogre::HardwareBuffer::HBL_READ_ONLY));
float* positionArrayHolder;
thisSectionStart = returnVertices.size() + pushVertices.size();
pushVertices.reserve(renderOp->vertexData->vertexCount);
for (unsigned int j = 0; j < renderOp->vertexData->vertexCount;
++j) {
vertexElement->baseVertexPointerToElement(
verticesBuffer + j * vertexBuffer->getVertexSize(),
&positionArrayHolder);
Ogre::Vector3 vertexPos = Ogre::Vector3(positionArrayHolder[0],
positionArrayHolder[1], positionArrayHolder[2]);
vertexPos = (orient * (vertexPos * scale)) + position;
pushVertices.push_back(vertexPos);
}
vertexBuffer->unlock();
}
//Collect the indices
{
if (renderOp->useIndexes) {
Ogre::HardwareIndexBufferSharedPtr indexBuffer =
renderOp->indexData->indexBuffer;
if (indexBuffer.isNull()
|| renderOp->operationType
!= Ogre::RenderOperation::OT_TRIANGLE_LIST) {
//No triangles here, so we just drop the collected vertices and move along to the next section.
continue;
} else {
returnVertices.reserve(
returnVertices.size() + pushVertices.size());
returnVertices.insert(returnVertices.end(),
pushVertices.begin(), pushVertices.end());
}
unsigned int* pLong =
static_cast<unsigned int*>(indexBuffer->lock(
Ogre::HardwareBuffer::HBL_READ_ONLY));
unsigned short* pShort =
reinterpret_cast<unsigned short*>(pLong);
returnIndices.reserve(
returnIndices.size() + renderOp->indexData->indexCount);
for (size_t j = 0; j < renderOp->indexData->indexCount; ++j) {
unsigned long index;
//We also have got to remember that for a multi section object, each section has
//different vertices, so the indices will not be correct. To correct this, we
//have to add the position of the first vertex in this section to the index
//(At least I think so...)
if (indexBuffer->getType()
== Ogre::HardwareIndexBuffer::IT_32BIT)
index = static_cast<unsigned long>(pLong[j])
+ thisSectionStart;
else
index = static_cast<unsigned long>(pShort[j])
+ thisSectionStart;
returnIndices.push_back(index);
}
indexBuffer->unlock();
}
}
}
//Now we simply return the data.
index_count = returnIndices.size();
vertex_count = returnVertices.size();
vertices = new Ogre::Vector3[vertex_count];
for (unsigned long i = 0; i < vertex_count; ++i)
vertices[i] = returnVertices[i];
indices = new unsigned long[index_count];
//.........这里部分代码省略.........
示例7: 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;
}
}
示例8: CreateKdTree
void OgreMeshAsset::CreateKdTree()
{
meshData.Clear();
normals.clear();
uvs.clear();
subMeshTriangleCounts.clear();
for(unsigned short i = 0; i < ogreMesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh *submesh = ogreMesh->getSubMesh(i);
assert(submesh);
Ogre::VertexData *vertexData = submesh->useSharedVertices ? ogreMesh->sharedVertexData : submesh->vertexData;
assert(vertexData);
const Ogre::VertexElement *posElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
if (!posElem)
{
subMeshTriangleCounts.push_back(0);
continue; // No position element. Ignore this submesh.
}
Ogre::HardwareVertexBufferSharedPtr vbufPos = vertexData->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char *pos = (unsigned char*)vbufPos->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
assert(pos);
size_t posOffset = posElem->getOffset();
size_t posSize = vbufPos->getVertexSize();
// Texcoord element is not mandatory
unsigned char *texCoord = 0;
size_t texOffset = 0;
size_t texSize = 0;
Ogre::HardwareVertexBufferSharedPtr vbufTex;
const Ogre::VertexElement *texElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);
if (texElem)
{
vbufTex = vertexData->vertexBufferBinding->getBuffer(texElem->getSource());
// Check if the texcoord buffer is different than the position buffer, in that case lock it separately
if (vbufTex != vbufPos)
texCoord = static_cast<unsigned char*>(vbufTex->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
else
texCoord = pos;
texOffset = texElem->getOffset();
texSize = vbufTex->getVertexSize();
}
Ogre::IndexData *indexData = submesh->indexData;
Ogre::HardwareIndexBufferSharedPtr ibuf = indexData->indexBuffer;
u32 *pLong = (u32*)ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY);
u16 *pShort = (u16*)pLong;
const bool use32BitIndices = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
for(unsigned j = 0; j+2 < indexData->indexCount; j += 3)
{
unsigned i0, i1, i2;
if (use32BitIndices)
{
i0 = pLong[j];
i1 = pLong[j+1];
i2 = pLong[j+2];
}
else
{
i0 = pShort[j];
i1 = pShort[j+1];
i2 = pShort[j+2];
}
float3 v0 = *(float3*)(pos + posOffset + i0 * posSize);
float3 v1 = *(float3*)(pos + posOffset + i1 * posSize);
float3 v2 = *(float3*)(pos + posOffset + i2 * posSize);
Triangle t(v0, v1, v2);
meshData.AddObjects(&t, 1);
if (texElem)
{
uvs.push_back(*((float2*)(texCoord + texOffset + i0 * texSize)));
uvs.push_back(*((float2*)(texCoord + texOffset + i1 * texSize)));
uvs.push_back(*((float2*)(texCoord + texOffset + i2 * texSize)));
}
float3 edge1 = v1 - v0;
float3 edge2 = v2 - v0;
float3 normal = edge1.Cross(edge2);
normal.Normalize();
normals.push_back(normal);
}
subMeshTriangleCounts.push_back((int)(indexData->indexCount / 3));
vbufPos->unlock();
if (!vbufTex.isNull() && vbufTex != vbufPos)
vbufTex->unlock();
ibuf->unlock();
}
{
PROFILE(OgreMeshAsset_KdTree_Build);
meshData.Build();
}
//.........这里部分代码省略.........
示例9: getMeshInformation
void PhysicsManager::getMeshInformation(Ogre::MeshPtr mesh,size_t &vertex_count,Vector3* &vertices, size_t &index_count, unsigned* &indices, const Ogre::Vector3 &position, const Ogre::Quaternion &orient,const Ogre::Vector3 &scale)
{
vertex_count = index_count = 0;
bool added_shared = false;
size_t current_offset = vertex_count;
size_t shared_offset = vertex_count;
size_t next_offset = vertex_count;
size_t index_offset = index_count;
size_t prev_vert = vertex_count;
size_t prev_ind = index_count;
// Calculate how many vertices and indices we're going to need
for(int i = 0;i < mesh->getNumSubMeshes();i++)
{
SubMesh* submesh = mesh->getSubMesh(i);
// We only need to add the shared vertices once
if(submesh->useSharedVertices)
{
if(!added_shared)
{
VertexData* vertex_data = mesh->sharedVertexData;
vertex_count += vertex_data->vertexCount;
added_shared = true;
}
}
else
{
VertexData* vertex_data = submesh->vertexData;
vertex_count += vertex_data->vertexCount;
}
// Add the indices
Ogre::IndexData* index_data = submesh->indexData;
index_count += index_data->indexCount;
}
// Allocate space for the vertices and indices
vertices = new Vector3[vertex_count];
indices = new unsigned[index_count];
added_shared = false;
// Run through the submeshes again, adding the data into the arrays
for(int i = 0;i < mesh->getNumSubMeshes();i++)
{
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));
Ogre::Real* pReal;
for(size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Vector3 pt;
pt.x = (*pReal++);
pt.y = (*pReal++);
pt.z = (*pReal++);
pt = (orient * (pt * scale)) + position;
vertices[current_offset + j].x = pt.x;
vertices[current_offset + j].y = pt.y;
vertices[current_offset + j].z = pt.z;
}
vbuf->unlock();
next_offset += vertex_data->vertexCount;
}
Ogre::IndexData* index_data = submesh->indexData;
size_t numTris = index_data->indexCount / 3;
unsigned short* pShort;
unsigned int* pInt;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
if (use32bitindexes) pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
else pShort = static_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
for(size_t k = 0; k < numTris; ++k)
{
size_t offset = (submesh->useSharedVertices)?shared_offset:current_offset;
unsigned int vindex = use32bitindexes? *pInt++ : *pShort++;
indices[index_offset + 0] = vindex + offset;
vindex = use32bitindexes? *pInt++ : *pShort++;
//.........这里部分代码省略.........
示例10: 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
//.........这里部分代码省略.........
示例11: meshBuffersToArrays
void MeshUtils::meshBuffersToArrays(const Ogre::MeshPtr& mesh, Ogre::Vector3* vertices, unsigned long* indices)
{
bool added_shared = false;
size_t current_offset = 0;
size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 0;
//const Ogre::Vector3 &position = ent->getParentNode()->_getDerivedPosition();
//const Ogre::Quaternion &orient = ent->getParentNode()->_getDerivedOrientation();
//const Ogre::Vector3 &scale = ent->getParentNode()->_getDerivedScale();
const Ogre::Vector3 &position = Ogre::Vector3::ZERO;
const Ogre::Quaternion &orient = Ogre::Quaternion::IDENTITY;
const Ogre::Vector3 &scale = Ogre::Vector3::UNIT_SCALE;
Ogre::Mesh::SubMeshIterator itr = mesh->getSubMeshIterator();
while (itr.hasMoreElements()) {
Ogre::SubMesh* submesh = itr.getNext();
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::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Real* pReal;
float* pReal;
for (size_t k = 0; k < vertex_data->vertexCount; ++k, vertex += vbuf->getVertexSize()) {
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
vertices[current_offset + k] = (orient * (pt * scale)) + position;
//vertices[current_offset + k] = pt;
}
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);
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 (use32bitindexes) {
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;
}
}
示例12: getMeshInformation
//-----------------------------------------------------------------------
void MeshInfo::getMeshInformation( Ogre::MeshPtr mesh,
const Vector3 &position,
const Quaternion &orient,
const Vector3 &scale)
{
size_t vertexCount = 0;
size_t indexCount = 0;
Vector3* vertices = 0;
Vector3* normals;
unsigned long* indices = 0;
bool added_shared = false;
size_t current_offset = 0;
size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 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 )
{
vertexCount += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else
{
vertexCount += submesh->vertexData->vertexCount;
}
// Add the indices
indexCount += submesh->indexData->indexCount;
}
// Allocate space for the vertices and indices
vertices = new Vector3[vertexCount];
normals = new Vector3[vertexCount];
indices = new unsigned long[indexCount];
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);
const Ogre::VertexElement* normalElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL);
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] = (orient * (pt * scale)) + position;
normalElem->baseVertexPointerToElement(vertex, &pReal);
Vector3 nt(pReal[0], pReal[1], pReal[2]);
normals[current_offset + j] = nt;
}
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);
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;
size_t numTrisMultThree = numTris*3;
if ( use32bitindexes )
{
for ( size_t k = 0; k < numTrisMultThree; ++k)
{
indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset);
}
}
else
{
//.........这里部分代码省略.........
示例13: catch
mesh::mesh(const std::string &mn, const mat4 &tf, const world &_world):
/** Don't know if world() is the best thing to pass but it works for now **/
_mesh(NewtonMeshCreate(_world))
{
Ogre::MeshPtr meshPtr;
try
{
meshPtr = Ogre::MeshPtr(Ogre::MeshManager::getSingleton().load(mn,
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME));
}
catch(...)
{
return;
}
const Ogre::Mesh &mesh = *meshPtr;
NewtonMeshBeginFace(_mesh);
for (unsigned smi = 0; smi < mesh.getNumSubMeshes(); smi++) {
Ogre::SubMesh *subMesh = mesh.getSubMesh(smi);
Ogre::VertexData *vertexData =
(subMesh->useSharedVertices) ?
vertexData = mesh.sharedVertexData : vertexData = subMesh->vertexData;
Ogre::VertexDeclaration *vertexDecl = vertexData->vertexDeclaration;
const Ogre::VertexElement *element = vertexDecl->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vertexHVBSP =
vertexData->vertexBufferBinding->getBuffer(element->getSource());
unsigned char *vPtr = (unsigned char*)(vertexHVBSP->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
Ogre::IndexData *indexData = subMesh->indexData;
size_t numIndices = indexData->indexCount;
size_t numTris = numIndices / 3;
// get pointer!
Ogre::HardwareIndexBufferSharedPtr indexHIBSP = indexData->indexBuffer;
// 16 or 32 bit indices?
bool indicesAre32Bit = (indexHIBSP->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
unsigned long *longPtr = NULL;
unsigned short *shortPtr = NULL;
if (indicesAre32Bit)
longPtr = static_cast<unsigned long*>(
indexHIBSP->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
else
shortPtr = static_cast<unsigned short*>(
indexHIBSP->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
//now loop through the indices, getting polygon info!
int iOffset = 0;
for (size_t i = 0; i < numTris; i++) {
vec3 triVertices[3];
unsigned char *vOffset = NULL;
float *vertexPosPtr = NULL;
int idx = 0;
for (int j = 0; j < 3; j++) {
if (indicesAre32Bit)
idx = longPtr[iOffset + j];
else
idx = shortPtr[iOffset + j];
vOffset = vPtr + (idx * vertexHVBSP->getVertexSize());
element->baseVertexPointerToElement(vOffset, &vertexPosPtr);
triVertices[j].x = *vertexPosPtr; vertexPosPtr++;
triVertices[j].y = *vertexPosPtr; vertexPosPtr++;
triVertices[j].z = *vertexPosPtr; vertexPosPtr++;
triVertices[j] = tf * triVertices[j];
}
// _mesh, 3 vertices (triangle), (float = 4 bytes) * 3
// index = index of sub mesh (easy to recognize)
NewtonMeshAddFace(_mesh, 3, &triVertices[0].x, sizeof(float) * 3, smi);
iOffset += 3;
}
//unlock the buffers!
vertexHVBSP->unlock();
indexHIBSP->unlock();
}
NewtonMeshEndFace(_mesh);
}
示例14: loadMesh
Mesh loadMesh(const std::string& meshName)
{
Mesh result;
bool addedShared = false;
size_t currentOffset = 0;
size_t sharedOffset = 0;
size_t nextOffset = 0;
size_t indexOffset = 0;
const v3 scale = v3::UNIT_SCALE;
const v3 position = v3::ZERO;
const qv4 orientation = qv4::IDENTITY;
Ogre::MeshManager* mm = Ogre::MeshManager::getSingletonPtr();
if (! mm)
{
initOgreForMeshLoading();
mm = Ogre::MeshManager::getSingletonPtr();
}
Ogre::MeshPtr mesh = mm->load(meshName, "General");
// Calculate how many result.mVertices and result.mIndices 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 result.mVertices once
if (subMesh->useSharedVertices)
{
if (!addedShared)
{
result.mVertexCount += mesh->sharedVertexData->vertexCount;
addedShared = true;
}
}
else
{
result.mVertexCount += subMesh->vertexData->vertexCount;
}
result.mIndexCount += subMesh->indexData->indexCount;
}
result.mVertices.reset(new v3[result.mVertexCount]);
result.mIndices.reset(new u32[result.mIndexCount]);
addedShared = false;
// Run through the sub-meshes again, adding the data into the arrays
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 && !addedShared))
{
if(subMesh->useSharedVertices)
{
addedShared = true;
sharedOffset = 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));
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be compiled/typedefed as double:
float* pReal;
for( size_t j = 0; j < vertexData->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
v3 pt(pReal[0], pReal[1], pReal[2]);
result.mVertices[currentOffset + j] = (orientation * (pt * scale)) + position;
}
vbuf->unlock();
nextOffset += vertexData->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);
unsigned long* pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);
//.........这里部分代码省略.........
示例15: GetTrianglesFromMesh
void GetTrianglesFromMesh(Ogre::Mesh* mesh, std::vector<float3>& dest)
{
dest.clear();
try
{
for(uint i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
const Ogre::VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char* vertices = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t vertexSize = vbuf->getVertexSize();
float* pReal = 0;
Ogre::IndexData* index_data = submesh->indexData;
size_t numTris = index_data->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
u32* pLong = static_cast<u32*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
u16* pShort = reinterpret_cast<u16*>(pLong);
bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
if (use32bitindexes)
{
for(size_t k = 0; k < numTris * 3; k += 3)
{
uint i1 = pLong[k];
uint i2 = pLong[k+1];
uint i3 = pLong[k+2];
posElem->baseVertexPointerToElement(vertices + i1 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
posElem->baseVertexPointerToElement(vertices + i2 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
posElem->baseVertexPointerToElement(vertices + i3 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
}
}
else
{
for(size_t k = 0; k < numTris * 3; k += 3)
{
uint i1 = pShort[k];
uint i2 = pShort[k+1];
uint i3 = pShort[k+2];
posElem->baseVertexPointerToElement(vertices + i1 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
posElem->baseVertexPointerToElement(vertices + i2 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
posElem->baseVertexPointerToElement(vertices + i3 * vertexSize, &pReal);
dest.push_back(float3(pReal[0], pReal[1], pReal[2]));
}
}
vbuf->unlock();
ibuf->unlock();
}
} catch(Ogre::Exception &e)
{
///\todo Fix Ogre to not allow meshes like this to be successfully created.
LogError("GetTrianglesFromMesh failed for mesh! Ogre threw an exception: " + QString(e.what()));
dest.clear();
}
}