From b0c6462ca1959a27038f67d5b692f43a8e50decc Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 27 Jan 2019 17:36:47 +0500 Subject: Basic animated textures support --- src/AssetManager.cpp | 18 +++++++++++++----- src/AssetManager.hpp | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 3765f02..9fd49bb 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -154,6 +154,14 @@ void ParseAssetTexture(AssetTreeNode &node) { std::memcpy(asset->textureData.data(), data, dataLen); asset->realWidth = w; asset->realHeight = h; + bool foundAnimationFile = false; + for (const auto &it : node.parent->childs) + if (it->name == node.name + ".png") { + foundAnimationFile = true; + break; + } + asset->frames = foundAnimationFile ? _max(w, h) / _min(w, h) : 1; + stbi_image_free(data); @@ -485,6 +493,7 @@ void ParseBlockModels() { } parsedFace.transform = faceTransform; TextureCoord texture; + unsigned int textureFrames = 1; textureName = face.second.texture; if (model.Textures.empty()) { texture = AssetManager::GetTexture("minecraft/textures/error"); @@ -496,11 +505,10 @@ void ParseBlockModels() { textureName = textureIt != model.Textures.end() ? textureIt->second : "minecraft/textures/error"; } textureName.insert(0, "minecraft/textures/"); - texture = AssetManager::GetTexture(textureName); - if (textureName.find("water_flow") != std::string::npos) - texture.h /= 32.0f; - if (textureName.find("lava_flow") != std::string::npos) - texture.h /= 16.0f; + AssetTexture *assetTexture = AssetManager::GetAsset(textureName); + texture = atlas->GetTexture(assetTexture->id); + textureFrames = assetTexture->frames; + texture.h /= textureFrames; if (!(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,16,0,16 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,0,0 }) && !(face.second.uv == BlockModel::ElementData::FaceData::Uv{ 0,0,16,16 })) { diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 852378f..6c5cb49 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -158,6 +158,7 @@ struct AssetBlockState : Asset { struct AssetTexture : Asset { std::vector textureData; unsigned int realWidth, realHeight; + unsigned int frames; size_t id; }; -- cgit v1.2.3