VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr) { VlakRen *vlr1 = RE_findOrAddVlak(obr, obr->totvlak++); MTFace *mtface, *mtface1; MCol *mcol, *mcol1; float *surfnor, *surfnor1, *tangent, *tangent1; int *origindex, *origindex1; RadFace **radface, **radface1; int i, index = vlr1->index; char *name; *vlr1= *vlr; vlr1->index= index; for (i=0; (mtface=RE_vlakren_get_tface(obr, vlr, i, &name, 0)) != NULL; i++) { mtface1= RE_vlakren_get_tface(obr, vlr1, i, &name, 1); memcpy(mtface1, mtface, sizeof(MTFace)*RE_MTFACE_ELEMS); } for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)) != NULL; i++) { mcol1= RE_vlakren_get_mcol(obr, vlr1, i, &name, 1); memcpy(mcol1, mcol, sizeof(MCol)*RE_MCOL_ELEMS); } origindex= RE_vlakren_get_origindex(obr, vlr, 0); if (origindex) { origindex1= RE_vlakren_get_origindex(obr, vlr1, 1); /* Just an int, but memcpy for consistency. */ memcpy(origindex1, origindex, sizeof(int)*RE_VLAK_ORIGINDEX_ELEMS); } surfnor= RE_vlakren_get_surfnor(obr, vlr, 0); if (surfnor) { surfnor1= RE_vlakren_get_surfnor(obr, vlr1, 1); copy_v3_v3(surfnor1, surfnor); } tangent= RE_vlakren_get_nmap_tangent(obr, vlr, 0); if (tangent) { tangent1= RE_vlakren_get_nmap_tangent(obr, vlr1, 1); memcpy(tangent1, tangent, sizeof(float)*RE_NMAP_TANGENT_ELEMS); } radface= RE_vlakren_get_radface(obr, vlr, 0); if (radface) { radface1= RE_vlakren_get_radface(obr, vlr1, 1); *radface1= *radface; } return vlr1; }
static int get_next_bake_face(BakeShade *bs) { ObjectRen *obr; VlakRen *vlr; MTFace *tface; static int v = 0, vdone = false; static ObjectInstanceRen *obi = NULL; if (bs == NULL) { vlr = NULL; v = vdone = false; obi = R.instancetable.first; return 0; } BLI_lock_thread(LOCK_CUSTOM1); for (; obi; obi = obi->next, v = 0) { obr = obi->obr; for (; v < obr->totvlak; v++) { vlr = RE_findOrAddVlak(obr, v); if ((bs->actob && bs->actob == obr->ob) || (!bs->actob && (obr->ob->flag & SELECT))) { if (R.r.bake_flag & R_BAKE_VCOL) { /* Gather face data for vertex color bake */ Mesh *me; int *origindex, vcollayer; CustomDataLayer *cdl; if (obr->ob->type != OB_MESH) continue; me = obr->ob->data; origindex = RE_vlakren_get_origindex(obr, vlr, 0); if (origindex == NULL) continue; if (*origindex >= me->totpoly) { /* Small hack for Array modifier, which gives false * original indices - z0r */ continue; } #if 0 /* Only shade selected faces. */ if ((me->mface[*origindex].flag & ME_FACE_SEL) == 0) continue; #endif vcollayer = CustomData_get_render_layer_index(&me->ldata, CD_MLOOPCOL); if (vcollayer == -1) continue; cdl = &me->ldata.layers[vcollayer]; bs->mpoly = me->mpoly + *origindex; bs->vcol = ((MLoopCol *)cdl->data) + bs->mpoly->loopstart; bs->mloop = me->mloop + bs->mpoly->loopstart; /* Tag mesh for reevaluation. */ me->id.flag |= LIB_DOIT; } else { Image *ima = NULL; ImBuf *ibuf = NULL; const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f}; const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f}; const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f}; const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f}; const float disp_alpha[4] = {0.5f, 0.5f, 0.5f, 0.0f}; const float disp_solid[4] = {0.5f, 0.5f, 0.5f, 1.0f}; tface = RE_vlakren_get_tface(obr, vlr, obr->bakemtface, NULL, 0); if (!tface || !tface->tpage) continue; ima = tface->tpage; ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL, IMA_IBUF_IMA); if (ibuf == NULL) continue; if (ibuf->rect == NULL && ibuf->rect_float == NULL) { BKE_image_release_ibuf(ima, ibuf, NULL); continue; } if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4)) { BKE_image_release_ibuf(ima, ibuf, NULL); continue; } if (ima->flag & IMA_USED_FOR_RENDER) { ima->id.flag &= ~LIB_DOIT; BKE_image_release_ibuf(ima, ibuf, NULL); continue; } /* find the image for the first time? */ if (ima->id.flag & LIB_DOIT) { ima->id.flag &= ~LIB_DOIT; /* we either fill in float or char, this ensures things go fine */ if (ibuf->rect_float) imb_freerectImBuf(ibuf); /* clear image */ if (R.r.bake_flag & R_BAKE_CLEAR) { if (R.r.bake_mode == RE_BAKE_NORMALS && R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid); else if (ELEM(R.r.bake_mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid); else IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid); } /* might be read by UI to set active image for display */ R.bakebuf = ima; } /* Tag image for redraw. */ ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; BKE_image_release_ibuf(ima, ibuf, NULL); } bs->obi = obi; bs->vlr = vlr; bs->vdone++; /* only for error message if nothing was rendered */ v++; BLI_unlock_thread(LOCK_CUSTOM1); return 1; } } } BLI_unlock_thread(LOCK_CUSTOM1); return 0; }