Last active
January 22, 2017 11:27
-
-
Save nasser/8acef1b1c8c4b811524081615740dac6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import [UnityEditor RagdollBuilder]) | |
;-) | |
(defn- invoke-private [obj meth & args] | |
(.Invoke | |
(.GetMethod | |
(type obj) meth | |
(enum-or BindingFlags/Instance | |
BindingFlags/NonPublic)) | |
obj | |
(into-array Object args))) | |
(defn ragdoll! | |
[{:keys [head middle-spine pelvis left-hips left-knee left-foot | |
right-hips right-knee right-elbow right-arm left-elbow | |
left-arm right-foot anchor | |
total-mass flip-forward]}] | |
(let [builder (RagdollBuilder.)] | |
(when flip-forward | |
(set! (.flipForward builder) flip-forward)) | |
(when total-mass | |
(set! (.totalMass builder) total-mass)) | |
(set! (.head builder) (.transform head)) | |
(set! (.middleSpine builder) (.transform middle-spine)) | |
(set! (.pelvis builder) (.transform pelvis)) | |
(set! (.leftHips builder) (.transform left-hips)) | |
(set! (.leftKnee builder) (.transform left-knee)) | |
(set! (.leftFoot builder) (.transform left-foot)) | |
(set! (.rightHips builder) (.transform right-hips)) | |
(set! (.rightKnee builder) (.transform right-knee)) | |
(set! (.rightElbow builder) (.transform right-elbow)) | |
(set! (.rightArm builder) (.transform right-arm)) | |
(set! (.leftElbow builder) (.transform left-elbow)) | |
(set! (.leftArm builder) (.transform left-arm)) | |
(set! (.rightFoot builder) (.transform right-foot)) | |
(invoke-private builder "CheckConsistency") | |
(invoke-private builder "OnWizardCreate"))) | |
(comment | |
(ragdoll! | |
{:head (object-named "Head_M") | |
:middle-spine (object-named "Spine1_M") | |
:pelvis (object-named "Root_M") | |
:left-hips (object-named "Hip_L") | |
:left-knee (object-named "Knee_L") | |
:left-foot (object-named "Ankle_L") | |
:left-elbow (object-named "Elbow_L") | |
:left-arm (object-named "Shoulder_L") | |
:right-arm (object-named "Shoulder_R") | |
:right-hips (object-named "Hip_R") | |
:right-knee (object-named "Knee_R") | |
:right-elbow (object-named "Elbow_R") | |
:right-foot (object-named "Ankle_R")})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment