bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/0.1
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
1 |
#include <STDIO.H> |
2 |
#include <STDLIB.H> |
|
3 |
#include <STRING.H> |
|
4 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
5 |
void parseface(char *facedata,int *varray,int *narray,int *tarray,int position, int hasuv, int hasnormals) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
6 |
char workstr[10]; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
7 |
int readpos = 0; |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
8 |
int i; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
9 |
for(i = 0; i < 3; i++) { |
10 |
int pos = 0; |
|
11 |
while(readpos < strlen(facedata) && facedata[readpos] != '/') { |
|
12 |
workstr[pos] = facedata[readpos]; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
13 |
pos++; |
14 |
readpos++; |
|
15 |
} |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
16 |
workstr[pos] = 0; |
17 |
pos = 0; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
18 |
readpos++; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
19 |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
20 |
// -1 to compensate for wavefront file starting on 1 and not 0 |
4.11.1
by a11patfr at his
Fixed the last indents |
21 |
if(i == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
22 |
varray[position] = atoi(workstr) - 1; |
23 |
} else if((i == 1) && (hasuv > 0)) { |
|
24 |
tarray[position] = atoi(workstr) - 1; |
|
25 |
} else if((i == 2) && (hasnormals > 0)) { |
|
26 |
narray[position] = atoi(workstr) - 1; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
27 |
} |
28 |
} |
|
29 |
}
|
|
30 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
31 |
void loadobj(char *objfilename, char *openobj, char *outputfile) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
32 |
FILE * pFile; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
33 |
pFile = fopen(objfilename, "r"); |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
34 |
char *buf; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
35 |
buf = (char*)malloc(1024); |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
36 |
char *result; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
37 |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
38 |
// foundobj is true if an object with a certain name is found |
39 |
// Set foundobj to true if we are loading all objects |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
40 |
int foundobj = 0; |
41 |
if(strcmp(openobj, "ALL") == 0) { |
|
42 |
foundobj = 1; |
|
43 |
} |
|
44 |
int vertcount = 0; |
|
45 |
int normalcount = 0; |
|
46 |
int texturecount = 0; |
|
47 |
int facecount = 0; |
|
48 |
int polycount = 0; |
|
49 |
int quadcount = 0; |
|
50 |
int trianglecount = 0; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
51 |
|
52 |
// Global Variables for Object |
|
53 |
float *vertexlist; |
|
54 |
float *uvlist; |
|
55 |
float *normallist; |
|
56 |
int *trianglelist; |
|
57 |
int *quadlist; |
|
4.11.1
by a11patfr at his
Fixed the last indents |
58 |
char *resultp1, *resultp2, *resultp3, *resultp4, *resultp5; |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
59 |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
60 |
if(pFile) { |
61 |
printf("Msg: Success opening: %s!\n", objfilename); |
|
62 |
while(fgets(buf, 1024, pFile) != NULL) { |
|
63 |
if(buf[0] == '#') { |
|
64 |
// Comment - Do Nothing |
|
65 |
} else { |
|
4.11.1
by a11patfr at his
Fixed the last indents |
66 |
result = strtok(buf, " \n\t"); |
67 |
if(result != NULL) { |
|
68 |
if(strcmp(result, "v") == 0) { |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
69 |
if(foundobj) { |
70 |
//Increase vertex counter |
|
71 |
vertcount++; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
72 |
} |
4.11.1
by a11patfr at his
Fixed the last indents |
73 |
} else if(strcmp(result, "vt") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
74 |
if(foundobj) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
75 |
// Increase texture coordinate counter |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
76 |
texturecount++; |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
77 |
} |
4.11.1
by a11patfr at his
Fixed the last indents |
78 |
} else if(strcmp(result, "vn") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
79 |
if(foundobj) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
80 |
// Increase normal counter |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
81 |
normalcount++; |
82 |
} |
|
4.11.1
by a11patfr at his
Fixed the last indents |
83 |
} else if(strcmp(result, "f") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
84 |
if(foundobj) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
85 |
// Increase face counter |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
86 |
facecount++; |
87 |
resultp1 = strtok(NULL, " \n\t"); |
|
88 |
resultp2 = strtok(NULL, " \n\t"); |
|
89 |
resultp3 = strtok(NULL, " \n\t"); |
|
90 |
resultp4 = strtok(NULL, " \n\t"); |
|
91 |
resultp5 = strtok(NULL, " \n\t"); |
|
92 |
if((resultp4 != NULL)&&(resultp5 == NULL)) { |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
93 |
quadcount++; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
94 |
} else if((resultp3 != NULL)&&(resultp4 == NULL)) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
95 |
trianglecount++; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
96 |
} else { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
97 |
polycount++; |
98 |
} |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
99 |
} |
100 |
} else if(strcmp(result, "g") == 0) { |
|
101 |
if(result=strtok(NULL, " \n\t")) { |
|
102 |
if(!strcmp(openobj, result)) { |
|
103 |
foundobj = 1; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
104 |
} |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
105 |
} else { |
106 |
printf("Error: Failed to read object name\n"); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
107 |
} |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
108 |
} else { |
109 |
//printf("O: %s \n",buf); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
110 |
} |
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
115 |
if(polycount > 0) { |
116 |
printf("Warning: Object %s in file %s contains faces that will be ignored, with more than 4 vertices.!\n", objfilename, openobj); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
117 |
} |
118 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
119 |
if(((trianglecount + quadcount) > 0)) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
120 |
// Set foundobj to true if we are loading all objects |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
121 |
if(strcmp(openobj, "ALL")) { |
4.11.1
by a11patfr at his
Fixed the last indents |
122 |
foundobj = 1; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
123 |
} |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
124 |
|
125 |
// Seek to beginning again |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
126 |
fseek(pFile, 0, SEEK_SET); |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
127 |
|
128 |
// Allocate local buffers |
|
4.11.1
by a11patfr at his
Fixed the last indents |
129 |
float *localvertexlist = (float *) malloc (sizeof(float) * vertcount * 3); |
130 |
float *localnormallist = (float *) malloc (sizeof(float) * normalcount * 3); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
131 |
float *localuvlist = (float *) malloc (sizeof(float) * texturecount * 2); |
132 |
int *localquadlist = (int *) malloc (sizeof(int) * quadcount * 4); |
|
133 |
int *localquadlistuv = (int *) malloc (sizeof(int) * quadcount * 4); |
|
134 |
int *localquadlistnormal = (int *) malloc (sizeof(int) * quadcount * 4); |
|
135 |
int *localtrianglelist = (int *) malloc (sizeof(int) * trianglecount * 3); |
|
136 |
int *localtrianglelistuv = (int *) malloc (sizeof(int) * trianglecount * 3); |
|
137 |
int *localtrianglelistnormal = (int *) malloc (sizeof(int) * trianglecount * 3); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
138 |
|
139 |
// Reset counters for second pass |
|
4.11.1
by a11patfr at his
Fixed the last indents |
140 |
trianglecount = 0; |
141 |
quadcount = 0; |
|
142 |
normalcount = 0; |
|
143 |
vertcount = 0; |
|
144 |
texturecount = 0; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
145 |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
146 |
while(fgets(buf, 1024, pFile) != NULL) { |
147 |
if(buf[0] == '#') { |
|
148 |
// Comment - Do Nothing |
|
149 |
} else { |
|
150 |
result = strtok(buf, " \n\t"); |
|
151 |
if(result != NULL) { |
|
4.11.1
by a11patfr at his
Fixed the last indents |
152 |
if(strcmp(result, "v") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
153 |
if(foundobj) { |
154 |
result = strtok(NULL, " \n\t"); |
|
155 |
localvertexlist[(vertcount * 3)] = atof(result); |
|
156 |
result = strtok(NULL, " \n\t"); |
|
157 |
localvertexlist[(vertcount * 3) + 1] = atof(result); |
|
158 |
result = strtok(NULL, " \n\t"); |
|
159 |
localvertexlist[(vertcount * 3) + 2] = atof(result); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
160 |
vertcount++; |
161 |
} |
|
4.11.1
by a11patfr at his
Fixed the last indents |
162 |
} else if(strcmp(result, "vt") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
163 |
if(foundobj) { |
164 |
result = strtok(NULL, " \n\t"); |
|
165 |
localuvlist[(texturecount * 2)] = atof(result); |
|
166 |
result = strtok(NULL, " \n\t"); |
|
167 |
localuvlist[(texturecount * 2) + 1] = atof(result); |
|
168 |
texturecount++; |
|
169 |
} |
|
4.11.1
by a11patfr at his
Fixed the last indents |
170 |
} else if(strcmp(result, "vn") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
171 |
if(foundobj) { |
172 |
result = strtok(NULL, " \n\t"); |
|
173 |
localnormallist[(normalcount * 3)] = atof(result); |
|
174 |
result = strtok(NULL, " \n\t"); |
|
175 |
localnormallist[(normalcount * 3) + 1] = atof(result); |
|
176 |
result = strtok(NULL, " \n\t"); |
|
177 |
localnormallist[(normalcount * 3) + 2] = atof(result); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
178 |
normalcount++; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
179 |
} |
4.11.1
by a11patfr at his
Fixed the last indents |
180 |
} else if(strcmp(result, "f") == 0) { |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
181 |
if(foundobj) { |
182 |
resultp1 = strtok(NULL, " \n\t"); |
|
183 |
resultp2 = strtok(NULL, " \n\t"); |
|
184 |
resultp3 = strtok(NULL, " \n\t"); |
|
185 |
resultp4 = strtok(NULL, " \n\t"); |
|
186 |
resultp5 = strtok(NULL, " \n\t"); |
|
187 |
if((resultp4 != NULL)&&(resultp5 == NULL)) { |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
188 |
// Parse all 4 points in quad |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
189 |
parseface(resultp1, localquadlist, localquadlistnormal, localquadlistuv, quadcount * 4, texturecount, normalcount); |
190 |
parseface(resultp2, localquadlist, localquadlistnormal, localquadlistuv, (quadcount * 4) + 1, texturecount, normalcount); |
|
191 |
parseface(resultp3, localquadlist, localquadlistnormal, localquadlistuv, (quadcount * 4) + 2, texturecount, normalcount); |
|
192 |
parseface(resultp4, localquadlist, localquadlistnormal, localquadlistuv, (quadcount * 4) + 3, texturecount, normalcount); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
193 |
quadcount++; |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
194 |
} else if((resultp3 != NULL)&&(resultp4 == NULL)) { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
195 |
// Parse all 3 points in triangle |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
196 |
parseface(resultp1, localtrianglelist, localtrianglelistnormal, localtrianglelistuv, trianglecount * 3, texturecount, normalcount); |
197 |
parseface(resultp2, localtrianglelist, localtrianglelistnormal, localtrianglelistuv, (trianglecount * 3) + 1, texturecount, normalcount); |
|
198 |
parseface(resultp3, localtrianglelist, localtrianglelistnormal, localtrianglelistuv, (trianglecount * 3) + 2, texturecount, normalcount); |
|
199 |
trianglecount++; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
200 |
} |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
201 |
} |
202 |
} else if(strcmp(result, "g") == 0) { |
|
203 |
if(result = strtok(NULL, " \n\t")) { |
|
204 |
if(!strcmp(openobj, result)) { |
|
4.11.1
by a11patfr at his
Fixed the last indents |
205 |
foundobj = 1; |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
206 |
} |
207 |
} |
|
208 |
} |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
209 |
} |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
210 |
} |
211 |
} |
|
4.11.1
by a11patfr at his
Fixed the last indents |
212 |
int i = 0; |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
213 |
// Allocate buffers |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
214 |
vertexlist = (float *) malloc (sizeof(float) * vertcount * 3); |
215 |
normallist = (float *) malloc (sizeof(float) * vertcount * 3); |
|
216 |
uvlist = (float *) malloc (sizeof(float) * vertcount * 2); |
|
217 |
trianglelist = (int *) malloc (sizeof(int) * trianglecount * 3); |
|
218 |
quadlist = (int *) malloc (sizeof(int) * quadcount * 4); |
|
219 |
||
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
220 |
// Copy data from Per Face model to Per Vertex model first for triangles and then for quads |
221 |
// If there are triangle normals, copy triangle normal data |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
222 |
if(normalcount > 0) { |
223 |
printf("Msg: Copying Triangle Normals: %i / %i !\n", normalcount, trianglecount); |
|
224 |
for(i = 0; i < trianglecount * 3; i++) { |
|
225 |
// Normal X |
|
226 |
normallist[localtrianglelist[i] * 3] = localnormallist[localtrianglelistnormal[i] * 3]; |
|
227 |
// Normal Y |
|
228 |
normallist[(localtrianglelist[i] * 3 ) + 1 ] = localnormallist[(localtrianglelistnormal[i] * 3) + 1 ]; |
|
229 |
// Normal Z |
|
230 |
normallist[(localtrianglelist[i] * 3) + 2] = localnormallist[(localtrianglelistnormal[i] * 3) + 2]; |
|
231 |
} |
|
232 |
for(i = 0; i < quadcount * 4; i++) { |
|
233 |
// Normal X |
|
234 |
normallist[localquadlist[i] * 3] = localnormallist[localquadlistnormal[i] * 3]; |
|
235 |
// Normal Y |
|
236 |
normallist[(localquadlist[i] * 3) + 1] = localnormallist[(localquadlistnormal[i] * 3) + 1]; |
|
237 |
// Normal Z |
|
238 |
normallist[(localquadlist[i] * 3) + 2] = localnormallist[(localquadlistnormal[i] * 3) + 2]; |
|
239 |
} |
|
240 |
} else { |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
241 |
printf("Msg: No Triangle Normals to Copy\n"); |
242 |
} |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
243 |
|
244 |
// If there are triangle uv coordinates, copy uv coordinate data |
|
245 |
if(texturecount > 0) { |
|
246 |
printf("Msg: Copying Triangle UV Coordinates: %i / %i !\n", texturecount, trianglecount); |
|
247 |
for(i = 0; i < trianglecount * 3; i++) { |
|
248 |
// U Coordinate |
|
249 |
uvlist[localtrianglelist[i] * 3] = localuvlist[localtrianglelistuv[i] * 3]; |
|
250 |
// V Coordinate |
|
251 |
uvlist[(localtrianglelist[i] * 3) + 1] = localuvlist[(localtrianglelistuv[i] * 3) + 1]; |
|
252 |
} |
|
253 |
for(i = 0;i < quadcount * 4; i++) { |
|
254 |
// U Coordinate |
|
255 |
uvlist[localquadlist[i] * 3] = localuvlist[localquadlistuv[i] * 3]; |
|
256 |
// V Coordinate |
|
257 |
uvlist[(localquadlist[i] * 3) + 1] = localuvlist[(localquadlistuv[i] * 3) + 1]; |
|
258 |
} |
|
259 |
} else { |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
260 |
printf("Msg: No Triangle UV Coordinates to Copy\n"); |
261 |
} |
|
262 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
263 |
// Same for Quads |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
264 |
printf("--------------------------------\n"); |
265 |
printf("Saving JSON Object file: %s\n", outputfile); |
|
266 |
printf("--------------------------------\n"); |
|
267 |
||
268 |
// Process data to JSON |
|
269 |
printf("{\n"); |
|
270 |
printf("\"vertexPositions\" : ["); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
271 |
for(i = 0; i < (vertcount * 3); i++) { |
272 |
if(i < ((vertcount * 3) - 1)) { |
|
273 |
printf("%f,", localvertexlist[i]); |
|
274 |
} else { |
|
275 |
printf("%f", localvertexlist[i]); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
276 |
} |
277 |
} |
|
278 |
printf("],\n"); |
|
279 |
printf("\"vertexNormals\" : ["); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
280 |
if(normalcount > 0) { |
281 |
for(i = 0; i < (vertcount * 3); i++) { |
|
282 |
if(i < ((vertcount * 3) - 1)) { |
|
283 |
printf("%f,", normallist[i]); |
|
284 |
} else { |
|
285 |
printf("%f", normallist[i]); |
|
286 |
} |
|
287 |
} |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
288 |
} |
289 |
printf("],\n"); |
|
290 |
printf("\"vertexTextureCoords\" : ["); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
291 |
if(texturecount > 0) { |
292 |
for(i = 0; i < (vertcount * 2); i++){ |
|
293 |
if(i < ((vertcount * 2) - 1)) { |
|
294 |
printf("%f,", uvlist[i]); |
|
295 |
} else { |
|
296 |
printf("%f", uvlist[i]); |
|
297 |
} |
|
298 |
} |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
299 |
} |
300 |
printf("],\n"); |
|
301 |
printf("\"indices\" : ["); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
302 |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
303 |
// Triangle indices |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
304 |
for(i = 0; i < (trianglecount * 3); i++) { |
305 |
if(i < ((trianglecount * 3) - 1)) { |
|
306 |
printf("%i,", localtrianglelist[i]); |
|
307 |
} else { |
|
308 |
printf("%i", localtrianglelist[i]); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
309 |
} |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
310 |
} |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
311 |
|
312 |
// Quad indices |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
313 |
for(i = 0; i < quadcount; i++) { |
314 |
if(i == (quadcount - 1)) { |
|
315 |
printf("%i,%i,%i,%i,%i,%i,", localquadlist[i], localquadlist[i + 1], localquadlist[i + 2], localquadlist[i + 2], localquadlist[i + 3], localquadlist[i]); |
|
316 |
} else { |
|
317 |
printf("%i,%i,%i,%i,%i,%i ", localquadlist[i], localquadlist[i + 1], localquadlist[i + 2], localquadlist[i + 2], localquadlist[i + 3], localquadlist[i]); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
318 |
} |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
319 |
} |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
320 |
|
321 |
printf("]\n"); |
|
322 |
printf("}\n"); |
|
323 |
||
324 |
// Free buffers |
|
325 |
free(localvertexlist); |
|
326 |
free(localnormallist); |
|
327 |
free(localuvlist); |
|
328 |
free(localtrianglelist); |
|
329 |
free(localtrianglelistuv); |
|
330 |
free(localtrianglelistnormal); |
|
331 |
free(localquadlist); |
|
332 |
free(localquadlistuv); |
|
333 |
free(localquadlistnormal); |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
334 |
} else { |
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
335 |
// Multigon |
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
336 |
printf("Error: Object did not contain any triangles or quads!\n"); |
337 |
} |
|
338 |
||
339 |
fclose(pFile); |
|
340 |
if(!foundobj) { |
|
341 |
printf("Error: Failed to find object %s!\n", openobj); |
|
342 |
} else { |
|
343 |
printf("Msg: Sucessful Parsing of Object %s in File %s\nMsg: %i vertices %i normals %i texture coordinates %i faces (%i triangles %i quads %i polys)\n", openobj, objfilename, vertcount, normalcount, texturecount, facecount, trianglecount, quadcount, polycount); |
|
344 |
} |
|
345 |
||
346 |
} else { |
|
347 |
printf("Error: Failed to open %s!\n", objfilename); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
348 |
} |
349 |
free(buf); |
|
350 |
}
|
|
351 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
352 |
int main(int argc, char** argv) { |
353 |
if(argc < 3) { |
|
354 |
printf("ERROR: not enough arguments. must have LOADFILE and SAVEFILE and if you want to process only a specific object, the name of object to process\n"); |
|
355 |
return 1; |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
356 |
} |
357 |
||
358 |
printf("--------------------------------\n"); |
|
359 |
printf("Loading Wavefront Object file: %s\n", argv[1]); |
|
360 |
printf("--------------------------------\n"); |
|
361 |
||
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
362 |
if(argc > 3) { |
363 |
printf("Msg: Loading Object: %s\n", argv[3]); |
|
364 |
loadobj(argv[1], argv[3], argv[2]); |
|
365 |
} else { |
|
366 |
printf("Msg: Loading all Objects\n"); |
|
367 |
loadobj(argv[1], "ALL", argv[2]); |
|
1
by Henrik G.
First seed of Lenasys ... Needs to be Organized Further |
368 |
} |
369 |
return 0; |
|
4.7.2
by a11patfr at his
Fixed formatting of trunk/ObjConv/objtojson.c. Now conforms to code standard. |
370 |
}
|