#pragma once #include #include #include #include #include #include #include #include #include "Vector.hpp" #include "Block.hpp" #include "TextureAtlas.hpp" #include "Gal.hpp" enum FaceDirection { down, up, north, south, west, east, northWest, northEast, southWest, southEast, none, }; static const Vector FaceDirectionVector[] = { Vector(0,-1,0), Vector(0,1,0), Vector(0,0,-1), Vector(0,0,1), Vector(-1,0,0), Vector(1,0,0), Vector(-1,0,-1), Vector(1,0,-1), Vector(-1,0,1), Vector(1,0,1), Vector(0,0,0) }; struct ParsedFace { FaceDirection visibility; glm::mat4 transform; glm::vec4 texture; float layer; float frames; glm::vec3 color; }; struct BlockFaces { glm::mat4 transform; 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]; }; struct BlockModel { bool IsBlock = false; std::string BlockName; bool AmbientOcclusion = true; enum DisplayVariants { thirdperson_righthand, thirdperson_lefthand, firstperson_righthand, firstperson_lefthand, gui, head, ground, fixed, DisplayVariantsCount, }; struct DisplayData { Vector rotation; Vector translation; Vector scale; }; std::map Display; std::map Textures; struct ElementData { Vector from; Vector to; Vector rotationOrigin = Vector(8, 8, 8); enum Axis { x, y, z, } rotationAxis = Axis::x; int rotationAngle = 0; bool rotationRescale = false; bool shade = true; struct FaceData { struct Uv { int x1, y1, x2, y2; } uv = { 0,0,0,0 }; std::string texture; FaceDirection cullface = FaceDirection::none; int rotation = 0; bool tintIndex = false; }; std::map faces; }; std::vector Elements; std::vector parsedFaces; }; struct BlockStateVariant { std::string variantName; struct Model { std::string modelName; int x = 0; int y = 0; bool uvLock = false; int weight = 1; }; std::vector models; }; struct BlockState { std::map variants; }; inline bool operator==(const BlockModel::ElementData::FaceData::Uv &lhs, const BlockModel::ElementData::FaceData::Uv &rhs) { return lhs.x1 == rhs.x1 && lhs.y1 == rhs.y1 && lhs.x2 == rhs.x2 && lhs.y2 == rhs.y2; } struct Asset { virtual ~Asset() {}; }; struct AssetTreeNode { std::vector> childs; std::vector data; std::string name; std::unique_ptr asset; AssetTreeNode *parent; }; struct AssetBlockModel : Asset { BlockModel blockModel; }; struct AssetBlockState : Asset { BlockState blockState; }; struct AssetTexture : Asset { std::vector textureData; unsigned int realWidth, realHeight; unsigned int frames; size_t id; }; struct AssetShader : Asset { }; struct AssetScript : Asset { std::string code; }; namespace AssetManager { void InitAssetManager(); void InitPostRml(); BlockFaces &GetBlockModelByBlockId(BlockId block); Asset *GetAssetPtr(const std::string &assetName); template T *GetAsset(const std::string &assetName) { return dynamic_cast(GetAssetPtr(assetName)); } void RecursiveWalkAsset(const std::string &assetPath, std::function fnc); AssetTreeNode *GetAssetByAssetName(const std::string &assetName); std::shared_ptr GetTextureAtlas(); TextureCoord GetTexture(const std::string &assetName); };