Unverified Commit 45962a9d authored by GovanifY's avatar GovanifY
Browse files

Oh my god it's horrible

parent ef0937b8
......@@ -5,7 +5,7 @@ It's as dirty as it can get and doesn't even include VU1 assembler
for now but eh, it kinda works.
Oh btw when I mean it kinda works datas are roughly placed, I just made the
tool in a day. It is still missing header reconstruction, fixing some unpack
tool in a day. It is still missing some unpack
commands and all, just figured I would upload this before I lose it
Good luck for understanding the code btw, should stop working
......
......@@ -4,6 +4,7 @@
#include <fstream>
#include <sstream>
#include <math.h>
#include <limits>
int flag(int x, int y, int z) {
int flagx = x;
......@@ -16,10 +17,17 @@ int main(int argc, char* argv[]){
if(argc<3){printf("Usage: obj2kh2v model.obj output.dsm"); return -1;}
std::ifstream in(argv[1], std::ios::in);
std::ofstream dsm (argv[2]);
dsm << ".align 0\n;" << argv[1] << "\n;Automatically generated by obj2kh2v\n;DO NOT EDIT IF YOU DON'T KNOW WHAT YOU ARE DOING\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V4_32, 0, *; Model Part Header\n.int 1, 0, 0, 0;type 1 Model\n.int 0, 0, 0, 0\n.int 0, 0, 0, 0; Nobody care about vertices merging and colors\n.int 0, 0, 0, 0\n.EndUnpack\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V2_16, 0, *; UV definition\n";
dsm << ".align 0\n;" << argv[1] << "\n;Automatically generated by obj2kh2v\n;DO NOT EDIT IF YOU DON'T KNOW WHAT YOU ARE DOING\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V4_32, 0, *; Model Part Header\n.int 1, 0, 0, 0;type 1 Model\n";
long hp = dsm.tellp();
//Can't insert if not at eof using ofstream so I put 10 spaces to fill up, size of INT_MAX and no \n to avoid linefeed not beeing rewritten
//It's so hacky but I'm fed up with this shit already
dsm << ".int " << " , , , ";
dsm << "\n.EndUnpack\n\nstcycl 01, 01; We write code to memory without skips/overwrite\n\nunpack 4, 128, V2_16, 0, *; UV definition\n";
int vi =0;
int ti =0;
if (dsm.is_open()){
std::string line;
int vi =0;
while (getline(in, line))
{
if (line.substr(0,2) == "v ")
......@@ -37,6 +45,7 @@ in.seekg(0, std::ios::beg);
float u, v;
s >> u; s >> v;
dsm << ".short " << int(round(u*4095)) << ", " << int(round(v*4095)) << "\n";
ti++;
}
}
......@@ -93,6 +102,13 @@ in.seekg(0, std::ios::beg);
dsm << ".EndUnpack\n\nunpack 4, 128, V4_32, 0, *; Vertex affiliation header\n.int " << vi+1 << ", 0, 0, 0\n.EndUnpack\n";
}
printf("h1: %i, h2: 4, h3: %i, h4: %i\nj1: %i, j2: %i, j3: 0, j4: 1\n",ti, 4+ti+vi, 4+ti+vi+1,vi, 4+ti);
//TODO: Stop hardcode Header size(5type-line exist) and Vert/Array
//h3: 1 not because 1 value but 1 array of 4, padding needs to be
//checked!
dsm.seekp(hp);
dsm << ".int " << ti << ", 4, " << 4+ti+vi << ", " << 4+ti+vi+1 << "; Number of u+v+flag+index, their offset, offset of vertex affiliation header, offset of mat definition(end)\n";
dsm << ".int 0, 0, 0, 0; Nobody care about vertices merging and colors\n";
dsm << ".int " << vi << ", " << 4+ti << ", 0, 1; Number of vertex, their offset, reserved and number of array attribution\n";
return 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment