Example #1
0
        /// <summary>
        /// Builds a contour set from the region outlines in the provided <see cref="CompactHeightfield"/>.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The raw contours will match the region outlines exactly.  The edgeMaxDeviation
        /// and maxEdgeLength parameters control how closely the simplified contours will match
        /// the raw contours.
        /// </para>
        /// <para>
        /// Simplified contours are generated such that the vertices for portals between areas
        /// match up.  (They are considered mandatory vertices.)
        /// </para>
        /// <para>
        /// Setting maxEdgeLength to zero will disabled the feature.
        /// </para>
        /// </remarks>
        /// <param name="context">The context to use for the build.</param>
        /// <param name="field">The field to use for the build.(Must have region data.)</param>
        /// <param name="edgeMaxDeviation">
        /// The maximum distance a simplified edge may deviate from the raw contour's vertices.
        /// [Limit: >= 0]
        /// </param>
        /// <param name="maxEdgeLength">
        /// The maximum allowed length of a simplified edge. [Limit: >= 0]
        /// </param>
        /// <param name="flags">The build flags.</param>
        /// <returns>The contour set, or null on failure.</returns>
        public static ContourSet Build(BuildContext context, CompactHeightfield field
                                       , float edgeMaxDeviation, int maxEdgeLength, ContourBuildFlags flags)
        {
            if (context == null || field == null || field.IsDisposed ||
                edgeMaxDeviation < 0 ||
                maxEdgeLength < 0)
            {
                return(null);
            }

            ContourSetEx root = new ContourSetEx();

            if (ContourSetEx.nmcsBuildSet(context.root, field
                                          , edgeMaxDeviation, maxEdgeLength
                                          , root
                                          , flags))
            {
                return(new ContourSet(root));
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Frees and marks as disposed all resources. (Including member <see cref="Contour"/> objects.)
        /// </summary>
        public void RequestDisposal()
        {
            if (IsDisposed)
            {
                return;
            }

            ContourSetEx.nmcsFreeSetData(root);

            if (mContours == null)
            {
                return;
            }

            for (int i = 0; i < mContours.Length; i++)
            {
                if (mContours[i] != null)
                {
                    mContours[i].Reset();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets the contour for the specified index.
        /// </summary>
        /// <param name="index">
        /// The contour index. [Limits: 0 &lt; value &lt; <see cref="Count"/>]
        /// </param>
        /// <returns>The contour, or null on failure.</returns>
        public Contour GetContour(int index)
        {
            if (IsDisposed || index < 0 || index >= root.contourCount)
            {
                return(null);
            }

            if (mContours == null)
            {
                mContours = new Contour[root.contourCount];
            }

            if (mContours[index] != null)
            {
                return(mContours[index]);
            }

            Contour result = new Contour();

            ContourSetEx.nmcsGetContour(root, index, result);
            mContours[index] = result;

            return(result);
        }
Example #4
0
 private ContourSet(ContourSetEx root)
 {
     this.root = root;
 }