Hello,
I was wondering if there's a running example or a detailed documentation on the use of the Unity3DSample. So far I have been able to connect to Motive Tracker. When I try to establish the connection to the Repeater (/Unity3DSample) from the SlipStream.cs script in unity, I get an "requested item has been unloaded" -error when trying to init the "mRemoteIpEndPoint":
mRemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 16000);
Any hints are highly appreciated.
Running example for Unity3DSample?
-
- Posts: 609
- Joined: Tue Mar 19, 2013 5:03 pm
Re: Running example for Unity3DSample?
Hello,
I will see if a member of our dev team can answer your questions.
Regards,
I will see if a member of our dev team can answer your questions.
Regards,
Dustin
Technical Support Engineer
OptiTrack | TrackIR | SmartNav
Technical Support Engineer
OptiTrack | TrackIR | SmartNav
Re: Running example for Unity3DSample?
Problem solved. I made some minor changes in the windows Forms sample and I'm now able to directly stream to my unity.
Thanks.
Thanks.
-
- Posts: 609
- Joined: Tue Mar 19, 2013 5:03 pm
Re: Running example for Unity3DSample?
Great! Thanks for the status update.
Dustin
Technical Support Engineer
OptiTrack | TrackIR | SmartNav
Technical Support Engineer
OptiTrack | TrackIR | SmartNav
-
- Posts: 10
- Joined: Mon Sep 01, 2014 2:35 pm
- Location: Los Angeles, CA
- Contact:
Re: Running example for Unity3DSample?
Running into related problems with SlipStream.cs. I'm just trying to stream a single rigid body to Unity.
[*]Motive 1.6.0 Beta 2
[*]NatNet SDK 2.7
[*]Unity 4.3.4
In Motive my Data Streaming settings are: In the command prompt I run UnitySample like so and get the following:
After doing some debugging of SlipStream.cs I noticed that:
1. mRemoteIpEndPoint.Address: seems to be 0.0.0.0 instead of initializing to 127.0.0.1.
2. I get the following exception:
Additionally, in Body.cs I see that OnPacketReceived is never called.
Here is the modified SlipStream.cs code:
[*]Motive 1.6.0 Beta 2
[*]NatNet SDK 2.7
[*]Unity 4.3.4
In Motive my Data Streaming settings are: In the command prompt I run UnitySample like so and get the following:
Code: Select all
C:\OptiTrack\NatNet_SDK_2.7\Samples\bin>UnitySample.exe 127.0.0.1 127.0.0.1
Connecting to server at 127.0.0.1...
Connecting from 127.0.0.1...
NatNet Sample Client (NatNet ver. 2.7.0.0)
[Client] Initializing using my address: 127.0.0.1
[Client] Initializing command listener.
[Client] Initializing data listener.
[Client] Received command from 127.0.0.1: Command=1, nDataBytes=264
[Client] Connected. (HostApp:Motive HostVer: 1.60.0.0 HostIP: 127.0.0.1 ()
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=517
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=517
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=517
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=529
[SampleClient] Server application info:
Application: Motive (ver. 1.60.0.0)
NatNet Version: 2.6.0.0
Client IP:127.0.0.1
Server IP:127.0.0.1
Server Name:WBMLSERVER
Client initialized and ready.
[SampleClient] Sending Test Request
[Client] Requesting: TestRequest
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=517
[Client] Received command from 127.0.0.1: Command=100, nDataBytes=264
[Client] Server returned NAT_UNRECOGNIZED_REQUEST.
[SampleClient] Requesting Data Descriptions...
[Client] Received command from 127.0.0.1: Command=5, nDataBytes=177
[SampleClient] Received 3 Data Descriptions:
Data Description # 0 (type=1)
RigidBody Name : Oculus Rift v3
RigidBody ID : 1
RigidBody Parent ID : -1
Parent Offset : 0.00,0.00,0.00
Data Description # 1 (type=0)
MarkerSet Name : Oculus Rift v3
Marker 1
Marker 2
Marker 3
Data Description # 2 (type=0)
MarkerSet Name : all
Oculus Rift v3-Marker 1
Oculus Rift v3-Marker 2
Oculus Rift v3-Marker 3
Client is connected to server and listening for data...
[Client] Received command from 127.0.0.1: Command=7, nDataBytes=517
1. mRemoteIpEndPoint.Address: seems to be 0.0.0.0 instead of initializing to 127.0.0.1.
2. I get the following exception:
Code: Select all
System.Net.Sockets.SocketException: A non-blocking socket operation could not be completed immediately.
at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x00000] in <filename unknown>:0
at SlipStream.UDPRead () [0x00000] in C:\Users\Leviathan\Documents\New Unity Project 1\Assets\SlipStream.cs:76
Here is the modified SlipStream.cs code:
Code: Select all
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public delegate void PacketReceivedHandler(object sender, string PacketData);
public class SlipStream : MonoBehaviour
{
public string IP = "127.0.0.1";
public int Port = 16000;
public event PacketReceivedHandler PacketNotification;
private IPEndPoint mRemoteIpEndPoint;
private Socket mListener;
private byte[] mReceiveBuffer;
private string mPacket;
private int mPreviousSubPacketIndex = 0;
private const int kMaxSubPacketSize = 1400;
void Start()
{
mReceiveBuffer = new byte[kMaxSubPacketSize];
mPacket = System.String.Empty;
//ORIGINAL CODE
//mRemoteIpEndPoint = new IPEndPoint(IPAddress.Any, Port);
//NEW CODE
mRemoteIpEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
print ("IP: " + mRemoteIpEndPoint.Address);
print ("Port: " + mRemoteIpEndPoint.Port);
//////////////
mListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
mListener.Bind(mRemoteIpEndPoint);
mListener.Blocking = false;
mListener.ReceiveBufferSize = 128*1024;
}
public void UDPRead()
{
try
{
int bytesReceived = mListener.Receive(mReceiveBuffer);
int maxSubPacketProcess = 200;
while(bytesReceived>0 && maxSubPacketProcess>0)
{
//== ensure header is present ==--
if(bytesReceived>=2)
{
int subPacketIndex = mReceiveBuffer[0];
bool lastPacket = mReceiveBuffer[1]==1;
if(subPacketIndex==0)
{
mPacket = System.String.Empty;
}
if(subPacketIndex==0 || subPacketIndex==mPreviousSubPacketIndex+1)
{
mPacket += Encoding.ASCII.GetString(mReceiveBuffer, 2, bytesReceived-2);
mPreviousSubPacketIndex = subPacketIndex;
if(lastPacket)
{
//== ok packet has been created from sub packets and is complete ==--
//== notify listeners ==--
if(PacketNotification!=null)
PacketNotification(this, mPacket);
}
}
}
bytesReceived = mListener.Receive(mReceiveBuffer);
//== time this out of packets are coming in faster than we can process ==--
maxSubPacketProcess--;
}
}
catch(System.Exception ex)
{
print (ex);
}
}
void Update()
{
UDPRead();
}
}
Bradley Newman
Senior Research Associate
USC School of Cinematic Arts
Worldbuilding Media Lab (WbML) - worldbuilding.usc.edu
Senior Research Associate
USC School of Cinematic Arts
Worldbuilding Media Lab (WbML) - worldbuilding.usc.edu
-
- Posts: 10
- Joined: Mon Sep 01, 2014 2:35 pm
- Location: Los Angeles, CA
- Contact:
Re: Running example for Unity3DSample?
Tried this out and it seemed to work, albeit only in multicast: https://github.com/ti2/UnityOptitrack
Bradley Newman
Senior Research Associate
USC School of Cinematic Arts
Worldbuilding Media Lab (WbML) - worldbuilding.usc.edu
Senior Research Associate
USC School of Cinematic Arts
Worldbuilding Media Lab (WbML) - worldbuilding.usc.edu