diff options
author | Martin Poirier <theeth@yahoo.com> | 2005-07-11 14:48:14 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2005-07-11 14:48:14 +0400 |
commit | 54cd0cf56dde84df9e8e1d1c473002873698e61e (patch) | |
tree | 46a3614877288b41aa14e15425c4b2f0121a2fd9 /source/blender/radiosity/intern | |
parent | 9cb84a662e0492565ec65770753d421911494c32 (diff) |
This commit fixes radiosity to correctly preserve and subdivide UV
coordinates.
Known problem: Pin status bleeds a bit, so new subdivided UVs around
points that were original pinned can end up pinned in the end. Could be
fixed, or could just drop pinned status entirely.
Also, when gathering meshes, it doesn't add materials twice, so it's harder to bust the 16 materials limit.
Diffstat (limited to 'source/blender/radiosity/intern')
-rw-r--r-- | source/blender/radiosity/intern/source/radnode.c | 24 | ||||
-rw-r--r-- | source/blender/radiosity/intern/source/radpostprocess.c | 363 | ||||
-rw-r--r-- | source/blender/radiosity/intern/source/radpreprocess.c | 66 |
3 files changed, 347 insertions, 106 deletions
diff --git a/source/blender/radiosity/intern/source/radnode.c b/source/blender/radiosity/intern/source/radnode.c index 844973e4d1f..d96649af30e 100644 --- a/source/blender/radiosity/intern/source/radnode.c +++ b/source/blender/radiosity/intern/source/radnode.c @@ -585,7 +585,7 @@ void subdivideTriNode(RNode *node, RNode *edge) } } - /* the subsidiving */ + /* the subdividing */ n1= mallocNode(); memcpy(n1, node, sizeof(RNode)); n2= mallocNode(); @@ -632,6 +632,9 @@ void subdivideTriNode(RNode *node, RNode *edge) n1->v1[2]= 0.5*(node->v1[2]+ node->v2[2]); n1->v1[3]= node->v1[3]; /* color */ } + /* UVs */ + n1->uv[0][0] = n2->uv[1][0] = 0.5*(node->uv[0][0]+ node->uv[1][0]); + n1->uv[0][1] = n2->uv[1][1] = 0.5*(node->uv[0][1]+ node->uv[1][1]); } else if(uvl==2) { @@ -667,6 +670,9 @@ void subdivideTriNode(RNode *node, RNode *edge) n1->v3[2]= 0.5*(node->v2[2]+ node->v3[2]); n1->v3[3]= node->v1[3]; /* color */ } + /* UVs */ + n1->uv[2][0] = n2->uv[1][0] = 0.5*(node->uv[1][0]+ node->uv[2][0]); + n1->uv[2][1] = n2->uv[1][1] = 0.5*(node->uv[1][1]+ node->uv[2][1]); } else if(uvl==3) { @@ -702,6 +708,9 @@ void subdivideTriNode(RNode *node, RNode *edge) n1->v3[2]= 0.5*(node->v1[2]+ node->v3[2]); n1->v3[3]= node->v3[3]; /* color */ } + /* UVs */ + n1->uv[2][0] = n2->uv[0][0] = 0.5*(node->uv[0][0]+ node->uv[2][0]); + n1->uv[2][1] = n2->uv[0][1] = 0.5*(node->uv[0][1]+ node->uv[2][1]); } n1->area= AreaT3Dfl(n1->v1, n1->v2, n1->v3); n2->area= AreaT3Dfl(n2->v1, n2->v2, n2->v3); @@ -828,6 +837,9 @@ void subdivideNode(RNode *node, RNode *edge) n1->v1[2]= 0.5*(node->v1[2]+ node->v2[2]); n1->v1[3]= node->v1[3]; /* color */ } + /* UVs */ + n1->uv[0][0] = n2->uv[1][0] = 0.5*(node->uv[0][0]+ node->uv[1][0]); + n1->uv[0][1] = n2->uv[1][1] = 0.5*(node->uv[0][1]+ node->uv[1][1]); /* NEW VERTEX from edge 3 */ if( setvertexpointersNode(n1->ed3, n1, n1->lev3, &v1, &v2) ) { /* nodes have equal levels */ @@ -847,6 +859,9 @@ void subdivideNode(RNode *node, RNode *edge) n1->v4[2]= 0.5*(node->v3[2]+ node->v4[2]); n1->v4[3]= node->v4[3]; /* color */ } + /* UVs */ + n1->uv[3][0] = n2->uv[2][0] = 0.5*(node->uv[2][0]+ node->uv[3][0]); + n1->uv[3][1] = n2->uv[2][1] = 0.5*(node->uv[2][1]+ node->uv[3][1]); } /* subdivide edge 2 and 4 */ else if(uvl==2) { @@ -887,6 +902,9 @@ void subdivideNode(RNode *node, RNode *edge) n1->v3[2]= 0.5*(node->v2[2]+ node->v3[2]); n1->v3[3]= node->v3[3]; /* color */ } + /* UVs */ + n1->uv[2][0] = n2->uv[1][0] = 0.5*(node->uv[1][0]+ node->uv[2][0]); + n1->uv[2][1] = n2->uv[1][1] = 0.5*(node->uv[1][1]+ node->uv[2][1]); /* NEW VERTEX from edge 4 */ if( setvertexpointersNode(n1->ed4, n1, n1->lev4, &v1, &v2) ) { /* nodes have equal levels */ @@ -906,7 +924,9 @@ void subdivideNode(RNode *node, RNode *edge) n1->v4[2]= 0.5*(node->v1[2]+ node->v4[2]); n1->v4[3]= node->v4[3]; /* color */ } - + /* UVs */ + n1->uv[3][0] = n2->uv[0][0] = 0.5*(node->uv[0][0]+ node->uv[3][0]); + n1->uv[3][1] = n2->uv[0][1] = 0.5*(node->uv[0][1]+ node->uv[3][1]); } n1->area= AreaQ3Dfl(n1->v1, n1->v2, n1->v3, n1->v4); diff --git a/source/blender/radiosity/intern/source/radpostprocess.c b/source/blender/radiosity/intern/source/radpostprocess.c index 45805dcc541..e0b42c6b775 100644 --- a/source/blender/radiosity/intern/source/radpostprocess.c +++ b/source/blender/radiosity/intern/source/radpostprocess.c @@ -171,7 +171,18 @@ Face *addface() } -void makeface(float *v1, float *v2, float *v3, float *v4, RNode *rn) +#define HALFUV(uv, uv1, uv2) {uv[0] = 0.5 * (uv1[0] + uv2[0]); uv[1] = 0.5 * (uv1[1] + uv2[1]);} +#define COPYUV(dst, src) {dst[0] = src[0]; dst[1] = src[1];} + +void dofaceuv(Face *face, float uvs[8][2], short flag1, short flag2, short flag3, short flag4) +{ + COPYUV(face->uv[0], uvs[flag1]); + COPYUV(face->uv[1], uvs[flag2]); + COPYUV(face->uv[2], uvs[flag3]); + COPYUV(face->uv[3], uvs[flag4]); +} + +Face * makeface(float *v1, float *v2, float *v3, float *v4, RNode *rn, short hasUV) { Face *face; @@ -182,140 +193,305 @@ void makeface(float *v1, float *v2, float *v3, float *v4, RNode *rn) face->v4= v4; face->col= rn->col; face->matindex= rn->par->matindex; -} + face->tface = rn->tface; + + if (hasUV) + memcpy(face->uv, rn->uv, sizeof(float) * 4 * 2); + return face; +} void anchorQuadface(RNode *rn, float *v1, float *v2, float *v3, float *v4, int flag) { + Face *face; + float uvs[8][2]; + + memcpy(uvs, rn->uv, sizeof(float) * 4 * 2); + HALFUV(uvs[4], rn->uv[0], rn->uv[1]); + HALFUV(uvs[5], rn->uv[1], rn->uv[2]); + HALFUV(uvs[6], rn->uv[2], rn->uv[3]); + HALFUV(uvs[7], rn->uv[3], rn->uv[0]); switch(flag) { case 1: - makeface(rn->v1, v1, rn->v4, 0, rn); - makeface(v1, rn->v3, rn->v4, 0, rn); - makeface(v1, rn->v2, rn->v3, 0, rn); + face = makeface(rn->v1, v1, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 0, 4, 3, 0); + + face = makeface(v1, rn->v3, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 4, 2, 3, 0); + + face = makeface(v1, rn->v2, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 2, 0); + break; case 2: - makeface(rn->v2, v2, rn->v1, 0, rn); - makeface(v2, rn->v4, rn->v1, 0, rn); - makeface(v2, rn->v3, rn->v4, 0, rn); + face = makeface(rn->v2, v2, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 1, 5, 0, 0); + + face = makeface(v2, rn->v4, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 5, 3, 0, 0); + + face = makeface(v2, rn->v3, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 3, 0); + break; case 4: - makeface(rn->v3, v3, rn->v2, 0, rn); - makeface(v3, rn->v1, rn->v2, 0, rn); - makeface(v3, rn->v4, rn->v1, 0, rn); + face = makeface(rn->v3, v3, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 2, 6, 1, 0); + + face = makeface(v3, rn->v1, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 6, 0, 1, 0); + + face = makeface(v3, rn->v4, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 0, 0); + break; case 8: - makeface(rn->v4, v4, rn->v3, 0, rn); - makeface(v4, rn->v2, rn->v3, 0, rn); - makeface(v4, rn->v1, rn->v2, 0, rn); + face = makeface(rn->v4, v4, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 3, 7, 2, 0); + + face = makeface(v4, rn->v2, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 7, 1, 2, 0); + + face = makeface(v4, rn->v1, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 1, 0); + break; case 3: - makeface(rn->v1, v1, rn->v4, 0, rn); - makeface(v1, v2, rn->v4, 0, rn); - makeface(v1, rn->v2, v2, 0, rn); - makeface(v2, rn->v3, rn->v4, 0, rn); + face = makeface(rn->v1, v1, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 0, 4, 3, 0); + + face = makeface(v1, v2, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 4, 5, 3, 0); + + face = makeface(v1, rn->v2, v2, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 5, 0); + + face = makeface(v2, rn->v3, rn->v4, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 3, 0); + break; case 6: - makeface(rn->v2, v2, rn->v1, 0, rn); - makeface(v2, v3, rn->v1, 0, rn); - makeface(v2, rn->v3, v3, 0, rn); - makeface(v3, rn->v4, rn->v1, 0, rn); + face = makeface(rn->v2, v2, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 1, 5, 0, 0); + + face = makeface(v2, v3, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 5, 6, 0, 0); + + face = makeface(v2, rn->v3, v3, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 6, 0); + + face = makeface(v3, rn->v4, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 0, 0); + break; case 12: - makeface(rn->v3, v3, rn->v2, 0, rn); - makeface(v3, v4, rn->v2, 0, rn); - makeface(v3, rn->v4, v4, 0, rn); - makeface(v4, rn->v1, rn->v2, 0, rn); + face = makeface(rn->v3, v3, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 2, 6, 1, 0); + + face = makeface(v3, v4, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 6, 7, 1, 0); + + face = makeface(v3, rn->v4, v4, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 7, 0); + + face = makeface(v4, rn->v1, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 1, 0); + break; case 9: - makeface(rn->v4, v4, rn->v3, 0, rn); - makeface(v4, v1, rn->v3, 0, rn); - makeface(v4, rn->v1, v1, 0, rn); - makeface(v1, rn->v2, rn->v3, 0, rn); + face = makeface(rn->v4, v4, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 3, 7, 2, 0); + + face = makeface(v4, v1, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 7, 4, 2, 0); + + face = makeface(v4, rn->v1, v1, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 4, 0); + + face = makeface(v1, rn->v2, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 2, 0); + break; case 5: - makeface(rn->v1, v1, v3, rn->v4, rn); - makeface(v1, rn->v2, rn->v3, v3, rn); + face = makeface(rn->v1, v1, v3, rn->v4, rn, 0); + dofaceuv(face, uvs, 0, 4, 6, 3); + + face = makeface(v1, rn->v2, rn->v3, v3, rn, 0); + dofaceuv(face, uvs, 4, 1, 2, 6); + break; case 10: - makeface(rn->v2, v2, v4, rn->v1, rn); - makeface(v2, rn->v3, rn->v4, v4, rn); + face = makeface(rn->v1, rn->v2, v2, v4, rn, 0); + dofaceuv(face, uvs, 0, 1, 5, 7); + + face = makeface(v4, v2, rn->v3, rn->v4, rn, 0); + dofaceuv(face, uvs, 7, 5, 2, 3); + break; case 7: - makeface(rn->v1, v1, v3, rn->v4, rn); - makeface(v1, v2, v3, 0, rn); - makeface(v1, rn->v2, v2, 0, rn); - makeface(v2, rn->v3, v3, 0, rn); + face = makeface(rn->v1, v1, v3, rn->v4, rn, 0); + dofaceuv(face, uvs, 0, 4, 6, 3); + + face = makeface(v1, v2, v3, NULL, rn, 0); + dofaceuv(face, uvs, 4, 5, 6, 0); + + face = makeface(v1, rn->v2, v2, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 5, 0); + + face = makeface(v2, rn->v3, v3, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 6, 0); + break; case 14: - makeface(rn->v2, v2, v4, rn->v1, rn); - makeface(v2, v3, v4, 0, rn); - makeface(v2, rn->v3, v3, 0, rn); - makeface(v3, rn->v4, v4, 0, rn); + face = makeface(rn->v2, v2, v4, rn->v1, rn, 0); + dofaceuv(face, uvs, 1, 5, 7, 0); + + face = makeface(v2, v3, v4, NULL, rn, 0); + dofaceuv(face, uvs, 5, 6, 7, 0); + + face = makeface(v2, rn->v3, v3, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 6, 0); + + face = makeface(v3, rn->v4, v4, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 7, 0); + break; case 13: - makeface(rn->v3, v3, v1, rn->v2, rn); - makeface(v3, v4, v1, 0, rn); - makeface(v3, rn->v4, v4, 0, rn); - makeface(v4, rn->v1, v1, 0, rn); + face = makeface(rn->v3, v3, v1, rn->v2, rn, 0); + dofaceuv(face, uvs, 2, 6, 4, 1); + + face = makeface(v3, v4, v1, NULL, rn, 0); + dofaceuv(face, uvs, 6, 7, 4, 0); + + face = makeface(v3, rn->v4, v4, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 7, 0); + + face = makeface(v4, rn->v1, v1, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 4, 0); + break; case 11: - makeface(rn->v4, v4, v2, rn->v3, rn); - makeface(v4, v1, v2, 0, rn); - makeface(v4, rn->v1, v1, 0, rn); - makeface(v1, rn->v2, v2, 0, rn); + face = makeface(rn->v4, v4, v2, rn->v3, rn, 0); + dofaceuv(face, uvs, 3, 7, 5, 2); + + face = makeface(v4, v1, v2, NULL, rn, 0); + dofaceuv(face, uvs, 7, 4, 5, 0); + + face = makeface(v4, rn->v1, v1, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 4, 0); + + face = makeface(v1, rn->v2, v2, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 5, 0); + break; case 15: - makeface(v1, v2, v3, v4, rn); - makeface(v1, rn->v2, v2, 0, rn); - makeface(v2, rn->v3, v3, 0, rn); - makeface(v3, rn->v4, v4, 0, rn); - makeface(v4, rn->v1, v1, 0, rn); + face = makeface(v1, v2, v3, v4, rn, 0); + dofaceuv(face, uvs, 4, 5, 6, 7); + + face = makeface(v1, rn->v2, v2, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 5, 0); + + face = makeface(v2, rn->v3, v3, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 6, 0); + + face = makeface(v3, rn->v4, v4, NULL, rn, 0); + dofaceuv(face, uvs, 6, 3, 7, 0); + + face = makeface(v4, rn->v1, v1, NULL, rn, 0); + dofaceuv(face, uvs, 7, 0, 4, 0); + break; } } void anchorTriface(RNode *rn, float *v1, float *v2, float *v3, int flag) { + Face *face; + float uvs[8][2]; + + memcpy(uvs, rn->uv, sizeof(float) * 4 * 2); + HALFUV(uvs[4], rn->uv[0], rn->uv[1]); + HALFUV(uvs[5], rn->uv[1], rn->uv[2]); + HALFUV(uvs[6], rn->uv[2], rn->uv[0]); + switch(flag) { case 1: - makeface(rn->v1, v1, rn->v3, 0, rn); - makeface(v1, rn->v2, rn->v3, 0, rn); + face = makeface(rn->v1, v1, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 0, 4, 2, 0); + + face = makeface(v1, rn->v2, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 2, 0); + break; case 2: - makeface(rn->v2, v2, rn->v1, 0, rn); - makeface(v2, rn->v3, rn->v1, 0, rn); + face = makeface(rn->v2, v2, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 1, 5, 0, 0); + + face = makeface(v2, rn->v3, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 0, 0); + break; case 4: - makeface(rn->v3, v3, rn->v2, 0, rn); - makeface(v3, rn->v1, rn->v2, 0, rn); + face = makeface(rn->v3, v3, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 2, 6, 1, 0); + + face = makeface(v3, rn->v1, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 6, 0, 1, 0); + break; case 3: - makeface(rn->v1, v2, rn->v3, 0, rn); - makeface(rn->v1, v1, v2, 0, rn); - makeface(v1, rn->v2, v2, 0, rn); + face = makeface(rn->v1, v2, rn->v3, NULL, rn, 0); + dofaceuv(face, uvs, 0, 5, 2, 0); + + face = makeface(rn->v1, v1, v2, NULL, rn, 0); + dofaceuv(face, uvs, 0, 4, 5, 0); + + face = makeface(v1, rn->v2, v2, NULL, rn, 0); + dofaceuv(face, uvs, 4, 1, 5, 0); + break; case 6: - makeface(rn->v2, v3, rn->v1, 0, rn); - makeface(rn->v2, v2, v3, 0, rn); - makeface(v2, rn->v3, v3, 0, rn); + face = makeface(rn->v2, v3, rn->v1, NULL, rn, 0); + dofaceuv(face, uvs, 1, 6, 0, 0); + + face = makeface(rn->v2, v2, v3, NULL, rn, 0); + dofaceuv(face, uvs, 1, 5, 6, 0); + + face = makeface(v2, rn->v3, v3, NULL, rn, 0); + dofaceuv(face, uvs, 5, 2, 6, 0); + break; case 5: - makeface(rn->v3, v1, rn->v2, 0, rn); - makeface(rn->v3, v3, v1, 0, rn); - makeface(v3, rn->v1, v1, 0, rn); + face = makeface(rn->v3, v1, rn->v2, NULL, rn, 0); + dofaceuv(face, uvs, 2, 4, 1, 0); + + face = makeface(rn->v3, v3, v1, NULL, rn, 0); + dofaceuv(face, uvs, 2, 6, 4, 0); + + face = makeface(v3, rn->v1, v1, NULL, rn, 0); + dofaceuv(face, uvs, 6, 0, 4, 0); + break; case 7: - makeface(v1, v2, v3, 0, rn); - makeface(rn->v1, v1, v3, 0, rn); - makeface(rn->v2, v2, v1, 0, rn); - makeface(rn->v3, v3, v2, 0, rn); + face = makeface(v1, v2, v3, NULL, rn, 0); + dofaceuv(face, uvs, 4, 5, 6, 0); + + face = makeface(rn->v1, v1, v3, NULL, rn, 0); + dofaceuv(face, uvs, 0, 4, 6, 0); + + face = makeface(rn->v2, v2, v1, NULL, rn, 0); + dofaceuv(face, uvs, 1, 5, 4, 0); + + face = makeface(rn->v3, v3, v2, NULL, rn, 0); + dofaceuv(face, uvs, 2, 6, 5, 0); + break; } } @@ -345,7 +521,6 @@ float *findmiddlevertex(RNode *node, RNode *nb, float *v1, float *v2) if(nb->v4==v1 || nb->v4==v2) test+=2; if(test==1) return nb->v4; else if(test==2) return nb->v3; - } else { if(nb->v3==v1 || nb->v3==v2) test++; @@ -426,7 +601,7 @@ void make_face_tab() /* takes care of anchoring */ /* using flag and vertexpointers now Faces can be made */ if(flag==0) { - makeface(rn->v1, rn->v2, rn->v3, rn->v4, rn); + makeface(rn->v1, rn->v2, rn->v3, rn->v4, rn, 1); } else if(rn->type==4) anchorQuadface(rn, v1, v2, v3, v4, flag); else anchorTriface(rn, v1, v2, v3, flag); @@ -662,9 +837,9 @@ void removeEqualNodes(short limit) } if(ok) { - rn->up->totrad[0]= 0.5*(rn->totrad[0]+rn1->totrad[0]); - rn->up->totrad[1]= 0.5*(rn->totrad[1]+rn1->totrad[1]); - rn->up->totrad[2]= 0.5*(rn->totrad[2]+rn1->totrad[2]); + rn->up->totrad[0]= 0.5f*(rn->totrad[0]+rn1->totrad[0]); + rn->up->totrad[1]= 0.5f*(rn->totrad[1]+rn1->totrad[1]); + rn->up->totrad[2]= 0.5f*(rn->totrad[2]+rn1->totrad[2]); rn1= rn->up; deleteNodes(rn1); if(rn1->down1) ; @@ -692,6 +867,7 @@ void rad_addmesh(void) Mesh *me; MVert *mvert; MFace *mface; + TFace *tface; Material *ma=0; unsigned int *md, *coldata, *cd; float **fpp, **poindata; @@ -771,8 +947,9 @@ void rad_addmesh(void) me->totface= endf-startf; me->flag= 0; me->mvert= MEM_callocN(me->totvert*sizeof(MVert), "mverts"); - me->mcol= MEM_callocN(4*me->totface*sizeof(MCol), "mverts"); + //me->mcol= MEM_callocN(4*me->totface*sizeof(MCol), "mverts"); me->mface= MEM_callocN(me->totface*sizeof(MFace), "mface"); + me->tface= MEM_callocN(me->totface*sizeof(TFace), "tface"); /* materials, and set VCOL flag */ @@ -789,12 +966,13 @@ void rad_addmesh(void) VECCOPY(mvert->co, *fpp); } - /* faces and mcol */ + /* faces, mcol and uv */ mface= me->mface; + tface = me->tface; md= (unsigned int *)me->mcol; face= RG.facebase[(startf-1)>>10]+((startf-1) & 1023); - for(a=startf; a<endf; a++, md+=4, mface++) { + for(a=startf; a<endf; a++, md+=4, mface++, tface++) { RAD_NEXTFACE(a); mface->v1= *((unsigned int *)face->v1+3); mface->v2= *((unsigned int *)face->v2+3); @@ -804,11 +982,16 @@ void rad_addmesh(void) mface->edcode= 3; test_index_mface(mface, face->v4 ? 4 : 3); mface->mat_nr= face->matindex; - - md[0]= coldata[mface->v1]; - md[1]= coldata[mface->v2]; - md[2]= coldata[mface->v3]; - md[3]= coldata[mface->v4]; + + if (face->tface) { + memcpy(tface, face->tface, sizeof(TFace)); + } + + memcpy(tface->uv, face->uv, sizeof(float) * 4 * 2); + tface->col[0]= coldata[mface->v1]; + tface->col[1]= coldata[mface->v2]; + tface->col[2]= coldata[mface->v3]; + tface->col[3]= coldata[mface->v4]; } /* boundbox and centrenew */ @@ -820,9 +1003,9 @@ void rad_addmesh(void) DO_MINMAX(mvert->co, min, max); } - cent[0]= (min[0]+max[0])/2.0; - cent[1]= (min[1]+max[1])/2.0; - cent[2]= (min[2]+max[2])/2.0; + cent[0]= (min[0]+max[0])/2.0f; + cent[1]= (min[1]+max[1])/2.0f; + cent[2]= (min[2]+max[2])/2.0f; mvert= me->mvert; for(a=0; a<me->totvert; a++, mvert++) { diff --git a/source/blender/radiosity/intern/source/radpreprocess.c b/source/blender/radiosity/intern/source/radpreprocess.c index 3c94bfc1a22..87ea1626edd 100644 --- a/source/blender/radiosity/intern/source/radpreprocess.c +++ b/source/blender/radiosity/intern/source/radpreprocess.c @@ -104,8 +104,8 @@ void splitconnected() else { /* is face from this vertex allowed for gouraud? */ vnc1= vnc; while(vnc1) { - if(VecCompare(vnc1->n, rp->norm, 0.01)) { - if(VecCompare(vnc1->col, rp->ref, 0.01)) { + if(VecCompare(vnc1->n, rp->norm, 0.01f)) { + if(VecCompare(vnc1->col, rp->ref, 0.01f)) { break; } } @@ -285,6 +285,18 @@ void setedgepointers() MEM_freeN(esblock); } +int materialIndex(Material *ma) +{ + int i = 0; + for(i=0;i< RG.totmat; i++) + { + if (RG.matar[i] == ma) { + return i; + } + } + return -1; +} + void rad_collect_meshes() { extern Material defmaterial; @@ -298,7 +310,7 @@ void rad_collect_meshes() RNode *rn; VeNoCo *vnc, **nodevert; float *vd, *v1, *v2, *v3, *v4 = NULL; - int a, b, offs, index, matindex; + int a, b, offs, index; if(G.obedit) { if (!during_script()) error("Unable to perform function in EditMode"); @@ -323,6 +335,8 @@ void rad_collect_meshes() RG.totvert+= me->totvert; } } + else if ((base->flag & SELECT) == 0) + break; base= base->next; } if(RG.totvert==0) { @@ -331,8 +345,8 @@ void rad_collect_meshes() } vnc= RG.verts= MEM_callocN(RG.totvert*sizeof(VeNoCo), "readvideoscape1"); - RG.min[0]= RG.min[1]= RG.min[2]= 1.0e20; - RG.max[0]= RG.max[1]= RG.max[2]= -1.0e20; + RG.min[0]= RG.min[1]= RG.min[2]= 1.0e20f; + RG.max[0]= RG.max[1]= RG.max[2]= -1.0e20f; /* min-max and material array */ base= (G.scene->base.first); @@ -359,20 +373,27 @@ void rad_collect_meshes() if(RG.totmat<MAXMAT) { if(noma==NULL) { noma= add_material("RadioMat"); + RG.matar[RG.totmat]= noma; + RG.totmat++; } - RG.matar[RG.totmat]= noma; - RG.totmat++; } } else { for(a=0; a<base->object->totcol; a++) { if(RG.totmat >= MAXMAT) break; - RG.matar[RG.totmat]= give_current_material(base->object, a+1); + + ma = give_current_material(base->object, a+1); + + if (materialIndex(ma)!=-1) break; + + RG.matar[RG.totmat]= ma; RG.totmat++; } } } } + else if ((base->flag & SELECT) == 0) + break; base= base->next; } @@ -390,7 +411,6 @@ void rad_collect_meshes() RG.totpatch= 0; RG.totlamp= 0; offs= 0; - matindex= 0; base= (G.scene->base.first); while(base) { @@ -404,6 +424,7 @@ void rad_collect_meshes() for(a=0; a<me->totface; a++, mface++) { if(mface->v3) { + TFace *tface; rp= callocPatch(); BLI_addtail(&(RG.patchbase), rp); @@ -441,6 +462,24 @@ void rad_collect_meshes() CalcNormFloat(v1, v2, v3, rp->norm); } + tface = me->tface ? &((TFace*)me->tface)[a] : (TFace*)NULL; + + if (tface) { + memcpy(rn->uv, tface->uv, sizeof(float) * 4 * 2); + rn->tface = tface; + } + else { + rn->uv[0][0] = 0.0f; + rn->uv[0][1] = 0.0f; + rn->uv[1][0] = 1.0f; + rn->uv[1][1] = 0.0f; + rn->uv[2][0] = 1.0f; + rn->uv[2][1] = 1.0f; + rn->uv[3][0] = 0.0f; + rn->uv[3][1] = 1.0f; + rn->tface = NULL; + } + rn->area= rp->area; /* color and emit */ @@ -475,19 +514,18 @@ void rad_collect_meshes() rp->cent[2]/= (float)rp->type; /* for reconstruction materials */ - rp->matindex= matindex+mface->mat_nr; - if(rp->matindex>MAXMAT-1) rp->matindex= MAXMAT-1; + rp->matindex= materialIndex(ma); + if(rp->matindex==-1) rp->matindex= 1; RG.totelem++; RG.totpatch++; } } offs+= me->totvert; - - matindex+= base->object->totcol; - if(base->object->totcol==0) matindex++; } } + else if ((base->flag & SELECT) == 0) + break; base= base->next; } |