示例#1
0
 /// <summary>
 /// Logs processor information to the context for debug purposes.
 /// </summary>
 /// <param name="context">The build context.</param>
 public void LogProcessors(NMGenContext context)
 {
     foreach (INMGenProcessor p in mProcessors)
     {
         context.Log(string.Format("Processor: {0} ({1})", p.Name, p.GetType().Name)
                     , this);
     }
 }
示例#2
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The flags will be applied during the <see cref="NMGenState.PolyMeshBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.PolyMeshBuild)
            {
                return(true);
            }

            PolyMesh     mesh = context.PolyMesh;
            PolyMeshData data = mesh.GetData(false);

            if (data.polyCount == 0)
            {
                return(true);
            }

            bool applied = false;

            for (int i = 0; i < mAreas.Length; i++)
            {
                byte   area  = mAreas[i];
                ushort flags = mFlags[i];

                int marked = 0;

                for (int iPoly = 0; iPoly < data.polyCount; iPoly++)
                {
                    if (data.areas[iPoly] == area)
                    {
                        data.flags[iPoly] |= flags;
                        marked++;
                    }
                }

                if (marked > 0)
                {
                    string msg = string.Format(
                        "{0} : Added '0x{1:X}' flag(s) to {2} poylgons assigned to area {3}."
                        , Name, flags, marked, area);

                    context.Log(msg, this);

                    applied = true;
                }
            }

            if (applied)
            {
                mesh.Load(data);
            }
            else
            {
                context.Log(Name + ": No flags applied.", this);
            }

            return(true);
        }
示例#3
0
 /// <summary>
 /// Runs all the processors in order of priority.  (Ascending)
 /// </summary>
 /// <remarks>
 /// <para>
 /// A return value of false indicates the build should be aborted.
 /// </para>
 /// </remarks>
 /// <param name="state">The current state of the build.</param>
 /// <param name="context">The build context.</param>
 /// <returns>False if the build should abort.</returns>
 public bool Process(NMGenContext context, NMGenState state)
 {
     foreach (INMGenProcessor p in mProcessors)
     {
         if (!p.ProcessBuild(context, state))
         {
             return(false);
         }
     }
     return(true);
 }
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The flags will be applied during the <see cref="NMGenState.PolyMeshBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.PolyMeshBuild)
                return true;

            PolyMesh mesh = context.PolyMesh;
            PolyMeshData data = mesh.GetData(false);

            if (data.polyCount == 0)
                return true;

            bool applied = false;

            for (int i = 0; i < mAreas.Length; i++)
            {
                byte area = mAreas[i];
                ushort flags = mFlags[i];

                int marked = 0;

                for (int iPoly = 0; iPoly < data.polyCount; iPoly++)
                {
                    if (data.areas[iPoly] == area)
                    {
                        data.flags[iPoly] |= flags;
                        marked++;
                    }
                }

                if (marked > 0)
                {
                    string msg = string.Format(
                        "{0} : Added '0x{1:X}' flag(s) to {2} poylgons assigned to area {3}."
                        , Name, flags, marked, area);

                    context.Log(msg, this);

                    applied = true;
                }
            }

            if (applied)
                mesh.Load(data);
            else
                context.Log(Name + ": No flags applied.", this);

            return true;
        }
示例#5
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Will be applied during the <see cref="NMGenState.HeightfieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.HeightfieldBuild)
                return true;

            if (context.Heightfield.MarkLowObstaclesWalkable(context
                , context.Config.WalkableStep))
            {
                context.Log(Name + ": Marked low obstacles as walklable.", this);
                return true;
            }

            context.Log(Name + ": Mark low obstacles failed.", this);
            return false;

        }
示例#6
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Will be applied during the <see cref="NMGenState.HeightfieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {

            if (state != NMGenState.HeightfieldBuild)
                return true;

            if (context.Heightfield.MarkLowHeightSpansNotWalkable(context
                , context.Config.WalkableHeight))
            {
                context.Log(Name + ": Marked low height spans as not walklable.", this);
                return true;
            }

            context.Log(Name + ": Mark low height spans failed.", this);
            return false;
        }
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
                return true;

            if (context.CompactField.MarkBoxArea(context, mBoundsMin, mBoundsMax, Area))
            {
                context.Log(string.Format("{0} : Marked box area: Area: {1}, Priority: {2}"
                    , Name, Area, Priority)
                    , this);
                return true;
            }

            context.Log(Name + ": Failed to mark box area.", this);
            return false;
        }
示例#8
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Will be applied during the <see cref="NMGenState.HeightfieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.HeightfieldBuild)
            {
                return(true);
            }

            if (context.Heightfield.MarkLowObstaclesWalkable(context
                                                             , context.Config.WalkableStep))
            {
                context.Log(Name + ": Marked low obstacles as walklable.", this);
                return(true);
            }

            context.Log(Name + ": Mark low obstacles failed.", this);
            return(false);
        }
示例#9
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Will be applied during the <see cref="NMGenState.HeightfieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.HeightfieldBuild)
            {
                return(true);
            }

            if (context.Heightfield.MarkLowHeightSpansNotWalkable(context
                                                                  , context.Config.WalkableHeight))
            {
                context.Log(Name + ": Marked low height spans as not walklable.", this);
                return(true);
            }

            context.Log(Name + ": Mark low height spans failed.", this);
            return(false);
        }
示例#10
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
            {
                return(true);
            }

            if (context.CompactField.MarkBoxArea(context, mBoundsMin, mBoundsMax, Area))
            {
                context.Log(string.Format("{0} : Marked box area: Area: {1}, Priority: {2}"
                                          , Name, Area, Priority)
                            , this);
                return(true);
            }

            context.Log(Name + ": Failed to mark box area.", this);
            return(false);
        }
示例#11
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
                return true;

            if (context.CompactField.MarkCylinderArea(context
                , mCenterBase, mRadius, mHeight
                , Area))
            {
                context.Log(string.Format("{0} : Marked box area: Area: {1}, Priority: {2}"
                    , Name, Area, Priority)
                    , this);
                return true;
            }

            context.Log(Name + ": Failed to mark cylinder area.", this);
            return false;
        }
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
                return true;

            if (context.CompactField.MarkConvexPolyArea(context, verts, ymin, ymax, Area))
            {
                context.Log(string.Format(
                    "{0}: Marked convex polygon area: Area: {1}, Priority: {2}"
                    , Name, Area, Priority)
                    , this);

                return true;
            }

            context.Log(Name + ": Failed to mark convex polygon area.", this);
            return false;
        }
        private IncrementalBuilder(NMGenTileParams tileConfig
                                   , NMGenParams config
                                   , NMGenAssetFlag resultOptions
                                   , InputGeometry source
                                   , ProcessorSet processors)
        {
            mConfig     = config;
            mTileConfig = tileConfig;

            mGeometry      = source;
            mProcessors    = processors;
            mResultOptions = resultOptions;

            mBuildContext = new NMGenContext(tileConfig.TileX, tileConfig.TileZ, mConfig.Clone());

            mTileText = string.Format("({0},{1})", tileConfig.TileX, tileConfig.TileZ);

            mState = NMGenState.Initialized;
        }
示例#14
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The flags will be applied during the <see cref="NMGenState.PolyMeshBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>True</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.PolyMeshBuild)
                return true;

            PolyMeshData data = context.PolyMesh.GetData(false);

            for (int i = 0; i < data.flags.Length; i++)
            {
                data.flags[i] |= mFlags;
            }

            context.PolyMesh.Load(data);
            context.Log(string.Format("{0}: Applied flag(s) to all polys. Flag(s): 0x{1:X}"
                , Name, mFlags)
                , this);

            return true;
        }
示例#15
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
            {
                return(true);
            }

            if (context.CompactField.MarkCylinderArea(context
                                                      , mCenterBase, mRadius, mHeight
                                                      , Area))
            {
                context.Log(string.Format("{0} : Marked box area: Area: {1}, Priority: {2}"
                                          , Name, Area, Priority)
                            , this);
                return(true);
            }

            context.Log(Name + ": Failed to mark cylinder area.", this);
            return(false);
        }
示例#16
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The area will be applied during the <see cref="NMGenState.CompactFieldBuild"/>
        /// state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>False on error, otherwise true.</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.CompactFieldBuild)
            {
                return(true);
            }

            if (context.CompactField.MarkConvexPolyArea(context, verts, ymin, ymax, Area))
            {
                context.Log(string.Format(
                                "{0}: Marked convex polygon area: Area: {1}, Priority: {2}"
                                , Name, Area, Priority)
                            , this);

                return(true);
            }

            context.Log(Name + ": Failed to mark convex polygon area.", this);
            return(false);
        }
示例#17
0
        /// <summary>
        /// Process the build context.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The flags will be applied during the <see cref="NMGenState.PolyMeshBuild"/> state.
        /// </para>
        /// </remarks>
        /// <param name="state">The current build state.</param>
        /// <param name="context">The context to process.</param>
        /// <returns>True</returns>
        public override bool ProcessBuild(NMGenContext context, NMGenState state)
        {
            if (state != NMGenState.PolyMeshBuild)
            {
                return(true);
            }

            PolyMeshData data = context.PolyMesh.GetData(false);

            for (int i = 0; i < data.flags.Length; i++)
            {
                data.flags[i] |= mFlags;
            }

            context.PolyMesh.Load(data);
            context.Log(string.Format("{0}: Applied flag(s) to all polys. Flag(s): 0x{1:X}"
                                      , Name, mFlags)
                        , this);

            return(true);
        }
        private IncrementalBuilder(NMGenTileParams tileConfig
            , NMGenParams config
            , NMGenAssetFlag resultOptions
            , InputGeometry source
            , ProcessorSet processors)
        {
            mConfig = config;
            mTileConfig = tileConfig;

            mGeometry = source;
            mProcessors = processors;
            mResultOptions = resultOptions;

            mBuildContext = new NMGenContext(tileConfig.TileX, tileConfig.TileZ, mConfig.Clone());

            mTileText = string.Format("({0},{1})", tileConfig.TileX, tileConfig.TileZ);

            mState = NMGenState.Initialized;
        }
 /// <summary>
 /// Logs processor information to the context for debug purposes.
 /// </summary>
 /// <param name="context">The build context.</param>
 public void LogProcessors(NMGenContext context)
 {
     foreach (INMGenProcessor p in mProcessors)
     {
         context.Log(string.Format("Processor: {0} ({1})", p.Name, p.GetType().Name)
             , this);
     }
 }
 /// <summary>
 /// Runs all the processors in order of priority.  (Ascending)
 /// </summary>
 /// <remarks>
 /// <para>
 /// A return value of false indicates the build should be aborted.
 /// </para>
 /// </remarks>
 /// <param name="state">The current state of the build.</param>
 /// <param name="context">The build context.</param>
 /// <returns>False if the build should abort.</returns>
 public bool Process(NMGenContext context, NMGenState state)
 {
     foreach (INMGenProcessor p in mProcessors)
     {
         if (!p.ProcessBuild(context, state))
             return false;
     }
     return true;
 }