Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. def pass_joint_to_scene(amt, part, parent, rotation):
  2.     #Already in edit mode
  3.     #I can create the bone normally
  4.     part_name = part['info']['name']
  5.     part_type = part['info']['type']
  6.     #Make bone to Center of Axes
  7.     loc = Vector(part['options']['transmat'][0:3])
  8.     bonevec = Vector((loc[0], loc[1], loc[2]))
  9.     if bonevec[0]==bonevec[1]==bonevec[2]==0:
  10.         bonevec = Vector((0,0,0.01))
  11.         print("Empty bone:",part_name)
  12.     localrot = part['options']['transmat'][3:6]
  13.     localscale = part['options']['transmat'][6:9]
  14.     localrot = Euler((math.radians(localrot[0]),
  15.                       math.radians(localrot[1]),
  16.                       math.radians(localrot[2])),"XYZ")
  17.    
  18.     #Update rotation
  19.     newrot = Euler((0,0,0),'XYZ')
  20.     newrot[0] = rotation[0] + localrot[0]
  21.     newrot[1] = rotation[1] + localrot[1]
  22.     newrot[2] = rotation[2] + localrot[2]
  23.    
  24.    
  25.     #Scale before rotating
  26.     #bonevec[0] *= localscale[0]
  27.     #bonevec[1] *= localscale[1]
  28.     #bonevec[2] *= localscale[2]
  29.     #Rotate vector on center
  30.     bonevec.rotate(rotation)
  31.        
  32.     #Add vector to bone
  33.     bone = amt.edit_bones.new(part_name)
  34.     if parent:
  35.         bone.parent = parent
  36.         bone.head = parent.tail;
  37.     bone.tail = bone.head + bonevec
  38.     #bone.use_connect
  39.    
  40.     if part['children']:
  41.         for e in part['children']:
  42.             pass_joint_to_scene(amt,e, bone, newrot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement