/// <summary>Request data descriptions from the host, then update our definitions.</summary>
    /// <exception cref="NatNetException">
    /// Thrown by <see cref="NatNetClient.GetDataDescriptions"/> if the request to the server fails.
    /// </exception>
    public void UpdateDefinitions()
    {
        // This may throw an exception if the server request times out or otherwise fails.
        m_dataDescs = m_client.GetDataDescriptions();

        m_skeletonDefinitions.Clear();

        for (int nativeDescIdx = 0; nativeDescIdx < m_dataDescs.SkeletonDescriptions.Count; ++nativeDescIdx)
        {
            sSkeletonDescription nativeSkel = m_dataDescs.SkeletonDescriptions[nativeDescIdx];

            OptitrackSkeletonDefinition skelDef = new OptitrackSkeletonDefinition {
                Id    = nativeSkel.Id,
                Name  = nativeSkel.Name,
                Bones = new List <OptitrackSkeletonDefinition.BoneDefinition>(nativeSkel.RigidBodyCount),
            };

            // Populate nested bone definitions.
            for (int nativeBoneIdx = 0; nativeBoneIdx < nativeSkel.RigidBodyCount; ++nativeBoneIdx)
            {
                sRigidBodyDescription nativeBone = nativeSkel.RigidBodies[nativeBoneIdx];

                OptitrackSkeletonDefinition.BoneDefinition boneDef = new OptitrackSkeletonDefinition.BoneDefinition {
                    Id       = nativeBone.Id,
                    ParentId = nativeBone.ParentId,
                    Name     = nativeBone.Name,
                    Offset   = new Vector3(nativeBone.OffsetX, nativeBone.OffsetY, nativeBone.OffsetZ),
                };

                skelDef.Bones.Add(boneDef);
            }

            m_skeletonDefinitions.Add(skelDef);
        }
    }
Esempio n. 2
0
    /// <summary>Request data descriptions from the host, then update our definitions.</summary>
    /// <exception cref="NatNetException">
    /// Thrown by <see cref="NatNetClient.GetDataDescriptions"/> if the request to the server fails.
    /// </exception>
    public void UpdateDefinitions()
    {
        if (m_client == null)
        {
            return;
        }

        // This may throw an exception if the server request times out or otherwise fails.
        m_dataDescs = m_client.GetDataDescriptions();

        m_skeletonDefinitions.Clear();

        for (int nativeDescIdx = 0; nativeDescIdx < m_dataDescs.SkeletonDescriptions.Count; ++nativeDescIdx)
        {
            sSkeletonDescription nativeSkel = m_dataDescs.SkeletonDescriptions[nativeDescIdx];

            OptitrackSkeletonDefinition skelDef = new OptitrackSkeletonDefinition {
                Id    = nativeSkel.Id,
                Name  = nativeSkel.Name,
                Bones = new List <OptitrackSkeletonDefinition.BoneDefinition>(nativeSkel.RigidBodyCount),
            };

            // Populate nested bone definitions.
            for (int nativeBoneIdx = 0; nativeBoneIdx < nativeSkel.RigidBodyCount; ++nativeBoneIdx)
            {
                sRigidBodyDescription nativeBone = nativeSkel.RigidBodies[nativeBoneIdx];

                OptitrackSkeletonDefinition.BoneDefinition boneDef = new OptitrackSkeletonDefinition.BoneDefinition {
                    Id       = nativeBone.Id,
                    ParentId = nativeBone.ParentId,
                    Name     = nativeBone.Name,
                    Offset   = new Vector3Serializer(nativeBone.OffsetX, nativeBone.OffsetY, nativeBone.OffsetZ),
                };

                skelDef.Bones.Add(boneDef);
            }

            m_skeletonDefinitions.Add(skelDef);
        }

        BinaryFormatter binFormatter = new BinaryFormatter();
        MemoryStream    mStream      = new MemoryStream();

        binFormatter.Serialize(mStream, m_skeletonDefinitions);

        photonView.RPC("RPC_UpdateDefinitions", PhotonTargets.AllBuffered, new object[] { mStream.ToArray() });
    }
Esempio n. 3
0
    /// <summary>Request data descriptions from the host, then update our definitions.</summary>
    /// <exception cref="NatNetException">
    /// Thrown by <see cref="NatNetClient.GetDataDescriptions"/> if the request to the server fails.
    /// </exception>
    public void UpdateDefinitions()
    {
        // This may throw an exception if the server request times out or otherwise fails.
        m_dataDescs = m_client.GetDataDescriptions();

        m_rigidBodyDefinitions.Clear();
        m_skeletonDefinitions.Clear();

        // Translate rigid body definitions.
        for (int nativeRbDescIdx = 0; nativeRbDescIdx < m_dataDescs.RigidBodyDescriptions.Count; ++nativeRbDescIdx)
        {
            sRigidBodyDescription nativeRb = m_dataDescs.RigidBodyDescriptions[nativeRbDescIdx];

            OptitrackRigidBodyDefinition rbDef = new OptitrackRigidBodyDefinition {
                Id      = nativeRb.Id,
                Name    = nativeRb.Name,
                Markers = new List <OptitrackRigidBodyDefinition.MarkerDefinition>(nativeRb.MarkerCount),
            };

            // Populate nested marker definitions.
            for (int nativeMarkerIdx = 0; nativeMarkerIdx < nativeRb.MarkerCount; ++nativeMarkerIdx)
            {
                int    positionOffset = nativeMarkerIdx * Marshal.SizeOf(typeof(MarkerDataVector));
                IntPtr positionPtr    = new IntPtr(nativeRb.MarkerPositions.ToInt64() + positionOffset);

                int    labelOffset = nativeMarkerIdx * Marshal.SizeOf(typeof(Int32));
                IntPtr labelPtr    = new IntPtr(nativeRb.MarkerRequiredLabels.ToInt64() + labelOffset);

                MarkerDataVector nativePos =
                    (MarkerDataVector)Marshal.PtrToStructure(positionPtr, typeof(MarkerDataVector));

                Int32 nativeLabel = Marshal.ReadInt32(labelPtr);

                OptitrackRigidBodyDefinition.MarkerDefinition markerDef =
                    new OptitrackRigidBodyDefinition.MarkerDefinition {
                    Position      = new Vector3(nativePos.Values[0], nativePos.Values[1], nativePos.Values[2]),
                    RequiredLabel = nativeLabel,
                };

                rbDef.Markers.Add(markerDef);
            }

            m_rigidBodyDefinitions.Add(rbDef);
        }

        // Translate skeleton definitions.
        for (int nativeSkelDescIdx = 0; nativeSkelDescIdx < m_dataDescs.SkeletonDescriptions.Count; ++nativeSkelDescIdx)
        {
            sSkeletonDescription nativeSkel = m_dataDescs.SkeletonDescriptions[nativeSkelDescIdx];

            OptitrackSkeletonDefinition skelDef = new OptitrackSkeletonDefinition {
                Id    = nativeSkel.Id,
                Name  = nativeSkel.Name,
                Bones = new List <OptitrackSkeletonDefinition.BoneDefinition>(nativeSkel.RigidBodyCount),
            };

            // Populate nested bone definitions.
            for (int nativeBoneIdx = 0; nativeBoneIdx < nativeSkel.RigidBodyCount; ++nativeBoneIdx)
            {
                sRigidBodyDescription nativeBone = nativeSkel.RigidBodies[nativeBoneIdx];

                OptitrackSkeletonDefinition.BoneDefinition boneDef =
                    new OptitrackSkeletonDefinition.BoneDefinition {
                    Id       = nativeBone.Id,
                    ParentId = nativeBone.ParentId,
                    Name     = nativeBone.Name,
                    Offset   = new Vector3(-nativeBone.OffsetX, nativeBone.OffsetY, nativeBone.OffsetZ),
                };

                skelDef.Bones.Add(boneDef);
            }

            m_skeletonDefinitions.Add(skelDef);
        }
    }