void OnEnable() { Transform midJoint = endJoint.parent; if (midJoint == null) { return; } Transform topJoint = midJoint.parent; if (topJoint == null) { return; } graph = PlayableGraph.Create("TwoBoneIK"); graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var output = AnimationPlayableOutput.Create(graph, "ouput", animator); //animator.fireEvents = false; var twoBoneIKJob = new TwoBoneIKJob(); twoBoneIKJob.Setup(animator, topJoint, midJoint, endJoint, targetTransform); playable = AnimationScriptPlayable.Create(graph, twoBoneIKJob); //m_LookAtPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f); output.SetSourcePlayable(playable); graph.Play(); }
public TwoBoneIkAnimNode(Animator animator, Skeleton skeleton, PlayableGraph graph, AnimGraph_TwoBoneIk settings) { m_graph = graph; var targetBone = skeleton.bones[skeleton.GetBoneIndex(settings.targetBone.GetHashCode())]; var drivenBone = skeleton.bones[skeleton.GetBoneIndex(settings.drivenBone.GetHashCode())]; // Setup settings var ikSettings = new TwoBoneIKJob.IkChain(); ikSettings.target.target = targetBone; ikSettings.target.readFrom = TwoBoneIKJob.TargetType.Stream; ikSettings.driven.type = TwoBoneIKJob.IkType.Generic; ikSettings.driven.genericEndJoint = drivenBone; // ikSettings.driven.humanoidLimb = AvatarIKGoal.LeftFoot; // Create job var leftArmIkJob = new TwoBoneIKJob(); var initialized = leftArmIkJob.Setup(animator, ikSettings, typeof(AnimStateController), "leftArmIK.weight.value", "leftArmIK.weight.propertyOffset", "leftArmIK.target.offset"); GameDebug.Assert(initialized, "Failed to initialize TwoBoneIKJob"); m_ikPlayable = AnimationScriptPlayable.Create(graph, leftArmIkJob, 1); m_ikPlayable.SetInputWeight(0, 1); }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_AimDrag settings) { m_settings = settings; m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; m_graph = graph; GameDebug.Assert(entityManager.HasComponent <Animator>(owner), "Owner has no Animator component"); var animator = entityManager.GetComponentObject <Animator>(owner); GameDebug.Assert(entityManager.HasComponent <Skeleton>(owner), "Owner has no Skeleton component"); var skeleton = entityManager.GetComponentObject <Skeleton>(owner); var weaponHandBone = skeleton.bones[skeleton.GetBoneIndex(settings.weaponHandBone.GetHashCode())]; var weaponBone = skeleton.bones[skeleton.GetBoneIndex(settings.weaponBone.GetHashCode())]; var resultBone = animator.transform.Find(settings.applyResultOnBone); // Weapon sway var aimDragJobSettings = new AimDragJob.EditorSettings(); aimDragJobSettings.weaponHandBone = weaponHandBone; aimDragJobSettings.weaponBone = weaponBone; aimDragJobSettings.applyResultOn = resultBone; aimDragJobSettings.settings = settings.aimDragSettings; var dragJob = new AimDragJob(); m_DragHistory = new NativeQueue <Quaternion>(Allocator.Persistent); var initialized = dragJob.Setup(animator, aimDragJobSettings, 2312, m_DragHistory); GameDebug.Assert(initialized, "Failed to initialize AimDragJob"); m_AimDragPlayable = AnimationScriptPlayable.Create(graph, dragJob, 1); m_AimDragPlayable.SetInputWeight(0, 1); // Hand IK var ikSettings = new TwoBoneIKJob.IkChain(); ikSettings.target.target = resultBone; ikSettings.target.readFrom = TwoBoneIKJob.TargetType.Scene; ikSettings.driven.type = TwoBoneIKJob.IkType.Generic; ikSettings.driven.genericEndJoint = weaponHandBone; ikSettings.driven.humanoidLimb = AvatarIKGoal.LeftFoot; var rightArmIkJob = new TwoBoneIKJob(); initialized = rightArmIkJob.Setup(animator, ikSettings, typeof(AnimStateController), "rightArmIK.weight.value", "rightArmIK.weight.propertyOffset", "rightArmIK.target.offset"); GameDebug.Assert(initialized, "Failed to initialize TwoBoneIKJob"); m_IKPlayable = AnimationScriptPlayable.Create(graph, rightArmIkJob); m_IKPlayable.AddInput(m_AimDragPlayable, 0, 1f); }
void OnEnable() { var idleClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "Idle"); if (idleClip == null) { return; } if (endJoint == null) { return; } m_MidJoint = endJoint.parent; if (m_MidJoint == null) { return; } m_TopJoint = m_MidJoint.parent; if (m_TopJoint == null) { return; } m_Effector = SampleUtility.CreateEffector("Effector_" + endJoint.name, endJoint.position, endJoint.rotation); m_Graph = PlayableGraph.Create("TwoBoneIK"); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var output = AnimationPlayableOutput.Create(m_Graph, "ouput", GetComponent <Animator>()); var twoBoneIKJob = new TwoBoneIKJob(); twoBoneIKJob.Setup(GetComponent <Animator>(), m_TopJoint, m_MidJoint, endJoint, m_Effector.transform); m_IKPlayable = AnimationScriptPlayable.Create(m_Graph, twoBoneIKJob); m_IKPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f); output.SetSourcePlayable(m_IKPlayable); m_Graph.Play(); }