本文整理汇总了C++中ogre::SubMesh类的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh类的具体用法?C++ SubMesh怎么用?C++ SubMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getSubMeshByOriginalMaterialName
unsigned GfxBody::getSubMeshByOriginalMaterialName (const std::string &n)
{
for (unsigned i=0 ; i<mesh->getNumSubMeshes() ; ++i) {
Ogre::SubMesh *sm = mesh->getSubMesh(i);
if (sm->getMaterialName() == n) {
return i;
}
}
CERR << "Mesh did not contain material \""<<n<<"\"" <<std::endl;
return 0;
}
示例3: 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");
}
}
示例4: 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");
}
}
}
示例5:
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;
}
示例6: unloadTheMesh
// unload all about this mesh. The mesh itself and the textures.
// BETWEEN FRAME OPERATION
void VisCalcFrustDist::unloadTheMesh(Ogre::MeshPtr meshP) {
if (m_shouldCullTextures) {
Ogre::Mesh::SubMeshIterator smi = meshP->getSubMeshIterator();
while (smi.hasMoreElements()) {
Ogre::SubMesh* oneSubMesh = smi.getNext();
Ogre::String subMeshMaterialName = oneSubMesh->getMaterialName();
Ogre::MaterialPtr subMeshMaterial = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(subMeshMaterialName);
if (!subMeshMaterial.isNull()) {
Ogre::Material::TechniqueIterator techIter = subMeshMaterial->getTechniqueIterator();
while (techIter.hasMoreElements()) {
Ogre::Technique* oneTech = techIter.getNext();
Ogre::Technique::PassIterator passIter = oneTech->getPassIterator();
while (passIter.hasMoreElements()) {
Ogre::Pass* onePass = passIter.getNext();
Ogre::Pass::TextureUnitStateIterator tusIter = onePass->getTextureUnitStateIterator();
while (tusIter.hasMoreElements()) {
Ogre::TextureUnitState* oneTus = tusIter.getNext();
Ogre::String texName = oneTus->getTextureName();
Ogre::TexturePtr texP = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(texName);
if (!texP.isNull()) {
// if (texP.useCount() <= 1) {
texP->unload();
LG::IncStat(LG::StatCullTexturesUnloaded);
// LG::Log("unloadTheMesh: unloading texture %s", texName.c_str());
// }
}
}
}
}
}
}
}
if (m_shouldCullMeshes) {
LG::OLMeshTracker::Instance()->MakeUnLoaded(meshP->getName(), Ogre::String(), NULL);
LG::IncStat(LG::StatCullMeshesUnloaded);
// LG::Log("unloadTheMesh: unloading mesh %s", mshName.c_str());
}
}
示例7: reinitialise
void GfxBody::reinitialise (void)
{
APP_ASSERT(mesh->isLoaded());
destroyGraphics();
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {
Ogre::SubMesh *sm = mesh->getSubMesh(i);
Sub* sub = new Sub(this, sm);
subList.push_back(sub);
GFX_MAT_SYNC;
std::string matname = apply_map(initialMaterialMap, sm->getMaterialName());
if (!gfx_material_has(matname)) {
CERR << "Mesh \"/"<<mesh->getName()<<"\" references non-existing material "
<< "\""<<matname<<"\""<<std::endl;
matname = "/system/FallbackMaterial";
}
sub->material = gfx_material_get(matname);
}
if (!mesh->getSkeleton().isNull()) {
skeleton = OGRE_NEW Ogre::SkeletonInstance(mesh->getSkeleton());
skeleton->load();
numBoneMatrixes = skeleton->getNumBones();
boneMatrixes = static_cast<Ogre::Matrix4*>(OGRE_MALLOC_SIMD(sizeof(Ogre::Matrix4) * numBoneMatrixes, Ogre::MEMCATEGORY_ANIMATION));
boneWorldMatrixes = static_cast<Ogre::Matrix4*>(OGRE_MALLOC_SIMD(sizeof(Ogre::Matrix4) * numBoneMatrixes, Ogre::MEMCATEGORY_ANIMATION));
mesh->_initAnimationState(&animationState);
} else {
skeleton = NULL;
numBoneMatrixes = 0;
boneMatrixes = NULL;
boneWorldMatrixes = NULL;
}
updateBones();
}
示例8: 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)
//.........这里部分代码省略.........
示例9: 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().
//.........这里部分代码省略.........
示例10: 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;
}
示例11: EngineSetup
//.........这里部分代码省略.........
ManualObject->position(1, 0, 0);
ManualObject->position(1, 1, 0);
ManualObject->position(1, 1, 1);
ManualObject->triangle(18, 19, 20);
ManualObject->position(1, 0, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(1, 0, 1);
ManualObject->triangle(21, 22, 23);
//face 5
ManualObject->position(0, 1, 0);
ManualObject->position(1, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(24, 25, 26);
ManualObject->position(1, 1, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(0, 1, 1);
ManualObject->triangle(27, 28, 29);
//face 6
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 1);
ManualObject->position(0, 0, 1);
ManualObject->triangle(30, 31, 32);
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(33, 34, 35);
ManualObject->end();
Ogre::MeshPtr MeshPtr = ManualObject->convertToMesh("Animation");
Ogre::SubMesh* sub = MeshPtr->getSubMesh(0);
Ogre::SkeletonPtr Skeleton = Ogre::SkeletonManager::getSingleton().create("Skeleton", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
MeshPtr.getPointer()->_notifySkeleton(Skeleton);
Ogre::Bone *Root1 = NULL;
Ogre::Bone *Child1 = NULL;
Ogre::Bone *Child2 = NULL;
Root1 = Skeleton.getPointer()->createBone("Root");
Root1->setPosition(Ogre::Vector3(0.0, 0.0, 0.0));
Root1->setOrientation(Ogre::Quaternion::IDENTITY);
Child1 = Root1->createChild(1);
Child1->setPosition(Ogre::Vector3(4.0, 0.0, 0.0));
Child1->setOrientation(Ogre::Quaternion::IDENTITY);
Child2 = Root1->createChild(2);
Child2->setPosition(Ogre::Vector3(5.0, 0.0, 0.0));
Child2->setOrientation(Ogre::Quaternion::IDENTITY);
Ogre::VertexBoneAssignment Assignment;
Assignment.boneIndex = 0;
Assignment.vertexIndex = 0;
Assignment.weight = 1.0;
Skeleton->setBindingPose();
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 1;
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 2;
sub->addBoneAssignment(Assignment);
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:67,代码来源:SceletalAnimationView.cpp
示例12: createLine
void WaterObjectView::createLine()
{
size_t verticesCount = ((mWaterObject->getPointCount() - 1) * mSegments + 1) * 2;
size_t verticesSize = verticesCount * 5;
size_t indicesSize = ((mWaterObject->getPointCount() - 1) * mSegments) * 6;
verticesCount = mWaterObject->getPointCount() * 2;
verticesSize = verticesCount * 5;
indicesSize = (mWaterObject->getPointCount() - 1) * 6;
Ogre::Real* vertices = new Ogre::Real[verticesSize];
Ogre::uint16* indices = new Ogre::uint16[indicesSize];
unsigned int i, index = 0;
// Prepare vertices.
for (i = 0; i < mWaterObject->getPointCount(); ++i)
{
const Point3D& point3D = mWaterObject->getPoint(i);
vertices[index++] = point3D.x - mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.y;
vertices[index++] = point3D.z + 1.0f;
vertices[index++] = point3D.x - mWaterObject->getWidth() * 0.5f;;
vertices[index++] = point3D.z;
vertices[index++] = point3D.x + mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.y;
vertices[index++] = point3D.z + 1.0f;
vertices[index++] = point3D.x + mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.z;
}
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;
//.........这里部分代码省略.........
示例13: renderFirstPerson
void GfxBody::renderFirstPerson (const GfxShaderGlobals &g,
bool alpha_blend)
{
if (!enabled || fade < 0.000001) return;
bool do_wireframe = (wireframe || gfx_option(GFX_WIREFRAME));
bool do_regular = !(do_wireframe && gfx_option(GFX_WIREFRAME_SOLID));
bool fade_dither = fade < 1;
bool instanced = false;
unsigned bone_weights = mesh->getNumBlendWeightsPerVertex();
const Ogre::Matrix4 &world = node->_getFullTransform();
// TODO(dcunnin): object parameters
// this is to protect the material to texture mappings which might be
// concurrently read by the background loading thread
// TODO: use a RW lock to avoid stalls
GFX_MAT_SYNC;
for (unsigned i=0 ; i<subList.size() ; ++i) {
Sub *sub = subList[i];
GfxMaterial *mat = sub->material;
// Skip if wrong kind of material for this set of passes
bool mat_alpha = mat->getSceneBlend() != GFX_MATERIAL_OPAQUE;
if (alpha_blend != mat_alpha) continue;
Ogre::SubMesh *sm = mesh->getSubMesh(i);
if (do_regular) {
// render sm using mat
const GfxMaterialTextureMap &mat_texs = mat->getTextures();
mat->getShader()->bindShader(GfxShader::FIRST_PERSON,
fade_dither, instanced, bone_weights,
g, world, boneWorldMatrixes, numBoneMatrixes, fade,
mat_texs, mat->getBindings());
switch (mat->getSceneBlend()) {
case GFX_MATERIAL_OPAQUE:
ogre_rs->_setDepthBufferParams(true, true, Ogre::CMPF_LESS_EQUAL);
ogre_rs->_setSceneBlending(Ogre::SBF_ONE, Ogre::SBF_ZERO);
break;
case GFX_MATERIAL_ALPHA:
ogre_rs->_setDepthBufferParams(true, false, Ogre::CMPF_LESS_EQUAL);
ogre_rs->_setSceneBlending(Ogre::SBF_ONE, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
break;
case GFX_MATERIAL_ALPHA_DEPTH:
ogre_rs->_setDepthBufferParams(true, true, Ogre::CMPF_LESS_EQUAL);
ogre_rs->_setSceneBlending(Ogre::SBF_ONE, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
break;
}
ogre_rs->_setPolygonMode(Ogre::PM_SOLID);
ogre_rs->setStencilCheckEnabled(false);
Ogre::RenderOperation op;
sm->_getRenderOperation(op);
ogre_rs->_render(op);
for (unsigned i=0 ; i<mat_texs.size() ; ++i) {
ogre_rs->_disableTextureUnit(i);
}
}
if (do_wireframe) {
mat->getShader()->bindShader(GfxShader::WIRE_FRAME, false, false, 0,
g, world, boneWorldMatrixes, numBoneMatrixes, 1,
GfxMaterialTextureMap(), mat->getBindings());
ogre_rs->_setDepthBufferParams(true, false, Ogre::CMPF_LESS_EQUAL);
ogre_rs->_setSceneBlending(Ogre::SBF_ONE, Ogre::SBF_ZERO);
ogre_rs->_setPolygonMode(Ogre::PM_WIREFRAME);
ogre_rs->setStencilCheckEnabled(false);
Ogre::RenderOperation op;
sm->_getRenderOperation(op);
ogre_rs->_render(op);
}
}
}
示例14: GetMeshInformation
void SceneObject::GetMeshInformation(
const Ogre::MeshPtr mesh,
size_t& vertex_count,
Ogre::Vector3* &vertices,
size_t& index_count,
unsigned long* &indices,
Ogre::Vector2* &coords,
const Ogre::Vector3& position,
const Ogre::Quaternion& orient,
const Ogre::Vector3& scale,
const std::string& _material)
{
bool added_shared = false;
size_t current_offset = 0;
//size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 0;
vertex_count = index_count = 0;
// Calculate how many vertices and indices we're going to need
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh( i );
if (submesh->getMaterialName() != _material)
continue;
// We only need to add the shared vertices once
if (submesh->useSharedVertices)
{
if ( !added_shared )
{
vertex_count += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else
{
vertex_count += submesh->vertexData->vertexCount;
}
// Add the indices
index_count += submesh->indexData->indexCount;
}
// Allocate space for the vertices and indices
vertices = new Ogre::Vector3[vertex_count];
indices = new unsigned long[index_count];
coords = new Ogre::Vector2[vertex_count];
added_shared = false;
// Run through the submeshes again, adding the data into the arrays
for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
if (submesh->getMaterialName() != _material)
continue;
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared))
{
if (submesh->useSharedVertices)
{
added_shared = true;
//shared_offset = current_offset;
}
const Ogre::VertexElement* coordElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);
const Ogre::VertexElement* posElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf =
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char* vertex =
static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Real* pReal;
float* pReal;
for ( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
vertices[current_offset + j] = (orient * (pt * scale)) + position;
posElem->baseVertexPointerToElement(vertex + coordElem->getOffset() - posElem->getOffset(), &pReal);
Ogre::Vector2 coord(pReal[0], pReal[1]);
coords[current_offset + j] = coord;
}
//.........这里部分代码省略.........
示例15: update
void LIRenAttachmentEntity::update (float secs)
{
/* Check if background loading has finished. */
if (loaded)
return;
lisys_assert (entity == NULL);
/* Wait for the mesh to load. */
if (!mesh->isLoaded ())
{
if (loading_mesh)
return;
loading_mesh = true;
#ifdef LIREN_BACKGROUND_LOADING
Ogre::ResourceBackgroundQueue::getSingleton ().load (
"Mesh", mesh->getName (), mesh->getGroup ());
#else
mesh->load ();
#endif
return;
}
/* Start loading dependencies. */
if (!loading_deps)
{
loading_deps = true;
for (size_t i = 0 ; i < mesh->getNumSubMeshes () ; i++)
{
Ogre::SubMesh* sub = mesh->getSubMesh (i);
if (sub->isMatInitialised ())
{
Ogre::MaterialManager& mgr = Ogre::MaterialManager::getSingleton ();
Ogre::MaterialPtr material = mgr.getByName (sub->getMaterialName (), mesh->getGroup ());
if (!material.isNull ())
{
resources.push_back (material);
#ifdef LIREN_BACKGROUND_LOADING
Ogre::ResourceBackgroundQueue::getSingleton ().load (
"Material", material->getName (), material->getGroup ());
#else
material->load (true);
#endif
}
}
}
return;
}
// Wait for the dependencies to load.
for (size_t i = 0 ; i < resources.size () ; i++)
{
Ogre::ResourcePtr& resource = resources[i];
if (!resource->isLoaded ())
return;
}
// Create the entity.
Ogre::String e_name = render->id.next ();
entity = render->scene_manager->createEntity (e_name, mesh->getName (), LIREN_RESOURCES_TEMPORARY);
object->node->attachObject (entity);
// Create the skeleton and its pose buffer.
if (create_skeleton ())
{
LIRenModelData* model = get_model ();
lisys_assert (pose_buffer == NULL);
if (model != NULL)
{
pose_buffer = limdl_pose_buffer_new_copy (model->rest_pose_buffer);
lisys_assert (pose_buffer != NULL);
lisys_assert (pose_buffer->bones.count == entity->getSkeleton ()->getNumBones ());
}
}
// Set the entity flags.
entity->setCastShadows (object->get_shadow_casting ());
// Trigger queued texture replacements.
//
// This needs to be done before showing the entity in order to avoid
// the textures flickering for a few frames.
for (size_t i = 0 ; i < queued_texture_replaces.size () ; ++i)
{
LIRenTextureReplace& repl = queued_texture_replaces[i];
replace_texture_now (repl.name, repl.texture);
}
queued_texture_replaces.clear();
// Set entity visibility.
//
// If a visible entity is added to a hidden scene node, the entity is
// still rendered. Hence, newly added entities needs to be explicitly
// hidden or Ogre will render our invisible objects. */
entity->setVisible (object->get_visible ());
// Apply queued settings.
update_settings ();
// Clear the now useless dependency list.
resources.clear ();
//.........这里部分代码省略.........