static private JobHandle ScheduleGenerateOptimizationData(Data data, OptimizedInfo info, bool useCullingData, bool useHeightData, NativeArray <MergeCellInfo> mergeInfoArray, JobHandle lastHandle) { if (useCullingData && useHeightData) { var checker = new CulledHeightMergeChecker() { heights = data.HeightsRawData, colNum = data.ColNum, culled = data.CullingDataRawData }; return(ScheduleGenerateOptimizationData(data, info, checker, mergeInfoArray, lastHandle)); } else if (useCullingData) { var checker = new CulledMergeChecker() { culled = data.CullingDataRawData }; return(ScheduleGenerateOptimizationData(data, info, checker, mergeInfoArray, lastHandle)); } else if (useHeightData) { var checker = new HeightMergeChecker() { heights = data.HeightsRawData, colNum = data.ColNum }; return(ScheduleGenerateOptimizationData(data, info, checker, mergeInfoArray, lastHandle)); } else { return(ScheduleGenerateOptimizationData(data, info, new SimpleMergeChecker(), mergeInfoArray, lastHandle)); } }
public void Regenerate(Data data) { original.InitInfo.Init(mesher, data); mesher.Start(); mesher.Complete(mesh); original.MeshFilter.sharedMesh = mesh; }
public static JobHandle Schedule(GeneratorType generator, Data data, NativeList <float3> vertices, NativeList <int> triangles, bool generateNormals, float3 normal, NativeList <float3> normals, bool generateUVs, NativeList <float2> uvs, NativeArray <InfoType> info, JobHandle dependOn = default) { var cornerJob = new CalculateInfoJob <GeneratorType, InfoType> { distanceColNum = data.ColNum, distanceRowNum = data.RowNum, generator = generator, distances = data.RawData, vertices = vertices, indices = triangles, generateNormals = generateNormals, normals = normals, normal = normal, generateUVs = generateUVs, uvs = uvs, info = info }; return(cornerJob.Schedule(dependOn)); }
public static JobHandle ScheduleCalculateVerticesJob(Data data, ScaledInfo info, bool useHeightData, float cellSize, NativeArray <TopCellInfo> infoArray, NativeList <float3> vertices, NativeArray <EdgeNormals> edgeNormalsArray, JobHandle lastHandle) { if (!edgeNormalsArray.IsCreated) { return(TopCellMesher.ScheduleCalculateVerticesJob(data, info, useHeightData, cellSize, infoArray, vertices, lastHandle)); } if (useHeightData) { if (info.LerpToExactEdge == 1f) { var vertexCalculator = new ScaledBasicHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = info.OffsetY, heights = data.HeightsRawData, heightScale = info.HeightScale, edgeNormalsArray = edgeNormalsArray, sideOffsetScale = info.ScaledOffset }; return(TopCellMesher.ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } else { var vertexCalculator = new ScaledLerpedHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = info.LerpToExactEdge, heightOffset = info.OffsetY, heights = data.HeightsRawData, heightScale = info.HeightScale, edgeNormalsArray = edgeNormalsArray, sideOffsetScale = info.ScaledOffset }; return(TopCellMesher.ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } } else { if (info.LerpToExactEdge == 1f) { var vertexCalculator = new ScaledBasicVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = info.OffsetY, edgeNormalsArray = edgeNormalsArray, sideOffsetScale = info.ScaledOffset }; return(TopCellMesher.ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } else { var vertexCalculator = new ScaledLerpedVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = info.LerpToExactEdge, heightOffset = info.OffsetY, edgeNormalsArray = edgeNormalsArray, sideOffsetScale = info.ScaledOffset }; return(TopCellMesher.ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } } }
public void Init(Data data, float cellSize, Info info) { this.data = data; this.cellSize = cellSize; this.info = info; CheckData(data, info); Inited(); }
public void Init(Data data, float cellSize, params MesherInfo[] mesherInfos) { Data = data; CellSize = cellSize; submeshInfos.Clear(); AddMeshers(mesherInfos); Inited(); }
public static JobHandle ScheduleCalculateUVJob(Data data, Info info, float cellSize, NativeArray <SideCellInfo> infoArray, NativeList <float3> vertices, NativeList <float2> uvs, JobHandle lastHandle = default) { float scaleU = info.UScale; float scaleV = info.VScale; if (info.NormalizeUV) { scaleU /= (math.max(data.ColNum, data.RowNum) - 1) * cellSize; } return(CalculateUVsJob.Schedule(scaleU, scaleV, infoArray, vertices, uvs, lastHandle)); }
public void Init(Data data, float cellSize, MesherInfo[][] mesherInfos) { Data = data; CellSize = cellSize; submeshInfos.Clear(); foreach (var infos in mesherInfos) { AddMeshers(infos); } Inited(); }
static public JobHandle Schedule(Data data, OptimizedInfo info, MergeChecker mergeChecker, NativeArray <MergeCellInfo> optimizationCells, JobHandle dependOn = default) { var optimizationJob = new GenerateOptimizationData <MergeChecker> { distanceColNum = data.ColNum, distanceRowNum = data.RowNum, mode = info.OptimizationMode, mergeChecker = mergeChecker, cells = optimizationCells, distances = data.RawData }; return(optimizationJob.Schedule(dependOn)); }
public void UpdateData(Data newData) { Init(newData.ColNum, newData.RowNum, newData.HasHeights, newData.HasCullingData); NativeArray <float> .Copy(newData.RawData, data); if (heightData != null && newData.HasHeights) { NativeArray <float> .Copy(newData.HeightsRawData, heightData); } if (cullingData != null && newData.HasCullingData) { NativeArray <bool> .Copy(newData.CullingDataRawData, cullingData); } }
static protected void CheckData(Data data, Info info) { if (data == null) { Debug.LogError("Data is null!"); } if (data.ColNum < 2 || data.RowNum < 2) { Debug.LogError($"data size is invalid col:{data.ColNum} row:{data.RowNum}, both needs to be >= 2!"); } if (info == null) { Debug.LogError("Info is null!"); } }
static public JobHandle ScheduleCalculateInfoJob(Data data, Info info, NativeArray <TopCellInfo> infoArray, NativeList <float3> vertices, NativeList <int> triangles, NativeList <float3> normals, NativeList <float2> uvs, JobHandle lastHandle = default) { float3 normal = info.IsFlipped ? new float3(0, -1, 0) : new float3(0, 1, 0); if (info.UseCullingData && data.HasCullingData) { var generator = new CulledTopCellInfoGenerator(); generator.cullingArray = data.CullingDataRawData; lastHandle = CalculateInfoJob <CulledTopCellInfoGenerator, TopCellInfo> .Schedule(generator, data, vertices, triangles, info.GenerateNormals, normal, normals, info.GenerateUvs, uvs, infoArray, lastHandle); } else { var generator = new TopCellInfoGenerator(); lastHandle = CalculateInfoJob <TopCellInfoGenerator, TopCellInfo> .Schedule(generator, data, vertices, triangles, info.GenerateNormals, normal, normals, info.GenerateUvs, uvs, infoArray, lastHandle); } return(lastHandle); }
static private JobHandle ScheduleCalculateInfoJob(Data data, Info info, bool useCullingData, NativeArray <TopCellInfo> infoArray, NativeArray <MergeCellInfo> mergeInfoArray, NativeList <float3> vertices, NativeList <int> triangles, NativeList <float3> normals, NativeList <float2> uvs, JobHandle lastHandle = default) { float3 normal = info.IsFlipped ? new float3(0, -1, 0) : new float3(0, 1, 0); if (useCullingData) { var generator = new CulledOptimizedTopCellInfoGenerator(); generator.mergeInfoArray = mergeInfoArray; generator.culledArray = data.CullingDataRawData; lastHandle = CalculateInfoJob <CulledOptimizedTopCellInfoGenerator, TopCellInfo> .Schedule(generator, data, vertices, triangles, info.GenerateNormals, normal, normals, info.GenerateUvs, uvs, infoArray, lastHandle); } else { var generator = new OptimizedTopCellInfoGenerator(); generator.mergeInfoArray = mergeInfoArray; lastHandle = CalculateInfoJob <OptimizedTopCellInfoGenerator, TopCellInfo> .Schedule(generator, data, vertices, triangles, info.GenerateNormals, normal, normals, info.GenerateUvs, uvs, infoArray, lastHandle); } return(lastHandle); }
public static JobHandle ScheduleCalculateVerticesJob(Data data, Info info, bool useHeightData, float cellSize, NativeArray <TopCellInfo> infoArray, NativeList <float3> vertices, JobHandle lastHandle) { if (useHeightData) { if (info.LerpToExactEdge == 1f) { var vertexCalculator = new BasicHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = info.OffsetY, heights = data.HeightsRawData, heightScale = info.HeightScale }; return(ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } else { var vertexCalculator = new LerpedHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = info.LerpToExactEdge, heightOffset = info.OffsetY, heights = data.HeightsRawData, heightScale = info.HeightScale }; return(ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } } else { if (info.LerpToExactEdge == 1f) { var vertexCalculator = new BasicVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = info.OffsetY }; return(ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } else { var vertexCalculator = new LerpedVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = info.LerpToExactEdge, heightOffset = info.OffsetY }; return(ScheduleCalculateVerticesJob(vertexCalculator, infoArray, vertices, lastHandle)); } } }
static private void CopyData(Data from, Data to) { int minCol = Mathf.Min(from.ColNum, to.ColNum); int minRow = Mathf.Min(from.RowNum, to.RowNum); for (int y = 0; y < minRow; ++y) { for (int x = 0; x < minCol; ++x) { to.SetDistanceAt(x, y, from.DistanceAt(x, y)); if (from.HasHeights && to.HasHeights) { to.SetHeightAt(x, y, from.HeightAt(x, y)); } if (from.HasCullingData && to.HasCullingData) { to.SetCullingAt(x, y, from.CullingAt(x, y)); } } } }
static private JobHandle ScheduleGenerateOptimizationData <MergeChecker>(Data data, OptimizedInfo info, MergeChecker checker, NativeArray <MergeCellInfo> mergeInfoArray, JobHandle lastHandle) where MergeChecker : struct, IMergeChecker => GenerateOptimizationData <MergeChecker> .Schedule(data, info, checker, mergeInfoArray, lastHandle);
private static IVertexCalculator SelectVertexCalculator(Data data, bool useHeightData, float heightOffset, float heightScale, float lerpToEdge, float cellSize, float sideOffset, NativeArray <EdgeNormals> edgeNormals) { IVertexCalculator selected; if (sideOffset > 0) { if (useHeightData) { if (lerpToEdge == 1f) { selected = new ScaledBasicHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = heightOffset, heights = data.HeightsRawData, heightScale = heightScale, sideOffsetScale = sideOffset, edgeNormalsArray = edgeNormals }; } else { selected = new ScaledLerpedHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = lerpToEdge, heightOffset = heightOffset, heights = data.HeightsRawData, heightScale = heightScale, sideOffsetScale = sideOffset, edgeNormalsArray = edgeNormals }; } } else { if (lerpToEdge == 1f) { selected = new ScaledBasicVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = heightOffset, sideOffsetScale = sideOffset, edgeNormalsArray = edgeNormals }; } else { selected = new ScaledLerpedVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = lerpToEdge, heightOffset = heightOffset, sideOffsetScale = sideOffset, edgeNormalsArray = edgeNormals }; } } } else { if (useHeightData) { if (lerpToEdge == 1f) { selected = new BasicHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = heightOffset, heights = data.HeightsRawData, heightScale = heightScale }; } else { selected = new LerpedHeightVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = lerpToEdge, heightOffset = heightOffset, heights = data.HeightsRawData, heightScale = heightScale }; } } else { if (lerpToEdge == 1f) { selected = new BasicVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, heightOffset = heightOffset }; } else { selected = new LerpedVertexCalculator() { colNum = data.ColNum, cellSize = cellSize, lerpToEdge = lerpToEdge, heightOffset = heightOffset }; } } } return(selected); }
static private bool DoesDataMatch(Data data, MarchingSquaresComponent.DataCreationInfo info) => data.ColNum == info.ColNum && data.RowNum == info.RowNum && data.HasHeights == info.HasHeightData && data.HasCullingData == info.HasCullingData;