Exemplo n.º 1
0
    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 RenderMesh()
    {
        if (m_Mesh == null)
        {
            m_Mesh = new Mesh();
        }

        // Draw the shape once
        int[]     tris;
        Vector3[] vectors;
        switch (m_RenderStyle)
        {
        case RenderShape.Cube:
            vectors = RenderShapeMeshUtils.AddCubeVectorsToMesh(m_ParticleSize, 0, 0, 0);
            tris    = RenderShapeMeshUtils.AddCubeTrisToMesh(0);
            break;

        case RenderShape.Arrow:
            vectors = RenderShapeMeshUtils.AddArrowVectorsToMesh(m_ParticleSize, Vector3.zero, Vector3.zero, m_Projection);
            tris    = RenderShapeMeshUtils.AddArrowTrisToMesh(0, m_Projection);
            break;

        case RenderShape.Square:
            vectors = RenderShapeMeshUtils.AddSquareVectorsToMesh(m_ParticleSize, m_RenderDirection, Vector3.zero, Vector3.zero);
            tris    = RenderShapeMeshUtils.AddSquareTrisToMesh(0);
            break;

        case RenderShape.PointToPoint:
            // FIXME: This needs more thinking. Obviously destination isn't fixed.
            // In fact, can we even use do this in the Instanced renderer?
            vectors = RenderShapeMeshUtils.AddP2PVectorsToMesh(m_ParticleSize, Vector3.zero, Vector3.one, false);
            tris    = RenderShapeMeshUtils.AddP2PTrisToMesh(0, false);
            break;

        case RenderShape.Triangle:
        default:
            vectors = RenderShapeMeshUtils.AddTriVectorsToMesh(m_ParticleSize, m_RenderDirection, Vector3.zero, Vector3.zero);
            tris    = RenderShapeMeshUtils.AddTriTrisToMesh(0);
            break;
        }

        // write
        m_Mesh.Clear();
        m_Mesh.vertices = vectors;
        m_Mesh.SetTriangles(tris, 0);
    }
Exemplo n.º 3
0
    void RenderSubmap(GameObject go, List <HeatPoint> submap)
    {
        var allTris    = new List <int[]>();
        var allVectors = new List <Vector3[]>();
        var allColors  = new List <Color32[]>();

        Vector3[] vector3   = null;
        var       materials = new Material[submap.Count];

        for (int a = 0; a < submap.Count; a++)
        {
            materials[a] = m_Materials[0];
            Vector3 position    = submap[a].position;
            Vector3 rotation    = submap[a].rotation;
            Vector3 destination = submap[a].destination;

            switch (m_RenderStyle)
            {
            case RenderShape.Cube:
                vector3 = RenderShapeMeshUtils.AddCubeVectorsToMesh(m_ParticleSize, position.x, position.y, position.z);
                allVectors.Add(vector3);
                allTris.Add(RenderShapeMeshUtils.AddCubeTrisToMesh(a * vector3.Length));
                break;

            case RenderShape.Arrow:
                if (m_MaskOption == k_RadiusMasking && m_Projection == RenderProjection.FirstPerson && IsOutsideRadius(submap[a]))
                {
                    vector3 = RenderShapeMeshUtils.AddDiamondVectorsToMesh(m_ParticleSize, RenderDirection.Billboard, position, m_MaskSource);
                    allVectors.Add(vector3);
                    allTris.Add(RenderShapeMeshUtils.AddArrowTrisToMesh(a * vector3.Length, m_Projection));
                }
                else
                {
                    vector3 = RenderShapeMeshUtils.AddArrowVectorsToMesh(m_ParticleSize, position, rotation, m_Projection);
                    allVectors.Add(vector3);
                    allTris.Add(RenderShapeMeshUtils.AddArrowTrisToMesh(a * vector3.Length, m_Projection));
                }
                break;

            case RenderShape.Square:
                vector3 = RenderShapeMeshUtils.AddSquareVectorsToMesh(m_ParticleSize, m_RenderDirection, position, m_MaskSource);
                allVectors.Add(vector3);
                allTris.Add(RenderShapeMeshUtils.AddSquareTrisToMesh(a * vector3.Length));
                break;

            case RenderShape.Triangle:
                vector3 = RenderShapeMeshUtils.AddTriVectorsToMesh(m_ParticleSize, m_RenderDirection, position, m_MaskSource);
                allVectors.Add(vector3);
                allTris.Add(RenderShapeMeshUtils.AddTriTrisToMesh(a * vector3.Length));
                break;

            case RenderShape.PointToPoint:
                var collapsed = m_MaskOption == k_RadiusMasking && m_Projection == RenderProjection.FirstPerson && IsOutsideRadius(submap[a]);
                vector3 = RenderShapeMeshUtils.AddP2PVectorsToMesh(m_ParticleSize, position, destination, collapsed);
                allVectors.Add(vector3);
                allTris.Add(RenderShapeMeshUtils.AddP2PTrisToMesh(a * vector3.Length, collapsed));
                break;
            }
            allColors.Add(AddColorsToMesh(vector3.Length, submap[a]));
        }
        Vector3[] combinedVertices = allVectors.SelectMany(x => x).ToArray <Vector3>();
        Mesh      mesh             = go.GetComponent <MeshFilter>().sharedMesh;

        mesh.vertices = combinedVertices;
        mesh.colors32 = allColors.SelectMany(x => x).ToArray <Color32>();

        for (int j = 0; j < allTris.Count; j++)
        {
            int[] t = allTris[j];
            mesh.SetTriangles(t, j);
        }
        go.GetComponent <Renderer>().materials                = materials;
        go.GetComponent <HeatmapSubmap>().m_PointData         = submap;
        go.GetComponent <HeatmapSubmap>().m_TrianglesPerShape = RenderShapeMeshUtils.GetTrianglesForShape(m_RenderStyle, m_Projection);
        //mesh.Optimize();

        if (m_Tips)
        {
            if (go.GetComponent <MeshCollider>() == null)
            {
                go.AddComponent <MeshCollider>();
            }

            go.GetComponent <MeshCollider>().sharedMesh = mesh;
        }
    }
Exemplo n.º 4
0
    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;
        }
    }