-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nbtm
committed
Sep 17, 2021
1 parent
98c0902
commit 7e70674
Showing
12 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Blender v2.92.0 OBJ File: '' | ||
# www.blender.org | ||
o Cube | ||
v 1.000000 1.000000 -1.000000 | ||
v 1.000000 -1.000000 -1.000000 | ||
v 1.000000 1.000000 1.000000 | ||
v 1.000000 -1.000000 1.000000 | ||
v -1.000000 1.000000 -1.000000 | ||
v -1.000000 -1.000000 -1.000000 | ||
v -1.000000 1.000000 1.000000 | ||
v -1.000000 -1.000000 1.000000 | ||
s off | ||
f 1 5 7 3 | ||
f 4 3 7 8 | ||
f 8 7 5 6 | ||
f 6 2 4 8 | ||
f 2 1 3 4 | ||
f 6 5 1 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include "obj.h" | ||
|
||
enum type { | ||
COL = 1, | ||
NOCOL = 2 | ||
}; | ||
|
||
struct quad { | ||
int x[4]; | ||
int y[4]; | ||
int z[4]; | ||
|
||
enum type type; | ||
unsigned int texture; | ||
}; | ||
|
||
struct vertice { | ||
int x; | ||
int y; | ||
int z; | ||
}; | ||
|
||
int next_char_pointer(char *content, int current_offset, int lim, char delim) { | ||
// Returns the index of the next newline char | ||
int i = 0; | ||
|
||
while ((*(content + current_offset + i) != delim) && i + current_offset < lim) { | ||
i += 1; | ||
} | ||
|
||
return current_offset + i; | ||
}; | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc < 3) { | ||
printf("No infile or outfile supplied"); | ||
return 0; | ||
} | ||
in_file = argv[1]; | ||
out_file = argv[2]; | ||
|
||
printf("Read: %s. Write: %s\n", in_file, out_file); | ||
|
||
// Allocate buffer for file size | ||
FILE *fp; | ||
fp = fopen(in_file, "r"); | ||
|
||
if (fp == NULL) { | ||
perror("Failed to open infile"); | ||
return 0; | ||
} | ||
|
||
fseek(fp, 0L, SEEK_END); | ||
int file_size = ftell(fp); | ||
fseek(fp, 0L, SEEK_SET); | ||
|
||
printf("%s %d bytes long\n", in_file, file_size); | ||
char fp_content[file_size]; | ||
|
||
fread(&fp_content, file_size, 1, fp); | ||
|
||
// Count vertexes | ||
int vertex_count = 0; | ||
int offset = 0; | ||
|
||
while (offset < file_size) { | ||
int line_size = next_char_pointer((char *) &fp_content, offset, file_size, (char) *"\n"); | ||
line_size -= offset; | ||
|
||
char *line = (char*) malloc(line_size + 2); | ||
memset(line, '\x00', line_size); | ||
memcpy(line, (char *) &fp_content[offset], line_size); | ||
|
||
if (line[0] == *"v" && line[1] == *" ") { | ||
vertex_count += 1; | ||
} | ||
|
||
free(line); | ||
offset += line_size + 1; | ||
} | ||
printf("%d\n", vertex_count); | ||
|
||
// Allocate the array for the vertices | ||
struct vertice object_vertices[vertex_count]; | ||
offset = 0; | ||
int vertex_i = 0; | ||
|
||
while (offset < file_size) { | ||
int line_size = next_char_pointer((char *) &fp_content, offset, file_size, (char) *"\n"); | ||
line_size -= offset; | ||
|
||
char *line = (char*) malloc(line_size + 2); | ||
memset(line, '\x00', line_size); | ||
memcpy(line, (char *) &fp_content[offset], line_size); | ||
|
||
if (line[0] == *"v" && line[1] == *" ") { | ||
// Interperate vertex | ||
int col_offset = 2; | ||
int v_size; | ||
|
||
v_size = next_char_pointer((char*) &fp_content, offset + col_offset, file_size, (char) *" "); | ||
v_size -= offset; | ||
v_size -= col_offset; | ||
|
||
char *x_str = (char*) malloc(v_size + 2); | ||
memset(x_str, '\x00', v_size); | ||
memcpy(x_str, (char*) &fp_content[offset + col_offset], v_size); | ||
object_vertices[0].x = atoi(x_str); | ||
free(x_str); | ||
printf("%d\n", object_vertices[0].x); | ||
} | ||
|
||
free(line); | ||
offset += line_size + 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
|
||
enum type; | ||
|
||
struct quad; | ||
struct vertice; | ||
|
||
int next_char_pointer(char *content, int current_offset, int lim, char delim); | ||
|
||
char *out_file; | ||
char *in_file; | ||
int main(int argc, char *argv[]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
jo_vertice plane[] = { | ||
{object[0].x[0], object[0].y[0], object[0].z[0]}, | ||
{object[0].x[1], object[0].y[1], object[0].z[1]}, | ||
{object[0].x[2], object[0].y[2], object[0].z[2]}, | ||
{object[0].x[3], object[0].y[3], object[0].z[3]}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters