void SpriteAnimationTest::PostLoad() { App::PostLoad(); GameObject* playerGameObject = scene->AddGameObject(new GameObject("player")); AnimationController* animationController = new AnimationController(); animationController->dataTypes.emplace_back(new AInt(20)); //----------------------------------------------------------------------------------------------------------------------------------- for (size_t i = 0; i < 8; i++) walkingLeftKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 0, 32, 48))); for (size_t i = 0; i < 6; i++) walkingRightKeyframes->emplace_back(KeyFrame(100 * (i + 1), BF::Math::Rectangle(32 * i, 48, 32, 48))); sequence->emplace_back(walkingLeftKeyframes); sequence->emplace_back(walkingRightKeyframes); AnimationData data("../Sandbox/Assets/Textures/player.png", sequence); data.filePath = "../Sandbox/Assets/Textures/player.png"; Texture2D* texture = new Texture2D(); texture->Create(ResourceManager::Load<TextureData>(data.textureName), Texture::Format::R8G8B8A8); BF::Graphics::Animation::Animation* walkingLeftAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[0], true); BF::Graphics::Animation::Animation* walkingRightAnimation = new BF::Graphics::Animation::Animation(texture, &(*data.sequences)[1], true); //----------------------------------------------------------------------------------------------------------------------------------- AnimationNode* walkingLeftAnimationNode = new AnimationNode(); walkingLeftAnimationNode->animation = walkingLeftAnimation; AnimationNode* walkingRightAnimationNode = new AnimationNode(); walkingRightAnimationNode->animation = walkingRightAnimation; //----------------------------------------------------------------------------------------------------------------------------------- Transition* startingNodeTransition = new Transition(walkingLeftAnimationNode, true); Condition* startingCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10)); startingNodeTransition->conditions.emplace_back(startingCondition); animationController->startingAnimationNode->transition = startingNodeTransition; //----------------------------------------------------------------------------------------------------------------------------------- Transition* walkingLeftTransition = new Transition(walkingRightAnimationNode, true); Condition* walkingLeftCondition = new Condition(animationController->dataTypes[0], Condition::EvaluationOperator::BiggerThan, new AInt(10)); walkingLeftTransition->conditions.emplace_back(walkingLeftCondition); walkingLeftAnimationNode->transitions.emplace_back(walkingLeftTransition); //----------------------------------------------------------------------------------------------------------------------------------- Animator* animator = (Animator*)playerGameObject->AddComponent(new Animator(animationController)); //animator->gameObject->GetTransform()->SetScale(Vector3f(3, 3, 3)); App::RunScene(*scene); }
ABOOL GBufferOne::VInitialize() { //== //Define properties for textures //== Texture2DParams * pParams = new Texture2DParams(); pParams->Init(SCREEN_WIDTH, SCREEN_HEIGHT, 1, TEX_R32G32B32A32_FLOAT, true, false, true, false, 1, 0, 1, true, false, false); //== //Create textures //== Texture2D pTex = *m_pPosTex; pTex.Create(pParams); m_pPosTex->Create(pParams); m_pNormalTex->Create(pParams); m_pDepthTex->Create(pParams); m_pDiffuseTex->Create(pParams); m_pSpecularTex->Create(pParams); //Define properties for shader resource views ShaderResourceViewParams * pSRVParams = new ShaderResourceViewParams(); pSRVParams->InitForTexture2D(pParams->Format, 1, 0); //== //Create Shader Resource Views //== m_pPosTex->CreateShaderResourceView(m_SRVList.GetView(0), pSRVParams); m_pNormalTex->CreateShaderResourceView(m_SRVList.GetView(1), pSRVParams); m_pDepthTex->CreateShaderResourceView(m_SRVList.GetView(2), pSRVParams); m_pDiffuseTex->CreateShaderResourceView(m_SRVList.GetView(3), pSRVParams); m_pSpecularTex->CreateShaderResourceView(m_SRVList.GetView(4), pSRVParams); //Define properties for shader resource views RenderTargetViewParams * pRTVParams = new RenderTargetViewParams(); pRTVParams->InitForTexture2D(pParams->Format, 0); //== //Create Render Target Views //== m_pPosTex->CreateRenderTargetView(m_RTVList.GetView(0), pRTVParams); m_pNormalTex->CreateRenderTargetView(m_RTVList.GetView(1), pRTVParams); m_pDepthTex->CreateRenderTargetView(m_RTVList.GetView(2), pRTVParams); m_pDiffuseTex->CreateRenderTargetView(m_RTVList.GetView(3), pRTVParams); m_pSpecularTex->CreateRenderTargetView(m_RTVList.GetView(4), pRTVParams); return 1; }
Resource* WoWImporter::Import( const String& pFilename, const String& /*pParams*/ ) { WoW::ADTFile adtFile; WoW::ADTFileReader adtFileReader( adtFile ); adtFileReader.Read( pFilename ); WorldTile* worldTile = GD_NEW(WorldTile, this, "WoW::WorldTile"); worldTile->GetTerrainChunks().resize( 256 ); worldTile->GetVertexList().Allocate( 16*16 * (9*9 + 8*8), (VertexFormat::Component) (VertexFormat::Position3 | VertexFormat::TexCoord2 | VertexFormat::TexCoord2_2 | VertexFormat::Normal3) ); Vector3f* ptrPosition = worldTile->GetVertexList().GetPositions(); Vector3f* ptrNormal = worldTile->GetVertexList().GetNormals(); Vector2f* ptrTexCoord = worldTile->GetVertexList().GetTextureCoords(); Vector2f* ptrTexCoordAlpha = worldTile->GetVertexList().GetTextureCoords_2(); UInt32 verticesOffset = 0; Vector3f firstChunkPos(0,0,0);//-1.0f*adtFile.mMapChunks[0].mHeader.mPosition.y, adtFile.mMapChunks[0].mHeader.mPosition.z, -1.0f*adtFile.mMapChunks[0].mHeader.mPosition.x ); for( UInt32 iChunk = 0; iChunk < 256; iChunk++ ) { WoW::ADTFile::MapChunk* mapChunk = &adtFile.mMapChunks[iChunk]; // Append vertex data to vertex buffer Float* ptrDataHeight = mapChunk->mHeightMap; Char* ptrDataNormals = mapChunk->mHeightMapNormals[0]; Vector3f chunkPos( -1.0f*mapChunk->mHeader.mPosition.y, mapChunk->mHeader.mPosition.z, -1.0f*mapChunk->mHeader.mPosition.x ); Float posX = chunkPos.x - firstChunkPos.x; Float posZ = chunkPos.z - firstChunkPos.z; for( UInt32 z = 0; z < 9; z++ ) { // Normal row posX = chunkPos.x - firstChunkPos.x; for( UInt32 x = 0; x < 9; x++ ) { ptrPosition->x = posX; ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y; ptrPosition->z = posZ; (*ptrPosition) *= 0.1f; ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f; ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f; ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f; ptrTexCoord->x = x / 8.0f; ptrTexCoord->y = z / 8.0f; ptrTexCoordAlpha->x = (x+0.125f) / 8.25f; ptrTexCoordAlpha->y = (z+0.125f) / 8.25f; ptrDataHeight++; ptrDataNormals += 3; ptrPosition++; ptrNormal++; ptrTexCoord++; ptrTexCoordAlpha++; posX += UNIT_SIZE; } posZ += 0.5f * UNIT_SIZE; if( z == 8 ) break; // Detailed row posX = chunkPos.x + 0.5f * UNIT_SIZE - firstChunkPos.x; for( UInt32 x = 0; x < 8; x++ ) { ptrPosition->x = posX; ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y; ptrPosition->z = posZ; (*ptrPosition) *= 0.1f; ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f; ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f; ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f; ptrTexCoord->x = (x+0.5f) / 8.0f; ptrTexCoord->y = (z+0.5f) / 8.0f; ptrTexCoordAlpha->x = (x+0.5f+0.125f) / 8.25f; ptrTexCoordAlpha->y = (z+0.5f+0.125f) / 8.25f; ptrDataHeight++; ptrDataNormals += 3; ptrPosition++; ptrNormal++; ptrTexCoord++; ptrTexCoordAlpha++; posX += UNIT_SIZE; } posZ += 0.5f * UNIT_SIZE; } WorldTile::TerrainChunk* newChunk = GD_NEW(WorldTile::TerrainChunk, this, "WoW::WorldTile::TerrainChunk"); for( UInt32 iLayer = 0; iLayer < mapChunk->mTextureLayers.size(); iLayer++ ) { String textureName("Data/"); textureName += adtFile.mTextureNames[mapChunk->mTextureLayers[iLayer].mTextureID]; HTexture2D texture(textureName); Texture2D* alpha = NULL; if( iLayer != 0 ) { alpha = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( "AlphaMap" )); alpha->Create( mapChunk->mAlphaMaps[iLayer-1], true ); alpha->Init(); alpha->SetWrapMode( Texture::Wrap_S, Texture::Wrap_Clamp ); alpha->SetWrapMode( Texture::Wrap_T, Texture::Wrap_Clamp ); alpha->SetMinFilter( Texture::MinFilter_Linear ); alpha->SetMagFilter( Texture::MagFilter_Linear ); } newChunk->AddTextureLayer( texture, alpha ); } UInt32 detailedStripSize = (16*18 + 7*2 + 8*2); UInt32 normalStripSize = 158; // Build index buffer newChunk->GetHiResTriangles().Allocate( TriangleBatch::TriangleStrip, detailedStripSize ); newChunk->GetLowResTriangles().Allocate( TriangleBatch::TriangleStrip, normalStripSize ); UInt16* ptrHiIndices = newChunk->GetHiResTriangles().GetIndices(); UInt16* ptrLoIndices = newChunk->GetLowResTriangles().GetIndices(); for( int row = 0; row < 8; row++ ) { UInt32 topRow = verticesOffset + row*(9+8); UInt32 detailrow = verticesOffset + row*(9+8) + 9; UInt32 nextRow = verticesOffset + (row+1)*(9+8); if( row > 0 ) { *ptrHiIndices++ = topRow + 0; // jump end *ptrLoIndices++ = topRow + 0; } for( int col = 0; col < 8; col++ ) { *ptrHiIndices++ = topRow + col; *ptrHiIndices++ = detailrow + col; *ptrLoIndices++ = topRow + col; *ptrLoIndices++ = nextRow + col; } *ptrHiIndices++ = topRow + 8; *ptrHiIndices++ = nextRow + 8; *ptrHiIndices++ = nextRow + 8; // jump start *ptrHiIndices++ = topRow + 0; // jump end *ptrHiIndices++ = topRow + 0; *ptrLoIndices++ = topRow + 8; *ptrLoIndices++ = nextRow + 8; for( int col = 0; col < 8; col++ ) { *ptrHiIndices++ = nextRow + col; *ptrHiIndices++ = detailrow + col; } if( row < 8 ) *ptrHiIndices++ = nextRow + 8; if( row < 7 ) { *ptrHiIndices++ = nextRow + 8; // jump start *ptrLoIndices++ = nextRow + 8; } } verticesOffset += 9*9 + 8*8; worldTile->GetTerrainChunks()[iChunk] = newChunk; } return (Resource*)worldTile; }
Resource* DevILImporter::Import( const String& pFilename, const String& /*pParams*/ ) { ILuint imageName; // Load the image. DevIL will guess the type of the image file using it's extension and if needed it's header. ilGenImages( 1, &imageName ); ilBindImage( imageName ); // Load the image. if( !ilLoadImage( const_cast<char*>(pFilename.c_str()) ) ) throw ResourceImportException( ToString(ilGetError()), Here ); // Get the image params. ILint bytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); ILint imgFormat = ilGetInteger( IL_IMAGE_FORMAT ); ILint imgWidth = ilGetInteger( IL_IMAGE_WIDTH ); ILint imgHeight = ilGetInteger( IL_IMAGE_HEIGHT ); // We do not support palettized texture currently, so un-palettize them! if( imgFormat == IL_COLOR_INDEX ) { switch( ilGetInteger( IL_PALETTE_TYPE ) ) { case IL_PAL_RGB24: case IL_PAL_RGB32: imgFormat = IL_RGB; break; case IL_PAL_BGR24: case IL_PAL_BGR32: imgFormat = IL_BGR; break; case IL_PAL_RGBA32: imgFormat = IL_RGBA; break; case IL_PAL_BGRA32: imgFormat = IL_BGRA; break; default: debugBreak(); } ilConvertImage( imgFormat, IL_UNSIGNED_BYTE ); bytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); imgFormat = ilGetInteger( IL_IMAGE_FORMAT ); } // Find what is the gamedesk internal image format that will be used. Image::Format gdImgFormat = GetImageFormat( imgFormat, bytesPerPixel ); Image newImage; newImage.Create( imgWidth, imgHeight, gdImgFormat ); memcpy( newImage.GetData(), ilGetData(), imgWidth*imgHeight*bytesPerPixel ); Texture* newTexture = NULL; // Allocate and create using image. if( imgWidth == 1 || imgHeight == 1 ) { Texture1D* tex = Cast<Texture1D>(Texture1D::StaticClass()->AllocateNew( pFilename )); tex->Create( newImage ); newTexture = tex; } else { Texture2D* tex = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( pFilename )); tex->Create( newImage ); newTexture = tex; } // The DevIL copy of the image is not needed anymore, so destroy it. ilDeleteImages( 1, &imageName ); return newTexture; }