Hello guys,
I would like to build a Laserscanner with Arduino, which gives me the coordinates of the scanned object.
Then I need to create the Mesh/Modell for this particular object (This isn’t the problem; Hardware already works fine). In the script down below you can find a simulation of this process.
So my question is: How can I create a mesh/modell in Unity with those coordinates as vertices of the mesh/modell?
It would be really nice if someone could help me, because this project is very important to me.
Arduino code: (sorry it’s in german)
int abstand = 0;
int rotXY = 0;
int rotZ = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for (int i = 0; i < 200; i++) { //200 = Steps für eine Umdrehung (Verdoppel und Vervierfachbar) i = Sensor Hoch und Runter
for (int j = 0; j < 200; j++) {
abstand = random(0, 1023); //0-1023 entspricht 4-30 cm j = Drehteller
rotXY = j;
rotZ = i;
String erg = "";
erg.concat(abstand);
erg.concat("|");
erg.concat(rotXY);
erg.concat("|");
erg.concat(rotZ);
Serial.println(erg);
delay(100);
}
}
delay(5000);
}
Unity code: (sorry it’s in Spanish)
SerialPort stream = new SerialPort("COM3", 9600);
public string receivedstring;
public GameObject carrito;
public Vector3 rot;
public Vector3 rot2;
public string[] datos;
public string[] datos_recibidos;
void Start()
{
stream.Open(); //Open the Serial Stream.
}
void Update()
{
receivedstring = stream.ReadLine(); //Read the information
stream.BaseStream.Flush(); //Clear the serial information so we assure we get new information.
string[] datos = receivedstring.Split(','); //My arduino script returns a 3 part value (IE: 12,30,18)
if (datos[0] != "" && datos[1] != "" && datos[2] != "") //Check if all values are recieved
{
datos_recibidos [0] = datos[0];
datos_recibidos[1] = datos[1];
datos_recibidos[2] = datos[2];
//Read the information and put it in a vector3
//Take the vector3 and apply it to the object this script is applied.
stream.BaseStream.Flush(); //Clear the serial information so we assure we get new information.
}
}