Пример #1
0
    /// <summary>
    /// Recursively applies an encoded skeleton, or part of it, to the shadow
    /// </summary>
    /// <param name="data">The encoded skeleton data</param>
    /// <param name="t">The current transform to apply to</param>
    /// <param name="nameFilter">The filter for names</param>
    /// <param name="bypass">Used for whitelists to take children of
    /// whitelisted transforms</param>
    public static void ReadShadowData(
        ShadowTransform[] data,
        Transform t,
        ShadowCoordinator coordinator,
        FilterList <string> nameFilter,
        bool bypass = false)
    {
        bool allowed   = (bypass == true || nameFilter.Allowed(t.name) == true);
        bool whitelist = (nameFilter.IsWhitelist() == true);

        bypass = (allowed == true && whitelist == true);

        // If this is a valid bone, and is allowed, read it to the skeleton
        int key = coordinator.GetBoneKey(t.name);

        if (allowed == true && ShadowTransform.IsValid(data[key]) == true)
        {
            data[key].WriteTo(t);
        }

        // See if we need to keep searching
        if (whitelist == true || allowed == true)
        {
            foreach (Transform child in t)
            {
                ReadShadowData(data, child, coordinator, nameFilter, bypass);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Recursively applies an encoded skeleton, or part of it, to the shadow
    /// </summary>
    /// <param name="data">The encoded skeleton data</param>
    /// <param name="t">The current transform to apply to</param>
    public static void ReadShadowData(
        ShadowTransform[] data,
        Transform t,
        ShadowCoordinator coordinator)
    {
        int key = coordinator.GetBoneKey(t.name);

        if (ShadowTransform.IsValid(data[key]) == true)
        {
            data[key].WriteTo(t);
        }
        foreach (Transform child in t)
        {
            ReadShadowData(data, child, coordinator);
        }
    }
Пример #3
0
    public static ShadowTransform[] Blend(
        ShadowTransform[] buffer,
        params BlendPair[] shadows)
    {
        int boneCount   = shadows[0].shadow.Length; // Bones per shadow
        int shadowCount = shadows.Length;           // Total number of shadows

        for (int i = 0; i < boneCount; i++)
        {
            List <float>      weights   = new List <float>();
            List <Vector3>    positions = new List <Vector3>();
            List <Quaternion> rotations = new List <Quaternion>();

            for (int j = 0; j < shadowCount; j++)
            {
                // Extract the features from the bone
                ShadowTransform bone = shadows[j].shadow[i];
                if (ShadowTransform.IsValid(bone) == true)
                {
                    weights.Add(shadows[j].weight);
                    positions.Add(bone.Position);
                    rotations.Add(bone.Rotation);
                }
            }

            // If we just have one weight for this bone
            if (weights.Count == 1)
            {
                buffer[i].ReadFrom(positions[0], rotations[0]);
            }
            // If we have anything to blend for this bone
            else if (weights.Count > 1)
            {
                float[] weightsArray = weights.ToArray();
                NormalizeWeights(weightsArray);

                buffer[i].ReadFrom(
                    BlendVector3(positions, weightsArray),
                    BlendQuaternion(rotations, weightsArray));
            }
        }

        return(buffer);
    }