MeshLinesGenerator.Start C# (CSharp) 메소드

Start() 공개 메소드

public Start ( ) : void
리턴 void
    void Start()
    {
        audioDirector = (AudioDirectorScript) GameObject.FindWithTag("AudioDirector").GetComponent("AudioDirectorScript");
        GenerateCalculationsMiniMesh();

        // mesh lines (i.e. rows) setup
        vertsArrayLast2 = new Vector3[2 * verticesFrequencyDepthCount];

        meshLinesPoolArray = new GameObject[meshLinesPoolSize];
        meshLinesMeshComponentArray = new Mesh[meshLinesPoolSize];
        meshLinesPVAComponentArray = new PVA[meshLinesPoolSize];
        meshLineDataArray = new MeshLine[meshLinesPoolSize];
        for(int i = 0; i < meshLinesPoolSize; i++)
        {
            meshLinesPoolArray[i] = (GameObject)Instantiate(meshLinePrefab, transform.position, Quaternion.identity);
            meshLinesPoolArray[i].name = meshLinesPoolArray[i].name + "_" + i.ToString();
            meshLinesPoolArray[i].GetComponentInChildren<MeshRenderer>().sharedMaterial = meshMaterial;
            meshLinesMeshComponentArray[i] = meshLinesPoolArray[i].GetComponentInChildren<MeshFilter>().mesh;
            meshLinesPVAComponentArray[i] = meshLinesPoolArray[i].GetComponent<PVA>();
            // TODO  no need for PVA, will probably remove entirely later
            meshLinesPVAComponentArray[i].enabled = false;
            // left/right offset to center mesh realtive to camera
            meshLinesPoolArray[i].transform.GetChild(0).transform.localPosition = new Vector3(0.5f  * verticesFrequencyDepthCount * verticesSpread, 0, 0);
            meshLineDataArray[i] =  meshLinesPoolArray[i].transform.GetComponent<MeshLine>();
            meshLineDataArray[i].meshlineVerticesArray = new Vector3[verticesFrequencyDepthCount];
            meshLinesPoolArray[i].SetActive(false);
        }

        // do basic setup for all meshe lines / rows
        verticesArray = new Vector3[verticesFrequencyDepthCount];
        freshLineMeshNormalsArray = new Vector3[verticesFrequencyDepthCount];
        for(int i = 0; i < verticesArray.Length; i++)
            verticesArray[i] = new Vector3(i * verticesSpread , 0, 0);

        List<int> indicesList = new List<int>();
        List<Vector2> uvsLinesList = new List<Vector2>();
        List<Vector4> tangentLinesList = new List<Vector4>();
        for(int i =0; i < verticesArray.Length - 1; i++)
        {
            indicesList.Add(i);
            indicesList.Add(i +1);
            uvsLinesList.Add(new Vector2(0, 0));
            tangentLinesList.Add(new Vector4(0, 0, 0, 0));
        }
        // add final uv
        uvsLinesList.Add(new Vector2(0,0));
        tangentLinesList.Add(new Vector4(0, 0, 0, 0));
        indicesArray = indicesList.ToArray();

        for(int i = 0; i < meshLinesPoolSize; i++)
        {
            meshLinesMeshComponentArray[i].Clear();
            meshLinesMeshComponentArray[i].vertices = verticesArray;
            meshLinesMeshComponentArray[i].uv = uvsLinesList.ToArray();
            meshLinesMeshComponentArray[i].tangents = tangentLinesList.ToArray();
            meshLinesMeshComponentArray[i].SetIndices(indicesArray, MeshTopology.Lines, 0);
        }

        // mesh collumns setup
        // basic object setup
        meshCollumnsArray = new GameObject[verticesFrequencyDepthCount];
        for(int i = 0; i < meshCollumnsArray.Length; i++)
        {
            meshCollumnsArray[i] = new GameObject("MeshCollumn_" + i);
            // parenting to make sure GO stays in view and does not get culled out when moving
            //meshCollumnsArray[i].transform.parent = gameObject.transform;
            meshCollumnsArray[i].AddComponent<MeshFilter>();
            meshCollumnsArray[i].AddComponent<MeshRenderer>();
            meshCollumnsArray[i].renderer.sharedMaterial = meshMaterial;
            meshCollumnsArray[i].renderer.receiveShadows = false;
            meshCollumnsArray[i].renderer.castShadows = false;
        }

        // vertices and indices setup
        tempCollumnVerticesArray = new Vector3[collumnDepth];
        tempCollumnNormalsArray = new Vector3[collumnDepth];

        // Generate indices
        List<int> rowIndicesList = new List<int>();
        List<Vector2> uvsCollumnsList = new List<Vector2>();
        List<Vector4> tangentsCollumnsList = new List<Vector4>();
        for(int i = 0; i< tempCollumnVerticesArray.Length -1; i++)
        {
            rowIndicesList.Add(i);
            rowIndicesList.Add(i+1);
            uvsCollumnsList.Add(new Vector2(0, 0));
            tangentsCollumnsList.Add( new Vector4(0, 0, 0, 0));
        }
        // add final uv
        uvsCollumnsList.Add(new Vector2(0, 0));
        tangentsCollumnsList.Add(new Vector4(0, 0, 0, 0));

        // setup mesh component
        meshCollumnsMeshComponentArray = new Mesh[meshCollumnsArray.Length];

        // these 2D arrays will be used to locally store and manage vertices and normals, minimizing how often mesh.verties,etc gets called (which causes GC spike)
        collumnsArrayVerticesArray = new Vector3[meshCollumnsMeshComponentArray.Length][];
        collumnsArrayNormalsArray = new Vector3[meshCollumnsMeshComponentArray.Length][];

        Vector3[] emptyNormals = new Vector3[tempCollumnVerticesArray.Length];
        for(int i = 0; i < meshCollumnsMeshComponentArray.Length; i++)
        {
            meshCollumnsMeshComponentArray[i] = meshCollumnsArray[i].GetComponent<MeshFilter>().mesh;
            meshCollumnsMeshComponentArray[i].Clear();
            meshCollumnsMeshComponentArray[i].vertices = tempCollumnVerticesArray;
            meshCollumnsMeshComponentArray[i].SetIndices(rowIndicesList.ToArray(), MeshTopology.Lines,0);
            meshCollumnsMeshComponentArray[i].normals = emptyNormals;
            meshCollumnsMeshComponentArray[i].uv = uvsCollumnsList.ToArray();
            meshCollumnsMeshComponentArray[i].tangents = tangentsCollumnsList.ToArray();
            meshCollumnsMeshComponentArray[i].bounds = new Bounds(Vector3.zero, Vector3.one * 10000000.0f);

            collumnsArrayVerticesArray[i] = new Vector3[collumnDepth];
            collumnsArrayNormalsArray[i] =  new Vector3[collumnDepth];
            for(int j = 0; j < collumnDepth; j++)
            {
                collumnsArrayVerticesArray[i][j] = new Vector3(0, 0, 0);
                collumnsArrayNormalsArray[i][j] = new Vector3(0, 0, 0);
            }

        }

        stitchPosObject = new GameObject();
        stitchPosObject.transform.parent = transform;
        stitchPosObject.transform.localPosition = stitchAnchorOffset;
        tempVector = new Vector3(0, 0, 0);

        fingertipStitch = GetComponent<LMC_FingertipsStitch>();
        //  array structured so that for [i][j], i represents the joint index (ex: fingertip row) and j represents the vertices
        // see https://developer.leapmotion.com/documentation/skeletal/csharp/devguide/Intro_Skeleton_API.html
        fingerJointsArrayStitchesPosArray = new Vector3[jointsPerFinger][];
        for (int i = 0; i < fingerJointsArrayStitchesPosArray.Length; i++)
        {
            fingerJointsArrayStitchesPosArray[i] = new Vector3[verticesFrequencyDepthCount];
        }
        //stitchOriginPosArray = new Vector3[verticesFrequencyDepthCount];

        //GenerateLineMesh();
        //StitchNewRowIntoCollumns()

        activeMeshLinesList = new List<GameObject>();
    }