Ejemplo n.º 1
0
    public void TwistChainConstraint_TransferMotionToSkeleton()
    {
        var data       = TwistChainConstraintTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var tip  = constraint.data.tip;
        var root = constraint.data.root;

        var tipTarget  = constraint.data.tipTarget;
        var rootTarget = constraint.data.rootTarget;

        var clip = new AnimationClip();

        var tipTargetPath  = AnimationUtility.CalculateTransformPath(tipTarget, rootGO.transform);
        var rootTargetPath = AnimationUtility.CalculateTransformPath(rootTarget, rootGO.transform);

        // Add keyframes for twist chain constraint.
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(rootTargetPath, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(rootTargetPath, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(rootTargetPath, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Linear(0f, 0f, 1f, -50f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(tipTargetPath, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(tipTargetPath, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(tipTargetPath, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Linear(0f, 0f, 1f, 50f));

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, ConstraintsUtils.ExtractChain(root, tip), CompareFlags.TR);
    }
    public void DampedTransform_TransferMotionToSkeleton()
    {
        var data       = DampedTransformTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var constrainedObject = constraint.data.constrainedObject;
        var sourceObject      = constraint.data.sourceObject;

        var clip = new AnimationClip();

        var constrainedObjectPath = AnimationUtility.CalculateTransformPath(constrainedObject, rootGO.transform);
        var sourceObjectPath      = AnimationUtility.CalculateTransformPath(sourceObject, rootGO.transform);

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Linear(0f, sourceObject.localPosition.x, 1f, sourceObject.localPosition.y + 0.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Linear(0f, sourceObject.localPosition.y, 1f, sourceObject.localPosition.y + 2.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Linear(0f, sourceObject.localPosition.z, 1f, sourceObject.localPosition.y + 4.5f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Linear(0f, -50f, 1f, 50f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(sourceObjectPath, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Constant(0f, 1f, 0f));

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, new Transform[] { constrainedObject }, CompareFlags.TR);
    }
    public void BlendConstraint_TransferMotionToSkeleton()
    {
        var data       = BlendConstraintTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var constrainedObject = constraint.data.constrainedObject;
        var src0 = constraint.data.sourceObjectA;
        var src1 = constraint.data.sourceObjectB;

        var clip = new AnimationClip();

        var constraintPath = AnimationUtility.CalculateTransformPath(constraint.transform, rootGO.transform);
        var src0Path       = AnimationUtility.CalculateTransformPath(src0, rootGO.transform);
        var src1Path       = AnimationUtility.CalculateTransformPath(src1, rootGO.transform);

        var positionWeightAttribute = ((IBlendConstraintData)constraint.data).positionWeightFloatProperty;
        var rotationWeightAttribute = ((IBlendConstraintData)constraint.data).rotationWeightFloatProperty;

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, src0.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Constant(0f, 1f, src0.localPosition.y));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src0.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, src1.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Constant(0f, 1f, src1.localPosition.y));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src1.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(constraintPath, typeof(BlendConstraint), positionWeightAttribute), AnimationCurve.Linear(0f, 0f, 1f, 1f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(constraintPath, typeof(BlendConstraint), rotationWeightAttribute), AnimationCurve.Linear(0f, 0f, 1f, 1f));

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, new Transform[] { constrainedObject }, CompareFlags.TR);
    }
    public void MultiReferentialConstraint_TransferMotionToSkeleton()
    {
        var data       = MultiReferentialConstraintTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var sources = constraint.data.sourceObjects;

        var clip = new AnimationClip();

        var src0 = sources[0];
        var src1 = sources[1];
        var src2 = sources[2];

        var constraintPath = AnimationUtility.CalculateTransformPath(constraint.transform, rootGO.transform);
        var src0Path       = AnimationUtility.CalculateTransformPath(src0, rootGO.transform);
        var src1Path       = AnimationUtility.CalculateTransformPath(src1, rootGO.transform);
        var src2Path       = AnimationUtility.CalculateTransformPath(src2, rootGO.transform);

        var driverAttribute = ((IMultiReferentialConstraintData)constraint.data).driverIntProperty;

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Linear(0f, src0.localPosition.x, 1f, src0.localPosition.x + 0.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Constant(0f, 1f, src0.localPosition.y));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src0.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Linear(0f, -50f, 1f, 50f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Constant(0f, 1f, 0f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, src1.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Linear(0f, src1.localPosition.y, 1f, src1.localPosition.y + 1.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src1.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Linear(0f, -40f, 1f, 40f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Constant(0f, 1f, 0f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, src2.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Constant(0f, 1f, src2.localPosition.y));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Linear(0f, src2.localPosition.z, 1f, src2.localPosition.z + 2.5f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src2Path, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Linear(0f, -30f, 1f, 30f));

        var driverCurve = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 0f), new Keyframe(0.33f, 1f, Mathf.Infinity, Mathf.Infinity), new Keyframe(0.66f, 2f, Mathf.Infinity, Mathf.Infinity), new Keyframe(1f, 2f) });

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(constraintPath, typeof(MultiReferentialConstraint), driverAttribute), driverCurve);

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, new Transform[] { src0 }, CompareFlags.TR);
    }
    public void MultiParentConstraint_TransferMotionToSkeleton()
    {
        var data       = MultiParentConstraintTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var constrainedObject = constraint.data.constrainedObject;
        var sources           = constraint.data.sourceObjects;

        var clip = new AnimationClip();

        var src0 = sources[0].transform;
        var src1 = sources[1].transform;

        var constraintPath = AnimationUtility.CalculateTransformPath(constraint.transform, rootGO.transform);
        var src0Path       = AnimationUtility.CalculateTransformPath(src0, rootGO.transform);
        var src1Path       = AnimationUtility.CalculateTransformPath(src1, rootGO.transform);

        var weight0Attribute = ((IMultiParentConstraintData)constraint.data).sourceObjectsProperty + ".m_Item0.weight";
        var weight1Attribute = ((IMultiParentConstraintData)constraint.data).sourceObjectsProperty + ".m_Item1.weight";

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, src0.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Linear(0f, src0.localPosition.y, 1f, src0.localPosition.y + 0.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src0.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Linear(0f, -50f, 1f, 50f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src0Path, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Constant(0f, 1f, 0f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(constraintPath, typeof(MultiParentConstraint), weight0Attribute), AnimationCurve.Linear(0f, 0f, 1f, 1f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Linear(0f, src1.localPosition.x, 1f, src1.localPosition.x + 0.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Constant(0f, 1f, src1.localPosition.y));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, src1.localPosition.z));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.x"), AnimationCurve.Linear(0f, -50f, 1f, 50f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.y"), AnimationCurve.Constant(0f, 1f, 0f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(src1Path, typeof(Transform), "localEulerAnglesRaw.z"), AnimationCurve.Constant(0f, 1f, 0f));

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(constraintPath, typeof(MultiParentConstraint), weight1Attribute), AnimationCurve.Linear(0f, 1f, 0f, 0f));

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, new Transform[] { constrainedObject }, CompareFlags.TR);
    }
    public void TwoBoneIKConstraint_TransferMotionToSkeleton()
    {
        var data       = TwoBoneIKConstraintTests.SetupConstraintRig();
        var constraint = data.constraint;

        var rootGO     = data.rigData.rootGO;
        var rigBuilder = rootGO.GetComponent <RigBuilder>();

        var tip  = constraint.data.tip;
        var mid  = constraint.data.mid;
        var root = constraint.data.root;

        var target = constraint.data.target;

        var clip = new AnimationClip();

        var targetPath = AnimationUtility.CalculateTransformPath(target, rootGO.transform);

        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(targetPath, typeof(Transform), "m_LocalPosition.x"), AnimationCurve.Constant(0f, 1f, target.localPosition.x));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(targetPath, typeof(Transform), "m_LocalPosition.y"), AnimationCurve.Linear(0f, target.localPosition.y, 1f, target.localPosition.y + 0.5f));
        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(targetPath, typeof(Transform), "m_LocalPosition.z"), AnimationCurve.Constant(0f, 1f, target.localPosition.z));

        RuntimeRiggingEditorTestFixture.TestTransferMotionToSkeleton(constraint, rigBuilder, clip, new Transform[] { tip, mid, root }, CompareFlags.TR);
    }