eacousineau

Nao Link Definition

Jul 10th, 2011
3,369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. Obj[rule_, chain_List] := Fold[#2 /. #1 &, rule, chain];
  2. Obj[rule_, args__] := Obj[rule, {args}];
  3.  
  4. (*How to detect if element member exists?*)
  5.  
  6. joints = {
  7. "Torso" -> {
  8. "Origin" :> {0, 0, 0}
  9. },
  10. "Head" -> {
  11. "Origin" :>
  12. Obj[joints, "Torso", "Origin"] + {0, 0, NeckOffsetZ},
  13. "Joint" -> {
  14. "Yaw" -> {0, 0, 1},
  15. "Pitch" -> {0, 1, 0}
  16. }
  17. },
  18. "RHip" -> {
  19. "Origin" :>
  20. Obj[joints, "Torso", "Origin"] + {0, -HipOffsetY, HipOffsetZ},
  21. "Joint" -> {
  22. "Pitch", {0, 1, 0},
  23. "Roll", {1, 0, 0},
  24. "YawPitch", {0, 1, 1}
  25. }
  26. },
  27. "RKnee" -> {
  28. "Origin" :>
  29. Obj[joints, "RHip", "Origin"] + {0, 0, -ThighLength},
  30. "Joint" -> {
  31. "Pitch" -> {0, 1, 0}
  32. }
  33. },
  34. "RAnkle" -> {
  35. "Origin" :> Obj[joints, "RKnee", "Origin"] + {0, 0, -TibiaLength},
  36. "Joint" -> {
  37. "Pitch" -> {0, 1, 0},
  38. "Roll" -> {1, 0, 0}
  39. }
  40. },
  41. "RShoulder" -> {
  42. "Origin" :>
  43. Obj[joints, "Torso", "Origin"] + {0, -ShoulderOffsetY,
  44. ShoulderOffsetZ},
  45. "Joint" -> {
  46. "Pitch" -> {0, 1, 0},
  47. "Roll" -> {0, 0, 1}
  48. }
  49. },
  50. "RElbow" -> {
  51. "Origin" :>
  52. Obj[joints, "RShoulder", "Origin"] + {UpperArmLength, 0, 0},
  53. "Joint" -> {
  54. "Roll" -> {0, 0, 1},
  55. "Yaw" -> {1, 0, 0}
  56. }
  57. },
  58. "RWrist" -> {
  59. "Origin" :>
  60. Obj[joints, "RElbow", "Origin"] + {LowerArmLength, 0, 0}
  61. }
  62. };
  63.  
  64. rightRegex = RegularExpression["^R([A-Z]\\w+)"];
  65. RightQ[str_] := StringMatchQ[str, rightRegex]
  66.  
  67. For[i = 1, i < Length[joints], i++,
  68. oldName = joints[[i, 1]];
  69. If[RightQ[oldName],
  70. (*Make new joint*)
  71. newName = "L" <> StringTake[oldName, {2, -1}];
  72. (*newO="Origin"*{1,-1,1}/.joints[[i,2]];*)
  73.  
  74. newO = Obj[joints, oldName, "Origin"]*{1, -1, 1};
  75. If[Position[joints[[i]], "Joint" -> _] != {},
  76. newJoints = Obj[joints, oldName, "Joint"];
  77. AppendTo[joints,
  78. newName -> {"Origin" -> newO, "Joints" -> newJoints}],
  79. AppendTo[joints, newName -> {"Origin" -> newO}]
  80. ]
  81. ]
  82. ];
  83.  
  84. pieces = {
  85. "Head" -> {
  86. "Origin" :> Obj[joints, "Head", "Origin"]
  87. },
  88. "Neck" -> {
  89. "Origin" :> Obj[joints, "Head", "Origin"]
  90. },
  91. "RBicep" -> {
  92. "Origin" :> Obj[joints, "RShoulder", "Origin"]
  93. },
  94. "RForearm" -> {
  95. "Origin" :> Obj[joints, "RElbow", "Origin"]
  96. },
  97. "RHand" -> {
  98. "Origin" :> Obj[joints, "RWrist", "Origin"]
  99. },
  100. "RPelvis" -> {
  101. "Origin" :> Obj[joints, "RHip", "Origin"]
  102. },
  103. "RHip" -> {
  104. "Origin" :> Obj[joints, "RHip", "Origin"]
  105. },
  106. "RThigh" -> {
  107. "Origin" :> Obj[joints, "RHip", "Origin"]
  108. },
  109. "RTibia" -> {
  110. "Origin" :> Obj[joints, "RKnee", "Origin"]
  111. },
  112. "RAnkle" -> {
  113. "Origin" :> Obj[joints, "RAnkle", "Origin"]
  114. },
  115. "RFoot" -> {
  116. "Origin" :> Obj[joints, "RAnkle", "Origin"]
  117. },
  118. (*Screw automation*)
  119.  
  120. "LBicep" -> {"Origin" :> Obj[joints, "LShoulder", "Origin"]},
  121. "LForearm" -> {"Origin" :> Obj[joints, "LElbow", "Origin"]},
  122. "LHand" -> {"Origin" :> Obj[joints, "LWrist", "Origin"]},
  123. "LPelvis" -> {"Origin" :> Obj[joints, "LHip", "Origin"]},
  124. "LHip" -> {"Origin" :> Obj[joints, "LHip", "Origin"]},
  125. "LThigh" -> {"Origin" :> Obj[joints, "LHip", "Origin"]},
  126. "LTibia" -> {"Origin" :> Obj[joints, "LKnee", "Origin"]},
  127. "LAnkle" -> {"Origin" :> Obj[joints, "LAnkle", "Origin"]},
  128. "LFoot" -> {"Origin" :> Obj[joints, "LAnkle", "Origin"]}
  129. };
  130.  
  131. chains = {"Head" -> {"HeadYaw", "HeadPitch"},
  132. "RArm" -> {"RShoulderPitch", "RShoulderRoll", "RElbowYaw",
  133. "RElbowRoll", "RWristYaw"},
  134. "RLeg" -> {"RHipYawPitch", "RHipRoll", "RHipPitch", "RKneePitch",
  135. "RAnklePitch", "RAnkleRoll"},
  136. "LArm" -> {"LShoulderPitch", "LShoulderRoll", "LElbowYaw",
  137. "LElbowRoll", "LWristYaw"},
  138. "LLeg" -> {"LHipYawPitch", "LHipRoll", "LHipPitch", "LKneePitch",
  139. "LAnklePitch", "LAnkleRoll"}};
Advertisement
Add Comment
Please, Sign In to add comment