/// <summary> /// Use the render description returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a render description and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> private void RenderDrawables(VisualizationEventArgs e) { //Debug.WriteLine(string.Format("Rendering full screen Watch3D on thread {0}.", System.Threading.Thread.CurrentThread.ManagedThreadId)); //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } var rd = e.Description; HelixPoints = null; HelixLines = null; HelixMesh = null; HelixXAxes = null; HelixYAxes = null; HelixZAxes = null; HelixPointsSelected = null; HelixLinesSelected = null; HelixMeshSelected = null; HelixPoints = rd.Points; HelixLines = rd.Lines; HelixPointsSelected = rd.SelectedPoints; HelixLinesSelected = rd.SelectedLines; HelixXAxes = rd.XAxisPoints; HelixYAxes = rd.YAxisPoints; HelixZAxes = rd.ZAxisPoints; HelixMesh = VisualizationManager.MergeMeshes(rd.Meshes); HelixMeshSelected = VisualizationManager.MergeMeshes(rd.SelectedMeshes); }
void viz_ResultsReadyToVisualize(VisualizationEventArgs args) { if (args.Id == Guid.Empty) { return; } Assert.AreEqual(0, args.Packages.Sum(rp => rp.PointVertexCount)); }
void VisualizationManager_VisualizationUpdateComplete(object sender, VisualizationEventArgs e) { Dispatcher.Invoke(new Action(delegate { var node = DataContext as Watch3D; if (node != null) { node.GetBranchVisualizationCommand.Execute(null); } })); }
/// <summary> /// Handler for the visualization manager's ResultsReadyToVisualize event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VisualizationManager_ResultsReadyToVisualize(object sender, VisualizationEventArgs e) { if (CheckAccess()) { RenderDrawables(e); } else { // Scheduler invokes ResultsReadyToVisualize on background thread. Dispatcher.BeginInvoke(new Action(() => RenderDrawables(e))); } }
void VisualizationManager_VisualizationUpdateComplete(object sender, VisualizationEventArgs e) { if (dynSettings.Controller == null) { return; } if (!dynSettings.Controller.DynamoViewModel.FullscreenWatchShowing) { return; } Dispatcher.Invoke(new Action <RenderDescription>(RenderDrawables), DispatcherPriority.Render, new object[] { e.Description }); }
private void VisualizationChangedHandler(object sender, VisualizationEventArgs e) { if (!label_nowPlayingSong.Text.Equals(e.name)) { label_nowPlayingSong.Text = e.name; } if (progressBar1.Maximum != e.totalTime) { progressBar1.Maximum = e.totalTime; } if (progressBar1.Value != e.currentTime) { progressBar1.Value = e.currentTime; } }
void m_visClient_ConnectionStateChanged(object sender, VisualizationEventArgs e) { if (m_visClient.IsConnected) { ToolTipService.SetToolTip(CaptureMenu.FindName("btnServer") as DependencyObject, String.Format("Change Infrastructure (Currently connected to '{0}')", m_visClient.ServerEndpoint)); connectionStatus.Visibility = System.Windows.Visibility.Collapsed; sbHideSelector.Begin(); } else { ToolTipService.SetToolTip(CaptureMenu.FindName("btnServer") as DependencyObject, "Change Infrastructure (Not Connected)"); if (connectionStatus.Visibility == System.Windows.Visibility.Collapsed) // Retry connecton { m_visClient.Connect(); } else { connectionStatus.Content = String.Format("Couldn't establish a connection please ensure the service is running and is available. '{0}'", e.ErrorText); connectionStatus.AllowApprove = true; } } }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { Attach(); NotifyPropertyChanged(""); return; } // Don't render if the user's system is incapable. if (renderingTier == 0) { return; } #if DEBUG renderTimer.Start(); #endif Text = null; var packages = e.Packages.Concat(e.SelectedPackages) .Cast <HelixRenderPackage>().Where(rp => rp.MeshVertexCount % 3 == 0); var text = HelixRenderPackage.InitText3D(); var aggParams = new PackageAggregationParams { Packages = packages, Text = text }; AggregateRenderPackages(aggParams); #if DEBUG renderTimer.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed)); renderTimer.Reset(); renderTimer.Start(); #endif //Helix render the packages in certain order. Here, the BillBoardText has to be rendered //after rendering all the geometry. Otherwise, the Text will not get rendered at the right //position. Also, BillBoardText gets attached only once. It is not removed from the tree everytime. //Instead, only the geometry gets updated every time. Once it is attached (after the geometry), helix // renders the text at the right position. if (Text != null && Text.TextInfo.Any()) { BillboardTextModel3D billboardText3D = new BillboardTextModel3D { Transform = Model1Transform }; if (model3DDictionary != null && !model3DDictionary.ContainsKey("BillBoardText")) { model3DDictionary.Add("BillBoardText", billboardText3D); } var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D; billBoardModel3D.Geometry = Text; if (!billBoardModel3D.IsAttached) { billBoardModel3D.Attach(View.RenderHost); } } else { if (model3DDictionary != null && model3DDictionary.ContainsKey("BillBoardText")) { var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D; billBoardModel3D.Geometry = Text; } } //This is required for Dynamo to send property changed notifications to helix. NotifyPropertyChanged(""); }
/// <summary> /// Use the render description returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a render description and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> private void RenderDrawables(VisualizationEventArgs e) { //Debug.WriteLine(string.Format("Rendering full screen Watch3D on thread {0}.", System.Threading.Thread.CurrentThread.ManagedThreadId)); //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } var sw = new Stopwatch(); sw.Start(); var rd = e.Description; HelixPoints = null; HelixLines = null; HelixMesh = null; HelixXAxes = null; HelixYAxes = null; HelixZAxes = null; HelixPointsSelected = null; HelixLinesSelected = null; HelixMeshSelected = null; HelixText = null; HelixPoints = rd.Points; HelixLines = rd.Lines; HelixPointsSelected = rd.SelectedPoints; HelixLinesSelected = rd.SelectedLines; HelixXAxes = rd.XAxisPoints; HelixYAxes = rd.YAxisPoints; HelixZAxes = rd.ZAxisPoints; HelixMesh = VisualizationManager.MergeMeshes(rd.Meshes); HelixMeshSelected = VisualizationManager.MergeMeshes(rd.SelectedMeshes); HelixText = rd.Text; // http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/comment-page-1/#comment-2892 //Dispatcher.CurrentDispatcher.BeginInvoke( // DispatcherPriority.Background, // new Action(() => // { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(string.Format("Rendering complete:")); sb.AppendLine(string.Format("Points: {0}", rd.Points.Count + rd.SelectedPoints.Count)); sb.AppendLine(string.Format("Line segments: {0}", rd.Lines.Count / 2 + rd.SelectedLines.Count / 2)); sb.AppendLine(string.Format("Mesh vertices: {0}", rd.Meshes.SelectMany(x => x.Positions).Count() + rd.SelectedMeshes.SelectMany(x => x.Positions).Count())); sb.Append(string.Format("Mesh faces: {0}", rd.Meshes.SelectMany(x => x.TriangleIndices).Count() / 3 + rd.SelectedMeshes.SelectMany(x => x.TriangleIndices).Count() / 3)); //DynamoLogger.Instance.Log(sb.ToString()); Debug.WriteLine(sb.ToString()); sw.Stop(); //DynamoLogger.Instance.Log(string.Format("{0} ellapsed for updating background preview.", sw.Elapsed)); Debug.WriteLine(string.Format("{0} ellapsed for updating background preview.", sw.Elapsed)); //})); }
/// <summary> /// Handler for the visualization manager's ResultsReadyToVisualize event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VisualizationManager_ResultsReadyToVisualize(object sender, VisualizationEventArgs e) { Dispatcher.Invoke(new Action <VisualizationEventArgs>(RenderDrawables), DispatcherPriority.Render, new object[] { e }); }
/// <summary> /// Handler for the visualization manager's ResultsReadyToVisualize event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VisualizationManager_ResultsReadyToVisualize(object sender, VisualizationEventArgs e) { if (CheckAccess()) RenderDrawables(e); else { // Scheduler invokes ResultsReadyToVisualize on background thread. Dispatcher.BeginInvoke(new Action(() => RenderDrawables(e))); } }
/** * Function called by Data when a new event is logged for visualization * * @param e */ public void newEvent(object sender, VisualizationEventArgs e) { }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } // Don't render if the user's system is incapable. if (renderingTier == 0) { return; } #if DEBUG renderTimer.Start(); #endif Detach(false); var packages = e.Packages.Concat(e.SelectedPackages) .Cast<HelixRenderPackage>().Where(rp=>rp.MeshVertexCount % 3 == 0); var points = HelixRenderPackage.InitPointGeometry(); var lines = HelixRenderPackage.InitLineGeometry(); var linesSel = HelixRenderPackage.InitLineGeometry(); var dynamoMesh = HelixRenderPackage.InitMeshGeometry(); var mesh = HelixRenderPackage.InitMeshGeometry(); var text = HelixRenderPackage.InitText3D(); var aggParams = new PackageAggregationParams { Packages = packages, Points = points, Lines = lines, SelectedLines = linesSel, DynamoMesh = dynamoMesh, Mesh = mesh, Text = text }; AggregateRenderPackages(aggParams); if (!points.Positions.Any()) points = null; if (!lines.Positions.Any()) lines = null; if (!linesSel.Positions.Any()) linesSel = null; if (!text.TextInfo.Any()) text = null; if (!dynamoMesh.Positions.Any()) dynamoMesh = null; if (!mesh.Positions.Any()) mesh = null; #if DEBUG renderTimer.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed)); renderTimer.Reset(); renderTimer.Start(); #endif var updateGraphicsParams = new GraphicsUpdateParams { Points = points, Lines = lines, SelectedLines = linesSel, DynamoMesh = dynamoMesh, Mesh = mesh, Text = text }; SendGraphicsToView(updateGraphicsParams); //DrawTestMesh(); }
/// <summary> /// Handler for the visualization manager's ResultsReadyToVisualize event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VisualizationManager_ResultsReadyToVisualize(object sender, VisualizationEventArgs e) { //Dispatcher.Invoke(new Action<VisualizationEventArgs>(RenderDrawables), DispatcherPriority.Render, // new object[] {e}); RenderDrawables(e); }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> private void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } var sw = new Stopwatch(); sw.Start(); Points = null; Lines = null; Mesh = null; XAxes = null; YAxes = null; ZAxes = null; PointsSelected = null; LinesSelected = null; MeshSelected = null; Text = null; MeshCount = 0; //separate the selected packages var packages = e.Packages.Where(x => x.Selected == false).ToArray(); var selPackages = e.Packages.Where(x => x.Selected).ToArray(); //pre-size the points collections var pointsCount = packages.Select(x => x.PointVertices.Count / 3).Sum(); var selPointsCount = selPackages.Select(x => x.PointVertices.Count / 3).Sum(); var points = new Point3DCollection(pointsCount); var pointsSelected = new Point3DCollection(selPointsCount); //pre-size the lines collections //these sizes are conservative as the axis lines will be //taken from the linestripvertex collections as well. var lineCount = packages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lineSelCount = selPackages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lines = new Point3DCollection(lineCount); var linesSelected = new Point3DCollection(lineSelCount); var redLines = new Point3DCollection(lineCount); var greenLines = new Point3DCollection(lineCount); var blueLines = new Point3DCollection(lineCount); //pre-size the text collection var textCount = e.Packages.Count(x => x.DisplayLabels); var text = new List <BillboardTextItem>(textCount); //http://blogs.msdn.com/b/timothyc/archive/2006/08/31/734308.aspx //presize the mesh collections var meshVertCount = packages.Select(x => x.TriangleVertices.Count / 3).Sum(); var meshVertSelCount = selPackages.Select(x => x.TriangleVertices.Count / 3).Sum(); var mesh = new MeshGeometry3D(); var meshSel = new MeshGeometry3D(); var verts = new Point3DCollection(meshVertCount); var vertsSel = new Point3DCollection(meshVertSelCount); var norms = new Vector3DCollection(meshVertCount); var normsSel = new Vector3DCollection(meshVertSelCount); var tris = new Int32Collection(meshVertCount); var trisSel = new Int32Collection(meshVertSelCount); foreach (var package in packages) { ConvertPoints(package, points, text); ConvertLines(package, lines, redLines, greenLines, blueLines, text); ConvertMeshes(package, verts, norms, tris); } foreach (var package in selPackages) { ConvertPoints(package, pointsSelected, text); ConvertLines(package, linesSelected, redLines, greenLines, blueLines, text); ConvertMeshes(package, vertsSel, normsSel, trisSel); } points.Freeze(); pointsSelected.Freeze(); Points = points; PointsSelected = pointsSelected; lines.Freeze(); linesSelected.Freeze(); redLines.Freeze(); greenLines.Freeze(); blueLines.Freeze(); Lines = lines; LinesSelected = linesSelected; XAxes = redLines; YAxes = greenLines; ZAxes = blueLines; verts.Freeze(); norms.Freeze(); tris.Freeze(); vertsSel.Freeze(); normsSel.Freeze(); trisSel.Freeze(); mesh.Positions = verts; mesh.Normals = norms; mesh.TriangleIndices = tris; meshSel.Positions = vertsSel; meshSel.Normals = normsSel; meshSel.TriangleIndices = trisSel; Mesh = mesh; MeshSelected = meshSel; Text = text; sw.Stop(); GC.Collect(); Debug.WriteLine(string.Format("{0} ellapsed for updating background preview.", sw.Elapsed)); }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> private void RenderDrawables(VisualizationEventArgs e) { try { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } var sw = new Stopwatch(); sw.Start(); Points = null; Lines = null; Mesh = null; XAxes = null; YAxes = null; ZAxes = null; PointsSelected = null; LinesSelected = null; MeshSelected = null; Text = null; MeshCount = 0; //separate the selected packages var packages = e.Packages.Where(x => x.Selected == false).ToArray(); var selPackages = e.Packages.Where(x => x.Selected).ToArray(); //pre-size the points collections var pointsCount = packages.Select(x => x.PointVertices.Count/3).Sum(); var selPointsCount = selPackages.Select(x => x.PointVertices.Count / 3).Sum(); var points = new Point3DCollection(pointsCount); var pointsSelected = new Point3DCollection(selPointsCount); //pre-size the lines collections //these sizes are conservative as the axis lines will be //taken from the linestripvertex collections as well. var lineCount = packages.Select(x => x.LineStripVertices.Count/3).Sum(); var lineSelCount = selPackages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lines = new Point3DCollection(lineCount); var linesSelected = new Point3DCollection(lineSelCount); var redLines = new Point3DCollection(lineCount); var greenLines = new Point3DCollection(lineCount); var blueLines = new Point3DCollection(lineCount); //pre-size the text collection var textCount = e.Packages.Count(x => x.DisplayLabels); var text = new List<BillboardTextItem>(textCount); //http://blogs.msdn.com/b/timothyc/archive/2006/08/31/734308.aspx //presize the mesh collections var meshVertCount = packages.Select(x => x.TriangleVertices.Count / 3).Sum(); var meshVertSelCount = selPackages.Select(x => x.TriangleVertices.Count / 3).Sum(); var mesh = new MeshGeometry3D(); var meshSel = new MeshGeometry3D(); var verts = new Point3DCollection(meshVertCount); var vertsSel = new Point3DCollection(meshVertSelCount); var norms = new Vector3DCollection(meshVertCount); var normsSel = new Vector3DCollection(meshVertSelCount); var tris = new Int32Collection(meshVertCount); var trisSel = new Int32Collection(meshVertSelCount); foreach (var package in packages) { ConvertPoints(package, points, text); ConvertLines(package, lines, redLines, greenLines, blueLines, text); ConvertMeshes(package, verts, norms, tris); } foreach (var package in selPackages) { ConvertPoints(package, pointsSelected, text); ConvertLines(package, linesSelected, redLines, greenLines, blueLines, text); ConvertMeshes(package, vertsSel, normsSel, trisSel); } points.Freeze(); pointsSelected.Freeze(); Points = points; PointsSelected = pointsSelected; lines.Freeze(); linesSelected.Freeze(); redLines.Freeze(); greenLines.Freeze(); blueLines.Freeze(); Lines = lines; LinesSelected = linesSelected; XAxes = redLines; YAxes = greenLines; ZAxes = blueLines; verts.Freeze(); norms.Freeze(); tris.Freeze(); vertsSel.Freeze(); normsSel.Freeze(); trisSel.Freeze(); mesh.Positions = verts; mesh.Normals = norms; mesh.TriangleIndices = tris; meshSel.Positions = vertsSel; meshSel.Normals = normsSel; meshSel.TriangleIndices = trisSel; Mesh = mesh; MeshSelected = meshSel; Text = text; sw.Stop(); Debug.WriteLine(string.Format("{0} ellapsed for updating background preview.", sw.Elapsed)); } catch (InvalidOperationException exp) { Debug.WriteLine("WARNING: Exception occured in rendering " + exp.ToString()); } }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } Debug.WriteLine(string.Format("Rendering visuals for {0}", e.Id)); var sw = new Stopwatch(); sw.Start(); Points = null; Lines = null; Mesh = null; XAxes = null; YAxes = null; ZAxes = null; PointsSelected = null; LinesSelected = null; MeshSelected = null; Text = null; MeshCount = 0; //separate the selected packages var packages = e.Packages.Where(x => x.Selected == false) .Where(rp => rp.TriangleVertices.Count % 9 == 0) .ToArray(); var selPackages = e.Packages .Where(x => x.Selected) .Where(rp => rp.TriangleVertices.Count % 9 == 0) .ToArray(); //pre-size the points collections var pointsCount = packages.Select(x => x.PointVertices.Count / 3).Sum(); var selPointsCount = selPackages.Select(x => x.PointVertices.Count / 3).Sum(); var points = new Point3DCollection(pointsCount); var pointsSelected = new Point3DCollection(selPointsCount); //pre-size the lines collections //these sizes are conservative as the axis lines will be //taken from the linestripvertex collections as well. var lineCount = packages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lineSelCount = selPackages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lines = new Point3DCollection(lineCount); var linesSelected = new Point3DCollection(lineSelCount); var redLines = new Point3DCollection(lineCount); var greenLines = new Point3DCollection(lineCount); var blueLines = new Point3DCollection(lineCount); //pre-size the text collection var textCount = e.Packages.Count(x => x.DisplayLabels); var text = new List <BillboardTextItem>(textCount); //http://blogs.msdn.com/b/timothyc/archive/2006/08/31/734308.aspx //presize the mesh collections var meshVertCount = packages.Select(x => x.TriangleVertices.Count / 3).Sum(); var meshVertSelCount = selPackages.Select(x => x.TriangleVertices.Count / 3).Sum(); var mesh = new MeshGeometry3D(); var meshSel = new MeshGeometry3D(); var verts = new Point3DCollection(meshVertCount); var vertsSel = new Point3DCollection(meshVertSelCount); var norms = new Vector3DCollection(meshVertCount); var normsSel = new Vector3DCollection(meshVertSelCount); var tris = new Int32Collection(meshVertCount); var trisSel = new Int32Collection(meshVertSelCount); foreach (var package in packages) { ConvertPoints(package, points, text); ConvertLines(package, lines, redLines, greenLines, blueLines, text); ConvertMeshes(package, verts, norms, tris); } foreach (var package in selPackages) { ConvertPoints(package, pointsSelected, text); ConvertLines(package, linesSelected, redLines, greenLines, blueLines, text); ConvertMeshes(package, vertsSel, normsSel, trisSel); } sw.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for updating background preview.", sw.Elapsed)); var vm = (IWatchViewModel)DataContext; if (vm.CheckForLatestRenderCommand.CanExecute(e.TaskId)) { vm.CheckForLatestRenderCommand.Execute(e.TaskId); } points.Freeze(); pointsSelected.Freeze(); lines.Freeze(); linesSelected.Freeze(); redLines.Freeze(); greenLines.Freeze(); blueLines.Freeze(); verts.Freeze(); norms.Freeze(); tris.Freeze(); vertsSel.Freeze(); normsSel.Freeze(); trisSel.Freeze(); Dispatcher.Invoke(new Action <Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Vector3DCollection, Int32Collection, Point3DCollection, Vector3DCollection, Int32Collection, MeshGeometry3D, MeshGeometry3D, List <BillboardTextItem> >(SendGraphicsToView), DispatcherPriority.Render, new object[] { points, pointsSelected, lines, linesSelected, redLines, greenLines, blueLines, verts, norms, tris, vertsSel, normsSel, trisSel, mesh, meshSel, text }); }
/// <summary> /// Handler for the visualization manager's ResultsReadyToVisualize event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VisualizationManager_ResultsReadyToVisualize(object sender, VisualizationEventArgs e) { RenderDrawables(e); }
void VisualizationManager_VisualizationUpdateComplete(object sender, VisualizationEventArgs e) { if (dynSettings.Controller == null) return; if (!dynSettings.Controller.DynamoViewModel.FullscreenWatchShowing) return; Dispatcher.Invoke(new Action<RenderDescription>(RenderDrawables),DispatcherPriority.Render, new object[]{e.Description}); }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } #if DEBUG renderTimer.Start(); #endif Points = null; Lines = null; LinesSelected = null; Mesh = null; PerVertexMesh = null; MeshSelected = null; Text = null; MeshCount = 0; var packages = e.Packages.Concat(e.SelectedPackages) .Cast <HelixRenderPackage>().Where(rp => rp.MeshVertexCount % 3 == 0); var points = HelixRenderPackage.InitPointGeometry(); var lines = HelixRenderPackage.InitLineGeometry(); var linesSel = HelixRenderPackage.InitLineGeometry(); var mesh = HelixRenderPackage.InitMeshGeometry(); var meshSel = HelixRenderPackage.InitMeshGeometry(); var perVertexMesh = HelixRenderPackage.InitMeshGeometry(); var text = HelixRenderPackage.InitText3D(); var aggParams = new PackageAggregationParams { Packages = packages, Points = points, Lines = lines, SelectedLines = linesSel, Mesh = mesh, PerVertexMesh = perVertexMesh, SelectedMesh = meshSel, Text = text }; AggregateRenderPackages(aggParams); if (!points.Positions.Any()) { points = null; } if (!lines.Positions.Any()) { lines = null; } if (!linesSel.Positions.Any()) { linesSel = null; } if (!text.TextInfo.Any()) { text = null; } if (!mesh.Positions.Any()) { mesh = null; } if (!meshSel.Positions.Any()) { meshSel = null; } if (!perVertexMesh.Positions.Any()) { perVertexMesh = null; } #if DEBUG renderTimer.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed)); renderTimer.Reset(); renderTimer.Start(); #endif var updateGraphicsParams = new GraphicsUpdateParams { Points = points, Lines = lines, SelectedLines = linesSel, Mesh = mesh, SelectedMesh = meshSel, PerVertexMesh = perVertexMesh, Text = text }; SendGraphicsToView(updateGraphicsParams); //DrawTestMesh(); }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { Attach(); NotifyPropertyChanged(""); return; } // Don't render if the user's system is incapable. if (renderingTier == 0) { return; } #if DEBUG renderTimer.Start(); #endif Text = null; var packages = e.Packages.Concat(e.SelectedPackages) .Cast<HelixRenderPackage>().Where(rp=>rp.MeshVertexCount % 3 == 0); var text = HelixRenderPackage.InitText3D(); var aggParams = new PackageAggregationParams { Packages = packages, Text = text }; AggregateRenderPackages(aggParams); #if DEBUG renderTimer.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed)); renderTimer.Reset(); renderTimer.Start(); #endif //Helix render the packages in certain order. Here, the BillBoardText has to be rendered //after rendering all the geometry. Otherwise, the Text will not get rendered at the right //position. Also, BillBoardText gets attached only once. It is not removed from the tree everytime. //Instead, only the geometry gets updated every time. Once it is attached (after the geometry), helix // renders the text at the right position. if (Text != null && Text.TextInfo.Any()) { BillboardTextModel3D billboardText3D = new BillboardTextModel3D { Transform = Model1Transform }; if (model3DDictionary != null && !model3DDictionary.ContainsKey("BillBoardText")) { model3DDictionary.Add("BillBoardText", billboardText3D); } var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D; billBoardModel3D.Geometry = Text; if (!billBoardModel3D.IsAttached) { billBoardModel3D.Attach(View.RenderHost); } } else { if (model3DDictionary != null && model3DDictionary.ContainsKey("BillBoardText")) { var billBoardModel3D = model3DDictionary["BillBoardText"] as BillboardTextModel3D; billBoardModel3D.Geometry = Text; } } //This is required for Dynamo to send property changed notifications to helix. NotifyPropertyChanged(""); }
/// <summary> /// Use the render packages returned from the visualization manager to update the visuals. /// The visualization event arguments will contain a set of render packages and an id representing /// the associated node. Visualizations for the background preview will return an empty id. /// </summary> /// <param name="e"></param> public void RenderDrawables(VisualizationEventArgs e) { //check the id, if the id is meant for another watch, //then ignore it if (e.Id != _id) { return; } Debug.WriteLine(string.Format("Rendering visuals for {0}", e.Id)); var sw = new Stopwatch(); sw.Start(); Points = null; Lines = null; Mesh = null; XAxes = null; YAxes = null; ZAxes = null; PointsSelected = null; LinesSelected = null; MeshSelected = null; Text = null; MeshCount = 0; //separate the selected packages var packages = e.Packages.Where(x => x.Selected == false) .Where(rp=>rp.TriangleVertices.Count % 9 == 0) .ToArray(); var selPackages = e.Packages .Where(x => x.Selected) .Where(rp => rp.TriangleVertices.Count % 9 == 0) .ToArray(); //pre-size the points collections var pointsCount = packages.Select(x => x.PointVertices.Count/3).Sum(); var selPointsCount = selPackages.Select(x => x.PointVertices.Count / 3).Sum(); var points = new Point3DCollection(pointsCount); var pointsSelected = new Point3DCollection(selPointsCount); //pre-size the lines collections //these sizes are conservative as the axis lines will be //taken from the linestripvertex collections as well. var lineCount = packages.Select(x => x.LineStripVertices.Count/3).Sum(); var lineSelCount = selPackages.Select(x => x.LineStripVertices.Count / 3).Sum(); var lines = new Point3DCollection(lineCount); var linesSelected = new Point3DCollection(lineSelCount); var redLines = new Point3DCollection(lineCount); var greenLines = new Point3DCollection(lineCount); var blueLines = new Point3DCollection(lineCount); //pre-size the text collection var textCount = e.Packages.Count(x => x.DisplayLabels); var text = new List<BillboardTextItem>(textCount); //http://blogs.msdn.com/b/timothyc/archive/2006/08/31/734308.aspx //presize the mesh collections var meshVertCount = packages.Select(x => x.TriangleVertices.Count / 3).Sum(); var meshVertSelCount = selPackages.Select(x => x.TriangleVertices.Count / 3).Sum(); var mesh = new MeshGeometry3D(); var meshSel = new MeshGeometry3D(); var verts = new Point3DCollection(meshVertCount); var vertsSel = new Point3DCollection(meshVertSelCount); var norms = new Vector3DCollection(meshVertCount); var normsSel = new Vector3DCollection(meshVertSelCount); var tris = new Int32Collection(meshVertCount); var trisSel = new Int32Collection(meshVertSelCount); foreach (var package in packages) { ConvertPoints(package, points, text); ConvertLines(package, lines, redLines, greenLines, blueLines, text); ConvertMeshes(package, verts, norms, tris); } foreach (var package in selPackages) { ConvertPoints(package, pointsSelected, text); ConvertLines(package, linesSelected, redLines, greenLines, blueLines, text); ConvertMeshes(package, vertsSel, normsSel, trisSel); } sw.Stop(); Debug.WriteLine(string.Format("RENDER: {0} ellapsed for updating background preview.", sw.Elapsed)); var vm = (IWatchViewModel)DataContext; if (vm.CheckForLatestRenderCommand.CanExecute(e.TaskId)) { vm.CheckForLatestRenderCommand.Execute(e.TaskId); } points.Freeze(); pointsSelected.Freeze(); lines.Freeze(); linesSelected.Freeze(); redLines.Freeze(); greenLines.Freeze(); blueLines.Freeze(); verts.Freeze(); norms.Freeze(); tris.Freeze(); vertsSel.Freeze(); normsSel.Freeze(); trisSel.Freeze(); Dispatcher.Invoke(new Action<Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Point3DCollection, Vector3DCollection, Int32Collection, Point3DCollection, Vector3DCollection, Int32Collection, MeshGeometry3D, MeshGeometry3D, List<BillboardTextItem>>(SendGraphicsToView), DispatcherPriority.Render, new object[] {points, pointsSelected, lines, linesSelected, redLines, greenLines, blueLines, verts, norms, tris, vertsSel, normsSel, trisSel, mesh, meshSel, text}); }