Exemplo n.º 1
0
    void Start()
    {
        //The render scale. Higher numbers = better quality, but trades performance
        m_RenderScale          = 1.5f;
        VRSettings.renderScale = m_RenderScale;
        // Debug.Log("WORKING");



        PNUtils.LoadSkeletonReference(bones, rootTrans, "Robot_", 0);



        _connection = NeuronDataReader.BRConnectTo(ServerIP, int.Parse(ServerPort));



        // Socket status handle
        _OnSocketStatusChanged = new SocketStatusChanged(OnSocketStatusChanged);
        NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, _OnSocketStatusChanged);
        // Data receive handle
        _OnFrameDataReceived = new FrameDataReceived(OnFrameDataReceived);
        NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, _OnFrameDataReceived);
        // Data receive handle
        _OnMatchedRigidBodyDataReceived = new MatchedRigidBodyDataReceived(OnMatchedRigidBodyDataReceived);
        NeuronDataReader.BRRegisterMatchedDataCallback(IntPtr.Zero, _OnMatchedRigidBodyDataReceived);
    }
Exemplo n.º 2
0
        static void DestroyConnection(NeuronSource source)
        {
            if (source == null)
            {
                return;
            }

            // We have to make a lock before removing the source from the maps.
            lock (_sourcesLock) _sources.Remove(source);
            // Now we can delete the source safely!

            if (source.SocketType == SocketType.TCP)
            {
                NeuronDataReader.BRCloseSocket(source.Socket);
                Debug.Log("[Neuron] Disconnected " + source.Address + ":" + source.Port);
            }
            else
            {
                NeuronDataReader.BRCloseSocket(source.Socket);
                Debug.Log("[Neuron] Stopped listening " + source.Port);
            }

            // Unregister the reader callback if this was the last connection.
            if (_sources.Count == 0)
            {
                NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, null);
            }
        }
Exemplo n.º 3
0
    void Update()
    {
        if (_connection != IntPtr.Zero)
        {
            if (NeuronDataReader.BRGetSocketStatus(_connection) == SocketStatus.CS_Running)
            {
                _IsSocketConnected = true;
            }
            else
            {
                _IsSocketConnected = false;
            }

            ApplyMotionToTargetSkeleton();
        }

        if (_IsSocketConnected)
        {
            text.text = "CONNECTED";
        }
        else
        {
            text.text = "DISCONNECTED";
        }
    }
        private void btnStartUDPService_Click(object sender, RoutedEventArgs e)
        {
            int nPort = 0;

            try
            {
                nPort = int.Parse(txtUDPPort.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong port number.", "UDP Service", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (btnStartUDPService.Content.ToString() == "Start")
            {
                sockUDPRef = NeuronDataReader.BRStartUDPServiceAt(nPort);
                if (sockUDPRef != IntPtr.Zero)
                {
                    btnStartUDPService.Content = "Stop";
                }
                else
                {
                    btnStartUDPService.Content = "Start";
                }
            }
            else
            {
                NeuronDataReader.BRCloseSocket(sockUDPRef);
                btnStartUDPService.Content = "Start";
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _DataReceived = new FrameDataReceived(bvhDataReceived);
            NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, _DataReceived);

            _CmdDataReceived = new CommandDataReceived(cmdDataReceived);
            NeuronDataReader.BRRegisterCommandDataCallback(IntPtr.Zero, _CmdDataReceived);

            _SocketStatusChanged = new SocketStatusChanged(socketStatusChanged);
            NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, _SocketStatusChanged);
        }
Exemplo n.º 6
0
 void OnApplicationQuit()
 {
     if (_connection != IntPtr.Zero)
     {
         if (NeuronDataReader.BRGetSocketStatus(_connection) != SocketStatus.CS_OffWork)
         {
             // disconnect
             NeuronDataReader.BRCloseSocket(_connection);
             _connection = IntPtr.Zero;
         }
     }
 }
 private void btnCmdFetches_Click(object sender, RoutedEventArgs e)
 {
     if (sockTCPRef != IntPtr.Zero)
     {
         if (_currentCommandId == CmdId.Cmd_AvatarCount)
         {
             NeuronDataReader.BRCommandFetchDataFromServer(sockTCPRef, _currentCommandId);
         }
         else
         {
             NeuronDataReader.BRCommandFetchAvatarDataFromServer(sockTCPRef, 0, _currentCommandId);
         }
     }
 }
        private void Window_Closed(object sender, EventArgs e)
        {
            if (sockTCPRef != IntPtr.Zero)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef);
                sockTCPRef = IntPtr.Zero;
            }

            if (sockUDPRef != IntPtr.Zero)
            {
                NeuronDataReader.BRCloseSocket(sockUDPRef);
                sockUDPRef = IntPtr.Zero;
            }
        }
        private void btnExitWindows(object sender, RoutedEventArgs e)
        {
            //添加状态判断,当TCP服务未断开时直接点击exit,会先关闭TCP连接再退出,避免程序崩溃
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef);
            }
            //添加状态判断,当UDP服务未断开时直接点击exit,会先关闭UDP连接再退出,避免程序崩溃
            if (sockUDPRef != IntPtr.Zero)
            {
                NeuronDataReader.BRCloseSocket(sockUDPRef);
            }

            Environment.Exit(0);    //立即
        }
Exemplo n.º 10
0
        static void DestroyConnection(NeuronSource source)
        {
            if (source != null)
            {
                if (source.commandSocketReference != IntPtr.Zero)
                {
                    commandSocketReferenceIndex.Remove(source.commandSocketReference);
                }

                source.OnDestroy();

                Guid       guid                   = source.guid;
                string     address                = source.address;
                int        port                   = source.port;
                int        commandServerPort      = source.commandServerPort;
                SocketType socketType             = source.socketType;
                IntPtr     socketReference        = source.socketReference;
                IntPtr     commandSocketReference = source.commandSocketReference;

                connections.Remove(guid);
                socketReferencesIndex.Remove(socketReference);

                if (commandSocketReference != IntPtr.Zero)
                {
                    NeuronDataReader.BRCloseSocket(commandSocketReference);
                    Debug.Log(string.Format("[NeuronConnection] Disconnected from command server {0}:{1}.", address,
                                            commandServerPort));
                }

                if (socketType == SocketType.TCP)
                {
                    NeuronDataReader.BRCloseSocket(socketReference);
                    Debug.Log(string.Format("[NeuronConnection] Disconnected from {0}:{1}.", address, port));
                }
                else
                {
                    NeuronDataReader.BRCloseSocket(socketReference);
                    Debug.Log(string.Format("[NeuronConnection] Stop listening at {0}. {1}", port,
                                            source.guid.ToString("N")));
                }
            }

            if (connections.Count == 0)
            {
                UnregisterReaderCallbacks();
            }
        }
Exemplo n.º 11
0
        static NeuronSource CreateConnection(string address, int port, SocketType socketType)
        {
            // Try to make connection with using the native plugin.
            var socket = IntPtr.Zero;

            if (socketType == SocketType.TCP)
            {
                socket = NeuronDataReader.BRConnectTo(address, port);

                if (socket == IntPtr.Zero)
                {
                    Debug.LogError("[Neuron] Connection failed " + address + ":" + port);
                    return(null);
                }

                Debug.Log("[Neuron] Connected " + address + ":" + port);
            }
            else
            {
                socket = NeuronDataReader.BRStartUDPServiceAt(port);

                if (socket == IntPtr.Zero)
                {
                    Debug.LogError("[Neuron] Failed listening " + port);
                    return(null);
                }

                Debug.Log("[Neuron] Started listening " + port);
            }

            // If this is the first connection, register the reader callack.
            if (_sources.Count == 0)
            {
                NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, OnFrameDataReceived);
            }

            // Create a new source.
            var source = new NeuronSource(address, port, socketType, socket);

            lock (_sourcesLock) _sources.Add(source);

            return(source);
        }
Exemplo n.º 12
0
        private void btnConnect1_Click(object sender, RoutedEventArgs e)
        {
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef1) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef1);
                sockTCPRef1 = IntPtr.Zero;

                btnConnect1.Content = "Connect";
            }
            else
            {
                sockTCPRef1 = NeuronDataReader.BRConnectTo(txtIP1.Text, int.Parse(txtPort1.Text));
                if (sockTCPRef1 == IntPtr.Zero)
                {
                    string msg = NeuronDataReader.strBRGetLastErrorMessage();
                    MessageBox.Show(msg, "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                btnConnect1.Content = "Disconnect";

                _frameCount1 = 0;
            }
        }
Exemplo n.º 13
0
        private void Window_Loaded(object sender, RoutedEventArgs e)    //在程序加载期间做一些初始化操作
        {
            _DataReceived = new FrameDataReceived(bvhDataReceived);
            NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, _DataReceived);

            _CalcDataReceived = new FrameDataReceived(calcDataReceived);
            NeuronDataReader.BRRegisterCalculationDataCallback(IntPtr.Zero, _CalcDataReceived);

            _SocketStatusChanged = new SocketStatusChanged(socketStatusChanged);
            NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, _SocketStatusChanged);

            // 更新接收BVH数据时的BoneID界面UI
            {
                cbBoneID.Items.Clear();
                for (int i = 0; i < 59; i++)
                {
                    string Bone = "Bone";
                    Bone += i.ToString();
                    Bone += "\n";
                    cbBoneID.Items.Add(Bone);
                }
                cbBoneID.SelectedIndex = 0;
            }

            // 更新接收Calc数据时的BoneID界面UI
            {
                cbBoneID2.Items.Clear();
                for (int i = 0; i < 21; i++)
                {
                    string Bone = "Bone";
                    Bone += i.ToString();
                    Bone += "\n";
                    cbBoneID2.Items.Add(Bone);
                }
                cbBoneID2.SelectedIndex = 0;
            }
        }
Exemplo n.º 14
0
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            if (NeuronDataReader.BRGetSocketStatus(sockTCPRef) == SocketStatus.CS_Running)
            {
                NeuronDataReader.BRCloseSocket(sockTCPRef);
                sockTCPRef = IntPtr.Zero;

                btnConnect.Content = "Connect";
            }
            else
            {
                sockTCPRef = NeuronDataReader.BRConnectTo(txtIP.Text, int.Parse(txtPort.Text));
                if (sockTCPRef == IntPtr.Zero)
                {
                    string msg = NeuronDataReader.strBRGetLastErrorMessage();
                    MessageBox.Show(msg, "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                NeuronDataReader.BRRegisterAutoSyncParmeter(sockTCPRef, CmdId.Cmd_AvatarCount);
                btnConnect.Content = "Disconnect";

                _frameCount = 0;
            }
        }
Exemplo n.º 15
0
    static NeuronSource CreateConnection(string address, int port, int commandServerPort, NeuronConnection.SocketType socketType)
    {
        NeuronSource source                 = null;
        IntPtr       socketReference        = IntPtr.Zero;
        IntPtr       commandSocketReference = IntPtr.Zero;

        if (socketType == NeuronConnection.SocketType.TCP)
        {
            socketReference = NeuronDataReader.BRConnectTo(address, port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Connected to {0}:{1}.", address, port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Connecting to {0}:{1} failed.", address, port));
                }
            }
        }
        else
        {
            socketReference = NeuronDataReader.BRStartUDPServiceAt(port);
            if (socketReference != IntPtr.Zero)
            {
                if (bDebugLog)
                {
                    Debug.Log(string.Format("[NeuronConnection] Start listening at {0}.", port));
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.LogError(string.Format("[NeuronConnection] Start listening at {0} failed.", port));
                }
            }
        }

        if (socketReference != IntPtr.Zero)
        {
            if (commandServerPort > 0)
            {
                // connect to command server
                commandSocketReference = NeuronDataReader.BRConnectTo(address, commandServerPort);
                if (commandSocketReference != IntPtr.Zero)
                {
                    if (bDebugLog)
                    {
                        Debug.Log(string.Format("[NeuronConnection] Connected to command server {0}:{1}.", address, commandServerPort));
                    }
                }
                else
                {
                    if (bDebugLog)
                    {
                        Debug.LogError(string.Format("[NeuronConnection] Connected to command server {0}:{1} failed.", address, commandServerPort));
                    }
                }
            }

            source = new NeuronSource(address, port, commandServerPort, socketType, socketReference, commandSocketReference);
        }

        return(source);
    }
Exemplo n.º 16
0
 public void QueryCombinationMode(int actorID)
 {
     NeuronDataReader.BRCommandFetchAvatarDataFromServer(commandSocketReference, actorID, CmdId.Cmd_CombinationMode);
 }
Exemplo n.º 17
0
 public void QueryBoneSizes(int actorID)
 {
     NeuronDataReader.BRCommandFetchAvatarDataFromServer(commandSocketReference, actorID, CmdId.Cmd_BoneSize);
 }
Exemplo n.º 18
0
 public void QueryDataFrequency(int actorID)
 {
     NeuronDataReader.BRCommandFetchAvatarDataFromServer(commandSocketReference, actorID, CmdId.Cmd_DataFrequency);
 }
Exemplo n.º 19
0
 public void QueryNumOfActors()
 {
     NeuronDataReader.BRCommandFetchDataFromServer(commandSocketReference, CmdId.Cmd_AvatarCount);
 }
Exemplo n.º 20
0
        static NeuronSource CreateConnection(string address, int port, int commandServerPort, SocketType socketType)
        {
            NeuronSource source                 = null;
            IntPtr       socketReference        = IntPtr.Zero;
            IntPtr       commandSocketReference = IntPtr.Zero;

            if (socketType == SocketType.TCP)
            {
                socketReference = NeuronDataReader.BRConnectTo(address, port);
                if (socketReference != IntPtr.Zero)
                {
                    Debug.Log(string.Format("[NeuronConnection] Connected to {0}:{1}.", address, port));
                }
                else
                {
                    Debug.LogError(string.Format("[NeuronConnection] Connecting to {0}:{1} failed.", address, port));
                }
            }
            else
            {
                socketReference = NeuronDataReader.BRStartUDPServiceAt(port);
                if (socketReference != IntPtr.Zero)
                {
                    Debug.Log(string.Format("[NeuronConnection] Start listening at {0}.", port));
                }
                else
                {
                    Debug.LogError(string.Format("[NeuronConnection] Start listening at {0} failed.", port));
                }
            }

            if (socketReference != IntPtr.Zero)
            {
                if (connections.Count == 0)
                {
                    RegisterReaderCallbacks();
                }

                if (commandServerPort > 0)
                {
                    // connect to command server
                    commandSocketReference = NeuronDataReader.BRConnectTo(address, commandServerPort);
                    if (commandSocketReference != IntPtr.Zero)
                    {
                        Debug.Log(string.Format("[NeuronConnection] Connected to command server {0}:{1}.", address,
                                                commandServerPort));
                    }
                    else
                    {
                        Debug.LogError(string.Format("[NeuronConnection] Connected to command server {0}:{1} failed.",
                                                     address, commandServerPort));
                    }
                }

                source = new NeuronSource(address, port, commandServerPort, socketType, socketReference,
                                          commandSocketReference);
                connections.Add(source.guid, source);
                socketReferencesIndex.Add(socketReference, source);
                if (commandSocketReference != IntPtr.Zero)
                {
                    commandSocketReferenceIndex.Add(commandSocketReference, source);
                }
            }

            return(source);
        }
Exemplo n.º 21
0
 static void UnregisterReaderCallbacks()
 {
     NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, (CalcFrameDataReceived)null);
     NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, null);
 }
Exemplo n.º 22
0
 static void RegisterReaderCallbacks()
 {
     NeuronDataReader.BRRegisterFrameDataCallback(IntPtr.Zero, (CalcFrameDataReceived)OnFrameDataReceived);
     NeuronDataReader.BRRegisterSocketStatusCallback(IntPtr.Zero, OnSocketStatusChanged);
 }