LOTRJ screws up again...

Hi guys, I have a favor to ask of you.:o Basically what I need is an IK constraint that will limit a bone’s X and Z rotation to a conical sector. For example: Just putting IK rotation limits on the X and Z axes of a bone results in a pyramid shaped range of motion like in the left of the pic below. I need the range of motion to be conical like on the right side of the image.

I would be really appreciative if someone could code this for me, but of course I understand if nobody wants to. I just figured it couldn’t hurt to ask.

Here’s a simple starter script, just add logic. :slight_smile:

    PyConstraint template, access this in the "add constraint" scripts submenu. 
    Add docstring here 
import Blender 
from Blender import Mathutils 
 This variable specifies the number of targets   
 that this constraint can use  
 This function is called to evaluate the constraint 
    obmatrix:        (Matrix) copy of owner's 'ownerspace' matrix 
    targetmatrices:    (List) list of copies of the 'targetspace' matrices of the targets (where applicable) 
    idprop:            (IDProperties) wrapped data referring to this  
                    constraint instance's idproperties 
def doConstraint(obmatrix, targetmatrices, idprop): 
    # Separate out the tranformation components for easy access. 
    obloc = obmatrix.translationPart()    # Translation 
    obrot = obmatrix.toEuler()            # Rotation 
    obsca = obmatrix.scalePart()        # Scale 
    print obrot 
    # add logic here :) 
    # Check rot here 
    #if idprop['u_rot'] == 1: 
    #    obrot[0] += ra*rv[0] 
    #    obrot[1] += ra*rv[1] 
    #    obrot[2] += ra*rv[2] 
    mtxloc = Mathutils.TranslationMatrix( obloc ) 
    mtxrot = obrot.toMatrix().resize4x4() 
    mtxsca = Mathutils.Matrix([obsca[0],0,0,0], [0,obsca[1],0,0], [0,0,obsca[2],0], [0,0,0,1]) 
    outputmatrix = mtxsca * mtxrot * mtxloc 
    # Return the new matrix. 
    return outputmatrix 
 This function manipulates the matrix of a target prior to sending it to doConstraint() 
    target_object:                    wrapped data, representing the target object 
    subtarget_bone:                    wrapped data, representing the subtarget pose-bone/vertex-group (where applicable) 
    target_matrix:                    (Matrix) the transformation matrix of the target 
    id_properties_of_constraint:    (IDProperties) wrapped idproperties 
def doTarget(target_object, subtarget_bone, target_matrix, id_properties_of_constraint): 
    return target_matrix 
 This function draws a pupblock that lets the user set 
 the values of custom settings the constraint defines. 
 This function is called when the user presses the settings button. 
    idprop:    (IDProperties) wrapped data referring to this  
            constraint instance's idproperties 
def getSettings(idprop): 
    return None 

In case you are wondering how to handle the logic, you could perhaps put it this way:

  • figure out how to convert current rotation to a sum of X and Z rotations. ie. rotate first in Z and then in X (hint: Y rotation is 0 in this case, perhaps that helps)
  • check X rotation and clamp it if needed</edit>

Hmm, looks like I’m going to have to trudge through the BSoD Python scripting wiki…

I know next to nothing about python.

[Edit] Didn’t help as much as I thought. After reading the BSoD I was able to write the script to translate an object a specified distance on a frame change by memory, but that’s about it.

It seems the link to the only practical example leads to a page that hasn’t been written yet. :frowning:

this would be useful in joints - range of motion stuff… I hope you can get this thing flying, Lord of the Rings Junkie :smiley:

Me too. Does anyone know of some PRACTICAL tutorials I could use to point myself in the right direction? I think it is laughable to call what is on the python site a tutorial, it’s more like a reference manual.

You’re probably better off adapting someone else’s script in stead of starting from scratch.

You can see in bebraw’s very neat starting point that the variable: obrot is created… that’s the current rotation… it’s a “euler” see how you can adapt that… play with the math functions there are in Mathutils in the python api for doing stuff to eulers.

I don’t even know where to start though… Could I at least see what a simple IK script looks like? Possibly heavily commented to explain what each part does?

I need some practical examples that I can understand before I can script anything myself. Right now my understanding is limited to:

  1. Displaying an object’s name, loc, rot, and scale in the command window.
  2. Changing an object’s loc, rot, or scale value by a specified amount through script linking.

That’s what I learned from the BSoD.

Ya know… What the HELL am I talking about?!

It’s regular rotation constraints that have a pyramid range of motion, the IK limits appear to work as needed. I feel so stupid…

Anyway, I would still add a question, BSoD Python introduction is really useful, but I still do not know how to access by Python single bone of armature. Because the object is Armature itself not its single bone. So my question is how should I change for example this simple python command from BSoD to acces a location of the particular bone and not just the armature:

import Blender

ob = Blender.Object.Get(‘Armature’)
print ob # the object
print ob.name # object name
print ‘location’, ob.loc # object location



import Blender

ob = Blender.Object.Get('Armature')
print  ob		# the object
print  ob.name	# object name
print 'location', ob.loc	# object location

ob_data = ob.getData() # returns armature block in this case

bone = ob_data.bones['name_of_the_bone'] # dictionary of bones (bone_name -&gt; bone)

print bone # should print wanted bone

BeBraw, thank you very much that really helps. As you are so kind in fact I need a help to make some kind of python expression for some repetitive work-flow in Blender, let say macro.

If you would be so kind to help I would PM you my problem (probably that is quite easy I just want to copy visual location/rotation from one bone to another, but as I do not know python it is very difficult to me). This would enable to speed up of FK/IK switching in Cessen simple Biped rig, some details here:

Thank you very much

PS: LOTR sorry to hijack your thread

No problem, I don’t need it anymore anyway. :slight_smile: