/// <summary> /// Rebuilds the axis based on the specified list of ticks. /// </summary> /// <param name="ticks">The list of ticks representing the topology of the axis.</param> /// <param name="axisLabel">The label shown for the whole axis.</param> public void RebuildAxis(AxisTick[] ticks, string axisLabel = null) { var meshFilter = GetComponent <MeshFilter>(); var canvasScale = _labelCanvas.transform.localScale; _invCanvasScale = new Vector3(1.0f / canvasScale.x, 1.0f / canvasScale.y, 1.0f / canvasScale.z); _axisRoot.localScale = new Vector3(_length, 1, 1); // set the canvas to the same size as the axis. Technically, there is no need to, but it looks nicer in the editor. _labelCanvas.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _length * _invCanvasScale.x); // Remove all previous labels for (int i = _labelCanvas.transform.childCount - 1; i >= 0; i--) { DestroyImmediate(_labelCanvas.transform.GetChild(i).gameObject); } // Create new Ticks & Labels var iMesh = new IntermediateMesh(); for (int i = 0; i < ticks.Length; i++) { CreateSingleTick(iMesh, ticks[i]); if (ticks[i].HasLabel) { CreateSingleLabel(ticks[i]); } } if (_hasAxisLabel) { CreateAxisLabel(axisLabel); } GameObject.Destroy(meshFilter.sharedMesh); meshFilter.sharedMesh = iMesh.GenerateMesh("AxisTicksMesh", MeshTopology.Lines); }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 2) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } var iMesh = new IntermediateMesh(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; for (int itemIndex = 0; itemIndex < length; itemIndex++) { for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { float pos_x = (float)dimIndex / _presenter.NumberOfDimensions; //Debug.Log(dimIndex + ", " + (itemIndex + offset)); float pos_y = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, itemIndex + offset, true); iMesh.Vertices.Add(new Vector3(pos_x * _size.x, pos_y * _size.y, 0.0f)); iMesh.Normals.Add(-Vector3.forward); iMesh.Colors.Add(_style.GetColorCategorical(itemIndex, pos_x)); if (dimIndex == 0) { continue; } iMesh.Indices.Add(iMesh.Vertices.Count - 2); iMesh.Indices.Add(iMesh.Vertices.Count - 1); } } var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = iMesh.GenerateMesh("ParallelCoordinatesMesh", MeshTopology.Lines); }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 1) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } var iMesh = new IntermediateMesh(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); float step = 1.0f / _presenter.NumberOfDimensions; for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { for (int itemIndex = 0; itemIndex < length; itemIndex++) { float valueX = (float)itemIndex / length; float valueY = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, itemIndex + offset) / maxValue; float valueZ = dimIndex * step + (0.5f * step); iMesh.Vertices.Add(new Vector3(valueX * _size.x, valueY * _size.y, valueZ * _size.z)); iMesh.Normals.Add(-Vector3.forward); iMesh.Colors.Add(_style.GetColorCategorical(dimIndex, valueX)); if (itemIndex == 0) { continue; } iMesh.Indices.Add(iMesh.Vertices.Count - 2); iMesh.Indices.Add(iMesh.Vertices.Count - 1); } } var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = iMesh.GenerateMesh("LineChart2DMesh", MeshTopology.Lines); }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 2) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } if (_dataItemMesh == null) { Debug.LogError("No DataMesh was set for this visualization."); return; } var iMesh = new IntermediateMesh(); // temporary save the mesh data from the template for faster access var tVertices = _dataItemMesh.vertices; var tNromals = _dataItemMesh.normals; var tUVs = _dataItemMesh.uv; var tIndices = _dataItemMesh.triangles; int offset = _presenter.SelectedMinItem; int length = _presenter.SelectedItemsCount; float posXStep = _size.x / length; float posXOffset = posXStep * 0.5f; float uStep = 1.0f / length; float uOffset = uStep * 0.5f; for (int i = 0; i < length; i++) { int itemIndex = i + offset; var value = VisViewHelper.GetItemValueAbsolute(_presenter, 1, itemIndex, true); var pos = new Vector3(posXOffset + i * posXStep, 0, 0); var scale = new Vector3(posXStep * _barThickness, value * _size.y, _size.z); var startIndex = iMesh.Vertices.Count; var color = _style.GetColorContinous(_presenter.IsItemHighlighted(itemIndex), uOffset + uStep * i); foreach (var v in tVertices) { iMesh.Vertices.Add(new Vector3(pos.x + v.x * scale.x, pos.y + v.y * scale.y, pos.z + v.z * scale.z)); iMesh.Colors.Add(color); } iMesh.Normals.AddRange(tNromals); iMesh.TexCoords.AddRange(tUVs); foreach (var j in tIndices) { iMesh.Indices.Add(startIndex + j); } } var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = iMesh.GenerateMesh("BarChart2DMesh", MeshTopology.Triangles); }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 3) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } var iMesh = new IntermediateMesh(); int offset = _presenter.SelectedMinItem; int length = _presenter.SelectedItemsCount; float posXStep = _size.x / length; float posZStep = _size.z / _presenter.NumberOfDimensions; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); float uStep = 1.0f / length; float vStep = 1.0f / _presenter.NumberOfDimensions; for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { for (int itemIndex = 0; itemIndex < length; itemIndex++) { float value = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, itemIndex + offset) / maxValue; var pos = new Vector3(posXStep * itemIndex, value, posZStep * dimIndex); iMesh.Vertices.Add(new Vector3(pos.x * _size.x, pos.y * _size.y, pos.z * _size.z)); iMesh.Colors.Add(_style.GetColorContinous(uStep * itemIndex, vStep * dimIndex)); if (itemIndex < 1 || dimIndex < 1) { continue; } iMesh.Indices.Add(dimIndex * length + itemIndex); iMesh.Indices.Add((dimIndex - 1) * length + itemIndex - 1); iMesh.Indices.Add(dimIndex * length + itemIndex - 1); iMesh.Indices.Add(dimIndex * length + itemIndex); iMesh.Indices.Add((dimIndex - 1) * length + itemIndex); iMesh.Indices.Add((dimIndex - 1) * length + itemIndex - 1); } } var mesh = iMesh.GenerateMesh("HeightmapMesh", MeshTopology.Triangles); mesh.RecalculateNormals(); var meshFilter = GetComponent <MeshFilter>(); Destroy(meshFilter.sharedMesh); meshFilter.sharedMesh = mesh; }
/// <summary> /// Creates a single tick line for the axis. /// </summary> /// <param name="iMesh">The intermediate mesh holding the components for the final mesh.</param> /// <param name="tick">The tick data.</param> protected void CreateSingleTick(IntermediateMesh iMesh, AxisTick tick) { float posX = tick.Position * _length; if (_mirrored) { posX = _length - posX; } float posY = _tickLength; if (!_swapped) { posY *= -1; } iMesh.Vertices.Add(new Vector3(posX, 0, 0)); iMesh.Vertices.Add(new Vector3(posX, posY, 0)); iMesh.Normals.Add(-Vector3.forward); iMesh.Normals.Add(-Vector3.forward); iMesh.Colors.Add(Color.white); iMesh.Colors.Add(Color.white); iMesh.Indices.Add(iMesh.Vertices.Count - 2); iMesh.Indices.Add(iMesh.Vertices.Count - 1); }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 3) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } if (_dataItemMesh == null) { _dataItemMesh = buildCircleMesh(); Debug.Log("No DataMesh was set for this visualization. Using default"); } var iMesh = new IntermediateMesh(); // temporary save the mesh data from the template for faster access var tVertices = _dataItemMesh.vertices; var tNromals = _dataItemMesh.normals; var tUVs = _dataItemMesh.uv; var tIndices = _dataItemMesh.triangles; //int offset = _presenter.SelectedMinItem; float divisor = 0; MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter; //TODO find better way to determine divisor (what 100% is) for (int valueIndex = 0; valueIndex < presenter[1].Count; valueIndex++) { float sum = 0; for (int dimIndex = 0; dimIndex < presenter.NumberOfDimensions; dimIndex++) { sum += VisViewHelper.GetItemValueAbsolute(presenter, dimIndex, valueIndex); } divisor = Mathf.Max(divisor, sum); //Debug.Log("Div " + divisor); } float startHeight = 0; _divisor = divisor; //Debug.Log(presenter.CaptionDimension.GetStringValue(ValueIndex)); for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { float dim; if (_useMinIndex) { dim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _presenter.SelectedMinItem); } else { dim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex); } float height = dim / divisor; //Debug.Log(presenter[dimIndex].Name + " height " + height+ " dim " + dim +" div " + divisor); //var pos = new Vector3(0, startHeight * _size.y, 0); var scale = new Vector3(_size.x, height * _size.y, _size.z); var startIndex = iMesh.Vertices.Count; foreach (var v in tVertices) { var vPos = new Vector3(v.x * scale.x, startHeight * _size.y + v.y * scale.y, v.z * scale.z); iMesh.Vertices.Add(vPos); iMesh.Colors.Add(_style.GetColorCategorical(dimIndex, height)); } iMesh.Normals.AddRange(tNromals); iMesh.TexCoords.AddRange(tUVs); foreach (var index in tIndices) { iMesh.Indices.Add(startIndex + index); } startHeight += height; } var mesh = iMesh.GenerateMesh("StackedBarMesh", MeshTopology.Triangles); var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; var meshCollider = GetComponent <MeshCollider>(); if (meshCollider != null) { meshCollider.sharedMesh = mesh; } }
protected override void RebuildVisualization() { if (_presenter == null || _presenter.NumberOfDimensions < 3) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } if (_dataItemMesh == null) { Debug.LogError("No DataMesh was set for this visualization."); return; } var iMesh = new IntermediateMesh(); // temporary save the mesh data from the template for faster access var tVertices = _dataItemMesh.vertices; var tNromals = _dataItemMesh.normals; var tUVs = _dataItemMesh.uv; var tIndices = _dataItemMesh.triangles; int offset = _presenter.SelectedMinItem; int length = _presenter.SelectedItemsCount; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); float posXStep = _size.x / length; float posXOffset = posXStep * 0.5f; float posZStep = _size.z / _presenter.NumberOfDimensions; float posZOffset = posZStep * 0.5f; float uStep = 1.0f / length; float uOffset = uStep * 0.5f; float vStep = 1.0f / _presenter.NumberOfDimensions; float vOffset = vStep * 0.5f; //TODO: UV coords of mesh based on height to add grid lines for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { for (int itemIndex = 0; itemIndex < length; itemIndex++) { float value = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, itemIndex + offset) / maxValue; var pos = new Vector3(posXOffset + posXStep * itemIndex, 0, posZOffset + posZStep * dimIndex); var scale = new Vector3(posXStep * _barThickness.x, value * _size.y, posZStep * _barThickness.y); var startIndex = iMesh.Vertices.Count; foreach (var v in tVertices) { var vPos = new Vector3(pos.x + v.x * scale.x, pos.y + v.y * scale.y, pos.z + v.z * scale.z); iMesh.Vertices.Add(vPos); iMesh.Colors.Add(_style.GetColorContinous(_presenter.IsItemHighlighted(itemIndex), uOffset + uStep * itemIndex, vOffset + vStep * dimIndex, vPos.y)); } iMesh.Normals.AddRange(tNromals); iMesh.TexCoords.AddRange(tUVs); foreach (var index in tIndices) { iMesh.Indices.Add(startIndex + index); } } } var mesh = iMesh.GenerateMesh("BarChart3DMesh", MeshTopology.Triangles); var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; // TODO Move this into separate class var meshCollider = GetComponent <MeshCollider>(); if (meshCollider != null) { meshCollider.sharedMesh = mesh; } }