/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tx">The x-index of the tile within the tile grid. (tx, tz)</param>
        /// <param name="tz">The z-index of the tile within the tile grid. (tx, tz)</param>
        /// <param name="config">The build configuration.</param>
        public NMGenContext(int tx, int tz, NMGenParams config)
        {
            mTileX = tx;
            mTileZ = tz;

            mConfig = config;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Derives the recommended border size for tiled mesh builds.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The tile size and agent parameters should be set before deriving the border size.
 /// </para>
 /// </remarks>
 /// <param name="config">The configuration to derive the border size from.</param>
 /// <returns>The recommended border size.</returns>
 public static int DeriveBorderSize(NMGenParams config)
 {
     if (config.TileSize > 0)
     {
         return(config.WalkableRadius + 3);
     }
     return(0);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Clones the object.
        /// </summary>
        /// <returns>A clone.</returns>
        public NMGenParams Clone()
        {
            NMGenParams result = new NMGenParams();

            result.xzCellSize           = xzCellSize;
            result.yCellSize            = yCellSize;
            result.detailMaxDeviation   = detailMaxDeviation;
            result.detailSampleDistance = detailSampleDistance;
            result.edgeMaxDeviation     = edgeMaxDeviation;
            result.borderSize           = borderSize;
            result.walkableSlope        = walkableSlope;
            result.walkableStep         = walkableStep;
            result.maxVertsPerPoly      = maxVertsPerPoly;
            result.walkableRadius       = walkableRadius;
            result.maxEdgeLength        = maxEdgeLength;
            result.walkableHeight       = walkableHeight;
            result.mergeRegionArea      = mergeRegionArea;
            result.minRegionArea        = minRegionArea;
            result.tileSize             = tileSize;
            result.contourOptions       = contourOptions;
            result.useMonotone          = useMonotone;

            return(result);
        }
        private void ApplyLocalsTo(NMGenParams config)
        {
            config.SetMaxEdgeLength(mMaxEdgeLength);
            config.SetMergeRegionArea(mMergeRegionArea);
            config.SetMinRegionArea(mMinRegionArea);

            config.SetWalkableHeight(mWalkableHeight);
            config.SetWalkableRadius(mWalkableRadius);
            config.SetWalkableStep(mWalkableStep);
        }
        private void UpdateLocalsFrom(NMGenParams config)
        {
            mMaxEdgeLength = config.WorldMaxEdgeLength;
            mMergeRegionArea = config.WorldMergeRegionArea;
            mMinRegionArea = config.WorldMinRegionArea;

            mWalkableHeight = config.WorldWalkableHeight;
            mWalkableRadius = config.WorldWalkableRadius;
            mWalkableStep = config.WorldWalkableStep;
        }
        /// <summary>
        /// Sets the configuration to match the provided configuration.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The <paramref name="config"/> parameter will be cleaned during this operation.
        /// </para>
        /// </remarks>
        /// <param name="config">The configuration to match.</param>
        public void SetConfig(NMGenParams config)
        {
            if (config == null)
                return;

            mRoot = config.Clone();
            mRoot.Clean();
            UpdateLocalsFrom(mRoot);
        }
 public void Reset()
 {
     mRoot = new NMGenParams();
     UpdateLocalsFrom(mRoot);
     mBuildFlags = DefaultBuildFlags;
 }
        /// <summary>
        /// Clones the object.
        /// </summary>
        /// <returns>A clone.</returns>
        public NMGenParams Clone()
        {
            NMGenParams result = new NMGenParams();
            result.xzCellSize = xzCellSize;
            result.yCellSize = yCellSize;
            result.detailMaxDeviation = detailMaxDeviation;
            result.detailSampleDistance = detailSampleDistance;
            result.edgeMaxDeviation = edgeMaxDeviation;
            result.borderSize = borderSize;
            result.walkableSlope = walkableSlope;
            result.walkableStep = walkableStep;
            result.maxVertsPerPoly = maxVertsPerPoly;
            result.walkableRadius = walkableRadius;
            result.maxEdgeLength = maxEdgeLength;
            result.walkableHeight = walkableHeight;
            result.mergeRegionArea = mergeRegionArea;
            result.minRegionArea = minRegionArea;
            result.tileSize = tileSize;
            result.contourOptions = contourOptions;
            result.useMonotone = useMonotone;

            return result;
        }
 /// <summary>
 /// Derives the recommended border size for tiled mesh builds.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The tile size and agent parameters should be set before deriving the border size.
 /// </para>
 /// </remarks>
 /// <param name="config">The configuration to derive the border size from.</param>
 /// <returns>The recommended border size.</returns>
 public static int DeriveBorderSize(NMGenParams config)
 {
     if (config.TileSize > 0)
     {
         return config.WalkableRadius + 3;
     }
     return 0;
 }
        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);
        }
Exemplo n.º 13
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);
        }