X-Git-Url: https://harrygodden.com/git/?p=fishladder.git;a=blobdiff_plain;f=mdlcomp.c;fp=mdlcomp.c;h=0000000000000000000000000000000000000000;hp=02450e7ae0b7d377797f86163f76c964a9d83487;hb=30490c4c08d5c0f811017a901aa9e25a95be7c40;hpb=3363633178b1eea582304742ad1202487af0feb1 diff --git a/mdlcomp.c b/mdlcomp.c deleted file mode 100644 index 02450e7..0000000 --- a/mdlcomp.c +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved - -#define VG_TOOLS -#include "vg/vg.h" - -// Super basic model compiler -int main( int argc, char *argv[] ) -{ - if( argc < 3 ) - { - vg_error( "Need input/output files\n" ); - return 0; - } - - float *vertex_buffer = NULL; - - int c; - FILE *file, *output; - file = fopen( argv[1], "r" ); - - if( file ) - { - output = fopen( argv[2], "w" ); - if( !output ) - { - vg_error( "couldn't open output for writing\n" ); - fclose(file); - return 0; - } - - fprintf( output, "/*triangle buffer generated from source file: '%s'*/\n", argv[1] ); - - char line[512]; - int i = 0, j = 0; - - while(( c = getc(file)) != EOF ) - { - if( i >= vg_list_size( line ) ) - { - vg_error( "Line was way too long.. (line %d)\n", j+1 ); - arrfree( vertex_buffer ); - fclose(file); - fclose(output); - return 0; - } - - if( c == '\n' ) - { - line[i] = 0x00; - - // Parse vert - if( line[0] == 'v' ) - { - v3f vert; - sscanf( line+2, "%f %f %f", vert, vert+1, vert+2 ); - arrpush( vertex_buffer, vert[0] ); - arrpush( vertex_buffer, -vert[2] ); - } - - // Write face - else if( line[0] == 'f' ) - { - int tri[3]; - sscanf( line+2, "%d %d %d", tri, tri+1, tri+2 ); - - for( int k = 0; k < 3; k ++ ) - fprintf( output, "%.6ff,%.6ff,", vertex_buffer[(tri[k]-1)*2], vertex_buffer[(tri[k]-1)*2+1] ); - fprintf( output, "\n" ); - } - - i = 0; - j ++; - } - else - { - line[i ++] = c; - } - } - - arrfree( vertex_buffer ); - fclose(file); - fclose(output); - } - else - { - vg_error( "Couldn't open source file\n" ); - return 0; - } -}