Exemplo n.º 1
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
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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
        }