本文整理汇总了C++中ogre::MeshPtr::createSubMesh方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::createSubMesh方法的具体用法?C++ MeshPtr::createSubMesh怎么用?C++ MeshPtr::createSubMesh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::createSubMesh方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFakeEntity
void ESKOgre::createFakeEntity(Ogre::SceneManager *mSceneMgr) {
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual(name + "_skeleton", XENOVIEWER_RESOURCE_GROUP);
msh->setSkeletonName(name);
Ogre::SubMesh* sub = msh->createSubMesh();
const size_t nVertices = 3;
const size_t nVertCount = 3;
const size_t vbufCount = nVertCount*nVertices;
float *vertices = (float *)malloc(sizeof(float)*vbufCount);
for (size_t i = 0; i < nVertices; i++) {
vertices[i*nVertCount] = 0.0;
vertices[i*nVertCount + 1] = 0.0;
vertices[i*nVertCount + 2] = 0.0;
}
const size_t ibufCount = 3;
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i < ibufCount; i++) {
faces[i] = i;
}
msh->sharedVertexData = new Ogre::VertexData();
msh->sharedVertexData->vertexCount = nVertices;
Ogre::VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offset, msh->sharedVertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
msh->_setBounds(Ogre::AxisAlignedBox(-100, -100, -100, 100, 100, 100));
msh->_setBoundingSphereRadius(100);
msh->load();
free(faces);
free(vertices);
skeleton_entity = mSceneMgr->createEntity(name + "_skeleton");
skeleton_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
skeleton_node->attachObject(skeleton_entity);
skeleton_node->setVisible(false);
}
示例2: a
void
MeshExtractor( const MeshData& mesh_data, const Ogre::String& material_name, File* file, int offset_to_data, VectorTexForGen& textures, const Ogre::MeshPtr& mesh, const Ogre::String& name, int bone_id )
{
int offset_to_vertex = offset_to_data;
int offset_to_triangle_t = offset_to_vertex + 0x04 + file->GetU32LE( offset_to_vertex );
int number_of_triangle_t = file->GetU16LE( offset_to_triangle_t );
u16 tpage = file->GetU16LE( offset_to_triangle_t + 0x02 );
int offset_to_quad_t = offset_to_triangle_t + 0x04 + number_of_triangle_t * 0x10;
int number_of_quad_t = file->GetU16LE( offset_to_quad_t );
int offset_to_triangle = offset_to_quad_t + 0x4 + number_of_quad_t * 0x14;
int number_of_triangle = file->GetU16LE( offset_to_triangle );
int offset_to_quad = offset_to_triangle + 0x4 + number_of_triangle * 0x14;
int number_of_quad = file->GetU16LE( offset_to_quad );
Ogre::SubMesh* sub_mesh = mesh->createSubMesh( name );
sub_mesh->setMaterialName( material_name );
sub_mesh->useSharedVertices = false;
sub_mesh->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
// Allocate and prepare vertex data
sub_mesh->vertexData = new Ogre::VertexData();
sub_mesh->vertexData->vertexStart = 0;
sub_mesh->vertexData->vertexCount = static_cast< size_t >( number_of_triangle_t * 3 + number_of_quad_t * 6 + number_of_triangle * 3 + number_of_quad * 6 );
sub_mesh->indexData = new Ogre::IndexData();
sub_mesh->indexData->indexStart = 0;
sub_mesh->indexData->indexCount = sub_mesh->vertexData->vertexCount;
sub_mesh->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
sub_mesh->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
u16* idata = static_cast< u16* >( sub_mesh->indexData->indexBuffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
u32 cur_index = 0;
Ogre::VertexDeclaration* decl = sub_mesh->vertexData->vertexDeclaration;
Ogre::VertexBufferBinding* bind = sub_mesh->vertexData->vertexBufferBinding;
// 1st buffer
decl->addElement( POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION );
Ogre::HardwareVertexBufferSharedPtr vbuf0 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( POSITION_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
bind->setBinding( POSITION_BINDING, vbuf0 );
// 2nd buffer
decl->addElement( COLOUR_BINDING, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE );
Ogre::HardwareVertexBufferSharedPtr vbuf1 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( COLOUR_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
// Set vertex buffer binding so buffer 1 is bound to our colour buffer
bind->setBinding( COLOUR_BINDING, vbuf1 );
// 3rd buffer
decl->addElement( TEXTURE_BINDING, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0 );
Ogre::HardwareVertexBufferSharedPtr vbuf2 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( TEXTURE_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
bind->setBinding( TEXTURE_BINDING, vbuf2 );
float* pPos = static_cast< float* >( vbuf0->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
float* tPos = static_cast< float* >( vbuf2->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
Ogre::RGBA colours[ sub_mesh->vertexData->vertexCount ];
// add textured triangle
for (int j = 0; j < number_of_triangle_t; ++j)
{
int offset_a = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x0);
int offset_b = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x2);
int offset_c = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x4);
Ogre::Vector3 a((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 00),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 02),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 04));
Ogre::Vector3 b((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 00),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 02),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 04));
Ogre::Vector3 c((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 00),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 02),
(s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 04));
a /= 512;
b /= 512;
c /= 512;
u16 clut = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0xa);
int clut_x = (clut & 0x003f) << 3;
int clut_y = (clut & 0xffc0) >> 6;
int bpp = (tpage >> 0x7) & 0x3;
int vram_x = (tpage & 0xf) * 64;
int vram_y = ((tpage & 0x10) >> 4) * 256;
TexForGen texture;
texture.palette_x = clut_x;
texture.palette_y = clut_y;
texture.texture_x = vram_x;
texture.texture_y = vram_y;
//.........这里部分代码省略.........
示例3: doExportMesh
void MilkshapePlugin::doExportMesh(msModel* pModel)
{
// Create singletons
Ogre::SkeletonManager skelMgr;
Ogre::DefaultHardwareBufferManager defHWBufMgr;
Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton();
Ogre::MeshManager meshMgr;
//
// choose filename
//
OPENFILENAME ofn;
memset (&ofn, 0, sizeof (OPENFILENAME));
char szFile[MS_MAX_PATH];
char szFileTitle[MS_MAX_PATH];
char szDefExt[32] = "mesh";
char szFilter[128] = "OGRE .mesh Files (*.mesh)\0*.mesh\0All Files (*.*)\0*.*\0\0";
szFile[0] = '\0';
szFileTitle[0] = '\0';
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrDefExt = szDefExt;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MS_MAX_PATH;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MS_MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrTitle = "Export to OGRE Mesh";
if (!::GetSaveFileName (&ofn))
return /*0*/;
logMgr.logMessage("Creating Mesh object...");
Ogre::MeshPtr ogreMesh = Ogre::MeshManager::getSingleton().create("export",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
logMgr.logMessage("Mesh object created.");
bool foundBoneAssignment = false;
// No shared geometry
int i;
int wh, numbones;
int intweight[3], intbones[3];
size_t j;
Ogre::Vector3 min, max, currpos;
Ogre::Real maxSquaredRadius;
bool first = true;
for (i = 0; i < msModel_GetMeshCount (pModel); i++)
{
msMesh *pMesh = msModel_GetMeshAt (pModel, i);
logMgr.logMessage("Creating SubMesh object...");
Ogre::SubMesh* ogreSubMesh = ogreMesh->createSubMesh();
logMgr.logMessage("SubMesh object created.");
// Set material
logMgr.logMessage("Getting SubMesh Material...");
int matIdx = msMesh_GetMaterialIndex(pMesh);
if (matIdx == -1)
{
// No material, use blank
ogreSubMesh->setMaterialName("BaseWhite");
logMgr.logMessage("No Material, using default 'BaseWhite'.");
}
else
{
msMaterial *pMat = msModel_GetMaterialAt(pModel, matIdx);
ogreSubMesh->setMaterialName(pMat->szName);
logMgr.logMessage("SubMesh Material Done.");
}
logMgr.logMessage("Setting up geometry...");
// Set up mesh geometry
ogreSubMesh->vertexData = new Ogre::VertexData();
ogreSubMesh->vertexData->vertexCount = msMesh_GetVertexCount (pMesh);
ogreSubMesh->vertexData->vertexStart = 0;
Ogre::VertexBufferBinding* bind = ogreSubMesh->vertexData->vertexBufferBinding;
Ogre::VertexDeclaration* decl = ogreSubMesh->vertexData->vertexDeclaration;
// Always 1 texture layer, 2D coords
#define POSITION_BINDING 0
#define NORMAL_BINDING 1
#define TEXCOORD_BINDING 2
decl->addElement(POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
decl->addElement(NORMAL_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
decl->addElement(TEXCOORD_BINDING, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
// Create buffers
Ogre::HardwareVertexBufferSharedPtr pbuf = Ogre::HardwareBufferManager::getSingleton().
createVertexBuffer(decl->getVertexSize(POSITION_BINDING), ogreSubMesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_DYNAMIC, false);
Ogre::HardwareVertexBufferSharedPtr nbuf = Ogre::HardwareBufferManager::getSingleton().
createVertexBuffer(decl->getVertexSize(NORMAL_BINDING), ogreSubMesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_DYNAMIC, false);
Ogre::HardwareVertexBufferSharedPtr tbuf = Ogre::HardwareBufferManager::getSingleton().
//.........这里部分代码省略.........
示例4: File
void
MeshExtractor( const MeshData& mesh_data, const Ogre::String& material_name, File* file, int offset_to_data, VectorTexForGen& textures, const Ogre::MeshPtr& mesh )
{
File* file12 = new File( "./data/field/5/1b/1/12/1" );
u32 offset_to_clut_tex = 4 + file12->GetU32LE( 4 + 4 ) & 0x00ffffff;
LOGGER->Log( "offset_to_clut_tex = \"" + HexToString( offset_to_clut_tex, 8, '0' ) + "\".\n" );
u32 offset_to_tx_ty = offset_to_clut_tex + file12->GetU8( 4 + 7 ) * 4;
LOGGER->Log( "offset_to_tx_ty = \"" + HexToString( offset_to_tx_ty, 8, '0' ) + "\".\n" );
int number_of_monochrome_textured_quads = file->GetU16LE( offset_to_data + 0x02 );
int number_of_monochrome_textured_triangles = file->GetU16LE( offset_to_data + 0x04 );
int number_of_shaded_textured_quads = file->GetU16LE( offset_to_data + 0x06 );
int number_of_shaded_textured_triangles = file->GetU16LE( offset_to_data + 0x08 );
int number_of_gradated_quads = file->GetU16LE( offset_to_data + 0x0a );
int number_of_gradated_triangles = file->GetU16LE( offset_to_data + 0x0c );
int number_of_monochrome_quads = file->GetU16LE( offset_to_data + 0x0e );
int number_of_monochrome_triangles = file->GetU16LE( offset_to_data + 0x10 );
u32 pointer_to_vertex_groups = file->GetU32LE( offset_to_data + 0x14 );
u32 pointer_to_vertex_data = file->GetU32LE( offset_to_data + 0x18 );
u32 pointer_to_mesh_data = file->GetU32LE( offset_to_data + 0x1c );
u32 pointer_to_texture_data = file->GetU32LE( offset_to_data + 0x20 );
Ogre::SubMesh* sub_mesh = mesh->createSubMesh(/* name */);
sub_mesh->setMaterialName( material_name );
sub_mesh->useSharedVertices = false;
sub_mesh->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
// Allocate and prepare vertex data
sub_mesh->vertexData = new Ogre::VertexData();
sub_mesh->vertexData->vertexStart = 0;
sub_mesh->vertexData->vertexCount = static_cast< size_t >(
number_of_monochrome_textured_quads * 6 +
number_of_monochrome_textured_triangles * 3/* +
number_of_shaded_textured_quads * 6 +
number_of_shaded_textured_triangles * 3 +
number_of_gradated_quads * 6 +
number_of_gradated_triangles * 3 +
number_of_monochrome_quads * 6 +
number_of_monochrome_triangles * 3*/ );
sub_mesh->indexData = new Ogre::IndexData();
sub_mesh->indexData->indexStart = 0;
sub_mesh->indexData->indexCount = sub_mesh->vertexData->vertexCount;
sub_mesh->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
sub_mesh->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
u16* idata = static_cast< u16* >( sub_mesh->indexData->indexBuffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
u32 cur_index = 0;
Ogre::VertexDeclaration* decl = sub_mesh->vertexData->vertexDeclaration;
Ogre::VertexBufferBinding* bind = sub_mesh->vertexData->vertexBufferBinding;
// 1st buffer
decl->addElement( POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION );
Ogre::HardwareVertexBufferSharedPtr vbuf0 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( POSITION_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
bind->setBinding( POSITION_BINDING, vbuf0 );
// 2nd buffer
decl->addElement( COLOUR_BINDING, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE );
Ogre::HardwareVertexBufferSharedPtr vbuf1 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( COLOUR_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
// Set vertex buffer binding so buffer 1 is bound to our colour buffer
bind->setBinding( COLOUR_BINDING, vbuf1 );
// 3rd buffer
decl->addElement( TEXTURE_BINDING, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0 );
Ogre::HardwareVertexBufferSharedPtr vbuf2 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
decl->getVertexSize( TEXTURE_BINDING ),
sub_mesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
bind->setBinding( TEXTURE_BINDING, vbuf2 );
float* pPos = static_cast< float* >( vbuf0->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
float* tPos = static_cast< float* >( vbuf2->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
std::vector<Ogre::RGBA> coloursVec(sub_mesh->vertexData->vertexCount);
Ogre::RGBA* colours = coloursVec.data();
for( int i = 0; i < number_of_monochrome_textured_quads; ++i )
{
int index_a = file->GetU16LE( pointer_to_mesh_data + 0x0 );
int index_b = file->GetU16LE( pointer_to_mesh_data + 0x2 );
int index_c = file->GetU16LE( pointer_to_mesh_data + 0x4 );
int index_d = file->GetU16LE( pointer_to_mesh_data + 0x6 );
//.........这里部分代码省略.........
示例5: createOgreSubmesh
// Write submesh data to an Ogre compatible mesh
bool Submesh::createOgreSubmesh(Ogre::MeshPtr pMesh,const ParamList& params)
{
size_t i,j;
bool stat;
// Create a new submesh
Ogre::SubMesh* pSubmesh;
if (m_name != "")
pSubmesh = pMesh->createSubMesh(m_name.c_str());
else
pSubmesh = pMesh->createSubMesh();
// Set material
pSubmesh->setMaterialName(m_pMaterial->name().c_str());
// Set use shared geometry flag
pSubmesh->useSharedVertices = params.useSharedGeom;
// Create vertex data for current submesh
pSubmesh->vertexData = new Ogre::VertexData();
// Set number of indexes
pSubmesh->indexData->indexCount = 3*m_faces.size();
pSubmesh->vertexData->vertexCount = m_vertices.size();
// Check if we need to use 32 bit indexes
bool use32BitIndexes = false;
if (m_vertices.size() > 65536 || params.useSharedGeom)
{
use32BitIndexes = true;
}
// Create a new index buffer
pSubmesh->indexData->indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
use32BitIndexes ? Ogre::HardwareIndexBuffer::IT_32BIT : Ogre::HardwareIndexBuffer::IT_16BIT,
pSubmesh->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Fill the index buffer with faces data
if (use32BitIndexes)
{
Ogre::uint32* pIdx = static_cast<Ogre::uint32*>(
pSubmesh->indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (i=0; i<m_faces.size(); i++)
{
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[0]);
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[1]);
*pIdx++ = static_cast<Ogre::uint32>(m_faces[i].v[2]);
}
pSubmesh->indexData->indexBuffer->unlock();
}
else
{
Ogre::uint16* pIdx = static_cast<Ogre::uint16*>(
pSubmesh->indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (i=0; i<m_faces.size(); i++)
{
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[0]);
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[1]);
*pIdx++ = static_cast<Ogre::uint16>(m_faces[i].v[2]);
}
pSubmesh->indexData->indexBuffer->unlock();
}
// Define vertex declaration (only if we're not using shared geometry)
if(!params.useSharedGeom)
{
Ogre::VertexDeclaration* pDecl = pSubmesh->vertexData->vertexDeclaration;
unsigned buf = 0;
size_t offset = 0;
// Add vertex position
pDecl->addElement(buf, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// Add vertex normal
if (params.exportVertNorm)
{
pDecl->addElement(buf, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
}
// Add vertex colour
if(params.exportVertCol)
{
pDecl->addElement(buf, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
}
// Add texture coordinates
for (i=0; i<m_vertices[0].texcoords.size(); i++)
{
Ogre::VertexElementType uvType = Ogre::VertexElement::multiplyTypeCount(Ogre::VET_FLOAT1, 2);
pDecl->addElement(buf, offset, uvType, Ogre::VES_TEXTURE_COORDINATES, static_cast<unsigned short>(i));
offset += Ogre::VertexElement::getTypeSize(uvType);
}
Ogre::VertexDeclaration* pOptimalDecl = pDecl->getAutoOrganisedDeclaration(
params.exportVBA, params.exportBlendShapes || params.exportVertAnims, false);
// Fill the vertex buffer using the newly created vertex declaration
stat = createOgreVertexBuffer(pSubmesh,pDecl,m_vertices);
// Write vertex bone assignements list
if (params.exportVBA)
{
// Create a new vertex bone assignements list
Ogre::SubMesh::VertexBoneAssignmentList vbas;
// Scan list of shared geometry vertices
for (i=0; i<m_vertices.size(); i++)
{
vertex v = m_vertices[i];
// Add all bone assignemnts for every vertex to the bone assignements list
for (j=0; j<v.vbas.size(); j++)
//.........这里部分代码省略.........
示例6: dist
//.........这里部分代码省略.........
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
bounds += pos;
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
if (s.flags & l2p::PF_TwoSided) {
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(-Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
}
}
// Index buffer.
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti - 1);
index_buf.push_back(vert_start + verti);
}
if (s.flags & l2p::PF_TwoSided) {
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti);
index_buf.push_back(vert_start + verti - 1);
}
}
}
if (vertex_data.size() == 0 || index_buf.size() == 0)
return nullptr;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(Ogre::String(name) + Ogre::String(m->name), "General");
Ogre::VertexData *data = new Ogre::VertexData();
mesh->sharedVertexData = data;
data->vertexCount = vertex_data.size() / 8;
Ogre::VertexDeclaration *decl = data->vertexDeclaration;
uint32_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset,
data->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), &vertex_data.front(), true);
data->vertexBufferBinding->setBinding(0, vbuf);
// Setup index buffer.
Ogre::HardwareIndexBufferSharedPtr ibuf =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
index_buf.size(),
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), &index_buf.front(), true);
Ogre::SubMesh *subMesh = mesh->createSubMesh();
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = index_buf.size();
subMesh->indexData->indexStart = 0;
mesh->_setBounds(Ogre::AxisAlignedBox(bounds.min.X, bounds.min.Y, bounds.min.Z, bounds.max.X, bounds.max.Y, bounds.max.Z));
mesh->_setBoundingSphereRadius((std::max(bounds.max.X - bounds.min.X, std::max(bounds.max.Y - bounds.min.Y, bounds.max.Z - bounds.min.Z))) / 2.0);
mesh->load();
Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::String(name) + Ogre::String(m->name) + "E", Ogre::String(name) + Ogre::String(m->name));
ent->setUserAny(Ogre::Any(static_cast<l2p::UObject*>(m.get())));
ent->setMaterialName("StaticMesh/Default");
Ogre::SceneNode *node = mUnrealCordNode->createChildSceneNode();
node->attachObject(ent);
return node;
}
示例7: TOSTRING
void RoR::GfxEnvmap::SetupEnvMap()
{
m_rtt_texture = Ogre::TextureManager::getSingleton().getByName("EnvironmentTexture");
for (int face = 0; face < NUM_FACES; face++)
{
m_render_targets[face] = m_rtt_texture->getBuffer(face)->getRenderTarget();
m_cameras[face] = gEnv->sceneManager->createCamera("EnvironmentCamera-" + TOSTRING(face));
m_cameras[face]->setAspectRatio(1.0);
m_cameras[face]->setProjectionType(Ogre::PT_PERSPECTIVE);
m_cameras[face]->setFixedYawAxis(false);
m_cameras[face]->setFOVy(Ogre::Degree(90));
m_cameras[face]->setNearClipDistance(0.1f);
m_cameras[face]->setFarClipDistance(gEnv->mainCamera->getFarClipDistance());
Ogre::Viewport* v = m_render_targets[face]->addViewport(m_cameras[face]);
v->setOverlaysEnabled(false);
v->setClearEveryFrame(true);
v->setBackgroundColour(gEnv->mainCamera->getViewport()->getBackgroundColour());
m_render_targets[face]->setAutoUpdated(false);
}
m_cameras[0]->setDirection(+Ogre::Vector3::UNIT_X);
m_cameras[1]->setDirection(-Ogre::Vector3::UNIT_X);
m_cameras[2]->setDirection(+Ogre::Vector3::UNIT_Y);
m_cameras[3]->setDirection(-Ogre::Vector3::UNIT_Y);
m_cameras[4]->setDirection(-Ogre::Vector3::UNIT_Z);
m_cameras[5]->setDirection(+Ogre::Vector3::UNIT_Z);
if (App::diag_envmap.GetActive())
{
// create fancy mesh for debugging the envmap
Ogre::Overlay* overlay = Ogre::OverlayManager::getSingleton().create("EnvMapDebugOverlay");
if (overlay)
{
Ogre::Vector3 position = Ogre::Vector3::ZERO;
float scale = 1.0f;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingletonPtr()->createManual("cubeMapDebug", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// create sub mesh
Ogre::SubMesh* sub = mesh->createSubMesh();
// Initialize render operation
sub->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
//
sub->useSharedVertices = true;
mesh->sharedVertexData = new Ogre::VertexData;
sub->indexData = new Ogre::IndexData;
// Create vertex declaration
size_t offset = 0;
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);
// Create and bind vertex buffer
mesh->sharedVertexData->vertexCount = 14;
Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
mesh->sharedVertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
// Vertex data
static const float vertexData[] = {
// Position Texture coordinates // Index
0.0, 2.0, -1.0, 1.0, 1.0, // 0
0.0, 1.0, -1.0, -1.0, 1.0, // 1
1.0, 2.0, -1.0, 1.0, -1.0, // 2
1.0, 1.0, -1.0, -1.0, -1.0, // 3
2.0, 2.0, 1.0, 1.0, -1.0, // 4
2.0, 1.0, 1.0, -1.0, -1.0, // 5
3.0, 2.0, 1.0, 1.0, 1.0, // 6
3.0, 1.0, 1.0, -1.0, 1.0, // 7
4.0, 2.0, -1.0, 1.0, 1.0, // 8
4.0, 1.0, -1.0, -1.0, 1.0, // 9
1.0, 3.0, -1.0, 1.0, 1.0, // 10
2.0, 3.0, 1.0, 1.0, 1.0, // 11
1.0, 0.0, -1.0, -1.0, 1.0, // 12
2.0, 0.0, 1.0, -1.0, 1.0, // 13
};
// Fill vertex buffer
float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
{
// Position
*pData++ = position.x + scale * vertexData[i++];
*pData++ = position.y + scale * vertexData[i++];
*pData++ = 0.0;
// Texture coordinates
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
}
vertexBuffer->unlock();
// Create index buffer
//.........这里部分代码省略.........
示例8: generateSphericDome
void GeometryFactory::generateSphericDome (const Ogre::String &name, int segments, DomeType type) {
// Return now if already exists
if (Ogre::MeshManager::getSingleton ().resourceExists (name)) {
return;
}
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: Creating " + name + " sphere mesh resource...");
// Use the mesh manager to create the mesh
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton ().createManual (name, RESOURCE_GROUP_NAME);
// Create a submesh
Ogre::SubMesh *sub = msh->createSubMesh ();
// Create the shared vertex data
Ogre::VertexData *vertexData = new Ogre::VertexData ();
msh->sharedVertexData = vertexData;
// Define the vertices' format
Ogre::VertexDeclaration *vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// Position
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Normal
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Texture coordinates
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT2);
// Allocate the vertex buffer
switch (type) {
case DT_GRADIENTS:
vertexData->vertexCount = segments * (segments - 1) + 2;
break;
case DT_STARFIELD:
vertexData->vertexCount = (segments + 1) * (segments + 1);
break;
};
Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton ().createVertexBuffer (vertexDecl->getVertexSize (0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::VertexBufferBinding *binding = vertexData->vertexBufferBinding;
binding->setBinding (0, vBuf);
float *pVertex = static_cast<float *>(vBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Allocate the index buffer
switch (type) {
case DT_GRADIENTS:
sub->indexData->indexCount = 2 * segments * (segments - 1) * 3;
break;
case DT_STARFIELD:
sub->indexData->indexCount = 2 * (segments - 1) * segments * 3;
break;
};
sub->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton ().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_16BIT, sub->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::HardwareIndexBufferSharedPtr iBuf = sub->indexData->indexBuffer;
unsigned short *pIndices = static_cast<unsigned short *>(iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Fill the buffers
switch (type) {
case DT_GRADIENTS:
fillGradientsDomeBuffers (pVertex, pIndices, segments);
break;
case DT_STARFIELD:
fillStarfieldDomeBuffers (pVertex, pIndices, segments);
break;
};
// Close the vertex buffer
vBuf->unlock ();
// Close the index buffer
iBuf->unlock ();
// Finishing it...
sub->useSharedVertices = true;
msh->_setBounds (Ogre::AxisAlignedBox (-1, -1, -1, 1, 1, 1), false);
msh->_setBoundingSphereRadius (1);
msh->load ();
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: generateSphericDome DONE");
}
示例9: 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);
//.........这里部分代码省略.........
示例10: createSphere
void TutorialApplication::createSphere(const std::string& strName, const float r, const int nRings, const int nSegments) {
Ogre::MeshPtr pSphere = Ogre::MeshManager::getSingleton().createManual(Ogre::String(strName), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::SubMesh *pSphereVertex = pSphere->createSubMesh();
pSphere->sharedVertexData = new Ogre::VertexData();
Ogre::VertexData* vertexData = pSphere->sharedVertexData;
// define the vertex format
Ogre::VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// positions
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// normals
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// two dimensional texture coordinates
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
// allocate the vertex buffer
vertexData->vertexCount = (nRings + 1) * (nSegments+1);
Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::VertexBufferBinding* binding = vertexData->vertexBufferBinding;
binding->setBinding(0, vBuf);
float* pVertex = static_cast<float*>(vBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
// allocate index buffer
pSphereVertex->indexData->indexCount = 6 * nRings * (nSegments + 1);
pSphereVertex->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, pSphereVertex->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::HardwareIndexBufferSharedPtr iBuf = pSphereVertex->indexData->indexBuffer;
unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
float fDeltaRingAngle = (Ogre::Math::PI / nRings);
float fDeltaSegAngle = (2 * Ogre::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;
Ogre::Vector3 vNormal = Ogre::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( Ogre::AxisAlignedBox( Ogre::Vector3(-r, -r, -r), Ogre::Vector3(r, r, r) ), false );
pSphere->_setBoundingSphereRadius(r);
// this line makes clear the mesh is loaded (avoids memory leaks)
pSphere->load();
}
示例11: createTerrain
//.........这里部分代码省略.........
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat2");
datalib->getData("GameData/BattleData/MapData/Ground/G1Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat3");
datalib->getData("GameData/BattleData/MapData/Ground/G2Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat4");
datalib->getData("GameData/BattleData/MapData/Ground/G3Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
//创建地面Mesh
mTerrainNode = Core::getSingleton().mSceneMgr->getRootSceneNode()->createChildSceneNode("TerrainNode");
int numVertices = terrainszie * terrainszie * VERTEX_QUAD;
int numIndex = terrainszie * terrainszie * VERTEX_PREQUAD;
Ogre::MeshPtr mTerrainMesh = Ogre::MeshManager::getSingleton().createManual("TerrianMesh",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::SubMesh* subMesh = mTerrainMesh->createSubMesh();
subMesh->useSharedVertices=false;
subMesh->setMaterialName("TerrainTile");
// 创建顶点数据结构
subMesh->vertexData = new Ogre::VertexData();
subMesh->vertexData->vertexStart = 0;
subMesh->vertexData->vertexCount = numVertices;
//顶点声明与缓冲区绑定
Ogre::VertexDeclaration* vdecl = subMesh->vertexData->vertexDeclaration;
Ogre::VertexBufferBinding* vbind = subMesh->vertexData->vertexBufferBinding;
//设置顶点数据结构
size_t offsetUV = 0;
vdecl->addElement(VERTEX_POS_BINDING, 0, Ogre::VET_FLOAT3,Ogre::VES_POSITION);//向顶点添加一个位置元素
vdecl->addElement(VERTEX_NOM_BINDING, 0, Ogre::VET_FLOAT3,Ogre::VES_NORMAL);
for(int i = 0 ; i < TEXTURE_COUNT ; i ++)
{
offsetUV += vdecl->addElement (VERTEX_UV_BINDING, offsetUV, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES , i).getSize();
}
// 创建世界坐标顶点缓冲区
Ogre::HardwareVertexBufferSharedPtr vbufPos =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
vdecl->getVertexSize(VERTEX_POS_BINDING),
numVertices,
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
vbind->setBinding(VERTEX_POS_BINDING, vbufPos);
Ogre::HardwareVertexBufferSharedPtr vbufNOM =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
vdecl->getVertexSize(VERTEX_NOM_BINDING),