void Start()
    {
        lmcLight = GetComponent<Light>();
        lightTransform = lmcLight.transform;
        lmcFingertipsStitch = GameObject.FindObjectOfType<LMC_FingertipsStitch>().GetComponent<LMC_FingertipsStitch>();

        lmcController = new Controller();
        if (lmcController == null)
            Debug.LogWarning("Cannot connect to controller. Make sure you have Leap Motion v2.0+ installed");
    }
Example #2
0
    void Start()
    {
        lmcLight            = GetComponent <Light>();
        lightTransform      = lmcLight.transform;
        lmcFingertipsStitch = GameObject.FindObjectOfType <LMC_FingertipsStitch>().GetComponent <LMC_FingertipsStitch>();

        lmcController = new Controller();
        if (lmcController == null)
        {
            Debug.LogWarning("Cannot connect to controller. Make sure you have Leap Motion v2.0+ installed");
        }
    }
    // Use this for initialization
    void Start()
    {
        //audioDirector = (AudioDirectorScript) GameObject.FindWithTag("AudioDirector").GetComponent("AudioDirectorScript");
        bciDataDirector = FindObjectOfType<BCIDataDirector>();
        verticesFrequencyDepthCount = bciDataDirector.currentDataArary_Raw.Length;

        GenerateCalculationsMiniMesh();

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

        meshLinesPoolArray = new GameObject[meshLinesPoolSize];
        meshLinesMeshComponentArray = new Mesh[meshLinesPoolSize];
        meshLinesPVAComponentArray = new PVA[meshLinesPoolSize];
        for(int i = 0; i < meshLinesPoolSize; i++)
        {
            meshLinesPoolArray[i] = (GameObject)Instantiate(meshLinePrefab, transform.position, Quaternion.identity);
            meshLinesPoolArray[i].GetComponentInChildren<MeshRenderer>().sharedMaterial = meshMaterial;
            meshLinesMeshComponentArray[i] = meshLinesPoolArray[i].GetComponentInChildren<MeshFilter>().mesh;
            meshLinesPVAComponentArray[i] = meshLinesPoolArray[i].GetComponent<PVA>();
            meshLinesPoolArray[i].transform.GetChild(0).transform.localPosition = new Vector3(-0.5f  * verticesFrequencyDepthCount * verticesSpread, 0, 0);
            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];
    }
    // Use this for initialization
    void Start()
    {
        //audioDirector = (AudioDirectorScript) GameObject.FindWithTag("AudioDirector").GetComponent("AudioDirectorScript");
        bciDataDirector             = FindObjectOfType <BCIDataDirector>();
        verticesFrequencyDepthCount = bciDataDirector.currentDataArary_Raw.Length;

        GenerateCalculationsMiniMesh();

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

        meshLinesPoolArray          = new GameObject[meshLinesPoolSize];
        meshLinesMeshComponentArray = new Mesh[meshLinesPoolSize];
        meshLinesPVAComponentArray  = new PVA[meshLinesPoolSize];
        for (int i = 0; i < meshLinesPoolSize; i++)
        {
            meshLinesPoolArray[i] = (GameObject)Instantiate(meshLinePrefab, transform.position, Quaternion.identity);
            meshLinesPoolArray[i].GetComponentInChildren <MeshRenderer>().sharedMaterial = meshMaterial;
            meshLinesMeshComponentArray[i] = meshLinesPoolArray[i].GetComponentInChildren <MeshFilter>().mesh;
            meshLinesPVAComponentArray[i]  = meshLinesPoolArray[i].GetComponent <PVA>();
            meshLinesPoolArray[i].transform.GetChild(0).transform.localPosition = new Vector3(-0.5f * verticesFrequencyDepthCount * verticesSpread, 0, 0);
            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];
    }
 void Start()
 {
     fingerTipStich = GetComponent<LMC_FingertipsStitch>();
 }
Example #6
0
 void Start()
 {
     fingerTipStich = GetComponent <LMC_FingertipsStitch>();
 }