/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1

« back to all changes in this revision

Viewing changes to trunk/ObjConv/objtojson.c

  • Committer: a11patfr at his
  • Date: 2013-03-28 14:32:10 UTC
  • mto: (4.7.6 GammaBear)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: a11patfr@student.his.se-20130328143210-ung7pp2n0fcxmc3r
Fixed the last indents

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
                readpos++;
19
19
 
20
20
                // -1 to compensate for wavefront file starting on 1 and not 0
21
 
                if (i == 0){
 
21
                if(i == 0) {
22
22
                        varray[position] = atoi(workstr) - 1;
23
23
                } else if((i == 1) && (hasuv > 0)) {
24
24
                        tarray[position] = atoi(workstr) - 1;
55
55
        float *normallist;
56
56
        int *trianglelist;
57
57
        int *quadlist;
58
 
        char *resultp1,*resultp2,*resultp3,*resultp4,*resultp5;
 
58
        char *resultp1, *resultp2, *resultp3, *resultp4, *resultp5;
59
59
 
60
60
        if(pFile) {
61
61
                printf("Msg: Success opening: %s!\n", objfilename);
63
63
                        if(buf[0] == '#') {
64
64
                                // Comment - Do Nothing
65
65
                        } else {
66
 
                                result=strtok(buf," \n\t");
67
 
                                if(result!=NULL) {
68
 
                                        if(strcmp(result, "v") ==0) {
 
66
                                result = strtok(buf, " \n\t");
 
67
                                if(result != NULL) {
 
68
                                        if(strcmp(result, "v") == 0) {
69
69
                                                if(foundobj) {
70
70
                                                        //Increase vertex counter
71
71
                                                        vertcount++;
72
72
                                                }
73
 
                                        } else if(strcmp(result, "vt") ==0) {
 
73
                                        } else if(strcmp(result, "vt") == 0) {
74
74
                                                if(foundobj) {
75
75
                                                        // Increase texture coordinate counter
76
76
                                                        texturecount++;
77
77
                                                }
78
 
                                        } else if(strcmp(result, "vn") ==0) {
 
78
                                        } else if(strcmp(result, "vn") == 0) {
79
79
                                                if(foundobj) {
80
80
                                                        // Increase normal counter
81
81
                                                        normalcount++;
82
82
                                                }
83
 
                                        } else if(strcmp(result, "f") ==0) {
 
83
                                        } else if(strcmp(result, "f") == 0) {
84
84
                                                if(foundobj) {
85
85
                                                        // Increase face counter
86
86
                                                        facecount++;
119
119
                if(((trianglecount + quadcount) > 0)) {
120
120
                        // Set foundobj to true if we are loading all objects
121
121
                        if(strcmp(openobj, "ALL")) {
122
 
                                foundobj=1;
 
122
                                foundobj = 1;
123
123
                        }
124
124
 
125
125
                        // Seek to beginning again
126
126
                        fseek(pFile, 0, SEEK_SET);
127
127
 
128
128
                        // Allocate local buffers
129
 
                        float *localvertexlist =(float *) malloc (sizeof(float) * vertcount * 3);
130
 
                        float *localnormallist =(float *) malloc (sizeof(float) * normalcount * 3);
 
129
                        float *localvertexlist = (float *) malloc (sizeof(float) * vertcount * 3);
 
130
                        float *localnormallist = (float *) malloc (sizeof(float) * normalcount * 3);
131
131
                        float *localuvlist = (float *) malloc (sizeof(float) * texturecount * 2);
132
132
                        int *localquadlist = (int *) malloc (sizeof(int) * quadcount * 4);
133
133
                        int *localquadlistuv = (int *) malloc (sizeof(int) * quadcount * 4);
137
137
                        int *localtrianglelistnormal = (int *) malloc (sizeof(int) * trianglecount * 3);
138
138
 
139
139
                        // Reset counters for second pass
140
 
                        trianglecount=0;
141
 
                        quadcount=0;
142
 
                        normalcount=0;
143
 
                        vertcount=0;
144
 
                        texturecount=0;
 
140
                        trianglecount = 0;
 
141
                        quadcount = 0;
 
142
                        normalcount = 0;
 
143
                        vertcount = 0;
 
144
                        texturecount = 0;
145
145
 
146
146
                        while(fgets(buf, 1024, pFile) != NULL) {
147
147
                                if(buf[0] == '#') {
149
149
                                } else {
150
150
                                        result = strtok(buf, " \n\t");
151
151
                                        if(result != NULL) {
152
 
                                                if(strcmp(result, "v") ==0) {
 
152
                                                if(strcmp(result, "v") == 0) {
153
153
                                                        if(foundobj) {
154
154
                                                                result = strtok(NULL, " \n\t");
155
155
                                                                localvertexlist[(vertcount * 3)] = atof(result);
159
159
                                                                localvertexlist[(vertcount * 3) + 2] = atof(result);
160
160
                                                                vertcount++;
161
161
                                                        }
162
 
                                                } else if(strcmp(result, "vt") ==0) {
 
162
                                                } else if(strcmp(result, "vt") == 0) {
163
163
                                                        if(foundobj) {
164
164
                                                                result = strtok(NULL, " \n\t");
165
165
                                                                localuvlist[(texturecount * 2)] = atof(result);
167
167
                                                                localuvlist[(texturecount * 2) + 1] = atof(result);
168
168
                                                                texturecount++;
169
169
                                                        }
170
 
                                                } else if(strcmp(result, "vn") ==0) {
 
170
                                                } else if(strcmp(result, "vn") == 0) {
171
171
                                                        if(foundobj) {
172
172
                                                                result = strtok(NULL, " \n\t");
173
173
                                                                localnormallist[(normalcount * 3)] = atof(result);
177
177
                                                                localnormallist[(normalcount * 3) + 2] = atof(result);
178
178
                                                                normalcount++;
179
179
                                                        }
180
 
                                                } else if(strcmp(result, "f") ==0) {
 
180
                                                } else if(strcmp(result, "f") == 0) {
181
181
                                                        if(foundobj) {
182
182
                                                                resultp1 = strtok(NULL, " \n\t");
183
183
                                                                resultp2 = strtok(NULL, " \n\t");
202
202
                                                } else if(strcmp(result, "g") == 0) {
203
203
                                                        if(result = strtok(NULL, " \n\t")) {
204
204
                                                                if(!strcmp(openobj, result)) {
205
 
                                                                        foundobj=1;
 
205
                                                                        foundobj = 1;
206
206
                                                                }
207
207
                                                        }
208
208
                                                }
209
209
                                        }
210
210
                                }
211
211
                        }
212
 
                        int i=0;
 
212
                        int i = 0;
213
213
                        // Allocate buffers
214
214
                        vertexlist = (float *) malloc (sizeof(float) * vertcount * 3);
215
215
                        normallist = (float *) malloc (sizeof(float) * vertcount * 3);