本文整理汇总了C++中ogre::SubMesh::setMaterialName方法的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh::setMaterialName方法的具体用法?C++ SubMesh::setMaterialName怎么用?C++ SubMesh::setMaterialName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::SubMesh
的用法示例。
在下文中一共展示了SubMesh::setMaterialName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setMaterialNames
void GraphicsResourceMesh::setMaterialNames(GraphicsResourceMesh* resourcePtr)
{
Ogre::ResourcePtr meshResource = Ogre::MeshManager::getSingleton().getByName(resourcePtr->getID());
Ogre::Mesh* meshPtr = static_cast<Ogre::Mesh *>(&*meshResource);
Ogre::Mesh::SubMeshIterator currSubMeshIter = meshPtr->getSubMeshIterator();
while (currSubMeshIter.hasMoreElements()) {
Ogre::SubMesh *curSubMesh = currSubMeshIter.getNext();
if (!OPTION_ENABLE_TEXTURES->as<bool>()) {
curSubMesh->setMaterialName("BaseWhiteTexture");
}
else {
const Ogre::String& curMatName = curSubMesh->getMaterialName();
int pos = curMatName.find_last_of(':');
if (pos != -1) {
String start = curMatName.substr(0, pos);
String ending = curMatName.substr(pos);
std::map<String, String>::iterator itr = resourcePtr->mMaterialNames.find(start);
if (itr != resourcePtr->mMaterialNames.end())
curSubMesh->setMaterialName(itr->second + ending);
}
}
}
}
示例2: SetDefaultMaterial
void OgreMeshAsset::SetDefaultMaterial()
{
if (!ogreMesh.get())
return;
for(unsigned short i = 0; i < ogreMesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh *submesh = ogreMesh->getSubMesh(i);
if (submesh)
submesh->setMaterialName("LitTextured");
}
}
示例3: SetDefaultMaterial
void OgreMeshAsset::SetDefaultMaterial()
{
if (ogreMesh.isNull())
return;
// originalMaterials.clear();
for (uint i = 0; i < ogreMesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh *submesh = ogreMesh->getSubMesh(i);
if (submesh)
{
// originalMaterials.push_back(submesh->getMaterialName().c_str());
submesh->setMaterialName("LitTextured");
}
}
}
示例4:
Ogre::SubMesh *EMDOgre::createOgreSubmesh(EMDTriangles *triangles, Ogre::MeshPtr mesh, std::string material_name) {
Ogre::SubMesh *sub = mesh->createSubMesh();
sub->setMaterialName(name + "_" + material_name + ".material");
const size_t ibufCount = triangles->faces.size();
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i<ibufCount; i++) {
faces[i] = triangles->faces[i];
}
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;
free(faces);
return sub;
}
示例5: createTerrain
//.........这里部分代码省略.........
name, "General").get();
// Create one submesh.
Ogre::SubMesh* subMesh = mMeshes[tileIndex]->createSubMesh();
// Create vertex data structure for vertices shared between submeshes.
mMeshes[tileIndex]->sharedVertexData = new Ogre::VertexData();
mMeshes[tileIndex]->sharedVertexData->vertexCount = vertexPerTile;
// Create declaration (memory format) of vertex data.
Ogre::VertexDeclaration* decl =
mMeshes[tileIndex]->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
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);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// Allocate vertex buffer of the requested number of vertices (vertexPerTile)
// and bytes per vertex (offset).
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset, vertexPerTile, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), &(vertices.front()), true);
// Set vertex buffer binding so buffer 0 is bound to our vertex buffer.
Ogre::VertexBufferBinding* bind =
mMeshes[tileIndex]->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
// Allocate index buffer of the requested number of vertices .
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
trianglesPerTile * 3,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the index data to the card.
ibuf->writeData(0, ibuf->getSizeInBytes(), &(indices[0].front()), true);
/// Set parameters of the submesh
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = indices[0].size();
subMesh->indexData->indexStart = 0;
subMesh->setMaterialName("terrain");
float xMin = vertices[0];
float yMin = vertices[1];
float zMin = vertices[2];
float xMax = vertices[0];
float yMax = vertices[1];
float zMax = vertices[2];
for (unsigned int i = 0; i < vertexPerTile * 11; i += 11)
{
if (vertices[i ] < xMin) xMin = vertices[i ]; else
if (vertices[i ] > xMax) xMax = vertices[i ];
if (vertices[i + 1] < yMin) yMin = vertices[i + 1]; else
if (vertices[i + 1] > yMax) yMax = vertices[i + 1];
if (vertices[i + 2] < zMin) zMin = vertices[i + 2]; else
if (vertices[i + 2] > zMax) zMax = vertices[i + 2];
}
// Set bounding information (for culling).
mMeshes[tileIndex]->_setBounds(Ogre::AxisAlignedBox(xMin, yMin, zMin, xMax, yMax, zMax));
mMeshes[tileIndex]->_setBoundingSphereRadius(1.0f);
// Notify Mesh object that it has been loaded.
mMeshes[tileIndex]->load();
// Create entity.
mEntities[tileIndex] = createEntity(name, name);
mEntities[tileIndex]->setCastShadows(false);
mEntities[tileIndex]->setUserAny(Ogre::Any(this));
// Create scene node.
mSceneNodes[tileIndex] = createSceneNode();
mSceneNodes[tileIndex]->attachObject(mEntities[tileIndex]);
// Advance to next tile.
tileIndex++;
}
}
}
示例6: createSubMesh
//.........这里部分代码省略.........
std::vector<Ogre::RGBA> colorsRGB(colors.size());
for(size_t i = 0;i < colorsRGB.size();i++)
{
Ogre::ColourValue clr(colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
rs->convertColourValue(clr, &colorsRGB[i]);
}
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR),
colorsRGB.size(), Ogre::HardwareBuffer::HBU_STATIC);
vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB[0], true);
decl->addElement(nextBuf, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
bind->setBinding(nextBuf++, vbuf);
}
// Texture UV coordinates
size_t numUVs = data->uvlist.size();
if (numUVs)
{
size_t elemSize = Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
for(size_t i = 0; i < numUVs; i++)
decl->addElement(nextBuf, elemSize*i, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, i);
vbuf = hwBufMgr->createVertexBuffer(decl->getVertexSize(nextBuf), srcVerts.size(),
Ogre::HardwareBuffer::HBU_STATIC);
std::vector<Ogre::Vector2> allUVs;
allUVs.reserve(srcVerts.size()*numUVs);
for (size_t vert = 0; vert<srcVerts.size(); ++vert)
for(size_t i = 0; i < numUVs; i++)
allUVs.push_back(data->uvlist[i][vert]);
vbuf->writeData(0, elemSize*srcVerts.size()*numUVs, &allUVs[0], true);
bind->setBinding(nextBuf++, vbuf);
}
// Triangle faces
const std::vector<short> &srcIdx = data->triangles;
if(srcIdx.size())
{
ibuf = hwBufMgr->createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, srcIdx.size(),
Ogre::HardwareBuffer::HBU_STATIC);
ibuf->writeData(0, ibuf->getSizeInBytes(), &srcIdx[0], true);
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = srcIdx.size();
sub->indexData->indexStart = 0;
}
// Assign bone weights for this TriShape
if(skin != NULL)
{
Ogre::SkeletonPtr skel = Ogre::SkeletonManager::getSingleton().getByName(mName);
const Nif::NiSkinData *data = skin->data.getPtr();
const Nif::NodeList &bones = skin->bones;
for(size_t i = 0;i < bones.length();i++)
{
Ogre::VertexBoneAssignment boneInf;
boneInf.boneIndex = skel->getBone(bones[i]->name)->getHandle();
const std::vector<Nif::NiSkinData::VertWeight> &weights = data->bones[i].weights;
for(size_t j = 0;j < weights.size();j++)
{
boneInf.vertexIndex = weights[j].vertex;
boneInf.weight = weights[j].weight;
sub->addBoneAssignment(boneInf);
}
}
}
const Nif::NiTexturingProperty *texprop = NULL;
const Nif::NiMaterialProperty *matprop = NULL;
const Nif::NiAlphaProperty *alphaprop = NULL;
const Nif::NiVertexColorProperty *vertprop = NULL;
const Nif::NiZBufferProperty *zprop = NULL;
const Nif::NiSpecularProperty *specprop = NULL;
const Nif::NiWireframeProperty *wireprop = NULL;
bool needTangents = false;
shape->getProperties(texprop, matprop, alphaprop, vertprop, zprop, specprop, wireprop);
std::string matname = NIFMaterialLoader::getMaterial(data, mesh->getName(), mGroup,
texprop, matprop, alphaprop,
vertprop, zprop, specprop,
wireprop, needTangents);
if(matname.length() > 0)
sub->setMaterialName(matname);
// build tangents if the material needs them
if (needTangents)
{
unsigned short src,dest;
if (!mesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src,dest))
mesh->buildTangentVectors(Ogre::VES_TANGENT, src,dest);
}
// Create a dummy vertex animation track if there's a geom morpher controller
// This is required to make Ogre create the buffers we will use for software vertex animation
if (srcVerts.size() && geomMorpherController)
mesh->createAnimation("dummy", 0)->createVertexTrack(1, sub->vertexData, Ogre::VAT_MORPH);
}
示例7: 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().
//.........这里部分代码省略.........
示例8: SetData
bool OgreMeshResource::SetData(Foundation::AssetPtr source)
{
if (!source)
{
OgreRenderingModule::LogError("Null source asset data pointer");
return false;
}
if (!source->GetSize())
{
OgreRenderingModule::LogError("Zero sized mesh asset");
return false;
}
try
{
if (ogre_mesh_.isNull())
{
ogre_mesh_ = Ogre::MeshManager::getSingleton().createManual(
id_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (ogre_mesh_.isNull())
{
OgreRenderingModule::LogError("Failed to create mesh " + id_);
return false;
}
ogre_mesh_->setAutoBuildEdgeLists(false);
}
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream((void*)source->GetData(), source->GetSize(), false));
Ogre::MeshSerializer serializer;
serializer.importMesh(stream, ogre_mesh_.getPointer());
// Generate tangents to mesh
try
{
unsigned short src, dest;
if (!ogre_mesh_->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
ogre_mesh_->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
}
catch (...) {}
// Generate extremity points to submeshes, 1 should be enough
try
{
for(uint i = 0; i < ogre_mesh_->getNumSubMeshes(); ++i)
{
Ogre::SubMesh *smesh = ogre_mesh_->getSubMesh(i);
if (smesh)
smesh->generateExtremes(1);
}
}
catch (...) {}
// Assign default materials that won't complain
original_materials_.clear();
for (uint i = 0; i < ogre_mesh_->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = ogre_mesh_->getSubMesh(i);
if (submesh)
{
original_materials_.push_back(submesh->getMaterialName());
submesh->setMaterialName("UnlitTextured");
}
}
}
catch (Ogre::Exception &e)
{
OgreRenderingModule::LogError("Failed to create mesh " + id_ + ": " + std::string(e.what()));
RemoveMesh();
return false;
}
OgreRenderingModule::LogDebug("Ogre mesh " + id_ + " created");
return true;
}
示例9: 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++)
//.........这里部分代码省略.........
示例10: 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)
//.........这里部分代码省略.........
示例11: createMesh
//.........这里部分代码省略.........
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);
//unsigned short *faceVertexIndices = (unsigned short*)
//indexBuffer->lock(0, numFaces*3*2, HardwareBuffer::HBL_DISCARD);
// Set index buffer for this submesh
sm->indexData->indexBuffer = indexBuffer;
sm->indexData->indexStart = 0;
sm->indexData->indexCount = 3*numFaces;
indexBuffer->writeData(0,indexBuffer->getSizeInBytes(),indices,true);
}
//vdecl->sort();
m->load();
m->touch();
m->_setBounds(AxisAlignedBox(data.bbox[0],data.bbox[1],data.bbox[2],
data.bbox[3],data.bbox[4],data.bbox[5]), false);
sm->setMaterialName("Terrain");
Ogre::Entity* ent = mSceneManager->createEntity(nombre,m->getName());
Ogre::SceneNode* node = mSceneManager->createSceneNode(nombre);
node->attachObject(ent);
ent->setCastShadows(false);
Mesh* mm = new Mesh(nombre,node,ent);
mSceneNodes.push_back(mm);
return mm;
}
示例12: createLine
//.........这里部分代码省略.........
}
index = 0;
// Prepare indices.
for (i = 0; i < verticesCount - 2; i += 2)
{
indices[index++] = (Ogre::uint16)i;
indices[index++] = (Ogre::uint16)i + 2;
indices[index++] = (Ogre::uint16)i + 1;
indices[index++] = (Ogre::uint16)i + 2;
indices[index++] = (Ogre::uint16)i + 3;
indices[index++] = (Ogre::uint16)i + 1;
}
// Create mesh.
mMesh = Ogre::MeshManager::getSingleton().createManual(
Ogre::StringConverter::toString(mID), "General").get();
// Create one submesh.
Ogre::SubMesh* sub = mMesh->createSubMesh();
// Create vertex data structure for 8 vertices shared between submeshes.
mMesh->sharedVertexData = new Ogre::VertexData();
mMesh->sharedVertexData->vertexCount = verticesCount;
// Create declaration (memory format) of vertex data.
Ogre::VertexDeclaration* decl = mMesh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
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);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset, mMesh->sharedVertexData->vertexCount,
Ogre::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
Ogre::VertexBufferBinding* bind =
mMesh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
/// Allocate index buffer of the requested number of vertices (ibufCount).
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
indicesSize,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card.
ibuf->writeData(0, ibuf->getSizeInBytes(), indices, true);
/// Set parameters of the submesh.
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = indicesSize;
sub->indexData->indexStart = 0;
sub->setMaterialName("Ocean2_Cg");
float xMin = vertices[0];
float yMin = vertices[1];
float zMin = vertices[2];
float xMax = vertices[0];
float yMax = vertices[1];
float zMax = vertices[2];
for (i = 0; i < verticesSize; i += 5)
{
if (vertices[i ] < xMin) xMin = vertices[i ]; else
if (vertices[i ] > xMax) xMax = vertices[i ];
if (vertices[i + 1] < yMin) yMin = vertices[i + 1]; else
if (vertices[i + 1] > yMax) yMax = vertices[i + 1];
if (vertices[i + 2] < zMin) zMin = vertices[i + 2]; else
if (vertices[i + 2] > zMax) zMax = vertices[i + 2];
}
/// Set bounding information (for culling).
mMesh->_setBounds(Ogre::AxisAlignedBox(xMin, yMin, zMin, xMax, yMax, zMax));
mMesh->_setBoundingSphereRadius(1.0f);
/// Notify Mesh object that it has been loaded.
mMesh->load();
delete [] vertices;
delete [] indices;
}
示例13: createTerrain
//.........这里部分代码省略.........
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),
numVertices,
Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);