| 784 |
|
{ |
| 785 |
|
VNDX my_vlist[4]; |
| 786 |
|
int *vert_map = NULL; |
| 787 |
< |
int *norm_map = NULL; |
| 788 |
< |
int *tex_map = NULL; |
| 787 |
> |
int tex_off = 0; |
| 788 |
> |
int norm_off = 0; |
| 789 |
|
VNDX *vlist = my_vlist; |
| 790 |
|
int vllen = sizeof(my_vlist)/sizeof(VNDX); |
| 791 |
|
int cur_mat = 0; |
| 808 |
|
} |
| 809 |
|
vert_map[i] = addVertex(scdst, v->p[0], v->p[1], v->p[2]); |
| 810 |
|
} |
| 811 |
< |
if (scsrc->ntex > 0) /* map texture coords */ |
| 812 |
< |
tex_map = (int *)emalloc(sizeof(int *)*scsrc->ntex); |
| 813 |
< |
for (i = 0; i < scsrc->ntex; i++) { |
| 814 |
< |
const TexCoord *t = scsrc->tex + i; |
| 815 |
< |
tex_map[i] = addTexture(scdst, t->u, t->v); |
| 811 |
> |
tex_off = scdst->ntex; /* append texture coords */ |
| 812 |
> |
if (scsrc->ntex > 0) { |
| 813 |
> |
scdst->tex = (TexCoord *)erealloc((char *)scdst->tex, |
| 814 |
> |
sizeof(TexCoord)*(tex_off+scsrc->ntex+(CHUNKSIZ-1))); |
| 815 |
> |
memcpy(scdst->tex+tex_off, scsrc->tex, |
| 816 |
> |
sizeof(TexCoord)*scsrc->ntex); |
| 817 |
|
} |
| 818 |
< |
if (scsrc->nnorms > 0) /* map normals */ |
| 819 |
< |
norm_map = (int *)emalloc(sizeof(int *)*scsrc->nnorms); |
| 820 |
< |
for (i = 0; i < scsrc->nnorms; i++) { |
| 821 |
< |
const float *n = scsrc->norm[i]; |
| 822 |
< |
norm_map[i] = addNormal(scdst, n[0], n[1], n[2]); |
| 818 |
> |
norm_off = scdst->nnorms; /* append normals */ |
| 819 |
> |
if (scsrc->nnorms > 0) { |
| 820 |
> |
scdst->norm = (Normal *)erealloc((char *)scdst->norm, |
| 821 |
> |
sizeof(Normal)*(norm_off+scsrc->nnorms+(CHUNKSIZ-1))); |
| 822 |
> |
memcpy(scdst->norm+norm_off, scsrc->norm, |
| 823 |
> |
sizeof(Normal)*scsrc->nnorms); |
| 824 |
|
} |
| 825 |
|
/* add faces */ |
| 826 |
|
scdst->lastgrp = scdst->lastmat = 0; |
| 842 |
|
if (f->v[i].vid >= 0) |
| 843 |
|
vlist[i][0] = vert_map[f->v[i].vid]; |
| 844 |
|
if (f->v[i].tid >= 0) |
| 845 |
< |
vlist[i][1] = tex_map[f->v[i].tid]; |
| 845 |
> |
vlist[i][1] = f->v[i].tid + tex_off; |
| 846 |
|
if (f->v[i].nid >= 0) |
| 847 |
< |
vlist[i][2] = norm_map[f->v[i].nid]; |
| 847 |
> |
vlist[i][2] = f->v[i].nid + norm_off; |
| 848 |
|
} |
| 849 |
|
fcnt += (addFace(scdst, vlist, f->nv) != NULL); |
| 850 |
|
} |
| 851 |
|
/* clean up */ |
| 852 |
|
if (vlist != my_vlist) efree((char *)vlist); |
| 851 |
– |
if (norm_map != NULL) efree((char *)norm_map); |
| 852 |
– |
if (tex_map != NULL) efree((char *)tex_map); |
| 853 |
|
efree((char *)vert_map); |
| 854 |
|
return(fcnt); |
| 855 |
|
} |