Blender: Difference between revisions

5,155 bytes removed ,  1 May 2022
Moved all scripts to their own page as they have become obsolete
(→‎Animation rig with IK and FK: Updated one of the links)
(Moved all scripts to their own page as they have become obsolete)
Line 101: Line 101:


==Scripts==
==Scripts==
===Script for enabling/disabling constraints in selected objects===
We used a number of scripts for the purpose of making the [[Using_the_Rigify_animation_rig|Rigify-Oni rig]] usable, however, those scripts have become obsolete with the introduction of the BlenderOni plugin. They are nonetheless archived [[Obsolete_Blender_Scripts|HERE]] for legacy purposes.
This script allows the user to enable or disable constraints in the currently selected objects. This is done by checking the value of the first constraint in the first selected object, flipping it and setting it for all constraints in all objects. Usage is simple, just select your objects and run the script.
<pre>#ObjectConstraintEnabler
import bpy
body_parts = bpy.context.selected_objects  #All selected objects
 
#Search all objects in body parts for the first object with constraint.
for part in body_parts:
    if len(part.constraints)>0:
        if part.constraints[0].mute==0: #At this point, check if the first constraint in the bone is enabled or disabled...
            value=1 #...and set the value as invertion of that
        else:
            value=0
        break #Break the loop as we just need the first mute value we will run into
   
for body_part in body_parts:
    for con in body_part.constraints:
        con.mute = value</pre>
 
===Script for enabling/disabling bone constraints in the selected armature===
This script allows the user to enable or disable bone constraints in the currently selected armature. This is done by checking the value of the first bone constraint in the first bone of the selected armature, flipping it and setting it for all bone constraints in all bones. Usage is simple, just select your armature in the Object Mode and run the script.
<pre>#BoneConstraintEnabler
import bpy
body_part = bpy.context.selected_pose_bones_from_active_object #All bones in the rig
 
#Search all bones in body parts for the first bone with constraint.
for bone in body_part:
    if len(bone.constraints)>0:
        if bone.constraints[0].mute==0: #At this point, check if the first constraint in the bone is enabled or disabled...
            value=1 #...and set the value as invertion of that
        else:
            value=0
        break #Break the loop as we just need the first mute value we will run into
           
 
for bone in body_part:
    for con in bone.constraints:
        con.mute = value</pre>
 
===Blender forward throw adjustment script===
[[XML:TRAM#Blender_script|Please see the XML:TRAM page describing this script.]]
 
===Rig bone constraint target setting script===
 
This script sets the targets of Geyser's rig bone constraints, after removing one of the existing pose-matching characters and replacing it with another.
<pre>
#RigBoneConstraintTargetSetter
import bpy
obj = bpy.data.objects
 
#SET THIS TO EITHER 1 OR 2 DEPENDING ON WHICH POSE YOU ARE GOING TO USE
prefix='1'
 
armature = bpy.data.objects['rig']
 
#copying location
armature.pose.bones["torso"].constraints['Copy Location.00'+prefix].target=obj['mid.00'+prefix]
armature.pose.bones["torso_pivot"].constraints['Copy Location.00'+prefix].target=obj['pelvis.00'+prefix]
 
#copying rotation
#Torso
armature.pose.bones["hips"].constraints['Copy Rotation.00'+prefix].target=obj['pelvis.00'+prefix]
armature.pose.bones["tweak_spine.001"].constraints['Copy Rotation.00'+prefix].target=obj['mid.00'+prefix]
armature.pose.bones["chest"].constraints['Copy Rotation.00'+prefix].target=obj['chest.00'+prefix]
armature.pose.bones["shoulder.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_shoulder.00'+prefix]
armature.pose.bones["shoulder.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_shoulder.00'+prefix]
armature.pose.bones["neck"].constraints['Copy Rotation.00'+prefix].target=obj['neck.00'+prefix]
armature.pose.bones["head"].constraints['Copy Rotation.00'+prefix].target=obj['head.00'+prefix]
 
#Arms
armature.pose.bones["upper_arm_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_biceps.00'+prefix]
armature.pose.bones["upper_arm_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_biceps.00'+prefix]
armature.pose.bones["forearm_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_wrist.00'+prefix]
armature.pose.bones["forearm_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_wrist.00'+prefix]
armature.pose.bones["hand_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_handfist.00'+prefix]
armature.pose.bones["hand_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_handfist.00'+prefix]
 
#Legs
armature.pose.bones["thigh_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_thigh.00'+prefix]
armature.pose.bones["thigh_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_thigh.00'+prefix]
armature.pose.bones["shin_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_calf.00'+prefix]
armature.pose.bones["shin_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_calf.00'+prefix]
armature.pose.bones["foot_fk.L"].constraints['Copy Rotation.00'+prefix].target=obj['left_foot.00'+prefix]
armature.pose.bones["foot_fk.R"].constraints['Copy Rotation.00'+prefix].target=obj['right_foot.00'+prefix]</pre>
 
===Visual transformer script===
This script "bakes" the animation done using Geyser's rig into Oni character model bones by applying visual transform and keyframing each frame within a specified frame range.
<pre>import bpy
 
start = 0
end = 100
 
scene = bpy.context.scene
 
scene.frame_set(start) #set start frame
for i in range(start, end): #loop for every frame
        scene.frame_set(i)
        bpy.ops.object.visual_transform_apply()
        bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_LocRot')</pre>


==Oni-specific issues with Blender==
==Oni-specific issues with Blender==
191

edits