Esempio n. 1
0
        /// <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;
        }
Esempio n. 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>
        /// 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));
        }
Esempio n. 4
0
        /// <summary>
        /// Generates a <see cref="NMGenParams"/> based on the the object
        /// values.
        /// </summary>
        /// <returns>A configuration based on the object values.</returns>
        public NMGenParams GetConfig()
        {
            NMGenParams result = mRoot.Clone();

            ApplyLocalsTo(result);

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

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

            mWalkableHeight = config.WorldWalkableHeight;
            mWalkableRadius = config.WorldWalkableRadius;
            mWalkableStep   = config.WorldWalkableStep;
        }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
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;
 }
Esempio n. 9
0
    private void SetConfigFromTargetIntern(Navmesh navmesh)
    {
        NavmeshBuildInfo targetConfig = BuildTarget.BuildInfo;
        NMGenParams      currConfig   = mConfig.GetConfig();

        // Note: Must ensure exact match with original configuration.
        // So this process is using the fields and trusting the
        // original configuration to have valid values.

        currConfig.tileSize       = targetConfig.tileSize;
        currConfig.walkableHeight = targetConfig.walkableHeight;
        currConfig.walkableRadius = targetConfig.walkableRadius;
        currConfig.walkableStep   = targetConfig.walkableStep;
        currConfig.xzCellSize     = targetConfig.xzCellSize;
        currConfig.yCellSize      = targetConfig.yCellSize;
        currConfig.borderSize     = targetConfig.borderSize;

        mBoundsMin = navmesh.GetConfig().origin;

        int maxTiles = navmesh.GetMaxTiles();

        // Make sure the maximum bounds fits the target mesh.
        // Note: Will not shrink the existing max bounds.
        for (int i = 0; i < maxTiles; i++)
        {
            NavmeshTile tile = navmesh.GetTile(i);

            if (tile == null)
            {
                continue;
            }

            NavmeshTileHeader tileHeader = tile.GetHeader();

            if (tileHeader.polyCount == 0)
            {
                continue;
            }

            mBoundsMax = Vector3.Max(mBoundsMax, tileHeader.boundsMax);
        }

        mConfig.SetConfig(currConfig);

        mIsDirty = 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;
        }
Esempio n. 11
0
        internal static NavmeshBuildInfo GetConfig(NavmeshBuild build)
        {
            if (!build)
            {
                return(null);
            }

            NMGenParams config = build.Config.GetConfig();

            NavmeshBuildInfo result = new NavmeshBuildInfo();

            result.tileSize       = config.TileSize;
            result.walkableHeight = config.WalkableHeight;
            result.walkableRadius = config.WalkableRadius;
            result.walkableStep   = config.WalkableStep;
            result.xzCellSize     = config.XZCellSize;
            result.yCellSize      = config.YCellSize;
            result.borderSize     = config.BorderSize;
            result.inputScene     = SceneManager.GetActiveScene().path;
            return(result);
        }
Esempio n. 12
0
        internal static NavmeshBuildInfo GetConfig(NavmeshBuild build)
        {
            if (!build)
            {
                return(null);
            }

            NMGenParams config = build.Config.GetConfig();

            NavmeshBuildInfo result = new NavmeshBuildInfo();

            result.tileSize       = config.TileSize;
            result.walkableHeight = config.WalkableHeight;
            result.walkableRadius = config.WalkableRadius;
            result.walkableStep   = config.WalkableStep;
            result.xzCellSize     = config.XZCellSize;
            result.yCellSize      = config.YCellSize;
            result.borderSize     = config.BorderSize;
            result.inputScene     = EditorApplication.currentScene;

            return(result);
        }
Esempio n. 13
0
 public void Reset()
 {
     mRoot = new NMGenParams();
     UpdateLocalsFrom(mRoot);
     mBuildFlags = DefaultBuildFlags;
 }