[Bf-blender-cvs] [350d253] bake-cycles: Code cleanup: cycles baking
Campbell Barton
noreply at git.blender.org
Sun Apr 27 12:44:34 CEST 2014
Commit: 350d253a4132e8af9ab5b23ea8e5cdeb3e4b3f4c
Author: Campbell Barton
Date: Sun Apr 27 18:54:25 2014 +1000
https://developer.blender.org/rB350d253a4132e8af9ab5b23ea8e5cdeb3e4b3f4c
Code cleanup: cycles baking
- remove unused headers
- respect 120 line length
- indentation
- was assigning all props to 'ot->prop' for no reason.
===================================================================
M source/blender/editors/object/object_bake_api.c
===================================================================
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index 7efb76a..094c7a9 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -36,21 +36,20 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
-#include "DNA_world_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_defs.h"
#include "DNA_material_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
-#include "BLI_blenlib.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_fileops.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
-#include "BLI_math.h"
#include "BLI_math_geom.h"
#include "BLI_path_util.h"
@@ -77,11 +76,8 @@
#include "RE_shader_ext.h"
#include "RE_multires_bake.h"
-#include "PIL_time.h"
-
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-#include "IMB_colormanagement.h"
#include "GPU_draw.h" /* GPU_free_image */
@@ -106,8 +102,9 @@ static int bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
/* running render */
switch (event->type) {
case ESCKEY:
+ {
return OPERATOR_RUNNING_MODAL;
- break;
+ }
}
return OPERATOR_PASS_THROUGH;
}
@@ -122,9 +119,9 @@ static int bake_break(void *UNUSED(rjv))
}
static bool write_internal_bake_pixels(
- Image *image, BakePixel pixel_array[], float *buffer,
- const int width, const int height, const bool is_linear,
- const int margin, const bool is_clear)
+ Image *image, BakePixel pixel_array[], float *buffer,
+ const int width, const int height, const bool is_linear,
+ const int margin, const bool is_clear)
{
ImBuf *ibuf;
void *lock;
@@ -148,33 +145,29 @@ static bool write_internal_bake_pixels(
if (is_clear) {
if (is_float) {
IMB_buffer_float_from_float(
- ibuf->rect_float, buffer, ibuf->channels,
- IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
- ibuf->x, ibuf->y, ibuf->x, ibuf->y
- );
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y);
}
else {
IMB_buffer_byte_from_float(
- (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
- (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
- false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
- );
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
}
}
else {
if (is_float) {
IMB_buffer_float_from_float_mask(
- ibuf->rect_float, buffer, ibuf->channels,
- IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
- ibuf->x, ibuf->y, ibuf->x, ibuf->y, mask_buffer
- );
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y, mask_buffer);
}
else {
IMB_buffer_byte_from_float_mask(
- (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
- (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
- false, ibuf->x, ibuf->y, ibuf->x, ibuf->x, mask_buffer
- );
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x, mask_buffer);
}
}
@@ -192,9 +185,9 @@ static bool write_internal_bake_pixels(
}
static bool write_external_bake_pixels(
- const char *filepath, BakePixel pixel_array[], float *buffer,
- const int width, const int height, bool is_linear, const int margin,
- ImageFormatData *im_format)
+ const char *filepath, BakePixel pixel_array[], float *buffer,
+ const int width, const int height, bool is_linear, const int margin,
+ ImageFormatData *im_format)
{
ImBuf *ibuf = NULL;
bool ok = false;
@@ -211,17 +204,15 @@ static bool write_external_bake_pixels(
/* populates the ImBuf */
if (is_float) {
IMB_buffer_float_from_float(
- ibuf->rect_float, buffer, ibuf->channels,
- IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
- ibuf->x, ibuf->y, ibuf->x, ibuf->y
- );
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y);
}
else {
IMB_buffer_byte_from_float(
- (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
- (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
- false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
- );
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
}
/* margins */
@@ -247,8 +238,7 @@ static bool write_external_bake_pixels(
/* garbage collection */
IMB_freeImBuf(ibuf);
- if (ok) return true;
- return false;
+ return ok;
}
static bool is_data_pass(ScenePassType pass_type)
@@ -265,9 +255,9 @@ static bool is_data_pass(ScenePassType pass_type)
static bool build_image_lookup(wmOperator *op, Main *bmain, Object *ob, BakeImages *images)
{
+ const int tot_mat = ob->totcol;
int i, j;
int tot_images = 0;
- int tot_mat = ob->totcol;
/* error handling and tag (in case multiple materials share the same image) */
BKE_main_id_tag_idcode(bmain, ID_IM, false);
@@ -387,11 +377,11 @@ static int bake_exec(bContext *C, wmOperator *op)
BakeImages images;
- int normal_space = RNA_enum_get(op->ptr, "normal_space");
- BakeNormalSwizzle normal_swizzle[] = {
- RNA_enum_get(op->ptr, "normal_r"),
- RNA_enum_get(op->ptr, "normal_g"),
- RNA_enum_get(op->ptr, "normal_b")
+ const int normal_space = RNA_enum_get(op->ptr, "normal_space");
+ const BakeNormalSwizzle normal_swizzle[] = {
+ RNA_enum_get(op->ptr, "normal_r"),
+ RNA_enum_get(op->ptr, "normal_g"),
+ RNA_enum_get(op->ptr, "normal_b")
};
char custom_cage[MAX_NAME];
@@ -410,17 +400,21 @@ static int bake_exec(bContext *C, wmOperator *op)
if (tot_materials == 0) {
if (is_save_internal) {
BKE_report(op->reports, RPT_ERROR,
- "No active image found. Add a material or bake to an external file");
+ "No active image found. Add a material or bake to an external file");
+
goto cleanup;
}
else if (is_split_materials) {
BKE_report(op->reports, RPT_ERROR,
- "No active image found. Add a material or bake without the Split Materials option");
+ "No active image found. Add a material or bake without the Split Materials option");
+
goto cleanup;
}
else {
+#if 0
/* baking externally without splitting materials */
- int tot_images = 1;
+ tot_images = 1;
+#endif
}
}
@@ -428,7 +422,7 @@ static int bake_exec(bContext *C, wmOperator *op)
images.data = MEM_callocN(sizeof(BakeImage) * tot_materials, "bake images dimensions (width, height, offset)");
images.lookup = MEM_callocN(sizeof(int) * tot_materials, "bake images lookup (from material to BakeImage)");
- if(!build_image_lookup(op, bmain, ob_low, &images))
+ if (!build_image_lookup(op, bmain, ob_low, &images))
goto cleanup;
if (is_save_internal) {
@@ -473,6 +467,7 @@ static int bake_exec(bContext *C, wmOperator *op)
if (tot_highpoly == 0) {
BKE_report(op->reports, RPT_ERROR, "No valid selected objects");
op_result = OPERATOR_CANCELLED;
+
goto cleanup;
}
else {
@@ -487,6 +482,7 @@ static int bake_exec(bContext *C, wmOperator *op)
if (ob_cage == NULL || ob_cage->type != OB_MESH) {
BKE_report(op->reports, RPT_ERROR, "No valid cage object");
op_result = OPERATOR_CANCELLED;
+
goto cleanup;
}
else {
@@ -561,7 +557,9 @@ static int bake_exec(bContext *C, wmOperator *op)
/* triangulating so BVH returns the primitive_id that will be used for rendering */
- highpoly[i].tri_mod = ED_object_modifier_add(op->reports, bmain, scene, highpoly[i].ob, "TmpTriangulate", eModifierType_Triangulate);
+ highpoly[i].tri_mod = ED_object_modifier_add(
+ op->reports, bmain, scene, highpoly[i].ob,
+ "TmpTriangulate", eModifierType_Triangulate);
tmd = (TriangulateModifierData *)highpoly[i].tri_mod;
tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED;
tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP;
@@ -585,14 +583,20 @@ static int bake_exec(bContext *C, wmOperator *op)
ob_low->restrictflag |= OB_RESTRICT_RENDER;
/* populate the pixel arrays with the corresponding face data for each high poly object */
- RE_populate_bake_pixels_from_objects(me_low, pixel_array_low, highpoly, tot_highpoly, num_pixels, cage_extrusion);
+ RE_populate_bake_pixels_from_objects(
+ me_low, pixel_array_low, highpoly, tot_highpoly,
+ num_pixels, cage_extrusion);
/* the baking itself */
for (i = 0; i < tot_highpoly; i++) {
- if (RE_engine_has_bake(re))
- ok = RE_engine_bake(re, highpoly[i].ob, highpoly[i].pixel_array, num_pixels, depth, pass_type, result);
- else
- ok = RE_internal_bake(re, highpoly[i].ob, highpoly[i].pixel_array, num_pixels, depth, pass_type, result);
+ if (RE_engine_has_bake(re)) {
+ ok = RE_engine_bake(re, highpoly[i].ob, highpoly[i].pixel_array, num_pixels,
+ depth, pass_type, result);
+ }
+ else {
+ ok = RE_internal_bake(re, highpoly[i].ob, highpoly[i].pixel_array, num_pixels,
+ depth, pass_type, result);
+ }
if (!ok)
break;
@@ -632,9 +636,9 @@ static int bake_exec(bContext *C, wmOperator *op)
case R_BAKE_SPACE_WORLD:
{
/* Cycles internal format */
- if (normal_swizzle[0] == R_BAKE_NEGX &&
- normal_swizzle[1] == R_BAKE_NEGY &&
- normal_swizzle[2] == R_BAKE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list