Esempio n. 1
0
        private void SplitBendAndTwist(Vector3 axis, Quaternion sourceRotation, Dictionary <string, Quaternion> target, string bendName, string twistName)
        {
            OrientationSpace orientationSpace = boneSystem.BonesByName[twistName].GetOrientationSpace(outputs);

            orientationSpace.DecomposeIntoTwistThenSwing(axis, sourceRotation, out Quaternion twist, out Quaternion swing);

            target[twistName] = twist;
            target[bendName]  = swing;
        }
    private Matrix3x3 GetCombinedScale(ChannelOutputs outputs)
    {
        Vector3 scale              = Scale.GetValue(outputs);
        float   generalScale       = (float)GeneralScale.GetValue(outputs);
        var     objectSpaceScaling = Matrix3x3.Scaling(scale * generalScale);

        OrientationSpace orientationSpace = GetOrientationSpace(outputs);
        var orientedSpaceScaling          = orientationSpace.TransformToOrientedSpace(objectSpaceScaling);

        return(orientedSpaceScaling);
    }
    public void TestDecomposeIntoSwingThenTwistInOrientedSpace()
    {
        Quaternion       orientation      = Quaternion.RotationYawPitchRoll(0.4f, 0.3f, 0.2f);
        OrientationSpace orientationSpace = new OrientationSpace(orientation);

        Quaternion q = Quaternion.RotationYawPitchRoll(0.1f, 0.2f, 0.3f);

        orientationSpace.DecomposeIntoTwistThenSwing(Vector3.UnitX, q, out var twist, out var swing);

        Quaternion twistThenSwing = twist.Chain(swing);

        Assert.AreEqual(twistThenSwing, q);
    }
    public Quaternion GetRotation(ChannelOutputs outputs)
    {
        OrientationSpace orientationSpace = GetOrientationSpace(outputs);

        Vector3    rotationAngles     = Rotation.GetValue(outputs);
        TwistSwing rotationTwistSwing = RotationOrder.FromTwistSwingAngles(MathExtensions.DegreesToRadians(rotationAngles));

        rotationTwistSwing = RotationConstraint.Clamp(rotationTwistSwing);

        Quaternion orientedSpaceRotation = rotationTwistSwing.AsQuaternion(RotationOrder.TwistAxis);
        Quaternion worldSpaceRotation    = orientationSpace.TransformFromOrientedSpace(orientedSpaceRotation);

        return(worldSpaceRotation);
    }
    public void Synchronize(ChannelOutputs outputs)
    {
        ScalingTransform parentScalingTransform = Parent != null ? Parent.chainedScalingTransform : ScalingTransform.Identity;
        Vector3          parentTranslation      = Parent != null ? Parent.chainedTranslation : Vector3.Zero;
        var sourceTranslation = Parent != null?Source.Translation.GetValue(outputs) : Vector3.Zero;           //don't bake in translation for root bone

        chainedScalingTransform = Source.GetObjectCenteredScalingTransform(outputs).Chain(parentScalingTransform);
        chainedTranslation      = Vector3.Transform(sourceTranslation, parentScalingTransform.Scale) + parentTranslation;

        Vector3 sourceCenter = Source.CenterPoint.GetValue(outputs);

        centerPoint = parentScalingTransform.Transform(sourceCenter) + chainedTranslation;

        orientationSpace = Source.GetOrientationSpace(outputs);
    }
    public Vector3 ConvertRotationToAngles(ChannelOutputs orientationOutputs, Quaternion objectSpaceRotation, bool applyClamp)
    {
        OrientationSpace orientationSpace         = GetOrientationSpace(orientationOutputs);
        Quaternion       orientatedSpaceRotationQ = orientationSpace.TransformToOrientedSpace(objectSpaceRotation);
        TwistSwing       orientatedSpaceRotation  = TwistSwing.Decompose(RotationOrder.TwistAxis, orientatedSpaceRotationQ);

        if (applyClamp)
        {
            orientatedSpaceRotation = RotationConstraint.Clamp(orientatedSpaceRotation);
        }

        Vector3 rotationAnglesRadians = RotationOrder.ToTwistSwingAngles(orientatedSpaceRotation);
        Vector3 rotationAnglesDegrees = MathExtensions.RadiansToDegrees(rotationAnglesRadians);

        return(rotationAnglesDegrees);
    }