void CreateInitialCopyOfSerializedObject() { var targetObj = (BodyPoseData)target; m_BodyPoseDataTargetToTweak = CreateInstance <BodyPoseData>(); m_BodyPoseDataTargetToTweak.Init(string.Empty, (float[])targetObj.Muscles.Clone(), (bool[])targetObj.MuscleRelevantData.Clone(), (Vector3[])targetObj.BonesOrientations.Clone(), (bool[])targetObj.RelevantBoneData.Clone(), targetObj.TrackCenterLine, targetObj.TrackRightArm, targetObj.TrackLeftArm, targetObj.TrackRightLeg, targetObj.TrackLeftLeg); m_SerializedObjToTweak = new SerializedObject(m_BodyPoseDataTargetToTweak); }
/// <summary> /// Puts objToApplyPoseTo into the selected pose, or resets the pose if bodyData is null. /// </summary> /// <param name="objToApplyPoseTo">The humanoid animator to pose</param> /// <param name="bodyData">(Optional) The pose to use. If null, animator will take on the default 'reset' pose</param> /// <param name="overrideRelevantMuscles">If true, all muscles will be posed, including those marked non-relevant (eg. lacking platform tracking support).</param> internal static void LoadBodyPose(Animator objToApplyPoseTo, BodyPoseData bodyData = null, bool overrideRelevantMuscles = false) { StopTimelineIfNecessary(); var animTransform = objToApplyPoseTo.transform; // if we don't set the transform to 0,0,0 then loading pose will offset the body from the transform root var originalPos = animTransform.localPosition; var originalRot = animTransform.localRotation; animTransform.localRotation = Quaternion.identity; animTransform.localPosition = Vector3.zero; var avatar = objToApplyPoseTo.avatar; if (!avatar.isHuman) { Debug.LogError("LoadBodyPose can only be used on humanoid avatars."); return; } var humanPoseHandler = new HumanPoseHandler(avatar, animTransform); var humanPose = new HumanPose(); humanPoseHandler.GetHumanPose(ref humanPose); if (bodyData == null) { for (var i = 0; i < humanPose.muscles.Length; i++) { humanPose.muscles[i] = 0; } } else { humanPose.bodyRotation = Quaternion.identity; for (var i = 0; i < bodyData.Muscles.Length; i++) { if (overrideRelevantMuscles || bodyData.MuscleRelevantData[i]) // Only set muscles with relevant data { humanPose.muscles[i] = bodyData.Muscles[i]; } } } humanPoseHandler.SetHumanPose(ref humanPose); animTransform.localRotation = originalRot; animTransform.localPosition = originalPos; }
void OnSceneGUI(SceneView sceneView) { if (!ShouldDrawBodyPoseUtilityWindow(sceneView)) { return; } s_LastFoundAnimator = FindHumanAnimatorObj(); if (s_LastFoundAnimator == null) { return; } // We don't want to show the window if the avatar isn't visible. // Specifically, we avoid changing the pose of the landmarks rig (Default Body Rig) if (!HasDisabledSkinnedMeshRenderer()) { return; } Handles.BeginGUI(); var winPos = new Rect(sceneView.position.width - k_WindowWidth - k_WindowOffsetFromEdges, sceneView.position.height - k_WindowHeight - k_WindowOffsetFromEdges - k_ToolbarHeight, k_WindowWidth, k_WindowHeight); using (new GUILayout.AreaScope(winPos, string.Empty, "Box")) { GUILayout.Label(k_CreatePoseToolLabel); using (new EditorGUI.DisabledScope(!s_LastFoundAnimator.isHuman)) { using (new GUILayout.HorizontalScope()) { m_ExternalBodyData = EditorGUIUtils.ObjectFieldWithControlIdCheck( m_ExternalBodyData, ref m_ObjectSelectorControlId, GUILayout.Width(135), GUILayout.Height(17)); using (new EditorGUI.DisabledScope(m_ExternalBodyData == null)) { if (GUILayout.Button(k_LoadExternalPose, GUILayout.Width(40), GUILayout.Height(17))) { LoadBodyPose(s_LastFoundAnimator, m_ExternalBodyData); } } } using (new GUILayout.HorizontalScope()) { if (GUILayout.Button(k_ResetPoseButton, GUILayout.Width(62))) { LoadBodyPose(s_LastFoundAnimator); } if (GUILayout.Button(k_TPoseButton, GUILayout.Width(62))) { LoadBodyPose(s_LastFoundAnimator, MarsBodySettings.instance.TPoseBodyData, true); } if (GUILayout.Button(k_SaveSelectedPoseButton, GUILayout.Width(65))) { GenerateSerializedDataFromAvatar(s_LastFoundAnimator); } } } } EditorGUIUtils.EatMouseInput(winPos, "BodyPoseUtility"); Handles.EndGUI(); }