本文整理汇总了C++中HardwareIndexBufferSharedPtr::writeData方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwareIndexBufferSharedPtr::writeData方法的具体用法?C++ HardwareIndexBufferSharedPtr::writeData怎么用?C++ HardwareIndexBufferSharedPtr::writeData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HardwareIndexBufferSharedPtr
的用法示例。
在下文中一共展示了HardwareIndexBufferSharedPtr::writeData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createPlane
//---------------------------------------------------------------------
void PrefabFactory::createPlane(Mesh* mesh)
{
SubMesh* sub = mesh->createSubMesh();
float vertices[32] = {
-100, -100, 0, // pos
0,0,1, // normal
0,1, // texcoord
100, -100, 0,
0,0,1,
1,1,
100, 100, 0,
0,0,1,
1,0,
-100, 100, 0 ,
0,0,1,
0,0
};
mesh->sharedVertexData = OGRE_NEW VertexData();
mesh->sharedVertexData->vertexCount = 4;
VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration;
VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding;
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_FLOAT2, VES_TEXTURE_COORDINATES, 0);
offset += VertexElement::getTypeSize(VET_FLOAT2);
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
bind->setBinding(0, vbuf);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
sub->useSharedVertices = true;
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
6,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
unsigned short faces[6] = {0,1,2,
0,2,3 };
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = 6;
sub->indexData->indexStart =0;
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
mesh->_setBounds(AxisAlignedBox(-100,-100,0,100,100,0), true);
mesh->_setBoundingSphereRadius(Math::Sqrt(100*100+100*100));
}
示例2: initialise
void VolumeRenderable::initialise()
{
// Create geometry
size_t nvertices = mSlices*4; // n+1 planes
size_t elemsize = 3*3;
size_t dsize = elemsize*nvertices;
size_t x;
Ogre::IndexData *idata = new Ogre::IndexData();
Ogre::VertexData *vdata = new Ogre::VertexData();
// Create structures
float *vertices = new float[dsize];
float coords[4][2] = {
{0.0f, 0.0f},
{0.0f, 1.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
for(x=0; x<mSlices; x++)
{
for(size_t y=0; y<4; y++)
{
float xcoord = coords[y][0]-0.5;
float ycoord = coords[y][1]-0.5;
float zcoord = -((float)x/(float)(mSlices-1) - 0.5f);
// 1.0f .. a/(a+1)
// coordinate
vertices[x*4*elemsize+y*elemsize+0] = xcoord*(mSize/2.0f);
vertices[x*4*elemsize+y*elemsize+1] = ycoord*(mSize/2.0f);
vertices[x*4*elemsize+y*elemsize+2] = zcoord*(mSize/2.0f);
// normal
vertices[x*4*elemsize+y*elemsize+3] = 0.0f;
vertices[x*4*elemsize+y*elemsize+4] = 0.0f;
vertices[x*4*elemsize+y*elemsize+5] = 1.0f;
// tex
vertices[x*4*elemsize+y*elemsize+6] = xcoord*sqrtf(3.0f);
vertices[x*4*elemsize+y*elemsize+7] = ycoord*sqrtf(3.0f);
vertices[x*4*elemsize+y*elemsize+8] = zcoord*sqrtf(3.0f);
}
}
unsigned short *faces = new unsigned short[mSlices*6];
for(x=0; x<mSlices; x++)
{
faces[x*6+0] = x*4+0;
faces[x*6+1] = x*4+1;
faces[x*6+2] = x*4+2;
faces[x*6+3] = x*4+1;
faces[x*6+4] = x*4+2;
faces[x*6+5] = x*4+3;
}
// Setup buffers
vdata->vertexStart = 0;
vdata->vertexCount = nvertices;
VertexDeclaration* decl = vdata->vertexDeclaration;
VertexBufferBinding* bind = vdata->vertexBufferBinding;
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_TEXTURE_COORDINATES);
offset += VertexElement::getTypeSize(VET_FLOAT3);
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, nvertices, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
bind->setBinding(0, vbuf);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
mSlices*6,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
idata->indexBuffer = ibuf;
idata->indexCount = mSlices*6;
idata->indexStart = 0;
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
// Delete temporary buffers
delete [] vertices;
delete [] faces;
// Now make the render operation
mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.indexData = idata;
mRenderOp.vertexData = vdata;
mRenderOp.useIndexes = true;
// Create a brand new private material
MaterialPtr material =
MaterialManager::getSingleton().create(mTexture, "VolumeRenderable",
false, 0); // Manual, loader
//.........这里部分代码省略.........
示例3: idstart
//.........这里部分代码省略.........
covertices[i*6+4 ].texcoord=Vector2((float)i/(float)nrays, 0.77f);
covertices[i*6+5 ].texcoord=Vector2((float)i/(float)nrays, 1.00f);
}
/// Define triangles
/// The values in this table refer to vertices in the above table
ibufCount = 3*10*nrays;
faces=(unsigned short*)malloc(ibufCount*sizeof(unsigned short));
for (i=0; i<nrays; i++)
{
faces[3*(i*10 )]=i*6; faces[3*(i*10 )+1]=i*6+1; faces[3*(i*10 )+2]=(i+1)*6;
faces[3*(i*10+1)]=i*6+1; faces[3*(i*10+1)+1]=(i+1)*6+1; faces[3*(i*10+1)+2]=(i+1)*6;
faces[3*(i*10+2)]=i*6+1; faces[3*(i*10+2)+1]=i*6+2; faces[3*(i*10+2)+2]=(i+1)*6+1;
faces[3*(i*10+3)]=i*6+2; faces[3*(i*10+3)+1]=(i+1)*6+2; faces[3*(i*10+3)+2]=(i+1)*6+1;
faces[3*(i*10+4)]=i*6+2; faces[3*(i*10+4)+1]=i*6+3; faces[3*(i*10+4)+2]=(i+1)*6+2;
faces[3*(i*10+5)]=i*6+3; faces[3*(i*10+5)+1]=(i+1)*6+3; faces[3*(i*10+5)+2]=(i+1)*6+2;
faces[3*(i*10+6)]=i*6+3; faces[3*(i*10+6)+1]=i*6+4; faces[3*(i*10+6)+2]=(i+1)*6+3;
faces[3*(i*10+7)]=i*6+4; faces[3*(i*10+7)+1]=(i+1)*6+4; faces[3*(i*10+7)+2]=(i+1)*6+3;
faces[3*(i*10+8)]=i*6+4; faces[3*(i*10+8)+1]=i*6+5; faces[3*(i*10+8)+2]=(i+1)*6+4;
faces[3*(i*10+9)]=i*6+5; faces[3*(i*10+9)+1]=(i+1)*6+5; faces[3*(i*10+9)+2]=(i+1)*6+4;
}
normy=1.0;
//update coords
updateVertices();
//compute normy;
normy=((covertices[0].vertex-covertices[1].vertex).crossProduct(covertices[1].vertex-covertices[6+1].vertex)).length();
//recompute for normals
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 ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
ibufCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
/// Set parameters of the submesh
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
/// Set bounding information (for culling)
msh->_setBounds(AxisAlignedBox(-1,-1,0,1,1,0), true);
//msh->_setBoundingSphereRadius(Math::Sqrt(1*1+1*1));
/// Notify Mesh object that it has been loaded
//msh->buildTangentVectors();
/*unsigned short src, dest;
if (!msh->suggestTangentVectorBuildParams(src, dest))
{
msh->buildTangentVectors(src, dest);
}
*/
msh->load();
//msh->touch();
// msh->load();
//msh->buildEdgeList();
}
示例4: verts
//.........这里部分代码省略.........
m_vertices[2+i*2].texcoord=Vector2(0.5+0.5*sin(i*2.0*3.14159/nrays), 0.5+0.5*cos(i*2.0*3.14159/nrays));
m_vertices[2+i*2+1].texcoord=m_vertices[2+i*2].texcoord;
}
}
// Define triangles
// The values in this table refer to vertices in the above table
size_t tiretread_num_indices = 3*2*nrays;
size_t wheelface_num_indices = 3*2*nrays;
if (m_is_rimmed) wheelface_num_indices=wheelface_num_indices*3;
m_wheelface_indices=(unsigned short*)malloc(wheelface_num_indices*sizeof(unsigned short));
m_tiretread_indices=(unsigned short*)malloc(tiretread_num_indices*sizeof(unsigned short));
for (i=0; i<nrays; i++)
{
//wheel sides
m_wheelface_indices[3*(i*2)]=0; m_wheelface_indices[3*(i*2)+1]=2+i*2; m_wheelface_indices[3*(i*2)+2]=2+((i+1)%nrays)*2;
m_wheelface_indices[3*(i*2+1)]=1; m_wheelface_indices[3*(i*2+1)+2]=2+i*2+1; m_wheelface_indices[3*(i*2+1)+1]=2+((i+1)%nrays)*2+1;
if (m_is_rimmed)
{
m_wheelface_indices[3*(i*4+0+2*nrays)]=2+i*2; m_wheelface_indices[3*(i*4+0+2*nrays)+1]=2+4*nrays+i*2; m_wheelface_indices[3*(i*4+0+2*nrays)+2]=2+((i+1)%nrays)*2;
m_wheelface_indices[3*(i*4+1+2*nrays)]=2+4*nrays+i*2; m_wheelface_indices[3*(i*4+1+2*nrays)+1]=2+4*nrays+((i+1)%nrays)*2; m_wheelface_indices[3*(i*4+1+2*nrays)+2]=2+((i+1)%nrays)*2;
m_wheelface_indices[3*(i*4+2+2*nrays)]=2+i*2+1; m_wheelface_indices[3*(i*4+2+2*nrays)+2]=2+4*nrays+i*2+1; m_wheelface_indices[3*(i*4+2+2*nrays)+1]=2+((i+1)%nrays)*2+1;
m_wheelface_indices[3*(i*4+3+2*nrays)]=2+4*nrays+i*2+1; m_wheelface_indices[3*(i*4+3+2*nrays)+2]=2+4*nrays+((i+1)%nrays)*2+1; m_wheelface_indices[3*(i*4+3+2*nrays)+1]=2+((i+1)%nrays)*2+1;
}
//wheel band
m_tiretread_indices[3*(i*2)]=2+2*nrays+i*2; m_tiretread_indices[3*(i*2)+1]=2+2*nrays+i*2+1; m_tiretread_indices[3*(i*2)+2]=2+2*nrays+((i+1)%nrays)*2;
m_tiretread_indices[3*(i*2+1)]=2+2*nrays+((i+1)%nrays)*2; m_tiretread_indices[3*(i*2+1)+2]=2+2*nrays+((i+1)%nrays)*2+1; m_tiretread_indices[3*(i*2+1)+1]=2+2*nrays+i*2+1;
}
//update coords
updateVertices();
// Create vertex data structure for 8 vertices shared between submeshes
m_mesh->sharedVertexData = new VertexData();
m_mesh->sharedVertexData->vertexCount = vertex_count;
// Create declaration (memory format) of vertex data
m_vertex_format = m_mesh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
m_vertex_format->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
m_vertex_format->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
// m_vertex_format->addElement(0, offset, VET_FLOAT3, VES_DIFFUSE);
// offset += VertexElement::getTypeSize(VET_FLOAT3);
m_vertex_format->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)
m_hw_vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, m_mesh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
// Upload the vertex data to the card
m_hw_vbuf->writeData(0, m_hw_vbuf->getSizeInBytes(), m_vertices, true);
// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = m_mesh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, m_hw_vbuf);
//for the sideface
// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr faceibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
wheelface_num_indices,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the index data to the card
faceibuf->writeData(0, faceibuf->getSizeInBytes(), m_wheelface_indices, true);
// Set parameters of the submesh
m_submesh_wheelface->useSharedVertices = true;
m_submesh_wheelface->indexData->indexBuffer = faceibuf;
m_submesh_wheelface->indexData->indexCount = wheelface_num_indices;
m_submesh_wheelface->indexData->indexStart = 0;
//for the band
// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr bandibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
tiretread_num_indices,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the index data to the card
bandibuf->writeData(0, bandibuf->getSizeInBytes(), m_tiretread_indices, true);
// Set parameters of the submesh
m_submesh_tiretread->useSharedVertices = true;
m_submesh_tiretread->indexData->indexBuffer = bandibuf;
m_submesh_tiretread->indexData->indexCount = tiretread_num_indices;
m_submesh_tiretread->indexData->indexStart = 0;
// Set bounding information (for culling)
m_mesh->_setBounds(AxisAlignedBox(-1,-1,0,1,1,0), true);
m_mesh->load();
}
示例5: nbrays
//.........这里部分代码省略.........
facefaces[3*(i*2+1)]=1; facefaces[3*(i*2+1)+2]=2+i*2+1; facefaces[3*(i*2+1)+1]=2+((i+1)%nrays)*2+1;
if (is_rimmed)
{
facefaces[3*(i*4+0+2*nrays)]=2+i*2; facefaces[3*(i*4+0+2*nrays)+1]=2+4*nrays+i*2; facefaces[3*(i*4+0+2*nrays)+2]=2+((i+1)%nrays)*2;
facefaces[3*(i*4+1+2*nrays)]=2+4*nrays+i*2; facefaces[3*(i*4+1+2*nrays)+1]=2+4*nrays+((i+1)%nrays)*2; facefaces[3*(i*4+1+2*nrays)+2]=2+((i+1)%nrays)*2;
facefaces[3*(i*4+2+2*nrays)]=2+i*2+1; facefaces[3*(i*4+2+2*nrays)+2]=2+4*nrays+i*2+1; facefaces[3*(i*4+2+2*nrays)+1]=2+((i+1)%nrays)*2+1;
facefaces[3*(i*4+3+2*nrays)]=2+4*nrays+i*2+1; facefaces[3*(i*4+3+2*nrays)+2]=2+4*nrays+((i+1)%nrays)*2+1; facefaces[3*(i*4+3+2*nrays)+1]=2+((i+1)%nrays)*2+1;
}
//wheel band
// bandfaces[3*(i*2)]=2+2*nrays+i*2; bandfaces[3*(i*2)+1]=2+2*nrays+i*2+1; bandfaces[3*(i*2)+2]=2+2*nrays+((i+1)%nrays)*2+1;
// bandfaces[3*(i*2+1)]=2+2*nrays+((i+1)%nrays)*2+1; bandfaces[3*(i*2+1)+2]=2+2*nrays+i*2; bandfaces[3*(i*2+1)+1]=2+2*nrays+((i+1)%nrays)*2;
bandfaces[3*(i*2)]=2+2*nrays+i*2; bandfaces[3*(i*2)+1]=2+2*nrays+i*2+1; bandfaces[3*(i*2)+2]=2+2*nrays+((i+1)%nrays)*2;
bandfaces[3*(i*2+1)]=2+2*nrays+((i+1)%nrays)*2; bandfaces[3*(i*2+1)+2]=2+2*nrays+((i+1)%nrays)*2+1; bandfaces[3*(i*2+1)+1]=2+2*nrays+i*2+1;
}
//update coords
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;
/// Set bounding information (for culling)
msh->_setBounds(AxisAlignedBox(-1,-1,0,1,1,0), true);
//msh->_setBoundingSphereRadius(Math::Sqrt(1*1+1*1));
/// Notify Mesh object that it has been loaded
//msh->buildTangentVectors();
/*unsigned short src, dest;
if (!msh->suggestTangentVectorBuildParams(src, dest))
{
msh->buildTangentVectors(src, dest);
}
*/
msh->load();
//msh->touch();
// msh->load();
//msh->buildEdgeList();
}
示例6: VertexData
Airbrake::Airbrake(char* basename, int num, node_t *ndref, node_t *ndx, node_t *ndy, node_t *nda, Vector3 pos, float width, float length, float maxang, char* texname, float tx1, float ty1, float tx2, float ty2, float lift_coef)
{
snode=0;
noderef=ndref;
nodex=ndx;
nodey=ndy;
nodea=nda;
offset=pos;
maxangle=maxang;
area=width*length*lift_coef;
char meshname[256];
sprintf(meshname, "airbrakemesh-%s-%i", basename, num);
/// Create the mesh via the MeshManager
msh = MeshManager::getSingleton().createManual(meshname, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
union
{
float *vertices;
CoVertice_t *covertices;
};
/// Create submesh
SubMesh* sub = msh->createSubMesh();
//materials
sub->setMaterialName(texname);
/// Define the vertices
size_t nVertices = 4;
size_t vbufCount = (2*3+2)*nVertices;
vertices=(float*)malloc(vbufCount*sizeof(float));
//textures coordinates
covertices[0].texcoord=Vector2(tx1, ty1);
covertices[1].texcoord=Vector2(tx2, ty1);
covertices[2].texcoord=Vector2(tx2, ty2);
covertices[3].texcoord=Vector2(tx1, ty2);
/// Define triangles
/// The values in this table refer to vertices in the above table
size_t ibufCount = 3*4;
unsigned short *faces=(unsigned short*)malloc(ibufCount*sizeof(unsigned short));
faces[0]=0; faces[1]=1; faces[2]=2;
faces[3]=0; faces[4]=2; faces[5]=3;
faces[6]=0; faces[7]=2; faces[8]=1;
faces[9]=0; faces[10]=3; faces[11]=2;
//set coords
covertices[0].vertex=Vector3(0,0,0);
covertices[1].vertex=Vector3(width,0,0);
covertices[2].vertex=Vector3(width,0,length);
covertices[3].vertex=Vector3(0,0,length);
covertices[0].normal=Vector3(0,1,0);
covertices[1].normal=Vector3(0,1,0);
covertices[2].normal=Vector3(0,1,0);
covertices[3].normal=Vector3(0,1,0);
/// Create vertex data structure for vertices shared between submeshes
msh->sharedVertexData = new VertexData();
msh->sharedVertexData->vertexCount = nVertices;
/// Create declaration (memory format) of vertex data
VertexDeclaration* 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)
HardwareVertexBufferSharedPtr 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);
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr faceibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
ibufCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
faceibuf->writeData(0, faceibuf->getSizeInBytes(), faces, true);
/// Set parameters of the submesh
sub->useSharedVertices = true;
sub->indexData->indexBuffer = faceibuf;
//.........这里部分代码省略.........
示例7: 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;
//.........这里部分代码省略.........
示例8: _prepareMesh
void _prepareMesh()
{
int i,lvl ;
mesh = MeshManager::getSingleton().createManual(name,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME) ;
subMesh = mesh->createSubMesh();
subMesh->useSharedVertices=false;
int numVertices = 4 ;
if (first) { // first Circle, create some static common data
first = false ;
// static buffer for position and normals
posnormVertexBuffer =
HardwareBufferManager::getSingleton().createVertexBuffer(
6*sizeof(float), // size of one vertex data
4, // number of vertices
HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage
false); // no shadow buffer
float *posnormBufData = (float*) posnormVertexBuffer->
lock(HardwareBuffer::HBL_DISCARD);
for(i=0;i<numVertices;i++) {
posnormBufData[6*i+0]=((Real)(i%2)-0.5f)*CIRCLE_SIZE; // pos X
posnormBufData[6*i+1]=0; // pos Y
posnormBufData[6*i+2]=((Real)(i/2)-0.5f)*CIRCLE_SIZE; // pos Z
posnormBufData[6*i+3]=0 ; // normal X
posnormBufData[6*i+4]=1 ; // normal Y
posnormBufData[6*i+5]=0 ; // normal Z
}
posnormVertexBuffer->unlock();
// static buffers for 16 sets of texture coordinates
texcoordsVertexBuffers = new HardwareVertexBufferSharedPtr[16];
for(lvl=0;lvl<16;lvl++) {
texcoordsVertexBuffers[lvl] =
HardwareBufferManager::getSingleton().createVertexBuffer(
2*sizeof(float), // size of one vertex data
numVertices, // number of vertices
HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage
false); // no shadow buffer
float *texcoordsBufData = (float*) texcoordsVertexBuffers[lvl]->
lock(HardwareBuffer::HBL_DISCARD);
float x0 = (Real)(lvl % 4) * 0.25 ;
float y0 = (Real)(lvl / 4) * 0.25 ;
y0 = 0.75-y0 ; // upside down
for(i=0;i<4;i++) {
texcoordsBufData[i*2 + 0]=
x0 + 0.25 * (Real)(i%2) ;
texcoordsBufData[i*2 + 1]=
y0 + 0.25 * (Real)(i/2) ;
}
texcoordsVertexBuffers[lvl]->unlock();
}
// Index buffer for 2 faces
unsigned short faces[6] = {2,1,0, 2,3,1};
indexBuffer =
HardwareBufferManager::getSingleton().createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
6,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
indexBuffer->writeData(0,
indexBuffer->getSizeInBytes(),
faces,
true); // true?
}
// Initialize vertex data
subMesh->vertexData = new VertexData();
subMesh->vertexData->vertexStart = 0;
subMesh->vertexData->vertexCount = 4;
// first, set vertex buffer bindings
VertexBufferBinding *vbind = subMesh->vertexData->vertexBufferBinding ;
vbind->setBinding(0, posnormVertexBuffer);
vbind->setBinding(1, texcoordsVertexBuffers[0]);
// now, set vertex buffer declaration
VertexDeclaration *vdecl = subMesh->vertexData->vertexDeclaration ;
vdecl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
vdecl->addElement(0, 3*sizeof(float), VET_FLOAT3, VES_NORMAL);
vdecl->addElement(1, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES);
// Initialize index data
subMesh->indexData->indexBuffer = indexBuffer;
subMesh->indexData->indexStart = 0;
subMesh->indexData->indexCount = 6;
// set mesh bounds
AxisAlignedBox circleBounds(-CIRCLE_SIZE/2.0f, 0, -CIRCLE_SIZE/2.0f,
CIRCLE_SIZE/2.0f, 0, CIRCLE_SIZE/2.0f);
mesh->_setBounds(circleBounds);
mesh->load();
mesh->touch();
}
示例9: switch
FlexObj::FlexObj(node_t *nds, std::vector<CabTexcoord>& texcoords, int numtriangles,
int* triangles, std::vector<CabSubmesh>& submesh_defs,
char* texname, const char* name, char* backtexname, char* transtexname)
{
m_triangle_count = numtriangles;
m_all_nodes=nds;
// Create the mesh via the MeshManager
m_mesh = MeshManager::getSingleton().createManual(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// Create submeshes
m_submeshes.reserve(submesh_defs.size());
for (size_t j=0; j<submesh_defs.size(); j++)
{
Ogre::SubMesh* submesh = m_mesh->createSubMesh();
switch (submesh_defs[j].backmesh_type)
{
case CabSubmesh::BACKMESH_OPAQUE: submesh->setMaterialName(backtexname); break;
case CabSubmesh::BACKMESH_TRANSPARENT: submesh->setMaterialName(transtexname); break;
default: submesh->setMaterialName(texname);
}
m_submeshes.push_back(submesh);
};
// Define the m_vertices_raw (8 vertices, each consisting of 3 groups of 3 floats
m_vertex_count = texcoords.size();
m_vertices_raw=(float*)malloc(((2*3+2)*m_vertex_count)*sizeof(float));
m_vertex_nodes=(int*)malloc(m_vertex_count*sizeof(int));
for (size_t i=0; i<m_vertex_count; i++)
{
m_vertex_nodes[i] = texcoords[i].node_id; //define node ids
m_vertices[i].texcoord=Vector2(texcoords[i].texcoord_u, texcoords[i].texcoord_v); //textures coordinates
}
// Define triangles
// The values in this table refer to vertices in the above table
m_index_count = 3*numtriangles;
m_indices=(unsigned short*)malloc(m_index_count*sizeof(unsigned short));
for (size_t i=0; i<m_index_count; i++)
{
m_indices[i]=ComputeVertexPos(i/3, triangles[i], submesh_defs);
}
m_s_ref=(float*)malloc(numtriangles*sizeof(float));
for (size_t i=0; i<(unsigned int)numtriangles;i++)
{
Ogre::Vector3 base_pos = m_all_nodes[m_vertex_nodes[m_indices[i*3]]].RelPosition;
Ogre::Vector3 v1 = m_all_nodes[m_vertex_nodes[m_indices[i*3+1]]].RelPosition - base_pos;
Ogre::Vector3 v2 = m_all_nodes[m_vertex_nodes[m_indices[i*3+2]]].RelPosition - base_pos;
m_s_ref[i]=v1.crossProduct(v2).length()*2.0;
}
this->UpdateMesh(); // Initialize the dynamic mesh
// Create vertex data structure for vertices shared between submeshes
m_mesh->sharedVertexData = new VertexData();
m_mesh->sharedVertexData->vertexCount = m_vertex_count;
// Create declaration (memory format) of vertex data
m_vertex_format = m_mesh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
m_vertex_format->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
m_vertex_format->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
m_vertex_format->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)
m_hw_vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
offset, m_mesh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
// Upload the vertex data to the card
m_hw_vbuf->writeData(0, m_hw_vbuf->getSizeInBytes(), m_vertices_raw, true);
// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = m_mesh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, m_hw_vbuf);
// Set parameters of the submeshes
for (size_t j=0; j<m_submeshes.size(); j++)
{
size_t index_count;
if (j == 0)
index_count = 3*submesh_defs[j].cabs_pos;
else
index_count = 3*(submesh_defs[j].cabs_pos-submesh_defs[j-1].cabs_pos); // 3 indices per triangle
m_submeshes[j]->useSharedVertices = true;
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
index_count,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the index data to the card
unsigned short* faces_ptr;
if (j == 0)
//.........这里部分代码省略.........
示例10: createMesh
Mesh* OgreSubsystem::createMesh(const MeshData& data,String name)
{
String nombre = name;
if(name=="AUTO_NAME_ME")
{
nombre = "OryxSceneNodeAutoNamed"+StringUtils::toString(mAutoNameIndex);
++mAutoNameIndex;
}
using namespace Ogre;
bool hasVertexColor = data.getDiffuse();
bool hasNormals = data.getNormals();
int numFaces = data.indices.size()/3;
int numVertices = data.vertices.size()/3;
HardwareVertexBufferSharedPtr posVertexBuffer;
HardwareVertexBufferSharedPtr normVertexBuffer;
std::vector<HardwareVertexBufferSharedPtr> texcoordsVertexBuffer;
HardwareVertexBufferSharedPtr diffuseVertexBuffer;
HardwareIndexBufferSharedPtr indexBuffer;
Ogre::Mesh* m = Ogre::MeshManager::getSingletonPtr()->createManual(
nombre,ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).get();
Ogre::SubMesh* sm = m->createSubMesh();
sm->useSharedVertices = false;
sm->vertexData = new VertexData();
sm->vertexData->vertexStart = 0;
sm->vertexData->vertexCount = numVertices;
Ogre::VertexDeclaration* vdecl = sm->vertexData->vertexDeclaration;
Ogre::VertexBufferBinding* vbind = sm->vertexData->vertexBufferBinding;
size_t bufferCount = 0;
vdecl->addElement(bufferCount, 0, VET_FLOAT3, VES_POSITION);
if(hasNormals)
vdecl->addElement(++bufferCount, 0, VET_FLOAT3, VES_NORMAL);
if(hasVertexColor)
vdecl->addElement(++bufferCount, 0, VET_FLOAT4, VES_DIFFUSE);
for(int i=0;i<data.texcoords.size();++i)
vdecl->addElement(++bufferCount, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES,i);
bufferCount = 0;
// Positions
posVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
3*sizeof(float),numVertices,Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
vbind->setBinding(bufferCount, posVertexBuffer);
float* vertices = data.getVertices();
float* normals = data.getNormals();
float* diffuse = data.getDiffuse();
unsigned short* indices = data.getIndices();
posVertexBuffer->writeData(0,posVertexBuffer->getSizeInBytes(),vertices, true);
// Normals
if(hasNormals)
{
normVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
3*sizeof(float),numVertices,HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
vbind->setBinding(++bufferCount, normVertexBuffer);
normVertexBuffer->writeData(0,normVertexBuffer->getSizeInBytes(),normals, true);
}
if(hasVertexColor)
{
diffuseVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
4*sizeof(float),numVertices,HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbind->setBinding(++bufferCount, diffuseVertexBuffer);
diffuseVertexBuffer->writeData(0,diffuseVertexBuffer->getSizeInBytes(), diffuse, true);
}
// Texcoords
for(int i=0;i<data.texcoords.size();++i)
{
texcoordsVertexBuffer.push_back(HardwareBufferManager::getSingleton().createVertexBuffer(
2*sizeof(float),numVertices,HardwareBuffer::HBU_STATIC_WRITE_ONLY));
vbind->setBinding(++bufferCount, texcoordsVertexBuffer[i]);
texcoordsVertexBuffer[i]->writeData(0,sizeof(float)*data.texcoords[i].size(),&data.texcoords[i][0], false);
}
if(!data.indices.empty())
{
// Prepare buffer for indices
indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,3*numFaces,HardwareBuffer::HBU_STATIC_WRITE_ONLY, true);
//.........这里部分代码省略.........
示例11: _generateSubMesh
//.........这里部分代码省略.........
// Define vertices color.
RenderSystem* rs = Root::getSingleton().getRenderSystem();
RGBA* colors = new RGBA[vertCount];
for(size_t i = 0; i < vertCount; ++i)
rs->convertColourValue(ColourValue(0.0f + 0.175f*i, 0.2f, 1.0f - 0.175f*i), colors + i);
// Define the triangles.
size_t faceCount = vertCount - 1; // Face count = vertCount - cent
size_t center = 0;
size_t last = 1; //collin was here
size_t curr = 2;
unsigned short* faces = new unsigned short[faceCount*3];
index = 0;
for(size_t i = 0; i < faceCount; ++i) {
assert(last < vertCount && curr < vertCount); // Panic check
faces[index++] = center;
faces[index++] = curr;
faces[index++] = last;
last = curr++;
if(curr >= vertCount) curr = 1;
}
// All information has been generated, move into mesh structures.
// Note: Currently does not implement or used any sort of shared
// vertices. This is intentional and should be changed at the
// soonest conveienence. IE -- Never. ;P
tileMesh->useSharedVertices = false;
tileMesh->vertexData = new VertexData();
tileMesh->vertexData->vertexCount = vertCount;
// Create memory footprint for vertex data.
size_t offset = 0;
VertexDeclaration* decl = tileMesh->vertexData->vertexDeclaration;
// Position and normal buffer.
// -- Position
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
// -- Normal
decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
// Allocate a vertex buffer for a number of vertices and vertex size.
HardwareVertexBufferSharedPtr vertBuff =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, // Size of a vertex, in bytes.
tileMesh->vertexData->vertexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Write our data to vertex buffer.
vertBuff->writeData(0, vertBuff->getSizeInBytes(), vertices, true);
// Set the buffer's bind location.
VertexBufferBinding* vertBind = tileMesh->vertexData->vertexBufferBinding;
vertBind->setBinding(0, vertBuff);
// Color buffer for vertices
offset = 0;
decl->addElement(1, offset, VET_COLOUR, VES_DIFFUSE);
offset += VertexElement::getTypeSize(VET_COLOUR);
// Allocate a new buffer for colors.
vertBuff = HardwareBufferManager::getSingleton().createVertexBuffer(
offset, // Size of a vertex, in bytes.
tileMesh->vertexData->vertexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Write color data to buffer.
vertBuff->writeData(0, vertBuff->getSizeInBytes(), colors, true);
// Set the color buffer's bind location
vertBind->setBinding(1, vertBuff);
// Allocate a buffer for the index information
HardwareIndexBufferSharedPtr indexBuff = HardwareBufferManager::getSingleton().createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
faceCount*3,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Write data to the buffer.
indexBuff->writeData(0, indexBuff->getSizeInBytes(), faces, true);
// Finalize submesh.
tileMesh->indexData->indexBuffer = indexBuff;
tileMesh->indexData->indexCount = faceCount*3;
tileMesh->indexData->indexStart = 0;
// Deallocate the vertex and face arrays.
if(vertices) delete[] vertices;
if(faces) delete[] faces;
}
示例12: 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;
}
示例13: sqrt
void BasicTutorial2::createColourCube()
{
/// Create the mesh via the MeshManager
Ogre::MeshPtr msh = MeshManager::getSingleton().createManual("ColourCube", "General");
/// Create one submesh
SubMesh* sub = msh->createSubMesh();
const float sqrt13 = 0.577350269f; /* sqrt(1/3) */
/// Define the vertices (8 vertices, each have 3 floats for position and 3 for normal)
const size_t nVertices = 8;
const size_t vbufCount = 3*2*nVertices;
float vertices[vbufCount] = {
-100.0,100.0,-100.0, //0 position
-sqrt13,sqrt13,-sqrt13, //0 normal
100.0,100.0,-100.0, //1 position
sqrt13,sqrt13,-sqrt13, //1 normal
100.0,-100.0,-100.0, //2 position
sqrt13,-sqrt13,-sqrt13, //2 normal
-100.0,-100.0,-100.0, //3 position
-sqrt13,-sqrt13,-sqrt13, //3 normal
-100.0,100.0,100.0, //4 position
-sqrt13,sqrt13,sqrt13, //4 normal
100.0,100.0,100.0, //5 position
sqrt13,sqrt13,sqrt13, //5 normal
100.0,-100.0,100.0, //6 position
sqrt13,-sqrt13,sqrt13, //6 normal
-100.0,-100.0,100.0, //7 position
-sqrt13,-sqrt13,sqrt13, //7 normal
};
RenderSystem* rs = Root::getSingleton().getRenderSystem();
RGBA colours[nVertices];
RGBA *pColour = colours;
// Use render system to convert colour value since colour packing varies
rs->convertColourValue(ColourValue(1.0,0.0,0.0), pColour++); //0 colour
rs->convertColourValue(ColourValue(1.0,1.0,0.0), pColour++); //1 colour
rs->convertColourValue(ColourValue(0.0,1.0,0.0), pColour++); //2 colour
rs->convertColourValue(ColourValue(0.0,0.0,0.0), pColour++); //3 colour
rs->convertColourValue(ColourValue(1.0,0.0,1.0), pColour++); //4 colour
rs->convertColourValue(ColourValue(1.0,1.0,1.0), pColour++); //5 colour
rs->convertColourValue(ColourValue(0.0,1.0,1.0), pColour++); //6 colour
rs->convertColourValue(ColourValue(0.0,0.0,1.0), pColour++); //7 colour
/// Define 12 triangles (two triangles per cube face)
/// The values in this table refer to vertices in the above table
const size_t ibufCount = 36;
unsigned short faces[ibufCount] = {
0,2,3,
0,1,2,
1,6,2,
1,5,6,
4,6,5,
4,7,6,
0,7,4,
0,3,7,
0,5,1,
0,4,5,
2,7,3,
2,6,7
};
/// 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
VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
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);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// 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);
// 2nd buffer
offset = 0;
decl->addElement(1, offset, VET_COLOUR, VES_DIFFUSE);
offset += VertexElement::getTypeSize(VET_COLOUR);
/// 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_STATIC_WRITE_ONLY);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), colours, true);
/// Set vertex buffer binding so buffer 1 is bound to our colour buffer
bind->setBinding(1, vbuf);
//.........这里部分代码省略.........
示例14: 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();
}
示例15: createCube
//.........这里部分代码省略.........
1,1,
CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
1,0,0,
1,0,
CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
1,0,0,
0,0,
// up side
-CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
0,1,0,
0,1,
CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
0,1,0,
1,1,
CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
0,1,0,
1,0,
-CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
0,1,0,
0,0,
// down side
-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
0,-1,0,
0,1,
CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
0,-1,0,
1,1,
CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
0,-1,0,
1,0,
-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
0,-1,0,
0,0
};
mesh->sharedVertexData = OGRE_NEW VertexData();
mesh->sharedVertexData->vertexCount = NUM_VERTICES;
VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration;
VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding;
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_FLOAT2, VES_TEXTURE_COORDINATES, 0);
offset += VertexElement::getTypeSize(VET_FLOAT2);
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, NUM_VERTICES, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
bind->setBinding(0, vbuf);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
sub->useSharedVertices = true;
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
NUM_INDICES,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
unsigned short faces[NUM_INDICES] = {
// front
0,1,2,
0,2,3,
// back
4,5,6,
4,6,7,
// left
8,9,10,
8,10,11,
// right
12,13,14,
12,14,15,
// up
16,17,18,
16,18,19,
// down
20,21,22,
20,22,23
};
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = NUM_INDICES;
sub->indexData->indexStart = 0;
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
mesh->_setBounds(AxisAlignedBox(-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE), true);
mesh->_setBoundingSphereRadius(CUBE_HALF_SIZE);
}