public void UpdateMesh(MeshVertexData cache) { int xw = (int)Mathf.Pow(2, lod); int yw = xw; UpdateMesh_InternalLod(cache, xw, yw, m_LeftLod, m_RightLod, m_UpLod, m_DownLod); }
protected void AddTopTriangle(MeshVertexData cache) { Vector3 v0 = new Vector3(offsetX + cellX * cellWidth, 0, offsetY + cellY * cellHeight + cellHeight); Vector3 v1 = new Vector3(offsetX + cellX * cellWidth + cellWidth, 0, offsetY + cellY * cellHeight + cellHeight); Vector3 v2 = new Vector3(offsetX + cellX * cellWidth + cellWidth * 0.5f, 0, offsetY + cellY * cellHeight + cellHeight * 0.5f); cache.AddTriangle(v0, v1, v2); }
protected void AddQuad(MeshVertexData cache) { cache.AddVertex(new Vector3(offsetX + cellX * cellWidth, 0, offsetY + cellY * cellHeight)); cache.AddVertex(new Vector3(offsetX + cellX * cellWidth, 0, offsetY + cellY * cellHeight + cellHeight)); cache.AddVertex(new Vector3(offsetX + cellX * cellWidth + cellWidth, 0, offsetY + cellY * cellHeight + cellHeight)); cache.AddVertex(new Vector3(offsetX + cellX * cellWidth + cellWidth, 0, offsetY + cellY * cellHeight)); cache.AddIndex(cache.index); cache.AddIndex(cache.index + 1); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index + 3); cache.index += 4; }
public Mesh GenerateMesh(Texture2D texture) { if (cellSizeX <= 0 || cellSizeZ <= 0 || widthX <= 0 || widthZ <= 0) { return(null); } float deltaX = widthX * 2 / cellSizeX; float deltaY = widthZ * 2 / cellSizeZ; MeshVertexData cache = new MeshVertexData(cellSizeX, cellSizeZ, deltaX, deltaY, -widthX, -widthZ); for (int i = 0; i < cellSizeZ; i++) { for (int j = 0; j < cellSizeX; j++) { Vector3 p0 = new Vector3(-widthX + j * deltaX, 0, -widthZ + i * deltaY); Vector3 p1 = new Vector3(-widthX + j * deltaX, 0, -widthZ + i * deltaY + deltaY); Vector3 p2 = new Vector3(-widthX + j * deltaX + deltaX, 0, -widthZ + i * deltaY + deltaY); Vector3 p3 = new Vector3(-widthX + j * deltaX + deltaX, 0, -widthZ + i * deltaY); cache.AddVertex(p0); cache.AddVertex(p1); cache.AddVertex(p2); cache.AddVertex(p3); cache.AddIndex(cache.index); cache.AddIndex(cache.index + 1); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index + 3); cache.index += 4; } } Mesh mesh = cache.Apply(texture, uvDir, samples); return(mesh); }
public Mesh GenerateMesh(Texture2D texture) { int cellSize = (int)Mathf.Pow(2, depth); if (widthX <= 0 || widthZ <= 0 || samples < 1) { return(null); } QuadTreeMeshNode[,] cells = new QuadTreeMeshNode[cellSize, cellSize]; //根据贴图尺寸和单元格数量,计算分配给单个单元格的像素宽高 int w = texture.width / cellSize; int h = texture.height / cellSize; //计算Lod for (int i = 0; i < cellSize; i++) { for (int j = 0; j < cellSize; j++) { var cell = new QuadTreeMeshLeaf(-widthX, -widthZ, i, j, widthX * 2 / cellSize, widthZ * 2 / cellSize); //为单元格分配指定区域的像素并计算极差和平均值 cell.Calculate(texture, i * w, j * h, w, h); cells[i, j] = cell; } } float dtx = widthX * 2 / cellSize; float dty = widthZ * 2 / cellSize; MeshVertexData cache = new MeshVertexData(cellSize, cellSize, dtx, dty, -widthX, -widthZ); while (cellSize > 1) { cellSize = cellSize / 2; QuadTreeMeshNode[,] nodes = new QuadTreeMeshNode[cellSize, cellSize]; for (int i = 0; i < cellSize; i++) { for (int j = 0; j < cellSize; j++) { QuadTreeMeshNode lb = cells[i * 2, j * 2]; QuadTreeMeshNode rb = cells[i * 2 + 1, j * 2]; QuadTreeMeshNode lt = cells[i * 2, j * 2 + 1]; QuadTreeMeshNode rt = cells[i * 2 + 1, j * 2 + 1]; QuadTreeMeshNode node = new QuadTreeMeshNode(lt, lb, rt, rb, -widthX, -widthZ, i, j, widthX * 2 / cellSize, widthZ * 2 / cellSize); nodes[i, j] = node; } } for (int i = 0; i < cellSize; i++) { for (int j = 0; j < cellSize; j++) { var left = i != 0 ? nodes[i - 1, j] : null; var right = i != nodes.GetLength(0) - 1 ? nodes[i + 1, j] : null; var down = j != 0 ? nodes[i, j - 1] : null; var up = j != nodes.GetLength(1) - 1 ? nodes[i, j + 1] : null; nodes[i, j].SetNeighbor(left, right, up, down); } } cells = nodes; } for (int i = 0; i < cellSize; i++) { for (int j = 0; j < cellSize; j++) { cells[i, j].UpdateMesh(cache); } } return(cache.Apply(texture, uvDir, samples)); }
private void UpdateMeshVerticalEdge(MeshVertexData cache, float x, int xwidth, int ywidth, int neighborLod, int bottomIndex, int upIndex, int firstIndex, bool clockWise) { neighborLod = neighborLod < 0 ? lod : neighborLod; int deltaLod = Mathf.Max(0, lod - neighborLod); int step = (int)Mathf.Pow(2, deltaLod); int sp = deltaLod * (deltaLod - 1); int offset = deltaLod == 0 ? 0 : (int)Mathf.Pow(2, deltaLod - 1) - 1; for (int i = 0; i <= ywidth; i += step) { int ind = i / step; if (i != 0 && i != ywidth) { float z = ((float)i) / ywidth * m_CellHeight + m_CellY * m_CellHeight + m_OffsetY; cache.AddVertex(new Vector3(x, 0, z)); } if (i != ywidth) { if (i == 0) { cache.AddIndex(bottomIndex); } else { cache.AddIndex(cache.index + ind - 1); } if (clockWise) { if (i == ywidth - step) { cache.AddIndex(upIndex); } else { cache.AddIndex(cache.index + ind + 1 - 1); } if (i == ywidth - 1) { cache.AddIndex(firstIndex + (ywidth - 2) * (xwidth - 1)); } else { cache.AddIndex(firstIndex + (i + offset) * (xwidth - 1)); } } else { if (i == ywidth - 1) { cache.AddIndex(firstIndex + (ywidth - 2) * (xwidth - 1)); } else { cache.AddIndex(firstIndex + (i + offset) * (xwidth - 1)); } if (i == ywidth - step) { cache.AddIndex(upIndex); } else { cache.AddIndex(cache.index + ind + 1 - 1); } } } if (i > 0 && i <= ywidth - step) { if (deltaLod != 0 || i != ywidth - 1) { cache.AddIndex(cache.index + ind - 1); if (clockWise) { cache.AddIndex(firstIndex + (i) * (xwidth - 1)); cache.AddIndex(firstIndex + (i - 1) * (xwidth - 1)); } else { cache.AddIndex(firstIndex + (i - 1) * (xwidth - 1)); cache.AddIndex(firstIndex + (i) * (xwidth - 1)); } } } if (deltaLod != 0) { if (i >= 0 && i < ywidth - step) { if (clockWise) { cache.AddIndex(firstIndex + (i + sp + 1) * (xwidth - 1)); cache.AddIndex(firstIndex + (i + sp) * (xwidth - 1)); } else { cache.AddIndex(firstIndex + (i + sp) * (xwidth - 1)); cache.AddIndex(firstIndex + (i + sp + 1) * (xwidth - 1)); } cache.AddIndex(cache.index + ind + 1 - 1); } if (i >= 0 && i <= ywidth - step) { int bindex = i == 0 ? bottomIndex : (cache.index + ind - 1); int eindex = i == ywidth - step ? upIndex : (cache.index + ind); for (int j = 0; j < step - 2; j++) { if (j < offset) { cache.AddIndex(bindex); } else { cache.AddIndex(eindex); } if (clockWise) { cache.AddIndex(firstIndex + (i + j + 1) * (xwidth - 1)); cache.AddIndex(firstIndex + (i + j) * (xwidth - 1)); } else { cache.AddIndex(firstIndex + (i + j) * (xwidth - 1)); cache.AddIndex(firstIndex + (i + j + 1) * (xwidth - 1)); } } } } } cache.index += deltaLod == 0 ? (ywidth - 1) : (ywidth - 2) / step; }
private void UpdateMeshHorizontalEdge(MeshVertexData cache, float z, int edgeWidth, int neighborLod, int leftIndex, int rightIndex, int firstIndex, bool clockWise) { neighborLod = neighborLod < 0 ? lod : neighborLod; int deltaLod = Mathf.Max(0, lod - neighborLod); int step = (int)Mathf.Pow(2, deltaLod); int sp = deltaLod * (deltaLod - 1); int offset = deltaLod == 0 ? 0 : (int)Mathf.Pow(2, deltaLod - 1) - 1; for (int i = 0; i <= edgeWidth; i += step) { int ind = i / step; if (i != 0 && i != edgeWidth) { float x = ((float)i) / edgeWidth * m_CellWidth + m_CellX * m_CellWidth + m_OffsetX; cache.AddVertex(new Vector3(x, 0, z)); } if (i != edgeWidth) { if (i == 0) { cache.AddIndex(leftIndex); } else { cache.AddIndex(cache.index + ind - 1); } if (clockWise) { if (i == edgeWidth - 1) { cache.AddIndex(firstIndex + edgeWidth - 2); } else { cache.AddIndex(firstIndex + i + offset); } if (i == edgeWidth - step) { cache.AddIndex(rightIndex); } else { cache.AddIndex(cache.index + ind + 1 - 1); } } else { if (i == edgeWidth - step) { cache.AddIndex(rightIndex); } else { cache.AddIndex(cache.index + ind + 1 - 1); } if (i == edgeWidth - 1) { cache.AddIndex(firstIndex + edgeWidth - 2); } else { cache.AddIndex(firstIndex + i + offset); } } } if (i > 0 && i <= edgeWidth - step) { if (deltaLod != 0 || i != edgeWidth - 1) { cache.AddIndex(cache.index + ind - 1); if (clockWise) { cache.AddIndex(firstIndex + i - 1); cache.AddIndex(firstIndex + i); } else { cache.AddIndex(firstIndex + i); cache.AddIndex(firstIndex + i - 1); } } } if (deltaLod != 0) { if (i >= 0 && i < edgeWidth - step) { if (clockWise) { cache.AddIndex(firstIndex + i + sp); cache.AddIndex(firstIndex + i + sp + 1); } else { cache.AddIndex(firstIndex + i + sp + 1); cache.AddIndex(firstIndex + i + sp); } cache.AddIndex(cache.index + ind + 1 - 1); } if (i >= 0 && i <= edgeWidth - step) { int bindex = i == 0 ? leftIndex : (cache.index + ind - 1); int eindex = i == edgeWidth - step ? rightIndex : (cache.index + ind); for (int j = 0; j < step - 2; j++) { if (j < offset) { cache.AddIndex(bindex); } else { cache.AddIndex(eindex); } if (clockWise) { cache.AddIndex(firstIndex + i + j); cache.AddIndex(firstIndex + i + j + 1); } else { cache.AddIndex(firstIndex + i + j + 1); cache.AddIndex(firstIndex + i + j); } } } } } cache.index += deltaLod == 0 ? (edgeWidth - 1) : (edgeWidth - 2) / step; }
private void UpdateMesh_InternalLod(MeshVertexData cache, int xwidth, int ywidth, int leftLod, int rightLod, int upLod, int downLod) { int firstIndex = cache.index; if (lod == 0) { cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_CellHeight + m_OffsetY)); cache.AddIndex(cache.index + 0); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index + 1); cache.AddIndex(cache.index + 1); cache.AddIndex(cache.index + 2); cache.AddIndex(cache.index + 3); cache.index += 4; return; } else if (lod == 1) { cache.AddVertex(new Vector3(m_CellX * m_CellWidth + 0.5f * m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + 0.5f * m_CellHeight + m_OffsetY)); cache.index += 1; } else { for (int i = 1; i < ywidth; i++) { for (int j = 1; j < xwidth; j++) { float x = ((float)j) / xwidth * m_CellWidth + m_CellX * m_CellWidth + m_OffsetX; float z = ((float)i) / ywidth * m_CellHeight + m_CellY * m_CellHeight + m_OffsetY; Vector3 pos = new Vector3(x, 0, z); cache.AddVertex(pos); if (j != xwidth - 1 && i != ywidth - 1) { cache.AddIndex(cache.index + (i - 1) * (xwidth - 1) + j - 1); cache.AddIndex(cache.index + (i) * (xwidth - 1) + j - 1); cache.AddIndex(cache.index + (i - 1) * (xwidth - 1) + j); cache.AddIndex(cache.index + (i - 1) * (xwidth - 1) + j); cache.AddIndex(cache.index + (i) * (xwidth - 1) + j - 1); cache.AddIndex(cache.index + (i) * (xwidth - 1) + j); } } } cache.index += (ywidth - 1) * (xwidth - 1); } cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_CellHeight + m_OffsetY)); cache.AddVertex(new Vector3(m_CellX * m_CellWidth + m_CellWidth + m_OffsetX, 0, m_CellY * m_CellHeight + m_CellHeight + m_OffsetY)); int lbindex = cache.index; int rbindex = cache.index + 1; int luindex = cache.index + 2; int ruindex = cache.index + 3; cache.index += 4; UpdateMeshHorizontalEdge(cache, m_CellY * m_CellHeight + m_OffsetY, xwidth, downLod, lbindex, rbindex, firstIndex, true); UpdateMeshHorizontalEdge(cache, m_CellY * m_CellHeight + m_CellHeight + m_OffsetY, xwidth, upLod, luindex, ruindex, firstIndex + (xwidth - 1) * (ywidth - 2), false); UpdateMeshVerticalEdge(cache, m_CellX * m_CellWidth + m_OffsetX, xwidth, ywidth, leftLod, lbindex, luindex, firstIndex, true); UpdateMeshVerticalEdge(cache, m_CellX * m_CellWidth + m_CellWidth + m_OffsetX, xwidth, ywidth, rightLod, rbindex, ruindex, firstIndex + xwidth - 2, false); }
public Mesh GenerateMesh(Texture2D texture) { if (cellSizeX <= 0 || cellSizeZ <= 0 || widthX <= 0 || widthZ <= 0 || maxLod < 0 || samples < 1) { return(null); } LodMeshCell[,] cells = new LodMeshCell[cellSizeX, cellSizeZ]; //根据贴图尺寸和单元格数量,计算分配给单个单元格的像素宽高 int w = texture.width / cellSizeX; int h = texture.height / cellSizeZ; //计算Lod for (int i = 0; i < cellSizeX; i++) { for (int j = 0; j < cellSizeZ; j++) { cells[i, j] = new LodMeshCell(-widthX, -widthZ, i, j, widthX * 2 / cellSizeX, widthZ * 2 / cellSizeZ); //为单元格分配指定区域的像素并计算极差和平均值 cells[i, j].Calculate(texture, i * w, j * h, w, h, maxLod); } } //根据上一步计算的结果,将最大lod单元格边上的格子设置lod递减 for (int i = 0; i < cellSizeX; i++) { for (int j = 0; j < cellSizeZ; j++) { LodMeshCell cell = cells[i, j]; if (cell.lod == -1) { continue; } if (cell.lod != maxLod) { continue; } for (int lx = maxLod - 1, ly = 0; lx >= 0; lx--, ly++) { for (int lk = 0; lk <= ly; lk++) { if (lk == 0 && lx == 0) { continue; } int clod = maxLod - lx - lk; //从最大lod处往外递减lod SetNeighborLOD(i - lx, j - lk, cellSizeX, cellSizeZ, clod, cells); SetNeighborLOD(i + lx, j - lk, cellSizeX, cellSizeZ, clod, cells); SetNeighborLOD(i - lx, j + lk, cellSizeX, cellSizeZ, clod, cells); SetNeighborLOD(i + lx, j + lk, cellSizeX, cellSizeZ, clod, cells); } } } } //根据Lod生成Mesh float p = Mathf.Pow(2, maxLod); float dtx = widthX * 2 / cellSizeX / p; float dty = widthZ * 2 / cellSizeZ / p; MeshVertexData cache = new MeshVertexData(cellSizeX * (int)p, cellSizeZ * (int)p, dtx, dty, -widthX, -widthZ); for (int i = 0; i < cellSizeX; i++) { for (int j = 0; j < cellSizeZ; j++) { LodMeshCell cell = cells[i, j]; if (cell.lod == -1) { continue; } int leftLod = i == 0 ? -1 : cells[i - 1, j].lod; int rightLod = i == cells.GetLength(0) - 1 ? -1 : cells[i + 1, j].lod; int downLod = j == 0 ? -1 : cells[i, j - 1].lod; int upLod = j == cells.GetLength(1) - 1 ? -1 : cells[i, j + 1].lod; cell.SetNeighborLOD(leftLod, rightLod, upLod, downLod); cell.UpdateMesh(cache); } } //生成网格 Mesh mesh = cache.Apply(texture, uvDir, samples); return(mesh); }
public virtual void UpdateMesh(MeshVertexData cache) { if (isEdge) { if (m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { m_LeftTopChild.UpdateMesh(cache); if (m_IsRightEdge && !m_IsDownEdge) { AddTopRightTriangle(cache); AddRightTopTriangle(cache); AddRightBottomTriangle(cache); AddBottomTriangle(cache); AddLeftBottomTriangle(cache); } else if (!m_IsRightEdge && m_IsDownEdge) { AddTopRightTriangle(cache); AddRightTriangle(cache); AddBottomRightTriangle(cache); AddBottomLeftTriangle(cache); AddLeftBottomTriangle(cache); } else if (m_IsRightEdge && m_IsDownEdge) { AddTopRightTriangle(cache); AddRightTopTriangle(cache); AddRightBottomTriangle(cache); AddBottomRightTriangle(cache); AddBottomLeftTriangle(cache); AddLeftBottomTriangle(cache); } else { AddBottomTriangle(cache); AddRightTriangle(cache); AddLeftBottomTriangle(cache); AddTopRightTriangle(cache); } } else if (!m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { m_RightTopChild.UpdateMesh(cache); if (m_IsLeftEdge && !m_IsDownEdge) { AddTopLeftTriangle(cache); AddLeftTopTriangle(cache); AddLeftBottomTriangle(cache); AddBottomTriangle(cache); AddRightBottomTriangle(cache); } else if (!m_IsLeftEdge && m_IsDownEdge) { AddTopLeftTriangle(cache); AddLeftTriangle(cache); AddBottomLeftTriangle(cache); AddBottomRightTriangle(cache); AddRightBottomTriangle(cache); } else if (m_IsLeftEdge && m_IsDownEdge) { AddTopLeftTriangle(cache); AddLeftTopTriangle(cache); AddLeftBottomTriangle(cache); AddBottomLeftTriangle(cache); AddBottomRightTriangle(cache); AddRightBottomTriangle(cache); } else { AddLeftTriangle(cache); AddBottomTriangle(cache); AddTopLeftTriangle(cache); AddRightBottomTriangle(cache); } } else if (!m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && m_RightBottomChild.isEdge) { m_RightBottomChild.UpdateMesh(cache); if (m_IsUpEdge && !m_IsLeftEdge) { AddLeftTriangle(cache); AddTopLeftTriangle(cache); AddTopRightTriangle(cache); AddBottomLeftTriangle(cache); AddRightTopTriangle(cache); } else if (!m_IsUpEdge && m_IsLeftEdge) { AddLeftTopTriangle(cache); AddTopTriangle(cache); AddLeftBottomTriangle(cache); AddBottomLeftTriangle(cache); AddRightTopTriangle(cache); } else if (m_IsUpEdge && m_IsLeftEdge) { AddLeftTopTriangle(cache); AddTopLeftTriangle(cache); AddTopRightTriangle(cache); AddBottomLeftTriangle(cache); AddRightTopTriangle(cache); AddLeftBottomTriangle(cache); } else { AddLeftTriangle(cache); AddTopTriangle(cache); AddBottomLeftTriangle(cache); AddRightTopTriangle(cache); } } else if (!m_LeftTopChild.isEdge && m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { m_LeftBottomChild.UpdateMesh(cache); if (!m_IsUpEdge && m_IsRightEdge) { AddTopTriangle(cache); AddLeftTopTriangle(cache); AddRightTopTriangle(cache); AddRightBottomTriangle(cache); AddBottomRightTriangle(cache); } else if (m_IsUpEdge && !m_IsRightEdge) { AddLeftTopTriangle(cache); AddTopLeftTriangle(cache); AddTopRightTriangle(cache); AddRightTriangle(cache); AddBottomRightTriangle(cache); } else if (m_IsUpEdge && m_IsRightEdge) { AddLeftTopTriangle(cache); AddTopLeftTriangle(cache); AddTopRightTriangle(cache); AddRightTopTriangle(cache); AddRightBottomTriangle(cache); AddBottomRightTriangle(cache); } else { AddTopTriangle(cache); AddRightTriangle(cache); AddLeftTopTriangle(cache); AddBottomRightTriangle(cache); } } else if (m_LeftTopChild.isEdge && m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { m_LeftTopChild.UpdateMesh(cache); m_LeftBottomChild.UpdateMesh(cache); if (m_IsRightEdge) { AddTopRightTriangle(cache); AddBottomRightTriangle(cache); AddRightTopTriangle(cache); AddRightBottomTriangle(cache); } else { AddTopRightTriangle(cache); AddBottomRightTriangle(cache); AddRightTriangle(cache); } } else if (m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { m_LeftTopChild.UpdateMesh(cache); m_RightTopChild.UpdateMesh(cache); if (m_IsDownEdge) { AddLeftBottomTriangle(cache); AddRightBottomTriangle(cache); AddBottomLeftTriangle(cache); AddBottomRightTriangle(cache); } else { AddLeftBottomTriangle(cache); AddRightBottomTriangle(cache); AddBottomTriangle(cache); } } else if (!m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && m_RightTopChild.isEdge && m_RightBottomChild.isEdge) { m_RightTopChild.UpdateMesh(cache); m_RightBottomChild.UpdateMesh(cache); if (m_IsLeftEdge) { AddTopLeftTriangle(cache); AddBottomLeftTriangle(cache); AddLeftTopTriangle(cache); AddLeftBottomTriangle(cache); } else { AddTopLeftTriangle(cache); AddBottomLeftTriangle(cache); AddLeftTriangle(cache); } } else if (!m_LeftTopChild.isEdge && m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && m_RightBottomChild.isEdge) { m_LeftBottomChild.UpdateMesh(cache); m_RightBottomChild.UpdateMesh(cache); if (m_IsUpEdge) { AddLeftTopTriangle(cache); AddRightTopTriangle(cache); AddTopLeftTriangle(cache); AddTopRightTriangle(cache); } else { AddLeftTopTriangle(cache); AddRightTopTriangle(cache); AddTopTriangle(cache); } } else if (!m_LeftTopChild.isEdge && !m_LeftBottomChild.isEdge && !m_RightTopChild.isEdge && !m_RightBottomChild.isEdge) { if (!m_IsLeftEdge && !m_IsRightEdge && !m_IsUpEdge && !m_IsDownEdge) { m_LeftBottomChild.UpdateMesh(cache); m_LeftTopChild.UpdateMesh(cache); m_RightBottomChild.UpdateMesh(cache); m_RightTopChild.UpdateMesh(cache); } else { if (m_IsLeftEdge) { AddLeftTopTriangle(cache); AddLeftBottomTriangle(cache); } else { AddLeftTriangle(cache); } if (m_IsUpEdge) { AddTopLeftTriangle(cache); AddTopRightTriangle(cache); } else { AddTopTriangle(cache); } if (m_IsRightEdge) { AddRightTopTriangle(cache); AddRightBottomTriangle(cache); } else { AddRightTriangle(cache); } if (m_IsDownEdge) { AddBottomLeftTriangle(cache); AddBottomRightTriangle(cache); } else { AddBottomTriangle(cache); } } } else { m_LeftBottomChild.UpdateMesh(cache); m_LeftTopChild.UpdateMesh(cache); m_RightBottomChild.UpdateMesh(cache); m_RightTopChild.UpdateMesh(cache); } } else { if (!m_IsLeftEdge && !m_IsRightEdge && !m_IsUpEdge && !m_IsDownEdge) { AddQuad(cache); } else { if (m_IsLeftEdge) { AddLeftTopTriangle(cache); AddLeftBottomTriangle(cache); } else { AddLeftTriangle(cache); } if (m_IsUpEdge) { AddTopLeftTriangle(cache); AddTopRightTriangle(cache); } else { AddTopTriangle(cache); } if (m_IsRightEdge) { AddRightTopTriangle(cache); AddRightBottomTriangle(cache); } else { AddRightTriangle(cache); } if (m_IsDownEdge) { AddBottomLeftTriangle(cache); AddBottomRightTriangle(cache); } else { AddBottomTriangle(cache); } } } }
public override void UpdateMesh(MeshVertexData cache) { this.AddQuad(cache); }