forked from drhastings/cameragl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.c
515 lines (457 loc) · 18.1 KB
/
models.c
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include "GLES/gl.h"
#include "EGL/egl.h"
#include "EGL/eglext.h"
#include "models.h"
#define VMCS_RESOURCE(a,b) (b)
/******************************************************************************
Private typedefs, macros and constants
******************************************************************************/
enum {VBO_VERTEX, VBO_NORMAL, VBO_TEXTURE, VBO_MAX};
#define MAX_MATERIALS 4
#define MAX_MATERIAL_NAME 32
typedef struct wavefront_material_s {
GLuint vbo[VBO_MAX];
int numverts;
char name[MAX_MATERIAL_NAME];
GLuint texture;
} WAVEFRONT_MATERIAL_T;
typedef struct wavefront_model_s {
WAVEFRONT_MATERIAL_T material[MAX_MATERIALS];
int num_materials;
GLuint texture;
} WAVEFRONT_MODEL_T;
/******************************************************************************
Static Data
******************************************************************************/
/******************************************************************************
Static Function Declarations
******************************************************************************/
/******************************************************************************
Static Function Definitions
******************************************************************************/
static void create_vbo(GLenum type, GLuint *vbo, int size, void *data)
{
glGenBuffers(1, vbo);
vc_assert(*vbo);
glBindBuffer(type, *vbo);
glBufferData(type, size, data, GL_STATIC_DRAW);
glBindBuffer(type, 0);
}
static void destroy_vbo(GLuint *vbo)
{
glDeleteBuffers(1, vbo);
*vbo = 0;
}
#define MAX_VERTICES 100000
static void *allocbuffer(int size)
{
return malloc(size);
}
static void freebuffer(void *p)
{
free (p);
}
static void centre_and_rescale(float *verts, int numvertices)
{
float cx=0.0f, cy=0.0f, cz=0.0f, scale=0.0f;
float minx=0.0f, miny=0.0f, minz=0.0f;
float maxx=0.0f, maxy=0.0f, maxz=0.0f;
int i;
float *v = verts;
minx = maxx = verts[0];
miny = maxy = verts[1];
minz = maxz = verts[2];
for (i=0; i<numvertices; i++) {
float x = *v++;
float y = *v++;
float z = *v++;
minx = vcos_min(minx, x);
miny = vcos_min(miny, y);
minz = vcos_min(minz, z);
maxx = vcos_max(maxx, x);
maxy = vcos_max(maxy, y);
maxz = vcos_max(maxz, z);
cx += x;
cy += y;
cz += z;
}
cx /= (float)numvertices;
cy /= (float)numvertices;
cz /= (float)numvertices;
scale = 3.0f / (maxx-minx + maxy-miny + maxz-minz);
v = verts;
for (i=0; i<numvertices; i++) {
*v = (*v-cx) * scale; v++;
*v = (*v-cy) * scale; v++;
*v = (*v-cz) * scale; v++;
}
}
static void renormalise(float *verts, int numvertices)
{
int i;
float *v = verts;
for (i=0;i<numvertices; i++) {
float x = v[0];
float y = v[1];
float z = v[2];
float scale = 1.0f/sqrtf(x*x + y*y + z*z);
*v++ = x * scale;
*v++ = y * scale;
*v++ = z * scale;
}
}
static void deindex(float *dst, const float *src, const unsigned short *indexes, GLsizei size, GLsizei count)
{
int i;
for (i=0; i<count; i++) {
int ind = size * (indexes[0]-1);
*dst++ = src[ind + 0];
*dst++ = src[ind + 1];
// todo: optimise - move out of loop
if (size >= 3) *dst++ = src[ind + 2];
indexes += 3;
}
}
int draw_wavefront(MODEL_T m, GLuint texture)
{
int i;
WAVEFRONT_MODEL_T *model = (WAVEFRONT_MODEL_T *)m;
for (i=0; i<model->num_materials; i++) {
WAVEFRONT_MATERIAL_T *mat = model->material + i;
if (mat->texture == -1) continue;
glBindTexture(GL_TEXTURE_2D, mat->texture ? mat->texture:texture);
if (mat->vbo[VBO_VERTEX]) {
glBindBuffer(GL_ARRAY_BUFFER, mat->vbo[VBO_VERTEX]);
glVertexPointer(3, GL_FLOAT, 0, NULL);
}
if (mat->vbo[VBO_NORMAL]) {
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, mat->vbo[VBO_NORMAL]);
glNormalPointer(GL_FLOAT, 0, NULL);
} else {
glDisableClientState(GL_NORMAL_ARRAY);
}
if (mat->vbo[VBO_TEXTURE]) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, mat->vbo[VBO_TEXTURE]);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
} else {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
glDrawArrays(GL_TRIANGLES, 0, mat->numverts);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
return 0;
}
struct wavefront_model_loading_s {
unsigned short material_index[MAX_MATERIALS];
int num_materials;
int numv, numt, numn, numf;
unsigned int data[0];
};
static int load_wavefront_obj(const char *modelname, WAVEFRONT_MODEL_T *model, struct wavefront_model_loading_s *m)
{
char line[256+1];
unsigned short pp[54+1];
FILE *fp;
int i, valid;
float *qv = (float *)m->data;
float *qt = (float *)m->data + 3 * MAX_VERTICES;
float *qn = (float *)m->data + (3+2) * MAX_VERTICES;
unsigned short *qf = (unsigned short *)((float *)m->data + (3+2+3) * MAX_VERTICES);
float *pv = qv, *pt = qt, *pn = qn;
unsigned short *pf = qf;
fp = fopen(modelname, "r");
if (!fp) return -1;
m->num_materials = 0;
m->material_index[0] = 0;
valid = fread(line, 1, sizeof(line)-1, fp);
while (valid > 0) {
char *s, *end = line;
while((end-line < valid) && *end != '\n' && *end != '\r')
end++;
*end++ = 0;
if((end-line < valid) && *end != '\n' && *end != '\r')
*end++ = 0;
s = line;
if (s[strlen(s)-1] == 10) s[strlen(s)-1]=0;
switch (s[0]) {
case '#': break; // comment
case '\r': case '\n': case '\0': break; // blank line
case 'm': vc_assert(strncmp(s, "mtllib", sizeof "mtllib"-1)==0); break;
case 'o': break;
case 'u':
if (sscanf(s, "usemtl %s", /*MAX_MATERIAL_NAME-1, */model->material[m->num_materials].name) == 1) {
if (m->num_materials < MAX_MATERIALS) {
if (m->num_materials > 0 && ((pf-qf)/3 == m->material_index[m->num_materials-1] || strcmp(model->material[m->num_materials-1].name, model->material[m->num_materials].name)==0)) {
strcpy(model->material[m->num_materials-1].name, model->material[m->num_materials].name);
m->num_materials--;
} else
m->material_index[m->num_materials] = (pf-qf)/3;
m->num_materials++;
}
} else { printf(s); vc_assert(0); }
break;
case 'g': vc_assert(strncmp(s, "g ", sizeof "g "-1)==0); break;
case 's': vc_assert(strncmp(s, "s ", sizeof "s "-1)==0); break;
case 'v': case 'f':
if (sscanf(s, "v %f %f %f", pv+0, pv+1, pv+2) == 3) {
pv += 3;
} else if (sscanf(s, "vt %f %f", pt+0, pt+1) == 2) {
pt += 2;
} else if (sscanf(s, "vn %f %f %f", pn+0, pn+1, pn+2) == 3) {
pn += 3;
} else if (i = sscanf(s, "f"" %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu"
" %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu"
" %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu//%hu %hu",
pp+ 0, pp+ 1, pp+ 2, pp+ 3, pp+ 4, pp+ 5, pp+ 6, pp+ 7, pp+ 8, pp+ 9, pp+10, pp+11,
pp+12, pp+13, pp+14, pp+15, pp+16, pp+17, pp+18, pp+19, pp+20, pp+21, pp+22, pp+23,
pp+24, pp+25, pp+26, pp+27, pp+28, pp+29, pp+30, pp+32, pp+32, pp+33, pp+34, pp+35, pp+36), i >= 6) {
int poly = i/2;
//vc_assert(i < countof(pp)); // may need to increment poly count and pp array
for (i=1; i<poly-1; i++) {
*pf++ = pp[0]; *pf++ = 0; *pf++ = pp[1];
*pf++ = pp[2*i+0]; *pf++ = 0; *pf++ = pp[2*i+1];
*pf++ = pp[2*(i+1)+0]; *pf++ = 0; *pf++ = pp[2*(i+1)+1];
}
} else if (i = sscanf(s, "f"" %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu"
" %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu"
" %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu/%hu %hu",
pp+ 0, pp+ 1, pp+ 2, pp+ 3, pp+ 4, pp+ 5, pp+ 6, pp+ 7, pp+ 8, pp+ 9, pp+10, pp+11,
pp+12, pp+13, pp+14, pp+15, pp+16, pp+17, pp+18, pp+19, pp+20, pp+21, pp+22, pp+23,
pp+24, pp+25, pp+26, pp+27, pp+28, pp+29, pp+30, pp+32, pp+32, pp+33, pp+34, pp+35, pp+36), i >= 6) {
int poly = i/2;
//vc_assert(i < countof(pp); // may need to increment poly count and pp array
for (i=1; i<poly-1; i++) {
*pf++ = pp[0]; *pf++ = pp[1]; *pf++ = 0;
*pf++ = pp[2*i+0]; *pf++ = pp[2*i+1]; *pf++ = 0;
*pf++ = pp[2*(i+1)+0]; *pf++ = pp[2*(i+1)+1]; *pf++ = 0;
}
} else if (i = sscanf(s, "f"" %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu"
" %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu"
" %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu/%hu/%hu %hu",
pp+ 0, pp+ 1, pp+ 2, pp+ 3, pp+ 4, pp+ 5, pp+ 6, pp+ 7, pp+ 8, pp+ 9, pp+10, pp+11, pp+12, pp+13, pp+14, pp+15, pp+16, pp+17,
pp+18, pp+19, pp+20, pp+21, pp+22, pp+23, pp+24, pp+25, pp+26, pp+27, pp+28, pp+29, pp+30, pp+32, pp+32, pp+33, pp+34, pp+35,
pp+36, pp+37, pp+38, pp+39, pp+40, pp+41, pp+42, pp+43, pp+44, pp+45, pp+46, pp+47, pp+48, pp+49, pp+50, pp+51, pp+52, pp+53, pp+54), i >= 9) {
int poly = i/3;
//vc_assert(i < countof(pp); // may need to increment poly count and pp array
for (i=1; i<poly-1; i++) {
*pf++ = pp[0]; *pf++ = pp[1]; *pf++ = pp[2];
*pf++ = pp[3*i+0]; *pf++ = pp[3*i+1]; *pf++ = pp[3*i+2];
*pf++ = pp[3*(i+1)+0]; *pf++ = pp[3*(i+1)+1]; *pf++ = pp[3*(i+1)+2];
}
} else { printf(s); vc_assert(0); }
break;
default:
printf("%02x %02x %s", s[0], s[1], s); vc_assert(0); break;
}
// shift down read characters and read some more into the end
// if we didn't find a newline, then end is one off the end of our
// line, so end-line will be valid+1
i = end-line > valid ? valid : end-line;
memmove(line, end, valid - i);
valid -= i;
valid += fread(line+valid, 1, sizeof(line)-1-valid, fp);
}
fclose(fp);
if (m->num_materials==0) m->material_index[m->num_materials++] = 0;
centre_and_rescale(qv, (pv-qv)/3);
renormalise(qn, (pn-qn)/3);
//centre_and_rescale2(qt, (pt-qt)/2);
m->numv = pv-qv;
m->numt = pt-qt;
m->numn = pn-qn;
m->numf = pf-qf;
// compress array
//memcpy((float *)m->data, (float *)m->data, m->numv * sizeof *qv); - nop
memcpy((float *)m->data + m->numv, (float *)m->data + 3 * MAX_VERTICES, m->numt * sizeof *qt);
memcpy((float *)m->data + m->numv + m->numt,(float *) m->data + (3 + 2) * MAX_VERTICES, m->numn * sizeof *qn);
memcpy((float *)m->data + m->numv + m->numt + m->numn, (float *)m->data + (3 + 2 + 3) * MAX_VERTICES, m->numf * sizeof *qf);
return 0;
}
static int load_wavefront_dat(const char *modelname, WAVEFRONT_MODEL_T *model, struct wavefront_model_loading_s *m)
{
FILE *fp;
int s;
const int size = sizeof *m +
sizeof(float)*(3+2+3)*MAX_VERTICES + // 3 vertices + 2 textures + 3 normals
sizeof(unsigned short)*3*MAX_VERTICES; //each face has 9 vertices
fp = fopen(modelname, "r");
if (!fp) return -1;
s = fread(m, 1, size, fp);
if (s < 0) return -1;
fclose(fp);
return 0;
}
MODEL_T load_wavefront(const char *modelname, const char *texturename)
{
WAVEFRONT_MODEL_T *model;
float *temp, *qv, *qt, *qn;
unsigned short *qf;
int i;
int numverts = 0, offset = 0;
struct wavefront_model_loading_s *m;
int s=-1;
char modelname_obj[128];
model = malloc(sizeof *model);
if (!model || !modelname) return NULL;
memset (model, 0, sizeof *model);
model->texture = 0; //load_texture(texturename);
m = allocbuffer(sizeof *m +
sizeof(float)*(3+2+3)*MAX_VERTICES + // 3 vertices + 2 textures + 3 normals
sizeof(unsigned short)*3*MAX_VERTICES); //each face has 9 vertices
if (!m) return 0;
if (strlen(modelname) + 5 <= sizeof modelname_obj) {
strcpy(modelname_obj, modelname);
strcat(modelname_obj, ".dat");
s = load_wavefront_dat(modelname_obj, model, m);
}
if (s==0) {}
else if (strncmp(modelname + strlen(modelname) - 4, ".obj", 4) == 0) {
#ifdef DUMP_OBJ_DAT
int size;
FILE *fp;
#endif
s = load_wavefront_obj(modelname, model, m);
#ifdef DUMP_OBJ_DAT
strcpy(modelname_obj, modelname);
strcat(modelname_obj, ".dat");
size = sizeof *m +
sizeof(float)*(3*m->numv+2*m->numt+3*m->numn) + // 3 vertices + 2 textures + 3 normals
sizeof(unsigned short)*3*m->numf; //each face has 9 vertices
fp = host_file_open(modelname_obj, "w");
fwrite(m, 1, size, fp);
fclose(fp);
#endif
} else if (strncmp(modelname + strlen(modelname) - 4, ".dat", 4) == 0) {
s = load_wavefront_dat(modelname, model, m);
}
if (s != 0) return 0;
qv = (float *)(m->data);
qt = (float *)(m->data + m->numv);
qn = (float *)(m->data + m->numv + m->numt);
qf = (unsigned short *)(m->data + m->numv + m->numt + m->numn);
numverts = m->numf/3;
vc_assert(numverts <= MAX_VERTICES);
temp = allocbuffer(3*numverts*sizeof *temp);
for (i=0; i<m->num_materials; i++) {
WAVEFRONT_MATERIAL_T *mat = model->material + i;
mat->numverts = i < m->num_materials-1 ? m->material_index[i+1]-m->material_index[i] : numverts - m->material_index[i];
// vertex, texture, normal
deindex(temp, qv, qf+3*offset+0, 3, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_VERTEX, 3 * mat->numverts * sizeof *qv, temp); // 3
deindex(temp, qt, qf+3*offset+1, 2, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_TEXTURE, 2 * mat->numverts * sizeof *qt, temp); // 2
deindex(temp, qn, qf+3*offset+2, 3, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_NORMAL, 3 * mat->numverts * sizeof *qn, temp); // 3
offset += mat->numverts;
mat->texture = model->texture;
}
model->num_materials = m->num_materials;
vc_assert(offset == numverts);
freebuffer(temp);
freebuffer(m);
return (MODEL_T)model;
}
void unload_wavefront(MODEL_T m)
{
WAVEFRONT_MODEL_T *model = (WAVEFRONT_MODEL_T *)m;
int i;
for (i=0; i<model->num_materials; i++) {
WAVEFRONT_MATERIAL_T *mat = model->material + i;
if (mat->vbo[VBO_VERTEX])
destroy_vbo(mat->vbo+VBO_VERTEX);
if (mat->vbo[VBO_TEXTURE])
destroy_vbo(mat->vbo+VBO_TEXTURE);
if (mat->vbo[VBO_NORMAL])
destroy_vbo(mat->vbo+VBO_NORMAL);
}
}
// create a cube model that looks like a wavefront model,
MODEL_T cube_wavefront(void)
{
static const float qv[] = {
-0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
};
static const float qn[] = {
0.0f, -1.0f, -0.0f,
0.0f, 1.0f, -0.0f,
0.0f, 0.0f, 1.0f,
1.0f, 0.0f, -0.0f,
0.0f, 0.0f, -1.0f,
-1.0f, 0.0f, -0.0f,
};
static const float qt[] = {
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
};
static const unsigned short qf[] = {
1,1,1, 2,2,1, 3,3,1,
3,3,1, 4,4,1, 1,1,1,
5,4,2, 6,1,2, 7,2,2,
7,2,2, 8,3,2, 5,4,2,
1,4,3, 4,1,3, 6,2,3,
6,2,3, 5,3,3, 1,4,3,
4,4,4, 3,1,4, 7,2,4,
7,2,4, 6,3,4, 4,4,4,
3,4,5, 2,1,5, 8,2,5,
8,2,5, 7,3,5, 3,4,5,
2,4,6, 1,1,6, 5,2,6,
5,2,6, 8,3,6, 2,4,6,
};
WAVEFRONT_MODEL_T *model = malloc(sizeof *model);
if (model) {
WAVEFRONT_MATERIAL_T *mat = model->material;
float *temp;
const int offset = 0;
memset(model, 0, sizeof *model);
temp = allocbuffer(3*MAX_VERTICES*sizeof *temp);
mat->numverts = countof(qf)/3;
// vertex, texture, normal
deindex(temp, qv, qf+3*offset+0, 3, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_VERTEX, 3 * mat->numverts * sizeof *qv, temp); // 3
deindex(temp, qt, qf+3*offset+1, 2, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_TEXTURE, 2 * mat->numverts * sizeof *qt, temp); // 2
deindex(temp, qn, qf+3*offset+2, 3, mat->numverts);
create_vbo(GL_ARRAY_BUFFER, mat->vbo+VBO_NORMAL, 3 * mat->numverts * sizeof *qn, temp); // 3
freebuffer(temp);
model->num_materials = 1;
}
return (MODEL_T)model;
}