Example #1
0
        public override void RenderScene(View dBView, DisplayStyle displayStyle)
        {
            try
            {
                if (primitives == null)
                {
                    if (rhinoObject is Rhino.DocObjects.PointObject pointObject)
                    {
                        primitives = new Primitive[] { new ObjectPrimitive(pointObject, pointObject.PointGeometry) };
                    }
                    else if (rhinoObject is Rhino.DocObjects.PointCloudObject pointCloudObject)
                    {
                        AddPointCloudPreviews(pointCloudObject.PointCloudGeometry);
                    }
                    else if (rhinoObject is Rhino.DocObjects.CurveObject curveObject)
                    {
                        primitives = new Primitive[] { new ObjectPrimitive(curveObject, curveObject.CurveGeometry) };
                    }
                    else if (rhinoObject is Rhino.DocObjects.MeshObject meshObject)
                    {
                        AddMeshPreviews(meshObject.MeshGeometry);
                    }
                    else if (rhinoObject.IsMeshable(MeshType.Render))
                    {
                        var meshingParameters = rhinoObject.GetRenderMeshParameters();
                        if (rhinoObject.MeshCount(MeshType.Render, meshingParameters) == 0)
                        {
                            rhinoObject.CreateMeshes(MeshType.Render, meshingParameters, false);
                        }

                        var renderMeshes = rhinoObject.GetMeshes(MeshType.Render);
                        if (renderMeshes?.Length > 0)
                        {
                            int vertexCount = renderMeshes.Select((x) => x.Vertices.Count).Sum();

                            if (vertexCount > VertexThreshold)
                            {
                                foreach (var m in renderMeshes)
                                {
                                    AddMeshPreviews(m);
                                }
                            }
                            else
                            {
                                var previewMesh = renderMeshes.Length == 1 ? renderMeshes[0] : null;
                                if (previewMesh == null)
                                {
                                    previewMesh = new Rhino.Geometry.Mesh();
                                    previewMesh.Append(renderMeshes);
                                }

                                AddMeshPreviews(previewMesh);
                            }
                        }
                    }
                }

                if (primitives != null)
                {
                    DrawContext.SetWorldTransform(Autodesk.Revit.DB.Transform.Identity.ScaleBasis(1.0 / Revit.ModelUnits));

                    foreach (var primitive in primitives)
                    {
                        if (DrawContext.IsInterrupted())
                        {
                            return;
                        }

                        primitive.Draw(displayStyle);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Fail(e.Source, e.Message);
            }
        }
Example #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjRef obj_ref;

            const string prompt = "Select surface or polysurface to mesh";
            const Rhino.DocObjects.ObjectType object_type =
                Rhino.DocObjects.ObjectType.Surface |
                Rhino.DocObjects.ObjectType.Brep;

            Result res = Rhino.Input.RhinoGet.GetOneObject(prompt, false, object_type, out obj_ref);

            if (res != Result.Success)
            {
                return(res);
            }

            Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
            if (null == obj)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Mesh obj_mesh = new Rhino.Geometry.Mesh();

            Rhino.Geometry.Mesh[] meshes = obj.GetMeshes(Rhino.Geometry.MeshType.Render);
            if (meshes.Length > 0)
            {
                foreach (Rhino.Geometry.Mesh m in meshes)
                {
                    obj_mesh.Append(m);
                }
            }
            else
            {
                Rhino.Geometry.MeshingParameters mesh_params = obj.GetRenderMeshParameters();
                if (obj.CreateMeshes(Rhino.Geometry.MeshType.Render, mesh_params, false) > 0)
                {
                    meshes = obj.GetMeshes(Rhino.Geometry.MeshType.Render);
                    if (meshes.Length > 0)
                    {
                        foreach (Rhino.Geometry.Mesh m in meshes)
                        {
                            obj_mesh.Append(m);
                        }
                    }
                }
            }

            if (obj_mesh.IsValid)
            {
                obj_mesh.Faces.ConvertQuadsToTriangles();
            }

            if (obj_mesh.IsValid)
            {
                doc.Objects.AddMesh(obj_mesh);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }