diff options
| author | Lywx <kiritodev01@gmail.com> | 2023-11-15 15:11:15 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-15 15:11:15 -0600 |
| commit | eaddecd0b402c12a780831e3139d7a35e78322e6 (patch) | |
| tree | 0c961e1ba2339f52892b54f44b8ff0018b77c382 /src/factories/VtxFactory.cpp | |
| parent | a66b259d7c10c3367a04819c6b55d47fb9a99f5e (diff) | |
Torch v0.1 (#12)
* Splitted version yamls and implemented wip geo and dlist extraction
* Fixed linux compilation
* Added PoC WSL 2 detection
* Add undefined behaviour
* Added gfxdis as submodule
* update
* Removed gfxdis as a submodule
* Code works
* Replace ByteSwap with BSWAP
* Cleanup vertice factory
* readability
* readability 2
* Cleanup gfxfactory
* last one
* Rename name to symbol
* More implementation
* Implemented first PoC of C file generation
* Added output formatting on factories
* changes
* Moved generated dlists onto their respective folder
* Migrated more factories onto the new extractor system
* Fully ported all factories and added header generation
* Some updates
* Added Lights factory
* fix
* Fixed vtx extraction
* Lights work now
* delete old startup_logo yaml
* Generate all sections in single file
* Added support to generate header and code for textures
* Added O3 for release builds
* Added WIP dlist extraction and moved to use f3dold microcode
* Added segment support, autogeneration and fixed C generation
* Added symbol names on display list extraction
* Removed warnings
* Moved back to transform and replace
* Removed unnecesary macros
* Added extraction order and reversed vtx order
* Implemented true backwards sort
* [WIP] Implemented runtime gbi, more headers and a few config features
* Fix CLI11 on WSL and variety of fixes
* Fixes
* Update DisplayListFactory.h
* Update TextureFactory.cpp
* wip lights
* fix
* Correct callback
* Added waypoints
* Update ceremony_data.yml
* Changes
* Update TextureFactory.cpp
* Update commandline args
* Update comment
* Remove printf
* Update couple commands
* Renamed cubeos to torch
* Removed unused stuff and added an example config file
---------
Co-authored-by: KiritoDv <kiritodev01@gmail.com>
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/factories/VtxFactory.cpp')
| -rw-r--r-- | src/factories/VtxFactory.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/factories/VtxFactory.cpp b/src/factories/VtxFactory.cpp new file mode 100644 index 0000000..8196571 --- /dev/null +++ b/src/factories/VtxFactory.cpp @@ -0,0 +1,114 @@ +#include "VtxFactory.h" + +#include "Companion.h" +#include "utils/MIODecoder.h" + +#define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x +#define COL(c) "0x" << std::hex << std::setw(2) << std::setfill('0') << c + +void VtxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { + const auto symbol = node["symbol"] ? node["symbol"].as<std::string>() : entryName; + + if(Companion::Instance->IsOTRMode()){ + write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + return; + } + + write << "extern Vtx " << symbol << "[];\n"; +} + +void VtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto vtx = std::static_pointer_cast<VtxData>(raw)->mVtxs; + const auto symbol = node["symbol"].as<std::string>(); + const auto offset = node["offset"].as<uint32_t>(); + + if (Companion::Instance->IsDebug()) { + write << "// 0x" << std::hex << std::uppercase << offset << "\n"; + } + + write << "Vtx " << symbol << "[] = {\n"; + + for (int i = 0; i < vtx.size(); ++i) { + auto v = vtx[i]; + + auto x = v.ob[0]; + auto y = v.ob[1]; + auto z = v.ob[2]; + + auto flag = v.flag; + + auto tc1 = v.tc[0]; + auto tc2 = v.tc[1]; + + auto c1 = (uint16_t) v.cn[0]; + auto c2 = (uint16_t) v.cn[1]; + auto c3 = (uint16_t) v.cn[2]; + auto c4 = (uint16_t) v.cn[3]; + + if(i <= vtx.size() - 1) { + write << fourSpaceTab; + } + + // {{{ x, y, z }, f, { tc1, tc2 }, { c1, c2, c3, c4 }}} + write << "{{{" << NUM(x) << ", " << NUM(y) << ", " << NUM(z) << "}, " << flag << ", {" << NUM(tc1) << ", " << NUM(tc2) << "}, {" << COL(c1) << ", " << COL(c2) << ", " << COL(c3) << ", " << COL(c4) << "}}},\n"; + } + + if (Companion::Instance->IsDebug()) { + write << fourSpaceTab << "// 0x" << std::hex << std::uppercase << (offset + (16 * vtx.size())) << "\n"; + } + + write << "};\n\n"; +} + +void VtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto vtx = std::static_pointer_cast<VtxData>(raw); + auto writer = LUS::BinaryWriter(); + + WriteHeader(writer, LUS::ResourceType::Vertex, 0); + writer.Write((uint32_t) vtx->mVtxs.size()); + for(auto v : vtx->mVtxs) { + writer.Write(v.ob[0]); + writer.Write(v.ob[1]); + writer.Write(v.ob[2]); + writer.Write(v.flag); + writer.Write(v.tc[0]); + writer.Write(v.tc[1]); + writer.Write(v.cn[0]); + writer.Write(v.cn[1]); + writer.Write(v.cn[2]); + writer.Write(v.cn[3]); + } + + writer.Finish(write); +} + +std::optional<std::shared_ptr<IParsedData>> VtxFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { + auto mio0 = node["mio0"].as<size_t>(); + auto offset = node["offset"].as<uint32_t>(); + auto count = node["count"].as<size_t>(); + + auto decoded = MIO0Decoder::Decode(buffer, mio0); + LUS::BinaryReader reader(decoded.data() + offset, count * sizeof(VtxRaw) ); + + reader.SetEndianness(LUS::Endianness::Big); + std::vector<VtxRaw> vertices; + + for(size_t i = 0; i < count; i++) { + auto x = reader.ReadInt16(); + auto y = reader.ReadInt16(); + auto z = reader.ReadInt16(); + auto flag = reader.ReadUInt16(); + auto tc1 = reader.ReadInt16(); + auto tc2 = reader.ReadInt16(); + auto cn1 = reader.ReadUByte(); + auto cn2 = reader.ReadUByte(); + auto cn3 = reader.ReadUByte(); + auto cn4 = reader.ReadUByte(); + + vertices.push_back(VtxRaw({ + {x, y, z}, flag, {tc1, tc2}, {cn1, cn2, cn3, cn4} + })); + } + + return std::make_shared<VtxData>(vertices); +}
\ No newline at end of file |
