public List <Vector3> GetSegmentStartList(Vector3 normDirectionVector) { List <Vector3> heights = new List <Vector3>(); Vector3 locSc = this.gameObject.transform.localScale; float startHeight = 0; heights.Add(new Vector3(0, 0, 0)); 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) * _size.y; startHeight += height; Vector3 heightVec = new Vector3(locSc.x * normDirectionVector.x * startHeight, locSc.y * normDirectionVector.y * startHeight, locSc.z * normDirectionVector.z * startHeight); heights.Add(heightVec); } return(heights); }
public override bool TryGetPosForItemIndex(int itemIndex, out Vector3 pos) { pos = Vector3.zero; if (itemIndex < _presenter.SelectedMinItem || itemIndex >= _presenter.SelectedMaxItem) { return(false); } int dimNum = _presenter.NumberOfDimensions; var zoomArea = _zoomMax - ZoomMin; float valueX = VisViewHelper.GetItemValue(_presenter, 0, itemIndex, true, _displayRelativeValues); float valueY = VisViewHelper.GetItemValue(_presenter, 1, itemIndex, true, _displayRelativeValues); float valueZ = dimNum < 3 ? 0 : VisViewHelper.GetItemValue(_presenter, 2, itemIndex, true, _displayRelativeValues); if (valueX < _zoomMin.x || valueX > _zoomMax.x || valueY < _zoomMin.y || valueY > _zoomMax.y || (dimNum > 2 && (valueZ < _zoomMin.z || valueZ > _zoomMax.z)) ) { return(false); } pos = new Vector3( (valueX - _zoomMin.x) / zoomArea.x * _size.x, (valueY - _zoomMin.y) / zoomArea.y * _size.y, (valueZ - _zoomMin.z) / zoomArea.z * _size.z ); return(true); }
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; } 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 RebuildAxes() { if (_axisViews == null || _fromEditor) { SetupInitialAxisViews(); } List <AxisTick> ticks = new List <AxisTick>(); var segmentStartList = GetSegmentStartList(new Vector3(1f, 0f, 0f)); ticks.Add(new AxisTick(0, "0")); float oldValue = 0; for (int index = 1; index < segmentStartList.Count; index++) { if (_useMinIndex) { float newValue = oldValue + VisViewHelper.GetItemValueAbsolute(_presenter, index - 1, _presenter.SelectedMinItem); ticks.Add(new AxisTick(segmentStartList[index].x / _axisViews[0].Length, newValue.ToString())); oldValue = newValue; } else { float newValue = oldValue + VisViewHelper.GetItemValueAbsolute(_presenter, index - 1, _valueIndex); ticks.Add(new AxisTick(segmentStartList[index].x / _axisViews[0].Length, newValue.ToString())); oldValue = newValue; } } //TODO: Find way to determine name of axis _axisViews[0].RebuildAxis(ticks.ToArray()); }
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; } List <Vector3> points = new List <Vector3>(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; float max = VisViewHelper.GetGlobalMaximum(_presenter); int dimNum = _presenter.NumberOfDimensions; for (int itemIndex = offset; itemIndex < length; itemIndex++) { float x = VisViewHelper.GetItemValueAbsolute(_presenter, 1, itemIndex, true) * _size.x; float y = VisViewHelper.GetItemValueAbsolute(_presenter, 0, itemIndex, true) * _size.y; if (_presenter.AxisPresenters[0].IsCategorical) { y = ((float)itemIndex / (float)length) * _size.y; } points.Add(new Vector3(x, y, 0)); Debug.Log(points[points.Count - 1]); } Debug.Log("points " + points.Count); Mesh mesh = CreateGeometry(points.ToArray(), _segments, false, true, _style, _usedCategorical, _dimIndex); mesh.name = "RotationalMesh"; var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; if (this.gameObject.transform.Find("innerSide") != null) { GameObject objToDestroy = this.gameObject.transform.Find("innerSide").gameObject; Destroy(objToDestroy); #if UNITY_EDITOR DestroyImmediate(objToDestroy); #endif } GameObject innerSide = new GameObject("innerSide"); innerSide.transform.SetParent(this.gameObject.transform); innerSide.transform.localPosition = Vector3.zero; innerSide.layer = this.gameObject.layer; innerSide.transform.localRotation = Quaternion.Euler(0, 0, 0); var mfis = innerSide.AddComponent <MeshFilter>(); var mris = innerSide.AddComponent <MeshRenderer>(); mfis.sharedMesh = CreateGeometry(points.ToArray(), _segments, false, false, _style, _usedCategorical, _dimIndex); mris.material = GetComponent <MeshRenderer>().material; }
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 < 2) { Debug.LogError("Presenter is either null or has not enough dimensions to represent this visualization"); return; } List <Vector3> vertices = new List <Vector3>(); List <int> indices = new List <int>(); List <Color> colors = new List <Color>(); //int offset = (int)_presenter.SelectedMinItem; //int length = (int)_presenter.SelectedMaxItem - offset; int dimNum = _presenter.NumberOfDimensions; var zoomArea = _zoomMax - ZoomMin; for (int itemIndex = _presenter.SelectedMinItem; itemIndex < _presenter.SelectedMaxItem; itemIndex++) { float valueX = VisViewHelper.GetItemValue(_presenter, 0, itemIndex, true, _displayRelativeValues); float valueY = VisViewHelper.GetItemValue(_presenter, 1, itemIndex, true, _displayRelativeValues); float valueZ = dimNum < 3 ? 0 : VisViewHelper.GetItemValue(_presenter, 2, itemIndex, true, _displayRelativeValues); if (valueX < _zoomMin.x || valueX > _zoomMax.x || valueY < _zoomMin.y || valueY > _zoomMax.y || (dimNum > 2 && (valueZ < _zoomMin.z || valueZ > _zoomMax.z)) ) { continue; } vertices.Add(new Vector3( (valueX - _zoomMin.x) / zoomArea.x * _size.x, (valueY - _zoomMin.y) / zoomArea.y * _size.y, (valueZ - _zoomMin.z) / zoomArea.z * _size.z )); colors.Add(_style.GetColorContinous(_presenter.IsItemHighlighted(itemIndex), valueX, valueY, valueZ)); indices.Add(vertices.Count - 1); } var mesh = new Mesh(); mesh.name = "ScatterplotMesh"; mesh.vertices = vertices.ToArray(); mesh.colors = colors.ToArray(); mesh.SetIndices(indices.ToArray(), MeshTopology.Points, 0); var meshFilter = GetComponent <MeshFilter>(); Destroy(meshFilter.sharedMesh); meshFilter.sharedMesh = mesh; }
protected virtual void ToggleHighlight(RaycastHit hit) { int offset = _presenter.SelectedMinItem; int length = _presenter.SelectedMaxItem - offset; var pos = transform.InverseTransformPoint(hit.point); int index = (int)(pos.x / _visualization.Size.x * length) + offset; float value = VisViewHelper.GetItemValueAbsolute(_presenter, 1, index, true); if (pos.y < value * _visualization.Size.y) { _presenter.ToogleItemHighlight(index); } //Debug.Log("itemIndex=" + index + ", value=" + value + ", pos.y=" + pos.y + ", nPos.y=" + (pos.y / _visualization.Size.y)); }
public override bool TryGetPosForItemIndex(int itemIndex, out Vector3 pos) { pos = Vector3.zero; if (itemIndex < _presenter.SelectedMinItem || itemIndex >= _presenter.SelectedMaxItem) { return(false); } var value = VisViewHelper.GetItemValueAbsolute(_presenter, 1, itemIndex, true); var i = itemIndex - _presenter.SelectedMinItem; int length = _presenter.SelectedItemsCount; float posXStep = _size.x / length; float posXOffset = posXStep * 0.5f; pos = new Vector3(posXOffset + i * posXStep, value * _size.y * 0.5f, 0); return(true); }
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 vertices = new List <Vector3>(); var normals = new List <Vector3>(); var colors = new List <Color>(); var indices = new List <int>(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); 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; vertices.Add(new Vector3(valueX * _size.x, valueY * _size.y, 0.0f)); normals.Add(-Vector3.forward); colors.Add(_style.GetColorCategorical(dimIndex, valueX)); if (itemIndex == 0) { continue; } indices.Add(vertices.Count - 2); indices.Add(vertices.Count - 1); } } var mesh = new Mesh(); mesh.name = "LineChart2DMesh"; mesh.vertices = vertices.ToArray(); mesh.normals = normals.ToArray(); mesh.colors = colors.ToArray(); mesh.SetIndices(indices.ToArray(), MeshTopology.Lines, 0); var meshFilter = GetComponent <MeshFilter>(); meshFilter.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; } 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; }
protected override void RebuildAxes() { if (_axisViews == null || _fromEditor) { SetupInitialAxisViews(); } AxisTick[] ticks; if (_presenter is MultiDimDataPresenter mdp) { ticks = _presenter.AxisPresenters[0].GenerateFromDimension(mdp.CaptionDimension, _presenter.SelectedMinItem, _presenter.SelectedMaxItem); } else { ticks = _presenter.AxisPresenters[0].GenerateFromDiscreteRange(_presenter.SelectedMinItem, _presenter.SelectedMaxItem); } _axisViews[0].RebuildAxis(ticks); ticks = _presenter.AxisPresenters[1].GenerateFromMinMaxValue(0.0f, VisViewHelper.GetGlobalMaximum(_presenter)); _axisViews[1].RebuildAxis(ticks); }
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 vertices = new List <Vector3>(); var normals = new List <Vector3>(); var colors = new List <Color>(); var indices = new List <int>(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); float radius = 0.5f * _size.x; float divisor = 0; //TODO find better way to determine divisor (what 100% is) for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { divisor += VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue; } MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter; float startAngle = 0; for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { vertices.Add(Vector3.zero); normals.Add(-Vector3.forward); float sumOfDim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue; float part = sumOfDim / divisor; colors.Add(_style.GetColorCategorical(dimIndex, part)); float angle = part * Mathf.PI * 2; float endAngle = startAngle + angle; List <Vector3> partMesh = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments); for (int vertex = 1; vertex < partMesh.Count; vertex++) { colors.Add(_style.GetColorCategorical(dimIndex, part)); normals.Add(-Vector3.forward); indices.Add(vertices.Count - 1); indices.Add(vertices.Count + vertex); indices.Add(vertices.Count - 1 + vertex); } colors.Add(_style.GetColorCategorical(dimIndex, part)); normals.Add(-Vector3.forward); startAngle = endAngle; vertices.AddRange(partMesh); } var mesh = new Mesh(); mesh.name = "PieChart2DMesh"; mesh.vertices = vertices.ToArray(); mesh.normals = normals.ToArray(); mesh.colors = colors.ToArray(); mesh.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0); var meshFilter = GetComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; }
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 vertices = new List <Vector3>(); var colors = new List <Color>(); var indices = new List <int>(); int offset = (int)_presenter.SelectedMinItem; int length = (int)_presenter.SelectedMaxItem - offset; float maxValue = VisViewHelper.GetGlobalMaximum(_presenter); float radius = 0.5f * _size.x; float divisor = 0; //TODO find better way to determine divisor (what 100% is) for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { divisor += VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue; } MultiDimDataPresenter presenter = (MultiDimDataPresenter)_presenter; Debug.Log(presenter.CaptionDimension.GetStringValue(ValueIndex)); float startAngle = 0; for (int dimIndex = 0; dimIndex < _presenter.NumberOfDimensions; dimIndex++) { float height = -(VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _3DIndex + offset) / maxValue) * _size.z; vertices.Add(new Vector3(0, 0, height)); int zeroTop = vertices.Count - 1; float sumOfDim = VisViewHelper.GetItemValueAbsolute(_presenter, dimIndex, _valueIndex + offset) / maxValue; float part = sumOfDim / divisor; colors.Add(_style.GetColorCategorical(dimIndex, part)); float angle = part * Mathf.PI * 2; float endAngle = startAngle + angle; List <Vector3> partMeshTop = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments); for (int i = 0; i < partMeshTop.Count; i++) { partMeshTop[i] = new Vector3(partMeshTop[i].x, partMeshTop[i].y, height); } for (int vertex = 1; vertex < partMeshTop.Count; vertex++) { colors.Add(_style.GetColorCategorical(dimIndex, part)); indices.Add(vertices.Count - 1); indices.Add(vertices.Count + vertex); indices.Add(vertices.Count - 1 + vertex); } colors.Add(_style.GetColorCategorical(dimIndex, part)); vertices.AddRange(partMeshTop); vertices.Add(Vector3.zero); int zeroBottom = vertices.Count - 1; colors.Add(_style.GetColorCategorical(dimIndex, part)); List <Vector3> partMeshBottom = Circles.CreatePartMesh(startAngle, endAngle, radius, _segments); for (int vertex = 1; vertex < partMeshBottom.Count; vertex++) { colors.Add(_style.GetColorCategorical(dimIndex, part)); indices.Add(vertices.Count - 1); indices.Add(vertices.Count - 1 + vertex); indices.Add(vertices.Count + vertex); } colors.Add(_style.GetColorCategorical(dimIndex, part)); vertices.AddRange(partMeshBottom); //adding side quads int[] tris = new int[] { zeroTop, zeroTop + 1, zeroBottom + 1, zeroTop, zeroBottom + 1, zeroBottom, zeroTop, vertices.Count - 1, zeroBottom - 1, zeroTop, zeroBottom, vertices.Count - 1 }; indices.AddRange(tris); //adding rounds List <int> round = Circles.CreateRound(vertices.Count - partMeshBottom.Count - partMeshTop.Count - 1, partMeshTop.Count - 1, 1); indices.AddRange(round); startAngle = endAngle; } var mesh = new Mesh(); mesh.name = "PieChart3DMesh"; mesh.vertices = vertices.ToArray(); mesh.colors = colors.ToArray(); mesh.SetIndices(indices.ToArray(), MeshTopology.Triangles, 0); mesh.RecalculateNormals(); var meshFilter = GetComponent <MeshFilter>(); meshFilter.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) { _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; } }