diff options
author | CansecoGPC <machaquiro@yahoo.es> | 2019-12-09 16:42:04 +0300 |
---|---|---|
committer | CansecoGPC <machaquiro@yahoo.es> | 2019-12-09 16:42:04 +0300 |
commit | 75af6e5dcf84cc2d2693374a01ecbad0f874701b (patch) | |
tree | 86d5ad098857a591e9f997881d762e839b33e98a /amaranth/misc | |
parent | 395ca8a4be7a66c72a5556c51f958644601a846b (diff) |
Amaranth: Add back from addons contrib
Diffstat (limited to 'amaranth/misc')
-rw-r--r-- | amaranth/misc/__init__.py | 0 | ||||
-rw-r--r-- | amaranth/misc/color_management.py | 84 | ||||
-rw-r--r-- | amaranth/misc/dupli_group_id.py | 197 | ||||
-rw-r--r-- | amaranth/misc/sequencer_extra_info.py | 67 | ||||
-rw-r--r-- | amaranth/misc/toggle_wire.py | 134 |
5 files changed, 482 insertions, 0 deletions
diff --git a/amaranth/misc/__init__.py b/amaranth/misc/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/amaranth/misc/__init__.py diff --git a/amaranth/misc/color_management.py b/amaranth/misc/color_management.py new file mode 100644 index 00000000..72ad4bb2 --- /dev/null +++ b/amaranth/misc/color_management.py @@ -0,0 +1,84 @@ +# 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. +""" +Color Management Presets + +Save your Color Management options as presets, for easy re-use. + +It will pretty much every option in the Color Management panel, such as +the look, color settings, and so on. Except the curve points (have to +figure out how to do that nicely), good news is that in Blender 2.69+ you +can now copy/paste curves. +""" + +import bpy +from bl_operators.presets import AddPresetBase + + +class AMTH_SCENE_MT_color_management_presets(bpy.types.Menu): + + """List of Color Management presets""" + bl_label = "Color Management Presets" + preset_subdir = "color" + preset_operator = "script.execute_preset" + draw = bpy.types.Menu.draw_preset + + +class AMTH_AddPresetColorManagement(AddPresetBase, bpy.types.Operator): + + """Add or remove a Color Management preset""" + bl_idname = "scene.color_management_preset_add" + bl_label = "Add Color Management Preset" + preset_menu = "AMTH_SCENE_MT_color_management_presets" + + preset_defines = [ + "scene = bpy.context.scene", + ] + + preset_values = [ + "scene.view_settings.view_transform", + "scene.display_settings.display_device", + "scene.view_settings.exposure", + "scene.view_settings.gamma", + "scene.view_settings.look", + "scene.view_settings.use_curve_mapping", + "scene.sequencer_colorspace_settings.name", + ] + + preset_subdir = "color" + + +def ui_color_management_presets(self, context): + + layout = self.layout + + row = layout.row(align=True) + row.menu("AMTH_SCENE_MT_color_management_presets", + text=bpy.types.AMTH_SCENE_MT_color_management_presets.bl_label) + row.operator("scene.color_management_preset_add", text="", icon="ZOOM_IN") + row.operator("scene.color_management_preset_add", + text="", icon="ZOOM_OUT").remove_active = True + layout.separator() + + +def register(): + bpy.utils.register_class(AMTH_AddPresetColorManagement) + bpy.utils.register_class(AMTH_SCENE_MT_color_management_presets) + bpy.types.RENDER_PT_color_management.prepend(ui_color_management_presets) + + +def unregister(): + bpy.utils.unregister_class(AMTH_AddPresetColorManagement) + bpy.utils.unregister_class(AMTH_SCENE_MT_color_management_presets) + bpy.types.RENDER_PT_color_management.remove(ui_color_management_presets) diff --git a/amaranth/misc/dupli_group_id.py b/amaranth/misc/dupli_group_id.py new file mode 100644 index 00000000..05fa7129 --- /dev/null +++ b/amaranth/misc/dupli_group_id.py @@ -0,0 +1,197 @@ +# 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. +""" +Object ID for Dupli Groups +Say you have a linked character or asset, you can now set an Object ID for the +entire instance (the objects in the group), and use it with the Object Index +pass later in compositing. Something that I always wanted and it wasn't +possible! + +In order for the Object ID to be loaded afterwards on computers without +Amaranth installed, it will automatically create a text file (called +AmaranthStartup.py) and save it inside the .blend, this will autorun on +startup and set the OB IDs. Remember to have auto-run python scripts on your +startup preferences. + +Set a Pass Index and press "Apply Object ID to Duplis" on the Relations panel, +Object Properties. +""" + + +import bpy +from amaranth.scene.debug import AMTH_SCENE_OT_blender_instance_open + + +# Some settings are bound to be saved on a startup py file +# TODO: refactor this, amth_text should not be declared as a global variable, +# otherwise becomes confusing when you call it in the classes below. +def amaranth_text_startup(context): + + amth_text_name = "AmaranthStartup.py" + amth_text_exists = False + + global amth_text + + try: + if bpy.data.texts: + for tx in bpy.data.texts: + if tx.name == amth_text_name: + amth_text_exists = True + amth_text = bpy.data.texts[amth_text_name] + break + else: + amth_text_exists = False + + if not amth_text_exists: + bpy.ops.text.new() + amth_text = bpy.data.texts[((len(bpy.data.texts) * -1) + 1)] + amth_text.name = amth_text_name + amth_text.write("# Amaranth Startup Script\nimport bpy\n") + amth_text.use_module = True + + return amth_text_exists + except AttributeError: + return None + + +# FEATURE: Dupli Group Path +def ui_dupli_group_library_path(self, context): + + ob = context.object + + row = self.layout.row() + row.alignment = "LEFT" + + if ob and ob.instance_collection and ob.instance_collection.library: + lib = ob.instance_collection.library.filepath + + row.operator(AMTH_SCENE_OT_blender_instance_open.bl_idname, + text="Library: %s" % lib, + emboss=False, + icon="LINK_BLEND").filepath = lib +# // FEATURE: Dupli Group Path + + +# FEATURE: Object ID for objects inside DupliGroups +class AMTH_OBJECT_OT_id_dupligroup(bpy.types.Operator): + + """Set the Object ID for objects in the dupli group""" + bl_idname = "object.amaranth_object_id_duplis" + bl_label = "Apply Object ID to Duplis" + + clear = False + + @classmethod + def poll(cls, context): + return context.active_object.instance_collection + + def execute(self, context): + self.__class__.clear = False + ob = context.active_object + amaranth_text_startup(context) + script_exists = False + script_intro = "# OB ID: %s" % ob.name + obdata = 'bpy.data.objects[" % s"]' % ob.name + # TODO: cleanup script var using format or template strings + script = "%s" % ( + "\nif %(obdata)s and %(obdata)s.instance_collection and %(obdata)s.pass_index != 0: %(obname)s \n" + " for dob in %(obdata)s.instance_collection.objects: %(obname)s \n" + " dob.pass_index = %(obdata)s.pass_index %(obname)s \n" % + {"obdata": obdata, "obname": script_intro}) + + for txt in bpy.data.texts: + if txt.name == amth_text.name: + for li in txt.lines: + if script_intro == li.body: + script_exists = True + continue + + if not script_exists: + amth_text.write("\n") + amth_text.write(script_intro) + amth_text.write(script) + + if ob and ob.instance_collection: + if ob.pass_index != 0: + for dob in ob.instance_collection.objects: + dob.pass_index = ob.pass_index + + self.report({"INFO"}, + "%s ID: %s to all objects in this Dupli Group" % ( + "Applied" if not script_exists else "Updated", + ob.pass_index)) + + return {"FINISHED"} + + +class AMTH_OBJECT_OT_id_dupligroup_clear(bpy.types.Operator): + + """Clear the Object ID from objects in dupli group""" + bl_idname = "object.amaranth_object_id_duplis_clear" + bl_label = "Clear Object ID from Duplis" + + @classmethod + def poll(cls, context): + return context.active_object.instance_collection + + def execute(self, context): + context.active_object.pass_index = 0 + AMTH_OBJECT_OT_id_dupligroup.clear = True + amth_text_exists = amaranth_text_startup(context) + match_first = "# OB ID: %s" % context.active_object.name + + if amth_text_exists: + for txt in bpy.data.texts: + if txt.name == amth_text.name: + for li in txt.lines: + if match_first in li.body: + li.body = "" + continue + + self.report({"INFO"}, "Object IDs back to normal") + return {"FINISHED"} + + +def ui_object_id_duplis(self, context): + + if context.active_object.instance_collection: + split = self.layout.split() + row = split.row(align=True) + row.enabled = context.active_object.pass_index != 0 + row.operator( + AMTH_OBJECT_OT_id_dupligroup.bl_idname) + row.operator( + AMTH_OBJECT_OT_id_dupligroup_clear.bl_idname, + icon="X", text="") + split.separator() + + if AMTH_OBJECT_OT_id_dupligroup.clear: + self.layout.label(text="Next time you save/reload this file, " + "object IDs will be back to normal", + icon="INFO") +# // FEATURE: Object ID for objects inside DupliGroups + + +def register(): + bpy.utils.register_class(AMTH_OBJECT_OT_id_dupligroup) + bpy.utils.register_class(AMTH_OBJECT_OT_id_dupligroup_clear) + bpy.types.OBJECT_PT_instancing.append(ui_dupli_group_library_path) + bpy.types.OBJECT_PT_relations.append(ui_object_id_duplis) + + +def unregister(): + bpy.utils.unregister_class(AMTH_OBJECT_OT_id_dupligroup) + bpy.utils.unregister_class(AMTH_OBJECT_OT_id_dupligroup_clear) + bpy.types.OBJECT_PT_instancing.remove(ui_dupli_group_library_path) + bpy.types.OBJECT_PT_relations.remove(ui_object_id_duplis) diff --git a/amaranth/misc/sequencer_extra_info.py b/amaranth/misc/sequencer_extra_info.py new file mode 100644 index 00000000..2d5d6b79 --- /dev/null +++ b/amaranth/misc/sequencer_extra_info.py @@ -0,0 +1,67 @@ +# 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. +# 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. +""" +Sequencer: Display Image File Name + +When seeking through an image sequence, display the active strips' file name +for the current frame, and it's [playhead]. + +Find it on the VSE header. +""" +import bpy + + +# FEATURE: Sequencer Extra Info +def act_strip(context): + try: + return context.scene.sequence_editor.active_strip + except AttributeError: + return None + + +def ui_sequencer_extra_info(self, context): + layout = self.layout + strip = act_strip(context) + if strip: + seq_type = strip.type + if seq_type and seq_type == 'IMAGE': + elem = strip.strip_elem_from_frame(context.scene.frame_current) + if elem: + layout.label( + text="%s %s" % + (elem.filename, "[%s]" % + (context.scene.frame_current - strip.frame_start))) + +# // FEATURE: Sequencer Extra Info + + +def register(): + bpy.types.SEQUENCER_HT_header.append(ui_sequencer_extra_info) + + +def unregister(): + bpy.types.SEQUENCER_HT_header.remove(ui_sequencer_extra_info) diff --git a/amaranth/misc/toggle_wire.py b/amaranth/misc/toggle_wire.py new file mode 100644 index 00000000..3d43660d --- /dev/null +++ b/amaranth/misc/toggle_wire.py @@ -0,0 +1,134 @@ +# 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. + +import bpy + + +# FEATURE: Toggle Wire Display +class AMTH_OBJECT_OT_wire_toggle(bpy.types.Operator): + + """Turn on/off wire display on mesh objects""" + bl_idname = "object.amth_wire_toggle" + bl_label = "Display Wireframe" + bl_options = {"REGISTER", "UNDO"} + + clear: bpy.props.BoolProperty( + default=False, name="Clear Wireframe", + description="Clear Wireframe Display") + + def execute(self, context): + + scene = context.scene + is_all_scenes = scene.amth_wire_toggle_scene_all + is_selected = scene.amth_wire_toggle_is_selected + is_all_edges = scene.amth_wire_toggle_edges_all + is_optimal = scene.amth_wire_toggle_optimal + clear = self.clear + + if is_all_scenes: + which = bpy.data.objects + elif is_selected: + if not context.selected_objects: + self.report({"INFO"}, "No selected objects") + which = context.selected_objects + else: + which = scene.objects + + if which: + for ob in which: + if ob and ob.type in { + "MESH", "EMPTY", "CURVE", + "META", "SURFACE", "FONT"}: + + ob.show_wire = False if clear else True + ob.show_all_edges = is_all_edges + + for mo in ob.modifiers: + if mo and mo.type == "SUBSURF": + mo.show_only_control_edges = is_optimal + + return {"FINISHED"} + + +def ui_object_wire_toggle(self, context): + + scene = context.scene + + self.layout.separator() + col = self.layout.column(align=True) + col.label(text="Wireframes:") + row = col.row(align=True) + row.operator(AMTH_OBJECT_OT_wire_toggle.bl_idname, + icon="MOD_WIREFRAME", text="Display").clear = False + row.operator(AMTH_OBJECT_OT_wire_toggle.bl_idname, + icon="X", text="Clear").clear = True + col.separator() + row = col.row(align=True) + row.prop(scene, "amth_wire_toggle_edges_all") + row.prop(scene, "amth_wire_toggle_optimal") + row = col.row(align=True) + sub = row.row(align=True) + sub.active = not scene.amth_wire_toggle_scene_all + sub.prop(scene, "amth_wire_toggle_is_selected") + sub = row.row(align=True) + sub.active = not scene.amth_wire_toggle_is_selected + sub.prop(scene, "amth_wire_toggle_scene_all") + + +def init_properties(): + scene = bpy.types.Scene + scene.amth_wire_toggle_scene_all = bpy.props.BoolProperty( + default=False, + name="All Scenes", + description="Toggle wire on objects in all scenes") + scene.amth_wire_toggle_is_selected = bpy.props.BoolProperty( + default=False, + name="Only Selected Objects", + description="Only toggle wire on selected objects") + scene.amth_wire_toggle_edges_all = bpy.props.BoolProperty( + default=True, + name="Draw All Edges", + description="Draw all the edges even on coplanar faces") + scene.amth_wire_toggle_optimal = bpy.props.BoolProperty( + default=False, + name="Subsurf Optimal Display", + description="Skip drawing/rendering of interior subdivided edges " + "on meshes with Subdivision Surface modifier") + + +def clear_properties(): + props = ( + 'amth_wire_toggle_is_selected', + 'amth_wire_toggle_scene_all', + "amth_wire_toggle_edges_all", + "amth_wire_toggle_optimal" + ) + wm = bpy.context.window_manager + for p in props: + if p in wm: + del wm[p] + +# //FEATURE: Toggle Wire Display + + +def register(): + init_properties() + bpy.utils.register_class(AMTH_OBJECT_OT_wire_toggle) + bpy.types.VIEW3D_PT_view3d_properties.append(ui_object_wire_toggle) + + +def unregister(): + bpy.utils.unregister_class(AMTH_OBJECT_OT_wire_toggle) + bpy.types.VIEW3D_PT_view3d_properties.remove(ui_object_wire_toggle) + clear_properties() |