Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-08-29 03:24:34 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-08-29 03:24:34 +0400
commit0e01fa4863a301f9776b8a6b5459493fc8830008 (patch)
tree9c9adc39b0f6acaaf8f3835ecc554ee7538f83dc /source/blender/render
parentc31b776dc9a914f0fcf1b988edb448f12ed4eb64 (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')
-rw-r--r--source/blender/render/extern/include/RE_pipeline.h4
-rw-r--r--source/blender/render/intern/source/pipeline.c57
2 files changed, 61 insertions, 0 deletions
diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h
index d9ed83a00b2..0736bed4faf 100644
--- a/source/blender/render/extern/include/RE_pipeline.h
+++ b/source/blender/render/extern/include/RE_pipeline.h
@@ -51,6 +51,7 @@ struct ReportList;
struct ReportList;
struct Scene;
struct SceneRenderLayer;
+struct EnvMap;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* this include is what is exposed of render to outside world */
@@ -230,6 +231,9 @@ void RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode);
void RE_WriteRenderResult(RenderResult *rr, const char *filename, int compress);
struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty);
+extern const float default_envmap_layout[];
+int RE_WriteEnvmapResult(struct ReportList *reports, struct Scene *scene, struct EnvMap *env, const char *relpath, int imtype, float layout[12]);
+
/* do a full sample buffer compo */
void RE_MergeFullSample(struct Render *re, struct Main *bmain, struct Scene *sce, struct bNodeTree *ntree);
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;
+ }
+}