示例#1
0
        /// <summary>
        /// Gets standard processors based on the provided options.
        /// </summary>
        /// <param name="options">The processors to include.</param>
        /// <returns>
        /// The standard processors, or a zero length array if no processors selected.
        /// </returns>
        public static INMGenProcessor[] GetStandard(NMGenBuildFlag options)
        {
            List <INMGenProcessor> ps = new List <INMGenProcessor>();

            if ((options & NMGenBuildFlag.ApplyPolyFlags) != 0)
            {
                ps.Add(new ApplyPolygonFlags("ApplyDefaultPolyFlag"
                                             , NMBuild.MinPriority, NMBuild.DefaultFlag));
            }

            if ((options & NMGenBuildFlag.LedgeSpansNotWalkable) != 0)
            {
                ps.Add(FilterLedgeSpans.Instance);
            }

            if ((options & NMGenBuildFlag.LowHeightSpansNotWalkable) != 0)
            {
                ps.Add(FilterLowHeightSpans.Instance);
            }

            if ((options & NMGenBuildFlag.LowObstaclesWalkable) != 0)
            {
                ps.Add(LowObstaclesWalkable.Instance);
            }

            return(ps.ToArray());
        }
示例#2
0
 private static void HandleFlagGUI(ref NMGenBuildFlag flags
                                   , string label
                                   , NMGenBuildFlag flag
                                   , bool isInspector)
 {
     if (isInspector)
     {
         flags = EditorGUILayout.Toggle(label, (flags & flag) != 0)
             ? (flags | flag)
             : (flags & ~flag);
     }
     else
     {
         flags = GUILayout.Toggle((flags & flag) != 0, label)
             ? (flags | flag)
             : (flags & ~flag);
     }
 }
示例#3
0
    internal bool SetInputData(BuildContext context
                               , InputGeometry geometry
                               , InputBuildInfo info
                               , INMGenProcessor[] processors
                               , ConnectionSet connections
                               , bool threadSafeOnly)
    {
        // Remember: Never allow this method to clear the input geometry.
        // Note: Don't set class fields until it is safe.

        if (geometry == null)
        {
            context.LogError("Set input data: Invalid parameters.", this);
            return(false);
        }

        // Generate the processor set.

        processors = org.critterai.ArrayUtil.Compress(processors);

        List <INMGenProcessor> lprocessors = new List <INMGenProcessor>();

        if (processors != null)
        {
            lprocessors.AddRange(processors);
        }

        NMGenBuildFlag bflags          = mConfig.BuildFlags;
        bool           threadCheckFail = false;

        // This section makes sure we don't get duplicate processors.
        // It also checks for thread-safety.
        foreach (INMGenProcessor p in lprocessors)
        {
            if (p is FilterLedgeSpans)
            {
                bflags &= ~NMGenBuildFlag.LedgeSpansNotWalkable;
            }

            if (p is FilterLowHeightSpans)
            {
                bflags &= ~NMGenBuildFlag.LowHeightSpansNotWalkable;
            }

            if (p is LowObstaclesWalkable)
            {
                bflags &= ~NMGenBuildFlag.LowObstaclesWalkable;
            }

            if (threadSafeOnly && !p.IsThreadSafe)
            {
                context.LogError(p.Name + " processor is not thread-safe.", this);
                threadCheckFail = true;
            }
        }

        if (threadCheckFail)
        {
            context.LogError("One or more processors is not thread-safe.", this);
            return(false);
        }

        lprocessors.AddRange(ProcessorSet.GetStandard(bflags));

        ProcessorSet pset = ProcessorSet.Create(lprocessors.ToArray());

        if (pset == null)
        {
            context.LogError("Set input data: No NMGen processors available.", this);
            return(false);
        }

        // If necessary, re-create the tile set definition.

        Vector3 bmin;
        Vector3 bmax;

        DeriveBounds(geometry.BoundsMin, geometry.BoundsMax, out bmin, out bmax);

        if (mBuildData.IsTiled)
        {
            mTileSet = TileSetDefinition.Create(bmin, bmax, mConfig.GetConfig(), geometry);

            if (mTileSet == null)
            {
                context.LogError("Set input data: Create tile build definition: Unexpected error."
                                 + " Invalid input data or configuration."
                                 , this);
                return(false);
            }
        }

        // Everything is OK.  Set the rest of the fields.

        mNMGenProcessors = pset;
        mBoundsMin       = bmin;
        mBoundsMax       = bmax;
        mInputGeom       = geometry;
        mInputInfo       = info;
        mConnections     = (connections == null ? ConnectionSet.CreateEmpty() : connections);

        mIsDirty = true;

        return(true);
    }
 public void Reset()
 {
     mRoot = new NMGenParams();
     UpdateLocalsFrom(mRoot);
     mBuildFlags = DefaultBuildFlags;
 }
示例#5
0
 public void Reset()
 {
     mRoot = new NMGenParams();
     UpdateLocalsFrom(mRoot);
     mBuildFlags = DefaultBuildFlags;
 }
示例#6
0
 private static void HandleFlagGUI(ref NMGenBuildFlag flags
     , string label
     , NMGenBuildFlag flag
     , bool isInspector)
 {
     if (isInspector)
     {
         flags = EditorGUILayout.Toggle(label, (flags & flag) != 0)
             ? (flags | flag) 
             : (flags & ~flag);
     }
     else
     {
         flags = GUILayout.Toggle((flags & flag) != 0, label)
             ? (flags | flag) 
             : (flags & ~flag);
     }
 }
 /// <summary>
 /// Creates a processor set based on the provided options.
 /// </summary>
 /// <remarks>
 /// <para>
 /// An empty processor set will be created if <paramref name="options"/> is zero.
 /// </para>
 /// </remarks>
 /// <param name="options">The processors to include.</param>
 /// <returns>A processor set with the standard processors.</returns>
 public static ProcessorSet CreateStandard(NMGenBuildFlag options)
 {
     return Create(GetStandard(options));
 }
        /// <summary>
        /// Gets standard processors based on the provided options.
        /// </summary>
        /// <param name="options">The processors to include.</param>
        /// <returns>
        /// The standard processors, or a zero length array if no processors selected.
        /// </returns>
        public static INMGenProcessor[] GetStandard(NMGenBuildFlag options)
        {
            List<INMGenProcessor> ps = new List<INMGenProcessor>();

            if ((options & NMGenBuildFlag.ApplyPolyFlags) != 0)
            {
                ps.Add(new ApplyPolygonFlags("ApplyDefaultPolyFlag"
                    , NMBuild.MinPriority, NMBuild.DefaultFlag));
            }

            if ((options & NMGenBuildFlag.LedgeSpansNotWalkable) != 0)
                ps.Add(FilterLedgeSpans.Instance);

            if ((options & NMGenBuildFlag.LowHeightSpansNotWalkable) != 0)
                ps.Add(FilterLowHeightSpans.Instance);

            if ((options & NMGenBuildFlag.LowObstaclesWalkable) != 0)
                ps.Add(LowObstaclesWalkable.Instance);

            return ps.ToArray();
        }
示例#9
0
        public static void OnGUIAdvanced(NMGenConfig config
                                         , bool isInspector)
        {
            GUILayout.Label("Advanced Settings");

            EditorGUIUtility.LookLikeControls(170);

            float xz = config.XZCellSize;

            float a = xz * xz;
            float effective;

            /////////////////////////////////////////////////////////////

            GUILayout.Space(MarginSize);

            effective = Mathf.Ceil(config.MaxEdgeLength / xz) * xz;

            config.MaxEdgeLength = EditorGUILayout.FloatField(
                NMGenConfig.EdgeLenLabel + Effective(effective)
                , config.MaxEdgeLength);

            config.EdgeMaxDeviation = EditorGUILayout.FloatField(
                NMGenConfig.EdgeDevLabel
                , config.EdgeMaxDeviation);

            config.MaxVertsPerPoly = EditorGUILayout.IntSlider(
                NMGenConfig.MaxPolyVertLabel
                , config.MaxVertsPerPoly
                , 3
                , NMGen.MaxAllowedVertsPerPoly);

            effective = Mathf.Ceil(config.MergeRegionArea / a) * a;

            config.MergeRegionArea = EditorGUILayout.FloatField(
                NMGenConfig.MergeSizeLabel + Effective(effective)
                , config.MergeRegionArea);

            GUILayout.Space(MarginSize * 2);

            NMGenBuildFlag flags = config.BuildFlags;

            HandleFlagGUI(ref flags
                          , NMGenConfig.LedgeSpansLabel
                          , NMGenBuildFlag.LedgeSpansNotWalkable
                          , isInspector);

            HandleFlagGUI(ref flags
                          , NMGenConfig.LowHeightLabel
                          , NMGenBuildFlag.LowHeightSpansNotWalkable
                          , isInspector);

            HandleFlagGUI(ref flags
                          , NMGenConfig.LowObstacleLabel
                          , NMGenBuildFlag.LowObstaclesWalkable
                          , isInspector);

            ContourBuildFlags cflags = config.ContourOptions;

            HandleFlagGUI(ref cflags
                          , NMGenConfig.TessWallsLabel
                          , ContourBuildFlags.TessellateWallEdges
                          , isInspector);

            HandleFlagGUI(ref cflags
                          , NMGenConfig.TessAreasLabel
                          , ContourBuildFlags.TessellateAreaEdges
                          , isInspector);

            config.ContourOptions = cflags;

            if (isInspector)
            {
                config.UseMonotone = EditorGUILayout.Toggle(NMGenConfig.UseMonoLabel
                                                            , config.UseMonotone);
            }
            else
            {
                config.UseMonotone = GUILayout.Toggle(config.UseMonotone
                                                      , NMGenConfig.UseMonoLabel);
            }

            HandleFlagGUI(ref flags
                          , NMGenConfig.FlagPolysLabel
                          , NMGenBuildFlag.ApplyPolyFlags
                          , isInspector);

            bool includeDetail;

            if (isInspector)
            {
                includeDetail = EditorGUILayout.Toggle("Include Detail Mesh"
                                                       , (config.ResultOptions & NMGenAssetFlag.DetailMesh) != 0);
            }
            else
            {
                includeDetail = GUILayout.Toggle(
                    (config.ResultOptions & NMGenAssetFlag.DetailMesh) != 0
                    , "Include Detail Mesh");
            }

            if (includeDetail)
            {
                config.ResultOptions |= NMGenAssetFlag.DetailMesh;
            }
            else
            {
                config.ResultOptions &= ~NMGenAssetFlag.DetailMesh;
            }

            HandleFlagGUI(ref flags
                          , NMGenConfig.BVTreeLabel
                          , NMGenBuildFlag.BVTreeEnabled
                          , isInspector);

            config.BuildFlags = flags;
        }
示例#10
0
 /// <summary>
 /// Creates a processor set based on the provided options.
 /// </summary>
 /// <remarks>
 /// <para>
 /// An empty processor set will be created if <paramref name="options"/> is zero.
 /// </para>
 /// </remarks>
 /// <param name="options">The processors to include.</param>
 /// <returns>A processor set with the standard processors.</returns>
 public static ProcessorSet CreateStandard(NMGenBuildFlag options)
 {
     return(Create(GetStandard(options)));
 }