bool CreatePlayableGraph()
        {
            var animator = GetComponent <Animator>();

            if (animator.avatar == null)
            {
                animator.avatar      = AvatarBuilder.BuildGenericAvatar(animator.gameObject, transform.name);
                animator.avatar.name = "Avatar";
            }

            var deltaTimeProperty = animator.BindSceneProperty(transform, typeof(Kinematica), "_deltaTime");

            job = new UpdateAnimationPoseJob();
            if (!job.Setup(animator,
                           GetComponentsInChildren <Transform>(), ref Synthesizer.Ref, deltaTimeProperty))
            {
                return(false);
            }

            playableGraph =
                PlayableGraph.Create(
                    $"Kinematica_{animator.transform.name}");

            var output = AnimationPlayableOutput.Create(playableGraph, "output", animator);

            var playable = AnimationScriptPlayable.Create(playableGraph, job);

            output.SetSourcePlayable(playable);

            playableGraph.Play();

            return(true);
        }
Beispiel #2
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings)
            {
                m_Settings       = settings;
                m_AnimState      = controller.GetComponent <AnimStateData>();
                m_PredictedState = controller.GetComponent <LogicStateData>();

                m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform");

                m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

                m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
                graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle);
                m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

                m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL);
                m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR);

                var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

                m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports);

                if (settings.animTurnL.events.Length != 0)
                {
                    m_LeftTurnFootFalls  = ExtractFootFalls(settings.animTurnL);
                    m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR);
                }

                var animator  = controller.GetComponent <Animator>();
                var skeleton  = controller.GetComponent <Skeleton>();
                var leftToes  = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())];
                var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())];

                var ikJob = new FootIkJob
                {
                    settings = settings.footIK,
                    leftToe  = animator.BindStreamTransform(leftToes),
                    rightToe = animator.BindStreamTransform(rightToes)
                };

                m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
                graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0);
                m_FootIk.SetInputWeight(0, 1f);

                m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

                m_AnimAimLeft  = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft);
                m_AnimAimMid   = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid);
                m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight);

                m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph);

                var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0);

                m_AdditiveMixer.SetInputWeight(locoMixerPort, 1);

                var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0);

                m_AdditiveMixer.SetInputWeight(aimMixerPort, 1);
                m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true);
            }
        protected override AnimationScriptPlayable InitializePlayable()
        {
            BonesLastFrame = sharedData.GetBonesLastFrameCopy();

            // Create job
            var job = new MixerJob()
            {
                blendMode      = BlendMode,
                handles        = boneHandles,
                boneWeights    = boneWeights,
                bonesLastFrame = BonesLastFrame,
                bonesLastState = BonesLastFrame,
                weight         = 0f,
            };

            // Debug.Log($"Initialize mixer playable {job}");

            var scriptPlayable = AnimationScriptPlayable.Create(sharedData.PlayableGraph, job, 2);

            scriptPlayable.SetProcessInputs(false);
            // sequenceList.ForEach(clip =>
            // {
            //     scriptPlayable.AddInput(AnimationClipPlayable.Create(sharedData.PlayableGraph, clip.pose), 0, 0f);
            // });

            return(scriptPlayable);
        }
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_CameraNoise settings)
        {
            m_Settings       = settings;
            m_graph          = graph;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            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 cameraBone        = skeleton.bones[skeleton.GetBoneIndex(settings.cameraBone.GetHashCode())];
            var characterRootBone = skeleton.bones[skeleton.GetBoneIndex(settings.characterRootBone.GetHashCode())];

            var cameraNoiseSettings = new CameraNoiseJob.EditorSettings();

            cameraNoiseSettings.cameraBone        = cameraBone;
            cameraNoiseSettings.characterRootBone = characterRootBone;
            cameraNoiseSettings.jobSettings       = settings.cameraNoiseJobSettings;

            var noiseJob    = new CameraNoiseJob();
            var initialized = noiseJob.Setup(animator, cameraNoiseSettings);

            GameDebug.Assert(initialized, "Failed to initialize AimDragJob");
            m_NoisePlayable = AnimationScriptPlayable.Create(graph, noiseJob, 1);
            m_NoisePlayable.SetInputWeight(0, 1);
        }
    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();
    }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public AnimationScriptPlayable GeneratePlayable(Animator outputAnimator, PlayableGraph graph)
        {
            var job = new TwoBoneIKJob();

            job.Setup(outputAnimator, top, mid, low, effector);
            return(AnimationScriptPlayable.Create(graph, job));
        }
Beispiel #8
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Banking settings)
        {
            m_Settings       = settings;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            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);

            GameDebug.Assert(entityManager.HasComponent <CharacterPredictedData>(m_AnimStateOwner), "Owner has no CharPredictedState component");

            var bankTransform = skeleton.bones[skeleton.GetBoneIndex(settings.bankTransform.GetHashCode())];

            var bankingSettings = new BankingJob.EditorSettings();

            bankingSettings.bankTransform = bankTransform;
            bankingSettings.settings      = settings.bankingSettings;

            var bankingJob = new BankingJob();

            m_HeadLeftRightMuscles  = new NativeArray <MuscleHandle>(2, Allocator.Persistent);
            m_SpineLeftRightMuscles = new NativeArray <MuscleHandle>(3, Allocator.Persistent);
            var initialized = bankingJob.Setup(animator, bankingSettings, 2312, m_HeadLeftRightMuscles, m_SpineLeftRightMuscles);

            GameDebug.Assert(initialized, "Failed to initialize BankingJob");
            m_Playable = AnimationScriptPlayable.Create(graph, bankingJob);
        }
        public ref AnimationScriptPlayable Initialize(Animator a_animator, AvatarMask a_avatarMask, PlayableGraph a_playableGraph, AnimationLayerMixerPlayable a_layerMixer)
        {
            m_animator   = a_animator;
            m_avatarMask = a_avatarMask;

            CollectAndBindAnimationTransforms();

            var inertializerJob = new InertializerJob()
            {
                BlendActive                 = false,
                DeltaTime                   = Time.deltaTime,
                RemainingTime               = 0f,
                TargetAnimationTransforms   = m_targetAnimationTransforms,
                CurrentAnimationTransforms  = m_currentAnimationTransforms,
                PreviousAnimationTransforms = m_previousAnimationTransforms
            };

            m_intertialPlayable = AnimationScriptPlayable.Create(a_playableGraph, inertializerJob);
            m_intertialPlayable.SetTraversalMode(PlayableTraversalMode.Mix);
            m_intertialPlayable.SetInputCount(1);
            m_intertialPlayable.SetInputWeight(0, 1f);
            m_intertialPlayable.SetProcessInputs(false);

            m_intertialPlayable.ConnectInput(0, a_layerMixer, 0);

            return(ref m_intertialPlayable);
        }
Beispiel #10
0
    void OnEnable()
    {
        m_Animator = GetComponent <Animator>();

        // Setting to Always animate because on the first frame the renderer can be not visible which break syncGoal on start up
        m_Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

        if (!m_Animator.avatar.isHuman)
        {
            throw new InvalidOperationException("Avatar must be a humanoid.");
        }

        m_Graph = PlayableGraph.Create();
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var output = AnimationPlayableOutput.Create(m_Graph, "output", m_Animator);

        var clip         = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Humanoid", "Idle");
        var clipPlayable = AnimationClipPlayable.Create(m_Graph, clip);

        clipPlayable.SetApplyFootIK(false);
        clipPlayable.SetApplyPlayableIK(false);

        var job = new FullBodyIKJob();

        job.stiffness        = stiffness;
        job.maxPullIteration = maxPullIteration;

        SetupIKLimbHandle(ref job.leftArm, HumanBodyBones.LeftUpperArm, HumanBodyBones.LeftLowerArm, HumanBodyBones.LeftHand);
        SetupIKLimbHandle(ref job.rightArm, HumanBodyBones.RightUpperArm, HumanBodyBones.RightLowerArm, HumanBodyBones.RightHand);
        SetupIKLimbHandle(ref job.leftLeg, HumanBodyBones.LeftUpperLeg, HumanBodyBones.LeftLowerLeg, HumanBodyBones.LeftFoot);
        SetupIKLimbHandle(ref job.rightLeg, HumanBodyBones.RightUpperLeg, HumanBodyBones.RightLowerLeg, HumanBodyBones.RightFoot);

        m_LeftFootEffector  = SetupEffector(ref job.leftFootEffector, "LeftFootEffector");
        m_RightFootEffector = SetupEffector(ref job.rightFootEffector, "RightFootEffector");
        m_LeftHandEffector  = SetupEffector(ref job.leftHandEffector, "LeftHandEffector");
        m_RightHandEffector = SetupEffector(ref job.rightHandEffector, "RightHandEffector");

        m_LeftKneeHintEffector   = SetupHintEffector(ref job.leftKneeHintEffector, "LeftKneeHintEffector");
        m_RightKneeHintEffector  = SetupHintEffector(ref job.rightKneeHintEffector, "RightKneeHintEffector");
        m_LeftElbowHintEffector  = SetupHintEffector(ref job.leftElbowHintEffector, "LeftElbowHintEffector");
        m_RightElbowHintEffector = SetupHintEffector(ref job.rightElbowHintEffector, "RightElbowHintEffector");

        m_LookAtEffector = SetupLookAtEffector(ref job.lookAtEffector, "LookAtEffector");

        m_BodyRotationEffector = SetupBodyEffector(ref job.bodyEffector, "BodyEffector");



        m_IKPlayable = AnimationScriptPlayable.Create <FullBodyIKJob>(m_Graph, job, 1);
        m_IKPlayable.ConnectInput(0, clipPlayable, 0, 1.0f);

        output.SetSourcePlayable(m_IKPlayable);

        m_Graph.Play();
        m_Graph.Evaluate(0);
        SyncIKFromPose();

        ResetIKWeight();
    }
Beispiel #11
0
        void OnEnable()
        {
            // Validation
            if (bones.Length < 1)
            {
                return;
            }
            if (axis == Vector3.zero)
            {
                return;
            }
            if (poleAxis == Vector3.zero && poleWeight > 0f)
            {
                return;
            }

            animator = GetComponent <Animator>();

            // Creating the target
            if (aimTransform == null)
            {
                aimTransform = bones[bones.Length - 1];
            }

            if (target == null)
            {
                target          = new GameObject("AimIKJ Target (" + name + ")").transform;
                target.position = bones[bones.Length - 1].position + aimTransform.rotation * axis * 3f;
            }

            if (poleTarget == null)
            {
                poleTarget          = new GameObject("AimIKJ Pole Target (" + name + ")").transform;
                poleTarget.position = bones[bones.Length - 1].position + aimTransform.rotation * poleAxis * 3f;
            }

            // Creating the grapsh and output
            graph = PlayableGraph.Create("AimIKJ");
            var output = AnimationPlayableOutput.Create(graph, "ouput", GetComponent <Animator>());

            // Setting up the Job
            job = new AimIKJob();
            job.Setup(GetComponent <Animator>(), bones, target, poleTarget, aimTransform);

            // Creating the playable
            IKPlayable = AnimationScriptPlayable.Create(graph, job);

            var controllerPlayable = AnimatorControllerPlayable.Create(graph, animator.runtimeAnimatorController);

            IKPlayable.AddInput(controllerPlayable, 0, 1.0f);

            // Starting the graphs
            output.SetSourcePlayable(IKPlayable);
            graph.Play();

            initiated = true;
        }
Beispiel #12
0
    void OnEnable()
    {
        // Load animation clips.
        var idleClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "Idle");
        var romClip  = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "ROM");

        if (idleClip == null || romClip == null)
        {
            return;
        }

        var animator = GetComponent <Animator>();

        // Get all the transforms in the hierarchy.
        var transforms    = animator.transform.GetComponentsInChildren <Transform>();
        var numTransforms = transforms.Length - 1;

        // Fill native arrays (all the bones have a weight of 1.0).
        m_Handles     = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        m_BoneWeights = new NativeArray <float>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        for (var i = 0; i < numTransforms; ++i)
        {
            m_Handles[i]     = animator.BindStreamTransform(transforms[i + 1]);
            m_BoneWeights[i] = 1.0f;
        }

        // Create job.
        var job = new MixerJob()
        {
            handles     = m_Handles,
            boneWeights = m_BoneWeights,
            weight      = 0.0f
        };

        // Create graph with custom mixer.
        m_Graph = PlayableGraph.Create("SimpleMixer");
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        m_CustomMixerPlayable = AnimationScriptPlayable.Create(m_Graph, job);
        m_CustomMixerPlayable.SetProcessInputs(false);

        AnimationClipPlayable idlePlayable = CreateAnimationPlayableClip(m_Graph, idleClip);
        AnimationClipPlayable romPlayable  = CreateAnimationPlayableClip(m_Graph, romClip);

        m_CustomMixerPlayable.AddInput(idlePlayable, 0, 1.0f);
        m_CustomMixerPlayable.AddInput(romPlayable, 0, 1.0f);

        var output = AnimationPlayableOutput.Create(m_Graph, "output", animator);

        output.SetSourcePlayable(m_CustomMixerPlayable);

        m_Graph.Play();

        emptyGraph = PlayableGraph.Create("EmptyGraph");
        emptyGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
    }
Beispiel #13
0
        //============================================================================================

        /**
         *  @brief Initializes the rigging integration. This is called automatically by MxM
         *
         *  This function sets up native arrays of TransformStreamHandles so that the transforms
         *  of the rig can be accessed from an animation job
         *
         *  @param [PlayableGraph] a_playableGraph - the playable graph to use for the integration
         *  @param [Animator] a_animator - a reference to the animator component
         *
         *********************************************************************************************/
        public void Initialize(PlayableGraph a_playableGraph, Animator a_animator)
        {
            m_rigBuilder = GetComponentInChildren <RigBuilder>();

            m_fixRigTransforms = false;
            m_lastTimeCached   = Time.time;

            if (m_rigBuilder != null)
            {
                var rigLayers = m_rigBuilder.layers;

                m_rigs = new Rig[rigLayers.Count];
                for (int i = 0; i < rigLayers.Count; ++i)
                {
                    Rig rig = rigLayers[i].rig;
                    m_rigs[i] = rig;
                }
            }

            m_rigStreamHandles  = new NativeArray <TransformStreamHandle>(m_rigControls.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            m_rigTransformCache = new NativeArray <TransformData>(m_rigControls.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            m_rigWeightHandles = new NativeArray <PropertyStreamHandle>(m_rigs.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            m_rigWeightCache   = new NativeArray <float>(m_rigs.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < m_rigControls.Length; ++i)
            {
                Transform controlTransform = m_rigControls[i];

                m_rigStreamHandles[i]  = a_animator.BindStreamTransform(controlTransform);
                m_rigTransformCache[i] = new TransformData()
                {
                    Position = controlTransform.localPosition, Rotation = controlTransform.localRotation
                };
            }

            for (int i = 0; i < m_rigs.Length; ++i)
            {
                m_rigWeightHandles[i] = a_animator.BindStreamProperty(m_rigs[i].transform, typeof(Rig), "m_Weight");
                m_rigWeightCache[i]   = m_rigs[i].weight;
            }

            var rigIntegrationJob = new RiggingIntegrationJob()
            {
                FixRigTransforms  = m_fixRigTransforms,
                RigStreamHandles  = m_rigStreamHandles,
                RigTransformCache = m_rigTransformCache,
                RigWeightHandles  = m_rigWeightHandles,
                RigWeightCache    = m_rigWeightCache,
            };

            m_riggingScriptPlayable = AnimationScriptPlayable.Create(a_playableGraph, rigIntegrationJob);
            var output = AnimationPlayableOutput.Create(a_playableGraph, "RigIntegrationOutput", a_animator);

            output.SetSourcePlayable(m_riggingScriptPlayable);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
    public SMixer(Animator animator, PlayableGraph graph)
    {
        InitHandle(animator);

        SMixerJob _Job = new SMixerJob()
        {
            handles = m_Handles, ApplyRootMotion = animator.applyRootMotion
        };

        m_Mixer = AnimationScriptPlayable.Create(graph, _Job, 2);
        m_Mixer.SetInputWeight(0, 1);
        m_Mixer.SetInputWeight(1, 1);
        m_Mixer.SetProcessInputs(false);
    }
Beispiel #16
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphTwoBoneIk settings)
            {
                var skeleton   = controller.GetComponent <Skeleton>();
                var targetBone = skeleton.bones[skeleton.GetBoneIndex(settings.targetBone.GetHashCode())];
                var drivenBone = skeleton.bones[skeleton.GetBoneIndex(settings.drivenBone.GetHashCode())];

                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;
                var leftArmIkJob = new TwoBoneIKJob();

                leftArmIkJob.Setup(controller.GetComponent <Animator>(), ikSettings, typeof(AnimStateController),
                                   "leftArmIK.weight.value", "leftArmIK.weight.propertyOffset", "leftArmIK.target.offset");
                m_IkPlayable = AnimationScriptPlayable.Create(graph, leftArmIkJob, 1);
                m_IkPlayable.SetInputWeight(0, 1);
            }
Beispiel #17
0
    void OnEnable()
    {
        if (joints.Length == 0)
        {
            return;
        }

        var animator = GetComponent <Animator>();

        // Create job.
        Initialize(animator);
        var dampingJob = new DampingJob()
        {
            rootHandle     = animator.BindStreamTransform(transform),
            jointHandles   = m_Handles,
            localPositions = m_LocalPositions,
            localRotations = m_LocalRotations,
            positions      = m_Positions,
            velocities     = m_Velocities
        };

        // Create graph.
        m_Graph = PlayableGraph.Create("Damping");
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        m_DampingPlayable = AnimationScriptPlayable.Create(m_Graph, dampingJob);

        var output = AnimationPlayableOutput.Create(m_Graph, "output", animator);

        output.SetSourcePlayable(m_DampingPlayable);

        // Start the graph.
        m_Graph.Play();

        // Create effectors for each joints.
        m_JointEffectors = new List <GameObject>(joints.Length);
        foreach (var joint in joints)
        {
            var effector = SampleUtility.CreateEffector(joint.name, joint.position, joint.rotation);
            effector.hideFlags |= HideFlags.HideInHierarchy;
            m_JointEffectors.Add(effector);
        }
    }
Beispiel #18
0
    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();
    }
        public override void RuntimeInitialize(int startNodeIndex)
        {
            base.RuntimeInitialize(startNodeIndex);

            if (Instance == null)
            {
                Instance = this;
            }
            else
            {
                Destroy(this);
            }

            // Creates the graph, the mixer and binds them to the Animator.
            playableGraph  = PlayableGraph.Create(base.name);
            playableOutput = AnimationPlayableOutput.Create(playableGraph, $"{base.name}_Output", PlayerAnimator.Value);
            activePlayable = AnimationScriptPlayable.Create(playableGraph, new NoOpJob());
            playableOutput.SetSourcePlayable(activePlayable);
            playableGraph.Play();
        }
Beispiel #20
0
    void OnEnable()
    {
        var idleClip = SampleUtility.LoadAnimationClipFromFbx("Chomper/Animations/@ChomperIdle", "Cooldown");

        if (idleClip == null)
        {
            return;
        }

        if (joint == null)
        {
            return;
        }

        var targetPosition = joint.position + gameObject.transform.rotation * Vector3.forward;

        m_Target = SampleUtility.CreateEffector("Effector_" + joint.name, targetPosition, Quaternion.identity);

        m_Graph = PlayableGraph.Create("TwoBoneIK");
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var output = AnimationPlayableOutput.Create(m_Graph, "ouput", GetComponent <Animator>());

        var animator = GetComponent <Animator>();

        animator.fireEvents = false;
        var lookAtJob = new LookAtJob()
        {
            joint    = animator.BindStreamTransform(joint),
            target   = animator.BindSceneTransform(m_Target.transform),
            axis     = GetAxisVector(axis),
            minAngle = Mathf.Min(minAngle, maxAngle),
            maxAngle = Mathf.Max(minAngle, maxAngle)
        };

        m_LookAtPlayable = AnimationScriptPlayable.Create(m_Graph, lookAtJob);
        m_LookAtPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f);

        output.SetSourcePlayable(m_LookAtPlayable);
        m_Graph.Play();
    }
Beispiel #21
0
        public override void OnBind()
        {
            if (bindObj && XTimeline.graph.IsValid())
            {
                var amtor         = bindObj.GetComponent <Animator>();
                var transforms    = amtor.transform.GetComponentsInChildren <Transform>();
                var numTransforms = transforms.Length - 1;

                if (timeline.IsHostTrack(this))
                {
                    playableOutput = timeline.blendPlayableOutput;
                    mixPlayable    = timeline.blendMixPlayable;
                    mixJob         = timeline.mixJob;
                }
                else
                {
                    var handles = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent,
                                                                          NativeArrayOptions.UninitializedMemory);
                    for (var i = 0; i < numTransforms; ++i)
                    {
                        handles[i] = amtor.BindStreamTransform(transforms[i + 1]);
                    }
                    mixJob = new MixerJob()
                    {
                        handles = handles, weight = 1.0f
                    };

                    AnimationTrackData Data = data as AnimationTrackData;
                    bindObj.transform.position = Data.pos;
                    bindObj.transform.rotation = Quaternion.Euler(0, Data.rotY, 0);

                    playableOutput = AnimationPlayableOutput.Create(XTimeline.graph, "AnimationOutput", amtor);
                    mixPlayable    = AnimationScriptPlayable.Create(XTimeline.graph, mixJob);
                    mixPlayable.SetProcessInputs(false);
                }
                playableOutput.SetSourcePlayable(mixPlayable);
            }
            base.OnBind();
        }
        private void Awake()
        {
            graph = PlayableGraph.Create(graphName);
            graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            var job = new AnimationIKApplyJobPlayable();

            animationPostprocess = AnimationScriptPlayable.Create(graph, job, 1);
            animationOutput      = ScriptPlayable <IKAnimationOutputBehavior> .Create(graph,
                                                                                      new IKAnimationOutputBehavior { postprocess = animationPostprocess });

            animationOutput.SetTraversalMode(PlayableTraversalMode.Mix);
            animationPostprocess.ConnectInput(0, animationOutput, 0);

            animatorOutput = AnimationPlayableOutput.Create(graph, graphName + ".Animation", playableAnimator);
            animatorOutput.SetSourcePlayable(animationPostprocess);

            rootLayerMixer = new LayerMixerNode(graph, gameObject);
            AttachOutputs(rootLayerMixer);

            graph.Play();
        }
        protected override AnimationScriptPlayable InitializePlayable()
        {
            // Create job
            var job = new SequenceBlendJob()
            {
                handles     = boneHandles,
                boneWeights = boneWeights,
                weight      = 0f,
                poseAIndex  = 0,
                poseBIndex  = 1
            };

            var scriptPlayable = AnimationScriptPlayable.Create(sharedData.PlayableGraph, job);

            scriptPlayable.SetProcessInputs(false);
            sequenceList.ForEach(clip =>
            {
                scriptPlayable.AddInput(AnimationClipPlayable.Create(sharedData.PlayableGraph, clip.pose), 0, 0f);
            });

            return(scriptPlayable);
        }
Beispiel #24
0
        void OnEnable()
        {
            // Validation
            if (bones.Length < 3)
            {
                return;
            }

            animator = GetComponent <Animator>();

            // Creating the target
            if (target == null)
            {
                target          = new GameObject("CCDIKJ Target (" + name + ")").transform;
                target.position = bones[bones.Length - 1].position;
                target.rotation = bones[bones.Length - 1].rotation;
            }

            // Creating the grapsh and output
            graph = PlayableGraph.Create("CCDIKJ");
            var output = AnimationPlayableOutput.Create(graph, "ouput", GetComponent <Animator>());

            // Setting up the Job
            job = new CCDIKJob();
            job.Setup(GetComponent <Animator>(), bones, target);

            // Creating the playable
            IKPlayable = AnimationScriptPlayable.Create(graph, job);

            var controllerPlayable = AnimatorControllerPlayable.Create(graph, animator.runtimeAnimatorController);

            IKPlayable.AddInput(controllerPlayable, 0, 1.0f);

            // Starting the graphs
            output.SetSourcePlayable(IKPlayable);
            graph.Play();

            initiated = true;
        }
Beispiel #25
0
    void OnEnable()
    {
        animator = GetComponent <Animator>();

        if (!animator.avatar.isHuman)
        {
            throw new InvalidOperationException("Avatar must be a humanoid.");
        }

        graph = PlayableGraph.Create();
        var output = AnimationPlayableOutput.Create(graph, "output", animator);

        var job = new FullBodyIKJob();

        leftFootEffector  = SetupEffector(ref job.leftFootEffector, "leftFootEffector");
        rightFootEffector = SetupEffector(ref job.rightFootEffector, "rightFootEffector");
        leftHandEffector  = SetupEffector(ref job.leftHandEffector, "leftHandEffector");
        rightHandEffector = SetupEffector(ref job.rightHandEffector, "rightHandEffector");

        leftKneeHintEffector   = SetupHintEffector(ref job.leftKneeHintEffector, "leftKneeHintEffector");
        rightKneeHintEffector  = SetupHintEffector(ref job.rightKneeHintEffector, "rightKneeHintEffector");
        leftElbowHintEffector  = SetupHintEffector(ref job.leftElbowHintEffector, "leftElbowHintEffector");
        rightElbowHintEffector = SetupHintEffector(ref job.rightElbowHintEffector, "rightElbowHintEffector");

        lookAtEffector = SetupLookAtEffector(ref job.lookAtEffector, "lookAtEffector");

        bodyRotationEffector = SetupBodyEffector(ref job.bodyEffector, "bodyEffector");

        ikPlayable = AnimationScriptPlayable.Create <FullBodyIKJob>(graph, job);

        output.SetSourcePlayable(ikPlayable);

        // Sync IK goal on original pose and activate ik weight
        SyncIKFromPose();
        ResetIKWeight();

        graph.Play();
    }
        // Start is called before the first frame update
        void Start()
        {
            graph = PlayableGraph.Create(name);

            if (m_maxSpringJoint <= 0)
            {
                m_maxSpringJoint = 4;
            }

            // points.
            m_SphereGameObjects = new GameObject[m_maxSpringJoint];
            for (int ii = 0; ii < m_maxSpringJoint; ii++)
            {
                m_SphereGameObjects[ii]       = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                m_SphereGameObjects[ii].layer = 8; // todo.
                m_SphereGameObjects[ii].transform.position =
                    new Vector3(0.0f, floorPositionY - (float)ii, 0.0f);
                m_SphereGameObjects[ii].name = "joint" + ii;
                if (GameObjectMaterial != null)
                {
                    var renderer =
                        m_SphereGameObjects[ii].GetComponent <MeshRenderer>();
                    renderer.material = GameObjectMaterial;
                }
            }
#if false
            // capusles.
            m_CapsuleGameObjects = new GameObject[m_maxSpringJoint - 1];
            for (int ii = 0; ii < m_maxSpringJoint - 1; ii++)
            {
                m_CapsuleGameObjects[ii] = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                m_CapsuleGameObjects[ii].transform.position = new Vector3(0.0f, -0.5f + (float)-ii, 0.0f);
            }
#endif
            m_rootGameObject = new GameObject();
            // Parent-child relationship.
#if false
            for (int ii = 1; ii < m_maxSpringJoint; ii++)
            {
                m_SphereGameObjects[ii].transform.parent = m_SphereGameObjects[ii - 1].transform;
            }
            if (m_CapsuleGameObjects != null)
            {
                for (int ii = 0; ii < m_maxSpringJoint - 1; ii++)
                {
                    m_CapsuleGameObjects[ii].transform.parent = m_SphereGameObjects[ii].transform;
                }
            }
            var animator = m_SphereGameObjects[0].AddComponent <Animator>();

            UnityEngine.AvatarBuilder.BuildGenericAvatar(
                m_SphereGameObjects[0], m_SphereGameObjects[0].name);
#else
            for (int ii = 0; ii < m_maxSpringJoint; ii++)
            {
                m_SphereGameObjects[ii].transform.parent = m_rootGameObject.transform;
            }
            var animator = m_rootGameObject.AddComponent <Animator>();

            UnityEngine.AvatarBuilder.BuildGenericAvatar(
                m_rootGameObject, m_rootGameObject.name);
#endif
            joints = new NativeArray <TransformStreamHandle>(m_maxSpringJoint, Allocator.Persistent);
            for (int ii = 0; ii < m_maxSpringJoint; ii++)
            {
                joints[ii] = animator.BindStreamTransform(m_SphereGameObjects[ii].transform);
            }


            //           AnimatorUtility.OptimizeTransformHierarchy(m_SphereGameObjects[0], null);
#if false
            effectors = new NativeArray <TransformSceneHandle>(m_maxSpringJoint, Allocator.Persistent);
            for (int ii = 0; ii < m_maxSpringJoint; ii++)
            {
                effectors[ii] = animator.BindSceneTransform(new GameObject().transform);
            }
            ;
#endif
            // targetEffector = animator.BindSceneTransform(m_targetGameObject.transform);

            job = new AnimationJob()
            {
                //                effectors = effectors,
                joints             = joints,
                floorPositionY     = floorPositionY,
                rootOffset         = rootOffset,
                restLength         = restLength,
                hangGameObjectFlag = HangGameObject ? 1:0,
                //    targetEffector = targetEffector,
            };
            job.SetUp();
            var playable = AnimationScriptPlayable.Create(graph, job);


            AnimationPlayableUtilities.Play(animator, playable, graph);
        }
Beispiel #27
0
        public CharacterAnimGraph_3PStand(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Stand template)
        {
            if (s_Instances == null)
            {
                s_Instances = new List <CharacterAnimGraph_3PStand>(16);
            }

            s_Instances.Add(this);


            m_template       = template;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            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);

            GameDebug.Assert(entityManager.HasComponent <CharPredictedStateData>(m_AnimStateOwner), "Owner has no CharPredictedState component");

            var leftToes  = skeleton.bones[skeleton.GetBoneIndex(template.leftToeBone.GetHashCode())];
            var rightToes = skeleton.bones[skeleton.GetBoneIndex(template.rightToeBone.GetHashCode())];

            // Locomotion mixer and loco animation
            m_locomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

            // Idle
            m_animIdle = AnimationClipPlayable.Create(graph, template.animIdle);
            m_animIdle.SetApplyFootIK(true);
            graph.Connect(m_animIdle, 0, m_locomotionMixer, (int)LocoMixerPort.Idle);
            m_locomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

            // Turns and trasitions
            m_animTurnL = CreateTurnAnim(graph, template.animTurnL, LocoMixerPort.TurnL);
            m_animTurnR = CreateTurnAnim(graph, template.animTurnR, LocoMixerPort.TurnR);

            var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

            m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_locomotionMixer, ports);

            // Foot IK
            if (m_template.animTurnL.events.Length != 0)
            {
                m_LeftTurnFootFalls  = ExtractFootFalls(m_template.animTurnL);
                m_RightTurnFootFalls = ExtractFootFalls(m_template.animTurnR);
            }

            var ikJob = new FootIkJob
            {
                settings = m_template.footIK,
                leftToe  = animator.BindStreamTransform(leftToes),
                rightToe = animator.BindStreamTransform(rightToes)
            };

            m_footIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
            graph.Connect(m_locomotionMixer, 0, m_footIk, 0);
            m_footIk.SetInputWeight(0, 1f);

            m_defaultLayer  = LayerMask.NameToLayer("Default");
            m_playerLayer   = LayerMask.NameToLayer("collision_player");
            m_platformLayer = LayerMask.NameToLayer("Platform");

            m_mask = 1 << m_defaultLayer | 1 << m_playerLayer | 1 << m_platformLayer;

            // Aim and Aim mixer
            m_aimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

            m_animAimLeft  = CreateAimAnim(graph, template.animAimLeft, AimMixerPort.AimLeft);
            m_animAimMid   = CreateAimAnim(graph, template.animAimMid, AimMixerPort.AimMid);
            m_animAimRight = CreateAimAnim(graph, template.animAimRight, AimMixerPort.AimRight);

            // Setup other additive mixer
            m_additiveMixer = AnimationLayerMixerPlayable.Create(graph);

            var locoMixerPort = m_additiveMixer.AddInput(m_footIk, 0);

            m_additiveMixer.SetInputWeight(locoMixerPort, 1);

            var aimMixerPort = m_additiveMixer.AddInput(m_aimMixer, 0);

            m_additiveMixer.SetInputWeight(aimMixerPort, 1);
            m_additiveMixer.SetLayerAdditive((uint)aimMixerPort, true);

            // Actions
            m_actionAnimationHandler = new ActionAnimationHandler(m_additiveMixer, template.actionAnimations);

            m_ReloadActionAnimation = m_actionAnimationHandler.GetActionAnimation(CharPredictedStateData.Action.Reloading);

            // Shoot pose
            m_animShootPose = AnimationClipPlayable.Create(graph, template.animShootPose);
            m_animShootPose.SetApplyFootIK(false);
            m_animShootPose.SetDuration(template.animShootPose.length);
            m_animShootPose.Pause();
            m_ShootPosePort = m_additiveMixer.AddInput(m_animShootPose, 0);
            m_additiveMixer.SetInputWeight(m_ShootPosePort, 0.0f);
            m_additiveMixer.SetLayerAdditive((uint)m_ShootPosePort, true);
        }
Beispiel #28
0
 /// <inheritdoc />
 AnimationScriptPlayable IAnimationJobBinder.CreatePlayable(PlayableGraph graph, IAnimationJob job)
 {
     Debug.Assert(job is TJob);
     return(AnimationScriptPlayable.Create(graph, (TJob)job));
 }
    void OnEnable()
    {
        // Load animation clips.
        var idleClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "Idle");
        var romClip  = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "ROM");

        if (idleClip == null || romClip == null)
        {
            return;
        }

        var animator = GetComponent <Animator>();

        // Get all the transforms in the hierarchy.
        var allTransforms = animator.transform.GetComponentsInChildren <Transform>();
        var numTransforms = allTransforms.Length - 1;

        // Fill native arrays (all the bones have a weight of 0.0).
        m_Handles     = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        m_BoneWeights = new NativeArray <float>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        for (var i = 0; i < numTransforms; ++i)
        {
            m_Handles[i] = animator.BindStreamTransform(allTransforms[i + 1]);
        }

        // Set bone weights for selected transforms and their hierarchy.
        m_BoneChildrenIndices = new List <List <int> >(boneTransformWeights.Length);
        foreach (var boneTransform in boneTransformWeights)
        {
            var childrenTransforms = boneTransform.transform.GetComponentsInChildren <Transform>();
            var childrenIndices    = new List <int>(childrenTransforms.Length);
            foreach (var childTransform in childrenTransforms)
            {
                var boneIndex = Array.IndexOf(allTransforms, childTransform);
                Debug.Assert(boneIndex > 0, "Index can't be less or equal to 0");
                childrenIndices.Add(boneIndex - 1);
            }

            m_BoneChildrenIndices.Add(childrenIndices);
        }

        // Create job.
        var job = new MixerJob()
        {
            handles     = m_Handles,
            boneWeights = m_BoneWeights,
            weight      = 1.0f
        };

        // Create graph with custom mixer.
        m_Graph = PlayableGraph.Create("CustomMixer");

        m_CustomMixerPlayable = AnimationScriptPlayable.Create(m_Graph, job);
        m_CustomMixerPlayable.SetProcessInputs(false);
        m_CustomMixerPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f);
        m_CustomMixerPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, romClip), 0, 1.0f);

        var output = AnimationPlayableOutput.Create(m_Graph, "output", animator);

        output.SetSourcePlayable(m_CustomMixerPlayable);

        m_Graph.Play();
    }