//Set default string variable to 'f '
STRINGWRITE = 'f '
//Checks wether the reset hex '98 00' occurs before the face ends (3 x 8), and if so,
//changes offset to the begging of the first face after the offending '98 00 xx'.
TESTSTRING = string_copy(MData,Position,19);
if string_pos('9800',TESTSTRING) != 0 && string_pos('009800',TESTSTRING) == 0 then {Position += string_pos('9800',TESTSTRING)+5;}
//Part of the model convert code, just ignore it. Also, it helps to check if
//the end of the file is reached.
//Also, from here till the next comment, it's just converting the first 4 digits
//from the offset ('Position' variable) from hex to decimal.
Hex = string_copy(MData,Position+1,1);
if Hex == 'Q' then {
file_text_write_string(MWrite,' ');
file_text_close(MWrite);
show_message('Done!');
obj_exportBut.image_index = 0;
obj_importBut.image_index = 0;
instance_destroy();
exit;}
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+2,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+3,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
//No more converting, and now variable Face1A to the converted hex.
Face1A = XXX+YYY;
//Now converts the second third of face 1, and makes the first third
//of the face 2 equal the same number.
Hex = string_copy(MData,Position+9,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+10,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+11,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face1B = XXX+YYY;
Face2A = Face1B;
//Now converts the last third of face 1, and makes the second third
//of the face 2 equal the same number, AND the first third of face 3.
Hex = string_copy(MData,Position+17,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+18,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+19,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face1C = XXX+YYY;
Face2B = Face1C;
Face3A = Face1C;
//Now converts the last third of face 2, and makes the second third
//of the face 3 equal the same number.
Hex = string_copy(MData,Position+25,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+26,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+27,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face2C = XXX+YYY;
Face3B = Face2C;
//And we convert the remaining third of face 3.
Hex = string_copy(MData,Position+33,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+34,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+35,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face3C = XXX+YYY;
/////////////////////////////////////////////////////////
//This following section tediously checks for duplicate//
//data, If it's found then it ignores one of the //
//duplicates and adds the one that follows //
/////////////////////////////////////////////////////////
//We start with face 3.
if Face3A == Face3B then {
Hex = string_copy(MData,Position+41,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+42,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+43,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face3D = XXX+YYY;
Face3B = Face3D;
}
if Face3A == Face3C then {
Hex = string_copy(MData,Position+41,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+42,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+43,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face3D = XXX+YYY;
Face3C = Face3D;
}
if Face3B == Face3C then {
Hex = string_copy(MData,Position+41,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+42,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+43,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face3D = XXX+YYY;
Face3C = Face3D;
}
////////////////////////////////////////////
if Face2A == Face2B then {
Hex = string_copy(MData,Position+33,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+34,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+35,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face2D = XXX+YYY;
Face2B = Face2D;
}
if Face2A == Face2C then {
Hex = string_copy(MData,Position+33,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+34,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+35,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face2D = XXX+YYY;
Face2C = Face2D;
}
if Face2B == Face2C then {
Hex = string_copy(MData,Position+33,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+34,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+35,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face2D = XXX+YYY;
Face2C = Face2D;
}
/////////////////////////////////////////////
if Face1A == Face1B then {
Hex = string_copy(MData,Position+25,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+26,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+27,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face1D = XXX+YYY;
Face1B = Face1D;
}
if Face1A == Face1C then {
Hex = string_copy(MData,Position+25,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+26,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+27,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face1D = XXX+YYY;
Face1C = Face1D;
}
if Face1B == Face1C then {
Hex = string_copy(MData,Position+25,1);
script_execute(scr_Za);
XXX = DigA;
Hex = string_copy(MData,Position+26,1);
script_execute(scr_DigA);
Hex = string_copy(MData,Position+27,1);
script_execute(scr_DigB);
YYY = DigA+DigB+1;
Face1D = XXX+YYY;
Face1C = Face1D;
}
//////////////////////////////////////////////////
//Writes the full line to be written to the file to 'STRINGWRITE' variable
STRINGWRITE += string(Face1A) + ' ';
STRINGWRITE += string(Face1B) + ' ';
STRINGWRITE += string(Face1C);
//This is more personal. Basically, it checks for duplicate values, or those that exceed the
//vertice number.
if Face1A == Face1B or Face1B == Face1C or Face1A == Face1C then {STRINGWRITE += string(Face1C) + 'ERROR';}
if Face1A > 2508 or Face1B > 2508 or Face1C > 2508 then {STRINGWRITE += 'FALSEFALSE';}
//Write 'STRINGWRITE' variable to file 'MWrite', then make a line break.
file_text_write_string(MWrite,STRINGWRITE);
file_text_writeln(MWrite);
//This mainly checks if there was room for face 2 before '98 00'... I know I should have checked this earlier
//but I didn't. If your still confused, it's like if in the hex, the last thing before '98 00' was
//the third part of Face 1, and no more room for faces 2 and 3 to finish.
TESTSTRING = string_copy(MData,Position,27);
if string_pos('9800',TESTSTRING) != 0 && string_pos('009800',TESTSTRING) == 0 then {
//Once again
STRINGWRITE = 'f '
STRINGWRITE += string(Face2A) + ' ';
STRINGWRITE += string(Face2B) + ' ';
STRINGWRITE += string(Face2C);
//And another personal check
if Face2A == Face2B or Face2B == Face2C or Face2A == Face2C then {STRINGWRITE += string(Face2C) + 'ERROR';}
if Face2A > 2508 or Face2B > 2508 or Face2C > 2508 then {STRINGWRITE += 'FALSEFALSE';}
//Write and break.
file_text_write_string(MWrite,STRINGWRITE);
file_text_writeln(MWrite);
}
TESTSTRING = string_copy(MData,Position,35);
if string_pos('9800',TESTSTRING) != 0 && string_pos('009800',TESTSTRING) == 0 then {
//And again
STRINGWRITE = 'f '
STRINGWRITE += string(Face3A) + ' ';
STRINGWRITE += string(Face3B) + ' ';
STRINGWRITE += string(Face3C);
//And again
if Face3A == Face3B or Face3B == Face3C or Face3A == Face3C then {STRINGWRITE += ' ' + string(Face3C) + 'ERROR';}
if Face3A > 2508 or Face3B > 2508 or Face3C > 2508 then {STRINGWRITE += 'FALSEFALSE';}
//Write and break
file_text_write_string(MWrite,STRINGWRITE);
file_text_writeln(MWrite);
}
Position += 24;