本文整理汇总了C++中HardwareIndexBufferSharedPtr类的典型用法代码示例。如果您正苦于以下问题:C++ HardwareIndexBufferSharedPtr类的具体用法?C++ HardwareIndexBufferSharedPtr怎么用?C++ HardwareIndexBufferSharedPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HardwareIndexBufferSharedPtr类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getIndex
//.........这里部分代码省略.........
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();
}
示例2: ResourceBuffer
//.........这里部分代码省略.........
nodeIDs[i]=(int)(texcoords[i].x);
}
//textures coordinates
for (i=0; i<nVertices; i++)
{
covertices[i].texcoord=Vector2(texcoords[i].y,texcoords[i].z);
}
/// Define triangles
/// The values in this table refer to vertices in the above table
ibufCount = 3*numtriangles;
faces=(unsigned short*)malloc(ibufCount*sizeof(unsigned short));
for (i=0; i<ibufCount; i++)
{
faces[i]=findID(i/3, triangles[i], numsubmeshes, subtexindex, subtriindex);
}
sref=(float*)malloc(numtriangles*sizeof(float));
for (i=0; i<(unsigned int)numtriangles;i++)
{
Vector3 v1, v2;
v1=nodes[nodeIDs[faces[i*3+1]]].RelPosition-nodes[nodeIDs[faces[i*3]]].RelPosition;
v2=nodes[nodeIDs[faces[i*3+2]]].RelPosition-nodes[nodeIDs[faces[i*3]]].RelPosition;
v1=v1.crossProduct(v2);
sref[i]=v1.length()*2.0;
}
//update coords
updateVertices();
/// Create vertex data structure for vertices shared between submeshes
msh->sharedVertexData = new VertexData();
msh->sharedVertexData->vertexCount = nVertices;
/// Create declaration (memory format) of vertex data
decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
// decl->addElement(0, offset, VET_FLOAT3, VES_DIFFUSE);
// offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
offset += VertexElement::getTypeSize(VET_FLOAT2);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
/// Set parameters of the submeshes
for (j=0; j<numsubmeshes; j++)
{
int smcount=3*(subtriindex[j+1]-subtriindex[j]);
subs[j]->useSharedVertices = true;
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
smcount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
ibuf->writeData(0, ibuf->getSizeInBytes(), &faces[subtriindex[j]*3], true);
subs[j]->indexData->indexBuffer = ibuf;
subs[j]->indexData->indexCount = smcount;
subs[j]->indexData->indexStart = 0;
}
/// Set bounding information (for culling)
msh->_setBounds(AxisAlignedBox(-100,-100,-100,100,100,100), true);
//msh->_setBoundingSphereRadius(100);
/// Notify Mesh object that it has been loaded
msh->load();
msh->buildEdgeList();
}
示例3: Airfoil
//.........这里部分代码省略.........
updateVertices();
/// Create vertex data structure for 8 vertices shared between submeshes
msh->sharedVertexData = new VertexData();
msh->sharedVertexData->vertexCount = nVertices;
/// Create declaration (memory format) of vertex data
decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
// decl->addElement(0, offset, VET_FLOAT3, VES_DIFFUSE);
// offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
offset += VertexElement::getTypeSize(VET_FLOAT2);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
//for the face
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr faceibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
faceibufCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
faceibuf->writeData(0, faceibuf->getSizeInBytes(), facefaces, true);
/// Set parameters of the submesh
subface->useSharedVertices = true;
subface->indexData->indexBuffer = faceibuf;
subface->indexData->indexCount = faceibufCount;
subface->indexData->indexStart = 0;
//for the band
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr bandibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
bandibufCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
bandibuf->writeData(0, bandibuf->getSizeInBytes(), bandfaces, true);
/// Set parameters of the submesh
subband->useSharedVertices = true;
subband->indexData->indexBuffer = bandibuf;
subband->indexData->indexCount = bandibufCount;
subband->indexData->indexStart = 0;
//for the aileron up
示例4: pt
void OgreToBulletMesh::getMeshInformation(MeshPtr mesh, unsigned& vertex_count, std::vector<Vector3>& vertices,
unsigned& index_count, std::vector<unsigned>& indices, const Vector3& position,
const Quaternion& orientation, const Vector3& scale)
{
bool added_shared = false;
unsigned current_offset = 0;
unsigned shared_offset = 0;
unsigned next_offset = 0;
unsigned index_offset = 0;
vertex_count = index_count = 0;
for (uint16_t i = 0; i < mesh->getNumSubMeshes(); ++i)
{
SubMesh* submesh = mesh->getSubMesh(i);
if (submesh->useSharedVertices)
{
if (!added_shared)
{
vertex_count += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else
vertex_count += submesh->vertexData->vertexCount;
index_count += submesh->indexData->indexCount;
}
vertices.clear();
vertices.reserve(vertex_count);
indices.clear();
indices.reserve(index_count);
added_shared = false;
for (uint16_t i = 0; i < mesh->getNumSubMeshes(); ++i)
{
SubMesh* submesh = mesh->getSubMesh(i);
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 VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(VertexElementSemantic::VES_POSITION);
HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
uint8_t* vertex = (uint8_t*)vbuf->lock(HardwareBuffer::LockOptions::HBL_READ_ONLY);
float* pReal;
for (int 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] = (orientation * (pt * scale)) + position;
}
vbuf->unlock();
next_offset += vertex_data->vertexCount;
}
IndexData* index_data = submesh->indexData;
uint numTris = index_data->indexCount / 3;
HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
bool use32bitindexes = (ibuf->getType() == HardwareIndexBuffer::IndexType::IT_32BIT);
uint* pLong = (uint*)ibuf->lock(HardwareBuffer::LockOptions::HBL_READ_ONLY);
ushort* pShort = (ushort*)pLong;
uint offset = submesh->useSharedVertices ? shared_offset : current_offset;
if (use32bitindexes)
for (int k = 0; k < index_data->indexCount; ++k)
indices[index_offset++] = pLong[k] + offset;
else
for (int k = 0; k < index_data->indexCount; ++k)
indices[index_offset++] = (uint)pShort[k] + (uint)offset;
ibuf->unlock();
current_offset = next_offset;
}
}
示例5: VertexData
//.........这里部分代码省略.........
{
rs->convertColourValue(ColourValue(colors[0],colors[1],colors[2],
colors[3]),pColour++);
colors += 4;
}
decl->addElement(nextBuf, 0, VET_COLOUR, VES_DIFFUSE);
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_COLOUR),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB.front(), true);
bind->setBinding(nextBuf++, vbuf);
}
if (data->uvlist.length)
{
decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES);
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_FLOAT2),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY,false);
if(flip)
{
float *datamod = new float[data->uvlist.length];
for(unsigned int i = 0; i < data->uvlist.length; i+=2){
float x = *(data->uvlist.ptr + i);
float y = *(data->uvlist.ptr + i + 1);
datamod[i] =x;
datamod[i + 1] =y;
}
vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false);
delete [] datamod;
}
else
vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, false);
bind->setBinding(nextBuf++, vbuf);
}
// Triangle faces - The total number of triangle points
int numFaces = data->triangles.length;
if (numFaces)
{
sub->indexData->indexCount = numFaces;
sub->indexData->indexStart = 0;
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
numFaces,
HardwareBuffer::HBU_STATIC_WRITE_ONLY, true);
if(flip && mFlipVertexWinding && sub->indexData->indexCount % 3 == 0){
sub->indexData->indexBuffer = ibuf;
uint16 *datamod = new uint16[numFaces];
int index = 0;
for (size_t i = 0; i < sub->indexData->indexCount; i+=3)
{
const short *pos = data->triangles.ptr + index;
uint16 i0 = (uint16) *(pos+0);
uint16 i1 = (uint16) *(pos+1);
uint16 i2 = (uint16) *(pos+2);
//std::cout << "i0: " << i0 << "i1: " << i1 << "i2: " << i2 << "\n";
datamod[index] = i2;
datamod[index+1] = i1;
datamod[index+2] = i0;
index += 3;
}
ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false);
delete [] datamod;
}
else
ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false);
sub->indexData->indexBuffer = ibuf;
}
// Set material if one was given
if (!material.empty()) sub->setMaterialName(material);
//add vertex bone assignments
for (std::list<VertexBoneAssignment>::iterator it = vertexBoneAssignments.begin();
it != vertexBoneAssignments.end(); it++)
{
sub->addBoneAssignment(*it);
}
if(mSkel.isNull())
needBoneAssignments.push_back(sub);
}
示例6: createOgreMesh
// Convert Nif::NiTriShape to Ogre::SubMesh, attached to the given
// mesh.
static void createOgreMesh(Mesh *mesh, NiTriShape *shape, const String &material)
{
NiTriShapeData *data = shape->data.getPtr();
SubMesh *sub = mesh->createSubMesh(shape->name.toString());
int nextBuf = 0;
// This function is just one long stream of Ogre-barf, but it works
// great.
// Add vertices
int numVerts = data->vertices.length / 3;
sub->vertexData = new VertexData();
sub->vertexData->vertexCount = numVerts;
sub->useSharedVertices = false;
VertexDeclaration *decl = sub->vertexData->vertexDeclaration;
decl->addElement(nextBuf, 0, VET_FLOAT3, VES_POSITION);
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_FLOAT3),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), data->vertices.ptr, true);
VertexBufferBinding* bind = sub->vertexData->vertexBufferBinding;
bind->setBinding(nextBuf++, vbuf);
// Vertex normals
if(data->normals.length)
{
decl->addElement(nextBuf, 0, VET_FLOAT3, VES_NORMAL);
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_FLOAT3),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), data->normals.ptr, true);
bind->setBinding(nextBuf++, vbuf);
}
// Vertex colors
if(data->colors.length)
{
const float *colors = data->colors.ptr;
RenderSystem* rs = Root::getSingleton().getRenderSystem();
std::vector<RGBA> colorsRGB(numVerts);
RGBA *pColour = &colorsRGB.front();
for(int i=0; i<numVerts; i++)
{
rs->convertColourValue(ColourValue(colors[0],colors[1],colors[2],
colors[3]),pColour++);
colors += 4;
}
decl->addElement(nextBuf, 0, VET_COLOUR, VES_DIFFUSE);
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_COLOUR),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB.front(), true);
bind->setBinding(nextBuf++, vbuf);
}
// Texture UV coordinates
if(data->uvlist.length)
{
decl->addElement(nextBuf, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES);
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
VertexElement::getTypeSize(VET_FLOAT2),
numVerts, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, true);
bind->setBinding(nextBuf++, vbuf);
}
// Triangle faces
int numFaces = data->triangles.length;
if(numFaces)
{
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
numFaces,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, true);
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = numFaces;
sub->indexData->indexStart = 0;
}
// Set material if one was given
if(!material.empty()) sub->setMaterialName(material);
/* Old commented D code. Might be useful when reimplementing
animation.
// Assign this submesh to the given bone
VertexBoneAssignment v;
v.boneIndex = ((Bone*)bone)->getHandle();
v.weight = 1.0;
std::cerr << "+ Assigning bone index " << v.boneIndex << "\n";
for(int i=0; i < numVerts; i++)
{
v.vertexIndex = i;
//.........这里部分代码省略.........
示例7: createIndexBuffer
//-----------------------------------------------------------------------
void MeshManager::tesselate2DMesh(SubMesh* sm, unsigned short meshWidth, unsigned short meshHeight,
bool doubleSided, HardwareBuffer::Usage indexBufferUsage, bool indexShadowBuffer)
{
// The mesh is built, just make a list of indexes to spit out the triangles
unsigned short vInc, v, iterations;
if (doubleSided)
{
iterations = 2;
vInc = 1;
v = 0; // Start with front
}
else
{
iterations = 1;
vInc = 1;
v = 0;
}
// Allocate memory for faces
// Num faces, width*height*2 (2 tris per square), index count is * 3 on top
sm->indexData->indexCount = (meshWidth-1) * (meshHeight-1) * 2 * iterations * 3;
sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
createIndexBuffer(HardwareIndexBuffer::IT_16BIT,
sm->indexData->indexCount, indexBufferUsage, indexShadowBuffer);
unsigned short v1, v2, v3;
//bool firstTri = true;
HardwareIndexBufferSharedPtr ibuf = sm->indexData->indexBuffer;
// Lock the whole buffer
unsigned short* pIndexes = static_cast<unsigned short*>(
ibuf->lock(HardwareBuffer::HBL_DISCARD) );
while (iterations--)
{
// Make tris in a zigzag pattern (compatible with strips)
unsigned short u = 0;
unsigned short uInc = 1; // Start with moving +u
unsigned short vCount = meshHeight - 1;
while (vCount--)
{
unsigned short uCount = meshWidth - 1;
while (uCount--)
{
// First Tri in cell
// -----------------
v1 = ((v + vInc) * meshWidth) + u;
v2 = (v * meshWidth) + u;
v3 = ((v + vInc) * meshWidth) + (u + uInc);
// Output indexes
*pIndexes++ = v1;
*pIndexes++ = v2;
*pIndexes++ = v3;
// Second Tri in cell
// ------------------
v1 = ((v + vInc) * meshWidth) + (u + uInc);
v2 = (v * meshWidth) + u;
v3 = (v * meshWidth) + (u + uInc);
// Output indexes
*pIndexes++ = v1;
*pIndexes++ = v2;
*pIndexes++ = v3;
// Next column
u += uInc;
}
// Next row
v += vInc;
u = 0;
}
// Reverse vInc for double sided
v = meshHeight - 1;
vInc = -vInc;
}
// Unlock
ibuf->unlock();
}
示例8: assert
void GeomUtils::createSphere(VertexData*& vertexData, IndexData*& indexData
, float radius
, int nRings, int nSegments
, bool bNormals
, bool bTexCoords)
{
assert(vertexData && indexData);
// 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);
if (bNormals)
{
// normals
vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL);
currOffset += VertexElement::getTypeSize(VET_FLOAT3);
}
// two dimensional texture coordinates
if (bTexCoords)
{
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
indexData->indexCount = 6 * nRings * (nSegments + 1);
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));
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 = radius * sinf (ring * fDeltaRingAngle);
float y0 = radius * 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;
if (bNormals)
{
Vector3 vNormal = Vector3(x0, y0, z0).normalisedCopy();
*pVertex++ = vNormal.x;
*pVertex++ = vNormal.y;
*pVertex++ = vNormal.z;
}
if (bTexCoords)
{
*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();
}
示例9:
//.........这里部分代码省略.........
for ( size_t i = 0; i < mpMesh->getNumSubMeshes(); ++i) {
SubMesh* submesh = mpMesh->getSubMesh(i);
bool useSharedVertices = submesh->useSharedVertices;
//----------------------------------------------------------------
// GET VERTEXDATA
//----------------------------------------------------------------
const VertexData * vertex_data;
if(useSoftwareBlendingVertices)
vertex_data = useSharedVertices ? pEntity->_getSkelAnimVertexData() : pEntity->getSubEntity(i)->_getSkelAnimVertexData();
else vertex_data = useSharedVertices ? mpMesh->sharedVertexData : submesh->vertexData;
if((!useSharedVertices)||(useSharedVertices && !added_shared))
{
if(useSharedVertices)
{
added_shared = true;
shared_offset = current_offset;
}
const VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char* vertex =
static_cast<unsigned char*>(vbuf->lock(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 is
// comiled/typedefed as double:
float* pReal;
mlVertices.reserve(mlVertices.size()+vertex_data->vertexCount);
for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
if (mlVertices.size() == 0) {
mvMin.x = mvMax.x = pReal[0];
mvMin.y = mvMax.y = pReal[1];
mvMin.z = mvMax.z = pReal[2];
} else {
if (mvMin.x > pReal[0]) mvMin.x = pReal[0];
if (mvMin.y > pReal[1]) mvMin.y = pReal[1];
if (mvMin.z > pReal[2]) mvMin.z = pReal[2];
if (mvMax.x < pReal[0]) mvMax.x = pReal[0];
if (mvMax.y < pReal[1]) mvMax.y = pReal[1];
if (mvMax.z < pReal[2]) mvMax.z = pReal[2];
}
mlVertices.push_back(Vector3(pReal[0],pReal[1],pReal[2]));
}
vbuf->unlock();
next_offset += vertex_data->vertexCount;
}
// TODO : GET TEXCOORD DATA
// TODO : GET FACE-MATERIAL MAP, or at least material cound....
// TODO : no need to update index, texcoord and material buffers for animation !
// TODO : const VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);
// for texture alpha checking, VertexElementType should be VET_FLOAT2
//----------------------------------------------------------------
// GET INDEXDATA
//----------------------------------------------------------------
IndexData* index_data = submesh->indexData;
size_t numTris = index_data->indexCount / 3;
HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
bool use32bitindexes = (ibuf->getType() == HardwareIndexBuffer::IT_32BIT);
::uint32 *pLong = static_cast< ::uint32*>(ibuf->lock(HardwareBuffer::HBL_READ_ONLY));
::uint16* pShort = reinterpret_cast< ::uint16*>(pLong);
size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;
mlIndices.reserve(mlIndices.size()+3*numTris);
if ( use32bitindexes )
{
for ( size_t k = 0; k < numTris*3; ++k)
{
mlIndices.push_back(pLong[k] + static_cast<int>(offset));
}
}
else
{
for ( size_t k = 0; k < numTris*3; ++k)
{
mlIndices.push_back(static_cast<int>(pShort[k]) + static_cast<int>(offset));
}
}
ibuf->unlock();
current_offset = next_offset;
}
//mvMid = 0.5*(mvMin + mvMax);
//mfBoundRad = 0.5 * (mvMax - mvMin).length();
}
示例10: 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();
}
示例11: VertexData
void Obstacle::createSphere(const std::string& strName, const float r, const int nRings, const int nSegments)
{
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();
}
示例12: switch
void ModelConverter::WriteSubMesh( DiSubMesh* subMod, const Ogre::SubMesh* s )
{
switch(s->operationType)
{
case RenderOperation::OT_LINE_LIST:
subMod->SetPrimitiveType(D3DPT_LINELIST);
break;
case RenderOperation::OT_LINE_STRIP:
subMod->SetPrimitiveType(D3DPT_LINESTRIP);
break;
case RenderOperation::OT_POINT_LIST:
subMod->SetPrimitiveType(D3DPT_POINTLIST);
break;
case RenderOperation::OT_TRIANGLE_FAN:
subMod->SetPrimitiveType(D3DPT_TRIANGLEFAN);
break;
case RenderOperation::OT_TRIANGLE_LIST:
subMod->SetPrimitiveType(PT_TRIANGLELIST);
break;
case RenderOperation::OT_TRIANGLE_STRIP:
subMod->SetPrimitiveType(D3DPT_TRIANGLESTRIP);
break;
}
VertexData* vertexData = nullptr;
if (mMesh->sharedVertexData)
{
vertexData = mMesh->sharedVertexData;
}
else
{
vertexData = s->vertexData;
}
int numFaces = 0;
switch(s->operationType)
{
case RenderOperation::OT_TRIANGLE_LIST:
// triangle list
numFaces = s->indexData->indexCount / 3;
break;
case RenderOperation::OT_LINE_LIST:
numFaces = s->indexData->indexCount / 2;
break;
case RenderOperation::OT_TRIANGLE_FAN:
case RenderOperation::OT_TRIANGLE_STRIP:
// triangle fan or triangle strip
numFaces = s->indexData->indexCount - 2;
break;
default:
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Unsupported render operation type",
__FUNCTION__);
}
subMod->SetPrimitiveCount(numFaces);
subMod->SetVerticeNum(vertexData->vertexCount);
// material name
DiString matName;
matName.Format("%s_%d.mtl",subMod->GetParentMesh()->GetName().c_str(),subMod->GetIndex());
subMod->SetMaterialName(matName);
bool use32BitIndexes = (!s->indexData->indexBuffer.isNull() &&
s->indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_32BIT);
// Write each face in turn
unsigned int* pInt = 0;
unsigned short* pShort = 0;
HardwareIndexBufferSharedPtr ibuf = s->indexData->indexBuffer;
// index data
if (use32BitIndexes)
{
pInt = static_cast<unsigned int*>(
ibuf->lock(HardwareBuffer::HBL_READ_ONLY));
}
else
{
pShort = static_cast<unsigned short*>(
ibuf->lock(HardwareBuffer::HBL_READ_ONLY));
}
void* indata = subMod->CreateIndexData(s->indexData->indexCount,use32BitIndexes?TRUE:FALSE);
if (use32BitIndexes)
{
memcpy(indata,pInt,sizeof(unsigned int)*s->indexData->indexCount);
}
else
{
memcpy(indata,pShort,sizeof(unsigned short)*s->indexData->indexCount);
}
ibuf->unlock();
// vertex declaration
VertexDeclaration* decl = vertexData->vertexDeclaration;
//.........这里部分代码省略.........
示例13: generateShadowVolume
// ------------------------------------------------------------------------
void ShadowCaster::generateShadowVolume(EdgeData* edgeData,
const HardwareIndexBufferSharedPtr& indexBuffer, const Light* light,
ShadowRenderableList& shadowRenderables, unsigned long flags)
{
// Edge groups should be 1:1 with shadow renderables
assert(edgeData->edgeGroups.size() == shadowRenderables.size());
// Whether to use the McGuire method, a triangle fan covering all silhouette
// this won't work properly with multiple separate edge groups
bool useMcGuire = edgeData->edgeGroups.size() <= 1;
EdgeData::EdgeGroupList::const_iterator egi, egiend;
ShadowRenderableList::const_iterator si;
Light::LightTypes lightType = light->getType();
// pre-count the size of index data we need since it makes a big perf difference
// to GL in particular if we lock a smaller area of the index buffer
size_t preCountIndexes = 0;
si = shadowRenderables.begin();
egiend = edgeData->edgeGroups.end();
for (egi = edgeData->edgeGroups.begin(); egi != egiend; ++egi, ++si)
{
const EdgeData::EdgeGroup& eg = *egi;
bool firstDarkCapTri = true;
EdgeData::EdgeList::const_iterator i, iend;
iend = eg.edges.end();
for (i = eg.edges.begin(); i != iend; ++i)
{
const EdgeData::Edge& edge = *i;
// Silhouette edge, when two tris has opposite light facing, or
// degenerate edge where only tri 1 is valid and the tri light facing
char lightFacing = edgeData->triangleLightFacings[edge.triIndex[0]];
if ((edge.degenerate && lightFacing) ||
(!edge.degenerate && (lightFacing != edgeData->triangleLightFacings[edge.triIndex[1]])))
{
preCountIndexes += 3;
// Are we extruding to infinity?
if (!(lightType == Light::LT_DIRECTIONAL &&
flags & SRF_EXTRUDE_TO_INFINITY))
{
preCountIndexes += 3;
}
if(useMcGuire)
{
// Do dark cap tri
// Use McGuire et al method, a triangle fan covering all silhouette
// edges and one point (taken from the initial tri)
if (flags & SRF_INCLUDE_DARK_CAP)
{
if (firstDarkCapTri)
{
firstDarkCapTri = false;
}
else
{
preCountIndexes += 3;
}
}
}
}
}
if(useMcGuire)
{
// Do light cap
if (flags & SRF_INCLUDE_LIGHT_CAP)
{
// Iterate over the triangles which are using this vertex set
EdgeData::TriangleList::const_iterator ti, tiend;
EdgeData::TriangleLightFacingList::const_iterator lfi;
ti = edgeData->triangles.begin() + eg.triStart;
tiend = ti + eg.triCount;
lfi = edgeData->triangleLightFacings.begin() + eg.triStart;
for ( ; ti != tiend; ++ti, ++lfi)
{
const EdgeData::Triangle& t = *ti;
assert(t.vertexSet == eg.vertexSet);
// Check it's light facing
if (*lfi)
{
preCountIndexes += 3;
}
}
}
}
else
{
// Do both caps
int increment = ((flags & SRF_INCLUDE_DARK_CAP) ? 3 : 0) + ((flags & SRF_INCLUDE_LIGHT_CAP) ? 3 : 0);
if(increment != 0)
{
//.........这里部分代码省略.........