void Start() { //audioDirector = GameObject.FindGameObjectWithTag("AudioDirector").GetComponent<AudioDirectorScript>(); bciDataDirector = FindObjectOfType <BCIDataDirector>(); lmcController = new Controller(); if (lmcController == null) { Debug.LogWarning("Cannot connect to controller. Make sure you have Leap Motion v2.0+ installed"); } fingertipsPosArray = new Vector3[5]; debugPosObjects = new GameObject[fingertipsPosArray.Length]; for (int i = 0; i < debugPosObjects.Length; i++) { debugPosObjects[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere); debugPosObjects[i].name = "Debug finger: " + i.ToString(); debugPosObjects[i].transform.parent = transform; debugPosObjects[i].renderer.enabled = false; } meshlinesGenerator = GetComponent <MeshLinesGenerator>(); fingerJointsArrayStitchesPosArray = new Vector3[jointsPerFinger][]; for (int i = 0; i < fingerJointsArrayStitchesPosArray.Length; i++) { fingerJointsArrayStitchesPosArray[i] = new Vector3[meshlinesGenerator.verticesFrequencyDepthCount]; } // internal array to store just joint positions fingersArrayJointsPositionsPosArray = new Vector3[5][]; // 5 because there are 5 fingers for (int i = 0; i < fingersArrayJointsPositionsPosArray.Length; i++) { fingersArrayJointsPositionsPosArray[i] = new Vector3[jointsPerFinger]; } bonesQuaternionsCacheArray = new Quaternion[25]; // 5 bones/joints (counting fingertip) for all 5 fingers bonesWidthsCacheArray = new float[25]; rotGO = new GameObject(); rotGO.name = "LMC bone rot GO"; rotTransform = rotGO.transform; rotTransform.parent = transform.parent; }
// Use this for initialization void Start() { //Start music for (int i = 0; i < maxTrackCount; i++) { audioSourceArray[i].Play(); } // Initialize array to 1 if not set in editor for (int i = 0; i < scalingPerDecadeArray.Length; i++) { if (scalingPerDecadeArray[i] == 0) { scalingPerDecadeArray[i] = 1.0f; } } if (audioSourceArray[0].clip != null) { currentlyPlayingFileName = audioSourceArray[0].clip.name; } //lowPassFilter = (AudioLowPassFilter)GetComponent("AudioLowPassFilter"); //mainCamera = (Camera)GameObject.FindWithTag("MainCamera").GetComponent("Camera"); // read only, don't need to account for L+R cameras //initialFOV = ( (PlayerScript)GameObject.FindWithTag("Player").GetComponent("PlayerScript") ).originalFieldOfView; if (isLiveAudio) { Debug.Log(Microphone.devices[0]); liveAudioSource = gameObject.AddComponent <AudioSource>(); liveAudioSource.loop = true; liveAudioSource.volume = 1.0f; liveAudioSource.mute = true; liveAudioSource.playOnAwake = false; currentLiveDeviceName = Microphone.devices[0]; StartCoroutine("LaunchLiveAudioSource"); } bciDataDirector = FindObjectOfType <BCIDataDirector>(); }
void Start() { //audioDirector = GameObject.FindGameObjectWithTag("AudioDirector").GetComponent<AudioDirectorScript>(); bciDataDirector = FindObjectOfType<BCIDataDirector>(); lmcController = new Controller(); if (lmcController == null) Debug.LogWarning("Cannot connect to controller. Make sure you have Leap Motion v2.0+ installed"); fingertipsPosArray = new Vector3[5]; debugPosObjects = new GameObject[fingertipsPosArray.Length]; for (int i = 0; i < debugPosObjects.Length; i++) { debugPosObjects[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere); debugPosObjects[i].name = "Debug finger: " + i.ToString(); debugPosObjects[i].transform.parent = transform; debugPosObjects[i].renderer.enabled = false; } meshlinesGenerator = GetComponent<MeshLinesGenerator>(); fingerJointsArrayStitchesPosArray = new Vector3[jointsPerFinger][]; for (int i = 0; i < fingerJointsArrayStitchesPosArray.Length; i++) { fingerJointsArrayStitchesPosArray[i] = new Vector3[meshlinesGenerator.verticesFrequencyDepthCount]; } // internal array to store just joint positions fingersArrayJointsPositionsPosArray = new Vector3[5][]; // 5 because there are 5 fingers for (int i = 0; i < fingersArrayJointsPositionsPosArray.Length; i++) { fingersArrayJointsPositionsPosArray[i] = new Vector3[jointsPerFinger]; } bonesQuaternionsCacheArray = new Quaternion[25]; // 5 bones/joints (counting fingertip) for all 5 fingers bonesWidthsCacheArray = new float[25]; rotGO = new GameObject(); rotGO.name = "LMC bone rot GO"; rotTransform = rotGO.transform; rotTransform.parent = transform.parent; }
void Awake() { bciDataDirector = FindObjectOfType<BCIDataDirector>(); }
// 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 Awake() { bciDataDirector = FindObjectOfType <BCIDataDirector>(); }
// Use this for initialization void Start() { //Start music for(int i = 0; i < maxTrackCount ; i++) audioSourceArray[i].Play(); // Initialize array to 1 if not set in editor for(int i = 0; i < scalingPerDecadeArray.Length; i++) if(scalingPerDecadeArray[i] == 0) scalingPerDecadeArray[i] = 1.0f; if(audioSourceArray[0].clip != null) currentlyPlayingFileName = audioSourceArray[0].clip.name; //lowPassFilter = (AudioLowPassFilter)GetComponent("AudioLowPassFilter"); //mainCamera = (Camera)GameObject.FindWithTag("MainCamera").GetComponent("Camera"); // read only, don't need to account for L+R cameras //initialFOV = ( (PlayerScript)GameObject.FindWithTag("Player").GetComponent("PlayerScript") ).originalFieldOfView; if(isLiveAudio) { Debug.Log(Microphone.devices[0]); liveAudioSource = gameObject.AddComponent<AudioSource>(); liveAudioSource.loop = true; liveAudioSource.volume = 1.0f; liveAudioSource.mute = true; liveAudioSource.playOnAwake = false; currentLiveDeviceName = Microphone.devices[0]; StartCoroutine("LaunchLiveAudioSource"); } bciDataDirector = FindObjectOfType<BCIDataDirector>(); }