-
Notifications
You must be signed in to change notification settings - Fork 0
/
textureadd.cs
179 lines (154 loc) · 3.63 KB
/
textureadd.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class textureadd : MonoBehaviour {
UdpClient listener;
IPEndPoint EP;
bool done = true;
System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();
Thread recThread, udpThread;
volatile bool val = false;
PointsPCD target;
cubePCD target1;
System.Diagnostics.Stopwatch sw;
// Use this for initialization
void Start () {
target = GetComponent<PointsPCD>();
target.dataPath = @"\test1_pcd";
target1 = GameObject.Find("CubeCreator").GetComponent<cubePCD>();
target1.dataPath = @"\test2_pcd";
//MakeCube();
recThread = new Thread(() => readBytes());
recThread.IsBackground = true;
recThread.Start();
sw = new System.Diagnostics.Stopwatch();
sw.Start();
sw.Stop();
print(sw.Elapsed);
/*
udpThread = new Thread(() => ReadUDP());
udpThread.IsBackground = true;
udpThread.Start();
*/
}
void readBytes() {
string data;
string path = Directory.GetCurrentDirectory();
Thread.Sleep(1000);
while (done)
{
try {
if (val == false){
if (downloadPCD(path)) {
val = true;
}
}
Thread.Sleep(2000);
} catch (Exception e) {
print("MAIN::"+e.ToString());
}
}
}
bool downloadPCD(string path){
using (var client = new System.Net.WebClient())
{
bool download = false;
while(download != true) {
try { // downloads pcd file from a HTTP server"
Debug.Log("Downloading files");
client.DownloadFile("http://192.168.10.200:8000/test_pcd.pcd", path+"/Assets/"+"test1_pcd.pcd");
//client.DownloadFile("http://192.168.1.2:8000/test_pcd.pcd", path+"/Assets/"+"test1_pcd.pcd");
download = true;
return true;
} catch (Exception e) {
Debug.Log("Problem downloading pcd: "+ e.ToString());
Thread.Sleep(2000);
continue;
return false;
}
}
return false;
}
}
void MakePCD(){
try{
Destroy(GameObject.Find("test1_pcd"));
} catch (Exception e) {
print("EEEEE: "+ e.ToString());
}
Debug.Log("LOADING PCD");
if (target == null){
target = GetComponent<PointsPCD>();
target.dataPath = @"\test1_pcd";
}
// target.dataPath = @"\PointCloud\example";
// target.enable = true;
target.makeCloud();
val = false;
}
void MakeCube(){
Debug.Log("Making CUBES");
if (target1 == null){
target1 = GameObject.Find("CubeCreator").GetComponent<cubePCD>();
target1.dataPath = @"\test1_pcd";
}
// target.dataPath = @"\PointCloud\example";
// target.enable = true;
target1.makeCloud();
val = false;
}
void ReadUDP()
{
IPEndPoint EP;
listener = new UdpClient(8888);
EP = new IPEndPoint(IPAddress.Any,8888);
byte[] rec = new byte[100];
string[] buffer;
string data;
Thread.Sleep(1000);
while (done)
{
try {
print("WAITING FOR INCOMING UDP PCD");
rec = listener.Receive(ref EP); // blocking call !!!
data = encode.GetString(rec);
print("REC:"+data);
buffer = data.Split();
print("CER:");
Thread.Sleep(10);
} catch (Exception e) {
print("MAIN::"+e.ToString());
}
}
}
void Update(){
if (val == true) {
MakePCD();
//MakeCube();
}
//target1.MakePoints();
}
public void OnApplicationQuit(){
///////////////////////////////
//// Application end procedures
///////////////////////////////
try
{
done = false;
recThread.Abort();
listener.Close();
//udpThread.Abort();
} catch(Exception e)
{
print("Problem closing application: "+ e.ToString());
}
print("Stopped");
}
}