diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-03-07 00:47:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-03-07 00:47:16 +0300 |
commit | 3838b80cf1cfe0a340a8471732bc86fde2852c29 (patch) | |
tree | 2f49637004aee3b734abca6fbaefd63f385dd93b | |
parent | 782cb1f0e0d9c019bfb7b9391ffa4b827ed1aa6f (diff) |
re-project + gimp integration, now its easy to edit the view in the gimp and apply the projection back without manually opening and saving files.
-rw-r--r-- | release/scripts/op/image.py | 95 | ||||
-rw-r--r-- | release/scripts/ui/space_view3d_toolbar.py | 11 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_image.c | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 12 |
4 files changed, 117 insertions, 6 deletions
diff --git a/release/scripts/op/image.py b/release/scripts/op/image.py index f60902e1832..be60bb96313 100644 --- a/release/scripts/op/image.py +++ b/release/scripts/op/image.py @@ -42,12 +42,103 @@ class SaveDirty(bpy.types.Operator): return {'FINISHED'} +_proj_hack = [""] +class ProjectEdit(bpy.types.Operator): + '''Select object matching a naming pattern''' + bl_idname = "image.project_edit" + bl_label = "Project Edit" + bl_options = {'REGISTER'} + + def execute(self, context): + import os + import subprocess + + EXT = "tga" # until we have a way to save as another format! + EDITOR = "gimp" # until we have a way to set a default image edior + + for image in bpy.data.images: + image.tag = True + + bpy.ops.paint.image_from_view() + + image_new = None + for image in bpy.data.images: + if not image.tag: + image_new = image + break + + if not image_new: + self.report({'ERROR'}, "Could not make new image") + return {'CANCELLED'} + + filename = os.path.basename(bpy.data.filename) + filename = os.path.splitext(filename)[0] + + if filename.startswith("."): # TODO, have a way to check if the file is saved, assuem .B25.blend + filename = os.path.join(os.path.dirname(bpy.data.filename), filename) + else: + filename = "//" + filename + + obj = context.object + + if obj: + filename += "_" + bpy.utils.clean_name(obj.name) + + filename_final = filename + "." + EXT + i = 0 + + while os.path.exists(bpy.utils.expandpath(filename_final)): + filename_final = filename + ("%.3d.%s" % (i, EXT)) + i += 1 + + image_new.name = os.path.basename(filename_final) + _proj_hack[0] = image_new.name + + image_new.filename_raw = filename_final # TODO, filename raw is crummy + image_new.save() + + subprocess.Popen([EDITOR, bpy.utils.expandpath(filename_final)]) + + return {'FINISHED'} + + +class ProjectApply(bpy.types.Operator): + '''Select object matching a naming pattern''' + bl_idname = "image.project_apply" + bl_label = "Project Apply" + bl_options = {'REGISTER'} + + def execute(self, context): + image_name = _proj_hack[0] # TODO, deal with this nicer + + try: + image = bpy.data.images[_proj_hack[0]] + except KeyError: + self.report({'ERROR'}, "Could not find image '%s'" % image_name) + return {'CANCELLED'} + + image.reload() + bpy.ops.paint.project_image(image=image_name) + + return {'FINISHED'} + + +classes = [ + SaveDirty, + ProjectEdit, + ProjectApply] + + def register(): - bpy.types.register(SaveDirty) + register = bpy.types.register + for cls in classes: + register(cls) def unregister(): - bpy.types.unregister(SaveDirty) + unregister = bpy.types.unregister + for cls in classes: + unregister(cls) if __name__ == "__main__": register() diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index 7acb0537316..7996407445f 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -906,10 +906,15 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel): sub = col.column() sub.prop(ipaint, "seam_bleed") - + + row = col.row(align=True) + row.operator("image.project_edit", text="View Edit") + row.operator("image.project_apply", text="Apply") + sub = col.column() - col.operator("image.save_dirty", text="Save Edited") - col.operator("paint.project_image") + sub.operator("paint.project_image") + + sub.operator("image.save_dirty", text="Save Edited") class VIEW3D_MT_tools_projectpaint_clone(bpy.types.Menu): diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index e9eec9bf64a..8996ac078dd 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -280,6 +280,11 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Filename", "Image/Movie file name"); RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update"); + /* eek. this is horrible but needed so we can save to a new name without blanking the data :( */ + prop= RNA_def_property(srna, "filename_raw", PROP_STRING, PROP_FILEPATH); + RNA_def_property_string_sdna(prop, NULL, "name"); + RNA_def_property_ui_text(prop, "Filename", "Image/Movie file name (without data refreshing)"); + prop= RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, image_source_items); RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Image_source_itemf"); diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index f2dbc7ef23f..ef7fa3360d4 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -40,6 +40,7 @@ #include "BKE_packedFile.h" #include "BKE_main.h" #include "BKE_utildefines.h" +#include "BKE_global.h" /* grr: G.sce */ #include "IMB_imbuf.h" @@ -84,12 +85,21 @@ static void rna_Image_save(Image *image, ReportList *reports) { ImBuf *ibuf= BKE_image_get_ibuf(image, NULL); if(ibuf) { + char filename[FILE_MAXDIR + FILE_MAXFILE]; + BLI_strncpy(filename, image->name, sizeof(filename)); + BLI_convertstringcode(filename, G.sce); + if(image->packedfile) { if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) { BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could saved packed file to \"%s\"", image->id.name+2, image->name); } } - else if (IMB_saveiff(ibuf, image->name, ibuf->flags)) { + else if (IMB_saveiff(ibuf, filename, ibuf->flags)) { + image->type= IMA_TYPE_IMAGE; + + if(image->source==IMA_SRC_GENERATED) + image->source= IMA_SRC_FILE; + ibuf->userflags &= ~IB_BITMAPDIRTY; } else { |