/// <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> /// 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); }
/// <summary> /// Builds polygon mesh from the provided contours. /// </summary> /// <remarks> /// <para> /// The values of the CellSize-based parameters will be converted to world units. /// </para> /// </remarks> /// <param name="context">The context to use for the operation.</param> /// <param name="contours">The contours to use to build the mesh.</param> /// <param name="maxVertsPerPoly"> /// The maximum allowed vertices for a polygon. /// [Limits: 3 <= value <= <see cref="NMGen.MaxAllowedVertsPerPoly"/>] /// </param> /// <param name="walkableHeight"> /// The walkable height used to build the contour data. /// [Limit: >= <see cref="NMGen.MinWalkableHeight"/>] [Units: YCellSize] /// </param> /// <param name="walkableRadius"> /// The radius used to erode the walkable area covered by the contours. /// [Limit: >= 0] [Units: XZCellSize] /// </param> /// <param name="walkableStep"> /// The walkable step used to build /// the contour data. [Limit: >= 0] [Units: YCellSize]</param> /// <returns>The generated polygon mesh, or null if there were errors.</returns> public static PolyMesh Build(BuildContext context, ContourSet contours , int maxVertsPerPoly, int walkableHeight, int walkableRadius, int walkableStep) { if (context == null || contours == null) { return(null); } PolyMesh result = new PolyMesh(AllocType.External); if (!PolyMeshEx.rcpmBuildFromContourSet(context.root , contours.root , maxVertsPerPoly , ref result.root , ref result.mMaxVerts)) { return(null); } result.mWalkableHeight = walkableHeight * contours.YCellSize; result.mWalkableRadius = walkableRadius * contours.XZCellSize; result.mWalkableStep = walkableStep * contours.YCellSize; return(result); }
/// <summary> /// Creates a polygon mesh from the data generated by the <see cref="GetSerializedData"/> /// method. /// </summary> /// <param name="serializedMesh">The serialized mesh data.</param> /// <returns>The new polygon mesh, or null on error.</returns> public static PolyMesh Create(byte[] serializedMesh) { PolyMesh result = new PolyMesh(AllocType.External); if (PolyMeshEx.rcpmBuildSerializedData(serializedMesh , serializedMesh.Length , ref result.root , ref result.mMaxVerts , ref result.mWalkableHeight , ref result.mWalkableRadius , ref result.mWalkableStep)) { return(result); } return(null); }
public bool QueueTask(BuildContext context , int tx, int tz , PolyMesh polyMesh, PolyMeshDetail detailMesh , bool bvTreeEnabled , int priority) { TileBuildTask task = TileBuildTask.Create(tx, tz , polyMesh.GetData(false) , (detailMesh == null ? null : detailMesh.GetData(true)) , Build.Connections , bvTreeEnabled , true , priority); if (!mTaskProcessor.QueueTask(task)) { context.LogError("Task processor rejected task.", this); return false; } mTileTasks.Add(task); return true; }
/// <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; }
internal void SetWorkingData(PolyMesh polyMesh, PolyMeshDetail detailMesh) { if (polyMesh == null || polyMesh.PolyCount == 0) { SetAsEmpty(); return; } this.polyMesh = polyMesh.GetSerializedData(false); if (detailMesh == null) this.detailMesh = new byte[0]; else this.detailMesh = detailMesh.GetSerializedData(false); }
internal void SetWorkingData(int x, int z, PolyMesh polyMesh, PolyMeshDetail detailMesh) { int i = GetIndex(x, z); if (i == IndexError) return; unsafeItems[i].SetWorkingData(polyMesh, detailMesh); mIsDirty = true; unsafeVersion++; }
/// <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; }
/// <summary> /// Creates a polygon mesh from the data generated by the <see cref="GetSerializedData"/> /// method. /// </summary> /// <param name="serializedMesh">The serialized mesh data.</param> /// <returns>The new polygon mesh, or null on error.</returns> public static PolyMesh Create(byte[] serializedMesh) { PolyMesh result = new PolyMesh(AllocType.External); if (PolyMeshEx.rcpmBuildSerializedData(serializedMesh , serializedMesh.Length , ref result.root , ref result.mMaxVerts , ref result.mWalkableHeight , ref result.mWalkableRadius , ref result.mWalkableStep)) { return result; } return null; }
/// <summary> /// Builds polygon mesh from the provided contours. /// </summary> /// <remarks> /// <para> /// The values of the CellSize-based parameters will be converted to world units. /// </para> /// </remarks> /// <param name="context">The context to use for the operation.</param> /// <param name="contours">The contours to use to build the mesh.</param> /// <param name="maxVertsPerPoly"> /// The maximum allowed vertices for a polygon. /// [Limits: 3 <= value <= <see cref="NMGen.MaxAllowedVertsPerPoly"/>] /// </param> /// <param name="walkableHeight"> /// The walkable height used to build the contour data. /// [Limit: >= <see cref="NMGen.MinWalkableHeight"/>] [Units: YCellSize] /// </param> /// <param name="walkableRadius"> /// The radius used to erode the walkable area covered by the contours. /// [Limit: >= 0] [Units: XZCellSize] /// </param> /// <param name="walkableStep"> /// The walkable step used to build /// the contour data. [Limit: >= 0] [Units: YCellSize]</param> /// <returns>The generated polygon mesh, or null if there were errors.</returns> public static PolyMesh Build(BuildContext context, ContourSet contours , int maxVertsPerPoly, int walkableHeight, int walkableRadius, int walkableStep) { if (context == null || contours == null) return null; PolyMesh result = new PolyMesh(AllocType.External); if (!PolyMeshEx.rcpmBuildFromContourSet(context.root , contours.root , maxVertsPerPoly , ref result.root , ref result.mMaxVerts)) { return null; } result.mWalkableHeight = walkableHeight * contours.YCellSize; result.mWalkableRadius = walkableRadius * contours.XZCellSize; result.mWalkableStep = walkableStep * contours.YCellSize; return result; }