Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_bake_api.c
| Show First 20 Lines • Show All 444 Lines • ▼ Show 20 Lines | static bool bake_object_check(ViewLayer *view_layer, | ||||
| if (me->totpoly == 0) { | if (me->totpoly == 0) { | ||||
| BKE_reportf(reports, RPT_ERROR, "No faces found in the object \"%s\"", ob->id.name + 2); | BKE_reportf(reports, RPT_ERROR, "No faces found in the object \"%s\"", ob->id.name + 2); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (target == R_BAKE_TARGET_VERTEX_COLORS) { | if (target == R_BAKE_TARGET_VERTEX_COLORS) { | ||||
| MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | ||||
| const bool mcol_valid = (mcol != NULL && U.experimental.use_sculpt_vertex_colors); | |||||
| MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | ||||
| if (mcol == NULL && mloopcol == NULL) { | if (mloopcol == NULL && !mcol_valid) { | ||||
| BKE_reportf(reports, | BKE_reportf(reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "No vertex colors layer found in the object \"%s\"", | "No vertex colors layer found in the object \"%s\"", | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| else if (target == R_BAKE_TARGET_IMAGE_TEXTURES) { | else if (target == R_BAKE_TARGET_IMAGE_TEXTURES) { | ||||
| ▲ Show 20 Lines • Show All 465 Lines • ▼ Show 20 Lines | static bool bake_targets_init_vertex_colors(BakeTargets *targets, Object *ob, ReportList *reports) | ||||
| if (ob->type != OB_MESH) { | if (ob->type != OB_MESH) { | ||||
| BKE_report( | BKE_report( | ||||
| reports, RPT_ERROR, "Vertex color baking not support with object types other than mesh"); | reports, RPT_ERROR, "Vertex color baking not support with object types other than mesh"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | ||||
| const bool mcol_valid = (mcol != NULL && U.experimental.use_sculpt_vertex_colors); | |||||
| MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | ||||
| if (mcol == NULL && mloopcol == NULL) { | if (mloopcol == NULL && !mcol_valid) { | ||||
| BKE_report(reports, RPT_ERROR, "No vertex colors layer found to bake to"); | BKE_report(reports, RPT_ERROR, "No vertex colors layer found to bake to"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| targets->images = MEM_callocN(sizeof(BakeImage), "BakeTargets.images"); | targets->images = MEM_callocN(sizeof(BakeImage), "BakeTargets.images"); | ||||
| targets->num_images = 1; | targets->num_images = 1; | ||||
| targets->material_to_image = MEM_callocN(sizeof(int) * ob->totcol, | targets->material_to_image = MEM_callocN(sizeof(int) * ob->totcol, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | else { | ||||
| rgba[3] += 1.0f; | rgba[3] += 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob, Mesh *me_split) | static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob, Mesh *me_split) | ||||
| { | { | ||||
| Mesh *me = ob->data; | Mesh *me = ob->data; | ||||
| MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); | ||||
| const bool mcol_valid = (mcol != NULL && U.experimental.use_sculpt_vertex_colors); | |||||
| MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); | ||||
| const int num_channels = targets->num_channels; | const int num_channels = targets->num_channels; | ||||
| const float *result = targets->result; | const float *result = targets->result; | ||||
| /* We bake using a mesh with additional vertices for split normals, but the | /* We bake using a mesh with additional vertices for split normals, but the | ||||
| * number of loops must match to be able to transfer the vertex colors. */ | * number of loops must match to be able to transfer the vertex colors. */ | ||||
| BLI_assert(me->totloop == me_split->totloop); | BLI_assert(me->totloop == me_split->totloop); | ||||
| UNUSED_VARS_NDEBUG(me_split); | UNUSED_VARS_NDEBUG(me_split); | ||||
| if (mcol) { | if (mcol_valid) { | ||||
| const int totvert = me->totvert; | const int totvert = me->totvert; | ||||
| const int totloop = me->totloop; | const int totloop = me->totloop; | ||||
| /* Accumulate float vertex colors in scene linear color space. */ | /* Accumulate float vertex colors in scene linear color space. */ | ||||
| int *num_loops_for_vertex = MEM_callocN(sizeof(int) * me->totvert, "num_loops_for_vertex"); | int *num_loops_for_vertex = MEM_callocN(sizeof(int) * me->totvert, "num_loops_for_vertex"); | ||||
| memset(mcol, 0, sizeof(MPropCol) * me->totvert); | memset(mcol, 0, sizeof(MPropCol) * me->totvert); | ||||
| MLoop *mloop = me->mloop; | MLoop *mloop = me->mloop; | ||||
| ▲ Show 20 Lines • Show All 999 Lines • Show Last 20 Lines | |||||