本文整理汇总了C++中ogre::MeshPtr::getNumSubMeshes方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::getNumSubMeshes方法的具体用法?C++ MeshPtr::getNumSubMeshes怎么用?C++ MeshPtr::getNumSubMeshes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::getNumSubMeshes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addMesh
//------------------------------------------------------------------------------------------------
void StaticMeshToShapeConverter::addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform)
{
// Each entity added need to reset size and radius
// next time getRadius and getSize are asked, they're computed.
mBounds = Ogre::Vector3(-1,-1,-1);
mBoundRadius = -1;
//_entity = entity;
//_node = (SceneNode*)(_entity->getParentNode());
mTransform = transform;
if (mesh->hasSkeleton ())
Ogre::LogManager::getSingleton().logMessage("MeshToShapeConverter::addMesh : Mesh " + mesh->getName () + " as skeleton but added to trimesh non animated");
if (mesh->sharedVertexData)
{
VertexIndexToShape::addStaticVertexData (mesh->sharedVertexData);
}
for(unsigned int i = 0;i < mesh->getNumSubMeshes();++i)
{
Ogre::SubMesh *sub_mesh = mesh->getSubMesh(i);
if (!sub_mesh->useSharedVertices)
{
VertexIndexToShape::addIndexData(sub_mesh->indexData, mVertexCount);
VertexIndexToShape::addStaticVertexData (sub_mesh->vertexData);
}
else
{
VertexIndexToShape::addIndexData (sub_mesh->indexData);
}
}
}
示例2: make_pair
std::pair<int, int> MeshUtils::getMeshCount(const Ogre::MeshPtr& mesh)
{
size_t vertex_count = 0;
size_t index_count = 0;
bool added_shared = false;
for (int j = 0; j < mesh->getNumSubMeshes(); j++) {
Ogre::SubMesh* submesh = mesh->getSubMesh(j);
// VertexData* vertex_data = submesh->vertexData;
// IndexData* index_data = submesh->indexData;
// 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;
}
return std::make_pair(vertex_count, index_count);
}
示例3: fillBuffer
void LodInputBuffer::fillBuffer( Ogre::MeshPtr mesh )
{
meshName = mesh->getName();
boundingSphereRadius = mesh->getBoundingSphereRadius();
bool sharedVerticesAdded = false;
unsigned short submeshCount = mesh->getNumSubMeshes();
submesh.resize(submeshCount);
for (unsigned short i = 0; i < submeshCount; i++) {
const SubMesh* ogresubmesh = mesh->getSubMesh(i);
LodInputBuffer::Submesh& outsubmesh = submesh[i];
outsubmesh.indexBuffer.fillBuffer(ogresubmesh->indexData);
outsubmesh.useSharedVertexBuffer = ogresubmesh->useSharedVertices;
if (!outsubmesh.useSharedVertexBuffer) {
outsubmesh.vertexBuffer.fillBuffer(ogresubmesh->vertexData);
} else if (!sharedVerticesAdded) {
sharedVerticesAdded = true;
sharedVertexBuffer.fillBuffer(mesh->sharedVertexData);
}
}
}
示例4: addMesh
//------------------------------------------------------------------------------------------------
void AnimatedMeshToShapeConverter::addMesh(const Ogre::MeshPtr &mesh,
const Ogre::Matrix4 &transform)
{
// Each entity added need to reset size and radius
// next time getRadius and getSize are asked, they're computed.
mBounds = Ogre::Vector3(-1.0f , -1.0f, -1.0f);
mBoundRadius = -1.0f;
//_entity = entity;
//_node = (SceneNode*)(_entity->getParentNode());
mTransform = transform;
assert(mesh->hasSkeleton());
if (mesh->sharedVertexData)
{
VertexIndexToShape::addAnimatedVertexData(mesh->sharedVertexData,
NULL,
&mesh->sharedBlendIndexToBoneIndexMap);
}
for (unsigned int i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh *sub_mesh = mesh->getSubMesh(i);
if (!sub_mesh->useSharedVertices)
{
VertexIndexToShape::addIndexData(sub_mesh->indexData, mVertexCount);
VertexIndexToShape::addAnimatedVertexData(sub_mesh->vertexData,
NULL,
&sub_mesh->blendIndexToBoneIndexMap);
}
else
{
VertexIndexToShape::addIndexData(sub_mesh->indexData);
}
}
}
示例5: setMaterialName
//---------------------------------------------------------------------
void MeshElement::setMaterialName(const String &name)
{
mMaterialName = name;
if (mEntity)
{
// if this is "none",we will use the origin material of the mesh
if (mMaterialName == "none")
{
if ( false == mMeshName.empty() )
{
Ogre::MeshPtr currentMesh = Ogre::MeshManager::getSingleton().getByName(mMeshName);
for ( unsigned short i=0; i<currentMesh->getNumSubMeshes(); ++i )
{
mEntity->getSubEntity(i)->setMaterialName( currentMesh->getSubMesh(i)->getMaterialName() );
}
}
}
else
mEntity->setMaterialName(mMaterialName);
}
}
示例6: 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;
}
}
示例7: 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++;
//.........这里部分代码省略.........
示例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
//-----------------------------------------------------------------------
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
{
//.........这里部分代码省略.........
示例10: processMesh
//---------------------------------------------------------------------
void OptimiseTool::processMesh(Ogre::MeshPtr mesh)
{
bool rebuildEdgeList = false;
// Shared geometry
if (mesh->sharedVertexData)
{
print("Optimising mesh shared vertex data...");
setTargetVertexData(mesh->sharedVertexData);
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
SubMesh* sm = mesh->getSubMesh(i);
if (sm->useSharedVertices)
{
addIndexData(sm->indexData);
}
}
if (optimiseGeometry())
{
if (mesh->getSkeletonName() != StringUtil::BLANK)
{
print(" fixing bone assignments...");
Mesh::BoneAssignmentIterator currentIt = mesh->getBoneAssignmentIterator();
Mesh::VertexBoneAssignmentList newList =
getAdjustedBoneAssignments(currentIt);
mesh->clearBoneAssignments();
for (Mesh::VertexBoneAssignmentList::iterator bi = newList.begin();
bi != newList.end(); ++bi)
{
mesh->addBoneAssignment(bi->second);
}
}
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
SubMesh* sm = mesh->getSubMesh(i);
if (mesh->getSkeletonName() != StringUtil::BLANK)
{
print(" fixing bone assignments...");
Mesh::BoneAssignmentIterator currentIt = sm->getBoneAssignmentIterator();
Mesh::VertexBoneAssignmentList newList =
getAdjustedBoneAssignments(currentIt);
sm->clearBoneAssignments();
for (Mesh::VertexBoneAssignmentList::iterator bi = newList.begin();
bi != newList.end(); ++bi)
{
sm->addBoneAssignment(bi->second);
}
}
if (sm->useSharedVertices)
{
fixLOD(sm->mLodFaceList);
}
}
rebuildEdgeList = true;
}
}
// Dedicated geometry
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
SubMesh* sm = mesh->getSubMesh(i);
if (!sm->useSharedVertices)
{
print("Optimising submesh " +
StringConverter::toString(i) + " dedicated vertex data ");
setTargetVertexData(sm->vertexData);
addIndexData(sm->indexData);
if (optimiseGeometry())
{
if (mesh->getSkeletonName() != StringUtil::BLANK)
{
print(" fixing bone assignments...");
Mesh::BoneAssignmentIterator currentIt = sm->getBoneAssignmentIterator();
Mesh::VertexBoneAssignmentList newList =
getAdjustedBoneAssignments(currentIt);
sm->clearBoneAssignments();
for (Mesh::VertexBoneAssignmentList::iterator bi = newList.begin();
bi != newList.end(); ++bi)
{
sm->addBoneAssignment(bi->second);
}
}
fixLOD(sm->mLodFaceList);
rebuildEdgeList = true;
}
}
}
if (rebuildEdgeList && mesh->isEdgeListBuilt())
{
// force rebuild of edge list
mesh->freeEdgeList();
//.........这里部分代码省略.........
示例11: 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);
//.........这里部分代码省略.........
示例12:
OgreNewt::ConvexCollisionPtr PhysicsRagDoll::RagBone::_makeConvexHull(OgreNewt::World* world, Ogre::MeshPtr mesh, Ogre::Real minWeight)
{
std::vector< Ogre::Vector3 > vertexVector;
// for this bone, gather all of the vertices linked to it, and make an individual convex hull.
std::string boneName = mOgreBone->getName();
unsigned int boneIndex = mOgreBone->getHandle();
Ogre::Matrix4 invMatrix;
invMatrix.makeInverseTransform(-mOgreBone->_getBindingPoseInversePosition(), Ogre::Vector3::UNIT_SCALE / mOgreBone->_getBindingPoseInverseScale(), mOgreBone->_getBindingPoseInverseOrientation().Inverse());
unsigned int num_sub = mesh->getNumSubMeshes();
for (unsigned int i = 0; i < num_sub; i++)
{
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::SubMesh::BoneAssignmentIterator bai = submesh->getBoneAssignmentIterator();
Ogre::VertexDeclaration* v_decl;
const Ogre::VertexElement* p_elem;
float* v_Posptr;
size_t v_count;
Ogre::VertexData* v_data = NULL;
if (submesh->useSharedVertices)
{
v_data = mesh->sharedVertexData;
v_count = v_data->vertexCount;
v_decl = v_data->vertexDeclaration;
p_elem = v_decl->findElementBySemantic(Ogre::VES_POSITION);
}
else
{
v_data = submesh->vertexData;
v_count = v_data->vertexCount;
v_decl = v_data->vertexDeclaration;
p_elem = v_decl->findElementBySemantic(Ogre::VES_POSITION);
}
size_t start = v_data->vertexStart;
//pointer
Ogre::HardwareVertexBufferSharedPtr v_sptr = v_data->vertexBufferBinding->getBuffer(p_elem->getSource());
unsigned char* v_ptr = static_cast<unsigned char*>(v_sptr->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
unsigned char* v_offset;
while (bai.hasMoreElements())
{
Ogre::VertexBoneAssignment vba = bai.getNext();
if (vba.boneIndex == boneIndex)
{
//found a vertex that is attached to this bone.
if (vba.weight >= minWeight)
{
//get offset to Position data!
v_offset = v_ptr + (vba.vertexIndex * v_sptr->getVertexSize());
p_elem->baseVertexPointerToElement(v_offset, &v_Posptr);
Ogre::Vector3 vert;
vert.x = *v_Posptr; v_Posptr++;
vert.y = *v_Posptr; v_Posptr++;
vert.z = *v_Posptr;
// apply transformation in to local space.
vert = invMatrix * vert;
vertexVector.push_back(vert);
Ogre::LogManager::getSingletonPtr()->logMessage(" vertex found! id:"+Ogre::StringConverter::toString(vba.vertexIndex));
}
}
}
v_sptr->unlock();
}
// okay, we have gathered all verts for this bone. make a convex hull!
unsigned int numVerts = vertexVector.size();
Ogre::Vector3* verts = new Ogre::Vector3[ numVerts ];
unsigned int j = 0;
while (!vertexVector.empty())
{
verts[j] = vertexVector.back();
vertexVector.pop_back();
j++;
}
//////////////////////////////////////////////////////////////////////////////////
OgreNewt::ConvexCollisionPtr col;
if (numVerts > 0)
col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull(world, verts, numVerts, 0));
delete []verts;
return col;
}
示例13: createConvexHull
PhysicsObject* PhysicsMgr::createConvexHull(String meshname,Ogre::Vector3 pos,Ogre::Vector3 scale)
{
bool newshape = false;
size_t vertex_count;
float* vertices;
size_t index_count;
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;
std::vector<Ogre::Vector3> vertVect;
btConvexShape *convexShape;
//btShapeHull* hull;
if(meshname=="CUBE"||meshname=="BOX")
{
return createCube(scale,pos);
}
if(mShapes.find(meshname)==mShapes.end())
{
newshape = true;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingletonPtr()->load(meshname,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// Calculate how many vertices and indices we're going to need
for(int 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)
{
Ogre::VertexData* vertex_data = mesh->sharedVertexData;
vertex_count += vertex_data->vertexCount;
added_shared = true;
}
}
else
{
Ogre::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
int a = vertex_count;
vertices = new float[vertex_count*3];
added_shared = false;
// Run through the submeshes again, adding the data into the arrays
for(int 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));
Ogre::Real* pReal;
for(size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt;
pt.x = (*pReal++);
pt.y = (*pReal++);
pt.z = (*pReal++);
bool skip = false;
// ignore duped verts
for(unsigned int i=0;i<vertVect.size();++i)
{
if(vertVect[i]==pt)
{
skip = true;
//std::cout<<"IGNORED!\n";
//.........这里部分代码省略.........
示例14: 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));
//.........这里部分代码省略.........
示例15: unshareVertices
//-----------------------------------------------------------------------
void InstanceManager::unshareVertices(const Ogre::MeshPtr &mesh)
{
// Retrieve data to copy bone assignments
const Mesh::VertexBoneAssignmentList& boneAssignments = mesh->getBoneAssignments();
Mesh::VertexBoneAssignmentList::const_iterator it = boneAssignments.begin();
Mesh::VertexBoneAssignmentList::const_iterator end = boneAssignments.end();
size_t curVertexOffset = 0;
// Access shared vertices
VertexData* sharedVertexData = mesh->sharedVertexData;
for (size_t subMeshIdx = 0; subMeshIdx < mesh->getNumSubMeshes(); subMeshIdx++)
{
SubMesh *subMesh = mesh->getSubMesh(subMeshIdx);
IndexData *indexData = subMesh->indexData;
HardwareIndexBuffer::IndexType idxType = indexData->indexBuffer->getType();
IndicesMap indicesMap = (idxType == HardwareIndexBuffer::IT_16BIT) ? getUsedIndices<uint16>(indexData) :
getUsedIndices<uint32>(indexData);
VertexData *newVertexData = new VertexData();
newVertexData->vertexCount = indicesMap.size();
newVertexData->vertexDeclaration = sharedVertexData->vertexDeclaration->clone();
for (size_t bufIdx = 0; bufIdx < sharedVertexData->vertexBufferBinding->getBufferCount(); bufIdx++)
{
HardwareVertexBufferSharedPtr sharedVertexBuffer = sharedVertexData->vertexBufferBinding->getBuffer(bufIdx);
size_t vertexSize = sharedVertexBuffer->getVertexSize();
HardwareVertexBufferSharedPtr newVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer
(vertexSize, newVertexData->vertexCount, sharedVertexBuffer->getUsage(), sharedVertexBuffer->hasShadowBuffer());
uint8 *oldLock = (uint8*)sharedVertexBuffer->lock(0, sharedVertexData->vertexCount * vertexSize, HardwareBuffer::HBL_READ_ONLY);
uint8 *newLock = (uint8*)newVertexBuffer->lock(0, newVertexData->vertexCount * vertexSize, HardwareBuffer::HBL_NORMAL);
IndicesMap::iterator indIt = indicesMap.begin();
IndicesMap::iterator endIndIt = indicesMap.end();
for (; indIt != endIndIt; ++indIt)
{
memcpy(newLock + vertexSize * indIt->second, oldLock + vertexSize * indIt->first, vertexSize);
}
sharedVertexBuffer->unlock();
newVertexBuffer->unlock();
newVertexData->vertexBufferBinding->setBinding(bufIdx, newVertexBuffer);
}
if (idxType == HardwareIndexBuffer::IT_16BIT)
{
copyIndexBuffer<uint16>(indexData, indicesMap);
}
else
{
copyIndexBuffer<uint32>(indexData, indicesMap);
}
// Store new attributes
subMesh->useSharedVertices = false;
subMesh->vertexData = newVertexData;
// Transfer bone assignments to the submesh
size_t offset = curVertexOffset + newVertexData->vertexCount;
for (; it != end; ++it)
{
size_t vertexIdx = (*it).first;
if (vertexIdx > offset)
break;
VertexBoneAssignment boneAssignment = (*it).second;
boneAssignment.vertexIndex = static_cast<unsigned int>(boneAssignment.vertexIndex - curVertexOffset);
subMesh->addBoneAssignment(boneAssignment);
}
curVertexOffset = newVertexData->vertexCount + 1;
}
// Release shared vertex data
delete mesh->sharedVertexData;
mesh->sharedVertexData = NULL;
mesh->clearBoneAssignments();
}