Beispiel #1
0
    public void BuildGut(string inputPath)
    {
        Debug.Log(inputPath);
        pointList = FastCSVReader.Read(inputPath);
        //Log to console
        Debug.Log(pointList);

        // Declare list of strings, fill with keys (column names)
        List <string> columnList = new List <string>(pointList[1].Keys);

        // Print number of keys (using .count)
        Debug.Log("There are " + columnList.Count + " columns in the CSV");

        foreach (string key in columnList)
        {
            Debug.Log("Column name is " + key);
        }

        // Assign column name from columnList to Name variables
        clusterNumberName = columnList[columnClusterNumber];
        xName             = columnList[columnX];
        yName             = columnList[columnY];
        zName             = columnList[columnZ];

        //Get max value of clusters, with assumption that integer increments and so 1-max is the number of things
        int numClusters = (int)FindMaxValue(clusterNumberName);


        // Get maxes of each axis
        float xMax = FindMaxValue(xName);
        float yMax = FindMaxValue(yName);
        float zMax = FindMaxValue(zName);

        // Get minimums of each axis
        float xMin = FindMinValue(xName);
        float yMin = FindMinValue(yName);
        float zMin = FindMinValue(zName);

        //Loop through cluster numbers, to keep meshes aligned
        // For every one layer, so same z, remove all ones besides the top and bottom points before using the pointlist
        // Excluding those with the first and last z values for a given cluster
        for (var j = 0; j < numClusters; j++)
        {
            // Create a child GameObject to attach a mesh to, easier to split up and more likely to be composable
            GameObject instance = Instantiate(microbe);
            instance.transform.position = new Vector3(0, 0, 0);
            //Loop through Pointlist
            for (var i = 0; i < pointList.Count; i++)
            {
                // Check if meets the criteria of cluster name
                if (System.Convert.ToSingle(pointList[i][clusterNumberName]) == j)
                {
                    float x = pointList[i][xName];
                    float y = pointList[i][yName] - yMin + 1;
                    float z = pointList[i][zName];

                    meshPoints.Add(new Vector3(x * 6 * plotScale, y * plotScale, z * plotScale));
                }
            }
            // Need to split based on cluster number, so different meshes for each
            triangles = CreateTrianglesLine(triangles, meshPoints);
            //Now use the list of Vector3's to make the mesh
            CreateMesh(meshPoints.ToArray(), triangles.ToArray(), instance);
            instance.AddComponent <BoxCollider>();
            // Reset meshPoints = 0 as next cluster is started
            triangles  = new List <int>();
            meshPoints = new List <Vector3>();
        }
    }
Beispiel #2
0
    public void BuildModel(string inputPath)
    {
        Debug.Log(inputPath);
        pointList = FastCSVReader.Read(inputPath);
        //Log to console
        Debug.Log(pointList);

        // Declare list of strings, fill with keys (column names)
        List <string> columnList = new List <string>(pointList[1].Keys);

        // Print number of keys (using .count)
        Debug.Log("There are " + columnList.Count + " columns in the CSV");

        foreach (string key in columnList)
        {
            Debug.Log("Column name is " + key);
        }

        // Assign column name from columnList to Name variables
        clusterNumberName = columnList[columnClusterNumber];
        xName             = columnList[columnX];
        yName             = columnList[columnY];
        zName             = columnList[columnZ];

        //Get max value of clusters, with assumption that integer increments and so 1-max is the number of things
        int numClusters = (int)FindMaxValue(clusterNumberName);


        // Get maxes of each axis
        float xMax = FindMaxValue(xName);
        float yMax = FindMaxValue(yName);
        float zMax = FindMaxValue(zName);

        // Get minimums of each axis
        float xMin = FindMinValue(xName);
        float yMin = FindMinValue(yName);
        float zMin = FindMinValue(zName);

        //Loop through cluster numbers, to keep meshes aligned
        // For every one layer, so same z, remove all ones besides the top and bottom points before using the pointlist
        // Excluding those with the first and last z values for a given cluster
        for (var j = 0; j < numClusters; j++)
        {
            // Create a child GameObject to attach a mesh to, easier to split up and more likely to be composable
            GameObject instance = Instantiate(microbe);
            instance.transform.position = new Vector3(0, 0, 0);
            //Loop through Pointlist
            for (var i = 0; i < pointList.Count; i++)
            {
                // Check if meets the criteria of cluster name
                if (System.Convert.ToSingle(pointList[i][clusterNumberName]) == j)
                {
                    float x = pointList[i][xName];
                    float y = pointList[i][yName] - yMin + 1;
                    float z = pointList[i][zName];

                    meshPoints.Add(new Vector3(x * 6 * plotScale, y * plotScale, z * plotScale));
                }

                // Get value in poinList at ith "row", in "column" Name, normalize

                // Instantiate as gameobject variable so that it can be manipulated within loop
                //GameObject dataPoint = Instantiate(
                //        PointPrefab,
                //        new Vector3(x, y, z * 6) * plotScale,
                //        Quaternion.identity);
                //dataPoint.transform.localScale = new Vector3(50 * plotScale, 50 * plotScale, 50 * plotScale);

                // Make child of PointHolder object, to keep points within container in hiearchy
                //dataPoint.transform.parent = PointHolder.transform;

                // Assigns original values to dataPointName
                // string dataPointName =
                //     "Cluster: " + pointList[i][clusterNumberName] + " " +
                //     pointList[i][xName] + " "
                //     + pointList[i][yName] + " "
                //     + pointList[i][zName];

                // Assigns name to the prefab
                //dataPoint.transform.name = dataPointName;

                // Gets material color and sets it to a new RGB color we define
                //dataPoint.GetComponent<Renderer>().material.color =
                //      new Color(j*50 + 0f, 255.0f, z % 255.0f, 1.0f);
                //new Color(x % 255.0f, y % 255.0f, z % 255.0f, 1.0f);
                // Add point to meshPoints
                //TODO: Split meshes up into different clusters
                //meshPoints.Add(new Vector3(x, y, z * 6));
                //Destroy(dataPoint);
            }
            // MeshFilter
            //MeshFilter mf = instance.GetComponent<MeshFilter>();
            // Need to split based on cluster number, so different meshes for each
            triangles = CreateTriangles(triangles, meshPoints);
            //Now use the list of Vector3's to make the mesh
            CreateMesh(meshPoints.ToArray(), triangles.ToArray(), instance);
            instance.AddComponent <BoxCollider>();
            // Reset meshPoints = 0 as next cluster is started
            triangles  = new List <int>();
            meshPoints = new List <Vector3>();
        }
    }