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/makesrna/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/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_texture.c | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_texture_api.c | 95 |
5 files changed, 105 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index cc7bcf04716..6b042a987e3 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -100,6 +100,7 @@ set(APISRC 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 diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index b95bd2b2087..d0dea41b384 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -2417,7 +2417,7 @@ typedef struct RNAProcessItem { 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}, diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index c0ae7b02b1a..955e56193c6 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -260,6 +260,7 @@ void RNA_api_wm(struct StructRNA *srna); 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); diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index 0ecc41d80d8..a1ce77b061d 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -664,6 +664,13 @@ static void rna_def_environment_map(BlenderRNA *brna) 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[] = { diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c new file mode 100644 index 00000000000..f83caca3944 --- /dev/null +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -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 |