Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_bake_api.c
| Show First 20 Lines • Show All 542 Lines • ▼ Show 20 Lines | else { | ||||
| BKE_reportf(reports, RPT_ERROR, "Uninitialized image %s", bk_image->image->id.name + 2); | BKE_reportf(reports, RPT_ERROR, "Uninitialized image %s", bk_image->image->id.name + 2); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| BKE_image_release_ibuf(bk_image->image, ibuf, lock); | BKE_image_release_ibuf(bk_image->image, ibuf, lock); | ||||
| } | } | ||||
| return tot_size; | return tot_size; | ||||
| } | } | ||||
| static int bake( | static int bake( | ||||
| Render *re, Main *bmain, Scene *scene, Object *ob_low, ListBase *selected_objects, ReportList *reports, | Render *re, Main *bmain, Scene *scene, Object *ob_low, ListBase *selected_objects, ReportList *reports, | ||||
| const ScenePassType pass_type, const int margin, | const ScenePassType pass_type, const int margin, | ||||
| const BakeSaveMode save_mode, const bool is_clear, const bool is_split_materials, | const BakeSaveMode save_mode, const bool is_clear, const bool is_split_materials, | ||||
| const bool is_automatic_name, const bool is_selected_to_active, const bool is_cage, | const bool is_automatic_name, const bool is_selected_to_active, const bool is_cage, | ||||
| const float cage_extrusion, const int normal_space, const BakeNormalSwizzle normal_swizzle[], | const float cage_extrusion, const int normal_space, const BakeNormalSwizzle normal_swizzle[], | ||||
| const char *custom_cage, const char *filepath, const int width, const int height, | const char *custom_cage, const char *filepath, const int width, const int height, | ||||
| const char *identifier, ScrArea *sa, const char *uv_layer) | const char *identifier, ScrArea *sa, const char *uv_layer) | ||||
| { | { | ||||
| int op_result = OPERATOR_CANCELLED; | int op_result = OPERATOR_CANCELLED; | ||||
| bool ok = false; | bool ok = false; | ||||
| Object *ob_cage = NULL; | Object *ob_cage = NULL; | ||||
| BakeHighPolyData *highpoly = NULL; | BakeHighPolyData *highpoly = NULL; | ||||
| int tot_highpoly; | int tot_highpoly; | ||||
campbellbarton: Realize its not directly related to this patch (since the triangulate modifier was used… | |||||
| char restrict_flag_low = ob_low->restrictflag; | char restrict_flag_low = ob_low->restrictflag; | ||||
| char restrict_flag_cage = 0; | char restrict_flag_cage = 0; | ||||
| Mesh *me_low = NULL; | Mesh *me_low = NULL; | ||||
| Mesh *me_cage = NULL; | Mesh *me_cage = NULL; | ||||
| float *result = NULL; | float *result = NULL; | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | for (link = selected_objects->first; link; link = link->next) { | ||||
| highpoly[i].me = BKE_mesh_new_from_object(bmain, scene, highpoly[i].ob, 1, 2, 0, 0); | highpoly[i].me = BKE_mesh_new_from_object(bmain, scene, highpoly[i].ob, 1, 2, 0, 0); | ||||
| highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; | highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; | ||||
| BKE_mesh_split_faces(highpoly[i].me); | BKE_mesh_split_faces(highpoly[i].me); | ||||
| BKE_mesh_tessface_ensure(highpoly[i].me); | BKE_mesh_tessface_ensure(highpoly[i].me); | ||||
| /* lowpoly to highpoly transformation matrix */ | /* lowpoly to highpoly transformation matrix */ | ||||
| copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); | copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->obmat); | ||||
| invert_m4_m4(highpoly[i].imat, highpoly[i].obmat); | invert_m4_m4(highpoly[i].imat, highpoly[i].obmat); | ||||
| unit_m4(highpoly[i].mat); | |||||
| highpoly[i].is_flip_object = is_negative_m4(highpoly[i].ob->obmat); | highpoly[i].is_flip_object = is_negative_m4(highpoly[i].ob->obmat); | ||||
| i++; | i++; | ||||
| } | } | ||||
| BLI_assert(i == tot_highpoly); | BLI_assert(i == tot_highpoly); | ||||
| ob_low->restrictflag |= OB_RESTRICT_RENDER; | ob_low->restrictflag |= OB_RESTRICT_RENDER; | ||||
| /* populate the pixel arrays with the corresponding face data for each high poly object */ | /* populate the pixel arrays with the corresponding face data for each high poly object */ | ||||
| if (!RE_bake_pixels_populate_from_objects( | if (!RE_bake_pixels_populate_from_objects( | ||||
| me_low, pixel_array_low, pixel_array_high, highpoly, tot_highpoly, num_pixels, ob_cage != NULL, | me_low, pixel_array_low, pixel_array_high, highpoly, tot_highpoly, num_pixels, ob_cage != NULL, | ||||
| cage_extrusion, ob_low->obmat, (ob_cage ? ob_cage->obmat : ob_low->obmat), me_cage)) | cage_extrusion, ob_low->obmat, (ob_cage ? ob_cage->obmat : ob_low->obmat), me_cage)) | ||||
| { | { | ||||
| BKE_report(reports, RPT_ERROR, "Error handling selected objects"); | BKE_report(reports, RPT_ERROR, "Error handling selected objects"); | ||||
| goto cage_cleanup; | goto cage_cleanup; | ||||
| } | } | ||||
| /* the baking itself */ | /* the baking itself */ | ||||
| for (i = 0; i < tot_highpoly; i++) { | for (i = 0; i < tot_highpoly; i++) { | ||||
| ok = RE_bake_engine(re, highpoly[i].ob, i, pixel_array_high, | ok = RE_bake_engine(re, highpoly[i].ob, i, pixel_array_high, | ||||
| num_pixels, depth, pass_type, result); | num_pixels, depth, pass_type, highpoly[i].mat, result); | ||||
| if (!ok) { | if (!ok) { | ||||
| BKE_reportf(reports, RPT_ERROR, "Error baking from object \"%s\"", highpoly[i].ob->id.name + 2); | BKE_reportf(reports, RPT_ERROR, "Error baking from object \"%s\"", highpoly[i].ob->id.name + 2); | ||||
| goto cage_cleanup; | goto cage_cleanup; | ||||
| } | } | ||||
| } | } | ||||
| cage_cleanup: | cage_cleanup: | ||||
| /* reverting data back */ | /* reverting data back */ | ||||
| Show All 9 Lines | if (!ok) { | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* make sure low poly renders */ | /* make sure low poly renders */ | ||||
| ob_low->restrictflag &= ~OB_RESTRICT_RENDER; | ob_low->restrictflag &= ~OB_RESTRICT_RENDER; | ||||
| if (RE_bake_has_engine(re)) { | if (RE_bake_has_engine(re)) { | ||||
| ok = RE_bake_engine(re, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, result); | float matrix[4][4]; | ||||
| unit_m4(matrix); | |||||
| ok = RE_bake_engine(re, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, matrix, result); | |||||
| } | } | ||||
Not Done Inline ActionsNo strong opinion. But this could just be a NULL argument. to avoid doing any transformation. (since this is such a common case) campbellbarton: No strong opinion. But this could just be a `NULL` argument. to avoid doing any transformation. | |||||
| else { | else { | ||||
| BKE_report(reports, RPT_ERROR, "Current render engine does not support baking"); | BKE_report(reports, RPT_ERROR, "Current render engine does not support baking"); | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| } | } | ||||
| /* normal space conversion | /* normal space conversion | ||||
| * the normals are expected to be in world space, +X +Y +Z */ | * the normals are expected to be in world space, +X +Y +Z */ | ||||
| ▲ Show 20 Lines • Show All 537 Lines • Show Last 20 Lines | |||||
Realize its not directly related to this patch (since the triangulate modifier was used already), but think we could use tessface layout, or have a version of BKE_mesh_recalc_tessellation that outputs MPoly tri's instead of MFace's\
Would avoid going via BMesh conversion.