本文整理汇总了C++中MeshEntity::GetSubMeshes方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshEntity::GetSubMeshes方法的具体用法?C++ MeshEntity::GetSubMeshes怎么用?C++ MeshEntity::GetSubMeshes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshEntity
的用法示例。
在下文中一共展示了MeshEntity::GetSubMeshes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Visit
//! visits a particular entity
void ColorVisitor::Visit(Entity* pTarget)
{
SHOOT_ASSERT(pTarget->IsA(MeshEntity::TypeID), "ColorVisitor target is not of type MeshEntity");
SHOOT_ASSERT(pTarget->GetComponent<ExplosionVisitor>() == NULL, "Can't apply ColorVisitor and ExplosionVisitor simultaneously");
m_OriginalVertexBuffers.clear();
m_VertexBuffers.clear();
MeshEntity* pMesh = static_cast<MeshEntity*>(pTarget);
std::vector<SubMesh*>& subMeshes = pMesh->GetSubMeshes();
for(u32 i=0; i<subMeshes.size(); ++i)
{
GraphicComponent* pGraphic = subMeshes[i]->GetComponent<GraphicComponent>();
VertexBuffer* pSourceVB = pGraphic->GetVertexBuffer();
SHOOT_ASSERT(pSourceVB->GetDynamic(), "ColorVisitor needs a dynamic vertex buffer");
SHOOT_ASSERT(pSourceVB->GetPrimitiveType() == GraphicsDriver::PT_Triangle, "ColorVisitor only supported triangulated meshes for now");
SHOOT_ASSERT(pSourceVB->GetIndices(), "ColorVisitor only works with indexed vertex buffers");
VertexBuffer* pVB = static_cast<VertexBuffer*>(pSourceVB->Copy());
Vertex3D* pVertices = snew Vertex3D[pSourceVB->GetNumVertices()];
u16* pIndices = snew u16[pSourceVB->GetNumIndices()];
memcpy(pVertices, pSourceVB->GetVertices(), pSourceVB->GetNumVertices()*sizeof(Vertex3D));
memcpy(pIndices, pSourceVB->GetIndices(), pSourceVB->GetNumIndices()*sizeof(u16));
pVB->SetVertices(pVertices, pSourceVB->GetNumVertices());
pVB->SetIndices(pIndices, pSourceVB->GetNumIndices());
pVB->SetVertexFlag(Vertex3D::VF_Color);
m_OriginalVertexBuffers.push_back(pSourceVB);
m_VertexBuffers.push_back(pVB);
pGraphic->SetVertexBuffer(pVB);
}
m_fInterpolator = 0.0f;
GraphicComponent* pGraphic = subMeshes[0]->GetComponent<GraphicComponent>();
m_SrcColor = pGraphic->GetMaterial()->GetColor();
m_DestColor = m_Color;
super::Visit(pTarget);
}
示例2: OnPaint
void EEViewPort::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
_glContext->SetCurrent(*this);
Engine::Instance()->Render();
// custom rendering
GraphicsDriver::Instance()->SetRenderTarget(NULL);
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_DepthFunc, GraphicsDriver::CF_LessOrEqual);
GraphicsDriver::Instance()->SetTransform(GraphicsDriver::TS_Projection, EntityRenderer::Instance()->Get3DCamera()->GetProjectionMatrix());
GraphicsDriver::Instance()->SetTransform(GraphicsDriver::TS_View, EntityRenderer::Instance()->Get3DCamera()->GetViewMatrix());
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_LineWidth, 1.0f);
ExplosionEditor* pEditor = static_cast<ExplosionEditor*>(wxTheApp->GetTopWindow());
MeshEntity* pMesh = pEditor->GetCurrentMesh();
ExplosionVisitor* pExplosionVisitor = pMesh ? pMesh->GetComponent<ExplosionVisitor>() : NULL;
if(pMesh && pExplosionVisitor)
{
Color wireColor = Color::Create(0.5f, 0.5f, 0.5f);
Color selectedColor = Color::White;
Color chunkColor = Color::Create(0.5f, 0.0f, 0.5f, 0.5f);
Color selectedChunkColor = Color::Create(1.0f, 1.0f, 0.0f, 0.5f);
std::vector<SubMesh*> subMeshes = pMesh->GetSubMeshes();
Array<ExplosionVisitor::ChunkGroup>& aChunkGroups = pExplosionVisitor->GetChunkGroups();
Material* pMaterial = pEditor->GetMaterial();
pMaterial->Begin();
pMaterial->GetShader()->Begin();
for(uint i=0; i<(uint)subMeshes.size(); ++i)
{
VertexBuffer* pVB = subMeshes[i]->GetComponent<GraphicComponent>()->GetVertexBuffer();
Vertex3D* pVertices = reinterpret_cast<Vertex3D*>(pVB->GetVertices());
//ushort* pIndices = (ushort*)pVB->GetIndices();
GraphicsDriver::Instance()->SetTransform(GraphicsDriver::TS_World, subMeshes[i]->GetWorldTransform());
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_FillMode, GraphicsDriver::FM_Line);
pMaterial->GetShader()->UploadConstant<Color>("uAmbientColor", &wireColor, 1);
pVB->Begin(pMaterial->GetShader());
pVB->Draw();
pVB->End();
// render explosion chunks
int selectedChunk = pEditor->GetSelectedChunk();
int selectedSubMesh = pEditor->GetSelectedSubMesh();
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_AlphaBlending, true);
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_FillMode, GraphicsDriver::FM_Solid);
Array<ExplosionVisitor::Chunk>& aChunks = aChunkGroups[i].m_aChunks;
for(uint j=0; j<aChunks.GetSize(); ++j)
{
if(i == selectedSubMesh
&& j == selectedChunk)
{
GraphicsDriver::Instance()->SetCullMode(GraphicsDriver::CM_None);
pMaterial->GetShader()->UploadConstant<Color>("uAmbientColor", &selectedChunkColor, 1);
}
else
{
GraphicsDriver::Instance()->SetCullMode(GraphicsDriver::CM_CounterClockWise);
pMaterial->GetShader()->UploadConstant<Color>("uAmbientColor", &chunkColor, 1);
}
for (uint k = 0; k<aChunks[j].aTriangleIndices.GetSize(); ++k)
{
uint triangleIndex = aChunks[j].aTriangleIndices[k];
pEditor->DrawTriangle(pVertices[(triangleIndex*3)+0].Pos, pVertices[(triangleIndex*3)+1].Pos, pVertices[(triangleIndex*3)+2].Pos);
}
}
GraphicsDriver::Instance()->SetCullMode(GraphicsDriver::CM_CounterClockWise);
if(m_SelectedTriangleIndex >= 0 && m_SelectedSubMeshIndex == i)
{
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_FillMode, GraphicsDriver::FM_Line);
pMaterial->GetShader()->UploadConstant<Color>("uAmbientColor", &selectedColor, 1);
pEditor->DrawTriangle(pVertices[(m_SelectedTriangleIndex*3)+0].Pos, pVertices[(m_SelectedTriangleIndex*3)+1].Pos, pVertices[(m_SelectedTriangleIndex*3)+2].Pos);
}
}
pEditor->GetMaterial()->GetShader()->End();
pEditor->GetMaterial()->End();
}
GraphicsDriver::Instance()->SetRenderState(GraphicsDriver::RS_FillMode, GraphicsDriver::FM_Solid);
glFlush();
SwapBuffers();
}