Version 0.2.0
Fixed Size/UV Issues Atlas builder Calculate UVS during Packing Fix File loader loading height into width Set Atlas Size on File load Push Entries on File load Only build palladium, if it is not in build space Add functionality to d7rc-make to check files and create files Fix Palladium Submodule Integration
This commit is contained in:
@@ -40,9 +40,6 @@ bool Atlas::AppendImage(PD::Image::Ref img, const std::string& name) {
|
||||
e.iImg = img;
|
||||
e.iPos = PD::ivec2(it.x, it.y);
|
||||
e.Size = PD::ivec2(img->Width(), img->Height());
|
||||
e.UV = PD::fvec4((float)it.x / (float)Size.x, (float)it.y / (float)Size.y,
|
||||
(float)(it.x + img->Width()) / (float)Size.x,
|
||||
(float)(it.x + img->Height()) / (float)Size.y);
|
||||
Entries.push_back(e);
|
||||
#ifdef DEBUG
|
||||
std::cout << std::format("Created Image {} ({})\n", name,
|
||||
@@ -86,6 +83,7 @@ void Atlas::Pack() {
|
||||
if (!PD::BitUtil::IsSingleBit(Max.y)) {
|
||||
Size.y = PD::BitUtil::GetPow2(Max.y);
|
||||
}
|
||||
pCreateUVs();
|
||||
Img.resize(Size.x * Size.y * 4);
|
||||
for (auto& it : Entries) {
|
||||
for (int i = 0; i < it.Size.x; i++) {
|
||||
@@ -128,4 +126,13 @@ PD::Li::Texture::Ref Atlas::Get(const std::string& name) {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Atlas::pCreateUVs() {
|
||||
for (auto& e : Entries) {
|
||||
e.UV = PD::fvec4((float)e.iPos.x / (float)Size.x,
|
||||
1.f - (float)e.iPos.y / (float)Size.y,
|
||||
(float)(e.iPos.x + e.Size.x) / (float)Size.x,
|
||||
1.f - (float)(e.iPos.y + e.Size.y) / (float)Size.y);
|
||||
}
|
||||
}
|
||||
} // namespace D7RC
|
||||
@@ -107,6 +107,7 @@ void File::Read(Atlas& atlas, const std::string& path) {
|
||||
hdr.Read(iff);
|
||||
pReadTab(iff, atlas);
|
||||
atlas.Img.resize(hdr.DataSize);
|
||||
atlas.Size = PD::ivec2(hdr.Width, hdr.Height);
|
||||
iff.read(reinterpret_cast<char*>(atlas.Img.data()), hdr.DataSize);
|
||||
iff.close();
|
||||
}
|
||||
@@ -118,11 +119,12 @@ void File::pReadTab(std::ifstream& iff, Atlas& atlas) {
|
||||
PD::u32 namelen = 0;
|
||||
iff.read(reinterpret_cast<char*>(&e.UV), sizeof(e.UV));
|
||||
iff.read(reinterpret_cast<char*>(&w), sizeof(w));
|
||||
iff.read(reinterpret_cast<char*>(&w), sizeof(h));
|
||||
iff.read(reinterpret_cast<char*>(&h), sizeof(h));
|
||||
iff.read(reinterpret_cast<char*>(&namelen), sizeof(PD::u32));
|
||||
e.Name.resize(namelen);
|
||||
iff.read(e.Name.data(), namelen);
|
||||
e.Size = PD::ivec2(w, h);
|
||||
atlas.Entries.push_back(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,21 +28,72 @@ SOFTWARE.
|
||||
#define VERSION ""
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
std::cout << "d7rc-make v" VERSION << std::endl;
|
||||
int szs = 1024;
|
||||
D7RC::Atlas a(szs);
|
||||
std::map<PD::Image::Ref, std::string> imgs;
|
||||
for (auto& it : std::filesystem::directory_iterator("images")) {
|
||||
auto img = PD::Image::New(it.path().string());
|
||||
PD::Image::Convert(img, PD::Image::RGBA);
|
||||
imgs[img] = it.path().filename().string();
|
||||
int main(int argc, char** argv) {
|
||||
if (argc > 1) {
|
||||
if (std::string(argv[1]) == "version") {
|
||||
std::cout << "d7rc-make v" << VERSION << std::endl;
|
||||
return 0;
|
||||
} else if (std::string(argv[1]) == "help") {
|
||||
std::cout << "d7rc-make v" << VERSION << std::endl;
|
||||
std::cout << "Usage: d7rc-make [cmd]" << std::endl;
|
||||
std::cout << "Commands:" << std::endl;
|
||||
std::cout << " version Show version" << std::endl;
|
||||
std::cout << " help Show this help message"
|
||||
<< std::endl;
|
||||
std::cout << " tex paths out Create Texture Atlas" << std::endl;
|
||||
std::cout << " check path Show D7RC file info" << std::endl;
|
||||
return 0;
|
||||
} else if (std::string(argv[1]) == "tex") {
|
||||
if (argc < 4) {
|
||||
std::cout << "Not paths given for 'tex'." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
int szs = 1024;
|
||||
D7RC::Atlas a(szs);
|
||||
std::map<PD::Image::Ref, std::string> imgs;
|
||||
for (int i = 2; i < argc - 1; i++) {
|
||||
for (auto& it : std::filesystem::directory_iterator(argv[i])) {
|
||||
auto img = PD::Image::New(it.path().string());
|
||||
PD::Image::Convert(img, PD::Image::RGBA);
|
||||
imgs[img] = it.path().filename().string();
|
||||
}
|
||||
}
|
||||
for (auto& it : imgs) {
|
||||
a.AppendImage(it.first, it.second);
|
||||
}
|
||||
a.Pack();
|
||||
D7RC::File f;
|
||||
f.Write(a, std::string(argv[argc - 1]));
|
||||
return 0;
|
||||
} else if (std::string(argv[1]) == "check") {
|
||||
if (argc < 3) {
|
||||
std::cout << "No path to .d7rc file was specified!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
D7RC::Atlas a;
|
||||
D7RC::File f;
|
||||
f.Read(a, argv[2]);
|
||||
// Probably not the way how you should output it... but my favourite
|
||||
std::cout << std::format("Magic: {}", std::string((char*)&f.hdr.Magic, 4))
|
||||
<< std::endl;
|
||||
std::cout << std::format("Size: {}", PD::ivec2(f.hdr.Width, f.hdr.Height))
|
||||
<< std::endl;
|
||||
std::cout << "Data Size: " << PD::Strings::FormatBytes(f.hdr.DataSize)
|
||||
<< std::endl;
|
||||
std::cout << "Images: " << f.hdr.NumEntries << std::endl;
|
||||
std::cout << std::format(
|
||||
"Atlas Info:\n {} Entries\n {} bytes\nEntries:\n", a.Entries.size(),
|
||||
a.Img.size());
|
||||
for (auto& it : a.Entries) {
|
||||
std::cout << std::format(" {} {}\n", it.Name, it.Size);
|
||||
}
|
||||
} else {
|
||||
std::cout << "Unknown command: " << argv[1] << std::endl;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
std::cout << "d7rc-make v" << VERSION << std::endl;
|
||||
std::cout << "Use 'd7rc-make help' for more information." << std::endl;
|
||||
}
|
||||
for (auto& it : imgs) {
|
||||
a.AppendImage(it.first, it.second);
|
||||
}
|
||||
a.Pack();
|
||||
D7RC::File f;
|
||||
f.Write(a, "test.d7rc");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user