当前位置: 首页>>代码示例>>C++>>正文


C++ Mesh::AddChild方法代码示例

本文整理汇总了C++中Mesh::AddChild方法的典型用法代码示例。如果您正苦于以下问题:C++ Mesh::AddChild方法的具体用法?C++ Mesh::AddChild怎么用?C++ Mesh::AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh::AddChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Import

Resource* ASEImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    ASEFile aseFile;

    try
    {
        ASE::MeshReader   reader(aseFile);
        reader.Read( pFilename );
    }
    catch( Exception& /*e*/ )
    {
        return NULL;
    }    

    if(aseFile.mGeomObjects.size() == 0)
        return NULL;
	
    Map<const ASEFile::Material*, ASESubMesh> mSubMeshes; 
    GenerateSubMeshes(aseFile, mSubMeshes);

    // Create mesh instance
    Mesh* newMesh = Cast<Mesh>(GraphicSubsystem::Instance()->Create( Mesh::StaticClass() ));
    
    // Create all submeshes
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMesh;
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMeshBegin = mSubMeshes.begin();
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMeshEnd = mSubMeshes.end();
    for(itSubMesh = itSubMeshBegin; itSubMesh != itSubMeshEnd; ++itSubMesh)
    {
        const ASEFile::Material& mat = *(*itSubMesh).first;
        const ASESubMesh& aseSubMesh = (*itSubMesh).second;

        // Create the sub mesh
        Mesh* subMesh = Cast<Mesh>(GraphicSubsystem::Instance()->Create( Mesh::StaticClass() ));
        newMesh->AddChild(subMesh);

        // Create VB
	    subMesh->GetVertexList().Allocate( aseSubMesh.mVertices.size(), (VertexFormat::Component) (VertexFormat::Position3 | VertexFormat::Normal3 | VertexFormat::TexCoord2 ));
        Vector3f* ptrPosition = subMesh->GetVertexList().GetPositions();
        Vector3f* ptrNormal   = subMesh->GetVertexList().GetNormals();
        Vector2f* ptrTexCoord = subMesh->GetVertexList().GetTextureCoords();

        UInt32 i = 0;
        for(Vector<ASEVertex>::const_iterator itVertex = aseSubMesh.mVertices.begin(); itVertex != aseSubMesh.mVertices.end(); ++itVertex, ++i)
        {
            ptrPosition[i].x = (*itVertex).mPosition.x;
            ptrPosition[i].y = (*itVertex).mPosition.z;
            ptrPosition[i].z = (*itVertex).mPosition.y;
            
            ptrNormal[i].x = (*itVertex).mNormal.x; 
            ptrNormal[i].y = (*itVertex).mNormal.z; 
            ptrNormal[i].z = (*itVertex).mNormal.y; 

            ptrTexCoord[i] = (*itVertex).mUV; 
        }

        // Create IB
        {
            subMesh->GetTriangles().Allocate( TriangleBatch::TriangleList, aseSubMesh.mIndices.size());
            UInt16* ptrIndices = subMesh->GetTriangles().GetIndices();
        
            UInt32 i = 0;
            for(Vector<UInt32>::const_iterator itIndex = aseSubMesh.mIndices.begin(); itIndex != aseSubMesh.mIndices.end(); ++itIndex, ++i)
                ptrIndices[i] = *itIndex;
        }

        // Shader
        {
            TextureShader* shader = GD_NEW(TextureShader, this, "TextureShader");

            if(mat.mMapDiffuse.mBitmap.size() != 0)
            {
                HTexture2D hdl( mat.mMapDiffuse.mBitmap );
                hdl->GetImage().FlipY();
                hdl->Update();
                shader->mTexture = hdl;
            }
            else if(mat.mMapGeneric.mBitmap.size() != 0)
            {
                HTexture2D hdl( mat.mMapGeneric.mBitmap );
                hdl->GetImage().FlipY();
                hdl->Update();
                shader->mTexture = hdl;
            }

            shader->mMaterial.mAmbient   = Color4f(mat.mAmbient.R, mat.mAmbient.G, mat.mAmbient.B);
            shader->mMaterial.mDiffuse   = Color4f(mat.mDiffuse.R, mat.mDiffuse.G, mat.mDiffuse.B);
            //shader->mMaterial.mSpecular  = Color4f(mat.mSpecular.R, mat.mSpecular.G, mat.mSpecular.B);
            shader->mMaterial.mShininess = mat.mShine;
            subMesh->mShader = shader;
        }
    }    

	return newMesh;
}
开发者ID:SebastienLussier,项目名称:Gamedesk,代码行数:95,代码来源:ASEImporter.cpp


注:本文中的Mesh::AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。