/// <summary>
        /// Creates a new builder for a single-tile mesh build.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The bounds of the tile will be based on the geometry.
        /// </para>
        /// <para>
        /// Will return null if a processor requires the the detail mesh but
        /// the detail mesh is not included in the result options.
        /// </para>
        /// </remarks>
        /// <param name="buildConfig">The build configuration.</param>
        /// <param name="resultOptions">The assets to include in the result.</param>
        /// <param name="geometry">The input geometry.</param>
        /// <param name="processors">The processors to apply.</param>
        /// <returns>A new builder, or null on error.</returns>
        public static IncrementalBuilder Create(NMGenParams buildConfig
                                                , NMGenAssetFlag resultOptions
                                                , InputGeometry geometry
                                                , ProcessorSet processors)
        {
            if (buildConfig == null ||
                geometry == null ||
                processors == null)
            {
                return(null);
            }

            resultOptions |= NMGenAssetFlag.PolyMesh;

            if ((processors.PreserveAssets & NMGenAssetFlag.DetailMesh) != 0 &&
                (resultOptions & NMGenAssetFlag.DetailMesh) == 0)
            {
                // The processors require the detail mesh, but the result won't include it.
                return(null);
            }

            NMGenTileParams tileConfig =
                new NMGenTileParams(0, 0, geometry.BoundsMin, geometry.BoundsMax);

            return(new IncrementalBuilder(tileConfig
                                          , buildConfig, resultOptions, geometry, processors));
        }
Exemple #2
0
        /// <summary>
        /// Creates a new tile set.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The bounds is normally based on the desired origin of the navigation mesh
        /// and the maximum bounds of the input geometry.
        /// </para>
        /// </remarks>
        /// <param name="boundsMin">The minimum AABB bounds of the set.</param>
        /// <param name="boundsMax">The maximum AABB counds of the set.</param>
        /// <param name="config">The shared NMGen configuration.</param>
        /// <param name="geom">The input geometry.</param>
        /// <returns>A new tile set, or null on error.</returns>
        public static TileSetDefinition Create(Vector3 boundsMin, Vector3 boundsMax
                                               , NMGenParams config
                                               , InputGeometry geom)
        {
            if (config == null || !config.IsValid() ||
                !TriangleMesh.IsBoundsValid(boundsMin, boundsMax) ||
                geom == null ||
                config.tileSize <= 0)
            {
                return(null);
            }

            int w;
            int d;

            NMGen.DeriveSizeOfTileGrid(boundsMin, boundsMax
                                       , config.XZCellSize
                                       , config.tileSize
                                       , out w, out d);

            if (w < 1 || d < 1)
            {
                return(null);
            }

            return(new TileSetDefinition(w, d, boundsMin, boundsMax, config, geom));
        }
        /// <summary>
        /// Performs the build in a single step.
        /// </summary>
        public void BuildAll()
        {
            if (mBuilder == null)
            {
                return;
            }

            mBuilder.BuildAll();

            mGeom    = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;
        }
Exemple #4
0
 private TileSetDefinition(int width, int depth
                           , Vector3 boundsMin, Vector3 boundsMax
                           , NMGenParams config
                           , InputGeometry geom)
 {
     // Note: The constructor is private, which is why
     // the references are being stored.
     mBaseConfig = config.Clone();
     mGeometry   = geom;
     mWidth      = width;
     mDepth      = depth;
     mBoundsMin  = boundsMin;
     mBoundsMax  = boundsMax;
 }
 private TileSetDefinition(int width, int depth
     , Vector3 boundsMin, Vector3 boundsMax
     , NMGenParams config
     , InputGeometry geom)
 {
     // Note: The constructor is private, which is why
     // the references are being stored.
     mBaseConfig = config.Clone();
     mGeometry = geom;
     mWidth = width;
     mDepth = depth;
     mBoundsMin = boundsMin;
     mBoundsMax = boundsMax;
 }
        /// <summary>
        /// Performs a single build step.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method must be called repeatedly until it resturns false in order
        /// to complete the build. (Useful in GUI environments.)
        /// </para>
        /// </remarks>
        /// <returns>
        /// True if the build is still underway and another call is required. False
        /// if the build is finished.
        /// </returns>
        public bool Build()
        {
            if (mBuilder == null)
            {
                return(false);
            }

            if (mBuilder.Build())
            {
                return(true);
            }

            mGeom    = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;

            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;
        }
        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>
        /// Creates a new builder for a single-tile mesh build.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The bounds of the tile will be based on the geometry.
        /// </para>
        /// <para>
        /// Will return null if a processor requires the the detail mesh but
        /// the detail mesh is not included in the result options.
        /// </para>
        /// </remarks>
        /// <param name="buildConfig">The build configuration.</param>
        /// <param name="resultOptions">The assets to include in the result.</param>
        /// <param name="geometry">The input geometry.</param>
        /// <param name="processors">The processors to apply.</param>
        /// <returns>A new builder, or null on error.</returns>
        public static IncrementalBuilder Create(NMGenParams buildConfig
            , NMGenAssetFlag resultOptions
            , InputGeometry geometry
            , ProcessorSet processors)
        {
            if (buildConfig == null
                || geometry == null
                || processors == null)
            {
                return null;
            }

            resultOptions |= NMGenAssetFlag.PolyMesh;

            if ((processors.PreserveAssets & NMGenAssetFlag.DetailMesh) != 0
                && (resultOptions & NMGenAssetFlag.DetailMesh) == 0)
            {
                // The processors require the detail mesh, but the result won't include it.
                return null;
            }

            NMGenTileParams tileConfig =
                new NMGenTileParams(0, 0, geometry.BoundsMin, geometry.BoundsMax);

            return new IncrementalBuilder(tileConfig
                , buildConfig, resultOptions, geometry, processors);
        }
        /// <summary>
        /// Creates a new tile set.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The bounds is normally based on the desired origin of the navigation mesh
        /// and the maximum bounds of the input geometry.
        /// </para>
        /// </remarks>
        /// <param name="boundsMin">The minimum AABB bounds of the set.</param>
        /// <param name="boundsMax">The maximum AABB counds of the set.</param>
        /// <param name="config">The shared NMGen configuration.</param>
        /// <param name="geom">The input geometry.</param>
        /// <returns>A new tile set, or null on error.</returns>
        public static TileSetDefinition Create(Vector3 boundsMin, Vector3 boundsMax
            , NMGenParams config
            , InputGeometry geom)
        {
            if (config == null || !config.IsValid()
                || !TriangleMesh.IsBoundsValid(boundsMin, boundsMax)
                || geom == null
                || config.tileSize <= 0)
            {
                return null;
            }

            int w;
            int d;

            NMGen.DeriveSizeOfTileGrid(boundsMin, boundsMax
                , config.XZCellSize
                , config.tileSize
                , out w, out d);

            if (w < 1 || d < 1)
                return null;

            return new TileSetDefinition(w, d, boundsMin, boundsMax, config, geom);
        }
        /// <summary>
        /// Performs the build in a single step.
        /// </summary>
        public void BuildAll()
        {
            if (mBuilder == null)
                return;

            mBuilder.BuildAll();

            mGeom = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;
        }
        /// <summary>
        /// Performs a single build step.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method must be called repeatedly until it resturns false in order
        /// to complete the build. (Useful in GUI environments.)
        /// </para>
        /// </remarks>
        /// <returns>
        /// True if the build is still underway and another call is required. False
        /// if the build is finished.
        /// </returns>
        public bool Build()
        {
            if (mBuilder == null)
                return false;

            if (mBuilder.Build())
                return true;

            mGeom = new InputGeometry(mBuilder.Result, mBoundsMin, mBoundsMax);
            mBuilder = null;

            return false;
        }