Пример #1
0
        public static rg.Transform ToRgTransform(this Transform transform)
        {
            rg.Transform t = rg.Transform.Identity;
            if (transform == null)
            {
                return(t);
            }
            var mtx = transform.Matrix;

            t.M00 = mtx.m11;
            t.M01 = mtx.m21;
            t.M02 = mtx.m31;
            t.M03 = mtx.tx;
            t.M10 = mtx.m12;
            t.M11 = mtx.m22;
            t.M12 = mtx.m32;
            t.M13 = mtx.ty;
            t.M20 = mtx.m13;
            t.M21 = mtx.m23;
            t.M22 = mtx.m33;
            t.M23 = mtx.tz;
            t.M30 = 0;
            t.M31 = 0;
            t.M32 = 0;
            t.M33 = 1;

            return(t);
        }
        /// <summary>
        /// Transform calculator
        /// </summary>
        public bool CalculateTransform(Rhino.Display.RhinoViewport vp, double length, ref Rhino.Geometry.Transform xform)
        {
            bool rc = false;

            if (null == xform)
            {
                xform = new Rhino.Geometry.Transform();
            }
            xform = Rhino.Geometry.Transform.Identity;

            if (length >= Rhino.RhinoMath.ZeroTolerance)
            {
                Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane())
                {
                    Origin = m_origin
                };

                Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane);
                Rhino.Geometry.Transform scale_xform  = Rhino.Geometry.Transform.Scale(plane, length, length, length);

                xform = scale_xform * rotate_xform;
                rc    = xform.IsValid;

                if (rc)
                {
                    m_length = length;
                }
            }

            return(rc);
        }
Пример #3
0
        static public Rhino.Geometry.Transform ToRhino(this Autodesk.Revit.DB.Transform transform)
        {
            var value = new Rhino.Geometry.Transform
            {
                M00 = transform.BasisX.X,
                M10 = transform.BasisX.Y,
                M20 = transform.BasisX.Z,
                M30 = 0.0,

                M01 = transform.BasisY.X,
                M11 = transform.BasisY.Y,
                M21 = transform.BasisY.Z,
                M31 = 0.0,

                M02 = transform.BasisZ.X,
                M12 = transform.BasisZ.Y,
                M22 = transform.BasisZ.Z,
                M32 = 0.0,

                M03 = transform.Origin.X,
                M13 = transform.Origin.Y,
                M23 = transform.Origin.Z,
                M33 = 1.0
            };

            return(value);
        }
Пример #4
0
        /***************************************************/

        public static BHG.TransformMatrix FromRhino(this RHG.Transform rhTrans)
        {
            BHG.TransformMatrix bhTrans = new BHG.TransformMatrix();
            bhTrans.Matrix[0, 0] = rhTrans[0, 0];
            bhTrans.Matrix[0, 1] = rhTrans[0, 1];
            bhTrans.Matrix[0, 2] = rhTrans[0, 2];
            bhTrans.Matrix[0, 3] = rhTrans[0, 3];

            bhTrans.Matrix[1, 0] = rhTrans[1, 0];
            bhTrans.Matrix[1, 1] = rhTrans[1, 1];
            bhTrans.Matrix[1, 2] = rhTrans[1, 2];
            bhTrans.Matrix[1, 3] = rhTrans[1, 3];

            bhTrans.Matrix[2, 0] = rhTrans[2, 0];
            bhTrans.Matrix[2, 1] = rhTrans[2, 1];
            bhTrans.Matrix[2, 2] = rhTrans[2, 2];
            bhTrans.Matrix[2, 3] = rhTrans[2, 3];

            bhTrans.Matrix[3, 0] = rhTrans[3, 0];
            bhTrans.Matrix[3, 1] = rhTrans[3, 1];
            bhTrans.Matrix[3, 2] = rhTrans[3, 2];
            bhTrans.Matrix[3, 3] = rhTrans[3, 3];

            return(bhTrans);
        }
Пример #5
0
        public override Rhino.Geometry.BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            var b = Boundingbox;

            b.Transform(xform);
            return(b);
        }
Пример #6
0
        public static Rhino.Geometry.Transform ToRhinoTransform(NXOpen.Matrix4x4 transform)
        {
            var value = new Rhino.Geometry.Transform
            {
                M00 = transform.Rxx,
                M10 = transform.Rxy,
                M20 = transform.Rxz,
                M30 = 0.0,

                M01 = transform.Ryx,
                M11 = transform.Ryy,
                M21 = transform.Ryz,
                M31 = 0.0,

                M02 = transform.Rzx,
                M12 = transform.Rzy,
                M22 = transform.Rzz,
                M32 = 0.0,

                M03 = transform.Sx,
                M13 = transform.Sy,
                M23 = transform.Sz,
                M33 = 1.0
            };

            return(value);
        }
Пример #7
0
        /***************************************************/

        public static RHG.Transform ToRhino(this BHG.TransformMatrix bhTrans)
        {
            if (bhTrans == null)
            {
                return(default(RHG.Transform));
            }

            RHG.Transform rhTrans = new RHG.Transform();
            rhTrans[0, 0] = bhTrans.Matrix[0, 0];
            rhTrans[0, 1] = bhTrans.Matrix[0, 1];
            rhTrans[0, 2] = bhTrans.Matrix[0, 2];
            rhTrans[0, 3] = bhTrans.Matrix[0, 3];

            rhTrans[1, 0] = bhTrans.Matrix[1, 0];
            rhTrans[1, 1] = bhTrans.Matrix[1, 1];
            rhTrans[1, 2] = bhTrans.Matrix[1, 2];
            rhTrans[1, 3] = bhTrans.Matrix[1, 3];

            rhTrans[2, 0] = bhTrans.Matrix[2, 0];
            rhTrans[2, 1] = bhTrans.Matrix[2, 1];
            rhTrans[2, 2] = bhTrans.Matrix[2, 2];
            rhTrans[2, 3] = bhTrans.Matrix[2, 3];

            rhTrans[3, 0] = bhTrans.Matrix[3, 0];
            rhTrans[3, 1] = bhTrans.Matrix[3, 1];
            rhTrans[3, 2] = bhTrans.Matrix[3, 2];
            rhTrans[3, 3] = bhTrans.Matrix[3, 3];

            return(rhTrans);
        }
Пример #8
0
        public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            if (Value == null)
            {
                return(BoundingBox.Empty);
            }

            var bbox = BoundingBox.Empty;

            if (xform == Rhino.Geometry.Transform.Identity)
            {
                foreach (var curve in Curves)
                {
                    bbox.Union(curve.GetBoundingBox(true));
                }
            }
            else
            {
                foreach (var curve in Curves)
                {
                    bbox.Union(curve.GetBoundingBox(xform));
                }
            }

            return(bbox);
        }
Пример #9
0
    public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
    {
      if (Value == null)
        return BoundingBox.Empty;

      return xform == Rhino.Geometry.Transform.Identity ?
        Curve.GetBoundingBox(true) :
        Curve.GetBoundingBox(xform);
    }
Пример #10
0
        static public Autodesk.Revit.DB.Transform ToHost(this Rhino.Geometry.Transform transform)
        {
            var value = Autodesk.Revit.DB.Transform.CreateTranslation(new XYZ(transform.M03, transform.M13, transform.M23));

            value.BasisX = new XYZ(transform.M00, transform.M10, transform.M20);
            value.BasisY = new XYZ(transform.M01, transform.M11, transform.M21);
            value.BasisZ = new XYZ(transform.M02, transform.M12, transform.M22);
            return(value);
        }
Пример #11
0
        public virtual void Transform(Rhino.Geometry.Transform xform)
        {
            Geometry.Transform(xform);
            m_plane.Transform(xform);

            for (int i = 0; i < Handles.Count; ++i)
            {
                Handles[i].Transform(xform);
            }
        }
Пример #12
0
        public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            if (Value == null)
            {
                return(BoundingBox.Empty);
            }

            return(xform == Rhino.Geometry.Transform.Identity ?
                   Point.GetBoundingBox(true) :
                   Point.GetBoundingBox(xform));
        }
Пример #13
0
        /// <summary> Add a point </summary>
        /// <param name="doc"></param>
        /// <param name="point"></param>
        /// <returns> ?? </returns>
        public Rhino.Geometry.Point3d AddPoint(RhinoDoc doc, System.Drawing.Point point)
        {
            Rhino.Geometry.Point3d start1 = new Point3d((point.X) - 400, (-point.Y) + 400, zDepth + .5);

            Rhino.Geometry.Transform plnXForm = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane1);
            start1.Transform(plnXForm);

            mRhinoDoc.Objects.AddPoint(start1);
            mRhinoDoc.Views.Redraw();

            return(start1);
        }
Пример #14
0
        /// <summary> btnNewDwgPlane creates new drawing plane perpedicular to camera centered around chosed origin </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewDwgPlane_Click(object sender, EventArgs e)
        {
            Rhino.Geometry.Point3d pt1 = org;

            Rhino.Geometry.Transform move1 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraX);
            Rhino.Geometry.Transform move2 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraY);

            var xRev = view3.MainViewport.CameraX;
            var yRev = view3.MainViewport.CameraY;

            xRev.Reverse();
            yRev.Reverse();

            Rhino.Geometry.Transform move3 = Rhino.Geometry.Transform.Translation(xRev);
            Rhino.Geometry.Transform move4 = Rhino.Geometry.Transform.Translation(yRev);

            Rhino.Geometry.Point3d pt2 = org;
            Rhino.Geometry.Point3d pt3 = org;
            Rhino.Geometry.Point3d pt4 = org;
            Rhino.Geometry.Point3d pt5 = org;

            //Rhino.Geometry.Vector3d.l

            pt2.Transform(move1);
            pt2.Transform(move2);

            pt3.Transform(move3);
            pt3.Transform(move4);

            pt4.Transform(move1);
            pt4.Transform(move4);

            pt5.Transform(move3);
            pt5.Transform(move2);

            srf1   = Rhino.Geometry.NurbsSurface.CreateFromCorners(pt2, pt4, pt3, pt5);
            plane1 = new Plane(org, view3.MainViewport.CameraX, view3.MainViewport.CameraY);
            Rhino.Geometry.Transform scale1 = Rhino.Geometry.Transform.Scale(org, 400);
            srf1.Transform(scale1);

            mRhinoDoc.Objects.AddPoint(pt1);
            mRhinoDoc.Objects.AddPoint(pt2);
            mRhinoDoc.Objects.AddPoint(pt3);
            mRhinoDoc.Objects.AddPoint(pt4);
            mRhinoDoc.Objects.AddPoint(pt5);

            mRhinoDoc.Objects.AddSurface(srf1);

            mRhinoDoc.Views.Redraw();
        }
Пример #15
0
        public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            if (Value == null)
            {
                return(BoundingBox.Empty);
            }

            bool IsIdentity = xform == Rhino.Geometry.Transform.Identity;
            var  point      = new Rhino.Geometry.Point(Value.Coord.ToRhino());

            point.Scale(Revit.ModelUnits);
            var bbox = IsIdentity ? point.GetBoundingBox(true) : point.GetBoundingBox(xform);

            return(bbox);
        }
Пример #16
0
        public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            if (Value == null)
            {
                return(BoundingBox.Empty);
            }

            bool IsIdentity = xform == Rhino.Geometry.Transform.Identity;
            var  curve      = Value.AsCurve().ToRhino();

            curve.Scale(Revit.ModelUnits);
            var bbox = IsIdentity ? curve.GetBoundingBox(true) : curve.GetBoundingBox(xform);

            return(bbox);
        }
Пример #17
0
 public void GenBaseCrvFloors()
 {
     BaseFlrCrvs = new List <Curve>();
     BaseCrvPts  = new List <List <Point3d> >();
     foreach (Curve crv in InpCrvs)
     {
         BaseCrvPts.Add(GetPtLiFromCrv(crv));
         for (int i = 0; i < NumBaseFlrs; i++)
         {
             Curve dupCrv = crv.DuplicateCurve();
             Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, FlrHt * i);
             dupCrv.Transform(xform);
             BaseFlrCrvs.Add(dupCrv);
         }
     }
 }
        /// <summary>
        /// Transform calculator
        /// </summary>
        public bool CalculateTransform(Rhino.Display.RhinoViewport vp, Rhino.Geometry.Point3d pt, ref Rhino.Geometry.Transform xform)
        {
            bool rc = false;

            if (null == xform)
            {
                xform = new Rhino.Geometry.Transform();
            }
            xform = Rhino.Geometry.Transform.Identity;

            if (pt.IsValid)
            {
                Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane())
                {
                    Origin = m_origin
                };

                Rhino.Geometry.Vector3d xaxis = (pt - plane.Origin);
                double length = xaxis.Length;

                if (length >= Rhino.RhinoMath.ZeroTolerance)
                {
                    Rhino.Geometry.Vector3d yaxis;
                    yaxis = 0 != xaxis.IsParallelTo(plane.Normal) ? plane.YAxis : Rhino.Geometry.Vector3d.CrossProduct(plane.Normal, xaxis);

                    plane = new Rhino.Geometry.Plane(plane.Origin, xaxis, yaxis);
                    if (!plane.IsValid)
                    {
                        return(rc);
                    }

                    Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane);
                    Rhino.Geometry.Transform scale_xform  = Rhino.Geometry.Transform.Scale(plane, length, length, length);

                    xform = scale_xform * rotate_xform;
                    rc    = xform.IsValid;

                    if (rc)
                    {
                        m_length = length;
                    }
                }
            }

            return(rc);
        }
Пример #19
0
        public GenCBspGeom(Curve site_crv, List <string> adjObjLi_, List <GeomObj> norGeomObjLi_, double rot)
        {
            SITE_CRV     = site_crv;
            AdjObjLi     = adjObjLi_;
            NorGeomObjLi = norGeomObjLi_;
            Rotation     = Rhino.RhinoMath.ToRadians(rot);

            Point3d SITE_CEN = AreaMassProperties.Compute(SITE_CRV).Centroid;

            XForm        = Rhino.Geometry.Transform.Rotation(Rotation, SITE_CEN);
            reverseXForm = Rhino.Geometry.Transform.Rotation(-Rotation, SITE_CEN);

            rot_SITE_CRV = SITE_CRV.DuplicateCurve();
            rot_SITE_CRV.Transform(XForm);

            BSPCrvs        = new List <Curve>();
            ResultBBxPolys = new List <Curve>();
        }
Пример #20
0
 private static void SerializeTransform(BinaryWriter Writer, Rhino.Geometry.Transform RhinoTransform)
 {
     Writer.Write(RhinoTransform.M00);
     Writer.Write(RhinoTransform.M01);
     Writer.Write(RhinoTransform.M02);
     Writer.Write(RhinoTransform.M03);
     Writer.Write(RhinoTransform.M10);
     Writer.Write(RhinoTransform.M11);
     Writer.Write(RhinoTransform.M12);
     Writer.Write(RhinoTransform.M13);
     Writer.Write(RhinoTransform.M20);
     Writer.Write(RhinoTransform.M21);
     Writer.Write(RhinoTransform.M22);
     Writer.Write(RhinoTransform.M23);
     Writer.Write(RhinoTransform.M30);
     Writer.Write(RhinoTransform.M31);
     Writer.Write(RhinoTransform.M32);
     Writer.Write(RhinoTransform.M33);
 }
Пример #21
0
        public static Transform ToTransform(this rg.Transform xform)
        {
            var mtx = new Matrix();

            mtx.m11 = xform.M00;
            mtx.m12 = xform.M10;
            mtx.m13 = xform.M20;
            mtx.m21 = xform.M01;
            mtx.m22 = xform.M11;
            mtx.m23 = xform.M21;
            mtx.m31 = xform.M02;
            mtx.m32 = xform.M12;
            mtx.m33 = xform.M22;
            mtx.tx  = xform.M03;
            mtx.ty  = xform.M13;
            mtx.tz  = xform.M23;

            return(new Transform(mtx));
        }
Пример #22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string name  = "";
            Plane  bpl   = Plane.WorldXY;
            Plane  tcppl = Plane.WorldXY;
            double w     = 0;

            if (!DA.GetData(0, ref name))
            {
                return;
            }
            if (!DA.GetData(1, ref bpl))
            {
                return;
            }
            if (!DA.GetData(2, ref tcppl))
            {
                return;
            }
            if (!DA.GetData(3, ref w))
            {
                return;
            }

            // Create a TCP plane as
            Rhino.Geometry.Transform rel = Rhino.Geometry.Transform.ChangeBasis(Plane.WorldXY, bpl);
            if (!tcppl.Transform(rel))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid input planes");
                return;
            }

            Point3d          cog = 0.5 * tcppl.Origin;
            ActionDefineTool adf = new ActionDefineTool(name,
                                                        tcppl.OriginX, tcppl.OriginY, tcppl.OriginZ,
                                                        tcppl.XAxis.X, tcppl.XAxis.Y, tcppl.XAxis.Z,
                                                        tcppl.YAxis.X, tcppl.YAxis.Y, tcppl.YAxis.Z,
                                                        w,
                                                        cog.X, cog.Y, cog.Z);

            DA.SetData(0, adf);
        }
        /// <summary>
        /// Dynamic draw event handler
        /// </summary>
        void PlatonicGetPoint_DynamicDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
        {
            if (m_draw)
            {
                if (null != m_faces && null != m_xform)
                {
                    Rhino.Geometry.Transform model_xform = e.Display.ModelTransform;
                    e.Display.ModelTransform = m_xform;

                    System.Drawing.Color color = e.RhinoDoc.Layers.CurrentLayer.Color;
                    foreach (Brep t in m_faces)
                    {
                        if (null != t)
                        {
                            e.Display.DrawBrepWires(t, color);
                        }
                    }

                    e.Display.ModelTransform = model_xform;
                }
            }
        }
Пример #24
0
        public override BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform)
        {
            if (Value == null)
            {
                return(BoundingBox.Empty);
            }

            bool IsIdentity = xform == Rhino.Geometry.Transform.Identity;
            var  bbox       = BoundingBox.Empty;

            foreach (var loop in Value.EdgeLoops.OfType <Autodesk.Revit.DB.EdgeArray>())
            {
                foreach (var edge in loop.OfType <Autodesk.Revit.DB.Edge>())
                {
                    var curve = edge.AsCurve().ToRhino();
                    curve.Scale(Revit.ModelUnits);
                    bbox.Union(IsIdentity ? curve.GetBoundingBox(true) : curve.GetBoundingBox(xform));
                }
            }

            return(bbox);
        }
Пример #25
0
        public override IGH_GeometricGoo Transform(Rhino.Geometry.Transform xform)
        {
            if (m_value != null)
            {
                var m = new PlanktonMesh(m_value);

                foreach (var v in m.Vertices)
                {
                    Point3f p = new Point3f(v.X, v.Y, v.Z);
                    p.Transform(xform);

                    v.X = p.X;
                    v.Y = p.Y;
                    v.Z = p.Z;
                }

                return(new GH_PlanktonMesh(m));
            }
            else
            {
                return(new GH_PlanktonMesh(null));
            }
        }
Пример #26
0
        public void genBaseMass()
        {
            PolylineCurve outerCrv    = new PolylineCurve(outerPtLi);
            double        outerAr     = AreaMassProperties.Compute(outerCrv).Area;
            PolylineCurve innerCrv    = new PolylineCurve(innerPtLi);
            double        innerAr     = AreaMassProperties.Compute(innerCrv).Area;
            double        diffAr      = outerAr - innerAr;
            int           numBaseFlrs = (int)(SITE_AR * baseFsr / diffAr) + 1;
            double        baseHt      = numBaseFlrs * flrHt;
            Extrusion     outerExtr   = Extrusion.Create(outerCrv, baseHt, true);
            Extrusion     innerExtr   = Extrusion.Create(innerCrv, baseHt, true);

            Brep[] outerBrep = { outerExtr.ToBrep() };
            Brep[] innerBrep = { innerExtr.ToBrep() };
            Brep[] diffBrep  = Brep.CreateBooleanDifference(outerBrep, innerBrep, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
            for (int i = 0; i < diffBrep.Length; i++)
            {
                globalBrepLi.Add(diffBrep[i]);
            }

            globalBaseCrvLi = new List <Curve>();
            double spineHt = 0.0;

            for (int i = 0; i < numBaseFlrs; i++)
            {
                Curve outerCrvDup = outerCrv.DuplicateCurve();
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, spineHt);
                outerCrvDup.Transform(xform);
                Curve innerCrvDup = innerCrv.DuplicateCurve();
                innerCrvDup.Transform(xform);
                globalBaseCrvLi.Add(innerCrvDup);
                globalBaseCrvLi.Add(outerCrvDup);
                spineHt += flrHt;
            }
            BaseMassHt = baseHt;
        }
Пример #27
0
        public static NXOpen.Matrix4x4 ToMatrix4x4(this Rhino.Geometry.Transform value, double factor)
        {
            Debug.Assert(value.IsAffine);

            NXOpen.Matrix4x4 result = default;
            result.Ss = factor;
            result.Sx = 0.0;
            result.Sy = 0.0;
            result.Sz = 0.0;

            result.Rxx = value.M00;
            result.Rxy = value.M10;
            result.Rxz = value.M20;

            result.Ryx = value.M01;
            result.Ryy = value.M11;
            result.Ryz = value.M21;

            result.Rzx = value.M02;
            result.Rzy = value.M12;
            result.Rzz = value.M22;

            return(result);
        }
Пример #28
0
 /// <summary>
 /// Computes a transform from a coordinate system to another.
 /// </summary>
 /// <param name="sourceSystem">The coordinate system to map from.</param>
 /// <param name="destinationSystem">The coordinate system to map into.</param>
 /// <returns>The 4x4 transformation matrix (acts on the left).</returns>
 public Rhino.Geometry.Transform GetXform(Rhino.DocObjects.CoordinateSystem sourceSystem, Rhino.DocObjects.CoordinateSystem destinationSystem)
 {
   Rhino.Geometry.Transform matrix = new Rhino.Geometry.Transform();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_Viewport_GetXform(pConstThis, (int)sourceSystem, (int)destinationSystem, ref matrix))
     matrix = Rhino.Geometry.Transform.Unset;
   return matrix;
 }
Пример #29
0
        /// <summary>
        /// Executes the platonic command
        /// </summary>
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Get the platonic geometry
            Rhino.Geometry.Brep[] faces = Platonic.Faces();
            if (null == faces)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Prompt for center point
            string prompt = string.Format("Center of {0}", Platonic.DisplayName.ToLower());

            Rhino.Geometry.Point3d origin;
            Rhino.Commands.Result  rc = Rhino.Input.RhinoGet.GetPoint(prompt, false, out origin);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }

            double length       = m_length;
            bool   create_solid = m_create_solid;
            bool   group_faces  = m_group_faces;

            // Prompt for edge length
            PlatonicGetPoint get = new PlatonicGetPoint(faces, origin);

            get.SetCommandPrompt(Platonic.Prompt);
            get.SetDefaultNumber(length);
            get.SetBasePoint(origin, true);
            get.DrawLineFromPoint(origin, true);
            get.AcceptNumber(true, false);

            Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform(1.0);
            rc = Rhino.Commands.Result.Cancel;

            for (; ;)
            {
                get.ClearCommandOptions();

                Rhino.Input.Custom.OptionToggle output_toggle = null;
                Rhino.Input.Custom.OptionToggle group_toggle  = null;

                output_toggle = new Rhino.Input.Custom.OptionToggle(create_solid, "Faces", "Solid");
                get.AddOptionToggle("Output", ref output_toggle);

                if (!create_solid)
                {
                    group_toggle = new Rhino.Input.Custom.OptionToggle(group_faces, "No", "Yes");
                    get.AddOptionToggle("Group", ref group_toggle);
                }

                Rhino.Input.GetResult res = get.Get();

                if (res == Rhino.Input.GetResult.Point)
                {
                    if (get.CalculateTransform(get.View().ActiveViewport, get.Point(), ref xform))
                    {
                        m_length = get.Length;
                        rc       = Rhino.Commands.Result.Success;
                        break;
                    }
                }
                else if (res == Rhino.Input.GetResult.Number)
                {
                    length = System.Math.Abs(get.Number());
                    if (get.CalculateTransform(get.View().ActiveViewport, length, ref xform))
                    {
                        m_length = get.Length;
                        rc       = Rhino.Commands.Result.Success;
                        break;
                    }
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    if (null != output_toggle && create_solid != output_toggle.CurrentValue)
                    {
                        create_solid = output_toggle.CurrentValue;
                    }

                    if (null != group_toggle && group_faces != group_toggle.CurrentValue)
                    {
                        group_faces = group_toggle.CurrentValue;
                    }

                    continue;
                }
                else
                {
                    break;
                }
            }

            // If we got here, then we have the center point and edge length,
            // any any command options. Time to add the geomtry to the document.
            if (rc == Rhino.Commands.Result.Success && xform.IsValid)
            {
                m_create_solid = create_solid;
                m_group_faces  = group_faces;

                Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes();
                attribs.Name        = Platonic.Name;
                attribs.WireDensity = 0; // solid looks "nicer" with wires turned off...

                if (m_create_solid)
                {
                    Rhino.Geometry.Brep[] breps = Rhino.Geometry.Brep.JoinBreps(faces, 2.1 * doc.ModelAbsoluteTolerance);
                    foreach (Brep t in breps)
                    {
                        if (null == t)
                        {
                            continue;
                        }
                        t.Transform(xform);
                        doc.Objects.AddBrep(t, attribs, null, false, false);
                    }
                }
                else
                {
                    if (m_group_faces)
                    {
                        attribs.AddToGroup(doc.Groups.Add());
                    }

                    foreach (Brep t in faces)
                    {
                        if (null == t)
                        {
                            continue;
                        }
                        t.Transform(xform);
                        doc.Objects.AddBrep(t, attribs, null, false, false);
                    }
                }

                doc.Views.Redraw();
            }

            return(Rhino.Commands.Result.Success);
        }
Пример #30
0
 public void applyTrasform(Rhino.Geometry.Transform transM)
 {
     UtilOld.updateRhinoObjectSceneNode(ref mScene, ref planeObjRef, transM);
 }
Пример #31
0
        /// <summary>
        /// This function will be called (successively) from within the
        /// ComputeData method of this component
        /// </summary>
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess data)
        {
            Rhino.Geometry.Point3d center = Rhino.Geometry.Point3d.Origin;
            double length = 1.0;

            if (!data.GetData(m_center_index, ref center))
            {
                return;
            }
            if (!data.GetData(m_length_index, ref length))
            {
                return;
            }
            if (!center.IsValid || length <= 0.0)
            {
                return;
            }

            Rhino.Geometry.Vector3d  dir          = center - Rhino.Geometry.Point3d.Origin;
            Rhino.Geometry.Plane     plane        = Rhino.Geometry.Plane.WorldXY;
            Rhino.Geometry.Transform xf_translate = Rhino.Geometry.Transform.Translation(dir);
            Rhino.Geometry.Transform xf_scale     = Rhino.Geometry.Transform.Scale(plane, length, length, length);
            Rhino.Geometry.Transform xf           = xf_translate * xf_scale;
            if (!xf.IsValid)
            {
                return;
            }

            PlatonicsCommon.PlatonicBase geom = Geometry();
            if (null == geom)
            {
                return;
            }

            Rhino.Geometry.Brep[] faces = geom.Faces();
            if (null != faces && 0 < faces.Length)
            {
                foreach (Brep t in faces)
                {
                    t.Transform(xf);
                }
                data.SetDataList(m_faces_index, faces);
            }

            Rhino.Geometry.Curve[] edges = geom.Edges();
            if (null != edges && 0 < edges.Length)
            {
                foreach (Curve t in edges)
                {
                    t.Transform(xf);
                }
                data.SetDataList(m_edges_index, edges);
            }

            Rhino.Geometry.Point3d[] vertices = geom.Vertices();
            if (null != vertices && 0 < vertices.Length)
            {
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].Transform(xf);
                }
                data.SetDataList(m_vertices_index, vertices);
            }
        }