private string DumpFaces(int index, DataRowView row) { string s = ""; string rects = Helper.GetPhotoString('R', row); string names = Helper.GetPhotoString('P', row); if (rects != "") { var rectsA = rects.Split(','); var namesA = names.Split(','); if (rectsA.Length == namesA.Length) { // Dump names here s += "var faces" + index + " = new Array();\r\n"; for (int i = 0; i < rectsA.Length; i++) { ulong urect; bool b = ulong.TryParse(rectsA[i], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out urect); if (!b) { s = ""; break; } Rect64 rect = new Rect64(urect, 0xffff, 0xffff); ulong t = (ulong)rect.Top; ulong l = (ulong)rect.Left; ulong w = (ulong)rect.Right - l; ulong h = (ulong)rect.Bottom - t; s += "faces" + index + "[" + i + "] = new Face('" + namesA[i].Trim() + "',true," + t + "," + l + "," + w + "," + h + ");\r\n"; } } } else if (names != "") { var namesA = names.Split(','); s += "var faces" + index + " = new Array();\r\n"; for (int i = 0; i < namesA.Length; i++) { s += "faces" + index + "[" + i + "] = new Face('" + namesA[i].Trim() + "',false,0,0,0,0);\r\n"; } } return s; }
private void Button_play_Click(object sender, RoutedEventArgs e) { // if the nester is working cancel the work if (_nester != null && _nester.IsBusy()) { _nester.CancelExecute(); Debug.WriteLine("cancelling..."); return; } // get the path of the .obj string file_path = string.Empty; OpenFileDialog open_file_dialog = new OpenFileDialog(); open_file_dialog.Filter = "Object files (*.obj; *.OBJ)|*.obj;*.OBJ"; if (open_file_dialog.ShowDialog() == true) { file_path = open_file_dialog.FileName; } // if no path then return if (string.IsNullOrEmpty(file_path)) { return; } // try to get the model data UVObjData data = null; try { data = ObjHandler.GetData(file_path); } catch { return; } // if data is null return if (data == null) { return; } // get the uv verts and triangles Vector64[] pts = data.uvs.Select(p => new Vector64(p.X, p.Y)).ToArray(); int[] tris = data.tris; // get the canvas container Rect64 container = new Rect64(0, canvas_main.Height, canvas_main.Width, 0); // create a new nester object and populate its data _nester = new Nester(); _handles = _nester.AddUVPolygons(pts, tris, 0.0); // set the nesting commands _nester.ClearCommandBuffer(); _nester.ResetTransformLib(); canvas_main.Children.Clear(); _nester.CMD_OptimalRotation(null); _nester.CMD_Nest(null, NFPQUALITY.Full); _nester.CMD_Refit(container, false, null); // change the button text and execute work button_play.Content = STOP; _nester.ExecuteCommandBuffer(NesterProgress, NesterComplete); }