Beispiel #1
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            //Clear the geometry values before adding the package.
            VisualizationManager_WorkspaceOpenedClosedHandled();

            foreach (var rp in parameters.Packages)
            {
                //Node ID gets updated with a ":" everytime this function is called.
                //For example, if the same point node is called multiple times (CBN), the ID has a ":"
                //and this makes the dictionary to have multiple entries for the same node. 
                var baseId = rp.Description;
                if (baseId.IndexOf(":", StringComparison.Ordinal) > 0)
                {
                    baseId = baseId.Split(':')[0];
                }
                var id = baseId;

                var p = rp.Points;
                if (p.Positions.Any())
                {
                    id = baseId + ":points";

                    PointGeometryModel3D pointGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D;
                    }
                    else
                    {
                        pointGeometry3D = new PointGeometryModel3D
                        {
                            Geometry = HelixRenderPackage.InitPointGeometry(),
                            Transform = Model1Transform,
                            Color = SharpDX.Color.White,
                            Figure = PointGeometryModel3D.PointFigure.Ellipse,
                            Size = DefaultPointSize,
                            IsHitTestVisible = true,
                            IsSelected = rp.IsSelected
                        };
                        model3DDictionary.Add(id, pointGeometry3D);
                    }

                    var points = pointGeometry3D.Geometry as PointGeometry3D;
                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    pointGeometry3D.Geometry = points;
                    pointGeometry3D.Name = baseId;
                    pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    id = baseId + ":lines";

                    LineGeometryModel3D lineGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D;
                    }
                    else
                    {
                        lineGeometry3D = new LineGeometryModel3D()
                        {
                            Geometry = HelixRenderPackage.InitLineGeometry(),
                            Transform = Model1Transform,
                            Color = SharpDX.Color.White,
                            Thickness = 0.5,
                            IsHitTestVisible = true,
                            IsSelected = rp.IsSelected
                        };

                        model3DDictionary.Add(id, lineGeometry3D);
                    }

                    var lineSet = lineGeometry3D.Geometry as LineGeometry3D;
                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    lineGeometry3D.Geometry = lineSet;
                    lineGeometry3D.Name = baseId;
                    lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var m = rp.Mesh;
                if (!m.Positions.Any()) continue;

                id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh";

                DynamoGeometryModel3D meshGeometry3D;

                if (model3DDictionary.ContainsKey(id))
                {
                    meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D;
                }
                else
                {
                    meshGeometry3D = new DynamoGeometryModel3D()
                    {
                        Transform = Model1Transform,
                        Material = WhiteMaterial,
                        IsHitTestVisible = true,
                        RequiresPerVertexColoration = rp.RequiresPerVertexColoration,
                        IsSelected = rp.IsSelected,
                    };
                    
                    if (rp.Colors != null)
                    {
                        var pf = PixelFormats.Bgra32;
                        var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8;
                        try
                        {
                            var diffMap = BitmapSource.Create(rp.ColorsStride/4, rp.Colors.Count()/rp.ColorsStride, 96.0, 96.0, pf, null,
                                rp.Colors.ToArray(), stride);
                            var diffMat = new PhongMaterial
                            {
                                Name = "White",
                                AmbientColor = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                                DiffuseColor = materialColor,
                                SpecularColor = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                                EmissiveColor = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                                SpecularShininess = 12.8f,
                                DiffuseMap = diffMap
                            };
                            meshGeometry3D.Material = diffMat;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    ((MaterialGeometryModel3D) meshGeometry3D).SelectionColor = selectionColor; 
                    model3DDictionary.Add(id, meshGeometry3D);
                }

                var mesh = meshGeometry3D.Geometry == null ? HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D;
                var idxCount = mesh.Positions.Count;

                mesh.Positions.AddRange(m.Positions);

                mesh.Colors.AddRange(m.Colors);
                mesh.Normals.AddRange(m.Normals);
                mesh.TextureCoordinates.AddRange(m.TextureCoordinates);
                mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                if (mesh.Colors.Any(c => c.Alpha < 1.0))
                {
                    meshGeometry3D.HasTransparency = true;
                }

                if (rp.DisplayLabels)
                {
                    var pt = mesh.Positions[idxCount];
                    parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    Text = parameters.Text;
                }

                meshGeometry3D.Geometry = mesh;
                meshGeometry3D.Name = baseId; 
                meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
            }

            Attach();
        }
Beispiel #2
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            foreach (var rp in parameters.Packages)
            {
                var p = rp.Points;
                if (p.Positions.Any())
                {
                    var points = parameters.Points;

                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i=> i + startIdx));

                    var endIdx = points.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            points.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    // Choose a collection to store the line data.
                    var lineSet = rp.IsSelected ? parameters.SelectedLines : parameters.Lines;

                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Any()? l.Indices.Select(i=>i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                    var endIdx = lineSet.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            lineSet.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var m = rp.Mesh;
                if (m.Positions.Any())
                {
                    // Pick a mesh to use to store the data. Selected geometry
                    // goes into the selected mesh. Geometry with
                    // colors goes into the per vertex mesh. Everything else
                    // goes into the plain mesh.

                    var meshSet = rp.IsSelected || rp.RequiresPerVertexColoration ? 
                        parameters.DynamoMesh : parameters.Mesh;

                    var idxCount = meshSet.Positions.Count;
                    
                    meshSet.Positions.AddRange(m.Positions);

                    meshSet.Colors.AddRange(rp.IsSelected ? Enumerable.Repeat(selectionColor,m.Positions.Count): m.Colors);
                    meshSet.Normals.AddRange(m.Normals);
                    meshSet.TextureCoordinates.AddRange(m.TextureCoordinates);
                    meshSet.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                    if (rp.DisplayLabels)
                    {
                        var pt = meshSet.Positions[idxCount];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }
            }
        }
Beispiel #3
0
        /// <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("");
        }
Beispiel #4
0
        /// <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();
        }
Beispiel #5
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            //Clear the geometry values before adding the package.
            VisualizationManager_WorkspaceOpenedClosedHandled();

            foreach (var rp in parameters.Packages)
            {
                //Node ID gets updated with a ":" everytime this function is called.
                //For example, if the same point node is called multiple times (CBN), the ID has a ":"
                //and this makes the dictionary to have multiple entries for the same node.
                var baseId = rp.Description;
                if (baseId.IndexOf(":", StringComparison.Ordinal) > 0)
                {
                    baseId = baseId.Split(':')[0];
                }
                var id = baseId;

                var p = rp.Points;
                if (p.Positions.Any())
                {
                    id = baseId + ":points";

                    PointGeometryModel3D pointGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        pointGeometry3D = model3DDictionary[id] as PointGeometryModel3D;
                    }
                    else
                    {
                        pointGeometry3D = new PointGeometryModel3D
                        {
                            Geometry         = HelixRenderPackage.InitPointGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Figure           = PointGeometryModel3D.PointFigure.Ellipse,
                            Size             = DefaultPointSize,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };
                        model3DDictionary.Add(id, pointGeometry3D);
                    }

                    var points   = pointGeometry3D.Geometry as PointGeometry3D;
                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    pointGeometry3D.Geometry     = points;
                    pointGeometry3D.Name         = baseId;
                    pointGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    id = baseId + ":lines";

                    LineGeometryModel3D lineGeometry3D;

                    if (model3DDictionary.ContainsKey(id))
                    {
                        lineGeometry3D = model3DDictionary[id] as LineGeometryModel3D;
                    }
                    else
                    {
                        lineGeometry3D = new LineGeometryModel3D()
                        {
                            Geometry         = HelixRenderPackage.InitLineGeometry(),
                            Transform        = Model1Transform,
                            Color            = SharpDX.Color.White,
                            Thickness        = 0.5,
                            IsHitTestVisible = true,
                            IsSelected       = rp.IsSelected
                        };

                        model3DDictionary.Add(id, lineGeometry3D);
                    }

                    var lineSet  = lineGeometry3D.Geometry as LineGeometry3D;
                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Any() ? l.Indices.Select(i => i + startIdx) : Enumerable.Range(startIdx, startIdx + l.Positions.Count));

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                        Text = parameters.Text;
                    }

                    lineGeometry3D.Geometry     = lineSet;
                    lineGeometry3D.Name         = baseId;
                    lineGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
                }

                var m = rp.Mesh;
                if (!m.Positions.Any())
                {
                    continue;
                }

                id = ((rp.RequiresPerVertexColoration || rp.Colors != null) ? rp.Description : baseId) + ":mesh";

                DynamoGeometryModel3D meshGeometry3D;

                if (model3DDictionary.ContainsKey(id))
                {
                    meshGeometry3D = model3DDictionary[id] as DynamoGeometryModel3D;
                }
                else
                {
                    meshGeometry3D = new DynamoGeometryModel3D()
                    {
                        Transform                   = Model1Transform,
                        Material                    = WhiteMaterial,
                        IsHitTestVisible            = true,
                        RequiresPerVertexColoration = rp.RequiresPerVertexColoration,
                        IsSelected                  = rp.IsSelected,
                    };

                    if (rp.Colors != null)
                    {
                        var pf     = PixelFormats.Bgra32;
                        var stride = (rp.ColorsStride / 4 * pf.BitsPerPixel + 7) / 8;
                        try
                        {
                            var diffMap = BitmapSource.Create(rp.ColorsStride / 4, rp.Colors.Count() / rp.ColorsStride, 96.0, 96.0, pf, null,
                                                              rp.Colors.ToArray(), stride);
                            var diffMat = new PhongMaterial
                            {
                                Name              = "White",
                                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                                DiffuseColor      = materialColor,
                                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                                SpecularShininess = 12.8f,
                                DiffuseMap        = diffMap
                            };
                            meshGeometry3D.Material = diffMat;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    ((MaterialGeometryModel3D)meshGeometry3D).SelectionColor = selectionColor;
                    model3DDictionary.Add(id, meshGeometry3D);
                }

                var mesh = meshGeometry3D.Geometry == null?HelixRenderPackage.InitMeshGeometry() : meshGeometry3D.Geometry as MeshGeometry3D;

                var idxCount = mesh.Positions.Count;

                mesh.Positions.AddRange(m.Positions);

                mesh.Colors.AddRange(m.Colors);
                mesh.Normals.AddRange(m.Normals);
                mesh.TextureCoordinates.AddRange(m.TextureCoordinates);
                mesh.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                if (mesh.Colors.Any(c => c.Alpha < 1.0))
                {
                    meshGeometry3D.HasTransparency = true;
                }

                if (rp.DisplayLabels)
                {
                    var pt = mesh.Positions[idxCount];
                    parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    Text = parameters.Text;
                }

                meshGeometry3D.Geometry     = mesh;
                meshGeometry3D.Name         = baseId;
                meshGeometry3D.MouseDown3D += meshGeometry3D_MouseDown3D;
            }

            Attach();
        }
Beispiel #6
0
        /// <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("");
        }
Beispiel #7
0
        private void AggregateRenderPackages(PackageAggregationParams parameters)
        {
            MeshCount = 0;
            foreach (var rp in parameters.Packages)
            {
                var p = rp.Points;
                if (p.Positions.Any())
                {
                    var points = parameters.Points;

                    var startIdx = points.Positions.Count;

                    points.Positions.AddRange(p.Positions);
                    points.Colors.AddRange(p.Colors.Any() ? p.Colors : Enumerable.Repeat(defaultPointColor, points.Positions.Count));
                    points.Indices.AddRange(p.Indices.Select(i => i + startIdx));

                    var endIdx = points.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            points.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = p.Positions[0];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var l = rp.Lines;
                if (l.Positions.Any())
                {
                    // Choose a collection to store the line data.
                    var lineSet = rp.IsSelected ? parameters.SelectedLines : parameters.Lines;

                    var startIdx = lineSet.Positions.Count;

                    lineSet.Positions.AddRange(l.Positions);
                    lineSet.Colors.AddRange(l.Colors.Any() ? l.Colors : Enumerable.Repeat(defaultLineColor, l.Positions.Count));
                    lineSet.Indices.AddRange(l.Indices.Select(i => i + startIdx));

                    var endIdx = lineSet.Positions.Count;

                    if (rp.IsSelected)
                    {
                        for (var i = startIdx; i < endIdx; i++)
                        {
                            lineSet.Colors[i] = selectionColor;
                        }
                    }

                    if (rp.DisplayLabels)
                    {
                        var pt = lineSet.Positions[startIdx];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }
                }

                var m = rp.Mesh;
                if (m.Positions.Any())
                {
                    // Pick a mesh to use to store the data. Selected geometry
                    // goes into the selected mesh. Geometry with
                    // colors goes into the per vertex mesh. Everything else
                    // goes into the plain mesh.

                    var meshSet = rp.IsSelected ?
                                  parameters.SelectedMesh :
                                  rp.RequiresPerVertexColoration ? parameters.PerVertexMesh : parameters.Mesh;

                    var idxCount = meshSet.Positions.Count;

                    meshSet.Positions.AddRange(m.Positions);

                    meshSet.Colors.AddRange(m.Colors);
                    meshSet.Normals.AddRange(m.Normals);
                    meshSet.TextureCoordinates.AddRange(m.TextureCoordinates);
                    meshSet.Indices.AddRange(m.Indices.Select(i => i + idxCount));

                    if (rp.DisplayLabels)
                    {
                        var pt = meshSet.Positions[idxCount];
                        parameters.Text.TextInfo.Add(new TextInfo(HelixRenderPackage.CleanTag(rp.Description), new Vector3(pt.X + 0.025f, pt.Y + 0.025f, pt.Z + 0.025f)));
                    }

                    MeshCount++;
                }
            }
        }
Beispiel #8
0
        /// <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();
        }