public static void DrawCurve(RenderDescription description, object obj)
        {
            var curve = obj as Curve;

            if (curve == null)
            {
                return;
            }

            IList <XYZ> points = curve.Tessellate();

            for (int i = 0; i < points.Count; ++i)
            {
                XYZ xyz = points[i];

                description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z));

                if (i == 0 || i == (points.Count - 1))
                {
                    continue;
                }

                description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z));
            }
        }
        // Why the if/else statements? Most dynRevitTransactionNode are created
        // via a Python script. This keeps logic in the main C# code base.

        public static void DrawGeometryObject(RenderDescription description, object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (typeof(Autodesk.Revit.DB.XYZ).IsAssignableFrom(obj.GetType()))
            {
                DrawXYZ(description, obj);
            }
            if (typeof(Autodesk.Revit.DB.Curve).IsAssignableFrom(obj.GetType()))
            {
                DrawCurve(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.Solid).IsAssignableFrom(obj.GetType()))
            {
                DrawSolid(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.Face).IsAssignableFrom(obj.GetType()))
            {
                DrawFace(description, obj);
            }
            else
            {
                DrawUndrawable(description, obj);
            }
        }
        // Why the if/else statements? Most dynRevitTransactionNode are created
        // via a Python script. This keeps logic in the main C# code base.

        public static void DrawGeometryObject(RenderDescription description, object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (obj is XYZ)
            {
                DrawXYZ(description, obj);
            }
            if (obj is Curve)
            {
                DrawCurve(description, obj);
            }
            else if (obj is Solid)
            {
                DrawSolid(description, obj);
            }
            else if (obj is Face)
            {
                DrawFace(description, obj);
            }
            else
            {
                DrawUndrawable(description, obj);
            }
        }
        public static void DrawCurveElement(RenderDescription description, object obj)
        {
            var elem = obj as CurveElement;

            if (elem == null)
            {
                return;
            }

            DrawCurve(description, elem.GeometryCurve);
        }
        public static void DrawXYZ(RenderDescription description, object obj)
        {
            var point = obj as XYZ;

            if (point == null)
            {
                return;
            }

            description.points.Add(new Point3D(point.X, point.Y, point.Z));
        }
        public static void DrawForm(RenderDescription description, object obj)
        {
            var form = obj as Form;

            if (form == null)
            {
                return;
            }

            DrawGeometryElement(description, form.get_Geometry(new Options()));
        }
        public static void DrawCurveElement(RenderDescription description, object obj)
        {
            Autodesk.Revit.DB.CurveElement elem = obj as Autodesk.Revit.DB.CurveElement;

            if (elem == null)
            {
                return;
            }

            DrawCurve(description, elem.GeometryCurve);
        }
 public ComponentDescription(string id, string componentName, bool canResize, bool canFlip, double minSize, ComponentProperty[] properties, ConnectionGroup[] connections, RenderDescription[] renderDescriptions, Conditional<FlagOptions>[] flags, ComponentDescriptionMetadata metadata)
 {
     ID = id;
     ComponentName = componentName;
     CanResize = canResize;
     CanFlip = canFlip;
     MinSize = minSize;
     Properties = properties;
     Connections = connections;
     RenderDescriptions = renderDescriptions;
     Flags = flags;
     Metadata = metadata;
 }
        public static void DrawReferencePoint(RenderDescription description, object obj)
        {
            var point = obj as ReferencePoint;

            if (point == null)
            {
                return;
            }

            description.points.Add(new Point3D(point.GetCoordinateSystem().Origin.X,
                                               point.GetCoordinateSystem().Origin.Y,
                                               point.GetCoordinateSystem().Origin.Z));
        }
        public static void DrawFace(RenderDescription description, object obj)
        {
            var face = obj as Face;

            if (face == null)
            {
                return;
            }

            Mesh3D[] meshes = RevitMeshToHelixMesh(face.Triangulate(0.2));

            foreach (Mesh3D mesh in meshes)
            {
                description.meshes.Add(mesh);
            }
        }
Esempio n. 11
0
        public static void DrawGeometryElement(RenderDescription description, object obj)
        {
            try
            {
                var gelem = obj as GeometryElement;

                foreach (GeometryObject go in gelem)
                {
                    DrawGeometryObject(description, go);
                }
            }
            catch (Exception ex)
            {
                dynSettings.Controller.DynamoViewModel.Log(ex.Message);
                dynSettings.Controller.DynamoViewModel.Log(ex.StackTrace);
            }
        }
        public static void DrawGeometryElement(RenderDescription description, object obj)
        {
            try
            {
                var gelem = obj as GeometryElement;

                foreach (GeometryObject go in gelem)
                {
                    DrawGeometryObject(description, go);
                }
            }
            catch (Exception ex)
            {
                DynamoLogger.Instance.Log(ex.Message);
                DynamoLogger.Instance.Log(ex.StackTrace);
            }
        }
        // Elements can cantain many Geometry
        public static void DrawElement(RenderDescription description, object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (obj is CurveElement)
            {
                DrawCurveElement(description, obj);
            }
            else if (obj is ReferencePoint)
            {
                DrawReferencePoint(description, obj);
            }
            else if (obj is Form)
            {
                DrawForm(description, obj);
            }
            else if (obj is GeometryElement)
            {
                DrawGeometryElement(description, obj);
            }
            else if (obj is GeometryObject)
            {
                DrawGeometryObject(description, obj);
            }
            else
            {
                var elem = obj as Element;
                if (elem != null)
                {
                    var o = new Options {
                        DetailLevel = ViewDetailLevel.Medium
                    };
                    GeometryElement geom = elem.get_Geometry(o);

                    if (geom != null)
                    {
                        DrawGeometryObject(description, geom);
                    }
                }
            }
        }
        public static void DrawSolid(RenderDescription description, object obj)
        {
            var solid = obj as Solid;

            if (solid == null)
            {
                return;
            }

            foreach (Face f in solid.Faces)
            {
                DrawFace(description, f);
            }

            foreach (Edge edge in solid.Edges)
            {
                DrawCurve(description, edge.AsCurve());
            }
        }
Esempio n. 15
0
        // Elements can cantain many Geometry
        public static void DrawElement(RenderDescription description, object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (typeof(Autodesk.Revit.DB.CurveElement).IsAssignableFrom(obj.GetType()))
            {
                DrawCurveElement(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.ReferencePoint).IsAssignableFrom(obj.GetType()))
            {
                DrawReferencePoint(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.Form).IsAssignableFrom(obj.GetType()))
            {
                DrawForm(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.GeometryElement).IsAssignableFrom(obj.GetType()))
            {
                DrawGeometryElement(description, obj);
            }
            else if (typeof(Autodesk.Revit.DB.GeometryObject).IsAssignableFrom(obj.GetType()))
            {
                DrawGeometryObject(description, obj);
            }
            else
            {
                Element elem = obj as Element;
                if (elem != null)
                {
                    Options o = new Options();
                    o.DetailLevel = ViewDetailLevel.Medium;
                    GeometryElement geom = elem.get_Geometry(o);

                    if (geom != null)
                    {
                        DrawGeometryObject(description, geom);
                    }
                }
            }
        }
        public virtual void Draw()
        {
            if (this.RenderDescription == null)
            {
                this.RenderDescription = new Nodes.RenderDescription();
            }
            else
            {
                this.RenderDescription.ClearAll();
            }

            var drawaableRevitElements = elements.SelectMany(x => x.Select(y => dynRevitSettings.Doc.Document.GetElement(y)));

            Debug.WriteLine(string.Format("Drawing {0} elements of type : {1}", drawaableRevitElements.Count(),
                                          this.GetType()));

            foreach (Element e in drawaableRevitElements)
            {
                Draw(this.RenderDescription, e);
            }
        }
Esempio n. 17
0
        private void RenderDrawables(RenderDescription rd)
        {
            //Debug.WriteLine(string.Format("Rendering full screen Watch3D on thread {0}.", System.Threading.Thread.CurrentThread.ManagedThreadId));

            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);
        }
 public void Draw(RenderDescription description, object obj)
 {
     DrawElement(description, obj);
 }
        public static void DrawLibGGraphicItem(NodeModel node, object geom, string tag, RenderDescription rd,  Octree.OctreeSearch.Octree octree)
        {
            var selected = DynamoSelection.Instance.Selection.Contains(node);
            var g = geom as GraphicItem;

            if (g is CoordinateSystem)
            {
                #region draw coordinate systems

                var line_strip_vertices = g.line_strip_vertices_threadsafe();

                for (int i = 0; i < line_strip_vertices.Count; i += 6)
                {
                    var p1 = new Point3D(
                        line_strip_vertices[i],
                        line_strip_vertices[i + 1],
                        line_strip_vertices[i + 2]);

                    var p2 = new Point3D(
                        line_strip_vertices[i + 3],
                        line_strip_vertices[i + 4],
                        line_strip_vertices[i + 5]);

                    if (i < 6)
                    {
                        rd.XAxisPoints.Add(p1);
                        rd.XAxisPoints.Add(p2);
                    }
                    else if (i >= 6 && i < 12)
                    {
                        rd.YAxisPoints.Add(p1);
                        rd.YAxisPoints.Add(p2);
                    }
                    else
                    {
                        rd.ZAxisPoints.Add(p1);
                        rd.ZAxisPoints.Add(p2);
                    }
                }

                #endregion
            }
            else
            {
                #region draw points

                var point_vertices = g.point_vertices_threadsafe();

                for (int i = 0; i < point_vertices.Count; i += 3)
                {
                    var pos = new Point3D(point_vertices[i],
                        point_vertices[i + 1], point_vertices[i + 2]);

                    if (selected)
                    {
                        rd.SelectedPoints.Add(pos);
                    }
                    else
                    {
                        rd.Points.Add(pos);
                    }

                    if (node.DisplayLabels)
                    {
                        rd.Text.Add(new BillboardTextItem { Text = tag, Position = pos });
                    }
                }

                #endregion

                #region draw lines

                FloatList line_strip_vertices = g.line_strip_vertices_threadsafe();

                for (int i = 0; i < line_strip_vertices.Count-3; i += 3)
                {
                    var start = new Point3D(
                            line_strip_vertices[i],
                            line_strip_vertices[i + 1],
                            line_strip_vertices[i + 2]);

                    var end = new Point3D(
                            line_strip_vertices[i + 3],
                            line_strip_vertices[i + 4],
                            line_strip_vertices[i + 5]);

                    //draw a label at the start of the curve
                    if (node.DisplayLabels && i == 0)
                    {
                        rd.Text.Add(new BillboardTextItem { Text = tag, Position = start });
                    }

                    if (selected)
                    {
                        rd.SelectedLines.Add(start);
                        rd.SelectedLines.Add(end);
                    }
                    else
                    {
                        rd.Lines.Add(start);
                        rd.Lines.Add(end);
                    }
                }

                #endregion

                #region draw surface

                //var sw = new Stopwatch();
                //sw.Start();

                var builder = new MeshBuilder();
                var points = new Point3DCollection();
                var tex = new PointCollection();
                var norms = new Vector3DCollection();
                var tris = new List<int>();

                FloatList triangle_vertices = g.triangle_vertices_threadsafe();
                FloatList triangle_normals = g.triangle_normals_threadsafe();

                for (int i = 0; i < triangle_vertices.Count; i+=3)
                {
                    var new_point = new Point3D(triangle_vertices[i],
                                                triangle_vertices[i + 1],
                                                triangle_vertices[i + 2]);

                    var normal = new Vector3D(triangle_normals[i],
                                                triangle_normals[i + 1],
                                                triangle_normals[i + 2]);

                    //find a matching point
                    //compare the angle between the normals
                    //to discern a 'break' angle for adjacent faces
                    //int foundIndex = -1;
                    //for (int j = 0; j < points.Count; j++)
                    //{
                    //    var testPt = points[j];
                    //    var testNorm = norms[j];
                    //    var ang = Vector3D.AngleBetween(normal, testNorm);

                    //    if (new_point.X == testPt.X &&
                    //        new_point.Y == testPt.Y &&
                    //        new_point.Z == testPt.Z &&
                    //        ang > 90.0000)
                    //    {
                    //        foundIndex = j;
                    //        break;
                    //    }
                    //}

                    //if (foundIndex != -1)
                    //{
                    //    tris.Add(foundIndex);
                    //    continue;
                    //}

                    tris.Add(points.Count);
                    points.Add(new_point);
                    norms.Add(normal);
                    tex.Add(new System.Windows.Point(0,0));

                    octree.AddNode(new_point.X, new_point.Y, new_point.Z, node.GUID.ToString());
                }

                //builder.AddTriangles(points, norms, tex);
                builder.Append(points, tris, norms, tex);

                //sw.Stop();
                //Debug.WriteLine(string.Format("{0} elapsed for drawing geometry.", sw.Elapsed));

                //don't add empty meshes
                if (builder.Positions.Count > 0)
                {
                    if (selected)
                    {
                        rd.SelectedMeshes.Add(builder.ToMesh(true));
                    }
                    else
                    {
                        rd.Meshes.Add(builder.ToMesh(true));
                    }
                }

                #endregion
            }
        }
        private void RenderDrawables(RenderDescription rd)
        {
            //Debug.WriteLine(string.Format("Rendering full screen Watch3D on thread {0}.", System.Threading.Thread.CurrentThread.ManagedThreadId));
            
            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);
        }
Esempio n. 21
0
 public Visualization()
 {
     RequiresUpdate = false;
     Description = new RenderDescription();
     Geometry = new List<object>();
 }
 public static void DrawUndrawable(RenderDescription description, object obj)
 {
     //TODO: write a message, throw an exception, draw a question mark
 }