コード例 #1
0
//----------------------------------------------------------------------------
bool SEWindowApplication3::OnInitialize()
{
    if( !SEWindowApplication::OnInitialize() )
    {
        return false;
    }

    m_spCamera = SE_NEW SECamera;
    m_pRenderer->SetCamera(m_spCamera);
    m_spMotionObject = 0;

    SEAttributes tempAttr;
    tempAttr.SetPositionChannels(3);
    tempAttr.SetColorChannels(0, 3);
    SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 6);
    (*(SEVector3f*)pVBuffer->PositionTuple(0)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 0)) = SEColorRGB::SE_RGB_RED;
    (*(SEVector3f*)pVBuffer->PositionTuple(1)) = m_XEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 1)) = SEColorRGB::SE_RGB_RED;
    (*(SEVector3f*)pVBuffer->PositionTuple(2)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 2)) = SEColorRGB::SE_RGB_GREEN;  
    (*(SEVector3f*)pVBuffer->PositionTuple(3)) = m_YEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 3)) = SEColorRGB::SE_RGB_GREEN;
    (*(SEVector3f*)pVBuffer->PositionTuple(4)) = m_Origin;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 4)) = SEColorRGB::SE_RGB_BLUE;
    (*(SEVector3f*)pVBuffer->PositionTuple(5)) = m_ZEnd;
    (*(SEColorRGB*)pVBuffer->ColorTuple(0, 5)) = SEColorRGB::SE_RGB_BLUE;
    m_spWorldAxis = SE_NEW SEPolyline(pVBuffer, false, false);

    SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect;
    m_spWorldAxis->AttachEffect(pEffect);

    return true;
}
コード例 #2
0
//----------------------------------------------------------------------------
SETriMesh* SEColladaUnimaterialMesh::ToTriMesh()
{
    // 创建所需Swing Engine VB.
    SEAttributes tempSEAttr;
    tempSEAttr.SetPositionChannels(3);
    if( m_aNormal )
    {
        tempSEAttr.SetNormalChannels(3);
    }
    if( m_aColor )
    {
        tempSEAttr.SetColorChannels(0, 3);
    }
    if( m_aTexture )
    {
        tempSEAttr.SetTCoordChannels(0, 2);
    }

    SEVertexBuffer* pSEVBuffer = SE_NEW SEVertexBuffer(tempSEAttr, m_iVCount);
    for( int i = 0; i < m_iVCount; i++ )
    {
        (*(SEVector3f*)pSEVBuffer->PositionTuple(i)) = m_aVertex[i];

        if( m_aNormal )
        {
            *(SEVector3f*)pSEVBuffer->NormalTuple(i) = m_aNormal[i];
        }
        if( m_aColor )
        {
            *(SEColorRGB*)pSEVBuffer->ColorTuple(0, i) = m_aColor[i];
        }
        if( m_aTexture )
        {
            *(SEVector2f*)pSEVBuffer->TCoordTuple(0, i) = m_aTexture[i];
        }
    }

    // 创建所需Swing Engine IB.
    SEIndexBuffer* pSEIBuffer = SE_NEW SEIndexBuffer(3 * m_iFCount);
    int* pSEIBufferData = pSEIBuffer->GetData();
    memcpy(pSEIBufferData, m_aiFace, 3*m_iFCount*sizeof(int));

    SETriMesh* pSEMesh = SE_NEW SETriMesh(pSEVBuffer, pSEIBuffer);

    SEEffect* pSEEffect = 0;

    // 根据Swing Engine网格所带材质和纹理,为其添加effect.
    // 目前导出器支持的材质和纹理effect是:
    // SEMaterialEffect,SEMaterialTextureEffect,SEDefaultShaderEffect.

    if( m_spSEMaterialState )
    {
        pSEMesh->AttachGlobalState(m_spSEMaterialState);

        if( m_spTState )
        {
            // 待实现.
            // 当拆分网格后如何处理多重纹理?
            SEImage* pImage = m_spTState->GetImage();
            SE_ASSERT( pImage );
            if( pImage )
            {
                std::string tempFName = pImage->GetName();
                // 减去".seif"长度.
                size_t uiLength = strlen(tempFName.c_str()) - 5;
                char tempBuffer[64];
                SESystem::SE_Strncpy(tempBuffer, 64, tempFName.c_str(), 
                    uiLength);
                tempBuffer[uiLength] = 0;
                pSEEffect = SE_NEW SEMaterialTextureEffect(tempBuffer);
            }
        }
        else
        {
            pSEEffect = SE_NEW SEDefaultShaderEffect;

            if( m_aTexture )
            {
                SE_DELETE[] m_aTexture;
            }
        }
    }

    // 理论上不可能出现这种情况.
    if( !m_spSEMaterialState && m_spTState )
    {
        SE_ASSERT( false );
    }

    if( !m_spSEMaterialState && !m_spTState )
    {
        pSEEffect = SE_NEW SEDefaultShaderEffect;
    }

    if( pSEEffect )
    {
        pSEMesh->AttachEffect(pSEEffect);
    }

    return pSEMesh;
}