Пример #1
0
        public void SmoothFill()
        {
            var tempSelection    = new IndexedSelection();
            var vertexSelector   = new GenericVertexSelector();
            var currentWeightSum = 0f;
            var prevWeightSum    = 0f;

            vertexSelector.spriteMeshData    = spriteMeshData;
            vertexSelector.selection         = tempSelection;
            vertexSelector.SelectionCallback = (int i) => {
                var sum = spriteMeshData.GetWeight(i).Sum();
                currentWeightSum += sum;
                return(sum < 0.99f);
            };

            do
            {
                prevWeightSum    = currentWeightSum;
                currentWeightSum = 0f;
                vertexSelector.Select();

                if (tempSelection.Count > 0)
                {
                    SmoothWeights(1, tempSelection);
                }
            } while (currentWeightSum - prevWeightSum > 0.001f);

            if (tempSelection.Count > 0)
            {
                NormalizeWeights(tempSelection);
            }
        }
Пример #2
0
        public void CalculateWeightsSafe(IWeightsGenerator weightsGenerator, ISelection <int> selection, float filterTolerance)
        {
            var tempSelection  = new IndexedSelection();
            var vertexSelector = new GenericVertexSelector();

            vertexSelector.spriteMeshData    = spriteMeshData;
            vertexSelector.selection         = tempSelection;
            vertexSelector.SelectionCallback = (int i) => {
                return(spriteMeshData.GetWeight(i).Sum() == 0f && (selection == null || selection.Count == 0 || selection.Contains(i)));
            };
            vertexSelector.Select();

            if (tempSelection.Count > 0)
            {
                CalculateWeights(weightsGenerator, tempSelection, filterTolerance);
            }
        }