/// <summary> /// Constructor /// </summary> /// <remarks> /// <para> /// A 'no result' object will be created if the <paramref name="polyMesh"/> parameter /// is null or has a polygon count of zero. /// </para> /// </remarks> /// <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="polyMesh">The polymesh.</param> /// <param name="detailMesh">The detail mesh.</param> /// <param name="heightfield">The heightfield.</param> /// <param name="compactField">The compact field.</param> /// <param name="contours">The contour set.</param> public NMGenAssets(int tx, int tz , PolyMesh polyMesh , PolyMeshDetail detailMesh , Heightfield heightfield , CompactHeightfield compactField , ContourSet contours) { mTileX = tx; mTileZ = tz; if (polyMesh == null || polyMesh.PolyCount == 0) { mPolyMesh = null; mDetailMesh = null; mHeightfield = null; mCompactField = null; mContours = null; } else { mPolyMesh = polyMesh; mDetailMesh = detailMesh; // OK to be null. mHeightfield = heightfield; mCompactField = compactField; mContours = contours; } }
/// <summary> /// Sets the context as having produced no result. /// </summary> public void SetAsNoResult() { mHeightfield = null; mCompactField = null; mContours = null; mPolyMesh = null; mDetailMesh = null; mNoResult = true; }
/// <summary> /// Builds a layer set from the <see cref="CompactHeightfield"/>. /// </summary> /// <param name="context">The context to use duing the operation.</param> /// <param name="field">The source field.</param> /// <returns>The resulting layer set, or null on failure.</returns> public static HeightfieldLayerSet Build(BuildContext context, CompactHeightfield field) { if (context == null) return null; IntPtr ptr = IntPtr.Zero; int layerCount = HeightfieldLayserSetEx.nmlsBuildLayers(context.root , field , field.BorderSize , field.WalkableHeight , ref ptr); if (ptr == IntPtr.Zero) return null; return new HeightfieldLayerSet(ptr, layerCount); }
/// <summary> /// Builds a contour set from the region outlines in the provided <see cref="CompactHeightfield"/>. /// </summary> /// <remarks> /// <para> /// The raw contours will match the region outlines exactly. The edgeMaxDeviation /// and maxEdgeLength parameters control how closely the simplified contours will match /// the raw contours. /// </para> /// <para> /// Simplified contours are generated such that the vertices for portals between areas /// match up. (They are considered mandatory vertices.) /// </para> /// <para> /// Setting maxEdgeLength to zero will disabled the feature. /// </para> /// </remarks> /// <param name="context">The context to use for the build.</param> /// <param name="field">The field to use for the build.(Must have region data.)</param> /// <param name="edgeMaxDeviation"> /// The maximum distance a simplified edge may deviate from the raw contour's vertices. /// [Limit: >= 0] /// </param> /// <param name="maxEdgeLength"> /// The maximum allowed length of a simplified edge. [Limit: >= 0] /// </param> /// <param name="flags">The build flags.</param> /// <returns>The contour set, or null on failure.</returns> public static ContourSet Build(BuildContext context, CompactHeightfield field , float edgeMaxDeviation, int maxEdgeLength, ContourBuildFlags flags) { if (context == null || field == null || field.IsDisposed || edgeMaxDeviation < 0 || maxEdgeLength < 0) { return null; } ContourSetEx root = new ContourSetEx(); if (ContourSetEx.nmcsBuildSet(context.root, field , edgeMaxDeviation, maxEdgeLength , root , flags)) { return new ContourSet(root); } return null; }
/// <summary> /// Creates a compact open heightfield from a solid heightfield. /// </summary> /// <param name="context">The context to use duing the operation.</param> /// <param name="sourceField"> /// The solid heighfield to derive the compact heightfield from. /// </param> /// <param name="walkableHeight"> /// The minimum floor to ceiling height that is still considered walkable. /// [Limit: >= <see cref="NMGen.MinWalkableHeight"/>] /// </param> /// <param name="walkableStep"> /// The maximum floor to floor step that is still considered walkable.</param> /// <returns>True if the operation completed successfully.</returns> public static CompactHeightfield Build(BuildContext context , Heightfield sourceField , int walkableHeight , int walkableStep) { if (context == null || sourceField == null || sourceField.IsDisposed || walkableHeight < NMGen.MinWalkableHeight || walkableStep < 0) { return null; } CompactHeightfield field = new CompactHeightfield(); if (CompactHeightfieldEx.nmcfBuildField(context.root , walkableHeight , walkableStep , sourceField.root , field)) { return field; } return null; }
/// <summary> /// Builds a detail mesh from the provided polygon mesh. /// </summary> /// <param name="context">The context to use for the operation.</param> /// <param name="polyMesh">The source polygon mesh.</param> /// <param name="field">The compact heightfield used to build the polygon mesh.</param> /// <param name="detailSampleDistance"> /// The sample distance to use when sampling the surface height of the polygon mesh. /// </param> /// <param name="detailMaxDeviation"> /// The maximum the surface of the detail mesh should deviate from the heightfield data. /// </param> /// <returns>A new detail mesh, or null on error.</returns> public static PolyMeshDetail Build(BuildContext context , PolyMesh polyMesh, CompactHeightfield field , float detailSampleDistance, float detailMaxDeviation) { if (context == null || polyMesh == null || polyMesh.IsDisposed || field == null || field.IsDisposed || detailSampleDistance < 0 || detailMaxDeviation < 0) { return null; } PolyMeshDetail result = new PolyMeshDetail(AllocType.External); if (PolyMeshDetailEx.rcpdBuildPolyMeshDetail(context.root , ref polyMesh.root , field , detailSampleDistance , detailMaxDeviation , result)) { return result; } return null; }