Ejemplo n.º 1
0
        /**
         * Callback called for each paintbrush stamp (each time the user drags the mouse, and when he first clicks down).
         */
        private void PaintbrushStampCallback(List <ParticleStampInfo> stampInfo, bool modified)
        {
            // Average and particle count for SMOOTH mode.
            float averageValue = 0;
            int   numParticles = 0;

            foreach (ParticleStampInfo info in stampInfo)
            {
                // Skip unselected particles, if selection mask is on.
                if (selectionMask && !selectionStatus[info.index])
                {
                    continue;
                }

                switch (paintMode)
                {
                case PaintBrushType.Gaussian:
                case PaintBrushType.Pencil:

                    float currentValue = GetPropertyValue(currentProperty, info.index);
                    float profile      = (paintMode == PaintBrushType.Pencil) ? brushModulation :
                                         ObiEditorUtils.GaussianBrushProfile(Mathf.Sqrt(info.sqrDistanceToMouse) / brushRadius, 4) * brushModulation;

                    if (modified)
                    {
                        SetPropertyValue(currentProperty, info.index, currentValue + profile * (currentValue - newProperty) * brushOpacity);
                    }
                    else
                    {
                        SetPropertyValue(currentProperty, info.index, currentValue - profile * (currentValue - newProperty) * brushOpacity);
                    }
                    break;

                case PaintBrushType.Smooth:
                    averageValue += GetPropertyValue(currentProperty, info.index);
                    numParticles++;
                    break;
                }
            }

            if (paintMode == PaintBrushType.Smooth)
            {
                averageValue /= numParticles;
                foreach (ParticleStampInfo info in stampInfo)
                {
                    // Skip unselected particles, if selection mask is on.
                    if (selectionMask && !selectionStatus[info.index])
                    {
                        continue;
                    }

                    float currentValue = GetPropertyValue(currentProperty, info.index);
                    float profile      = ObiEditorUtils.GaussianBrushProfile(Mathf.Sqrt(info.sqrDistanceToMouse) / brushRadius, 4) * brushModulation;

                    if (modified)                      //Sharpen
                    {
                        SetPropertyValue(currentProperty, info.index, currentValue + profile * (currentValue - averageValue) * brushOpacity);
                    }
                    else                        //Smooth
                    {
                        SetPropertyValue(currentProperty, info.index, currentValue - profile * (currentValue - averageValue) * brushOpacity);
                    }
                }
            }
        }