Advertisement
Guest User

rigify example type

a guest
Aug 10th, 2021
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.21 KB | None | 0 0
  1. import bpy
  2. from rigify.base_rig import stage, BaseRig
  3. import rigify.utils as utils
  4.  
  5. class Rig(BaseRig):
  6.  
  7.     def generate_bbone(self, name):
  8.         #create bone
  9.         bone_name = self.copy_bone(name, utils.naming.make_derived_name(name, 'def'))
  10.  
  11.         #set bbone stuff
  12.         bone = self.get_bone(bone_name)
  13.         bone.bbone_segments = self.params.example_bb_segs
  14.  
  15.         return bone_name
  16.  
  17.     def generate_control(self, name):
  18.         #create bone
  19.         bone_name = self.copy_bone(name, utils.naming.make_derived_name(name, 'ctrl'))
  20.  
  21.         #set orientation and size
  22.         utils.bones.align_bone_to_axis(self.obj, bone_name, 'y', length=self.scale)
  23.         return bone_name
  24.  
  25.     def generate_control_chain(self, names, include_head, include_tail):
  26.         if include_head:
  27.             chain_names = [self.generate_control(b) for b in names]
  28.         else:
  29.             chain_names = [self.generate_control(b) for b in names[1:]]
  30.         if include_tail:
  31.             chain_names.append(self.generate_control(names[-1]))
  32.             utils.bones.put_bone(self.obj, chain_names[-1], self.get_bone(names[-1]).tail)
  33.         return chain_names
  34.  
  35.     def initialize(self):
  36.         self.scale = self.get_bone(self.base_bone).length * 0.25
  37.  
  38.     @stage.generate_bones
  39.     def generate_chain_bones(self):
  40.         base_chain = [self.base_bone] + utils.connected_children_names(self.obj, self.base_bone)
  41.         self.bones.deform = [self.generate_bbone(b) for b in base_chain]
  42.         self.bones.ctrl = self.generate_control_chain(base_chain, True, True)
  43.        
  44.     @stage.parent_bones
  45.     def set_bone_relations(self):
  46.         self.parent_bone_chain(self.bones.deform, use_connect=True, inherit_scale="NONE")
  47.    
  48.     @stage.configure_bones
  49.     def set_layers(self):
  50.         Rig.tweak.assign_rig(self, self.bones.ctrl)
  51.  
  52.     @stage.rig_bones
  53.     def add_constraints_and_drivers(self):
  54.         prop_b = self.bones.ctrl[0]
  55.         self.make_property(prop_b, 'stretch', default=1.0, min=0.0, max=1.0)
  56.  
  57.         panel = self.script.panel_with_selected_check(self, self.bones.ctrl)
  58.         panel.custom_prop (prop_b, 'stretch', text='stretch', slider=True)
  59.  
  60.         for ctrl, deform in zip(self.bones.ctrl[1:], self.bones.deform):
  61.             self.make_constraint(deform, "DAMPED_TRACK", ctrl)
  62.             self.make_constraint(deform, "STRETCH_TO", ctrl, name=f'{deform}_stretch')
  63.             self.make_driver(self.get_bone(deform).constraints[f'{deform}_stretch'], "influence", variables=[(prop_b, 'stretch')])
  64.        
  65.         for b, c1, c2 in zip(self.bones.deform, self.bones.ctrl, self.bones.ctrl[1:]):
  66.             self.make_driver(self.get_bone(b), 'bbone_scaleinx', variables=[utils.mechanism.driver_var_transform(self.obj, c1, type='SCALE_X', space='WORLD')])
  67.             self.make_driver(self.get_bone(b), 'bbone_scaleiny', variables=[utils.mechanism.driver_var_transform(self.obj, c1, type='SCALE_Y', space='WORLD')])
  68.             self.make_driver(self.get_bone(b), 'bbone_scaleoutx', variables=[utils.mechanism.driver_var_transform(self.obj, c2, type='SCALE_X', space='WORLD')])
  69.             self.make_driver(self.get_bone(b), 'bbone_scaleouty', variables=[utils.mechanism.driver_var_transform(self.obj, c2, type='SCALE_Y', space='WORLD')])
  70.  
  71.    
  72.     @stage.generate_widgets
  73.     def generate_control_widgets(self):
  74.         for ctrl in self.bones.ctrl:
  75.             utils.widgets_basic.create_cube_widget(self.obj, ctrl)
  76.    
  77.     @classmethod
  78.     def add_parameters(self, params):
  79.         """ Add the parameters of this rig type to the
  80.            RigifyParameters PropertyGroup
  81.        """
  82.        
  83.         params.example_bb_segs = bpy.props.IntProperty(
  84.             name        = 'B-Bone Segments',
  85.             default     = 3,
  86.             min         = 1,
  87.             description = 'Number of B-Bone segments'
  88.         )
  89.        
  90.         Rig.tweak.add_parameters(params)
  91.  
  92.     @classmethod
  93.     def parameters_ui(self, layout, params):
  94.         """ Create the ui for the rig parameters."""
  95.  
  96.         layout.row().prop(params, 'example_bb_segs')
  97.         Rig.tweak.parameters_ui(layout.row(), params)
  98.  
  99. Rig.tweak = utils.layers.ControlLayersOption('Tweak', description="Layers for the tweak controls to be on")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement