Skip to content
57 changes: 57 additions & 0 deletions data/rig/arm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"bindjnts": [
"bind_s_shoulder_jnt",
"bind_s_elbow_jnt",
"bind_s_wrist_jnt",
"bind_s_wristEnd_jnt"
],
"fkcontrols": [
"ctrl_s_fk_shoulder",
"ctrl_s_fk_elbow",
"ctrl_s_fk_wrist"
],
"fkjnts": [
"fk_s_shoulder_jnt",
"fk_s_elbow_jnt",
"fk_s_wrist_jnt",
"fk_s_wristEnd_jnt"
],
"ikcontrols": [
"ctrl_s_ik_arm, ikh_s_arm",
"ctrl_s_pv_arm"
],
"ikjnts": [
"ik_s_shoulder_jnt",
"ik_s_elbow_jnt",
"ik_s_wrist_jnt",
"ik_s_wristEnd_jnt"
],
"positions": [
[
2.1,
0.0,
5.0
],
[
-0.1,
0.0,
0.0
],
[
-0.1,
0.0,
-5.0
],
[
1.0,
0.0,
-8.0
]
],
"rigjnt": [
"rig_s_shoulder_jnt",
"rig_s_elbow_jnt",
"rig_s_wrist_jnt",
"rig_s_wristEnd_jnt"
]
}
1 change: 1 addition & 0 deletions layout/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fkcontrols": ["ctrl_fk_shoulder", "ctrl_fk_elbow", "ctrl_fk_wrist"], "ikjnts": ["ik_shoulder_jnt", "ik_elbow_jnt", "ik_wrist_jnt", "ik_wristEnd_jnt"], "fkjnts": ["fk_shoulder_jnt", "fk_elbow_jnt", "fk_wrist_jnt", "fk_wristEnd_jnt"], "rigjnt": ["rig_shoulder_jnt", "rig_elbow_jnt", "rig_wrist_jnt", "rig_wristEnd_jnt"], "bindjnts": ["bind_shoulder_jnt", "bind_elbow_jnt", "bind_wrist_jnt", "bind_wristEnd_jnt"], "positions": [[2.1, 0.0, 5.0], [-0.1, 0.0, 0.0], [-0.1, 0.0, -5.0], [1.0, 0.0, -8.0]], "ikcontrols": ["ctrl_ik_arm, ikh_arm", "ctrl_pv_arm"]}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
'''


joint_info = [['shoulder_jnt', [2.1, 0.0, 5.0]], ['elbow_jnt', [-0.1, 0.0, 0.0]], ['wrist_jnt', [-0.1, 0.0, -5.0]], ['wristEnd_jnt',[1.0, 0.0, -8.0]]]
ikjnt_list = [['ik_shoulder_jnt', [2.1, 0.0, 5.0]], ['ik_elbow_jnt', [-0.1, 0.0, 0.0]], ['ik_wrist_jnt', [-0.1, 0.0, -5.0]], ['ik_wristEnd_jnt',[1.0, 0.0, -8.0]]]
fkjnt_list = [['fk_shoulder_jnt', [2.1, 0.0, 5.0]], ['fk_elbow_jnt', [-0.1, 0.0, 0.0]], ['fk_wrist_jnt', [-0.1, 0.0, -5.0]], ['fk_wristEnd_jnt',[1.0, 0.0, -8.0]]]
rigjnt_list = [['rig_shoulder_jnt', [2.1, 0.0, 5.0]], ['rig_elbow_jnt', [-0.1, 0.0, 0.0]], ['rig_wrist_jnt', [-0.1, 0.0, -5.0]], ['rig_wristEnd_jnt',[1.0, 0.0, -8.0]]]



#Creating Empty Dictionary
joint_dict = {}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 0 additions & 51 deletions rig/rig_arm_class.py

This file was deleted.

109 changes: 77 additions & 32 deletions rig/rig_arm_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,95 @@
import os
import system.utils as utils

# Class Attr
classname = 'Rig_Arm'
lytfile = 'arm.json'
numjnts = 4


class Rig_Arm:
'''creates instance of arm, default is right arm'''
'''creates instance of arm'''

def __init__( self ):
# Get our joint lists from a json file.
data_path = os.environ["RDOJO_DATA"] + 'rig/arm.json'
#data_path = "C:/Users/Bears/Documents/GitHub/Python_101_S1_2016/data/" + 'rig/arm.json'
# Use our readJson function
data = utils.readJson( data_path )
# Load the json in a dictionary
self.module_info = json.loads( data )
# stores data to be modified
self.rig_info = {}

# Allows for seletion of new joints to get new positions from
if len( cmds.ls( sl=True, type='joint' )) == numjnts :
sel = cmds.ls( sl=True, type='joint' )
positions = []
for s in sel:
positions.append( cmds.xform( s, q=True, ws=True, t=True ))
self.rig_info['positions'] = positions

else:
#goes to default
self.rig_info['positions'] = self.module_info['positions']

self.instance = '_L_'
# run rig_arm function
self.rig_arm()



def rig_arm( self ):
# Create Ik joints, passing in keys
self.createJoint( self.module_info['ikjnts'] )
# de select because of the check in class
cmds.select( d=True )
# Create Ik joints, passing in keys
self.rig_info['ikjnts'] = utils.createJoint( self.module_info['ikjnts'], self.rig_info['positions'], self.instance )
#cmds.select( d=True )

# Create Fk joints
self.createJoint( self.module_info['fkjnts'] )
cmds.select( d=True )
self.rig_info['fkjnts'] = utils.createJoint( self.module_info['fkjnts'], self.rig_info['positions'], self.instance )
#cmds.select( d=True )

# Create Rig joints
self.createJoint( self.moduel_info['rigjnts'] )
cmds.select( d=True )


def orient_joints( self ):
for i in sel:
cmds.joint(i, edit=True, zeroScaleOrient=True, orientJoint="xyz", secondaryAxisOrient="yup", children=True)

def calculatePVPosition( self, jnts ):
#Calculates the Position of jnts
from maya import cmds, OpenMaya
start = cmds.xform( jnts[0], q=True, ws=True, t=True )
mid = cmds.xform( jnts[1], q=True, ws=True, t=True )
end = cmds.xform( jnts[2], q=True, ws=True, t=True )
startV = OpenMaya.MVector( start[0], start[1], start[2] )
midV = OpenMaya.MVector( mid[0], mid[1], mid[2] )
endV = OpenMaya.MVector( end[0], end[1], end[2] )
startEnd = endV - startV
startMid = midV -startV
dotP = startMid * startEnd
proj = float( dotP ) / float( startEnd.length() )
startEndN = startEnd.normal()
projV = startEndN * proj
arrowV = startMid - projV
arrowV*= 0.5
finalV = arrowV + midV
return ( [finalV.x, finalV.y, finalV.z] )
self.rig_info['rigjnt'] = utils.createJoint( self.module_info['rigjnt'], self.rig_info['positions'], self.instance )
#cmds.select( d=True )


# Create Ik Rig
# Ik handle
# "ikcontrols" : ["ctrl_ik_arm, ikh_arm", "ctrl_pv_arm"]
ikhname = self.module_info["ikcontrols"][1].replace( '_s_', self.instance )
self.rig_info['ikh'] = cmds.ikHandle( n=ikhname, sj=self.rig_info['ikjnts'][0], ee=self.rig_info['ikjnts'][2], sol='ikRPsolver', p=2, w=1)

self.rig_info['ikcontrol'] = utils.createControl( [[self.module_info['positions'][2], self.module_info["ikcontrols"][0]]] )

pvpos = utils.calculatePVPosition( [self.rig_info['ikjnts'][0], self.rig_info['ikjnts'][1], self.rig_info['ikjnts'][2]] )

pvctrlinfo = [ [pvpos, self.module_info["ikcontrols"][2]] ]
self.rig_info['pvcontrol'] = utils.createControl(pvctrlinfo)

# Parent ikh to ctrl
cmds.parent( self.rig_info["ikh"][0], self.rig_info["ikcontrols"][1] )

# PV constraint
cmds.poleVectorConstraint( self.rig_info["ikcontrols"][1], self.rig_info["ikjnts"][2], mo=True )

# Orient constrain arm ik_wrist to ctrl arm
cmds.orientConstraint( self.rig_info["ikcontrols"][0], self.rig_info['ikjnts'][2], mo=True)


# Create FK Rig
self.rig_info['fkcontrols'] = utils.createControl( [[self.module_info["positions"][2], self.module_info["fkcontrols"][2]],
[self.module_info["positions"][1], self.module_info["fkcontrols"][1]],
[self.module_info["positions"][0], self.module_info["fkcontrols"][0]]] )

#Parent fk controls`
cmds.parent( self.rig_info['fkcontrols'][2][0], self.rig_info['fkcontrols'][1][1] )
cmds.parent( self.rig_info['fkcontrols'][1][0], self.rig_info['fkcontrols'][0][1] )

# Create Rig jnts by parenting FK and IK to Rig jnts
pass




6 changes: 3 additions & 3 deletions startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
print "Startup"

# Change the current time unit to ntsc
cmds.currentUnit( time='ntsc' )
#cmds.currentUnit( time='ntsc' )

# Change the current linear unit to inches
cmds.currentUnit( linear='cm' )
#cmds.currentUnit( linear='cm' )

# set a system path to data files. WE can do this with the os modulke
os.environ["RDOJO_DATA"] = 'C:/Users/blam/Documents/GitHub/Python_101_S1_2016/data'
os.environ["RDOJO_DATA"] = 'C:/Users/blam/Documents/GitHub/Python_101_S1_2016/data/'

#import ui from ui folder
import ui.ui as ui
Expand Down
65 changes: 65 additions & 0 deletions system/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import maya.cmds as cmds
import json
import tempfile

def writeJson( fileName, data ):
''' writes a pretty json file'''

with open(fileName, 'w') as outfile:
json.dump( data, outfile, sort_keys = True, indent = 4, ensure_ascii=False )
file.close(outfile)

def readJson( fileName ):
'''reads json file'''

with open(fileName, 'r') as infile:
data = ( open(infile.name, 'r' ).read())
return data

def createJoint( name, position, instance ):
'''
for i in range(len( jntinfo )):
cmds.joint( n=jntinfo[i], p=self.module_info['positions'][i] )
'''
jnt_list = [cmds.joint( n = name[i].replace('_s_', instance), p=position[i]) for i in range(len(name)) ]
cmds.select( d=True )
return( jnt_list )
#orient joints
for i in range(len( jntinfo )):
cmds.joint(jntinfo[i], edit=True, zeroScaleOrient=True, orientJoint="xyz", secondaryAxisOrient="yup", children=True)

def createControl( ctrlinfo ):
for info in ctrlinfo:
# Create ik control
# get ws position of wrist joint
pos = info[0]
# create an empty group
ctrlgrp = cmds.group( em=True, name=info[1] )
# Create circle control object
ctrl = cmds.circle( n=info[1], nr=(0, 0, 1), c=(0, 0, 0) )
# Parent the control to the group
cmds.parent( ctrl, ctrlgrp )
# Move the group to the joint
cmds.xform( ctrlgrp, t=pos, ws=True )



def calculatePVPosition( jnts ):
#Calculates the pole vector of jnts
from maya import cmds, OpenMaya
start = cmds.xform( jnts[0], q=True, ws=True, t=True )
mid = cmds.xform( jnts[1], q=True, ws=True, t=True )
end = cmds.xform( jnts[2], q=True, ws=True, t=True )
startV = OpenMaya.MVector( start[0], start[1], start[2] )
midV = OpenMaya.MVector( mid[0], mid[1], mid[2] )
endV = OpenMaya.MVector( end[0], end[1], end[2] )
startEnd = endV - startV
startMid = midV -startV
dotP = startMid * startEnd
proj = float( dotP ) / float( startEnd.length() )
startEndN = startEnd.normal()
projV = startEndN * proj
arrowV = startMid - projV
arrowV*= 0.5
finalV = arrowV + midV
return ( [finalV.x, finalV.y, finalV.z] )
13 changes: 0 additions & 13 deletions system/utils_json.py

This file was deleted.

Loading