File include/fgc.h changed (mode: 100644) (index f3608b6..9af3514) |
... |
... |
FGCMesh fgcLoadOBJ( const char* filePath ){ |
1010 |
1010 |
// Read the file, one line at a time. |
// Read the file, one line at a time. |
1011 |
1011 |
while( fgets( ln, sizeof(ln), file ) ){ |
while( fgets( ln, sizeof(ln), file ) ){ |
1012 |
1012 |
if( ln[0] && ln[0] != '#' ){ |
if( ln[0] && ln[0] != '#' ){ |
1013 |
|
// TODO. |
|
1014 |
|
// { strtof( str, str_end ), strtof( str, str_end ), strtof( str, str_end ) } |
|
|
1013 |
|
size_t len = strlen( ln ); |
|
1014 |
|
// Strip away new line characters. |
|
1015 |
|
for( int i = 0; i < 2; i++ ){ |
|
1016 |
|
if(len > 0 && (ln[len - 1] == '\r' || ln[len - 1] == '\n')){ |
|
1017 |
|
len--; |
|
1018 |
|
} |
|
1019 |
|
} |
|
1020 |
|
// Determine the type of element. |
|
1021 |
|
int type = 0; |
|
1022 |
|
if( len > 5 && ln[0] == 'v' && ln[1] == '\x20' ){ |
|
1023 |
|
type = 1; |
|
1024 |
|
}else if( len > 5 && ln[0] == 'v' && ln[1] == 't' ){ |
|
1025 |
|
type = 2; |
|
1026 |
|
}else if( len > 5 && ln[0] == 'v' && ln[1] == 'n' ){ |
|
1027 |
|
type = 3; |
|
1028 |
|
}else if( len > 5 && ln[0] == 'f' && ln[1] == '\x20' ){ |
|
1029 |
|
type = 4; |
|
1030 |
|
} |
|
1031 |
|
if( type > 0 ){ |
|
1032 |
|
// Start at the first non-space character. |
|
1033 |
|
size_t start = 2; |
|
1034 |
|
while( start < len && ln[start] == '\x20' ){ |
|
1035 |
|
start++; |
|
1036 |
|
} |
|
1037 |
|
// Parse the line. |
|
1038 |
|
for( size_t i = start; i <= len; i++ ){ |
|
1039 |
|
size_t num_len = i - start; |
|
1040 |
|
char num_str[32]; |
|
1041 |
|
if((i == len || ln[i] == '\x20' || ln[i] == '/') && num_len < sizeof(num_str)){ |
|
1042 |
|
memcpy( num_str, ln + start, num_len ); |
|
1043 |
|
// Null-terminate the string for strtof. |
|
1044 |
|
num_str[num_len] = '\0'; |
|
1045 |
|
// Note: strtof is locale-dependent. Set locale in main() |
|
1046 |
|
// TODO. |
|
1047 |
|
//{strtof(str, str_end), strtof(str, str_end), strtof(str, str_end)} |
|
1048 |
|
start = i + 1; |
|
1049 |
|
} |
|
1050 |
|
} |
|
1051 |
|
} |
1015 |
1052 |
} |
} |
1016 |
1053 |
} |
} |
1017 |
1054 |
|
|