本文整理汇总了C++中MeshPtr::_setBoundingSphereRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::_setBoundingSphereRadius方法的具体用法?C++ MeshPtr::_setBoundingSphereRadius怎么用?C++ MeshPtr::_setBoundingSphereRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::_setBoundingSphereRadius方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createSphere
void GeomUtils::createSphere( const String& strName
, float radius
, int nRings, int nSegments
, bool bNormals
, bool bTexCoords)
{
MeshPtr pSphere = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
SubMesh *pSphereVertex = pSphere->createSubMesh();
pSphere->sharedVertexData = new VertexData();
createSphere(pSphere->sharedVertexData, pSphereVertex->indexData
, radius
, nRings, nSegments
, bNormals // need normals
, bTexCoords // need texture co-ordinates
);
// Generate face list
pSphereVertex->useSharedVertices = true;
// the original code was missing this line:
pSphere->_setBounds( AxisAlignedBox( Vector3(-radius, -radius, -radius), Vector3(radius, radius, radius) ), false );
pSphere->_setBoundingSphereRadius(radius);
// this line makes clear the mesh is loaded (avoids memory leaks)
pSphere->load();
}
示例2: AddMesh
void SplineRoad::AddMesh(MeshPtr mesh, String sMesh, const AxisAlignedBox& aabox,
Entity** pEnt, SceneNode** pNode, String sEnd)
{
mesh->_setBounds(aabox);
mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0);
mesh->load();
unsigned short src, dest;
if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
mesh->buildTangentVectors(VES_TANGENT, src, dest);
*pEnt = mSceneMgr->createEntity("rd.ent"+sEnd, sMesh);
*pNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("rd.node"+sEnd);
(*pNode)->attachObject(*pEnt);
(*pEnt)->setVisible(false); (*pEnt)->setCastShadows(false);
(*pEnt)->setVisibilityFlags(RV_Road);
}
示例3: getMesh
MeshPtr Tile::getMesh(std::string tileName)
{
// Create the overall mesh.
MeshPtr tileMesh = MeshManager::getSingleton().createManual(tileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// Add the tile as a submesh to mesh major.
this->_generateSubMesh(tileMesh);
/// Set bounding information (for culling)
tileMesh->_setBounds(AxisAlignedBox(-5,-5,-5,5,5,5));
tileMesh->_setBoundingSphereRadius(Math::Sqrt(3*5*5));
// Signal that the mesh has loaded.
tileMesh->load();
// Return finished mesh.
return tileMesh;
}
示例4: createCone
void GeomUtils::createCone(const Ogre::String& strName , float radius , float height, int nVerticesInBase)
{
MeshPtr pCone = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
SubMesh *pConeVertex = pCone->createSubMesh();
pCone->sharedVertexData = new VertexData();
createCone(pCone->sharedVertexData, pConeVertex->indexData
, radius
, height
, nVerticesInBase);
// Generate face list
pConeVertex->useSharedVertices = true;
// the original code was missing this line:
pCone->_setBounds( AxisAlignedBox(
Vector3(-radius, 0, -radius),
Vector3(radius, height, radius) ), false );
pCone->_setBoundingSphereRadius(Math::Sqrt(height*height + radius*radius));
// this line makes clear the mesh is loaded (avoids memory leaks)
pCone->load();
}
示例5: bounds
//.........这里部分代码省略.........
y = heightFunction(x, z, heightFunctionUserData);
} else {
y = 0;
}
float x1 = (x - page.centerPoint.x);
float z1 = (z - page.centerPoint.z);
//Get the color at the grass position
uint32 color;
if (layer->colorMap)
color = layer->colorMap->getColorAt(x, z, layer->mapBounds);
else
color = 0xFFFFFFFF;
//Calculate size
float rnd = *posPtr++; //The same rnd value is used for width and height to maintain aspect ratio
float halfXScale = (layer->minWidth + rndWidth * rnd) * 0.5f;
float scaleY = (layer->minHeight + rndHeight * rnd);
//Randomly mirror grass textures
float uvLeft, uvRight;
if (*posPtr++ > 0.5f){
uvLeft = 0;
uvRight = 1;
} else {
uvLeft = 1;
uvRight = 0;
}
//Add vertices
*pReal++ = x1; *pReal++ = y; *pReal++ = z1; //center position
*pReal++ = -halfXScale; *pReal++ = scaleY; *pReal++ = 0; *pReal++ = 0; //normal (used to store relative corner positions)
*((uint32*)pReal++) = color; //color
*pReal++ = uvLeft; *pReal++ = 0; //uv
*pReal++ = x1; *pReal++ = y; *pReal++ = z1; //center position
*pReal++ = +halfXScale; *pReal++ = scaleY; *pReal++ = 0; *pReal++ = 0; //normal (used to store relative corner positions)
*((uint32*)pReal++) = color; //color
*pReal++ = uvRight; *pReal++ = 0; //uv
*pReal++ = x1; *pReal++ = y; *pReal++ = z1; //center position
*pReal++ = -halfXScale; *pReal++ = 0.0f; *pReal++ = 0; *pReal++ = 0; //normal (used to store relative corner positions)
*((uint32*)pReal++) = color; //color
*pReal++ = uvLeft; *pReal++ = 1; //uv
*pReal++ = x1; *pReal++ = y; *pReal++ = z1; //center position
*pReal++ = +halfXScale; *pReal++ = 0.0f; *pReal++ = 0; *pReal++ = 0; //normal (used to store relative corner positions)
*((uint32*)pReal++) = color; //color
*pReal++ = uvRight; *pReal++ = 1; //uv
//Update bounds
if (y < minY) minY = y;
if (y + scaleY > maxY) maxY = y + scaleY;
}
vbuf->unlock();
subMesh->vertexData->vertexBufferBinding->setBinding(0, vbuf);
//Populate index buffer
subMesh->indexData->indexStart = 0;
subMesh->indexData->indexCount = 6 * quadCount;
subMesh->indexData->indexBuffer = HardwareBufferManager::getSingleton()
.createIndexBuffer(HardwareIndexBuffer::IT_16BIT, subMesh->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
uint16* pI = static_cast<uint16*>(subMesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
for (uint16 i = 0; i < quadCount; ++i)
{
uint16 offset = i * 4;
*pI++ = 0 + offset;
*pI++ = 2 + offset;
*pI++ = 1 + offset;
*pI++ = 1 + offset;
*pI++ = 2 + offset;
*pI++ = 3 + offset;
}
subMesh->indexData->indexBuffer->unlock();
//subMesh->setBuildEdgesEnabled(autoEdgeBuildEnabled);
//Finish up mesh
AxisAlignedBox bounds(page.bounds.left - page.centerPoint.x, minY, page.bounds.top - page.centerPoint.z,
page.bounds.right - page.centerPoint.x, maxY, page.bounds.bottom - page.centerPoint.z);
mesh->_setBounds(bounds);
Vector3 temp = bounds.getMaximum() - bounds.getMinimum();
mesh->_setBoundingSphereRadius(temp.length() * 0.5f);
LogManager::getSingleton().setLogDetail(static_cast<LoggingLevel>(0));
mesh->setAutoBuildEdgeLists(autoEdgeBuildEnabled);
mesh->load();
LogManager::getSingleton().setLogDetail(LL_NORMAL);
//Apply grass material to mesh
subMesh->setMaterialName(layer->material->getName());
//Return the mesh
return mesh.getPointer();
}
示例6: createSphere
void createSphere(const std::string& strName, const float r, const int nRings = 16, const int nSegments = 16)
{
MeshPtr pSphere = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
SubMesh *pSphereVertex = pSphere->createSubMesh();
pSphere->sharedVertexData = new VertexData();
VertexData* vertexData = pSphere->sharedVertexData;
// define the vertex format
VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// positions
vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION);
currOffset += VertexElement::getTypeSize(VET_FLOAT3);
// normals
vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL);
currOffset += VertexElement::getTypeSize(VET_FLOAT3);
// two dimensional texture coordinates
vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
currOffset += VertexElement::getTypeSize(VET_FLOAT2);
// allocate the vertex buffer
vertexData->vertexCount = (nRings + 1) * (nSegments + 1);
HardwareVertexBufferSharedPtr vBuf = HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
VertexBufferBinding* binding = vertexData->vertexBufferBinding;
binding->setBinding(0, vBuf);
float* pVertex = static_cast<float*>(vBuf->lock(HardwareBuffer::HBL_DISCARD));
// allocate index buffer
pSphereVertex->indexData->indexCount = 6 * nRings * (nSegments + 1);
pSphereVertex->indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, pSphereVertex->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
HardwareIndexBufferSharedPtr iBuf = pSphereVertex->indexData->indexBuffer;
unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(HardwareBuffer::HBL_DISCARD));
float fDeltaRingAngle = (Math::PI / nRings);
float fDeltaSegAngle = (2 * Math::PI / nSegments);
unsigned short wVerticeIndex = 0;
// Generate the group of rings for the sphere
for (int ring = 0; ring <= nRings; ring++) {
float r0 = r * sinf(ring * fDeltaRingAngle);
float y0 = r * cosf(ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for (int seg = 0; seg <= nSegments; seg++) {
float x0 = r0 * sinf(seg * fDeltaSegAngle);
float z0 = r0 * cosf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
*pVertex++ = x0;
*pVertex++ = y0;
*pVertex++ = z0;
Vector3 vNormal = Vector3(x0, y0, z0).normalisedCopy();
*pVertex++ = vNormal.x;
*pVertex++ = vNormal.y;
*pVertex++ = vNormal.z;
*pVertex++ = (float)seg / (float)nSegments;
*pVertex++ = (float)ring / (float)nRings;
if (ring != nRings) {
// each vertex (except the last) has six indices pointing to it
*pIndices++ = wVerticeIndex + nSegments + 1;
*pIndices++ = wVerticeIndex;
*pIndices++ = wVerticeIndex + nSegments;
*pIndices++ = wVerticeIndex + nSegments + 1;
*pIndices++ = wVerticeIndex + 1;
*pIndices++ = wVerticeIndex;
wVerticeIndex++;
}
}; // end for seg
} // end for ring
// Unlock
vBuf->unlock();
iBuf->unlock();
// Generate face list
pSphereVertex->useSharedVertices = true;
// the original code was missing this line:
pSphere->_setBounds(AxisAlignedBox(Vector3(-r, -r, -r), Vector3(r, r, r)), false);
pSphere->_setBoundingSphereRadius(r);
// this line makes clear the mesh is loaded (avoids memory leaks)
pSphere->load();
}
示例7: createConvexHullMesh
Ogre::MeshPtr LodOutsideMarker::createConvexHullMesh(const String& meshName, const String& resourceGroupName)
{
// Based on the wiki sample: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Generating+A+Mesh
// Resource with given name should not exist!
assert(MeshManager::getSingleton().getByName(meshName).isNull());
generateHull(); // calculate mHull triangles.
// Convex hull can't be empty!
assert(!mHull.empty());
MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, resourceGroupName, NULL);
SubMesh* subMesh = mesh->createSubMesh();
vector<Real>::type vertexBuffer;
vector<unsigned short>::type indexBuffer;
// 3 position/triangle * 3 Real/position
vertexBuffer.reserve(mHull.size() * 9);
// 3 index / triangle
indexBuffer.reserve(mHull.size() * 3);
int id=0;
// min & max position
Vector3 minBounds(std::numeric_limits<Real>::max(), std::numeric_limits<Real>::max(), std::numeric_limits<Real>::max());
Vector3 maxBounds(std::numeric_limits<Real>::min(), std::numeric_limits<Real>::min(), std::numeric_limits<Real>::min());
for (size_t i = 0; i < mHull.size(); i++) {
assert(!mHull[i].removed);
for(size_t n = 0; n < 3; n++){
indexBuffer.push_back(id++);
vertexBuffer.push_back(mHull[i].vertex[n]->position.x);
vertexBuffer.push_back(mHull[i].vertex[n]->position.y);
vertexBuffer.push_back(mHull[i].vertex[n]->position.z);
minBounds.x = std::min<Real>(minBounds.x, mHull[i].vertex[n]->position.x);
minBounds.y = std::min<Real>(minBounds.y, mHull[i].vertex[n]->position.y);
minBounds.z = std::min<Real>(minBounds.z, mHull[i].vertex[n]->position.z);
maxBounds.x = std::max<Real>(maxBounds.x, mHull[i].vertex[n]->position.x);
maxBounds.y = std::max<Real>(maxBounds.y, mHull[i].vertex[n]->position.y);
maxBounds.z = std::max<Real>(maxBounds.z, mHull[i].vertex[n]->position.z);
}
}
/// Create vertex data structure for 8 vertices shared between submeshes
mesh->sharedVertexData = new VertexData();
mesh->sharedVertexData->vertexCount = mHull.size() * 3;
/// Create declaration (memory format) of vertex data
VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, mesh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), &vertexBuffer[0], true);
/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
indexBuffer.size(),
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
ibuf->writeData(0, ibuf->getSizeInBytes(), &indexBuffer[0], true);
/// Set parameters of the submesh
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = indexBuffer.size();
subMesh->indexData->indexStart = 0;
/// Set bounding information (for culling)
mesh->_setBounds(AxisAlignedBox(minBounds, maxBounds));
mesh->_setBoundingSphereRadius(maxBounds.distance(minBounds) / 2.0f);
/// Set material to transparent blue
subMesh->setMaterialName("Examples/TransparentBlue50");
/// Notify -Mesh object that it has been loaded
mesh->load();
return mesh;
}
示例8: importObject
//.........这里部分代码省略.........
*(pFloat++) = (float)vertex.x();
*(pFloat++) = (float)vertex.y();
*(pFloat++) = (float)vertex.z();
positions.append(vertex.x());
positions.append(vertex.y());
positions.append(vertex.z());
/* While we're at it, calculate the bounding sphere */
pos.x = vertex.x();
pos.y = vertex.y();
pos.z = vertex.z();
if (firstVertex) {
min = max = pos;
maxSquaredRadius = pos.squaredLength();
firstVertex = false;
} else {
min.makeFloor(pos);
max.makeCeil(pos);
maxSquaredRadius = qMax(pos.squaredLength(), maxSquaredRadius);
}
pVert += vbuf->getVertexSize();
}
// Set bounds
const AxisAlignedBox& currBox = ogreMesh->getBounds();
Real currRadius = ogreMesh->getBoundingSphereRadius();
if (currBox.isNull())
{
//do not pad the bounding box
ogreMesh->_setBounds(AxisAlignedBox(min, max), false);
ogreMesh->_setBoundingSphereRadius(Math::Sqrt(maxSquaredRadius));
}
else
{
AxisAlignedBox newBox(min, max);
newBox.merge(currBox);
//do not pad the bounding box
ogreMesh->_setBounds(newBox, false);
ogreMesh->_setBoundingSphereRadius(qMax(Math::Sqrt(maxSquaredRadius), currRadius));
}
/*
Create faces
*/
// All children should be submeshes
SubMesh* sm = ogreMesh->createSubMesh();
sm->setMaterialName("clippingMaterial");
sm->operationType = RenderOperation::OT_TRIANGLE_LIST;
sm->useSharedVertices = true;
// tri list
sm->indexData->indexCount = indexCount;
// Allocate space
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
sm->indexData->indexCount,
HardwareBuffer::HBU_DYNAMIC,
false);
sm->indexData->indexBuffer = ibuf;
unsigned short *pShort = static_cast<unsigned short*>(ibuf->lock(HardwareBuffer::HBL_DISCARD));
示例9: connect
//.........这里部分代码省略.........
setIntermediateWall(entireIntermediate, NORTHWEST, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(wallLength2 / 2, wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q2 * move;
p3 = end + move;
move = Vector3(wallLength1 / 2, wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[NORTH])
setIntermediateWall(entireIntermediate, NORTH, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength2 / 2, 0);
move = q2 * move;
p3 = end + move;
move = Vector3(wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength1 / 2, 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[NORTHEAST])
setIntermediateWall(entireIntermediate, NORTHEAST, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength2 / 2, 0);
move = q2 * move;
p3 = end + move;
move = Vector3(wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength1 / 2, 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[EAST])
setIntermediateWall(entireIntermediate, EAST, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(wallLength2 / 2, -wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q2 * move;
p3 = end + move;
move = Vector3(wallLength1 / 2, -wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[SOUTHEAST])
setIntermediateWall(entireIntermediate, SOUTHEAST, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(-wallLength2 / 2, -wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q2 * move;
p3 = end + move;
move = Vector3(-wallLength1 / 2, -wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[SOUTH])
setIntermediateWall(entireIntermediate, SOUTH, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(-wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength2 / 2, 0);
move = q2 * move;
p3 = end + move;
move = Vector3(-wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength1 / 2, 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[SOUTHWEST])
setIntermediateWall(entireIntermediate, SOUTHWEST, manual, p1, p2, p3, p4, bl, tr);
p1 = p4;
p2 = p3;
move = Vector3(-wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength1 / 2, 0);
move = q2 * move;
p3 = end + move;
move = Vector3(-wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength2 / 2, 0);
move = q1 * move;
p4 = start + move;
if (sidesUsed[WEST])
setIntermediateWall(entireIntermediate, WEST, manual, p1, p2, p3, p4, bl, tr);
MeshPtr mesh = manual->convertToMesh(meshName);
mesh->_setBounds( AxisAlignedBox( bl, tr ), true );
float l = (tr - bl).length() / 2;
mesh->_setBoundingSphereRadius(l);
unsigned short src, dest;
if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
{
mesh->buildTangentVectors(VES_TANGENT, src, dest);
}
Entity* intermediateSegmentEntity = entireIntermediate->getCreator()->createEntity("intermediateSegmentEntity" + Util::toStringInt(intermediateMeshID), meshName);
//intermediateSegmentEntity->setMaterialName(getMaterialName());
for (int i = 0; i < intermediateSegmentEntity->getNumSubEntities(); ++i)
intermediateSegmentEntity->getSubEntity(i)->setMaterialName(getMaterialName());
entireIntermediate->attachObject(intermediateSegmentEntity);
meshes.push_back(mesh);
intermediateMeshID++;
parentNode->getCreator()->destroyManualObject(manual);
}
示例10: createIndexedFaceSet
//.........这里部分代码省略.........
std::swap(t.vertices[1], t.vertices[2]);
triangles.push_back(t);
triVerts[1] = vpos;
}
}
}
// createOgreMesh
int nvertices = vertices.size();
int nfaces = triangles.size();
VertexData* vertexData = new VertexData();
sub->vertexData = vertexData;
IndexData* indexData = sub->indexData;
VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// positions
vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION);
currOffset += VertexElement::getTypeSize(VET_FLOAT3);
if (hasPointNormals)
{
// normals
vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL);
currOffset += VertexElement::getTypeSize(VET_FLOAT3);
}
// two dimensional texture coordinates
if (hasTextureCoordinates)
{
vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
currOffset += VertexElement::getTypeSize(VET_FLOAT2);
}
std::cout << std::endl;
// allocate index buffer
indexData->indexCount = nfaces * 3;
indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
HardwareIndexBufferSharedPtr iBuf = indexData->indexBuffer;
unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(HardwareBuffer::HBL_DISCARD));
std::cout << triangles.size() << ": ";
for(std::vector<triangle>::const_iterator T = triangles.begin(); T != triangles.end(); T++)
{
const triangle &t = (*T);
*pIndices++ = t.vertices[0];
*pIndices++ = t.vertices[1];
*pIndices++ = t.vertices[2];
std::cout << t.vertices[0] << " " << t.vertices[1] << " " << t.vertices[2] << " ";
}
std::cout << std::endl;
// allocate the vertex buffer
vertexData->vertexCount = nvertices;
HardwareVertexBufferSharedPtr vBuf = HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
VertexBufferBinding* binding = vertexData->vertexBufferBinding;
binding->setBinding(0, vBuf);
float* pVertex = static_cast<float*>(vBuf->lock(HardwareBuffer::HBL_DISCARD));
AxisAlignedBox aabox;
std::cout << vertices.size() << ": ";
for(std::vector<vertex>::const_iterator V = vertices.begin(); V != vertices.end(); V++)
{
const vertex &v = (*V);
SFVec3f pos = _coords.at(v.pos);
*pVertex++ = pos.x;
*pVertex++ = pos.y;
*pVertex++ = pos.z;
aabox.merge(Vector3(pos.x, pos.y, pos.z));
std::cout << pos.x << " " << pos.y << " " << pos.z << " " << std::endl;
//std::cout << v.pos << " ";
if (hasPointNormals)
{
const SFVec3f normal = _normals.at(v.normal);
*pVertex++ = normal.x;
*pVertex++ = normal.y;
*pVertex++ = normal.z;
}
}
std::cout << std::endl;
// Unlock
vBuf->unlock();
iBuf->unlock();
sub->useSharedVertices = false;
// the original code was missing this line:
mesh->_setBounds(aabox);
mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0);
// this line makes clear the mesh is loaded (avoids memory leaks)
mesh->load();
}
示例11: createSphereMesh
void createSphereMesh(const String &name, const float radius, const int slices, const int stacks)
{
MeshPtr mesh = MeshManager::getSingleton().createManual(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mesh->sharedVertexData = new VertexData();
mesh->_setBounds(AxisAlignedBox(Vector3(-radius, -radius, -radius), Vector3(radius, radius, radius)));
mesh->_setBoundingSphereRadius(radius);
VertexData *vertexData = mesh->sharedVertexData;
vertexData->vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
vertexData->vertexDeclaration->addElement(1, 0, VET_FLOAT3, VES_NORMAL);
vertexData->vertexCount = slices * (stacks + 1);
HardwareVertexBufferSharedPtr positionBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
vertexData->vertexDeclaration->getVertexSize(0),
vertexData->vertexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
HardwareVertexBufferSharedPtr normalBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
vertexData->vertexDeclaration->getVertexSize(1),
vertexData->vertexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
float *position = static_cast<float *>(positionBuffer->lock(HardwareBuffer::HBL_DISCARD));
float *normal = static_cast<float *>(normalBuffer->lock(HardwareBuffer::HBL_DISCARD));
for (int ring = 0; ring <= stacks; ring++) {
float r = radius * sinf(ring * Math::PI / stacks);
float y = radius * cosf(ring * Math::PI / stacks);
for (int segment = 0; segment < slices; segment++) {
float x = r * sinf(segment * 2 * Math::PI / slices);
float z = r * cosf(segment * 2 * Math::PI / slices);
*position++ = x;
*position++ = y;
*position++ = z;
Vector3 tmp = Vector3(x, y, z).normalisedCopy();
*normal++ = tmp.x;
*normal++ = tmp.y;
*normal++ = tmp.z;
}
}
positionBuffer->unlock();
normalBuffer->unlock();
vertexData->vertexBufferBinding->setBinding(0, positionBuffer);
vertexData->vertexBufferBinding->setBinding(1, normalBuffer);
SubMesh *subMesh = mesh->createSubMesh();
subMesh->useSharedVertices = true;
IndexData *indexData = subMesh->indexData;
indexData->indexCount = 6 * slices * stacks;
HardwareIndexBufferSharedPtr indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
indexData->indexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
unsigned short *index = static_cast<unsigned short *>(indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
unsigned short i = 0;
for (int ring = 0; ring < stacks; ring++) {
for (int segment = 0; segment < slices - 1; segment++) {
*index++ = i;
*index++ = i + slices;
*index++ = i + slices + 1;
*index++ = i;
*index++ = i + slices + 1;
*index++ = i + 1;
i++;
}
*index++ = i;
*index++ = i + slices;
*index++ = i + 1;
*index++ = i;
*index++ = i + 1;
*index++ = i + 1 - slices;
i++;
}
indexBuffer->unlock();
indexData->indexBuffer = indexBuffer;
mesh->load();
}