コード例 #1
0
    public static Rhino.Commands.Result UnrollSurface2(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Unroller unroll = null;
        Rhino.Geometry.Brep     brep   = objref.Brep();
        Rhino.Geometry.Mesh     mesh   = null;
        if (brep != null)
        {
            unroll = new Rhino.Geometry.Unroller(brep);
            mesh   = brep.Faces[0].GetMesh(Rhino.Geometry.MeshType.Render);
        }
        else
        {
            Rhino.Geometry.Surface srf = objref.Surface();
            if (srf != null)
            {
                unroll = new Rhino.Geometry.Unroller(srf);
            }
        }
        if (unroll == null || mesh == null)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        unroll.AddFollowingGeometry(mesh.Vertices.ToPoint3dArray());

        unroll.ExplodeOutput = false;
        Rhino.Geometry.Curve[]   curves;
        Rhino.Geometry.Point3d[] points;
        Rhino.Geometry.TextDot[] dots;
        unroll.PerformUnroll(out curves, out points, out dots);

        // change the mesh vertices to the flattened form and add it to the document
        if (points.Length == mesh.Vertices.Count)
        {
            for (int i = 0; i < points.Length; i++)
            {
                mesh.Vertices.SetVertex(i, points[i]);
            }
            mesh.Normals.ComputeNormals();
        }
        doc.Objects.AddMesh(mesh, objref.Object().Attributes);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
コード例 #2
0
  public static Rhino.Commands.Result UnrollSurface2(Rhino.RhinoDoc doc)
  {
    const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;
    Rhino.DocObjects.ObjRef objref;
    Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    Rhino.Geometry.Unroller unroll=null;
    Rhino.Geometry.Brep brep = objref.Brep();
    Rhino.Geometry.Mesh mesh=null;
    if (brep != null)
    {
      unroll = new Rhino.Geometry.Unroller(brep);
      mesh = brep.Faces[0].GetMesh(Rhino.Geometry.MeshType.Render);
    }
    else
    {
      Rhino.Geometry.Surface srf = objref.Surface();
      if (srf != null)
      {
        unroll = new Rhino.Geometry.Unroller(srf);
      }
    }
    if (unroll == null || mesh==null)
      return Rhino.Commands.Result.Cancel;

    unroll.AddFollowingGeometry(mesh.Vertices.ToPoint3dArray());

    unroll.ExplodeOutput = false;
    Rhino.Geometry.Curve[] curves;
    Rhino.Geometry.Point3d[] points;
    Rhino.Geometry.TextDot[] dots;
    unroll.PerformUnroll(out curves, out points, out dots);

    // change the mesh vertices to the flattened form and add it to the document
    if( points.Length == mesh.Vertices.Count )
    {
      for( int i=0; i<points.Length; i++ )
        mesh.Vertices.SetVertex(i, points[i]);
      mesh.Normals.ComputeNormals();
    }
    doc.Objects.AddMesh(mesh, objref.Object().Attributes);
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
コード例 #3
0
  public static Rhino.Commands.Result UnrollSurface(Rhino.RhinoDoc doc)
  {
    const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;
    Rhino.DocObjects.ObjRef objref;
    Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);
    if (rc != Rhino.Commands.Result.Success)
      return rc;
    Rhino.Geometry.Unroller unroll=null;
    Rhino.Geometry.Brep brep = objref.Brep();
    if (brep != null)
      unroll = new Rhino.Geometry.Unroller(brep);
    else
    {
      Rhino.Geometry.Surface srf = objref.Surface();
      if (srf != null)
        unroll = new Rhino.Geometry.Unroller(srf);
    }
    if (unroll == null)
      return Rhino.Commands.Result.Cancel;

    unroll.AbsoluteTolerance = 0.01;
    unroll.RelativeTolerance = 0.01;

    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select points, curves, and dots to unroll with surface");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot;
    go.AcceptNothing(true);
    go.GetMultiple(0, 0);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();
    for (int i = 0; i < go.ObjectCount; i++)
    {
      objref = go.Object(i);
      Rhino.Geometry.GeometryBase g = objref.Geometry();
      Rhino.Geometry.Point pt = g as Rhino.Geometry.Point;
      Rhino.Geometry.Curve crv = g as Rhino.Geometry.Curve;
      Rhino.Geometry.TextDot dot = g as Rhino.Geometry.TextDot;
      if (pt != null)
        unroll.AddFollowingGeometry(pt.Location);
      else if (crv != null)
        unroll.AddFollowingGeometry(crv);
      else if (dot != null)
        unroll.AddFollowingGeometry(dot);
    }

    unroll.ExplodeOutput = false;
    Rhino.Geometry.Curve[] curves;
    Rhino.Geometry.Point3d[] points;
    Rhino.Geometry.TextDot[] dots;
    Rhino.Geometry.Brep[] breps = unroll.PerformUnroll(out curves, out points, out dots);
    if (breps == null || breps.Length < 1)
      return Rhino.Commands.Result.Failure;

    for (int i = 0; i < breps.Length; i++)
      doc.Objects.AddBrep(breps[i]);
    for (int i = 0; i < curves.Length; i++)
      doc.Objects.AddCurve(curves[i]);
    doc.Objects.AddPoints(points);
    for (int i = 0; i < dots.Length; i++)
      doc.Objects.AddTextDot(dots[i]);
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
コード例 #4
0
    public static Rhino.Commands.Result UnrollSurface(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface;

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Unroller unroll = null;
        Rhino.Geometry.Brep     brep   = objref.Brep();
        if (brep != null)
        {
            unroll = new Rhino.Geometry.Unroller(brep);
        }
        else
        {
            Rhino.Geometry.Surface srf = objref.Surface();
            if (srf != null)
            {
                unroll = new Rhino.Geometry.Unroller(srf);
            }
        }
        if (unroll == null)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        unroll.AbsoluteTolerance = 0.01;
        unroll.RelativeTolerance = 0.01;

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select points, curves, and dots to unroll with surface");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot;
        go.AcceptNothing(true);
        go.GetMultiple(0, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        for (int i = 0; i < go.ObjectCount; i++)
        {
            objref = go.Object(i);
            Rhino.Geometry.GeometryBase g   = objref.Geometry();
            Rhino.Geometry.Point        pt  = g as Rhino.Geometry.Point;
            Rhino.Geometry.Curve        crv = g as Rhino.Geometry.Curve;
            Rhino.Geometry.TextDot      dot = g as Rhino.Geometry.TextDot;
            if (pt != null)
            {
                unroll.AddFollowingGeometry(pt.Location);
            }
            else if (crv != null)
            {
                unroll.AddFollowingGeometry(crv);
            }
            else if (dot != null)
            {
                unroll.AddFollowingGeometry(dot);
            }
        }

        unroll.ExplodeOutput = false;
        Rhino.Geometry.Curve[]   curves;
        Rhino.Geometry.Point3d[] points;
        Rhino.Geometry.TextDot[] dots;
        Rhino.Geometry.Brep[]    breps = unroll.PerformUnroll(out curves, out points, out dots);
        if (breps == null || breps.Length < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        for (int i = 0; i < breps.Length; i++)
        {
            doc.Objects.AddBrep(breps[i]);
        }
        for (int i = 0; i < curves.Length; i++)
        {
            doc.Objects.AddCurve(curves[i]);
        }
        doc.Objects.AddPoints(points);
        for (int i = 0; i < dots.Length; i++)
        {
            doc.Objects.AddTextDot(dots[i]);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
コード例 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---- Declareing ---------------------------------------------------------------------------
            GH_Structure<GH_Brep> AllStripes;
            DA.GetDataTree("Triloop Stipes", out AllStripes);

            GH_Structure<GH_Point> AllPoints;
            DA.GetDataTree("Points", out AllPoints);

            bool Reorient = false;
            DA.GetData<bool>("Merge Stripes", ref Reorient);

            bool Switch = false;
            DA.GetData<bool>("Switch", ref Switch);

            int Seam = 0;
            DA.GetData<int>("Seam", ref Seam);

            DataTree<Brep> AllUnrolledBreps = new DataTree<Brep>();
            DataTree<Brep> ForReorientBreps = new DataTree<Brep>();
            DataTree<Plane> AllOrientPlanes = new DataTree<Plane>();
            DataTree<Curve> AllSharedCurves = new DataTree<Curve>();
            DataTree<Point3d> AllUnrolledPoints = new DataTree<Point3d>();

            //---- End Declareing -----------------------------------------------------------------------
            //---- Functions ----------------------------------------------------------------------------

            #region Unroll

            for (int i = 0; i < AllStripes.Branches.Count; i++)
            {
                GH_Path pth = new GH_Path(i);
                GH_Path originalPath = AllStripes.Paths[i];
                int stripecounter = 0;

                foreach (GH_Brep gbrep in AllStripes[i])
                {
                    Unroller unroll = new Unroller(gbrep.Value);
                    // Add points to unroll with
                    if (AllPoints.Branches.Count != 0)
                    {
                        foreach (GH_Point pt in AllPoints[i])
                        { unroll.AddFollowingGeometry(pt.Value); }
                    }

                    unroll.ExplodeOutput = false;

                    Curve[] curves;
                    Point3d[] unrolledPoints;
                    TextDot[] dots;
                    Brep[] unrolledBreps = unroll.PerformUnroll(out curves, out unrolledPoints, out dots);

                    if (Reorient == false)
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, originalPath); }

                        foreach (Point3d p in unrolledPoints)
                        { AllUnrolledPoints.Add(p, originalPath); }
                    }

                    else
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, pth.AppendElement(stripecounter)); }
                    }

                    // For reorientation
                    if (Reorient == true)
                    { ForReorientBreps.Add(unrolledBreps[Seam], pth); }

                    stripecounter++;
                }
            }
            #endregion unroll

            if (Reorient == true)
            {
                //ForReorientBreps.Branch(0)[0].Curves3D[0].PointAtEnd;

                for (int i = 0; i < ForReorientBreps.BranchCount; i++)
                {
                    GH_Path pth = new GH_Path(i);

                    foreach (Curve crv0 in ForReorientBreps.Branch(i)[0].Curves3D)
                    {
                        foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv1.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {

                                // orient crv0
                                Plane origin0 = new Plane(new Point3d(0, 0, 0), new Vector3d(1, 0, 0), new Vector3d(0, 1, 0));
                                Plane target0 = new Plane(origin0);
                                AllOrientPlanes.Add(origin0, pth.AppendElement(0));
                                AllOrientPlanes.Add(target0, pth.AppendElement(0));

                                // orient crv1
                                Vector3d vect0 = crv1.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin1 = new Plane(crv1.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target1 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin1, pth.AppendElement(1));
                                AllOrientPlanes.Add(target1, pth.AppendElement(1));
                                // shared curve of stripe0 and stripe 1
                                AllSharedCurves.Add(crv0, pth.AppendElement(0));
                                AllSharedCurves.Add(crv1, pth.AppendElement(0));

                            }
                        }

                        // orient crv2
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv2.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {
                                Vector3d vect0 = crv2.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin2 = new Plane(crv2.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target2 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin2, pth.AppendElement(2));
                                AllOrientPlanes.Add(target2, pth.AppendElement(2));
                                // shared curve of stripe0 and stripe 2
                                AllSharedCurves.Add(crv2, pth.AppendElement(2));
                                AllSharedCurves.Add(crv0, pth.AppendElement(2));
                            }
                        }

                    }
                    // find the shared curve oft stripe 1 and stripe 2
                    foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                    {
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l1 = crv1.GetLength();
                            double l2 = crv2.GetLength();

                            // shared curve of stripe1 and stripe 2
                            if (Math.Abs(l1 - l2) < 0.00001)
                            {
                                AllSharedCurves.Add(crv1, pth.AppendElement(1));
                                AllSharedCurves.Add(crv2, pth.AppendElement(1));
                            }

                        }

                    }
                }

            }

            //---- End Functions --------------------------------------------------------------------------
            //----Set Output-------------------------------------------------------------------------------

            DA.SetDataTree(0, AllUnrolledBreps);
            DA.SetDataTree(1, AllOrientPlanes);
            DA.SetDataTree(2, AllSharedCurves);
            DA.SetDataTree(3, AllUnrolledPoints);

            //----End Set Output---------------------------------------------------------------------------
        }