/// <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> /// 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> /// Constructs a detail mesh from the data generated by the <see cref="GetSerializedData"/> /// method. /// </summary> /// <param name="serializedMesh">The source data.</param> /// <returns>The new detail mesh, or null on error.</returns> public static PolyMeshDetail Create(byte[] serializedMesh) { PolyMeshDetail result = new PolyMeshDetail(AllocType.External); if (PolyMeshDetailEx.rcpdBuildFromMeshData(serializedMesh , serializedMesh.Length , result)) { return(result); } return(null); }
/// <summary> /// Builds an aggregate triangle mesh from a detail mesh. /// </summary> /// <remarks> /// <para> /// All duplicate vertices are merged. /// </para> /// </remarks> /// <param name="source">The detail mesh to extract the triangle mesh from.</param> /// <param name="verts">The result vertices.</param> /// <param name="tris"> /// The result triangles. [(vertAIndex, vertBIndex, vertCIndex) * triCount] /// </param> /// <returns>True if the operation completed successfully.</returns> public static bool ExtractTriMesh(PolyMeshDetail source , out Vector3[] verts , out int[] tris) { // TODO: EVAL: v0.5: Inefficient. verts = null; tris = null; if (source == null || source.IsDisposed || source.TriCount == 0) { return(false); } // Assume no duplicate verts. Vector3[] tverts = new Vector3[source.VertCount]; tris = new int[source.TriCount * 3]; int vertCount = 0; int triCount = 0; if (PolyMeshDetailEx.rcpdFlattenMesh(source , tverts , ref vertCount , source.VertCount , tris , ref triCount , source.TriCount)) { verts = new Vector3[vertCount]; for (int i = 0; i < vertCount; i++) { verts[i] = tverts[i]; } return(true); } tris = null; return(false); }
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; }
/// <summary> /// Builds an aggregate triangle mesh from a detail mesh. /// </summary> /// <remarks> /// <para> /// All duplicate vertices are merged. /// </para> /// </remarks> /// <param name="source">The detail mesh to extract the triangle mesh from.</param> /// <param name="verts">The result vertices.</param> /// <param name="tris"> /// The result triangles. [(vertAIndex, vertBIndex, vertCIndex) * triCount] /// </param> /// <returns>True if the operation completed successfully.</returns> public static bool ExtractTriMesh(PolyMeshDetail source , out Vector3[] verts , out int[] tris) { // TODO: EVAL: v0.5: Inefficient. verts = null; tris = null; if (source == null || source.IsDisposed || source.TriCount == 0) return false; // Assume no duplicate verts. Vector3[] tverts = new Vector3[source.VertCount]; tris = new int[source.TriCount * 3]; int vertCount = 0; int triCount = 0; if (PolyMeshDetailEx.rcpdFlattenMesh(source , tverts , ref vertCount , source.VertCount , tris , ref triCount , source.TriCount)) { verts = new Vector3[vertCount]; for (int i = 0; i < vertCount; i++) { verts[i] = tverts[i]; } return true; } tris = null; return false; }
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> /// Constructs a detail mesh from the data generated by the <see cref="GetSerializedData"/> /// method. /// </summary> /// <param name="serializedMesh">The source data.</param> /// <returns>The new detail mesh, or null on error.</returns> public static PolyMeshDetail Create(byte[] serializedMesh) { PolyMeshDetail result = new PolyMeshDetail(AllocType.External); if (PolyMeshDetailEx.rcpdBuildFromMeshData(serializedMesh , serializedMesh.Length , result)) { return result; } 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; }