private void WorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { // Shoe ProgressBar Dispatcher.BeginInvoke((Action) delegate() { _control.LoadingGrid.Visibility = Visibility.Visible; _control.statusLabel.Content = "Status: Loading ..."; }); if (InputPorts[0] == null || ControlElements[0] == null || InputPorts[0].Data == null) { return; } if (InputPorts[0].Data.GetType() == typeof(DtoShortProject)) { var project = InputPorts[0].Data as DtoShortProject; if (project != null) { projectId = project.Id; var topo = _controller.IntBase.ApiCore.Projects.GetTopology(project.Id); if (topo == null) { return; } var model = _controller.IntBase.ApiCore.DtObjects.GetObjectGeometryAsThreeJs(topo.Id); if (model.Objects == null) { return; } foreach (var elem in model.Objects) { var geom = new DbGeometry(); var jObject = elem.AttributeGroups["geometry"]["threejs"] as JObject; if (jObject != null) { geom.Vertices = jObject.SelectToken("vertices").ToList().Select(value => value.Value <double>()).ToList(); geom.Faces = jObject.SelectToken("faces").ToList().Select(value => value.Value <uint>()).ToList(); var colorid = (int)jObject.SelectToken("metadata")["colorid"]; var colorInteger = model.Colors[colorid]; var color = Color.FromArgb((int)colorInteger); GeometryWriter.EvaluateAndSaveGeometry(geom, elem, color); } } // model.Colors // Color c = Color.FromArgb(someInt); // var model = _controller.IntBase.APICore.DtObjects.GetObjectGeometry(topo.Id); _elements = (List <DtObject>)model.Objects; } // _elements = _controller.IntBase.APICore.GetElementsFromTopologyId(project.Id); // OutputPorts[0].Data = _elements; } if (InputPorts[0].Data.GetType() == typeof(DtoDivision)) { var dtoDivision = InputPorts[0].Data as DtoDivision; if (dtoDivision?.TopologyDivisionId != null) { var model = _controller.IntBase.ApiCore.DtObjects.GetObjectGeometryAsThreeJs((Guid)dtoDivision.TopologyDivisionId); projectId = dtoDivision.ProjectId; if (model == null) { return; } foreach (var elem in model.Objects) { var geom = new DbGeometry(); var jObject = elem.AttributeGroups["geometry"]["threejs"] as JObject; if (jObject != null) { geom.Vertices = jObject.SelectToken("vertices").ToList().Select(value => value.Value <double>()).ToList(); geom.Faces = jObject.SelectToken("faces").ToList().Select(value => value.Value <uint>()).ToList(); var colorid = (int)jObject.SelectToken("metadata")["colorid"]; var colorInteger = model.Colors[colorid]; var color = Color.FromArgb((int)colorInteger); GeometryWriter.EvaluateAndSaveGeometry(geom, elem, color); } } _elements = (List <DtObject>)model.Objects; } } doWorkEventArgs.Result = _elements; }
static void Export3DB(string mdlName, LUtfNode node3db, OutModel mdl, LUtfNode vmeshlibrary = null) { var vms = vmeshlibrary ?? new LUtfNode() { Name = "VMeshLibrary", Parent = node3db, Children = new List <LUtfNode>() }; for (int i = 0; i < mdl.LODs.Count; i++) { var n = new LUtfNode() { Name = string.Format("{0}-{1}.lod{2}.{3}.vms", mdlName, mdl.Name, i, (int)GeometryWriter.FVF(mdl.LODs[i].Geometry)), Parent = vms }; n.Children = new List <LUtfNode>(); n.Children.Add(new LUtfNode() { Name = "VMeshData", Parent = n, Data = GeometryWriter.VMeshData(mdl.LODs[i].Geometry) }); vms.Children.Add(n); } if (vmeshlibrary == null) { node3db.Children.Add(vms); } if (mdl.LODs.Count > 1) { var multilevel = new LUtfNode() { Name = "MultiLevel", Parent = node3db }; multilevel.Children = new List <LUtfNode>(); var switch2 = new LUtfNode() { Name = "Switch2", Parent = multilevel }; multilevel.Children.Add(switch2); for (int i = 0; i < mdl.LODs.Count; i++) { var n = new LUtfNode() { Name = "Level" + i, Parent = multilevel }; n.Children = new List <LUtfNode>(); n.Children.Add(new LUtfNode() { Name = "VMeshPart", Parent = n, Children = new List <LUtfNode>() }); n.Children[0].Children.Add(new LUtfNode() { Name = "VMeshRef", Parent = n.Children[0], Data = GeometryWriter.VMeshRef(mdl.LODs[i].Geometry, string.Format("{0}-{1}.lod{2}.{3}.vms", mdlName, mdl.Name, i, (int)GeometryWriter.FVF(mdl.LODs[i].Geometry))) }); multilevel.Children.Add(n); } //Generate Switch2: TODO - Be more intelligent about this var mlfloats = new float[multilevel.Children.Count]; mlfloats[0] = 0; float cutOff = 2250; for (int i = 1; i < mlfloats.Length - 1; i++) { mlfloats[i] = cutOff; cutOff *= 2; } mlfloats[mlfloats.Length - 1] = 1000000; switch2.Data = UnsafeHelpers.CastArray(mlfloats); node3db.Children.Add(multilevel); } else { var part = new LUtfNode() { Name = "VMeshPart", Parent = node3db }; part.Children = new List <LUtfNode>(); part.Children.Add(new LUtfNode() { Name = "VMeshRef", Parent = part, Data = GeometryWriter.VMeshRef(mdl.LODs[0].Geometry, string.Format("{0}-{1}.lod0.{2}.vms", mdlName, mdl.Name, (int)GeometryWriter.FVF(mdl.LODs[0].Geometry))) }); node3db.Children.Add(part); } }