Пример #1
0
            static public void CalculateVertices(int index, CellInfo info, CellVertices verts, NativeArray <float3> vertices, int colNum, float cellSize, float heightOffset, float lerpToEdge, float sideOffsetScale, NativeArray <EdgeNormals> edgeNormalsArray)
            {
                int x = index % colNum;
                int y = index / colNum;

                float3 pos = new float3(x * cellSize, heightOffset, y * cellSize);

                EdgeNormals normals = edgeNormalsArray[index];

                if (verts.corner >= 0)
                {
                    vertices[verts.corner] = pos;
                }

                if (verts.leftEdge >= 0)
                {
                    float  edgeLerp = cellSize * VcLerpT(info, lerpToEdge);
                    float2 offset   = math.normalize(normals.leftEdgeDir) * sideOffsetScale;
                    vertices[verts.leftEdge] = new float3(pos.x + offset.x, pos.y, pos.z + edgeLerp + offset.y);
                }

                if (verts.bottomEdge >= 0)
                {
                    float  edgeLerp = cellSize * HzLerpT(info, lerpToEdge);
                    float2 offset   = math.normalize(normals.bottomEdgeDir) * sideOffsetScale;
                    vertices[verts.bottomEdge] = new float3(pos.x + edgeLerp + offset.x, pos.y, pos.z + offset.y);
                }
            }
Пример #2
0
 public void UpdateNormals(SideCellInfo cell, SideCellInfo top, SideCellInfo right, ref EdgeNormals cellNormal, ref EdgeNormals topNormal, ref EdgeNormals rightNormal, float lerpToEdge)
 => ScaledTopCellMesher.UpdateNormals(cell.info, top.info, right.info, ref cellNormal, ref topNormal, ref rightNormal, lerpToEdge);
Пример #3
0
        public static void UpdateNormals(CellInfo cell, CellInfo top, CellInfo right, ref EdgeNormals cellNormal, ref EdgeNormals topNormal, ref EdgeNormals rightNormal, float lerpToEdge)
        {
            switch (cell.config)
            {
            // full
            case MaskBL | MaskBR | MaskTR | MaskTL: break;

            // corners
            case MaskBL: AddNormal(0, LerpVc(cell, lerpToEdge), LerpHz(cell, lerpToEdge), 0, ref cellNormal.bottomEdgeDir, ref cellNormal.leftEdgeDir); break;

            case MaskBR: AddNormal(LerpHz(cell, lerpToEdge), 0, 1, LerpVc(right, lerpToEdge), ref cellNormal.bottomEdgeDir, ref rightNormal.leftEdgeDir); break;

            case MaskTR: AddNormal(1, LerpVc(right, lerpToEdge), LerpHz(top, lerpToEdge), 1, ref rightNormal.leftEdgeDir, ref topNormal.bottomEdgeDir); break;

            case MaskTL: AddNormal(LerpHz(top, lerpToEdge), 1, 0, LerpVc(cell, lerpToEdge), ref topNormal.bottomEdgeDir, ref cellNormal.leftEdgeDir); break;

            // halves
            case MaskBL | MaskBR: AddNormal(0, LerpVc(cell, lerpToEdge), 1, LerpVc(right, lerpToEdge), ref cellNormal.leftEdgeDir, ref rightNormal.leftEdgeDir); break;

            case MaskTL | MaskTR: AddNormal(1, LerpVc(right, lerpToEdge), 0, LerpVc(cell, lerpToEdge), ref cellNormal.leftEdgeDir, ref rightNormal.leftEdgeDir); break;

            case MaskBL | MaskTL: AddNormal(LerpHz(top, lerpToEdge), 1, LerpHz(cell, lerpToEdge), 0, ref cellNormal.bottomEdgeDir, ref topNormal.bottomEdgeDir); break;

            case MaskBR | MaskTR: AddNormal(LerpHz(cell, lerpToEdge), 0, LerpHz(top, lerpToEdge), 1, ref cellNormal.bottomEdgeDir, ref topNormal.bottomEdgeDir); break;

            // diagonals
            case MaskBL | MaskTR:
            {
                AddNormal(0, LerpVc(cell, lerpToEdge), LerpHz(top, lerpToEdge), 1, ref cellNormal.leftEdgeDir, ref topNormal.bottomEdgeDir);
                AddNormal(1, LerpVc(right, lerpToEdge), LerpHz(cell, lerpToEdge), 0, ref rightNormal.leftEdgeDir, ref cellNormal.bottomEdgeDir);
                break;
            }

            case MaskTL | MaskBR:
            {
                AddNormal(LerpHz(top, lerpToEdge), 1, 1, LerpVc(right, lerpToEdge), ref topNormal.bottomEdgeDir, ref rightNormal.leftEdgeDir);
                AddNormal(LerpHz(cell, lerpToEdge), 0, 0, LerpVc(cell, lerpToEdge), ref cellNormal.leftEdgeDir, ref cellNormal.bottomEdgeDir);
                break;
            }

            // three quarters
            case MaskBL | MaskTR | MaskBR: AddNormal(0, LerpVc(cell, lerpToEdge), LerpHz(top, lerpToEdge), 1, ref cellNormal.leftEdgeDir, ref topNormal.bottomEdgeDir); break;

            case MaskBL | MaskTL | MaskBR: AddNormal(LerpHz(top, lerpToEdge), 1, 1, LerpVc(right, lerpToEdge), ref topNormal.bottomEdgeDir, ref rightNormal.leftEdgeDir); break;

            case MaskBL | MaskTL | MaskTR: AddNormal(1, LerpVc(right, lerpToEdge), LerpHz(cell, lerpToEdge), 0, ref rightNormal.leftEdgeDir, ref cellNormal.bottomEdgeDir); break;

            case MaskTL | MaskTR | MaskBR: AddNormal(LerpHz(cell, lerpToEdge), 0, 0, LerpVc(cell, lerpToEdge), ref cellNormal.leftEdgeDir, ref cellNormal.bottomEdgeDir); break;
            }
        }