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);
    }
Example #2
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;
        }
    }