/// <summary> /// add a pose, if a pose with same name presents, overwrite it; /// /// `joints' are the joints belonging to the pose /// </summary> public void AddPose(string poseName, Transform[] joints, Transform animRoot) { DelPose(poseName); //del existing same name pose first if there is one PoseDesc newDesc = new PoseDesc(); newDesc.m_PoseName = poseName; var data = newDesc.m_PoseData = new PoseDataDict(); for (int idx = 0; idx < joints.Length; ++idx) { Transform j = joints[idx]; XformData trData = new XformData(); trData.CopyFrom(j); string boneTrPath = AnimationUtility.CalculateTransformPath(j, animRoot); if (!data.ContainsKey(boneTrPath)) { data.Add(boneTrPath, trData); } else { Dbg.LogWarn("PoseSet.AddPose: Found duplicate bone transform path: {0}", boneTrPath); } } m_Poses.Add(newDesc); }
public static XformData CreateW(Transform srcTr) { XformData trData = new XformData(); trData.CopyFromW(srcTr); return(trData); }
private void _RecordIKChainState() { m_backupData.Clear(); for (int i = 0; i < m_jointArr.Length - 1; ++i) { var j = m_jointArr[i]; m_backupData.Add(XformData.Create(j)); } }
void LateUpdate() { // head control if (m_AllowManualControl) { float XRotDelta = -Input.GetAxis("Horizontal") * Time.deltaTime * m_RotSpeed; float ZRotDelta = Input.GetAxis("Vertical") * Time.deltaTime * m_RotSpeed; XformData backup = m_TransformBackup; backup.Apply(m_Tr); m_Tr.Rotate(XRotDelta, 0, ZRotDelta, Space.Self); Vector3 currentUp = m_Tr.parent.InverseTransformDirection(m_Tr.up).normalized; float cosVal = Vector3.Dot(currentUp, m_StartDir); float costhres = Mathf.Cos(m_RotThres * Mathf.Deg2Rad); if (cosVal < costhres) { backup.Apply(m_Tr); } else { m_Tr.LookAtYX(m_Tr.up + m_Tr.position, Vector3.down); // ensure head upward backup.CopyFrom(m_Tr); } } else { if (m_IKWeight > 0) { m_Tr.localRotation = Quaternion.Lerp(m_Tr.localRotation, m_TransformBackup.rot, m_IKWeight); } else { m_TransformBackup.CopyFrom(m_StartTrBackup); //reset the data } } // hand IK control if (Input.GetMouseButton(0) && m_AllowManualControl) { m_IKWeight = Mathf.Clamp01(m_IKWeight + m_IKWeightIncSpeed * Time.deltaTime); RaycastHit hit; Ray ray = new Ray(m_Tr.position, m_Tr.up); if (m_ColliderQuad.Raycast(ray, out hit, float.PositiveInfinity)) { Vector3 hitpos = hit.point; m_Solver.Target = hitpos; m_Solver.Execute(m_IKWeight); } } else { if (m_IKWeight > 0) { m_IKWeight = Mathf.Clamp01(m_IKWeight - m_IKWeightIncSpeed * Time.deltaTime); m_Solver.Execute(m_IKWeight); } } }
public void CopyFrom(XformData data) { pos = data.pos; rot = data.rot; scale = data.scale; }