diff options
author | lijenstina <lijenstina@gmail.com> | 2018-03-03 12:02:03 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2018-03-03 12:02:03 +0300 |
commit | 85b618370f825e12a1a6412cf5c4fec053ac9f15 (patch) | |
tree | 689c7baa1095c70aecaa102652c3a8c811d5f5fe /add_advanced_objects_menu | |
parent | c68d4e3b5f803f33f0a88b563b644409a99569e4 (diff) |
Add Advanced Objects: CubeSter vertex color changes, small cleanup
Bump version to 1.1.6
Some style tweaks
activelatticeobject unregister code not needed, since it was removed
in the previous commit
CubeSter module:
- Address the vertex color changes using versioning, search for the
**bl_version** and **get_colors** pattern in the code
- Fix a missed property call during previous refactor
- Remove an unused variable
Diffstat (limited to 'add_advanced_objects_menu')
-rw-r--r-- | add_advanced_objects_menu/__init__.py | 363 | ||||
-rw-r--r-- | add_advanced_objects_menu/cubester.py | 111 |
2 files changed, 240 insertions, 234 deletions
diff --git a/add_advanced_objects_menu/__init__.py b/add_advanced_objects_menu/__init__.py index 46a3dffc..42a33445 100644 --- a/add_advanced_objects_menu/__init__.py +++ b/add_advanced_objects_menu/__init__.py @@ -25,7 +25,7 @@ bl_info = { "name": "Add Advanced Objects", "author": "Meta Androcto", - "version": (0, 1, 5), + "version": (0, 1, 6), "blender": (2, 78, 0), "location": "View3D > Add ", "description": "Add Object & Camera extras", @@ -55,7 +55,6 @@ if "bpy" in locals(): importlib.reload(arrange_on_curve) importlib.reload(mesh_easylattice) - else: from . import add_light_template from . import scene_objects_bi @@ -78,18 +77,18 @@ else: import bpy from bpy.types import ( - Menu, - AddonPreferences, - PropertyGroup, - ) + AddonPreferences, + Menu, + PropertyGroup, +) from bpy.props import ( - BoolProperty, - EnumProperty, - FloatProperty, - IntProperty, - StringProperty, - PointerProperty, - ) + BoolProperty, + EnumProperty, + FloatProperty, + IntProperty, + StringProperty, + PointerProperty, +) # Define the "Scenes" menu @@ -204,15 +203,15 @@ class AdvancedObjPreferences(AddonPreferences): bl_idname = __name__ show_menu_list = BoolProperty( - name="Menu List", - description="Show/Hide the Add Menu items", - default=False - ) + name="Menu List", + description="Show/Hide the Add Menu items", + default=False + ) show_panel_list = BoolProperty( - name="Panels List", - description="Show/Hide the Panel items", - default=False - ) + name="Panels List", + description="Show/Hide the Panel items", + default=False + ) def draw(self, context): layout = self.layout @@ -315,214 +314,214 @@ class AdvancedObjProperties(PropertyGroup): # cubester # main properties cubester_check_audio = BoolProperty( - name="", - default=False - ) + name="", + default=False + ) cubester_audio_image = EnumProperty( - name="Input Type", - items=(("image", "Image", - "Use an Image as input for generating Geometry", "IMAGE_COL", 0), - ("audio", "Audio", - "Use a Sound Strip as input for generating Geometry", "FILE_SOUND", 1)) - ) + name="Input Type", + items=(("image", "Image", + "Use an Image as input for generating Geometry", "IMAGE_COL", 0), + ("audio", "Audio", + "Use a Sound Strip as input for generating Geometry", "FILE_SOUND", 1)) + ) cubester_audio_file_length = IntProperty( - default=0 - ) + default=0 + ) # audio cubester_audio_path = StringProperty( - default="", - name="Audio File", - subtype="FILE_PATH", - update=find_audio_length - ) + default="", + name="Audio File", + subtype="FILE_PATH", + update=find_audio_length + ) cubester_audio_min_freq = IntProperty( - name="Minimum Frequency", - min=20, max=100000, - default=20 - ) + name="Minimum Frequency", + min=20, max=100000, + default=20 + ) cubester_audio_max_freq = IntProperty( - name="Maximum Frequency", - min=21, max=999999, - default=5000 - ) + name="Maximum Frequency", + min=21, max=999999, + default=5000 + ) cubester_audio_offset_type = EnumProperty( - name="Offset Type", - items=(("freq", "Frequency Offset", ""), - ("frame", "Frame Offset", "")), - description="Type of offset per row of mesh" - ) + name="Offset Type", + items=(("freq", "Frequency Offset", ""), + ("frame", "Frame Offset", "")), + description="Type of offset per row of mesh" + ) cubester_audio_frame_offset = IntProperty( - name="Frame Offset", - min=0, max=10, - default=2 - ) + name="Frame Offset", + min=0, max=10, + default=2 + ) cubester_audio_block_layout = EnumProperty( - name="Block Layout", - items=(("rectangle", "Rectangular", ""), - ("radial", "Radial", "")) - ) + name="Block Layout", + items=(("rectangle", "Rectangular", ""), + ("radial", "Radial", "")) + ) cubester_audio_width_blocks = IntProperty( - name="Width Block Count", - min=1, max=10000, - default=5 - ) + name="Width Block Count", + min=1, max=10000, + default=5 + ) cubester_audio_length_blocks = IntProperty( - name="Length Block Count", - min=1, max=10000, - default=50 - ) + name="Length Block Count", + min=1, max=10000, + default=50 + ) # image cubester_load_type = EnumProperty( - name="Image Input Type", - items=(("single", "Single Image", ""), - ("multiple", "Image Sequence", "")) - ) + name="Image Input Type", + items=(("single", "Single Image", ""), + ("multiple", "Image Sequence", "")) + ) cubester_image = StringProperty( - default="", - name="" - ) + default="", + name="" + ) cubester_load_image = StringProperty( - default="", - name="Load Image", - subtype="FILE_PATH", - update=adjust_selected_image - ) + default="", + name="Load Image", + subtype="FILE_PATH", + update=adjust_selected_image + ) cubester_skip_images = IntProperty( - name="Image Step", - min=1, max=30, - default=1, - description="Step from image to image by this number" - ) + name="Image Step", + min=1, max=30, + default=1, + description="Step from image to image by this number" + ) cubester_max_images = IntProperty( - name="Max Number Of Images", - min=2, max=1000, - default=10, - description="Maximum number of images to be used" - ) + name="Max Number Of Images", + min=2, max=1000, + default=10, + description="Maximum number of images to be used" + ) cubester_frame_step = IntProperty( - name="Frame Step Size", - min=1, max=10, - default=4, - description="The number of frames each picture is used" - ) + name="Frame Step Size", + min=1, max=10, + default=4, + description="The number of frames each picture is used" + ) cubester_skip_pixels = IntProperty( - name="Skip # Pixels", - min=0, max=256, - default=64, - description="Skip this number of pixels before placing the next" - ) + name="Skip # Pixels", + min=0, max=256, + default=64, + description="Skip this number of pixels before placing the next" + ) cubester_mesh_style = EnumProperty( - name="Mesh Type", - items=(("blocks", "Blocks", ""), - ("plane", "Plane", "")), - description="Compose mesh of multiple blocks or of a single plane" - ) + name="Mesh Type", + items=(("blocks", "Blocks", ""), + ("plane", "Plane", "")), + description="Compose mesh of multiple blocks or of a single plane" + ) cubester_block_style = EnumProperty( - name="Block Style", - items=(("size", "Vary Size", ""), - ("position", "Vary Position", "")), - description="Vary Z-size of block, or vary Z-position" - ) + name="Block Style", + items=(("size", "Vary Size", ""), + ("position", "Vary Position", "")), + description="Vary Z-size of block, or vary Z-position" + ) cubester_height_scale = FloatProperty( - name="Height Scale", - subtype="DISTANCE", - min=0.1, max=2, - default=0.2 - ) + name="Height Scale", + subtype="DISTANCE", + min=0.1, max=2, + default=0.2 + ) cubester_invert = BoolProperty( - name="Invert Height", - default=False - ) + name="Invert Height", + default=False + ) # general adjustments cubester_size_per_hundred_pixels = FloatProperty( - name="Size Per 100 Blocks/Points", - subtype="DISTANCE", - min=0.001, max=5, - default=1 - ) + name="Size Per 100 Blocks/Points", + subtype="DISTANCE", + min=0.001, max=5, + default=1 + ) # material based stuff cubester_materials = EnumProperty( - name="Material", - items=(("vertex", "Vertex Colors", ""), - ("image", "Image", "")), - description="Color with vertex colors, or uv unwrap and use an image" - ) + name="Material", + items=(("vertex", "Vertex Colors", ""), + ("image", "Image", "")), + description="Color with vertex colors, or uv unwrap and use an image" + ) cubester_use_image_color = BoolProperty( - name="Use Original Image Colors'?", - default=True, - description="Use original image colors, or replace with an another one" - ) + name="Use Original Image Colors'?", + default=True, + description="Use original image colors, or replace with an another one" + ) cubester_color_image = StringProperty( - default="", - name="" - ) + default="", + name="" + ) cubester_load_color_image = StringProperty( - default="", - name="Load Color Image", - subtype="FILE_PATH", - update=adjust_selected_color_image - ) + default="", + name="Load Color Image", + subtype="FILE_PATH", + update=adjust_selected_color_image + ) cubester_vertex_colors = {} # advanced cubester_advanced = BoolProperty( - name="Advanced Options", - default=False - ) + name="Advanced Options", + default=False + ) cubester_random_weights = BoolProperty( - name="Random Weights", - default=False - ) + name="Random Weights", + default=False + ) cubester_weight_r = FloatProperty( - name="Red", - subtype="FACTOR", - min=0.01, max=1.0, - default=0.25 - ) + name="Red", + subtype="FACTOR", + min=0.01, max=1.0, + default=0.25 + ) cubester_weight_g = FloatProperty( - name="Green", - subtype="FACTOR", - min=0.01, max=1.0, - default=0.25 - ) + name="Green", + subtype="FACTOR", + min=0.01, max=1.0, + default=0.25 + ) cubester_weight_b = FloatProperty( - name="Blue", - subtype="FACTOR", - min=0.01, max=1.0, - default=0.25 - ) + name="Blue", + subtype="FACTOR", + min=0.01, max=1.0, + default=0.25 + ) cubester_weight_a = FloatProperty( - name="Alpha", - subtype="FACTOR", - min=0.01, max=1.0, - default=0.25 - ) + name="Alpha", + subtype="FACTOR", + min=0.01, max=1.0, + default=0.25 + ) # arrange_on_curve arrange_c_use_selected = BoolProperty( - name="Use Selected", - description="Use the selected objects to duplicate", - default=True, - ) + name="Use Selected", + description="Use the selected objects to duplicate", + default=True, + ) arrange_c_obj_arranjar = StringProperty( - name="" - ) + name="" + ) arrange_c_select_type = EnumProperty( - name="Type", - description="Select object or group", - items=[ - ('O', "Object", "Make duplicates of a specific object"), - ('G', "Group", "Make duplicates of the objects in a group"), - ], - default='O', - ) + name="Type", + description="Select object or group", + items=[ + ('O', "Object", "Make duplicates of a specific object"), + ('G', "Group", "Make duplicates of the objects in a group"), + ], + default='O', + ) def register(): bpy.utils.register_module(__name__) bpy.types.Scene.advanced_objects = PointerProperty( - type=AdvancedObjProperties - ) + type=AdvancedObjProperties + ) # Add "Extras" menu to the "Add" menu bpy.types.INFO_MT_add.append(menu) @@ -543,10 +542,6 @@ def unregister(): bpy.utils.unregister_module(__name__) del bpy.types.Scene.advanced_objects - # cleanup Easy Lattice Scene Property if it was created - if hasattr(bpy.types.Scene, "activelatticeobject"): - del bpy.types.Scene.activelatticeobject - if __name__ == "__main__": register() diff --git a/add_advanced_objects_menu/cubester.py b/add_advanced_objects_menu/cubester.py index f1a8f581..87322f4f 100644 --- a/add_advanced_objects_menu/cubester.py +++ b/add_advanced_objects_menu/cubester.py @@ -25,28 +25,28 @@ bl_info = { "name": "CubeSter", "author": "Jacob Morris", - "version": (0, 7, 1), + "version": (0, 7, 2), "blender": (2, 78, 0), "location": "View 3D > Toolbar > CubeSter", "description": "Takes image, image sequence, or audio file and converts it " "into a height map based on pixel color and alpha values", "category": "Add Mesh" - } +} import bpy import bmesh from bpy.types import ( - Operator, - Panel, - ) + Operator, + Panel, +) import timeit from random import uniform from math import radians from os import ( - path, - listdir, - ) + path, + listdir, +) # create block at center position x, y with block width 2 * hx and 2 * hy and height of h @@ -146,18 +146,18 @@ def create_material(scene, ob, name): if adv_obj.cubester_materials == "image": mat.node_tree.links.new( - nodes["Image Texture"].outputs[0], - nodes["Diffuse BSDF"].inputs[0] - ) + nodes["Image Texture"].outputs[0], + nodes["Diffuse BSDF"].inputs[0] + ) mat.node_tree.links.new( - nodes["Texture Coordinate"].outputs[2], - nodes["Image Texture"].inputs[0] - ) + nodes["Texture Coordinate"].outputs[2], + nodes["Image Texture"].inputs[0] + ) else: mat.node_tree.links.new( - nodes["Attribute"].outputs[0], - nodes["Diffuse BSDF"].inputs[0] - ) + nodes["Attribute"].outputs[0], + nodes["Diffuse BSDF"].inputs[0] + ) else: if adv_obj.cubester_materials == "image" or scene.render.engine != "BLENDER_RENDER": tex = bpy.data.textures.new("CubeSter_" + name, "IMAGE") @@ -177,9 +177,11 @@ def create_mesh_from_audio(self, scene, verts, faces): audio_filepath = adv_obj.cubester_audio_path width = adv_obj.cubester_audio_width_blocks length = adv_obj.cubester_audio_length_blocks - size_per_hundred = adv_obj.cubester_size_per_hundred_pixels + size_per_hundred = adv_obj.cubester_size_per_hundred_pixels size = size_per_hundred / 100 + # Note: used for compatibility with vertex colors changes + bl_version = bool(bpy.app.version >= (2, 79, 1)) # create all blocks y = -(width / 2) * size + (size / 2) @@ -212,7 +214,8 @@ def create_mesh_from_audio(self, scene, verts, faces): # go through each column, step by appropriate amount for column in range(0, picture.size[0] * 4, 4 + skip_x * 4): r, g, b, a = get_pixel_values(picture, pixels, row, column) - vert_colors += [(r, g, b) for i in range(24)] + get_colors = (r, g, b, a) if bl_version else (r, g, b) + vert_colors += [get_colors for i in range(24)] bpy.ops.mesh.vertex_color_add() @@ -244,7 +247,8 @@ def create_mesh_from_audio(self, scene, verts, faces): for row in range(0, picture.size[1], skip_y + 1): for column in range(0, picture.size[0] * 4, 4 + skip_x * 4): r, g, b, a = get_pixel_values(picture, pixels, row, column) - frame_colors += [(r, g, b) for i in range(24)] + get_colors = (r, g, b, a) if bl_version else (r, g, b) + frame_colors += [get_colors for i in range(24)] frames_vert_colors.append(frame_colors) @@ -354,6 +358,8 @@ def create_mesh_from_image(self, scene, verts, faces): adv_obj = scene.advanced_objects picture = bpy.data.images[adv_obj.cubester_image] pixels = list(picture.pixels) + # Note: used for compatibility with vertex colors changes + bl_version = bool(bpy.app.version >= (2, 79, 1)) x_pixels = picture.size[0] / (adv_obj.cubester_skip_pixels + 1) y_pixels = picture.size[1] / (adv_obj.cubester_skip_pixels + 1) @@ -367,7 +373,6 @@ def create_mesh_from_image(self, scene, verts, faces): y = -height / 2 + half_width vert_colors = [] - weights = [uniform(0.0, 1.0) for i in range(4)] # random weights rows = 0 # go through each row of pixels stepping by adv_obj.cubester_skip_pixels + 1 @@ -377,16 +382,17 @@ def create_mesh_from_image(self, scene, verts, faces): # go through each column, step by appropriate amount for column in range(0, picture.size[0] * 4, 4 + adv_obj.cubester_skip_pixels * 4): r, g, b, a = get_pixel_values(picture, pixels, row, column) + get_colors = (r, g, b, a) if bl_version else (r, g, b) h = find_point_height(r, g, b, a, scene) # if not transparent if h != -1: if adv_obj.cubester_mesh_style == "blocks": create_block(x, y, half_width, h, verts, faces) - vert_colors += [(r, g, b) for i in range(24)] + vert_colors += [get_colors for i in range(24)] else: verts += [(x, y, h)] - vert_colors += [(r, g, b) for i in range(4)] + vert_colors += [get_colors for i in range(4)] x += step y += step @@ -464,14 +470,15 @@ def create_mesh_from_image(self, scene, verts, faces): for row in range(0, picture.size[1], adv_obj.cubester_skip_pixels + 1): for column in range(0, picture.size[0] * 4, 4 + adv_obj.cubester_skip_pixels * 4): r, g, b, a = get_pixel_values(picture, pixels, row, column) + get_colors = (r, g, b, a) if bl_version else (r, g, b) h = find_point_height(r, g, b, a, scene) if h != -1: frame_heights.append(h) if adv_obj.cubester_mesh_style == "blocks": - frame_colors += [(r, g, b) for i in range(24)] + frame_colors += [get_colors for i in range(24)] else: - frame_colors += [(r, g, b) for i in range(4)] + frame_colors += [get_colors for i in range(4)] if adv_obj.cubester_mesh_style == "plane": del vert_colors[len(vert_colors) - 4:len(vert_colors)] @@ -482,24 +489,24 @@ def create_mesh_from_image(self, scene, verts, faces): # determine what data to use if adv_obj.cubester_materials == "vertex" or scene.render.engine == "BLENDER_ENGINE": adv_obj.cubester_vertex_colors[ob.name] = { - "type": "vertex", "frames": frames_vert_colors, - "frame_skip": adv_obj.cubester_frame_step, - "total_images": max_images - } + "type": "vertex", "frames": frames_vert_colors, + "frame_skip": adv_obj.cubester_frame_step, + "total_images": max_images + } else: adv_obj.cubester_vertex_colors[ob.name] = { - "type": "image", "frame_skip": scene.cubester_frame_step, - "total_images": max_images - } + "type": "image", "frame_skip": adv_obj.cubester_frame_step, + "total_images": max_images + } att = get_image_node(ob.data.materials[0]) att.image_user.frame_duration = len(frames) * adv_obj.cubester_frame_step # animate mesh create_f_curves( - mesh, frames, - adv_obj.cubester_frame_step, - adv_obj.cubester_mesh_style - ) + mesh, frames, + adv_obj.cubester_frame_step, + adv_obj.cubester_mesh_style + ) # generate uv map for object @@ -879,11 +886,12 @@ class CubeSterPanel(Panel): class CubeSter(Operator): bl_idname = "mesh.cubester" - bl_label = "Generate Mesh" + bl_label = "Generate CubeSter Mesh" bl_description = "Generate a mesh from an Image or Sound File" bl_options = {"REGISTER", "UNDO"} def execute(self, context): + verts, faces = [], [] start = timeit.default_timer() @@ -901,7 +909,8 @@ class CubeSter(Operator): return {"CANCELLED"} else: if (adv_obj.cubester_audio_path != "" and - path.isfile(adv_obj.cubester_audio_path) and adv_obj.cubester_check_audio is True): + path.isfile(adv_obj.cubester_audio_path) and + adv_obj.cubester_check_audio is True): create_mesh_from_audio(self, scene, verts, faces) created = adv_obj.cubester_audio_file_length @@ -913,19 +922,21 @@ class CubeSter(Operator): stop = timeit.default_timer() if adv_obj.cubester_mesh_style == "blocks" or adv_obj.cubester_audio_image == "audio": - self.report({"INFO"}, - "CubeSter: {} blocks and {} frame(s) " - "in {}s".format(str(int(len(verts) / 8)), - str(created), - str(round(stop - start, 4))) - ) + self.report( + {"INFO"}, + "CubeSter: {} blocks and {} frame(s) " + "in {}s".format(str(int(len(verts) / 8)), + str(created), + str(round(stop - start, 4))) + ) else: - self.report({"INFO"}, - "CubeSter: {} points and {} frame(s) " - "in {}s" .format(str(len(verts)), - str(created), - str(round(stop - start, 4))) - ) + self.report( + {"INFO"}, + "CubeSter: {} points and {} frame(s) " + "in {}s" .format(str(len(verts)), + str(created), + str(round(stop - start, 4))) + ) return {"FINISHED"} |