forums.naturalpoint.com

Discussion and Support for the OptiTrack, SmartNav and TrackIR brands by NaturalPoint

Streaming Individual Markers

NatNet, VRPN, TrackD, and Plugins

by Hanowde » Sat Oct 31, 2015 12:03 pm

Hello, everyone

I want to do the same too. But i cant find a solution how to read the position of a single Marker from Motive to Unity. Has anyone good idea for my problem?

@heath789 : have your find a solution for your problem?

Thank your!
Hanowde
 
Posts: 7
Joined: Sat Oct 10, 2015 10:01 am

by iko79 » Wed Jul 12, 2017 4:09 am

I realize the thread is inactive for some time, but maybe some folks will find this helpful, regarding Hanowde's question concerning Unity3D, since I also had this question rectently:

There is a very simple way of adding this functionality in the official Optitrack Untiy Plugin (I'm referring to version 1.0.1 here, but I expect you will get this done in future releases in a similar way):

In Assets/OptiTrack/Scripts/OptitrackStreamingClient.cs, there is a method called OnNatNetFrameReceived, where you get NatNetClient.NativeFrameReceivedEventArgs eventArgs as an argument. The class already implements doing most of the marshalling for you, although it is not used by the plugin (yet?), giving you an sFrameOfMocapData struct, which contains the fields OtherMarkersCount and OtherMarkers. I added a list of OptitrackMarkerState to the OptitrackStreamingClient class like this

Code: Select all
private List<OptitrackMarkerState> m_latestOtherMarkerStates = new List<OptitrackMarkerState>();


and added this to the OnNatNetFrameReceived method, just above the code where updating of rigid bodies is done:

Code: Select all
sFrameOfMocapData frame = eventArgs.MarshaledFrame;
//Debug.Log( "labeled: " + frame.LabeledMarkerCount + ", other: " + frame.OtherMarkerCount + ", sets: " + frame.MarkerSetCount );

float[] vec = new float[3 * frame.OtherMarkerCount];
System.Runtime.InteropServices.Marshal.Copy( frame.OtherMarkers, vec, 0, vec.Length );

m_latestOtherMarkerStates.Clear();
for( int i = 0; i < frame.OtherMarkerCount; i++ )
{
    OptitrackMarkerState state = new OptitrackMarkerState();
    state.Position = new Vector3( -vec[i * 3 + 0], vec[i * 3 + 1], vec[i * 3 + 2] );
    //TODO: where do i get the size from?
    state.Size = 0.01f;

    m_latestOtherMarkerStates.Add( state );
    //Debug.Log( "marker #" + i + ": [" + vec[i * 3 + 0] + ", " + vec[i * 3 + 1] + ", " + vec[i * 3 + 2] );
}


Works like a charm for me. You can also go ahead and implement an editor script so you have the markers drawn in the Unity scene view, use OptitrackRigidBodyEditor.cs as a reference, it isn't too hard.
iko79
 
Posts: 11
Joined: Fri Apr 02, 2010 5:31 am

Previous

Return to OptiTrack Data Streaming

cron