Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #----------------------------------------------------------------------------------------------------------------------------------#
  2.  
  3. #you can use the script for any type of project but its prohibited to sell it. Questions about the script ask in the forum
  4. #and add @Dodo2207. !!!!Im not responsible for what you do with the script!!!!! If you use the script you agree to this.
  5.  
  6. #----------------------------------------------------------------------------------------------------------------------------------#
  7.  
  8. #----------------------------------------------------------------------------------------------------------------------------------#
  9. #Replace "iclone 3 skelleton" with your imported source.
  10. #----------------------------------------------------------------------------------------------------------------------------------#
  11. #Change the scaleing factor, that your source will approximitly match your target or remove it and do it .
  12. #----------------------------------------------------------------------------------------------------------------------------------#
  13. #Replace "mcrig" with your target.
  14. #----------------------------------------------------------------------------------------------------------------------------------#
  15. #Change my bonenames to your target and source bonenames. Names didnt need to match between your source and target.
  16. #----------------------------------------------------------------------------------------------------------------------------------#
  17. #If you have more or less bones as me, delete or add codeblocks. If nesessary you can add copy location as well.
  18. #----------------------------------------------------------------------------------------------------------------------------------#
  19. #Save your modification of the script and you can save a lot of time if you have many bvh files or amatrues with the same armature structure. Copy the script in the text editor, be in objectmode and have both source and target rig imported.
  20. #----------------------------------------------------------------------------------------------------------------------------------#
  21.  
  22. import bpy
  23.  
  24.  # set bvh rig as active
  25. bpy.context.view_layer.objects.active = bpy.data.objects['iclone 3 skelleton']
  26.  
  27. # viewport display in front
  28. bpy.context.object.show_in_front = True
  29.  
  30. # set scale for the imported byh armatrue to nearly match your target armature. In my case its mcrig
  31. bpy.context.object.scale[0] = 0.0106921
  32. bpy.context.object.scale[1] = 0.009831
  33. bpy.context.object.scale[2] = 0.00983105
  34.  
  35. # select mcrig
  36. bpy.context.view_layer.objects.active = bpy.data.objects['mcrig']
  37.  
  38. # switch to pose mode
  39. bpy.ops.object.posemode_toggle()
  40.  
  41. # for set active bone in posemode
  42. ob  = bpy.data.objects["mcrig"]
  43.  
  44. #----------Head----------
  45. ob.data.bones.active = ob.data.bones["Head"]
  46.  
  47. # add copy rotation constraint on the Head bone/ works fine
  48. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  49.  
  50. # set target and subtarget
  51. bpy.context.object.pose.bones["Head"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  52. bpy.context.object.pose.bones["Head"].constraints["Copy Rotation"].subtarget = "Head"
  53.  
  54.  
  55. #----------Torso----------
  56. #rotation
  57. ob.data.bones.active = ob.data.bones["Torso"]
  58. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  59. bpy.context.object.pose.bones["Torso"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  60. bpy.context.object.pose.bones["Torso"].constraints["Copy Rotation"].subtarget = "Chest"
  61. bpy.context.object.pose.bones["Torso"].constraints["Copy Rotation"].use_z = False
  62. #location
  63. bpy.ops.pose.constraint_add(type='COPY_LOCATION')
  64. bpy.context.object.pose.bones["Torso"].constraints["Copy Location"].target = bpy.data.objects["iclone 3 skelleton"]
  65. bpy.context.object.pose.bones["Torso"].constraints["Copy Location"].subtarget = "Chest"
  66.  
  67. #----------Top Arm.R----------
  68. #rotation
  69. ob.data.bones.active = ob.data.bones["Top Arm.R"]
  70. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  71. bpy.context.object.pose.bones["Top Arm.R"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  72. bpy.context.object.pose.bones["Top Arm.R"].constraints["Copy Rotation"].subtarget = "RightShoulder"
  73.  
  74. #----------Bottom Arm.R----------
  75. #rotation
  76. ob.data.bones.active = ob.data.bones["Bottom Arm.R"]
  77. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  78. bpy.context.object.pose.bones["Bottom Arm.R"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  79. bpy.context.object.pose.bones["Bottom Arm.R"].constraints["Copy Rotation"].subtarget = "RightElbow"
  80.  
  81. #----------Top Arm.L----------
  82. #rotation
  83. ob.data.bones.active = ob.data.bones["Top Arm.L"]
  84. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  85. bpy.context.object.pose.bones["Top Arm.L"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  86. bpy.context.object.pose.bones["Top Arm.L"].constraints["Copy Rotation"].subtarget = "LeftShoulder"
  87.  
  88. #----------Bottom Arm.L----------
  89. #rotation
  90. ob.data.bones.active = ob.data.bones["Bottom Arm.L"]
  91. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  92. bpy.context.object.pose.bones["Bottom Arm.L"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  93. bpy.context.object.pose.bones["Bottom Arm.L"].constraints["Copy Rotation"].subtarget = "LeftElbow"
  94.  
  95. #----------Pelvis----------
  96. #rotation
  97. ob.data.bones.active = ob.data.bones["Pelvis"]
  98. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  99. bpy.context.object.pose.bones["Pelvis"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  100. bpy.context.object.pose.bones["Pelvis"].constraints["Copy Rotation"].subtarget = "Hips"
  101. bpy.context.object.pose.bones["Pelvis"].constraints["Copy Rotation"].use_z = False
  102. #location
  103. bpy.ops.pose.constraint_add(type='COPY_LOCATION')
  104. bpy.context.object.pose.bones["Pelvis"].constraints["Copy Location"].target = bpy.data.objects["iclone 3 skelleton"]
  105. bpy.context.object.pose.bones["Pelvis"].constraints["Copy Location"].subtarget = "Hips"
  106.  
  107. #----------Top Leg.R----------
  108. #rotation
  109. ob.data.bones.active = ob.data.bones["Top Leg.R"]
  110. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  111. bpy.context.object.pose.bones["Top Leg.R"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  112. bpy.context.object.pose.bones["Top Leg.R"].constraints["Copy Rotation"].subtarget = "RightHip"
  113.  
  114. #----------Bottom Leg.R----------
  115. #rotation
  116. ob.data.bones.active = ob.data.bones["Bottom Leg.R"]
  117. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  118. bpy.context.object.pose.bones["Bottom Leg.R"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  119. bpy.context.object.pose.bones["Bottom Leg.R"].constraints["Copy Rotation"].subtarget = "RightKnee"
  120.  
  121. #----------Leg IK.R----------
  122. #location
  123. ob.data.bones.active = ob.data.bones["Leg IK.R"]
  124. bpy.ops.pose.constraint_add(type='COPY_LOCATION')
  125. bpy.context.object.pose.bones["Leg IK.R"].constraints["Copy Location"].target = bpy.data.objects["iclone 3 skelleton"]
  126. bpy.context.object.pose.bones["Leg IK.R"].constraints["Copy Location"].subtarget = "RightAnkle"
  127.  
  128. #----------Top Leg.L----------
  129. #rotation
  130. ob.data.bones.active = ob.data.bones["Top Leg.L"]
  131. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  132. bpy.context.object.pose.bones["Top Leg.L"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  133. bpy.context.object.pose.bones["Top Leg.L"].constraints["Copy Rotation"].subtarget = "LeftHip"
  134.  
  135. #----------Bottom Leg.L----------
  136. #rotation
  137. ob.data.bones.active = ob.data.bones["Bottom Leg.L"]
  138. bpy.ops.pose.constraint_add(type='COPY_ROTATION')
  139. bpy.context.object.pose.bones["Bottom Leg.L"].constraints["Copy Rotation"].target = bpy.data.objects["iclone 3 skelleton"]
  140. bpy.context.object.pose.bones["Bottom Leg.L"].constraints["Copy Rotation"].subtarget = "LeftKnee"
  141.  
  142. #----------Leg IK.L----------
  143. #location
  144. ob.data.bones.active = ob.data.bones["Leg IK.L"]
  145. bpy.ops.pose.constraint_add(type='COPY_LOCATION')
  146. bpy.context.object.pose.bones["Leg IK.L"].constraints["Copy Location"].target = bpy.data.objects["iclone 3 skelleton"]
  147. bpy.context.object.pose.bones["Leg IK.L"].constraints["Copy Location"].subtarget = "LeftAnkle"
  148.  
  149. #----------Root follows Hips----------
  150. #location
  151. ob.data.bones.active = ob.data.bones["Root"]
  152. bpy.ops.pose.constraint_add(type='COPY_LOCATION')
  153. bpy.context.object.pose.bones["Root"].constraints["Copy Location"].target = bpy.data.objects["mcrig"]
  154. bpy.context.object.pose.bones["Root"].constraints["Copy Location"].subtarget = "Hips"