-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcado.c
More file actions
139 lines (124 loc) · 3.4 KB
/
Copy pathcado.c
File metadata and controls
139 lines (124 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// Autodesk DXF to POV-Ray SDL converter
//
// Supported entities: 3DMESH
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINE_MAX 80
int main(int argc, char* argv[])
{
char* filein;
char fileout[FILENAME_MAX];
char line[LINE_MAX];
size_t len = 0;
#ifdef __linux__
size_t eol = 2;
#elif _WIN32
size_t eol = 1;
#endif
if (argc < 2) {
fprintf(stderr, "Autodesk DXF to Povray SDL converter: creates 'mesh' object from '3DFACE's.\n\
Usage: dxf2pov infile [outfile]\n");
exit(1);
}
filein = argv[1];
if (argc < 3) {
size_t len = strlen(filein);
memcpy(fileout, filein, len);
memcpy(&fileout[len-4], ".inc\0", 6);
} else {
memcpy(fileout, argv[2], strlen(argv[2]) + 1);
}
FILE* fin = fopen(filein, "r");
if (fin == NULL) {
fprintf(stderr, "Can't open file '%s'\n", filein);
exit(1);
}
FILE* fout = fopen(fileout, "w");
if (fout == NULL) {
fprintf(stderr, "Can't open file '%s'\n", fileout);
exit(1);
}
int face = 0;
fwrite("#declare Geometry = mesh\n{\n", 27, 1, fout);
while (fgets(line, LINE_MAX, fin) != NULL)
{
len = strlen(line);
line[len-eol] = '\0';
if(!strcmp(line, "3DFACE"))
{
fwrite(" triangle { " , 13, 1, fout);
face = 1;
}
else if (!strcmp(line, "10") && face) {
fgets(line, LINE_MAX, fin);
fwrite("<", 1, 1, fout);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "20") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "30") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(">, ", 3, 1, fout);
}
else if (!strcmp(line, "11") && face) {
fgets(line, LINE_MAX, fin);
fwrite("<", 1, 1, fout);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "21") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "31") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(">, ", 3, 1, fout);
}
else if (!strcmp(line, "12") && face) {
fgets(line, LINE_MAX, fin);
fwrite("<", 1, 1, fout);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "22") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(",", 1, 1, fout);
}
else if (!strcmp(line, "32") && face) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite("> }\n", 4, 1, fout);
face = 0;
}
/* TODO: Compare with 12, 22, 32
else if (!strcmp(line, "13\r\n")) {
fgets(line, LINE_MAX, fin);
fwrite("<", 1, 1, fout);
fwrite(line, strlen(line) - eol, 1, fout);
}
else if (!strcmp(line, "23\r\n")) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
}
else if (!strcmp(line, "33\r\n")) {
fgets(line, LINE_MAX, fin);
fwrite(line, strlen(line) - eol, 1, fout);
fwrite(">}\n", 3, 1, fout);
}
*/
}
fwrite("}\n", 2, 1, fout);
fclose(fin);
fclose(fout);
}