/// <summary> /// CombineMesh : conbine destination mesh into current mesh. /// <summary> public void CombineGeometry(GeometryBuffer geometryBuffer) { if (null == geometryBuffer) { throw new UChartGeometryException("geometryBuffer is null."); } int vertexIndexHead = m_vertices.Count; foreach (var vertex in geometryBuffer.vertices) { this.m_vertices.Add(vertex); } foreach (var color in geometryBuffer.colors) { this.m_colors.Add(color); } foreach (var uv in geometryBuffer.uvs) { this.m_uvs.Add(uv); } for (var i = 0; i < geometryBuffer.indices.Length; i++) { this.m_indices.Add(vertexIndexHead + geometryBuffer.indices[i]); } }
public override void OnDrawArrow() { GameObject arrow = new GameObject("__AXISARROW__"); arrow.hideFlags = HideFlags.HideInHierarchy; arrow.transform.SetParent(this.myTransform); var meshFilter = arrow.AddComponent <MeshFilter>(); var meshRenderer = arrow.AddComponent <MeshRenderer>(); GeometryBuffer geometryBuffer = new GeometryBuffer(); Mesh arrowMesh = new Mesh(); arrowMesh.name = "__AXIS3DARROW__"; // FIXME: // geometryBuffer.FillMesh(arrowMesh); vIndex = 0; int vertexCount = (arrowSmooth + 2) * 3; aVertices = new Vector3[vertexCount]; aColors = new Color[vertexCount]; aIndices = new int[arrowSmooth * 6 * 3]; Vector3 xBottom = transform.right * axisLenght * 1.1f; Vector3 xTop = xBottom + transform.right * arrowSize * 2; Vector3 yBottom = transform.up * axisLenght * 1.1f; Vector3 yTop = yBottom + transform.up * arrowSize * 2; Vector3 zBottom = transform.forward * axisLenght * 1.1f; Vector3 zTop = zBottom + transform.forward * arrowSize * 2; DrawCone(transform.right, xBottom, xTop, xArrowColor); DrawCone(transform.up, yBottom, yTop, yArrowColor); DrawCone(transform.forward, zBottom, zTop, zArrowColor); // vertices arrowMesh.vertices = aVertices; // colors arrowMesh.colors = aColors; // indices arrowMesh.SetIndices(aIndices, MeshTopology.Triangles, 0); arrowMesh.RecalculateNormals(); meshFilter.mesh = arrowMesh; meshRenderer.material = new Material(Shader.Find("UChart/Axis/AxisArrow(Basic)")); coneIndex = 0; }
private void DrawPerBarchart(int xCount, int yCount, int xArrayIndex, int yArrayIndex, Vector3 startPos, MeshFilter meshFilter) { float halfWidth = barWidth / 2.0f; Mesh mesh = new Mesh(); mesh.name = "__submesh__"; GeometryBuffer buffer = new GeometryBuffer(); for (int x = 0; x < xCount; x++) { for (int y = 0; y < yCount; y++) { var pos = startPos + new Vector3(halfWidth + (x - 1) * barWidth + (x - 1) * barOffset, 0, halfWidth + (y - 1) * barWidth + (y - 1) * barOffset); CubeGeometry cube = new CubeGeometry(); cube.center = pos; cube.length = barWidth; cube.width = barWidth; if (null != colors) { cube.color = colors[xArrayIndex + x, yArrayIndex + y]; } cube.height = baseHeight + datas[xArrayIndex + x, yArrayIndex + y]; cube.anchor = GeometryAnchor.Bottom; cube.FillGeometry(); buffer.CombineGeometry(cube.geometryBuffer); } } buffer.FillMesh(mesh, MeshTopology.Triangles); mesh.RecalculateNormals(); mesh.RecalculateTangents(); if (drawOutline) { buffer.FillMesh(mesh, MeshTopology.Lines); } meshFilter.mesh = mesh; }