Пример #1
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));
                }
            }
        }
Пример #2
0
        static byte CalcTriIndexCount(byte config)
        {
            byte count = (byte)(2 * TopCellMesher.CalcTriIndexCount(config));

            if (config != 0 && config != MaskFull)
            {
                count += 2 * 3;
            }
            return(count);
        }
Пример #3
0
 public void CalculateIndices(Orderer orderer, byte config, int triangleIndex, MergeTriInfo mergeInfo, IndexSpan tris, CellVertices bl, CellVertices br, CellVertices tr, CellVertices tl)
 {
     if (mergeInfo.triangleCount > 0)
     {
         if (mergeInfo.triangleCount == 1)
         {
             orderer.AddTriangle(triangles, ref triangleIndex, VertexIndexA0(mergeInfo), VertexIndexA1(mergeInfo), VertexIndexA2(mergeInfo));
         }
         else if (mergeInfo.triangleCount == 2)
         {
             orderer.AddTriangle(triangles, ref triangleIndex, VertexIndexA0(mergeInfo), VertexIndexA1(mergeInfo), VertexIndexA2(mergeInfo));
             orderer.AddTriangle(triangles, ref triangleIndex, VertexIndexB0(mergeInfo), VertexIndexB1(mergeInfo), VertexIndexB2(mergeInfo));
         }
     }
     else
     {
         TopCellMesher.CalculateIndices(orderer, config, triangleIndex, tris, bl, br, tr, tl, triangles);
     }
 }
Пример #4
0
            static public TopCellInfo GenerateInfo(NativeArray <MergeCellInfo> mergeInfoArray, int index, float cornerDistance, float rightDistance, float topRightDistance, float topDistance, ref int nextVertex, ref int nextTriIndex, bool hasTriangle)
            {
                MergeCellInfo mergeCell = mergeInfoArray[index];
                MergeTriInfo  mergeInfo = mergeCell.mergedInfo;

                if (mergeCell.canBeMerged)
                {
                    byte indexLength = (byte)(mergeInfo.triangleCount * 3);

                    byte config   = CalcConfiguration(cornerDistance, rightDistance, topRightDistance, topDistance);
                    var  cellInfo = new TopCellInfo()
                    {
                        info = new CellInfo()
                        {
                            config = config, cornerDist = cornerDistance, rightDist = rightDistance, topDist = topDistance
                        },
                        verts = new CellVertices {
                            corner = -1, leftEdge = -1, bottomEdge = -1
                        },
                        tris = new IndexSpan(nextTriIndex, indexLength)
                    };

                    if (hasTriangle)
                    {
                        nextTriIndex += indexLength;
                    }

                    if (mergeCell.needsVertex)
                    {
                        cellInfo.verts.corner = nextVertex;
                        ++nextVertex;
                    }

                    return(cellInfo);
                }
                else
                {
                    return(hasTriangle ?
                           TopCellMesher.GenerateInfoWithTriangles(cornerDistance, rightDistance, topRightDistance, topDistance, ref nextVertex, ref nextTriIndex) :
                           TopCellMesher.GenerateInfoNoTriangles(cornerDistance, rightDistance, topRightDistance, topDistance, ref nextVertex, ref nextTriIndex));
                }
            }
Пример #5
0
 public TopCellInfo GenerateInfoNoTriangles(int index, float cornerDistance, float rightDistance, float topRightDistance, float topDistance, ref int nextVertex, ref int nextTriIndex)
 => TopCellMesher.GenerateInfoNoTriangles(cornerDistance, rightDistance, topRightDistance, topDistance, ref nextVertex, ref nextTriIndex);