void UpdateMaterials() { int pt = 0; // cursor that increments each time we find a point in the time range int currentSubmap = 0; int oldSubmap = -1; int verticesPerShape = RenderShapeMeshUtils.GetVecticesForShape(m_RenderStyle, m_Projection); GameObject go = null; Material[] materials = null; for (int a = 0; a < m_Data.Length; a++) { if (m_Data[a].time >= m_StartTime && m_Data[a].time <= m_EndTime) { currentSubmap = (pt * verticesPerShape) / k_VerticesPerMesh; if (currentSubmap != oldSubmap) { if (go != null && materials != null) { go.GetComponent <Renderer>().materials = materials; } go = m_GameObjects[currentSubmap]; materials = go.GetComponent <Renderer>().sharedMaterials; } materials = m_Materials; oldSubmap = currentSubmap; pt++; } } if (go != null && materials != null) { go.GetComponent <Renderer>().materials = materials; } }
void CreatePoints() { if (hasData()) { // m_CollapseDensity = 0f; totalPoints = m_Data.Length; currentPoints = 0; var submaps = new List <List <HeatPoint> >(); int currentSubmap = 0; int verticesPerShape = RenderShapeMeshUtils.GetVecticesForShape(m_RenderStyle, m_Projection); // Filter & Aggregate Dictionary <Vector3, HeatPoint> collapsePoints = new Dictionary <Vector3, HeatPoint>(); List <HeatPoint> otherPoints = new List <HeatPoint>(); for (int a = 0; a < m_Data.Length; a++) { // FILTER FOR TIME & POSITION var pt = m_Data[a]; if (FilterPoint(pt)) { if (m_MaskOption == k_RadiusMasking && m_Projection == RenderProjection.FirstPerson && IsOutsideRadius(pt)) { Aggregate(pt, collapsePoints); } else { otherPoints.Add(pt); } } } HeatPoint[] dictData = collapsePoints.Values.ToArray(); HeatPoint[] filteredData = new HeatPoint[dictData.Length + otherPoints.Count]; dictData.CopyTo(filteredData, 0); otherPoints.CopyTo(filteredData, dictData.Length); // Arrange into submaps for (int a = 0; a < filteredData.Length; a++) { var pt = filteredData[a]; currentPoints++; if (submaps.Count <= currentSubmap) { submaps.Add(new List <HeatPoint>()); } submaps[currentSubmap].Add(pt); currentSubmap = (currentPoints * verticesPerShape) / k_VerticesPerMesh; } int neededSubmaps = submaps.Count; int currentSubmaps = m_GameObjects.Count; int addCount = neededSubmaps - currentSubmaps; if (addCount > 0) { // Add submaps if we need more for (int a = 0; a < addCount; a++) { int submapID = currentSubmaps + a; var go = new GameObject("Submap" + submapID); go.AddComponent <HeatmapSubmap>(); go.GetComponent <MeshFilter>().sharedMesh = new Mesh(); go.transform.parent = gameObject.transform; m_GameObjects.Add(go); } } else if (addCount < 0) { // Dispose of excess submaps for (var a = neededSubmaps; a < currentSubmaps; a++) { Transform trans = gameObject.transform.Find("Submap" + a); if (trans != null) { trans.parent = null; m_GameObjects.Remove(trans.gameObject); GameObject.DestroyImmediate(trans.gameObject); } } } //Render submaps for (var a = 0; a < m_GameObjects.Count; a++) { Mesh renderMesh = m_GameObjects[a].GetComponent <MeshFilter>().sharedMesh; renderMesh.Clear(); renderMesh.subMeshCount = submaps[a].Count; RenderSubmap(m_GameObjects[a], submaps[a]); } m_RenderState = k_NotRendering; } }