diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-08-29 03:24:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-08-29 03:24:34 +0400 |
commit | 0e01fa4863a301f9776b8a6b5459493fc8830008 (patch) | |
tree | 9c9adc39b0f6acaaf8f3835ecc554ee7538f83dc /source/blender/editors | |
parent | c31b776dc9a914f0fcf1b988edb448f12ed4eb64 (diff) |
patch [#28355] Better Environment Map scripting
from Tom Edwards (artfunkel), with minor edits.
This patch makes the following improvements to environment map scripting:
* Adds a "is_valid" RNA property to envmaps. True if the map is ready for use, False if it needs rendering.
* Adds a "clear" RNA function to envmaps. Deletes any envmap image data.
* Adds a "save" RNA function to envmaps. Writes the envmap to disc with a configurable layout. (Defaults to the current hard-coded layout.)
* Updates bpy.ops.texture.envmap_save with configurable layout support as above.
These changes, particularly configurable layouts, make exporting envmaps to other software much easier.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/render/render_shading.c | 69 |
1 files changed, 17 insertions, 52 deletions
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index fbdcf7ba9b3..1b24d660411 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -85,6 +85,8 @@ #include "UI_interface.h" +#include "RE_pipeline.h" + #include "render_intern.h" // own include /********************** material slot operators *********************/ @@ -661,60 +663,21 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot) /********************** environment map operators *********************/ -static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *str, int imtype) +static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, int imtype) { - ImBuf *ibuf=NULL; - int dx; - int retval; - int relative= (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path")); - - if(env->cube[1]==NULL) { - BKE_report(op->reports, RPT_ERROR, "There is no generated environment map available to save"); - return OPERATOR_CANCELLED; - } - - dx= env->cube[1]->x; - - if (env->type == ENV_CUBE) { - ibuf = IMB_allocImBuf(3*dx, 2*dx, 24, IB_rectfloat); - - IMB_rectcpy(ibuf, env->cube[0], 0, 0, 0, 0, dx, dx); - IMB_rectcpy(ibuf, env->cube[1], dx, 0, 0, 0, dx, dx); - IMB_rectcpy(ibuf, env->cube[2], 2*dx, 0, 0, 0, dx, dx); - IMB_rectcpy(ibuf, env->cube[3], 0, dx, 0, 0, dx, dx); - IMB_rectcpy(ibuf, env->cube[4], dx, dx, 0, 0, dx, dx); - IMB_rectcpy(ibuf, env->cube[5], 2*dx, dx, 0, 0, dx, dx); - } - else if (env->type == ENV_PLANE) { - ibuf = IMB_allocImBuf(dx, dx, 24, IB_rectfloat); - IMB_rectcpy(ibuf, env->cube[1], 0, 0, 0, 0, dx, dx); + float layout[12]; + if ( RNA_struct_find_property(op->ptr, "layout") ) + RNA_float_get_array(op->ptr, "layout",layout); + else + memcpy(layout, default_envmap_layout, sizeof(layout)); + + if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) { + return OPERATOR_FINISHED; } else { - BKE_report(op->reports, RPT_ERROR, "Invalid environment map type"); return OPERATOR_CANCELLED; } - - if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) - ibuf->profile = IB_PROFILE_LINEAR_RGB; - - /* to save, we first get absolute path */ - BLI_path_abs(str, G.main->name); - - if (BKE_write_ibuf(ibuf, str, imtype, scene->r.subimtype, scene->r.quality)) { - retval = OPERATOR_FINISHED; - } - else { - BKE_reportf(op->reports, RPT_ERROR, "Error saving environment map to %s.", str); - retval = OPERATOR_CANCELLED; - } - /* in case we were saving with relative paths, change back again */ - if(relative) - BLI_path_rel(str, G.main->name); - - IMB_freeImBuf(ibuf); - ibuf = NULL; - - return retval; + } static int envmap_save_exec(bContext *C, wmOperator *op) @@ -753,7 +716,6 @@ static int envmap_save_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event return envmap_save_exec(C, op); //RNA_enum_set(op->ptr, "file_type", scene->r.imtype); - RNA_string_set(op->ptr, "filepath", G.main->name); WM_event_add_fileselect(C, op); @@ -776,6 +738,7 @@ static int envmap_save_poll(bContext *C) void TEXTURE_OT_envmap_save(wmOperatorType *ot) { + PropertyRNA *prop; /* identifiers */ ot->name= "Save Environment Map"; ot->idname= "TEXTURE_OT_envmap_save"; @@ -790,8 +753,10 @@ void TEXTURE_OT_envmap_save(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER; /* no undo since this doesnt modify the env-map */ /* properties */ - //RNA_def_enum(ot->srna, "file_type", image_file_type_items, R_PNG, "File Type", "File type to save image as."); - WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH); + prop= RNA_def_float_array(ot->srna, "layout", 12, default_envmap_layout, 0.0f, 0.0f, "File layout", "Flat array describing the X,Y position of each cube face in the output image, where 1 is the size of a face. Order is [+Z -Z +Y -X -Y +X]. Use -1 to skip a face.", 0.0f, 0.0f); + RNA_def_property_flag(prop, PROP_HIDDEN); + + WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH); } static int envmap_clear_exec(bContext *C, wmOperator *UNUSED(op)) |