def execute(self, context): # active = Get.active(context) mode = context.mode # pose = list() for rig in context.selected_objects: if (not Is.armature(rig)) or (rig.data.get('rig_id') is None): continue meta = New.object(context, name="metarig", data=rig.data.copy()) meta.data.animation_data_clear() metafy_rigify(context, meta) # pose.append(meta, rig) else: if context.mode != mode: bpy.ops.object.mode_set(mode=mode) # if mode == 'POSE': # Set.mode(context, 'OBJECT') # for (meta, rig) in pose: # Set.select(rig, True) # Set.select(meta, False) # if meta == active: # Set.active(context, rig) # if mode == 'POSE': # Set.mode(context, 'POSE') return {'FINISHED'}
def execute(self, context): if self.bones: bones = eval(self.bones) else: bones = Get.selected_pose_bones(context) if not bones: return {'CANCELLED'} wgts = readWidgets() if self.widget: widget = wgts[self.widget] else: widget = wgts[context.scene.widget_list] for bone in bones: if bone.id_data.proxy: continue slide = list(self.slide) rotate = list(self.rotate) if self.mirror: mirror = findMirrorObject(bone) if mirror and mirror in bones and bone.name.endswith( ('L', 'l')): slide[0] *= -1 rotate[1] *= -1 rotate[2] *= -1 createWidget( context, bone, widget, self.relative_size, self.global_size, [*self.scale], slide, rotate, get_collection(context), ) utils.update(context) pr = utils.prefs(__addon__).bone_widgets # pr = prefs.prefs().bone_widgets if pr.keep_settings: pr.slide = self.slide pr.rotate = self.rotate pr.relative_size = self.relative_size pr.global_size = self.global_size pr.scale = self.scale pr.mirror = self.mirror # Create new object then delete it. # When creating multiple widgets, if the last one tries to enter edit # mode before a particular update occurs, Blender will crash. # If the last object created (I.E. this empty) is not the widget, # Blender can enter edit mode without crash Get.objects(context, link=True).unlink(New.object(context)) return {'FINISHED'}
def empty(context, name="Empty", type='PLAIN_AXES', size=1.0, link=True): "Create a new empty object" empty = New.object(context, name, None, link) Set.empty_type(empty, type) Set.empty_size(empty, size) return empty
def camera(context, name="Camera", size=1.0, link=True): "Create a new camera object" data = bpy.data.cameras.new(name) obj = New.object(context, name=name, data=data, link=link) data.display_size = size return obj
def armature(context, name="Armature", display_type=None, link=True): "Create and return a rig object" data = bpy.data.armatures.new(name) # armature.show_in_front = True if display_type is not None: Set.armature_display_type(data, display_type) return New.object(context, name, data, link)
def curve(context, name="Spline IK", link=True): "Create a curve object" # Create curve data = bpy.data.curves.new(name, 'CURVE') # Setup curve's display settings data.dimensions = '3D' data.fill_mode = 'FULL' data.bevel_depth = 0.01 curve = New.object(context, name, data, link) if hasattr(curve, 'display_type'): # 2.8 curve.display_type = 'WIRE' elif hasattr(curve, 'draw_type'): # 2.7 curve.draw_type = 'WIRE' return curve
def execute(self, context): an = context.space.grease_pencil # context.space.grease_pencil = ob = New.object(context, name=an.name, data=an) ob.location.z = 0.5 ob.rotation_mode = 'XYZ' ob.rotation_euler.x = 1.5707963705062866 # Face front ob.scale = (0.001, ) * 3 an.stroke_thickness_space = 'SCREENSPACE' # Send the color from annotations to the grease pencil object for layer in an.layers: layer.tint_color = layer.channel_color layer.tint_factor = 1 """ In addition to not "currently" knowing where individual stroke colors are Setting them will take longer and override any manual colors I may use. Setting the tint color (which annotations can only used) is faster and easier """ return {'FINISHED'}
def execute_new(self, context): """ Either made this originally then scrapped for the simpler version above, or was making this then got distracted and never came back to it """ def sync(owner, target, *attribs): for attrib in attribs: try: setattr(target, attrib, getattr(owner, attrib)) except: print("Can't write", attrib, "in", target) gp = bpy.data.grease_pencils.new(name=an.name) New.object(context, name=an.name, data=gp) for alayer in an.layers: glayer = gp.layers.new(alayer.info) for aframe in alayer.frames: gframe = glayer.frames.new(aframe.frame_number) for astroke in aframe.strokes: gstroke = gframe.strokes.new() gstroke.points.add(len(astroke.points)) for (index, gpoint) in enumerate(gstroke.points): apoint = astroke.points[index] sync(apoint, gpoint, 'co', 'pressure', 'select', 'strength', 'uv_factor', 'uv_rotation') sync( astroke, gstroke, 'draw_cyclic', 'end_cap_mode', 'gradient_factor', 'gradient_shape', 'line_width', 'material_index', 'select', 'start_cap_mode', # 'groups', 'triangles' ) gstroke.display_mode = '3DSPACE' sync(aframe, gframe, 'frame_number', 'select') sync( alayer, glayer, # 'active_frame', 'annotation_hide', 'annotation_onion_after_color', 'annotation_onion_before_color', 'annotation_onion_after_range', 'annotation_onion_before_range', 'blend_mode', 'channel_color', 'color', 'hide', 'line_change', 'lock', 'lock_frame', 'lock_material', 'mask_layer', 'matrix_inverse', 'opacity', 'parent', 'parent_bone', 'parent_type', 'pass_index', 'select', 'show_in_front', 'show_points', 'thickness', 'tint_color', 'tint_factor', 'use_annotation_onion_skinning', 'use_onion_skinning', 'use_solo_mode', 'viewlayer_render') return {'FINISHED'}
def mesh(context, name='Mesh', type='PLANE', link=True, **kargs): "Create a box-mesh object" import bmesh from mathutils import Matrix # from bpy_extras.object_utils import AddObjectHelper width = kargs.get('width', 1.0) height = kargs.get('height', 1.0) depth = kargs.get('depth', 1.0) loc = kargs.get('loc', None) rot = kargs.get('rot', None) def gen_mesh(): """ This function takes inputs and returns vertex and face arrays. no actual mesh data creation is done here. """ if type == 'CUBE': left = -1.0 right = +1.0 top = +1.0 bottom = -1.0 front = -1.0 back = +1.0 verts = [ (right, front, top), # right-front-top (right, front, bottom), # right-front-bottom (left, front, bottom), # left-front-bottom (left, front, top), # left-front-top (right, back, top), # right-back-top (right, back, bottom), # right-back-bottom (left, back, bottom), # left-back-bottom (left, back, top), # left-back-top ] faces = [ (3, 2, 1, 0), (5, 6, 7, 4), (1, 5, 4, 0), (2, 6, 5, 1), (3, 7, 6, 2), (7, 3, 0, 4), # (3, 2, 1, 0), # # (4, 7, 6, 5), # # (0, 4, 5, 1), # # (1, 5, 6, 2), # # (2, 6, 7, 3), # # (4, 0, 3, 7), ] elif type == 'PLANE': left = -1.0 right = +1.0 top = +0.0 bottom = -0.0 front = -1.0 back = +1.0 # Plane verts = [ (left, back, bottom), # left-back-bottom (left, front, bottom), # left-front-bottom (right, front, bottom), # right-front-bottom (right, back, bottom), # right-back-bottom ] faces = [ (0, 1, 2, 3), # top ] elif type == 'POINT': verts = [(0, 0, 0)] faces = [] else: # null mesh verts = [] faces = [] # apply size if loc: for (dist, axis) in zip(loc, (0, 1, 2)): for i, v in enumerate(verts): verts[i] = list(verts[i]) verts[i][axis] += dist for i, v in enumerate(verts): verts[i] = v[0] * width, v[1] * depth, v[2] * height return (verts, faces) verts_loc, faces = gen_mesh() mesh = bpy.data.meshes.new(name) bm = bmesh.new() for v_co in verts_loc: bm.verts.new(v_co) # if loc: # bm.transform(Matrix().Translation(loc)) if rot: from zpy import utils bm.transform(utils.rotate_matrix(Matrix(), rot)) bm.verts.ensure_lookup_table() for f_idx in faces: bm.faces.new([bm.verts[i] for i in f_idx]) bm.to_mesh(mesh) mesh.update() # # add the mesh as an object into the scene with this utility module # from bpy_extras import object_utils # object_utils.object_data_add(context, mesh, operator=self) return New.object(context, name, mesh, link)
def update_pose(self, context): # for region in context.area.regions: # if region.type == 'WINDOW': # break # else: # return self.cancel(context) region = context.region rv3d = context.space_data.region_3d gp = context.annotation_data stroke = gp.layers.active.frames[0].strokes[0] for chain in Get.sorted_chains(context.selected_pose_bones): bone_chain = list() for bone in reversed(chain): bone_chain.insert(0, bone) if bone == chain[0]: # Do location pass # continue # or break; should do the same else: pass while bone.parent not in chain: # Do unselected in betweens bone = bone.parent if not Is.visible(context, bone): # Don't rotate hidden bones continue bone_chain.insert(0, bone) bcount = len(bone_chain) - 1 gcount = len(stroke.points) - 1 # if bcount: # while gcount > bcount * 3: # # Split point count in half # index = 0 # while index < len(stroke.points) - 1: # stroke.points.pop(index=index + 1) # index += 1 # print(bcount, gcount, '\t', index, len(stroke.points)) # gcount = len(stroke.points) - 1 bone_mats = list() con_tmp = list() index = 0 for bone in bone_chain: if index > bcount: index = bcount point_index = utils.scale_range(index, 0, bcount, 0, gcount) point = stroke.points[int(point_index)] if index == 0: if not (bone.parent): bone = bone_chain[0] point = stroke.points[0] to_2d = location_3d_to_region_2d( region, rv3d, point.co) # get 2d space of stroke if to_2d: to_3d = region_2d_to_location_3d( region, rv3d, to_2d, bone.head) # keep depth of bone empty = New.object(context, bone.name) empty.empty_display_size = 0.25 empty.location = to_3d con = bone.constraints.new('COPY_LOCATION') con.target = empty con_tmp.append((bone, con, empty)) if bcount == 0: point = stroke.points[-1] else: # index += 1 point_index = utils.scale_range( 0.5, 0, bcount, 0, gcount) point = stroke.points[int(point_index)] to_2d = location_3d_to_region_2d( region, rv3d, point.co) # get 2d space of stroke if to_2d: to_3d = region_2d_to_location_3d( region, rv3d, to_2d, bone.tail) # keep depth of bone empty = New.object(context, bone.name) empty.empty_display_size = 0.1 empty.location = to_3d con = bone.constraints.new('DAMPED_TRACK') con.target = empty con_tmp.append((bone, con, empty)) index += 1 utils.update(context) for (bone, con, empty) in reversed(con_tmp): mat = Get.matrix_constraints(context, bone) # mat = Get.matrix(bone) bone_mats.append((bone, mat)) bone.constraints.remove(con) Get.objects(context, link=True).unlink(empty) for (bone, mat) in bone_mats: Set.matrix(bone, mat) keyframe.keyingset(context, selected=[bone], skip_bones=True) self.remove_annotation(context) return {'FINISHED'}