/// <summary>
        /// Adds orientation to brush optionally with rotational symmetry.
        /// </summary>
        /// <param name="mask">Bit mask describing orientation.</param>
        /// <param name="rotationalSymmetry">Indicates whether additional orientations should
        /// be added which have rotational symmetry.</param>
        /// <returns>
        /// First <see cref="BrushOrientation"/> in group with rotational symmetry.
        /// </returns>
        /// <exception cref="System.Exception">
        /// If orientation already exists.
        /// </exception>
        /// <seealso cref="BrushOrientation.AddVariation(Object)">BrushOrientation.AddVariation(Object)</seealso>
        public BrushOrientation AddOrientation(int mask, bool rotationalSymmetry)
        {
            int[] masks = rotationalSymmetry
                ? OrientationUtility.GetMasksWithRotationalSymmetry(mask)
                : new int[] { mask }
            ;

            // Obviously, there is no rotational symmetry if there is only 1!
            if (masks.Length == 1)
            {
                rotationalSymmetry = false;
            }

            // First, make sure that orientations do not alreay exist.
            for (int i = 0; i < masks.Length; ++i)
            {
                if (this.FindOrientation(mask) != null)
                {
                    throw new Exception("Orientation already exists.");
                }
            }

            var newOrientations = new List <BrushOrientation>();

            // Add orientation(s).
            for (int i = 0; i < masks.Length; ++i)
            {
                var orientation = new BrushOrientation(masks[i]);
                orientation.type     = rotationalSymmetry;
                orientation.rotation = i;

                newOrientations.Add(orientation);

                // Upgrade default orientation reference?
                // Note: This is necessary when brush is first created.
                if (masks[i] == this.defaultOrientationMask)
                {
                    this.defaultOrientation = newOrientations[0];
                }
            }

            // Add the new orientation(s).
            int newIndex = this.orientations.Length;

            Array.Resize(ref this.orientations, this.orientations.Length + newOrientations.Count);
            for (int i = 0; i < newOrientations.Count; ++i)
            {
                this.orientations[newIndex + i] = newOrientations[i];
            }

            // Sort orientations by mask.
            this.SortOrientationsByRotationalSymmetry();

            this.RefreshOrientationLookupTable();

            return(newOrientations[0]);
        }
Example #2
0
        /// <summary>
        /// Synchronize variations from another orientation.
        /// </summary>
        /// <remarks>
        /// <para>Does nothing when attempting to synchronize variations from self.</para>
        /// </remarks>
        /// <param name="other">The other orientation.</param>
        /// <seealso cref="OrientedBrush.SyncGroupedVariations(int)"/>
        public void SyncVariationsFrom(BrushOrientation other)
        {
            if (other == this)
            {
                return;
            }

            this.variations       = (Object[])other.variations.Clone();
            this.variationWeights = (int[])other.VariationWeights.Clone();
        }
        /// <inheritdoc/>
        public override void Awake()
        {
            base.Awake();

            this.defaultOrientation = this.FindOrientation(this.DefaultOrientationMask);
        }