private static BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1, LocalTranslationDefaultValue = new float3(100.0f, 0.0f, 0.0f), LocalRotationDefaultValue = quaternion.RotateX(math.radians(90.0f)), LocalScaleDefaultValue = new float3(10.0f, 1.0f, 1.0f)
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1, LocalTranslationDefaultValue = new float3(0.0f, 100.0f, 0.0f), LocalRotationDefaultValue = quaternion.RotateY(math.radians(90.0f)), LocalScaleDefaultValue = new float3(1.0f, 1.0f, 10.0f)
                }
            };

            var animationChannel = new IAnimationChannel[] {
                new FloatChannel {
                    Id = "Root", DefaultValue = 10f
                },
                new FloatChannel {
                    Id = "Child1", DefaultValue = 10f
                },
                new IntChannel {
                    Id = "Root", DefaultValue = 20
                },
                new IntChannel {
                    Id = "Child1", DefaultValue = 20
                }
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
        private static BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode
                {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1,
                    LocalTranslationDefaultValue = new float3(0, 0, 0),
                    LocalRotationDefaultValue    = new quaternion(0, 0, 0, 1),
                    LocalScaleDefaultValue       = new float3(1, 1, 1),
                },
                new SkeletonNode
                {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1,
                    LocalTranslationDefaultValue = new float3(0, 0, 0),
                    LocalRotationDefaultValue    = new quaternion(0, 0, 0, 1),
                    LocalScaleDefaultValue       = new float3(1, 1, 1),
                },
                new SkeletonNode
                {
                    ParentIndex = 0, Id = "Child2", AxisIndex = -1,
                    LocalTranslationDefaultValue = new float3(0, 0, 0),
                    LocalRotationDefaultValue    = new quaternion(0, 0, 0, 1),
                    LocalScaleDefaultValue       = new float3(1, 1, 1),
                }
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes));
        }
    public void Init(CharacterParametersSO charSO)
    {
        parametersSO = charSO;

        agent        = GetComponent <NavMeshAgent>();
        animator     = GetComponent <Animator>();
        currentState = CharacterStates.Idle;

        mainCollider     = GetComponent <Collider>();
        ragdollColliders = GetComponentsInChildren <Collider>(true);
        rb  = GetComponent <Rigidbody>();
        rbs = GetComponentsInChildren <Rigidbody>(true);

        rigBuilder         = GetComponent <RigBuilder>();
        rigBuilder.enabled = false;

        if (parametersSO.team != 1)
        {
            SetBullet(PlayerControlHandler.instance.bulletParametersSO[0]);
        }

        GetComponentInChildren <SpriteRenderer>().color = parametersSO.team == 1 ? Color.green : Color.red;

        SetRagdol(false);
    }
        private static BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 1, Id = "Child2", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 2, Id = "Child3", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 3, Id = "Child4", AxisIndex = -1
                },
            };

            var channels = new IAnimationChannel[]
            {
                new FloatChannel {
                    Id = "IKWeight", DefaultValue = 0.0f
                },
                new IntChannel {
                    Id = "Type", DefaultValue = 10
                }
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes, null, channels));
        }
        public void CanInstantiatePrefabEntity()
        {
            var instanceCount = 100;
            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Hips", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 1, Id = "LeftUpLeg", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 1, Id = "RightUpLeg", AxisIndex = -1
                }
            };

            var rigDefinition = RigBuilder.CreateRigDefinition(skeletonNodes);

            var prefab = RigEntityBuilder.CreatePrefabEntity(m_Manager, rigDefinition);

            var entities = new NativeArray <Entity>(instanceCount, Allocator.Temp);

            m_Manager.Instantiate(prefab, entities);

            foreach (var entity in entities)
            {
                CheckEntityHasRigComponentTypeAndBufferResized(entity, rigDefinition, RigEntityBuilder.RigComponentTypes, skeletonNodes.Length);
            }
        }
        /// <summary>
        /// Validates if the Editor and the provided RigBuilder are in a correct state to do motion transfer.
        /// </summary>
        /// <param name="rigBuilder">The RigBuilder that will be used for motion transfer.</param>
        /// <returns>Returns true if both the editor and the provided RigBuilder are in a valid state for motion transfer. Returns false if the requirements are not met.</returns>
        public static bool TransferMotionValidate(RigBuilder rigBuilder)
        {
            if (!AnimationWindowUtils.isPreviewing || AnimationWindowUtils.activeAnimationClip == null)
            {
                return(false);
            }

            var selected = Selection.instanceIDs;

            if (selected.Length != 1)
            {
                return(false);
            }

            var selectedGO = EditorUtility.InstanceIDToObject(selected[0]) as GameObject;

            if (selectedGO != rigBuilder.gameObject)
            {
                return(false);
            }

            var animator = rigBuilder.GetComponent <Animator>();

            if (animator.isHuman)
            {
                return(false);
            }

            return(true);
        }
Exemple #7
0
        static BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child2", AxisIndex = -1
                }
            };

            var customChannels = new IAnimationChannel[]
            {
                new FloatChannel {
                    Id = "myFloat", DefaultValue = k_DefaultFloatValue
                },
                new IntChannel {
                    Id = "myInt", DefaultValue = k_DefaultIntValue
                }
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes, null, customChannels));
        }
Exemple #8
0
        public void CanSetDestinationRigDefinition()
        {
            var channels = new IAnimationChannel[]
            {
                new LocalTranslationChannel {
                    Id = "Root", DefaultValue = float3.zero
                },
                new LocalTranslationChannel {
                    Id = "Child1", DefaultValue = float3.zero
                },
                new LocalTranslationChannel {
                    Id = "Child2", DefaultValue = float3.zero
                },
            };

            var rig = new Rig {
                Value = RigBuilder.CreateRigDefinition(channels)
            };

            var rigRemapper = CreateNode <RigRemapperNode>();

            Set.SendMessage(rigRemapper, RigRemapperNode.SimulationPorts.DestinationRig, rig);

            var otherRig = Set.GetDefinition(rigRemapper).ExposeKernelData(rigRemapper).DestinationRigDefinition;

            Assert.That(otherRig.Value.GetHashCode(), Is.EqualTo(rig.Value.Value.GetHashCode()));
        }
        private static BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1
                },
            };

            var animationChannel = new IAnimationChannel[] {
                new FloatChannel {
                    Id = "Root", DefaultValue = 1000.0f
                },
                new FloatChannel {
                    Id = "Child1", DefaultValue = 1000.0f
                },
                new IntChannel {
                    Id = "Root", DefaultValue = 1000
                },
                new IntChannel {
                    Id = "Child1", DefaultValue = 1000
                },
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
        private static EditorCurveBinding GetWeightCurveBinding(RigBuilder rigBuilder, Rig rig)
        {
            var path    = AnimationUtility.CalculateTransformPath(rig.transform, rigBuilder.transform);
            var binding = EditorCurveBinding.FloatCurve(path, typeof(Rig), ConstraintProperties.s_Weight);

            return(binding);
        }
        public void CannotCreateRigSkeletonWithMoreThanOneRoot()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
            };

            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0
                },
                new SkeletonNode {
                    ParentIndex = -1
                },
            };

            Assert.Throws <ArgumentException>(() => RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
        public void CannotCreateRigSkeletonWhenAxisIndexIsValidAndAxisIsNull()
        {
            var animationChannel = new IAnimationChannel[] {
                new LocalTranslationChannel {
                    Id = "Root"
                },
                new LocalRotationChannel {
                    Id = "Root"
                },
                new LocalScaleChannel {
                    Id = "Root"
                },
            };

            var skeletonNodes = new SkeletonNode[] {
                new SkeletonNode {
                    ParentIndex = -1, AxisIndex = 0
                },
                new SkeletonNode {
                    ParentIndex = 0, AxisIndex = 1
                },
                new SkeletonNode {
                    ParentIndex = 1, AxisIndex = 2
                },
            };

            Assert.Throws <ArgumentNullException>(() => RigBuilder.CreateRigDefinition(skeletonNodes, null, animationChannel));
        }
        /// <inheritdoc />
        IEnumerable <EditorCurveBinding> IBakeParameters.GetConstrainedCurveBindings(RigBuilder rigBuilder, IRigConstraint constraint)
        {
            Debug.Assert(constraint is T);
            T tConstraint = (T)constraint;

            return(GetConstrainedCurveBindings(rigBuilder, tConstraint));
        }
Exemple #14
0
    // TODO (mogens) move this to RigConversion in animation package ?
    public static BlobAssetReference <RigDefinition> ConvertRig(RigComponent rigComponent)
    {
        var skeletonNodes = RigGenerator.ExtractSkeletonNodesFromRigComponent(rigComponent);
        var channels      = RigGenerator.ExtractAnimationChannelFromRigComponent(rigComponent);
        var rigDefinition = RigBuilder.CreateRigDefinition(skeletonNodes, null, channels);

        return(rigDefinition);
    }
        public override IEnumerable <EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, OverrideTransform constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            EditorCurveBindingUtils.CollectTRSBindings(rigBuilder.transform, constraint.data.constrainedObject, bindings);

            return(bindings);
        }
Exemple #16
0
        public override IEnumerable <EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, DampedTransform constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            EditorCurveBindingUtils.CollectTRBindings(rigBuilder.transform, constraint.data.sourceObject, bindings);

            return(bindings);
        }
        public override IEnumerable <EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, ChainIKConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            EditorCurveBindingUtils.CollectTRBindings(rigBuilder.transform, constraint.data.target, bindings);

            return(bindings);
        }
Exemple #18
0
        public override IEnumerable <EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, MultiParentConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            EditorCurveBindingUtils.CollectPositionBindings(rigBuilder.transform, constraint.data.constrainedObject, bindings);
            EditorCurveBindingUtils.CollectRotationBindings(rigBuilder.transform, constraint.data.constrainedObject, bindings);
            return(bindings);
        }
        private static EditorCurveBinding GetWeightCurveBinding <T>(RigBuilder rigBuilder, T constraint)
            where T : MonoBehaviour, IRigConstraint
        {
            var path    = AnimationUtility.CalculateTransformPath(constraint.transform, rigBuilder.transform);
            var binding = EditorCurveBinding.FloatCurve(path, typeof(T), ConstraintProperties.s_Weight);

            return(binding);
        }
Exemple #20
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);
        }
Exemple #21
0
        private void Start()
        {
            _animator   = this.gameObject.AddComponent <Animator>();
            _rigBuilder = this.gameObject.AddComponent <RigBuilder>();

            rigObjects = new GameObject[rigSize];
            for (int i = 0; i < rigSize; i++)
            {
            }
        }
Exemple #22
0
    private void Start()
    {
        rigBuilder   = GetComponent <RigBuilder>();
        starthealth  = health;
        sceneManager = GameObject.FindGameObjectWithTag("SceneManager");
        gStatus      = sceneManager.GetComponent <GameStatus>();
        roundScript  = sceneManager.GetComponent <Round>();

        EnemyHealthImage.fillAmount = 1;
    }
Exemple #23
0
        public override IEnumerable <EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, MultiReferentialConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            var transform = constraint.data.sourceObjects[0];

            EditorCurveBindingUtils.CollectTRBindings(rigBuilder.transform, transform, bindings);

            return(bindings);
        }
        public override IEnumerable <EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, TwistCorrection constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            foreach (var node in constraint.data.twistNodes)
            {
                EditorCurveBindingUtils.CollectRotationBindings(rigBuilder.transform, node.transform, bindings);
            }

            return(bindings);
        }
Exemple #25
0
        BlobAssetReference <RigDefinition> CreateTestRigDefinition()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = "Root", AxisIndex = -1
                }
            };

            return(RigBuilder.CreateRigDefinition(skeletonNodes));
        }
Exemple #26
0
 protected override void OnUpdate()
 {
     Entities.ForEach((RigComponent rigComponent) =>
     {
         var rigEntity     = GetPrimaryEntity(rigComponent);
         var skeletonNodes = RigGenerator.ExtractSkeletonNodesFromRigComponent(rigComponent);
         var channels      = RigGenerator.ExtractAnimationChannelFromRigComponent(rigComponent);
         var rigDefinition = RigBuilder.CreateRigDefinition(skeletonNodes, null, channels);
         RigEntityBuilder.SetupRigEntity(rigEntity, DstEntityManager, rigDefinition);
     });
 }
        public void OneTimeSetup()
        {
            var skeletonNodes = new[]
            {
                new SkeletonNode {
                    ParentIndex = -1, Id = string.Empty, AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child1", AxisIndex = -1
                },
                new SkeletonNode {
                    ParentIndex = 0, Id = "Child2", AxisIndex = -1
                }
            };

            RigDefinition = RigBuilder.CreateRigDefinition(skeletonNodes);

            var r        = new Mathematics.Random(0x12345678);
            var range    = new float3(100);
            var fullClip = new UnityEngine.AnimationClip();

            // add some error into the clip, so it is not perfectly frame aligned
            float clipDuration = clipFrames / fullClip.frameRate + 0.123f / fullClip.frameRate;


            CreateLinearTranslate(fullClip, string.Empty, float3.zero, new float3(0, 1, 0), clipDuration);
            CreateLinearTranslate(fullClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration);
            CreateLinearTranslate(fullClip, "Child2", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration);
            CreateRotation(fullClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), clipDuration);
            CreateRotation(fullClip, "Child1", r.NextQuaternionRotation(), r.NextQuaternionRotation(), clipDuration);
            CreateRotation(fullClip, "Child2", r.NextQuaternionRotation(), r.NextQuaternionRotation(), clipDuration);
            CreateScale(fullClip, string.Empty, new float3(1), new float3(1), clipDuration);
            CreateScale(fullClip, "Child1", new float3(1), new float3(2), clipDuration);
            CreateScale(fullClip, "Child2", new float3(2), new float3(3), clipDuration);
            FullAnimationClip = ClipBuilder.AnimationClipToDenseClip(fullClip);

            var partialClip = new UnityEngine.AnimationClip();

            CreateLinearTranslate(partialClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), clipDuration);
            CreateRotation(partialClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), clipDuration);
            CreateRotation(partialClip, "Child2", quaternion.identity, r.NextQuaternionRotation(), clipDuration);
            CreateScale(partialClip, string.Empty, float3.zero, new float3(1), clipDuration);
            PartialAnimationClip = ClipBuilder.AnimationClipToDenseClip(partialClip);

            var alignedClip = new UnityEngine.AnimationClip();

            CreateLinearTranslate(alignedClip, string.Empty, float3.zero, new float3(0, 1, 0), 1.0f);
            CreateLinearTranslate(alignedClip, "Child1", r.NextFloat3(-range, range), r.NextFloat3(-range, range), 1.0f);
            CreateLinearTranslate(alignedClip, "Child2", r.NextFloat3(-range, range), r.NextFloat3(-range, range), 1.0f);
            CreateRotation(alignedClip, string.Empty, quaternion.identity, r.NextQuaternionRotation(), 1.0f);
            AlignedClip = ClipBuilder.AnimationClipToDenseClip(alignedClip);
        }
Exemple #28
0
        public override IEnumerable <EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, MultiReferentialConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            var sources = constraint.data.sourceObjects;

            for (int i = 1; i < sources.Count; ++i)
            {
                EditorCurveBindingUtils.CollectTRBindings(rigBuilder.transform, sources[i], bindings);
            }

            return(bindings);
        }
        public override IEnumerable <EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, TwoBoneIKConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            EditorCurveBindingUtils.CollectTRBindings(rigBuilder.transform, constraint.data.target, bindings);

            if (constraint.data.hint != null)
            {
                EditorCurveBindingUtils.CollectPositionBindings(rigBuilder.transform, constraint.data.hint, bindings);
            }

            return(bindings);
        }
        public override IEnumerable <EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, TwistChainConstraint constraint)
        {
            var bindings = new List <EditorCurveBinding>();

            // Retrieve chain in-between root and tip transforms.
            Transform[] chain = ConstraintsUtils.ExtractChain(constraint.data.root, constraint.data.tip);

            for (int i = 0; i < chain.Length; ++i)
            {
                EditorCurveBindingUtils.CollectRotationBindings(rigBuilder.transform, chain[i], bindings);
            }

            return(bindings);
        }