/// <summary>
        /// Setup binding between character joints and animator stream, that will be written by Kinematica job
        /// </summary>
        /// <param name="animator">Unity animator associated with the animation job</param>
        /// <param name="transforms">Character joint transforms</param>
        /// <param name="synthesizer">Reference to motion synthesizer</param>
        /// <param name="deltaTimePropertyHandle">Property handle for the deltaTime</param>
        /// <returns></returns>
        public bool Setup(Animator animator, Transform[] transforms, ref MotionSynthesizer synthesizer, PropertySceneHandle deltaTimePropertyHandle)
        {
            this.synthesizer = MemoryRef <MotionSynthesizer> .Create(ref synthesizer);

            int numJoints = synthesizer.Binary.numJoints;

            this.transforms = new NativeArray <TransformStreamHandle>(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            boundJoints = new NativeArray <bool>(numJoints, Allocator.Persistent, NativeArrayOptions.ClearMemory);

            // Root joint is always first transform, and names don't need to match contrary to other joints
            this.transforms[0] = animator.BindStreamTransform(transforms[0]);
            boundJoints[0]     = true;

            for (int i = 1; i < transforms.Length; i++)
            {
                int jointNameIndex = synthesizer.Binary.GetStringIndex(transforms[i].name);
                int jointIndex     = (jointNameIndex >= 0) ? synthesizer.Binary.animationRig.GetJointIndexForNameIndex(jointNameIndex) : -1;
                if (jointIndex >= 0)
                {
                    this.transforms[jointIndex] = animator.BindStreamTransform(transforms[i]);
                    boundJoints[jointIndex]     = true;
                }
            }

            deltaTime = deltaTimePropertyHandle;

            return(true);
        }
            public void Setup(Animator animator, RotationConstraint[] constraints)
            {
                int count = constraints.Length;

                referenceTransforms = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                currentTransforms   = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                minMaxSpeeds = new NativeArray <Vector2>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                minMaxAngles = new NativeArray <Vector2>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                lastPositions    = new NativeArray <Vector3>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                initialRotations = new NativeArray <Quaternion>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                lastAngles       = new NativeArray <float>(count, Allocator.Persistent);

                for (int i = 0; i < count; ++i)
                {
                    Assert.IsTrue(constraints[i].referenceTransform != null);
                    Assert.IsTrue(constraints[i].transform != null);

                    referenceTransforms[i] = animator.BindStreamTransform(constraints[i].referenceTransform);
                    currentTransforms[i]   = animator.BindStreamTransform(constraints[i].transform);

                    minMaxSpeeds[i] = new Vector2(constraints[i].minimumSpeed, constraints[i].maximumSpeed);
                    minMaxAngles[i] = new Vector2(constraints[i].minimumAngle, constraints[i].maximumAngle);

                    lastPositions[i]    = constraints[i].referenceTransform.position;
                    initialRotations[i] = constraints[i].transform.localRotation;
                }

                deltaTime = animator.BindSceneProperty(animator.gameObject.transform, typeof(Unit), "m_deltaTime");
            }
Пример #3
0
        /************************************************************************************************************************/

        public static NativeArray <TransformStreamHandle> GetDefaultHumanoidLeanBones(Animator animator)
        {
            var leanBones = new NativeArray <TransformStreamHandle>(2, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            leanBones[0] = animator.BindStreamTransform(animator.GetBoneTransform(HumanBodyBones.Spine));
            leanBones[1] = animator.BindStreamTransform(animator.GetBoneTransform(HumanBodyBones.Chest));
            return(leanBones);
        }
Пример #4
0
//
    public bool Setup(Animator animator, EditorSettings editorSettings)
    {
        jobSettings = editorSettings.jobSettings;

        m_CameraHandle  = animator.BindStreamTransform(editorSettings.cameraBone);
        m_CharacterRoot = animator.BindStreamTransform(editorSettings.characterRootBone);
        return(true);
    }
Пример #5
0
    public void Setup(Animator animator, Transform topX, Transform midX, Transform lowX, Transform effectorX)
    {
        top = animator.BindStreamTransform(topX);
        mid = animator.BindStreamTransform(midX);
        low = animator.BindStreamTransform(lowX);

        effector = animator.BindSceneTransform(effectorX);
    }
Пример #6
0
    public bool Setup(Animator animator, IkChain chain, Type componentType, string weightProperty, string weightOffsetProperty, string targetOffsetProperty)
    {
        if (!chain.HasValidData())
        {
            return(false);
        }

        // Target
        m_TargetOffset = chain.target.offset;

        if (chain.target.readFrom == TargetType.Stream)
        {
            m_EffectorStreamHandle = animator.BindStreamTransform(chain.target.target);
            m_UseStreamEffector    = true;
        }
        else
        {
            m_EffectorSceneHandle = animator.BindSceneTransform(chain.target.target);
            m_UseStreamEffector   = false;
        }


        // Weight
        if (chain.weight.useAnimatorProperty && chain.weight.propertyName != "")
        {
            m_AnimatorWeight      = animator.BindStreamProperty(animator.transform, typeof(Animator), chain.weight.propertyName);
            m_UseAnimatorProperty = true;
        }

        m_WeightHandle         = animator.BindSceneProperty(animator.transform, componentType, weightProperty);
        m_AnimatorWeightOffset = animator.BindSceneProperty(animator.transform, componentType, weightOffsetProperty);


        // Driven
        m_IkType = chain.driven.type;

        if (m_IkType == IkType.Generic)
        {
            var end   = chain.driven.genericEndJoint;
            var mid   = end.parent;
            var start = mid.parent;

            m_StartHandle = animator.BindStreamTransform(start);
            m_MidHandle   = animator.BindStreamTransform(mid);
            m_EndHandle   = animator.BindStreamTransform(end);
        }
        else
        {
            m_HumanLimb = chain.driven.humanoidLimb;
        }

        return(true);
    }
Пример #7
0
    public bool Setup(Animator animator, EditorSettings editorSettings, float deltaTime, NativeQueue <Quaternion> dragHistory)
    {
        if (!editorSettings.HasValidData())
        {
            return(false);
        }

        settings           = editorSettings.settings;
        m_Effectorhandle   = animator.BindStreamTransform(editorSettings.weaponHandBone);
        m_WeaponPivot      = animator.BindStreamTransform(editorSettings.weaponBone);
        m_WeaponHandResult = animator.BindSceneTransform(editorSettings.applyResultOn);
        m_DragHistory      = dragHistory;
        return(true);
    }
Пример #8
0
        public void Setup(Animator animator, Transform[] bones, Transform target)
        {
            this.bones       = new NativeArray <UnityEngine.Animations.TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length - 1, Allocator.Persistent);
            this.boneSqrMags = new NativeArray <float>(bones.Length - 1, Allocator.Persistent);

            for (int i = 0; i < this.bones.Length; i++)
            {
                this.bones[i] = animator.BindStreamTransform(bones[i]);
            }

            for (int i = 0; i < this.bones.Length - 1; i++)
            {
                var boneParams = bones[i].gameObject.GetComponent <IKJBoneParams>();
                if (boneParams == null)
                {
                    boneParams = bones[i].gameObject.AddComponent <IKJBoneParams>();
                }

                this.boneWeights[i] = animator.BindSceneProperty(bones[i].transform, typeof(IKJBoneParams), "weight");
            }

            // Rotation Limits
            SetUpRotationLimits(animator, bones);

            _target           = animator.BindSceneTransform(target);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "weight");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(CCDIKJ), "useRotationLimits");
        }
Пример #9
0
        public void Setup(Animator animator, Transform[] bones, Transform target, Transform poleTarget, Transform aimTransform)
        {
            this.bones       = new NativeArray <UnityEngine.Animations.TransformStreamHandle>(bones.Length, Allocator.Persistent);
            this.boneWeights = new NativeArray <UnityEngine.Animations.PropertySceneHandle>(bones.Length, Allocator.Persistent);

            for (int i = 0; i < this.bones.Length; i++)
            {
                this.bones[i] = animator.BindStreamTransform(bones[i]);
            }


            for (int i = 0; i < this.bones.Length; i++)
            {
                var boneParams = bones[i].gameObject.GetComponent <IKJBoneParams>();
                if (boneParams == null)
                {
                    boneParams = bones[i].gameObject.AddComponent <IKJBoneParams>();
                }

                this.boneWeights[i] = animator.BindSceneProperty(bones[i].transform, typeof(IKJBoneParams), "weight");
            }

            // Rotation Limits
            SetUpRotationLimits(animator, bones);

            _target           = animator.BindSceneTransform(target);
            _poleTarget       = animator.BindSceneTransform(poleTarget);
            _transform        = animator.BindStreamTransform(aimTransform);
            _IKPositionWeight = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "weight");
            _poleWeight       = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleWeight");
            _axisX            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisX");
            _axisY            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisY");
            _axisZ            = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "axisZ");
            _poleAxisX        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisX");
            _poleAxisY        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisY");
            _poleAxisZ        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "poleAxisZ");
            _clampWeight      = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampWeight");
            _clampSmoothing   = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "clampSmoothing");
            _maxIterations    = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "maxIterations");
            _tolerance        = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "tolerance");
            _XY = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "XY");
            _useRotationLimits = animator.BindSceneProperty(animator.transform, typeof(AimIKJ), "useRotationLimits");

            step = 1f / (float)bones.Length;
        }
Пример #10
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);
        }
Пример #11
0
            public void Setup(Animator animator, AverageConstraint[] constraints)
            {
                int count = constraints.Length;

                startTransforms   = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                endTransforms     = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                currentTransforms = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                for (int i = 0; i < count; ++i)
                {
                    Assert.IsTrue(constraints[i].startTransform != null);
                    Assert.IsTrue(constraints[i].endTransform != null);
                    Assert.IsTrue(constraints[i].transform != null);

                    startTransforms[i]   = animator.BindStreamTransform(constraints[i].startTransform);
                    endTransforms[i]     = animator.BindStreamTransform(constraints[i].endTransform);
                    currentTransforms[i] = animator.BindStreamTransform(constraints[i].transform);
                }
            }
Пример #12
0
        /// <summary>
        /// Create a ReadWriteTransformHandle representing the new binding between the Animator and a Transform already bound to the Animator.
        /// </summary>
        /// <param name="animator">The Animator on which to bind the new handle.</param>
        /// <param name="transform">The Transform to bind.</param>
        /// <returns>Returns the ReadWriteTransformHandle that represents the new binding.</returns>
        public static ReadWriteTransformHandle Bind(Animator animator, Transform transform)
        {
            ReadWriteTransformHandle handle = new ReadWriteTransformHandle();

            if (transform == null || !transform.IsChildOf(animator.transform))
            {
                return(handle);
            }

            handle.m_Handle = animator.BindStreamTransform(transform);
            return(handle);
        }
Пример #13
0
    protected Transform[] InitHandle(Animator animator)
    {
        // Get all the transforms in the hierarchy.
        Transform[] boneList      = animator.transform.GetComponentsInChildren <Transform>();
        var         numTransforms = boneList.Length - 1;

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

        return(boneList);
    }
Пример #14
0
            public void Setup(Animator animator, LookAtConstraint[] constraints)
            {
                int count = constraints.Length;

                targetTransforms  = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                upAxisTransforms  = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                currentTransforms = new NativeArray <TransformStreamHandle>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                lookAtAxes        = new NativeArray <Vector3>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                upAxes            = new NativeArray <Vector3>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                for (int i = 0; i < count; ++i)
                {
                    Assert.IsTrue(constraints[i].targetTransform != null);
                    Assert.IsTrue(constraints[i].upAxisTransform != null);
                    Assert.IsTrue(constraints[i].transform != null);

                    targetTransforms[i]  = animator.BindStreamTransform(constraints[i].targetTransform);
                    upAxisTransforms[i]  = animator.BindStreamTransform(constraints[i].upAxisTransform);
                    currentTransforms[i] = animator.BindStreamTransform(constraints[i].transform);

                    lookAtAxes[i] = Convert(constraints[i].lookAtAxis);
                    upAxes[i]     = Convert(constraints[i].upAxis);
                }
            }
        private void CollectAndBindAnimationTransforms()
        {
            List <Transform> transforms = new List <Transform>(60);

            if (m_animator.isHuman)
            {
                for (int i = 0; i < (int)HumanBodyBones.LastBone; ++i)
                {
                    var boneTransform = m_animator.GetBoneTransform((HumanBodyBones)i);

                    if (boneTransform != null)
                    {
                        transforms.Add(boneTransform);
                    }
                }
            }

            if (m_avatarMask != null)
            {
                //All non human bones
                for (int i = 0; i < m_avatarMask.transformCount; ++i)
                {
                    var jointTransformPath = m_avatarMask.GetTransformPath(i);
                    var jointTransform     = m_animator.transform.Find(jointTransformPath);

                    if (jointTransform != null)
                    {
                        transforms.Add(jointTransform);
                    }
                }
            }

            m_transforms = transforms.ToArray();

            m_targetAnimationTransforms   = new NativeArray <TransformStreamHandle>(m_transforms.Length, Allocator.Persistent);
            m_currentAnimationTransforms  = new NativeArray <TransformSceneHandle>(m_transforms.Length, Allocator.Persistent);
            m_previousAnimationTransforms = new NativeArray <TransformData>(m_transforms.Length, Allocator.Persistent);

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

                m_targetAnimationTransforms[i]   = m_animator.BindStreamTransform(tform);
                m_currentAnimationTransforms[i]  = m_animator.BindSceneTransform(tform);
                m_previousAnimationTransforms[i] = new TransformData(tform.position, tform.rotation);
            }
        }
Пример #16
0
        public override SyncSceneToStreamJob Create(Animator animator, ref T data)
        {
            var job = new SyncSceneToStreamJob();

            var objects = data.objects;
            var sync = data.sync;
            job.sceneHandles = new NativeArray<TransformSceneHandle>(objects.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.streamHandles = new NativeArray<TransformStreamHandle>(objects.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            job.syncSceneToStream = new BitArray(data.sync);

            for (int i = 0; i < objects.Length; ++i)
            {
                job.sceneHandles[i] = animator.BindSceneTransform(objects[i]);
                job.streamHandles[i] = animator.BindStreamTransform(objects[i]);
            }

            return job;
        }
Пример #17
0
    void Initialize(Animator animator)
    {
        // Create arrays (without the root which has its own handle).
        var numJoints = joints.Length;

        m_Handles        = new NativeArray <TransformStreamHandle>(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        m_LocalPositions = new NativeArray <Vector3>(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        m_LocalRotations = new NativeArray <Quaternion>(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        m_Positions      = new NativeArray <Vector3>(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        for (var i = 0; i < numJoints; ++i)
        {
            m_Handles[i]        = animator.BindStreamTransform(joints[i]);
            m_LocalPositions[i] = joints[i].localPosition;
            m_LocalRotations[i] = joints[i].localRotation;
            m_Positions[i]      = joints[i].position;
        }

        m_Velocities = new NativeArray <Vector3>(numJoints, Allocator.Persistent);
    }
Пример #18
0
        /// <summary>
        /// Create a ReadOnlyTransformHandle representing the new binding between the Animator and a Transform already bound to the Animator.
        /// </summary>
        /// <param name="animator">The Animator on which to bind the new handle.</param>
        /// <param name="transform">The Transform to bind.</param>
        /// <returns>Returns the ReadOnlyTransformHandle that represents the new binding.</returns>
        public static ReadOnlyTransformHandle Bind(Animator animator, Transform transform)
        {
            ReadOnlyTransformHandle handle = new ReadOnlyTransformHandle();

            if (transform == null)
            {
                return(handle);
            }

            handle.m_InStream = (byte)(transform.IsChildOf(animator.transform) ? 1 : 0);
            if (handle.m_InStream == 1)
            {
                handle.m_StreamHandle = animator.BindStreamTransform(transform);
            }
            else
            {
                handle.m_SceneHandle = animator.BindSceneTransform(transform);
            }

            return(handle);
        }
        public SharedAnimationData(
            Animator animator,
            PlayableGraph playableGraph)
        {
            Animator      = animator;
            PlayableGraph = playableGraph;

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

            // Fill native arrays (all the bones have a weight of 0.0).
            boneHandles = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory);
            boneWeights = new NativeArray <float>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory);
            for (var i = 0; i < numTransforms; ++i)
            {
                boneHandles[i] = animator.BindStreamTransform(AllAnimatorTransforms[i + 1]);
                boneWeights[i] = 1;
            }
            bonesLastFrame = new NativeArray <BoneLocation>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        }
Пример #20
0
    public bool Setup(Animator animator, EditorSettings editorSettings, float deltaTime,
                      NativeArray <MuscleHandle> headMuscles, NativeArray <MuscleHandle> spineMuscles)
    {
        if (!editorSettings.HasValidData())
        {
            return(false);
        }

        m_SkeletonHandle = animator.BindStreamTransform(editorSettings.bankTransform);

        m_HeadLeftRightMuscles  = headMuscles;
        m_SpineLeftRightMuscles = spineMuscles;

        m_HeadLeftRightMuscles[0] = new MuscleHandle(HeadDof.NeckLeftRight);
        m_HeadLeftRightMuscles[1] = new MuscleHandle(HeadDof.HeadLeftRight);

        m_SpineLeftRightMuscles[0] = new MuscleHandle(BodyDof.SpineLeftRight);
        m_SpineLeftRightMuscles[1] = new MuscleHandle(BodyDof.ChestLeftRight);
        m_SpineLeftRightMuscles[2] = new MuscleHandle(BodyDof.UpperChestLeftRight);


        return(true);
    }
Пример #21
0
 public void Setup(Animator animator, Transform boneToFollow, Transform slavedTransform)
 {
     m_BoneToFollow    = animator.BindStreamTransform(boneToFollow);
     m_SlavedTransform = animator.BindSceneTransform(slavedTransform);
 }
Пример #22
0
 private void SetupIKLimbHandle(ref FullBodyIKJob.IKLimbHandle handle, HumanBodyBones top, HumanBodyBones middle, HumanBodyBones end)
 {
     handle.top    = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(top));
     handle.middle = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(middle));
     handle.end    = m_Animator.BindStreamTransform(m_Animator.GetBoneTransform(end));
 }
Пример #23
0
    public void Setup(Animator animator, Skeleton skeleton, AvatarMask boneMask)
    {
        int numBones;
        var activeBones = new List <Transform>();

        if (boneMask != null)
        {
            for (var i = 0; i < boneMask.transformCount; i++)
            {
                if (boneMask.GetTransformActive(i))
                {
                    var tokens        = boneMask.GetTransformPath(i).Split('/');
                    var name          = tokens[tokens.Length - 1];
                    var skeletonIndex = skeleton.GetBoneIndex(name.GetHashCode());

                    if (skeletonIndex != -1)
                    {
                        activeBones.Add(skeleton.bones[skeletonIndex]);
                    }
                }
            }

            numBones = activeBones.Count;
        }

        else
        {
            numBones = skeleton.bones.Length;
        }

        m_CurrentBufferIndex = -1;

        m_Bones = new NativeArray <TransformStreamHandle>(numBones, Allocator.Persistent);

        m_OutputPositions = new NativeArray <float3>(numBones * k_OutputBufferCount, Allocator.Persistent);
        m_OutputRotations = new NativeArray <quaternion>(numBones * k_OutputBufferCount, Allocator.Persistent);
        m_OutputScales    = new NativeArray <float3>(numBones * k_OutputBufferCount, Allocator.Persistent);

        m_OutputIkPositions = new NativeArray <float3>(k_NumIkHandles * k_OutputBufferCount, Allocator.Persistent);
        m_OutputIkRotations = new NativeArray <quaternion>(k_NumIkHandles * k_OutputBufferCount, Allocator.Persistent);

        m_PosDirArray      = new NativeArray <float3>(numBones, Allocator.Persistent);
        m_PosDeltaArray    = new NativeArray <float>(numBones, Allocator.Persistent);
        m_PosDeltaVelArray = new NativeArray <float>(numBones, Allocator.Persistent);

        m_RotAxisArray     = new NativeArray <float3>(numBones, Allocator.Persistent);
        m_RotDeltaArray    = new NativeArray <float>(numBones, Allocator.Persistent);
        m_RotDeltaVelArray = new NativeArray <float>(numBones, Allocator.Persistent);

        m_StarteScaleArray = new NativeArray <float3>(numBones, Allocator.Persistent);

        m_FromIkPositions = new NativeArray <float3>(k_NumIkHandles, Allocator.Persistent);
        m_FromIkRotations = new NativeArray <quaternion>(k_NumIkHandles, Allocator.Persistent);



        for (var i = 0; i < numBones; i++)
        {
            if (boneMask != null)
            {
                m_Bones[i] = animator.BindStreamTransform(activeBones[i]);
            }
            else
            {
                m_Bones[i] = animator.BindStreamTransform(skeleton.bones[i]);
            }
        }
    }
 public void BindAt(int index, Animator animator, Transform transform)
 {
     sceneHandles[index]  = animator.BindSceneTransform(transform);
     streamHandles[index] = animator.BindStreamTransform(transform);
 }