Revision: 39760
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39760
Author:   campbellbarton
Date:     2011-08-28 23:24:34 +0000 (Sun, 28 Aug 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/render/render_shading.c
    trunk/blender/source/blender/makesrna/intern/CMakeLists.txt
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_internal.h
    trunk/blender/source/blender/makesrna/intern/rna_texture.c
    trunk/blender/source/blender/render/extern/include/RE_pipeline.h
    trunk/blender/source/blender/render/intern/source/pipeline.c

Added Paths:
-----------
    trunk/blender/source/blender/makesrna/intern/rna_texture_api.c

Modified: trunk/blender/source/blender/editors/render/render_shading.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_shading.c        
2011-08-28 21:48:52 UTC (rev 39759)
+++ trunk/blender/source/blender/editors/render/render_shading.c        
2011-08-28 23:24:34 UTC (rev 39760)
@@ -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 @@
 
 /********************** 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);
+       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));
 
-               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);
+       if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, 
layout)) {
+               return OPERATOR_FINISHED;
        }
-       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(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 @@
                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 @@
 
 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 @@
        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))

Modified: trunk/blender/source/blender/makesrna/intern/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/makesrna/intern/CMakeLists.txt 2011-08-28 
21:48:52 UTC (rev 39759)
+++ trunk/blender/source/blender/makesrna/intern/CMakeLists.txt 2011-08-28 
23:24:34 UTC (rev 39760)
@@ -100,6 +100,7 @@
        rna_main_api.c
        rna_material_api.c
        rna_mesh_api.c
+       rna_texture_api.c
        rna_object_api.c
        rna_pose_api.c
        rna_scene_api.c

Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/makesrna.c     2011-08-28 
21:48:52 UTC (rev 39759)
+++ trunk/blender/source/blender/makesrna/intern/makesrna.c     2011-08-28 
23:24:34 UTC (rev 39760)
@@ -2417,7 +2417,7 @@
 static RNAProcessItem PROCESS_ITEMS[]= {
        {"rna_rna.c", NULL, RNA_def_rna},
        {"rna_ID.c", NULL, RNA_def_ID},
-       {"rna_texture.c", NULL, RNA_def_texture},
+       {"rna_texture.c", "rna_texture_api.c", RNA_def_texture},
        {"rna_action.c", "rna_action_api.c", RNA_def_action},
        {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
        {"rna_animviz.c", NULL, RNA_def_animviz},

Modified: trunk/blender/source/blender/makesrna/intern/rna_internal.h
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_internal.h 2011-08-28 
21:48:52 UTC (rev 39759)
+++ trunk/blender/source/blender/makesrna/intern/rna_internal.h 2011-08-28 
23:24:34 UTC (rev 39760)
@@ -260,6 +260,7 @@
 void RNA_api_sensor(struct StructRNA *srna);
 void RNA_api_controller(struct StructRNA *srna);
 void RNA_api_actuator(struct StructRNA *srna);
+void RNA_api_environment_map(struct StructRNA *srna);
 
 /* main collection functions */
 void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop);

Modified: trunk/blender/source/blender/makesrna/intern/rna_texture.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_texture.c  2011-08-28 
21:48:52 UTC (rev 39759)
+++ trunk/blender/source/blender/makesrna/intern/rna_texture.c  2011-08-28 
23:24:34 UTC (rev 39760)
@@ -664,6 +664,13 @@
        RNA_def_property_range(prop, 0, 5);
        RNA_def_property_ui_text(prop, "Depth", "Number of times a map will be 
rendered recursively (mirror effects.)");
        RNA_def_property_update(prop, 0, "rna_Texture_update");
+
+       prop= RNA_def_property(srna, "is_valid", PROP_BOOLEAN, 0);
+       RNA_def_property_boolean_sdna(prop, NULL, "ok", 2);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Validity", "True if this map is ready 
for use, False if it needs rendering.");
+
+       RNA_api_environment_map(srna);
 }
 
 static EnumPropertyItem prop_noise_basis_items[] = {

Added: trunk/blender/source/blender/makesrna/intern/rna_texture_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_texture_api.c              
                (rev 0)
+++ trunk/blender/source/blender/makesrna/intern/rna_texture_api.c      
2011-08-28 23:24:34 UTC (rev 39760)
@@ -0,0 +1,95 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Tom Edwards
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_texture_api.c
+ *  \ingroup RNA
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#include "RNA_define.h"
+#include "BKE_utildefines.h"
+
+#ifdef RNA_RUNTIME
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+#include "DNA_scene_types.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "RE_pipeline.h"
+
+void save_envmap(struct EnvMap *env, bContext *C, ReportList *reports, const 
char* filepath, struct Scene *scene, float layout[12])
+{
+       if (scene == NULL) {
+               scene = CTX_data_scene(C);
+       }
+
+       RE_WriteEnvmapResult(reports, scene, env, filepath, scene->r.imtype, 
layout);
+}
+
+void clear_envmap(struct EnvMap *env, bContext *C)
+{
+       Main *bmain = CTX_data_main(C);
+       Tex *tex;
+
+       BKE_free_envmapdata(env);
+       
+       for (tex=bmain->tex.first; tex; tex=tex->id.next)
+               if (tex->env == env) {
+                       WM_event_add_notifier(C, NC_TEXTURE|NA_EDITED, tex);
+                       break;
+               }
+}
+
+#else
+
+void RNA_api_environment_map(StructRNA *srna)
+{
+       FunctionRNA *func;
+       PropertyRNA *parm;
+       
+       static const float default_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };
+       
+       func= RNA_def_function(srna, "clear", "clear_envmap");
+               RNA_def_function_ui_description(func, "Discard the environment 
map and free it from memory.");
+               RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+
+
+       func= RNA_def_function(srna,"save", "save_envmap");
+               RNA_def_function_ui_description(func, "Save the environment map 
to disc using the scene render settings.");
+               RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+       
+               parm= 
RNA_def_string_file_name(func,"filepath","",FILE_MAX,"File path","Location of 
the output file");
+                       RNA_def_property_flag(parm, PROP_REQUIRED);
+       
+               RNA_def_pointer(func, "scene", "Scene", "", "Overrides the 
scene from which image parameters are taken.");
+
+               parm = RNA_def_float_array(func, "layout", 12, default_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);
+}
+
+#endif

Modified: trunk/blender/source/blender/render/extern/include/RE_pipeline.h
===================================================================

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to