//---------------------------------------------------------------------------- void HelloiPhone::CreateScene() { // 创建纹理资源. SEImage* pImage = SEImageCatalog::GetActive()->Find("rock"); SETexture* pTextureDiffuse = SE_NEW SETexture(pImage); pImage = SEImageCatalog::GetActive()->Find("kate"); SETexture* pTextureGirl = SE_NEW SETexture(pImage); m_spScene = SE_NEW SENode; // 创建一个box. SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetNormalChannels(3); //tempAttr.SetColorChannels(0, 3); tempAttr.SetTCoordChannels(0, 2); tempAttr.SetTCoordChannels(1, 2); SEStandardMesh tempSM(tempAttr); m_spMesh = tempSM.Box(1.0f, 1.0f, 1.0f); // m_spMesh->VBuffer->ColorTuple(0, 0)[0] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 0)[1] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 0)[2] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 1)[0] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 1)[1] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 1)[2] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 2)[0] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 2)[1] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 2)[2] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 3)[0] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 3)[1] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 3)[2] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 4)[0] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 4)[1] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 4)[2] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 5)[0] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 5)[1] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 5)[2] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 6)[0] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 6)[1] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 6)[2] = 0.0f; // m_spMesh->VBuffer->ColorTuple(0, 7)[0] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 7)[1] = 1.0f; // m_spMesh->VBuffer->ColorTuple(0, 7)[2] = 1.0f; SEOGLES1FixedEffect* pEffect = SE_NEW SEOGLES1FixedEffect(2, 0); pEffect->SetTexture(0, pTextureDiffuse); pEffect->SetTexture(1, pTextureGirl); m_spMesh->AttachEffect(pEffect); m_spScene->AttachChild(m_spMesh); }
//---------------------------------------------------------------------------- void Lighting::CreateModels() { // polished gold. SEMaterialState* pGoldMaterial = SE_NEW SEMaterialState; pGoldMaterial->Ambient = SEColorRGB(0.24725f, 0.2245f, 0.0645f); pGoldMaterial->Diffuse = SEColorRGB(0.34615f, 0.3143f, 0.0903f); pGoldMaterial->Specular = SEColorRGB(0.797357f, 0.723991f, 0.208006f); pGoldMaterial->Shininess = 83.2f; // polished red. SEMaterialState* pRedMaterial = SE_NEW SEMaterialState; pRedMaterial->Ambient = SEColorRGB(0.8f, 0.0f, 0.0f); pRedMaterial->Diffuse = SEColorRGB(0.8f, 0.0f, 0.0f); pRedMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f); pRedMaterial->Shininess = 83.2f; // polished blue. SEMaterialState* pBlueMaterial = SE_NEW SEMaterialState; pBlueMaterial->Ambient = SEColorRGB(0.0f, 0.0f, 0.2f); pBlueMaterial->Diffuse = SEColorRGB(0.0f, 0.0f, 0.8f); pBlueMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f); pBlueMaterial->Shininess = 83.2f; // polished white. SEMaterialState* pWhiteMaterial = SE_NEW SEMaterialState; pWhiteMaterial->Ambient = SEColorRGB(0.2f, 0.2f, 0.2f); pWhiteMaterial->Diffuse = SEColorRGB(0.8f, 0.8f, 0.8f); pWhiteMaterial->Specular = SEColorRGB(1.0f, 1.0f, 1.0f); pWhiteMaterial->Shininess = 50.0f; // polished copper. SEMaterialState* pCopperMaterial = SE_NEW SEMaterialState; pCopperMaterial->Ambient = SEColorRGB(0.2295f, 0.08825f, 0.0275f); pCopperMaterial->Diffuse = SEColorRGB(0.5508f, 0.2118f, 0.066f); pCopperMaterial->Specular = SEColorRGB(0.580594f, 0.223257f, 0.0695701f); pCopperMaterial->Shininess = 51.2f; // We apply these texture effects as post-lighting effects, // so the src output fragments should be modulated with dst buffer pixels. SETextureEffect* pTextureRockEffect = SE_NEW SETextureEffect("rock"); SEAlphaState* pAState = pTextureRockEffect->GetBlending(0); pAState->SrcBlend = SEAlphaState::SBF_DST_COLOR; pAState->DstBlend = SEAlphaState::DBF_ZERO; SETextureEffect* pTextureWoodEffect = SE_NEW SETextureEffect("wood512"); pAState = pTextureWoodEffect->GetBlending(0); pAState->SrcBlend = SEAlphaState::SBF_DST_COLOR; pAState->DstBlend = SEAlphaState::DBF_ZERO; SENode* pRoot = SE_NEW SENode; SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetNormalChannels(3); tempAttr.SetTCoordChannels(0, 2); #if defined(SE_USING_OES2) SEGeometry::GeometryLightingMode eLMode = SEGeometry::GLM_PIPELINE_VERTEX; #else SEGeometry::GeometryLightingMode eLMode = SEGeometry::GLM_PIPELINE_PIXEL; #endif float fExtend = 8.0f; SEStandardMesh tempSM(tempAttr); // floor. SETriMesh* pMesh = tempSM.Rectangle(4, 4, fExtend, fExtend); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pWhiteMaterial); pMesh->AttachEffect(pTextureWoodEffect); pMesh->GenerateNormals(); SEMatrix3f mat3fRot; mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pRoot->AttachChild(pMesh); // far wall. pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pWhiteMaterial); pMesh->AttachEffect(pTextureRockEffect); pMesh->GenerateNormals(); pMesh->Local.SetTranslate(SEVector3f(0.0f, fExtend, fExtend)); pRoot->AttachChild(pMesh); // left wall. pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pWhiteMaterial); pMesh->AttachEffect(pTextureRockEffect); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(0.0f, -SEMathf::PI/2.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(-fExtend, fExtend, 0.0f)); pRoot->AttachChild(pMesh); // right wall. pMesh = SE_NEW SETriMesh(pMesh->VBuffer, pMesh->IBuffer); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pWhiteMaterial); pMesh->AttachEffect(pTextureRockEffect); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(0.0f, SEMathf::PI/2.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(fExtend, fExtend, 0.0f)); pRoot->AttachChild(pMesh); // sphere. pMesh = tempSM.Sphere(32, 32, 1.0f); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pGoldMaterial); pMesh->GenerateNormals(); pMesh->Local.SetTranslate(SEVector3f(0.0f, 1.0f, 0.0f)); pRoot->AttachChild(pMesh); // cylinder. pMesh = tempSM.Cylinder(8, 32, 1.0f, 2.0f, false); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pRedMaterial); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(2.0f, 1.0f, 1.0f)); pRoot->AttachChild(pMesh); // box. pMesh = tempSM.Box(0.6f, 0.6f, 0.6f); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pBlueMaterial); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(0.0f, SEMathf::PI/3.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(-1.6f, 0.6f, -1.0f)); pRoot->AttachChild(pMesh); // torus. pMesh = tempSM.Torus(32, 32, 1.0f, 0.2f); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pCopperMaterial); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(SEMathf::PI/2.0f, 0.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(0.0f, 0.2f, 0.0f)); pRoot->AttachChild(pMesh); // tetrahedron. pMesh = tempSM.Tetrahedron(); pMesh->LightingMode = eLMode; pMesh->AttachGlobalState(pWhiteMaterial); pMesh->GenerateNormals(); mat3fRot.FromEulerAnglesXYZ(-SEMathf::PI/2.0f, 0.0f, 0.0f); pMesh->Local.SetRotate(mat3fRot); pMesh->Local.SetTranslate(SEVector3f(1.8f, 1.0f/3.0f, -0.8f)); pRoot->AttachChild(pMesh); m_spModelRoot = pRoot; }
//---------------------------------------------------------------------------- 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; }