private void SetDirtySolversAffectedByTransform(Transform transform) { foreach (Solver2D solver in m_IKSolvers) { if (solver.isValid) { for (int i = 0; i < solver.chainCount; ++i) { var chain = solver.GetChain(i); if (chain.effector == null) { continue; } if (!(IKUtility.IsDescendentOf(chain.effector, transform) && IKUtility.IsDescendentOf(chain.rootTransform, transform)) && (chain.effector == transform || IKUtility.IsDescendentOf(chain.effector, transform) || IKUtility.IsDescendentOf(chain.target, transform))) { SetSolverDirty(solver); break; } } } } }
private void SetDirtyUnderHierarchy(Transform hierarchyRoot) { if (hierarchyRoot == null) { return; } foreach (Solver2D solver in m_IKSolvers) { if (solver.isValid) { for (int i = 0; i < solver.chainCount; ++i) { var chain = solver.GetChain(i); if (chain.effector == null) { continue; } if (hierarchyRoot == chain.effector || IKUtility.IsDescendentOf(chain.effector, hierarchyRoot) || IKUtility.IsDescendentOf(chain.target, hierarchyRoot)) { SetSolverDirty(solver); break; } } } } }
public static IEnumerable <Quaternion[]> InverseKinematicsIterator(Bone[] bones, Vector3 position, float step, float delta, int iteration) { var rotations = new Quaternion[bones.Length]; for (var i = 0; i < bones.Length; i++) { rotations[i] = bones[i].transform.localRotation; } var dFK = new float[bones.Length * 4]; for (var iterate = 0; iterate < iteration; iterate++) { for (var i = 0; i < bones.Length * 4; i++) { dFK[i] = IKUtility.FKDistanceDerivate(bones, rotations, position, i, delta); } for (var i = 0; i < bones.Length * 4; i++) { int idxBone = i / 4; int idxQuaternion = i % 4; rotations[idxBone][idxQuaternion] -= step * dFK[i]; } yield return(rotations); } }
public void GetChainCountForOtherChildGO_IsCorrect() { var ikGO = new GameObject(); var solver = ikGO.AddComponent <FabrikSolver2D>(); var chain = solver.GetChain(0); chain.target = otherChildGO.transform; Assert.AreEqual(2, IKUtility.GetMaxChainCount(chain)); UnityEngine.Object.Destroy(ikGO); }
public override void OnInspectorGUI() { IKChain2D chain = m_Solver.GetChain(0); serializedObject.Update(); EditorGUILayout.PropertyField(m_EffectorProperty, Contents.effectorLabel); EditorGUILayout.PropertyField(m_TargetProperty, Contents.targetLabel); EditorGUILayout.IntSlider(m_TransformCountProperty, 0, IKUtility.GetMaxChainCount(chain), Contents.chainLengthLabel); EditorGUILayout.PropertyField(m_IterationsProperty, Contents.iterationsLabel); EditorGUILayout.PropertyField(m_ToleranceProperty, Contents.toleranceLabel); DrawCommonSolverInspector(); serializedObject.ApplyModifiedProperties(); }
public void RootGO_IsNotDescendentOfChildGO() { var result = IKUtility.IsDescendentOf(rootGO.transform, childGO.transform); Assert.AreEqual(false, result); }
public void GrandChildGO_IsNotDescendentOfOtherChildGO() { var result = IKUtility.IsDescendentOf(grandChildGO.transform, otherChildGO.transform); Assert.AreEqual(false, result); }
public void OtherChildGO_IsDescendentOfOtherGO() { var result = IKUtility.IsDescendentOf(otherChildGO.transform, otherGO.transform); Assert.AreEqual(true, result); }
public void GrandChildGO_IsDescendentOfRootGO() { var result = IKUtility.IsDescendentOf(grandChildGO.transform, rootGO.transform); Assert.AreEqual(true, result); }
public void RootGO_HasNoAncestors() { var result = IKUtility.GetAncestorCount(rootGO.transform); Assert.AreEqual(0, result); }
public void ChildGO_HasOneAncestor() { var result = IKUtility.GetAncestorCount(childGO.transform); Assert.AreEqual(1, result); }
public void GrandChildGO_HasTwoAncestors() { var result = IKUtility.GetAncestorCount(grandChildGO.transform); Assert.AreEqual(2, result); }
protected override void DoInitialize() { chain.transformCount = chain.effector == null || IKUtility.GetAncestorCount(chain.effector) < 1 ? 0 : 2; base.DoInitialize(); }