コード例 #1
0
 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));
     }
 }
コード例 #2
0
 public void Regenerate(Data data)
 {
     original.InitInfo.Init(mesher, data);
     mesher.Start();
     mesher.Complete(mesh);
     original.MeshFilter.sharedMesh = mesh;
 }
コード例 #3
0
            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));
            }
コード例 #4
0
        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));
                }
            }
        }
コード例 #5
0
ファイル: TopCellMesher.cs プロジェクト: hbence/MeshBuilder
        public void Init(Data data, float cellSize, Info info)
        {
            this.data     = data;
            this.cellSize = cellSize;
            this.info     = info;

            CheckData(data, info);

            Inited();
        }
コード例 #6
0
        public void Init(Data data, float cellSize, params MesherInfo[] mesherInfos)
        {
            Data     = data;
            CellSize = cellSize;

            submeshInfos.Clear();
            AddMeshers(mesherInfos);

            Inited();
        }
コード例 #7
0
ファイル: SideCellMesher.cs プロジェクト: hbence/MeshBuilder
        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));
        }
コード例 #8
0
        public void Init(Data data, float cellSize, MesherInfo[][] mesherInfos)
        {
            Data     = data;
            CellSize = cellSize;

            submeshInfos.Clear();
            foreach (var infos in mesherInfos)
            {
                AddMeshers(infos);
            }

            Inited();
        }
コード例 #9
0
            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));
            }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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!");
            }
        }
コード例 #12
0
ファイル: TopCellMesher.cs プロジェクト: hbence/MeshBuilder
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: TopCellMesher.cs プロジェクト: hbence/MeshBuilder
 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));
         }
     }
 }
コード例 #15
0
        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));
                    }
                }
            }
        }
コード例 #16
0
 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);
コード例 #17
0
ファイル: SideCellMesher.cs プロジェクト: hbence/MeshBuilder
        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);
        }
コード例 #18
0
 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;