Пример #1
0
        public static MeshData EncodeMesh(Mesh mesh)
        {
            MeshData meshData = new MeshData();

            foreach (Vector3 point in mesh.vertices)
            {
                meshData.vertices.Add(EncodeUtilities.EncodeLocation(point));
            }
            for (int i = 0; i < mesh.triangles.Length; i += 3)
            {
                meshData.faces.Add(new int[] {
                    mesh.triangles[i],
                    mesh.triangles[i + 1],
                    mesh.triangles[i + 2]
                });
            }
            if ((meshData.colors == null) || (meshData.colors.Count == 0))
            {
                foreach (Color color in mesh.colors)
                {
                    meshData.colors.Add(EncodeUtilities.EncodeColor(color));
                }
            }
            else
            {
                foreach (Vector3 point in mesh.vertices)
                {
                    meshData.colors.Add(EncodeUtilities.EncodeColor(Color.red));
                }
            }

            return(meshData);
        }
Пример #2
0
        // Constantly check for new messages on given port.
        private void ReceiveData()
        {
            // Open.
            this.client = new UdpClient(this.localPort);
            IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);

            // Infinite loop.
            try {
                byte[] data;
                string receiveString;
                while (true)
                {
                    // Receive Bytes.
                    data = client.Receive(ref anyIP);
                    if (data.Length > 0)
                    {
                        // If buffer not empty - decode it.
                        receiveString = EncodeUtilities.DecodeData(data);
                        // If string not empty and not read yet - react to it.
                        if (!string.IsNullOrEmpty(receiveString))
                        {
                                                        #if DEBUG2
                            DebugUtilities.UniversalDebug(this.sourceName, "Total Data found: " + receiveString, ref this.debugMessages);
                                                        #endif
                            if ((this.dataMessages.Count == 0) ||
                                (this.flagForce || (this.dataMessages[this.dataMessages.Count - 1] != receiveString)))
                            {
                                this.dataMessages.Add(receiveString);
                                this.connectionHistory.Add(anyIP.Address.ToString());
                                this.flagDataRead = false;
                                if (OnReceive != null)
                                {
                                    OnReceive();
                                }
                            }
                            else
                            {
                                                                #if DEBUG2
                                DebugUtilities.UniversalDebug(this.sourceName, "Message already added.", ref this.debugMessages);
                                                                #endif
                            }
                        }
                    }
                }
            } catch (SocketException exception) {
                // SocketException.
                                #if DEBUGWARNING
                DebugUtilities.UniversalWarning(this.sourceName, "SocketException: " + exception.ToString(), ref this.debugMessages);
                                #endif
            } catch (Exception exception) {
                // Exception.
                                #if DEBUGWARNING
                DebugUtilities.UniversalWarning(this.sourceName, "Exception: " + exception.ToString(), ref this.debugMessages);
                                #endif
            } finally {
                this.Disconnect();
            }
        }
Пример #3
0
        //////////////////////////////////////////////////////////////////////////
        // React to a value change.
        public void OnValueChanged()
        {
            if (UDPReceiveComponent.flagUICommunicationStarted)
            {
                                #if DEBUG
                Debug.Log("ParameterUIMenu: Updating UI values.");
                                #endif
                // Find Objects.
                GameObject[] goBooleans = GameObject.FindGameObjectsWithTag(this.tagUIItemBoolean);
                GameObject[] goCounters = GameObject.FindGameObjectsWithTag(this.tagUIItemCounter);
                GameObject[] goSliders  = GameObject.FindGameObjectsWithTag(this.tagUIItemSlider);
                                #if DEBUG
                Debug.Log("ParameterUIMenu: Found items: booleans: " + goBooleans.Length + ", counters: " + goCounters.Length + ", sliders: " + goSliders.Length);
                                #endif

                // Extract data.
                List <bool>  bools  = new List <bool>();
                List <int>   ints   = new List <int>();
                List <float> floats = new List <float>();
                foreach (GameObject goItem in goBooleans)
                {
                    bools.Add(goItem.GetComponent <BooleanToggle>().value);
                }
                foreach (GameObject goItem in goCounters)
                {
                    ints.Add(goItem.GetComponent <Counter>().value);
                }
                foreach (GameObject goItem in goSliders)
                {
                    floats.Add(goItem.GetComponent <FloatSlider>().value);
                }
                UIData ui = new UIData(bools, ints, floats);

                // Encode and if changed - send it.
                byte[] data = EncodeUtilities.EncodeData("UIDATA", ui, out string currentMessage);
                if (ParameterUIMenu.lastMessage != currentMessage)                   // TODO: Technically not necessary now since we call directly from UI elements themselves.
                {
                    ParameterUIMenu.lastMessage = currentMessage;
                                        #if DEBUG
                    Debug.Log("ParameterUIMenu: values changed, sending: " + currentMessage);
                                        #endif

                    if (ParameterUIMenu.sender == null)
                    {
                        ParameterUIMenu.sender = FindObjectOfType <UDPSendComponent>();
                    }
                    if (ParameterUIMenu.sender == null)
                    {
                                                #if DEBUGWARNING
                        Debug.Log("ParameterUIMenu: No sender Found.");
                                                #endif
                        return;
                    }
                    ParameterUIMenu.sender.SendUI(data);
                }
            }
        }
Пример #4
0
        // Encode a Mesh with a Color.
        public static MeshData EncodeMesh(Mesh _mesh, Color _color)
        {
            MeshData meshData = EncodeMesh(_mesh);

            meshData.colors = new List <int[]>()
            {
                EncodeUtilities.EncodeColor(_color)
            };
            return(meshData);
        }
 /////////////////////////////////////////////////////////////////////////////
 // A function responsible for decoding and reacting to received UDP data.
 private bool InterpreteData(string message)
 {
     if (!string.IsNullOrEmpty(message))
     {
         message = EncodeUtilities.StripSplitter(message);
         if (this.lastMessage != message)
         {
             this.lastMessage = message;
                                 #if DEBUG
             DebugUtilities.UniversalDebug(this.sourceName, "New message found: " + message);
                                 #endif
             string[] messageComponents = message.Split(new string[] { EncodeUtilities.headerSplitter }, 2, StringSplitOptions.RemoveEmptyEntries);
             if (messageComponents.Length > 1)
             {
                 string header = messageComponents[0], content = messageComponents[1];
                                         #if DEBUG
                 DebugUtilities.UniversalDebug(this.sourceName, "Header: " + header + ", content: " + content);
                                         #endif
                 if (header == "MESHSTREAMING")
                 {
                     InterpreteMesh(content, SourceType.UDP);
                     return(true);
                 }
                 else if (header == "CONTROLLER")
                 {
                     InterpreteRobotController(content);
                     return(true);
                 }
                 else if (header == "HOLOTAG")
                 {
                     InterpreteTag(content);
                     return(true);
                 }
                 else if (header == "IPADDRESS")
                 {
                     InterpreteIPAddress(content);
                     return(true);
                 }
                 else
                 {
                                                 #if DEBUGWARNING
                     DebugUtilities.UniversalWarning(this.sourceName, "Header Not Recognized");
                                                 #endif
                 }
             }
             else
             {
                                         #if DEBUGWARNING
                 DebugUtilities.UniversalWarning(this.sourceName, "Improper message");
                                         #endif
             }
         }
     }
     return(true);           // Since we have one interpreter anyway
 }
Пример #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            List <RobotData> inputRobots = new List <RobotData>();
            Connection       connect     = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetData <Connection>(1, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.

                // Send robot data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOBOTS", inputRobots.ToArray(), out string currentMessage);
                if (this.flagForce || (this.lastMessage != currentMessage))
                {
                    connect.tcpSender.QueueUpData(bytes);
                    //bool success = connect.tcpSender.flagSuccess;
                    //string message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count-1];
                    //if (success)
                    //	this.lastMessage = currentMessage;
                    //UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, RobotStreaming.debugMessages[RobotStreaming.debugMessages.Count - 1]);
                        #endif

            // Expire Solution.
            if ((connect.status) && (connect.PendingMessages))
            {
                GH_Document document = this.OnPingDocument();
                if (document != null)
                {
                    document.ScheduleSolution(RobotStreaming.expireDelay, ScheduleCallback);
                }
            }
        }
Пример #7
0
        // Collect environment meshes
        public List <byte[]> EncodeEnvironmentMesh(out string currentMessage)
        {
            currentMessage = string.Empty;
            List <byte[]> data = new List <byte[]>();

            FindMeshes();
            if (this.scannedEnvironment.Count > 0)
            {
                // Combine meshes
                CombineInstance[] combineStructure = new CombineInstance[this.scannedEnvironment.Count];
                int i = 0;
                foreach (MeshRenderer meshRenderer in this.scannedEnvironment)
                {
                    MeshFilter meshFilter = meshRenderer.gameObject.GetComponent <MeshFilter>();
                    combineStructure[i].mesh      = meshFilter.sharedMesh;
                    combineStructure[i].transform = meshRenderer.transform.localToWorldMatrix;
                    i++;
                }
                Mesh mesh = new Mesh();
                mesh.CombineMeshes(combineStructure);

                // Encode mesh
                MeshData meshData  = MeshUtilities.EncodeMesh(mesh);
                byte[]   localData = EncodeUtilities.EncodeData("ENVIRONMENT", meshData, out string currentLocalMessage);
                data.Add(localData);
                                #if DEBUG
                DebugUtilities.UniversalDebug(this.sourceName, "Mesh Encoding: " + currentLocalMessage);
                                #endif
                currentMessage = currentLocalMessage;

                // // Encode meshes separately
                // // {
                // //   MeshRenderer meshRenderer = this.scannedEnvironment[0];
                // foreach (MeshRenderer meshRenderer in this.scannedEnvironment) {
                //  MeshFilter meshFilter = meshRenderer.gameObject.GetComponent<MeshFilter>();
                //  MeshData meshData = MeshUtilities.EncodeMesh(meshFilter.sharedMesh);
                //  byte[] localData = EncodeUtilities.EncodeData("ENVIRONMENT", meshData, out string currentLocalMessage);
                //  #if DEBUG
                //  DebugUtilities.UniversalDebug(this.sourceName, "Mesh Encoding: " + currentLocalMessage);
                //  #endif
                //  data.Add(localData);
                //  currentMessage += currentLocalMessage;
                // }
            }
            else
            {
                                #if DEBUG
                DebugUtilities.UniversalDebug(this.sourceName, "No meshes found.");
                                #endif
            }

            return(data);
        }
        // - RobotControllers
        private void InterpreteRobotController(string data)
        {
            List <RobotControllerData> controllersData = EncodeUtilities.InterpreteRobotController(data);

            RobotProcessor processor = ObjectManager.instance.GetComponent <RobotProcessor>();

            foreach (RobotControllerData controllerData in controllersData)
            {
                if (processor.robotsInstantiated.ContainsKey(controllerData.robotID))
                {
                    processor.robotsInstantiated[controllerData.robotID].GetComponentInChildren <RobotController>().ProcessRobotController(controllerData);
                }
            }
        }
        // - IP address
        private void InterpreteIPAddress(string data)
        {
            string remoteIP = EncodeUtilities.InterpreteIPAddress(data);

                        #if DEBUG
            DebugUtilities.UniversalDebug(this.sourceName, "Remote IP: " + remoteIP);
                        #endif
            // TODO: Add ip integrity check
            // TODO: Should not be stored in udp sender.
            UDPSendComponent sender = gameObject.GetComponent <UDPSendComponent>();
            sender.remoteIP = remoteIP;
            UDPReceiveComponent.flagUICommunicationStarted = true;
            // Inform UI Manager.
            ParameterUIMenu.instance.OnValueChanged();
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            List <RobotData> inputRobots = new List <RobotData>();
            Connection       connect     = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetData(1, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.

                // Send robot data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOBOTS", inputRobots.ToArray(), out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    connect.tcpSender.Send(bytes);
                    bool   success = connect.tcpSender.success;
                    string message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count - 1];
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, RobotStreaming.debugMessages[RobotStreaming.debugMessages.Count - 1]);
                        #endif
        }
Пример #11
0
        private void OnClientFound()
        {
            this.flagConnectionFound = true;
            byte[] buffer = new byte[bufferSize];

            // Receive Bytes.
            int dataLengthToRead = this.stream.Read(buffer, 0, buffer.Length);

            while ((dataLengthToRead != 0) && (!this.currentHistory.Contains(EncodeUtilities.messageSplitter)))
            {
                this.currentHistory += EncodeUtilities.DecodeData(buffer, 0, dataLengthToRead);
                dataLengthToRead     = this.stream.Read(buffer, 0, buffer.Length);
            }
            if (this.currentHistory.Contains(EncodeUtilities.messageSplitter))
            {
                ReactToMessage();
            }
        }
Пример #12
0
        // Constantly check for new messages on given port.
        private void ReceiveData()
        {
            IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);

            byte[] data;
            string receiveString;

            try {
                // Receive Bytes.
                data = this.client.Receive(ref anyIP);
                if (data.Length > 0)
                {
                    // If buffer not empty - decode it.
                    receiveString = EncodeUtilities.DecodeData(data);
                    // If string not empty and not read yet - react to it.
                    if (!string.IsNullOrEmpty(receiveString))
                    {
                                                #if DEBUG2
                        DebugUtilities.UniversalDebug(this.sourceName, "Total Data found: " + receiveString, ref this.debugMessages);
                                                #endif
                        this.dataMessages.Enqueue(receiveString);
                        this.connectionHistory.Enqueue(anyIP.Address.ToString());
                        if (OnReceive != null)
                        {
                            OnReceive();
                        }
                    }
                }
            } catch (SocketException exception) {
                // SocketException.
                                #if DEBUGWARNING
                DebugUtilities.UniversalWarning(this.sourceName, "SocketException: " + exception.ToString(), ref this.debugMessages);
                                #endif
            } catch (Exception exception) {
                // Exception.
                                #if DEBUGWARNING
                DebugUtilities.UniversalWarning(this.sourceName, "Exception: " + exception.ToString(), ref this.debugMessages);
                                #endif
            }
        }
Пример #13
0
        //////////////////////////////////////////////////////////////////////////////
        #region RhinoOnly
                #if !(UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS || WINDOWS_UWP)
        // Encode a Mesh.
        public static MeshData EncodeMesh(Mesh _mesh)
        {
            MeshData meshData = new MeshData();

            for (int i = 0; i < _mesh.Vertices.Count; i++)
            {
                meshData.vertices.Add(EncodeUtilities.EncodeLocation(_mesh.Vertices[i]));
            }

            for (int i = 0; i < _mesh.Faces.Count; i++)
            {
                if (!_mesh.Faces[i].IsQuad)
                {
                    meshData.faces.Add(new int[] { 0, _mesh.Faces[i].A, _mesh.Faces[i].B, _mesh.Faces[i].C });
                }
                else
                {
                    meshData.faces.Add(new int[] { 1, _mesh.Faces[i].A, _mesh.Faces[i].B, _mesh.Faces[i].C, _mesh.Faces[i].D });
                }
            }

            return(meshData);
        }
        // - IP address
        private void InterpreteIPAddress(string data)
        {
            string remoteIP = EncodeUtilities.InterpreteIPAddress(data);

                        #if DEBUG
            DebugUtilities.UniversalDebug(this.sourceName, "Remote IP: " + remoteIP);
                        #endif
            // TODO: Add ip integrity check

            // - UDP
            // TODO: Should not be stored in udp sender.
            UDPSendComponent udpSender = gameObject.GetComponent <UDPSendComponent>();
            if (udpSender != null)
            {
                udpSender.remoteIP = remoteIP;
                UDPReceiveComponent.flagUICommunicationStarted = true;
                // Inform UI Manager.
                ParameterUIMenu.instance.OnValueChanged();
            }

            // - TCP
            TCPSendComponent tcpSender = gameObject.GetComponent <TCPSendComponent>();
                        #if DEBUG
            DebugUtilities.UniversalDebug(this.sourceName, "Tcp sender found. Sending mesh to: " + remoteIP);
                        #endif
            if (tcpSender != null)
            {
                tcpSender.UpdateIP(remoteIP);
                // byte[] environmentData = ObjectManager.instance.EnvironmentMesh();
                // // Echo Environment Mesh
                // if (environmentData != null) {
                //  tcpSender.remoteIP = remoteIP;
                //  tcpSender.SendMesh(environmentData);
                //  UDPReceiveComponent.flagEnvironmentSent = true;
                // }
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            Connection connect = null;

            if (!DA.GetData(0, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                if (!UIReceiver.flagProcessed)
                {
                    UIReceiver.flagProcessed = true;
                    // Send local IPAddress for device to communicate back.
                    byte[] bytes = EncodeUtilities.EncodeData("IPADDRESS", NetworkUtilities.LocalIPAddress(), out string currentMessage);
                    connect.udpSender.Send(bytes);
                    bool success = connect.udpSender.success;
                    UniversalDebug("Sent local IP.");
                }

                // Prepare to receive UI data.
                try {
                    if (!connect.udpReceiver.flagDataRead)
                    {
                        connect.udpReceiver.flagDataRead = true;
                        UIReceiver.currentInput          = connect.udpReceiver.dataMessages[connect.udpReceiver.dataMessages.Count - 1];
                        if (UIReceiver.lastInputs != currentInput)
                        {
                            currentInput          = EncodeUtilities.StripSplitter(currentInput);
                            UIReceiver.lastInputs = currentInput;
                            UniversalDebug("New Message without Message Splitter removed: " + currentInput);
                            string[] messageComponents = currentInput.Split(new string[] { EncodeUtilities.headerSplitter }, 2, StringSplitOptions.RemoveEmptyEntries);
                            if (messageComponents.Length > 1)
                            {
                                string header = messageComponents[0], content = messageComponents[1];
                                UniversalDebug("Header: " + header + ", content: " + content);
                                if (header == "UIDATA")
                                {
                                    // If any new data received - process it.
                                    UIData data = JsonConvert.DeserializeObject <UIData>(content);
                                    UIReceiver.currentBools  = new List <bool> (data.bools);
                                    UIReceiver.currentInts   = new List <int> (data.ints);
                                    UIReceiver.currentFloats = new List <float> (data.floats);
                                    UniversalDebug("Data Received!");
                                }
                                else
                                {
                                    UniversalDebug("Header Not Recognized!", GH_RuntimeMessageLevel.Warning);
                                }
                            }
                            else
                            {
                                UniversalDebug("Data not Received!", GH_RuntimeMessageLevel.Warning);
                            }
                        }
                        else
                        {
                            UniversalDebug("Improper Message!", GH_RuntimeMessageLevel.Warning);
                        }
                    }
                    else
                    {
                        UniversalDebug("No data received.");
                    }
                } catch {
                    UniversalDebug("Error Processing Data.", GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                // If connection disabled - stop receiving.
                UIReceiver.flagProcessed = false;
                UIReceiver.lastInputs    = string.Empty;
                UIReceiver.currentBools  = new List <bool>();
                UIReceiver.currentInts   = new List <int>();
                UIReceiver.currentFloats = new List <float>();
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
            DA.SetDataList(0, UIReceiver.currentBools);
            DA.SetDataList(1, UIReceiver.currentInts);
            DA.SetDataList(2, UIReceiver.currentFloats);
                        #if DEBUG
            DA.SetData(3, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif

            // Expire Solution.
            if (connect.status)
            {
                GH_Document document = this.OnPingDocument();
                if (document != null)
                {
                    document.ScheduleSolution(UIReceiver.expireDelay, ScheduleCallback);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            string inputRobotName       = "";
            Mesh   inputEndeffectorMesh = new Mesh();
            int    inputRobotID         = 0;
            Plane  inputPlane           = this.defaultPlane;

            if (!DA.GetData(0, ref inputRobotName))
            {
                RobotOptionList();
            }
            DA.GetData(1, ref inputEndeffectorMesh);
            DA.GetData(2, ref inputRobotID);
            DA.GetData(3, ref inputPlane);
            //////////////////////////////////////////////////////
            // Process data.
            inputEndeffectorMesh.Weld(Math.PI);
            EndeffectorData endEffector = new EndeffectorData(MeshUtilities.EncodeMesh(inputEndeffectorMesh));
            RobotData       robot       = new RobotData(inputRobotID, inputRobotName, endEffector, EncodeUtilities.EncodePlane(inputPlane));

            UniversalDebug("Robot Object Created.");
            //////////////////////////////////////////////////////
            // Output.
            DA.SetData(0, robot);
                        #if DEBUG
            DA.SetData(1, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            List <string>  inputText          = new List <string>();
            List <Point3d> inputTextLocations = new List <Point3d>();
            List <double>  inputTextSize      = new List <double>();
            List <Color>   inputTextColor     = new List <Color>();
            Connection     connect            = null;

            if (!DA.GetDataList(0, inputText))
            {
                return;
            }
            if (!DA.GetDataList(1, inputTextLocations))
            {
                return;
            }
            DA.GetDataList(2, inputTextSize);
            DA.GetDataList(3, inputTextColor);
            if (!DA.GetData <Connection>(4, ref connect))
            {
                return;
            }
            // Check inputs.
            if (inputTextLocations.Count != inputText.Count)
            {
                UniversalDebug("The number of 'tag locations' and 'tag texts' should be equal.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            if ((inputTextSize.Count > 1) && (inputTextSize.Count != inputText.Count))
            {
                UniversalDebug("The number of 'tag text sizes' should be one or equal to one or the number of 'tag texts'.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            if ((inputTextColor.Count > 1) && (inputTextColor.Count != inputText.Count))
            {
                UniversalDebug("The number of 'tag text colors' should be one or equal to one or the number of 'tag texts'.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                List <string> currentTexts = new List <string>()
                {
                };
                List <float[]> currentTextLocations = new List <float[]>()
                {
                };
                List <float> currentTextSizes = new List <float>()
                {
                };
                List <int[]> currentTextColors = new List <int[]>()
                {
                };
                for (int i = 0; i < inputText.Count; i++)
                {
                    float currentSize  = (float)((inputTextSize.Count > 1) ? inputTextSize[i] : inputTextSize[0]);
                    Color currentColor = (inputTextColor.Count > 1) ? inputTextColor[i] : inputTextColor[0];
                    currentTexts.Add(inputText[i]);
                    currentTextLocations.Add(EncodeUtilities.EncodeLocation(inputTextLocations[i]));
                    currentTextSizes.Add((float)Math.Round(currentSize / 1000.0, 3));
                    currentTextColors.Add(EncodeUtilities.EncodeColor(currentColor));
                }
                LabelData tags = new LabelData(currentTexts, currentTextLocations, currentTextSizes, currentTextColors);

                // Send tag data.
                byte[] bytes = EncodeUtilities.EncodeData("HOLOTAG", tags, out string currentMessage);
                if (this.flagForce || (this.lastMessage != currentMessage))
                {
                    connect.udpSender.QueueUpData(bytes);
                    //bool success = connect.udpSender.flagSuccess;
                    //string message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count-1];
                    //if (success)
                    //	this.lastMessage = currentMessage;
                    //UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif

            //// Expire Solution.
            //if ((connect.status) && (connect.PendingMessages)) {
            //	GH_Document document = this.OnPingDocument();
            //	if (document != null)
            //		document.ScheduleSolution(HoloTag.expireDelay, ScheduleCallback);
            //}
        }
Пример #18
0
 // - HoloBots
 private void InterpreteHoloBots(string data)
 {
     ObjectManager.instance.GetComponent <RobotProcessor>().ProcessRobot(EncodeUtilities.InterpreteHoloBots(data));
 }
Пример #19
0
 // Functions to interprete and react to determined type of messages: // TODO: Join with UDP interpreters?
 // - Mesh
 private void InterpreteMesh(string data, SourceType meshSourceType)
 {
     ObjectManager.instance.GetComponent <MeshProcessor>().ProcessMesh(EncodeUtilities.InterpreteMesh(data), meshSourceType);
 }
Пример #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //CheckType();
            // Get inputs.
            string       message;
            List <Mesh>  inputMeshes = new List <Mesh>();
            List <Color> inputColor  = new List <Color>();
            Connection   connect     = null;

            if (!DA.GetDataList(0, inputMeshes))
            {
                return;
            }
            DA.GetDataList(1, inputColor);
            if (!DA.GetData(2, ref connect))
            {
                return;
            }
            // Check inputs.
            if ((inputColor.Count > 1) && (inputColor.Count != inputMeshes.Count))
            {
                message = (inputColor.Count > inputMeshes.Count) ?
                          "The number of Colors does not match the number of Mesh objects. Extra colors will be ignored." :
                          "The number of Colors does not match the number of Mesh objects. The last color will be repeated.";
                UniversalDebug(message, GH_RuntimeMessageLevel.Warning);
            }
            ////////////////////////////////////////////////////////////////////

            // If connection open start acting.
            if (connect.status)
            {
                // Encode mesh data.
                List <MeshData> inputMeshData = new List <MeshData> {
                };
                for (int i = 0; i < inputMeshes.Count; i++)
                {
                    Color currentColor = inputColor[Math.Min(i, inputColor.Count)];
                    inputMeshData.Add(MeshUtilities.EncodeMesh(inputMeshes[i], currentColor));
                }
                // Send mesh data.
                byte[] bytes = EncodeUtilities.EncodeData("MESHSTREAMING", inputMeshData, out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    bool success = false;
                    if (this.sourceType == SourceType.TCP)
                    {
                        connect.tcpSender.Send(bytes);
                        success = connect.tcpSender.success;
                        message = connect.tcpSender.debugMessages[connect.tcpSender.debugMessages.Count - 1];
                    }
                    else
                    {
                        connect.udpSender.Send(bytes);
                        success = connect.udpSender.success;
                        message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count - 1];
                    }
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }

            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }
Пример #21
0
 // - Tag
 private void InterpreteTag(string data)
 {
     ObjectManager.instance.GetComponent <TagProcessor>().ProcessTag(EncodeUtilities.InterpreteTag(data));
 }
Пример #22
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            Connection connect = null;

            if (!DA.GetData(0, ref connect))
            {
                return;
            }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                // Prepare to receive UI data.
                try {
                    if (connect.udpReceiver.dataMessages.Count > 0)
                    {
                        UIReceiver.currentInput = connect.udpReceiver.dataMessages.Peek();
                        UIReceiver.currentInput = EncodeUtilities.StripSplitter(UIReceiver.currentInput);
                        if (UIReceiver.lastInputs != UIReceiver.currentInput)
                        {
                            UIReceiver.lastInputs = UIReceiver.currentInput;
                            UniversalDebug("New Message without Message Splitter removed: " + currentInput);
                            string[] messageComponents = UIReceiver.currentInput.Split(new string[] { EncodeUtilities.headerSplitter }, 2, StringSplitOptions.RemoveEmptyEntries);
                            if (messageComponents.Length > 1)
                            {
                                string header = messageComponents[0], content = messageComponents[1];
                                UniversalDebug("Header: " + header + ", content: " + content);
                                if (header == "UIDATA")
                                {
                                    // If any new data received - process it.
                                    UIData data = JsonConvert.DeserializeObject <UIData>(content);
                                    UIReceiver.currentBools  = new List <bool> (data.bools);
                                    UIReceiver.currentInts   = new List <int> (data.ints);
                                    UIReceiver.currentFloats = new List <float> (data.floats);
                                    UniversalDebug("Data Received!");
                                    connect.udpReceiver.dataMessages.Dequeue();                                     // Actually remove from the queue since it has been processed.
                                }
                                // else
                                //	UniversalDebug("Header Not Recognized!", GH_RuntimeMessageLevel.Warning);
                            }
                            else
                            {
                                UniversalDebug("Data not Received!", GH_RuntimeMessageLevel.Warning);
                            }
                        }
                        else
                        {
                            UniversalDebug("Improper Message!", GH_RuntimeMessageLevel.Warning);
                        }
                    }
                    else
                    {
                        UniversalDebug("No data received.");
                    }
                } catch {
                    UniversalDebug("Error Processing Data.", GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                // If connection disabled - reset memoty.
                UIReceiver.lastInputs    = string.Empty;
                UIReceiver.currentBools  = new List <bool>();
                UIReceiver.currentInts   = new List <int>();
                UIReceiver.currentFloats = new List <float>();
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
            DA.SetDataList(0, UIReceiver.currentBools);
            DA.SetDataList(1, UIReceiver.currentInts);
            DA.SetDataList(2, UIReceiver.currentFloats);
                        #if DEBUG
            DA.SetData(3, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif

            //// Expire Solution.
            //if (connect.status) {
            //	GH_Document document = this.OnPingDocument();
            //	if (document != null)
            //		document.ScheduleSolution(UIReceiver.expireDelay, ScheduleCallback);
            //}
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            List <RobotData>         inputRobots     = new List <RobotData>();
            GH_Structure <GH_Number> inputAxisAngles = new GH_Structure <GH_Number> {
            };
            Connection connect = null;

            if (!DA.GetDataList(0, inputRobots))
            {
                return;
            }
            if (!DA.GetDataTree(1, out inputAxisAngles))
            {
                return;
            }
            if (!DA.GetData(2, ref connect))
            {
                return;
            }
            // Check inputs.
            if ((inputAxisAngles.Paths.Count > 1) && (inputAxisAngles.Paths.Count != inputRobots.Count))
            {
                UniversalDebug("The number of Branches of Axis Angles should be one or equal to the number of HoloBot objects.",
                               GH_RuntimeMessageLevel.Error);
                return;
            }
            // if (inputAxisAngles.Count != 6) {
            //  Positioner.debugMessages.Add("Component: Controller: The number of Axis should be equal to the number of Robot Joints.");
            //  return;
            // }
            //////////////////////////////////////////////////////
            // Process data.
            if (connect.status)
            {
                // If connection open start acting.
                UniversalDebug("Robots Found: " + inputRobots.Count + ", Axis Count, " + inputAxisAngles.Paths.Count);
                List <RobotControllerData> robotControllers = new List <RobotControllerData>();
                for (int i = 0; i < inputRobots.Count; i++)
                {
                    List <double> currentRobotAxisValues = new List <double> {
                    };
                    int index = (inputAxisAngles.Paths.Count > 1) ? i : 0;
                    Console.WriteLine(index);
                    double currentValue;
                    for (int j = 0; j < inputAxisAngles[index].Count; j++)
                    {
                        currentValue = (double)inputAxisAngles[index][j].Value;
                        currentRobotAxisValues.Add(currentValue * (180.0 / Math.PI));
                    }
                    robotControllers.Add(new RobotControllerData(inputRobots[i].robotID, currentRobotAxisValues));
                }

                // Send robot controller data.
                byte[] bytes = EncodeUtilities.EncodeData("CONTROLLER", robotControllers, out string currentMessage);
                if (this.lastMessage != currentMessage)
                {
                    connect.udpSender.Send(bytes);
                    bool   success = connect.udpSender.success;
                    string message = connect.udpSender.debugMessages[connect.udpSender.debugMessages.Count - 1];
                    if (success)
                    {
                        this.lastMessage = currentMessage;
                    }
                    UniversalDebug(message, (success) ? GH_RuntimeMessageLevel.Remark : GH_RuntimeMessageLevel.Error);
                }
            }
            else
            {
                this.lastMessage = string.Empty;
                UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'.", GH_RuntimeMessageLevel.Warning);
            }
            //////////////////////////////////////////////////////
            // Output.
                        #if DEBUG
            DA.SetData(0, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }