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); }
// 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); }
/// <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); //} }