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/render/intern | |
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/render/intern')
-rw-r--r-- | source/blender/render/intern/source/pipeline.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index b9006b390ab..eff8402d8b5 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -3463,3 +3463,60 @@ static int external_render_3d(Render *re, int do_all) return 1; } +const float default_envmap_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 }; + +int RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, const char *relpath, int imtype, float layout[12]) +{ + ImBuf *ibuf=NULL; + int ok; + int dx; + int maxX=0,maxY=0,i=0; + char filepath[FILE_MAX]; + + if(env->cube[1]==NULL) { + BKE_report(reports, RPT_ERROR, "There is no generated environment map available to save"); + return 0; + } + + dx= env->cube[1]->x; + + if (env->type == ENV_CUBE) { + for (i=0; i < 12; i+=2) { + maxX = MAX2(maxX,layout[i] + 1); + maxY = MAX2(maxY,layout[i+1] + 1); + } + + ibuf = IMB_allocImBuf(maxX*dx, maxY*dx, 24, IB_rectfloat); + + for (i=0; i < 12; i+=2) + if (layout[i] > -1 && layout[i+1] > -1) + IMB_rectcpy(ibuf, env->cube[i/2], layout[i]*dx, layout[i+1]*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); + } + else { + BKE_report(reports, RPT_ERROR, "Invalid environment map type"); + return 0; + } + + if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) + ibuf->profile = IB_PROFILE_LINEAR_RGB; + + /* to save, we first get absolute path */ + BLI_strncpy(filepath, relpath, sizeof(filepath)); + BLI_path_abs(filepath, G.main->name); + + ok= BKE_write_ibuf(ibuf, filepath, imtype, scene->r.subimtype, scene->r.quality); + + IMB_freeImBuf(ibuf); + + if(ok) { + return TRUE; + } + else { + BKE_report(reports, RPT_ERROR, "Error writing environment map."); + return FALSE; + } +} |