//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- SENode* SEWidget::AABBFrame(const SEVector3f& rMin, const SEVector3f& rMax, const SEColorRGB& rColor) { SENode* pNode = SE_NEW SENode; SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetColorChannels(0, 3); SEVector3f vec3fV0(rMin); SEVector3f vec3fV1(rMin.X, rMin.Y, rMax.Z); SEVector3f vec3fV2(rMax.X, rMin.Y, rMax.Z); SEVector3f vec3fV3(rMax.X, rMin.Y, rMin.Z); SEVector3f vec3fV4(rMax.X, rMax.Y, rMin.Z); SEVector3f vec3fV5(rMin.X, rMax.Y, rMin.Z); SEVector3f vec3fV6(rMin.X, rMax.Y, rMax.Z); SEVector3f vec3fV7(rMax); // AABBFrame has 12 edges, 24 ending points. SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 24); pVBuffer->Position3(0 ) = vec3fV0; pVBuffer->Position3(1 ) = vec3fV1; pVBuffer->Position3(2 ) = vec3fV1; pVBuffer->Position3(3 ) = vec3fV2; pVBuffer->Position3(4 ) = vec3fV2; pVBuffer->Position3(5 ) = vec3fV3; pVBuffer->Position3(6 ) = vec3fV3; pVBuffer->Position3(7 ) = vec3fV0; pVBuffer->Position3(8 ) = vec3fV5; pVBuffer->Position3(9 ) = vec3fV6; pVBuffer->Position3(10) = vec3fV6; pVBuffer->Position3(11) = vec3fV7; pVBuffer->Position3(12) = vec3fV7; pVBuffer->Position3(13) = vec3fV4; pVBuffer->Position3(14) = vec3fV4; pVBuffer->Position3(15) = vec3fV5; pVBuffer->Position3(16) = vec3fV0; pVBuffer->Position3(17) = vec3fV5; pVBuffer->Position3(18) = vec3fV1; pVBuffer->Position3(19) = vec3fV6; pVBuffer->Position3(20) = vec3fV2; pVBuffer->Position3(21) = vec3fV7; pVBuffer->Position3(22) = vec3fV3; pVBuffer->Position3(23) = vec3fV4; for( int i = 0; i < 24; i++ ) { pVBuffer->Color3(0, i) = rColor; } SEPolyline* pAABBFrame = SE_NEW SEPolyline(pVBuffer, false, false); pAABBFrame->SetName("AABBFrame"); SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect; pAABBFrame->AttachEffect(pEffect); pNode->AttachChild(pAABBFrame); pNode->UpdateGS(); return pNode; }
//---------------------------------------------------------------------------- void DynamicShader::CreateScene() { m_spScene = SE_NEW SENode; m_spWireframe = SE_NEW SEWireframeState; m_spScene->AttachGlobalState(m_spWireframe); // 创建一个场景中的矩形. SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetTCoordChannels(0, 2); SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 4); (*(SEVector3f*)pVBuffer->PositionTuple(0)).X = -1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(0)).Y = -1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(0)).Z = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 0)).X = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 0)).Y = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(1)).X = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(1)).Y = -1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(1)).Z = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 1)).X = 1.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 1)).Y = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(2)).X = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(2)).Y = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(2)).Z = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 2)).X = 1.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 2)).Y = 0.0f; (*(SEVector3f*)pVBuffer->PositionTuple(3)).X = -1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(3)).Y = 1.0f; (*(SEVector3f*)pVBuffer->PositionTuple(3)).Z = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 3)).X = 0.0f; (*(SEVector2f*)pVBuffer->TCoordTuple(0, 3)).Y = 0.0f; SEIndexBuffer* pIBuffer = SE_NEW SEIndexBuffer(6); int* pIBufferData = pIBuffer->GetData(); pIBufferData[0] = 0; pIBufferData[1] = 3; pIBufferData[2] = 1; pIBufferData[3] = 1; pIBufferData[4] = 3; pIBufferData[5] = 2; m_spMesh = SE_NEW SETriMesh(pVBuffer, pIBuffer); m_spScene->AttachChild(m_spMesh); m_spEffect = SE_NEW DynamicMultiTextureEffect(1); m_spMesh->AttachEffect(m_spEffect); m_spEffect->SetImageName(0, m_ImageNames[0]); m_spEffect->SetTextureTypeName(0, "ImageTexture"); m_spEffect->Configure(); ConstantColorController* pController = SE_NEW ConstantColorController; m_spEffect->AttachController(pController); m_spController = pController; pController->Frequency = 5.0; pController->MinTime = 0.0; pController->MaxTime = 4.0; pController->Repeat = SEController::RT_CYCLE; }
//---------------------------------------------------------------------------- void Lighting::CreateLights() { // Create light0(point light). m_spLight0 = SE_NEW SELight(SELight::LT_POINT); m_spLight0->Ambient = m_Light0Color*0.5f; m_spLight0->Diffuse = m_Light0Color; m_spLight0->Specular = m_Light0Color*0.5f; m_spLight0->Linear = 0.02f; m_spLight0->Quadratic = 0.02f; // Create light0's node. m_spLight0Node = SE_NEW SELightNode(m_spLight0); m_spLight0Node->Local.SetTranslate(SEVector3f(0.0f, m_fLight0Height, 0.0f)); // Create a sphere to represent the light0's source. SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetColorChannels(0, 3); float fRadius = 0.2f; SETriMesh* pPLightSphere = SEStandardMesh(tempAttr).Sphere(8, 8, fRadius); m_spLight0Node->AttachChild(pPLightSphere); SEVertexBuffer* pVBuffer = pPLightSphere->VBuffer; int iVCount = pVBuffer->GetVertexCount(); for( int i = 0; i < iVCount; i++ ) { pVBuffer->Color3(0, i) = m_Light0Color; } SEVertexColor3Effect* pLightSphereEffect = SE_NEW SEVertexColor3Effect; pPLightSphere->AttachEffect(pLightSphereEffect); // Create light1(point light). m_spLight1 = SE_NEW SELight(SELight::LT_POINT); m_spLight1->Ambient = m_Light1Color*0.5f; m_spLight1->Diffuse = m_Light1Color; m_spLight1->Specular = m_Light1Color*0.5f; m_spLight1->Linear = 0.02f; m_spLight1->Quadratic = 0.02f; // Create light1's node. m_spLight1Node = SE_NEW SELightNode(m_spLight1); m_spLight1Node->Local.SetTranslate(SEVector3f(0.0f, m_fLight1Height, 0.0f)); // Create a sphere to represent the light1's source. pPLightSphere = SEStandardMesh(tempAttr).Sphere(8, 8, fRadius); m_spLight1Node->AttachChild(pPLightSphere); pVBuffer = pPLightSphere->VBuffer; iVCount = pVBuffer->GetVertexCount(); for( int i = 0; i < iVCount; i++ ) { pVBuffer->Color3(0, i) = m_Light1Color; } pPLightSphere->AttachEffect(pLightSphereEffect); }
//---------------------------------------------------------------------------- void DefaultShader::CreateScene() { m_spScene = SE_NEW SENode; SEAttributes tempAttr; tempAttr.SetPositionChannels(3); SEStandardMesh tempSM(tempAttr); m_spMesh = tempSM.Box(1.0f, 1.0f, 1.0f); m_spScene->AttachChild(m_spMesh); SEDefaultShaderEffect* pEffect = SE_NEW SEDefaultShaderEffect; m_spMesh->AttachEffect(pEffect); }
//---------------------------------------------------------------------------- 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 DefaultShader::CreateScene() { m_spScene = SE_NEW SENode; m_spWireframe = SE_NEW SEWireframeState; m_spScene->AttachGlobalState(m_spWireframe); SEAttributes tempAttr; tempAttr.SetPositionChannels(3); SEStandardMesh tempSM(tempAttr); float fExt = 1.0f; m_spMesh = tempSM.Box(fExt, fExt, fExt); m_spScene->AttachChild(m_spMesh); SEDefaultShaderEffect* pEffect = SE_NEW SEDefaultShaderEffect; m_spMesh->AttachEffect(pEffect); }
//---------------------------------------------------------------------------- void ImageExporterApp::CreateScene() { m_spScene = SE_NEW SENode; m_spWireframe = SE_NEW SEWireframeState; m_spWireframe->Enabled = false; m_spScene->AttachGlobalState(m_spWireframe); // 创建用于显示纹理图的矩形. SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetTCoordChannels(0, 2); SEVertexBuffer* pVB = SE_NEW SEVertexBuffer(tempAttr, 4); pVB->Position3(0) = SEVector3f(-1, 1, 0); pVB->Position3(1) = SEVector3f(1, 1, 0); pVB->Position3(2) = SEVector3f(1, -1, 0); pVB->Position3(3) = SEVector3f(-1, -1, 0); pVB->TCoord2(0, 0) = SEVector2f(0, 0); pVB->TCoord2(0, 1) = SEVector2f(1, 0); pVB->TCoord2(0, 2) = SEVector2f(1, 1); pVB->TCoord2(0, 3) = SEVector2f(0, 1); SEIndexBuffer* pIB = SE_NEW SEIndexBuffer(6); int* pIBData = pIB->GetData(); *(pIBData ) = 0; *(pIBData + 1) = 2; *(pIBData + 2) = 3; *(pIBData + 3) = 0; *(pIBData + 4) = 1; *(pIBData + 5) = 2; m_spMesh = SE_NEW SETriMesh(pVB, pIB); m_spScene->AttachChild(m_spMesh); m_spScene->UpdateGS(); m_spScene->UpdateRS(); m_Culler.SetCamera(m_spCamera); m_Culler.ComputeUnculledSet(m_spScene); }
//---------------------------------------------------------------------------- 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; }
//---------------------------------------------------------------------------- SENode* SEWidget::CoordinateFrame(float fLengthOfAxis) { SE_ASSERT( fLengthOfAxis > 0 ); SENode* pNode = SE_NEW SENode; SEAttributes tempAttr; tempAttr.SetPositionChannels(3); tempAttr.SetColorChannels(0, 3); SEStandardMesh tempSM(tempAttr); SEMatrix3f mat3fRot; float fAxisHeight = 0.667f*fLengthOfAxis; float fArrowRadius = 0.08f*fLengthOfAxis; float fArrowHeight = (1.0f - 0.667f)*fLengthOfAxis; // Create axis x. SEVertexBuffer* pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2); pVBuffer->Position3(0) = SEVector3f::ZERO; pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_X; pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_RED; pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_RED; SEPolyline* pAxisX = SE_NEW SEPolyline(pVBuffer, false, false); pAxisX->SetName("AxisX"); // Create axis x's ending arrow. SETriMesh* pArrowX = tempSM.Cone(16, fArrowRadius, fArrowHeight); for( int i = 0; i < pArrowX->VBuffer->GetVertexCount(); i++ ) { pArrowX->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_RED; } mat3fRot.FromAxisAngle(SEVector3f::UNIT_Y, SEMathf::HALF_PI); pArrowX->Local.SetRotate(mat3fRot); pArrowX->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_X); pArrowX->SetName("ArrowX"); // Create axis y. pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2); pVBuffer->Position3(0) = SEVector3f::ZERO; pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_Y; pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_GREEN; pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_GREEN; SEPolyline* pAxisY = SE_NEW SEPolyline(pVBuffer, false, false); pAxisY->SetName("AxisY"); // Create axis y's ending arrow. SETriMesh* pArrowY = tempSM.Cone(16, fArrowRadius, fArrowHeight); for( int i = 0; i < pArrowY->VBuffer->GetVertexCount(); i++ ) { pArrowY->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_GREEN; } mat3fRot.FromAxisAngle(SEVector3f::UNIT_X, -SEMathf::HALF_PI); pArrowY->Local.SetRotate(mat3fRot); pArrowY->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_Y); pArrowY->SetName("ArrowY"); // Create axis z. pVBuffer = SE_NEW SEVertexBuffer(tempAttr, 2); pVBuffer->Position3(0) = SEVector3f::ZERO; pVBuffer->Position3(1) = fAxisHeight*SEVector3f::UNIT_Z; pVBuffer->Color3(0, 0) = SEColorRGB::SE_RGB_BLUE; pVBuffer->Color3(0, 1) = SEColorRGB::SE_RGB_BLUE; SEPolyline* pAxisZ = SE_NEW SEPolyline(pVBuffer, false, false); pAxisZ->SetName("AxisZ"); // Create axis z's ending arrow. SETriMesh* pArrowZ = tempSM.Cone(16, fArrowRadius, fArrowHeight); for( int i = 0; i < pArrowZ->VBuffer->GetVertexCount(); i++ ) { pArrowZ->VBuffer->Color3(0, i) = SEColorRGB::SE_RGB_BLUE; } pArrowZ->Local.SetTranslate(fAxisHeight*SEVector3f::UNIT_Z); pArrowZ->SetName("ArrowZ"); SEVertexColor3Effect* pEffect = SE_NEW SEVertexColor3Effect; pAxisX->AttachEffect(pEffect); pArrowX->AttachEffect(pEffect); pAxisY->AttachEffect(pEffect); pArrowY->AttachEffect(pEffect); pAxisZ->AttachEffect(pEffect); pArrowZ->AttachEffect(pEffect); pNode->AttachChild(pAxisX); pNode->AttachChild(pArrowX); pNode->AttachChild(pAxisY); pNode->AttachChild(pArrowY); pNode->AttachChild(pAxisZ); pNode->AttachChild(pArrowZ); pNode->UpdateGS(); return pNode; }