void Start() { // Give all the required components to the gameObject. GameObject rosbridge = GameObject.Find("RosBridge"); if (null == rosbridge) { Debug.Log("PointCloudRenderer.cs: RosBridge object not found."); } subscriber = rosbridge.GetComponent <PointCloudSubscriber>(); if (subscriber == null) { Debug.Log("PointCloudRenderer.cs: Pointcloud subscriber component not found."); } meshRenderer = gameObject.AddComponent <MeshRenderer>(); mf = gameObject.AddComponent <MeshFilter>(); meshRenderer.material = new Material(Shader.Find("Custom/PointCloudShader")); mesh = new Mesh { indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; transform.position = offset.position; transform.rotation = offset.rotation; }
private void LateUpdate() { #if ENABLE_WINMD_SUPPORT // update depth map texture Debug.Log("last update"); if (startRealtimePreview && researchMode.DepthMapTextureUpdated()) { if (!mediaTexture) { mediaTexture = new Texture2D(512, 512, TextureFormat.Alpha8, false); mediaMaterial.mainTexture = mediaTexture; } // byte[] frameTexture = researchMode.GetDepthMapTextureBuffer(); // ushort[] depth = researchMode.GetDepthMapBuffer(); float[] pointCloud = researchMode.GetPointCloudBuffer(); //if (frameTexture.Length > 0) //{ // if (frameData == null) // { // frameData = frameTexture; // } // else // { // System.Buffer.BlockCopy(frameTexture, 0, frameData, 0, frameData.Length); // } // if (frameData != null) // { // Debug.Log("data updated"); // //File.WriteAllBytes(Application.persistentDataPath + "/depthData.dat", frameData); // mediaTexture.LoadRawTextureData(frameData); // mediaTexture.Apply(); // } //} //if (depth.Length > 0) //{ // var byteArray = new byte[depth.Length * 2]; // Buffer.BlockCopy(depth, 0, byteArray, 0, byteArray.Length); // File.WriteAllBytes(String.Format(Application.persistentDataPath+"/"+"depth_{0}.dat", frame), byteArray); // Debug.Log("depthData written"); //} if (pointCloud.Length > 0) { PointCloudSubscriber.ReceiveMessage(pointCloud); //var byteArray2 = new byte[pointCloud.Length * 4]; //Buffer.BlockCopy(pointCloud, 0, byteArray2, 0, byteArray2.Length); //File.WriteAllBytes(String.Format(Application.persistentDataPath+"/"+"pointCloud_{0}.dat", frame), byteArray2); //Debug.Log(pointCloud[0]); //Debug.Log(pointCloud[1]); //Debug.Log(pointCloud[2]); Debug.Log("research mode: point cloud data written"); } } #endif }
/// <summary> /// Called before first frame. /// Sets up variables in order to communicate with PointCloudSubscriber /// </summary> void Start() { // Find ROS Connection in order to access point data GameObject g = GameObject.FindGameObjectWithTag("ROSManager"); p = g.GetComponent <PointCloudSubscriber>(); InvokeRepeating("FixedUpdateEx", 0.5f, 0.5f); }
//private HandJoints joints; void Start() { rm = new ResearchMode(); PointCloudSubscriber.startTimer(); ResearchMode.StartPreviewEvent(); //PointCloudRenderer.toggleView(); //joints = gameObject.AddComponent<HandJoints>(); //joints.toggleRecording(); }
void UpdateMesh() { runningFrame++; positions = PointCloudSubscriber.GetPCL(runningFrame); Debug.Log("Renderer: points received"); if (positions == null || positions.Length == 0) { Debug.Log("Empty array"); return; } int size = positions.Length; colours = new Color[size]; Debug.Log(size); for (int n = 0; n < size; n++) { //pcl[n] = new Vector3(points[n * 3], points[n * 3 + 1], points[n * 3 + 2]); colours[n] = new Color(1, 1, 1, 1); } mf.mesh.Clear(); Mesh mesh2 = new Mesh { // Use 32 bit integer values for the mesh, allows for stupid amount of vertices (2,147,483,647 I think?) indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; mesh2.vertices = positions; mesh2.colors = colours; int[] indices = new int[positions.Length]; for (int i = 0; i < positions.Length; i++) { indices[i] = i; } mesh2.SetIndices(indices, MeshTopology.Points, 0); mesh2.RecalculateNormals(); mf.mesh = mesh2; Debug.Log("Renderer: points updated"); }