//------------------------------------------------------------------------------------ void Sky::_InitMesh() { SVertex* vert = new SVertex[8]; DWORD* pIndices = new DWORD[6*2*3]; if(!vert || !pIndices) throw std::exception("Error!Not enough memory!"); vert[0].pos.Set(-1, -1, -1); vert[1].pos.Set( 1, -1, -1); vert[2].pos.Set( 1, -1, 1); vert[3].pos.Set(-1, -1, 1); vert[4].pos.Set(-1, 1, -1); vert[5].pos.Set( 1, 1, -1); vert[6].pos.Set( 1, 1, 1); vert[7].pos.Set(-1, 1, 1); pIndices[0] = 0; pIndices[1] = 2; pIndices[2] = 1; pIndices[3] = 0; pIndices[4] = 3; pIndices[5] = 2; pIndices[6] = 5; pIndices[7] = 7; pIndices[8] = 4; pIndices[9] = 5; pIndices[10] = 6; pIndices[11] = 7; pIndices[12] = 3; pIndices[13] = 6; pIndices[14] = 2; pIndices[15] = 3; pIndices[16] = 7; pIndices[17] = 6; pIndices[18] = 1; pIndices[19] = 4; pIndices[20] = 0; pIndices[21] = 1; pIndices[22] = 5; pIndices[23] = 4; pIndices[24] = 0; pIndices[25] = 7; pIndices[26] = 3; pIndices[27] = 0; pIndices[28] = 4; pIndices[29] = 7; pIndices[30] = 2; pIndices[31] = 5; pIndices[32] = 1; pIndices[33] = 2; pIndices[34] = 6; pIndices[35] = 5; m_pMesh = new Mesh; SubMesh* pSubMesh = new SubMesh; pSubMesh->InitVertData(eVertexType_General, vert, 8, true); pSubMesh->InitIndexData(pIndices, 6*2*3, true); m_pMesh->AddSubMesh(pSubMesh); SAFE_DELETE_ARRAY(vert); SAFE_DELETE_ARRAY(pIndices); Neo::Material* pMaterial = new Neo::Material; pMaterial->SetTexture(0, new Neo::D3D11Texture(GetResPath("Skybox.dds"), eTextureType_CubeMap)); pMaterial->InitShader(GetResPath("Sky.hlsl"), GetResPath("Sky.hlsl"), eShaderFlag_EnableClipPlane); pSubMesh->SetMaterial(pMaterial); pMaterial->Release(); D3D11_SAMPLER_DESC& sampler = pMaterial->GetSamplerStateDesc(0); sampler.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; sampler.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; pMaterial->SetSamplerStateDesc(0, sampler); m_pEntity = new Entity(m_pMesh); m_pEntity->SetCastShadow(false); m_pEntity->SetReceiveShadow(false); }
//------------------------------------------------------------------------------------ bool SceneManager::Init() { m_camera = new Camera; m_camera->SetAspectRatio(m_pRenderSystem->GetWndWidth() / (float)m_pRenderSystem->GetWndHeight()); m_sunLight.lightDir.Set(1, -1, 2); m_sunLight.lightDir.Normalize(); m_sunLight.lightColor.Set(0.8f, 0.8f, 0.8f); m_pSSAO = new SSAO; { m_pDebugRTMesh = new Mesh; SubMesh* pSubMesh = new SubMesh; SVertex v[4] = { SVertex(VEC3(0.5f,1.0f,0), VEC2(0,0)), SVertex(VEC3(1.0f,1.0f,0), VEC2(1,0)), SVertex(VEC3(0.5f,0.4f,0), VEC2(0,1)), SVertex(VEC3(1.0f,0.4f,0), VEC2(1,1)) }; DWORD index[6] = { 0,1,2, 1,3,2 }; pSubMesh->InitVertData(eVertexType_General, v, ARRAYSIZE(v), true); pSubMesh->InitIndexData(index, ARRAYSIZE(index), true); m_pDebugRTMesh->AddSubMesh(pSubMesh); m_pDebugRTMaterial = new Material; m_pDebugRTMaterial->InitShader(GetResPath("DebugRT.hlsl"), GetResPath("DebugRT.hlsl")); pSubMesh->SetMaterial(m_pDebugRTMaterial); } _InitAllScene(); return true; }
SubMesh* ColladaSubMeshReader::Load( void ) { COLLADAFW::MeshPrimitiveArray& primitives = m_pMesh->getMeshPrimitives(); //若没有几何图元信息 if( 0 == primitives.getCount() ) { return NULL; } COLLADAFW::MeshPrimitive* pPrimitive = primitives[0]; if( COLLADAFW::MeshPrimitive::TRIANGLES != pPrimitive->getPrimitiveType() ) { return NULL; } COLLADAFW::UIntValuesArray& positionIndices = pPrimitive->getPositionIndices(); //若没有位置索引 则直接退出 if( 0 == positionIndices.getCount() ) { return NULL; } COLLADAFW::UIntValuesArray& normalIndices = pPrimitive->getNormalIndices(); m_bHasNormals = ( normalIndices.getCount() != 0 ); COLLADAFW::UIntValuesArray& tangentIndices = pPrimitive->getTangentIndices(); m_bHasTangents = ( tangentIndices.getCount() != 0 ); COLLADAFW::UIntValuesArray& binormalIndices = pPrimitive->getBinormalIndices(); m_bHasBinormals = ( binormalIndices.getCount() != 0 ); COLLADAFW::IndexList* pUVs = NULL; if( pPrimitive->getUVCoordIndicesArray().getCount() ) { pUVs = pPrimitive->getUVCoordIndicesArray()[0]; m_bHasUVs = ( pUVs->getIndices().getCount() != 0 ); } SubMesh* pSubMesh = new SubMesh; pSubMesh->SetName( m_pMesh->getName() ); Resource::Material* pMaterial = Resource::MaterialManager::GetInstance()->CreateOrRetrieveMaterial( m_pMesh->getName() ); pSubMesh->SetMaterial( pMaterial ); Render::VertexBuffer& vertexBuf = pSubMesh->RenderData().VertexBuf(); pSubMesh->RenderData().PrimitiveType( Render::TYPE_TRIANGLES ); vertexBuf.ChannelFlag() = Render::POSITION_CH; if( m_bHasNormals ) { vertexBuf.ChannelFlag() |= Render::NORMAL_CH; } if( m_bHasUVs ) { vertexBuf.ChannelFlag() |= Render::TEXCOORD_CH; } if( m_bHasTangents ) { vertexBuf.ChannelFlag() |= Render::TANGENT_CH; } if( m_bHasBinormals ) { vertexBuf.ChannelFlag() |= Render::BINORMAL_CH; } unsigned int uiCurrIndex = 0; unsigned int uiIndicesCount = positionIndices.getCount(); for( unsigned int uiIndex = 0 ; uiIndex < uiIndicesCount ; uiIndex++ ) { Tuple tuple; tuple.m_posIndex = positionIndices[uiIndex]; if( m_bHasNormals ) { tuple.m_normIndex = normalIndices[uiIndex]; } if( m_bHasUVs ) { tuple.m_uvIndex = pUVs->getIndices()[uiIndex]; } if( m_bHasTangents ) { tuple.m_tangentIndex = tangentIndices[uiIndex]; } if( m_bHasBinormals ) { tuple.m_binormalIndex = binormalIndices[uiIndex]; } indicesTable_t::iterator itIndex = m_indicesMap.find(tuple); if( itIndex == m_indicesMap.end() ) { Render::Vertex newVert; LoadVertexByTuple( tuple , newVert ); vertexBuf.AppendVertex( newVert ); m_indicesMap.insert( std::make_pair( tuple , uiCurrIndex ) ); pSubMesh->RenderData().AppendIndex( uiCurrIndex ); uiCurrIndex++; }else{ pSubMesh->RenderData().AppendIndex( itIndex->second ); } }//for( unsigned int uiIndex = 0 ; uiIndex < uiIndicesCount ; uiIndex++ ) return pSubMesh; }