From e265b7f69f9fa0d81e8d6882fae08a0acbb1c50c Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Tue, 28 Dec 2021 09:19:31 +0500 Subject: Added fallback liquids meshing --- src/AssetManager.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/AssetManager.hpp | 1 + 2 files changed, 48 insertions(+) diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 3e3f677..09f5209 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -573,6 +573,52 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) { return it->second; BlockInfo *blockInfo = GetBlockInfo(block); + if (blockInfo->blockstate == "@liquid") { + BlockFaces blockFaces; + blockFaces.isBlock = false; + blockFaces.isLiquid = true; + blockFaces.transform = glm::mat4(1.0f); + blockFaces.ambientOcclusion = false; + for (size_t i = 0; i < FaceDirection::none; i++) { + blockFaces.faceDirectionVector[i] = FaceDirectionVector[i]; + } + + const auto& liquidInfo = GetBlockLiquidInfo(BlockId{ block.id, 0 }); + + { + AssetTexture* assetTexture = AssetManager::GetAsset("minecraft/textures/" + liquidInfo.flowTexture); + if (!assetTexture) + return errorFaces; + TextureCoord texture = atlas->GetTexture(assetTexture->id); + float textureFrames = assetTexture->frames; + blockFaces.faces.emplace_back(ParsedFace{ + FaceDirection::none, + glm::translate(glm::mat4(1.0f), glm::vec3{0.0f, 1.0f, 0.0f}), + glm::vec4{ texture.x,texture.y,texture.w,texture.h }, + static_cast(texture.layer), + static_cast(assetTexture->frames), + glm::vec3(1.0f), + }); + } + + { + AssetTexture* assetTexture = AssetManager::GetAsset("minecraft/textures/" + liquidInfo.stillTexture); + if (!assetTexture) + return errorFaces; + TextureCoord texture = atlas->GetTexture(assetTexture->id); + float textureFrames = assetTexture->frames; + blockFaces.faces.emplace_back(ParsedFace{ + FaceDirection::none, + glm::translate(glm::mat4(1.0f), glm::vec3{0.0f, 1.0f, 0.0f}), + glm::vec4{ texture.x,texture.y,texture.w,texture.h }, + static_cast(texture.layer), + static_cast(assetTexture->frames), + glm::vec3(1.0f), + }); + } + + return blockIdToBlockFaces.insert(std::make_pair(block, blockFaces)).first->second; + } AssetBlockState *asset = GetAsset("/minecraft/blockstates/" + blockInfo->blockstate); if (!asset) return errorFaces; @@ -595,6 +641,7 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) { blockFaces.faces = assetModel->blockModel.parsedFaces; blockFaces.isBlock = assetModel->blockModel.IsBlock; blockFaces.ambientOcclusion = assetModel->blockModel.AmbientOcclusion; + blockFaces.isLiquid = false; glm::mat4 transform = glm::mat4(1.0); if (model.y != 0) { diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 59fc851..cad7eaf 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -49,6 +49,7 @@ struct BlockFaces { std::vector faces; bool isBlock; bool ambientOcclusion; + bool isLiquid; //if true, then faces contains only two elements with valid texture data Vector faceDirectionVector[FaceDirection::none]; }; -- cgit v1.2.3