Example #1
0
        public static string ToSVG(this Rg.Ellipse input)
        {
            Rg.Vector3d axisX = input.Plane.XAxis;
            axisX.Unitize();
            axisX = axisX * input.Radius1;

            Rg.Vector3d axisY = input.Plane.YAxis;
            axisY.Unitize();
            axisY = axisY * input.Radius2;

            Rg.Point3d A = input.Plane.Origin + axisX;
            Rg.Point3d B = input.Plane.Origin + axisY;

            axisX.Reverse();
            axisY.Reverse();

            Rg.Point3d C = input.Plane.Origin + axisX;
            Rg.Point3d D = input.Plane.Origin + axisY;

            double radians = Rg.Vector3d.VectorAngle(input.Plane.YAxis, Rg.Vector3d.YAxis, Rg.Plane.WorldXY);
            double degrees = 180.0 - (radians / Math.PI) * 180.0;
            int    flip    = Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 1));

            return("M " + A.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + B.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + C.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + D.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + A.ToSVG());
        }
Example #2
0
        //addRhinoObject-pointOnObjRef (where curve on)
        //drawPoint,editPointSN in PointMarkers-addSceneNode
        public void resetVariables()
        {
            point_g      = new Geometry.PointMarker(new Vector3());
            currentState = State.READY;

            targetPRhObjID = Guid.Empty;
            //pointOnObjRef = null;
            drawPoint = null;
            projectP  = new Point3d();

            snapPointsList = new List <Point3d>();
            rayCastingObjs = new List <ObjRef>();

            pointsList   = new List <Point3d>();
            pointMarkers = new List <SceneNode>();
            contourCurve = null;
            curvePlane   = new Plane();

            toleranceMax = 100;
            snapDistance = 40;
            isSnap       = false;
            shouldSnap   = false;

            moveControlerOrigin = new Point3d();
            movePlaneRef        = null;
            planeNormal         = new Rhino.Geometry.Vector3d();

            lastTranslate = 0.0f;
        }
Example #3
0
        /***************************************************/
        /**** Public Methods - IRender                  ****/
        /***************************************************/

        public static Text3d ToRhino(this RenderText renderText)
        {
            if (renderText == null)
            {
                return(null);
            }

            RHG.Vector3d xdir      = (RHG.Vector3d)renderText.Cartesian.X.IToRhino();
            RHG.Vector3d ydir      = (RHG.Vector3d)renderText.Cartesian.Y.IToRhino();
            RHG.Point3d  pos       = (RHG.Point3d)renderText.Cartesian.Origin.IToRhino();
            RHG.Plane    textPlane = new RHG.Plane(pos, xdir, ydir);
            Text3d       text3D    = new Text3d(renderText.Text, textPlane, renderText.Height);

            if (renderText.FontName.Contains("Italic"))
            {
                text3D.Italic = true;
            }

            if (renderText.FontName.Contains("Bold"))
            {
                text3D.Bold = true;
            }

            text3D.FontFace = renderText.FontName.Replace("Italic", "").Replace("Bold", "").Trim();

            return(text3D);
        }
Example #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Point3d startPoint = new Rhino.Geometry.Point3d();
            DA.GetData(0, ref startPoint);

            Rhino.Geometry.Vector3d directionVector = new Rhino.Geometry.Vector3d();
            DA.GetData(1, ref directionVector);

            double lineDistance = 0;

            DA.GetData(2, ref lineDistance);

            double startingVectorLength = directionVector.Length;
            double scalingFactor        = lineDistance / startingVectorLength;

            Rhino.Geometry.Vector3d newDirectionVector = directionVector * scalingFactor;

            double deltaX = newDirectionVector.X;
            double deltaY = newDirectionVector.Y;

            double baseX = startPoint.X;
            double baseY = startPoint.Y;

            Rhino.Geometry.Point2d outputCurveEndPoint   = new Rhino.Geometry.Point2d(baseX + deltaX, baseY + deltaY);
            Rhino.Geometry.Point2d outputCurveStartPoint = new Rhino.Geometry.Point2d(baseX - deltaX, baseY - deltaY);

            Rhino.Geometry.Curve outputCurve = new Rhino.Geometry.LineCurve(outputCurveStartPoint, outputCurveEndPoint) as Rhino.Geometry.Curve;

            DA.SetData(0, outputCurve);
        }
Example #5
0
        //Dynamic Object Draw
        void RefObjDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
        {
            double factorTemp = (scaleCenter.DistanceTo(e.CurrentPoint)) / (scaleCenter.DistanceTo(scaleRefPoint));

            if (dimensionIndex == 0)
            {
                for (int i = 0; i < goList.Count; i++)
                {
                    Rhino.Geometry.Vector3d      vec   = (centers[i] - scaleCenter) * (factorTemp - 1);
                    Rhino.DocObjects.RhinoObject rhobj = goList[i] as Rhino.DocObjects.RhinoObject;
                    var xform = Rhino.Geometry.Transform.Translation(vec);
                    e.Display.DrawObject(rhobj, xform);
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < goList.Count; i++)
                {
                    Rhino.Geometry.Vector3d      vec   = (centers[i] - scaleCenter) * (factorTemp - 1);
                    Rhino.DocObjects.RhinoObject rhobj = goList[i] as Rhino.DocObjects.RhinoObject;
                    Vector3d planeNormal = plane2D.Normal;
                    if (planeNormal[0] != 0)
                    {
                        vec.X = 0;
                    }
                    else if (planeNormal[1] != 0)
                    {
                        vec.Y = 0;
                    }
                    else if (planeNormal[2] != 0)
                    {
                        vec.Z = 0;
                    }
                    var xform = Rhino.Geometry.Transform.Translation(vec);
                    e.Display.DrawObject(rhobj, xform);
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < goList.Count; i++)
                {
                    Vector3d vecEach       = (centers[i] - scaleCenter);
                    double   vecEachLength = vecEach.Length * (factorTemp - 1);
                    Vector3d vec           = (scaleRefPoint - scaleCenter);
                    double   angleVec      = Vector3d.VectorAngle(vecEach, vec);
                    int      pol           = 1;
                    if (angleVec > 1.57)
                    {
                        pol = -1;
                    }
                    vec.Unitize();
                    vec = vec * vecEachLength * pol;
                    var xform = Transform.Translation(vec);
                    Rhino.DocObjects.RhinoObject rhobj = goList[i] as Rhino.DocObjects.RhinoObject;
                    e.Display.DrawObject(rhobj, xform);
                }
            }
        }
Example #6
0
        /// <inheritdoc />
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh   = null;
            var  colors = new List <Color>();
            var  dir    = new Vec3d();

            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetDataList(1, colors))
            {
                return;
            }
            if (!DA.GetData(2, ref dir))
            {
                return;
            }

            var norms = mesh.Normals;

            if (norms.Count != mesh.Vertices.Count)
            {
                norms.ComputeNormals();
            }

            mesh.ColorVertices(i => colors.Lerp(dir * norms[i] * 0.5 + 0.5), true);
            DA.SetData(0, new GH_Mesh(mesh));
        }
Example #7
0
        /// <inheritdoc />
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve crv = null;
            var   dir = new Vec3d();

            if (!DA.GetData(0, ref crv))
            {
                return;
            }
            if (!DA.GetData(1, ref dir))
            {
                return;
            }

            Polyline poly;

            if (!crv.TryGetPolyline(out poly))
            {
                throw new ArgumentException();
            }

            var mesh = RhinoFactory.Mesh.CreateExtrusion(poly, dir);

            DA.SetData(0, new GH_Mesh(mesh));
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d basePt;
            Result  rc = RhinoGet.GetPoint("Start of line", false, out basePt);

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

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(basePt, true);
            gp.DrawLineFromPoint(basePt, true);
            gp.DynamicDraw += new EventHandler <GetPointDrawEventArgs>(gp_DynamicDraw);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d endPt = gp.Point();

            Rhino.Geometry.Vector3d vector = endPt - basePt;
            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                Line line = new Line(basePt, endPt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Example #9
0
            /// <summary>
            ///
            /// </summary>
            private static T CreateExtrusionClosed(Polyline polyline, Vec3d direction)
            {
                T   result = new T();
                var verts  = result.Vertices;
                var faces  = result.Faces;

                int n = polyline.Count - 1;

                // add verts
                for (int i = 0; i < n; i++)
                {
                    verts.Add(polyline[i]);
                }

                for (int i = 0; i < n; i++)
                {
                    verts.Add(polyline[i] + direction);
                }

                // add faces
                for (int i = 0; i < n; i++)
                {
                    int j = (i + 1) % n;
                    faces.AddFace(i, j, j + n, i + n);
                }

                return(result);
            }
Example #10
0
            /// <summary>
            ///
            /// </summary>
            private static T CreateExtrusionOpen(Polyline polyline, Vec3d direction)
            {
                T   result = new T();
                var verts  = result.Vertices;
                var faces  = result.Faces;

                int n = polyline.Count;

                // add vertices
                for (int i = 0; i < n; i++)
                {
                    verts.Add(polyline[i]);
                }

                for (int i = 0; i < n; i++)
                {
                    verts.Add(polyline[i] + direction);
                }

                // add faces
                for (int i = 0; i < n - 1; i++)
                {
                    faces.AddFace(i, i + 1, i + n + 1, i + n);
                }

                return(result);
            }
Example #11
0
        /// <summary>
        /// Returns the entries of the cotangent-weighted Laplacian matrix in row-major order.
        /// Based on symmetric derivation of the Laplace-Beltrami operator detailed in http://www.cs.jhu.edu/~misha/ReadingSeminar/Papers/Vallet08.pdf.
        /// Also returns the barycentric dual area of each vertex.
        /// Assumes triangle mesh.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="entriesOut"></param>
        /// <param name="areasOut"></param>
        public static void GetLaplacianMatrix(this Mesh mesh, double[] entriesOut, double[] areasOut)
        {
            var    verts = mesh.Vertices;
            int    n     = verts.Count;
            double t     = 1.0 / 6.0;

            Array.Clear(entriesOut, 0, n * n);
            Array.Clear(areasOut, 0, n);

            // iterate faces to collect weights and vertex areas (upper triangular only)
            foreach (MeshFace mf in mesh.Faces)
            {
                // circulate verts in face
                for (int i = 0; i < 3; i++)
                {
                    int i0 = mf[i];
                    int i1 = mf[(i + 1) % 3];
                    int i2 = mf[(i + 2) % 3];

                    Vec3d v0 = verts[i0] - verts[i2];
                    Vec3d v1 = verts[i1] - verts[i2];

                    // add to vertex area
                    double a = Vec3d.CrossProduct(v0, v1).Length;
                    areasOut[i0] += a * t;

                    // add to edge cotangent weights (assumes consistent face orientation)
                    if (i1 < i0)
                    {
                        entriesOut[i0 * n + i1] += 0.5 * v0 * v1 / a;
                    }
                    else
                    {
                        entriesOut[i1 * n + i0] += 0.5 * v0 * v1 / a;
                    }
                }
            }

            // normalize weights with areas and sum along diagonals
            for (int i = 0; i < n; i++)
            {
                int ii = i * n + i;

                for (int j = i + 1; j < n; j++)
                {
                    double w = entriesOut[i * n + j];
                    w /= Math.Sqrt(areasOut[i] * areasOut[j]);

                    // set symmetric entries
                    entriesOut[i * n + j] = entriesOut[j * n + i] = w;

                    // sum along diagonal entries
                    entriesOut[j * n + j] -= w;
                    entriesOut[ii]        -= w;
                }
            }
        }
Example #12
0
        public bool TriangleLineIntersect(Rhino.Geometry.Point3d[] Vx, Rhino.Geometry.Vector3d Normal, Rhino.Geometry.Line L)
        {
            if (Vx.Length != 3)
            {
                throw new Exception("Triangle is not valid!");
            }
            Point3d  O = Vx[0];
            Vector3d U = Vx[1] - O;
            Vector3d V = Vx[2] - O;
            Vector3d N = Normal;//Vector3d.CrossProduct(U, V);
            //plane normal

            Point3d PS = L.From; //start point of the line
            Point3d PE = L.To;   //end point of the line

            double Nomin = ((O - PS) * N);
            //operator * for dot product
            double Denom = N * (PE - PS);

            // only if the line is not paralell to the plane containing triangle T
            if (Denom != 0)
            {
                double alpha = Nomin / Denom;
                // parameter along the line where it intersects the plane in question, only if not paralell to the plane
                Point3d P = PS + alpha * (PE - PS);
                //L.PointAt(alpha) '

                Vector3d W = P - O;

                double UU = U * U;
                double VV = V * V;
                double UV = U * V;
                double WU = W * U;
                double WV = W * V;

                double STDenom = Math.Pow(UV, 2) - UU * VV;

                double s = (UV * WV - VV * WU) / STDenom;
                double t = (UV * WU - UU * WV) / STDenom;

                Point3d Point = O + s * U + t * V;

                if (s >= 0 & t >= 0 & s + t <= 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #13
0
        /***************************************************/

        public static bool IsEqual(this BHG.Vector bhVector, RHG.Vector3d rhVector, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhVector == null & rhVector == default(RHG.Vector3d))
            {
                return(true);
            }

            return(Math.Abs(bhVector.X - rhVector.X) < tolerance &&
                   Math.Abs(bhVector.Y - rhVector.Y) < tolerance &&
                   Math.Abs(bhVector.Z - rhVector.Z) < tolerance);
        }
Example #14
0
 /// <summary>
 ///
 /// </summary>
 public static T CreateExtrusion(Polyline polyline, Vec3d direction)
 {
     if (polyline.IsClosed)
     {
         return(CreateExtrusionClosed(polyline, direction));
     }
     else
     {
         return(CreateExtrusionOpen(polyline, direction));
     }
 }
        private static rg.Brep ExtrudeBrep(rg.Brep brep, rg.Vector3d dir)
        {
            if (dir.IsZero)
            {
                return(brep);
            }
            List <rg.Curve> edgeCurves = new List <rg.Curve>();
            List <rg.Brep>  breps;

            checked
            {
                int num = brep.Edges.Count - 1;
                for (int i = 0; i <= num; i++)
                {
                    if (brep.Edges[i].TrimCount == 1)
                    {
                        rg.Curve item = brep.Edges[i].DuplicateCurve();
                        edgeCurves.Add(item);
                    }
                }
                if (edgeCurves.Count == 0)
                {
                    return(brep);
                }
                breps = new List <rg.Brep>()
                {
                    brep
                };
                int num2 = edgeCurves.Count - 1;
                for (int j = 0; j <= num2; j++)
                {
                    rg.Surface extrusion = Rhino.Compute.SurfaceCompute.CreateExtrusion(edgeCurves[j], dir);
                    if (extrusion != null)
                    {
                        rg.Brep val2 = extrusion.ToBrep();
                        // val2.Faces.SplitKinkyFaces();
                        breps.Add(val2);
                    }
                }
                rg.Brep topFace = brep.DuplicateBrep();
                topFace.Translate(dir);
                breps.Add(topFace);
            }
            rg.Brep[] array = Rhino.Compute.BrepCompute.JoinBreps(breps, 0.0001);
            if (array == null)
            {
                return(brep);
            }
            return(array[0]);
        }
Example #16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;

            Rhino.Geometry.Vector3d vec = new Rhino.Geometry.Vector3d(0, 0, 0);

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref vec);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            MeshTransforms.Translate(dMsh_copy, vec.ToVec3d());

            DA.SetData(0, dMsh_copy);
        }
Example #17
0
        //TODO- check if the x,y axis of the plane will change whenever we call tryGetPlane
        //railPlaneSN-addRhinoObjSceneNode(draw on referece), curveOnObjRef-addRhinoObj(!=In3D)
        //drawPoint, strokeSN-addSceneNode, renderObjSN-updateSceneNode(Revolve or Curve2)
        public void resetVariables()
        {
            stroke_g     = new Geometry.GeometryStroke(ref mScene);
            currentState = State.READY;

            reducePoints = new List <Vector3>();

            targetPRhObjID = Guid.Empty;
            drawPoint      = null;
            snapPointSN    = null;
            projectP       = new Point3d();

            rhinoCurvePoints      = new List <Point3d>();
            rhinoCurve            = null;
            proj_plane            = new Plane();
            simplifiedCurvePoints = new List <Point3d>();
            simplifiedCurve       = null;
            editCurve             = null; //for extrude
            //curveOnObjRef = null;


            backgroundStart = false;
            displacement    = 0;
            dynamicBrep     = null;
            modelName       = "tprint";
            //dynamicRender = "none"; // need to save same as drawType and shapeType
            snapPointsList = new List <Point3d>();
            rayCastingObjs = new List <ObjRef>();


            toleranceMax = 100000;
            snapDistance = 40;
            isSnap       = false;
            shouldSnap   = false;

            moveControlerOrigin = new Point3d();
            movePlaneRef        = null;
            planeNormal         = new Rhino.Geometry.Vector3d();

            curvePlane    = new Plane();
            lastTranslate = 0.0f;
            d             = null;

            localListCurve  = mScene.iCurveList;
            oldCurveOnObjID = "";
            oldPlaneOrigin  = "";
            oldPlaneNormal  = "";
        }
Example #18
0
        public void SpreadObjects(double step, Boolean refresh)
        {
            if (myDisplayBool == null)
            {
            }
            else
            {
                Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

                Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport;

                //viewport.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe");
                Rhino.Geometry.BoundingBox myGlobalBbox = new Rhino.Geometry.BoundingBox();
                myGlobalBbox = Rhino.Geometry.BoundingBox.Empty;
                List <Rhino.Geometry.Point3d> myCentroids = new List <Rhino.Geometry.Point3d>();
                //myCentroids.Clear();
                //Rhino.Geometry.Point3d explosionCenter;

                // First iteration: find initial object and initial bounding box center
                if (originalCentroids.Count == 0 || refresh == true)
                {
                    myCentroids.Clear();
                    foreach (Guid guid in allGuids)
                    {
                        RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
                        Rhino.Geometry.BoundingBox foundBbox = foundObject.Geometry.GetBoundingBox(true);
                        myGlobalBbox.Union(foundBbox);
                        myCentroids.Add(foundBbox.Center);
                        explosionCenter = myGlobalBbox.Center;
                    }
                    originalCentroids = myCentroids;
                }
                else
                {
                    for (int i = 0; i < allGuids.Count; i++)
                    {
                        RhinoObject             foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(allGuids[i]);
                        Rhino.Geometry.Vector3d trans       = explosionCenter - originalCentroids[i];

                        // Brings back to original position.
                        Rhino.Geometry.Vector3d backTrans = originalCentroids[i] - foundObject.Geometry.GetBoundingBox(true).Center;
                        trans.Unitize();
                        Rhino.RhinoDoc.ActiveDoc.Objects.Transform(foundObject, Rhino.Geometry.Transform.Translation(backTrans - Rhino.Geometry.Vector3d.Multiply(step, trans)), true);
                        Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                    }
                }
            }
        }
Example #19
0
        public virtual Rhino.Display.Color4f GetColor(Rhino.Geometry.Point3d uvw, Rhino.Geometry.Vector3d duvwdx, Rhino.Geometry.Vector3d duvwdy)
        {
            if (m_runtime_serial_number > 0)
            {
                return(Rhino.Display.Color4f.Empty);
            }
            IntPtr pConstThis = ConstPointer();

            Rhino.Display.Color4f rc = new Rhino.Display.Color4f();

            if (!UnsafeNativeMethods.Rdk_TextureEvaluator_GetColor(pConstThis, uvw, duvwdx, duvwdy, ref rc))
            {
                return(Rhino.Display.Color4f.Empty);
            }
            return(rc);
        }
        /// <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);
        }
Example #21
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Brep    surface = null;
            Motions motions = null;
            MotionsPlasticLimits motionsPlasticLimit = null;

            Rhino.Geometry.Vector3d x = Vector3d.Zero;
            Rhino.Geometry.Vector3d z = Vector3d.Zero;
            string identifier         = "S";

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref motions))
            {
                return;
            }
            DA.GetData(2, ref motionsPlasticLimit);
            DA.GetData(3, ref x);
            DA.GetData(4, ref z);
            DA.GetData(5, ref identifier);

            if (surface == null || motions == null || identifier == null)
            {
                return;
            }

            Geometry.Region         region = surface.FromRhino();
            Supports.SurfaceSupport obj    = new Supports.SurfaceSupport(region, motions, motionsPlasticLimit, identifier);

            // Set local x-axis
            if (!x.Equals(Vector3d.Zero))
            {
                obj.CoordinateSystem.SetXAroundZ(x.FromRhino());
            }

            // Set local z-axis
            if (!z.Equals(Vector3d.Zero))
            {
                obj.CoordinateSystem.SetZAroundX(z.FromRhino());
            }

            DA.SetData(0, obj);
        }
Example #22
0
 public PlaneConverter(Vector3DConverter vecConv, Point3dConverter ptConv) :
     base(
         (rhp) =>
 {
     pp.Vec origin = ptConv.ToPipe <rh.Point3d, pp.Vec>(rhp.Origin);
     pp.Vec x      = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rhp.XAxis);
     pp.Vec y      = vecConv.ToPipe <rh.Vector3d, pp.Vec>(rhp.YAxis);
     //we won't convert the z-axis because we can simply cross the x and y
     return(new pp.Plane(origin, x, y));
 },
         (ppp) =>
 {
     rh.Point3d origin = ptConv.FromPipe <rh.Point3d, pp.Vec>(ppp.Origin);
     rh.Vector3d x     = vecConv.FromPipe <rh.Vector3d, pp.Vec>(ppp.X);
     rh.Vector3d y     = vecConv.FromPipe <rh.Vector3d, pp.Vec>(ppp.Y);
     return(new rh.Plane(origin, x, y));
 }
         ) { }
Example #23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DMesh3_goo dMsh_goo = null;

            Rhino.Geometry.Vector3d sFact = new Rhino.Geometry.Vector3d(1, 1, 1);
            Point3d origin = new Point3d(0, 0, 0);

            DA.GetData(0, ref dMsh_goo);
            DA.GetData(1, ref sFact);
            DA.GetData(2, ref origin);

            DMesh3 dMsh_copy = new DMesh3(dMsh_goo.Value);

            MeshTransforms.Scale(dMsh_copy, sFact.ToVec3d(), origin.ToVec3d());



            DA.SetData(0, dMsh_copy);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="re">The result element containing the data</param>
        /// <param name="values">The values to be plotted</param>
        /// <param name="dir">The direction in which the plot should go</param>
        /// <param name="sFac">Scaling factor for the graph</param>
        private List <Curve> CreateCurvesFromResults(ResultElement re, List <double> values, Vector3d dir, double sFac)
        {
            List <Curve> crvs = new List <Curve>();

            // Get points on original element
            List <Point3d> basePts = new List <Point3d>();
            List <Point3d> pts     = new List <Point3d>();

            Rhino.Geometry.Vector3d elX     = re.LocalX;
            List <double>           lengths = re.pos;

            foreach (double l in lengths)
            {
                Vector3d vec = l * elX;
                Point3d  pt  = new Point3d(re.sPos.X + vec.X, re.sPos.Y + vec.Y, re.sPos.Z + vec.Z);
                pts.Add(pt);
                basePts.Add(pt);
            }

            // Move points to get curve points
            for (int i = 0; i < values.Count; i++)
            {
                pts[i] = pts[i] + dir * sFac * values[i];
            }

            // Create curve and add it to _dispCrvs
            crvs.Add(Rhino.Geometry.Curve.CreateInterpolatedCurve(pts, 3));
            crvs.Add(Rhino.Geometry.Curve.CreateInterpolatedCurve(basePts, 1));
            for (int i = 0; i < pts.Count; i++)
            {
                crvs.Add(new Rhino.Geometry.Line(basePts[i], pts[i]).ToNurbsCurve());
            }

            // Add points to bounding box
            _bbPts.AddRange(pts);

            return(crvs);
        }
Example #25
0
        protected override void onClickOculusGrip(ref VREvent_t vrEvent)
        {
            if (targetPRhObjID == Guid.Empty || currentState != State.READY)
            {
                return;
            }

            currentState  = State.MOVEPLANE;
            movePlaneRef  = new ObjRef(targetPRhObjID);
            lastTranslate = 0.0f;

            //get the plane info
            RhinoObject movePlaneObj = movePlaneRef.Object();

            planeNormal = new Rhino.Geometry.Vector3d();
            //PointOnObject still null at this point
            if (movePlaneObj.Attributes.Name.Contains("planeXY"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(0, 0, 1);
            }
            else if (movePlaneObj.Attributes.Name.Contains("planeYZ"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(1, 0, 0);
            }
            else if (movePlaneObj.Attributes.Name.Contains("planeXZ"))
            {
                planeNormal = new Rhino.Geometry.Vector3d(0, 1, 0);
            }

            OpenTK.Vector4 controller_p     = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z));

            float translate = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;

            //move from the porjection point not origin
            moveControlerOrigin = new Point3d(0 + translate * planeNormal.X, 0 + translate * planeNormal.Y, 0 + translate * planeNormal.Z);
        }
 /// <summary>
 /// Gets location and vectors of this camera.
 /// </summary>
 /// <param name="location">An out parameter that will be filled with a point during the call.</param>
 /// <param name="cameraX">An out parameter that will be filled with the X vector during the call.</param>
 /// <param name="cameraY">An out parameter that will be filled with the Y vector during the call.</param>
 /// <param name="cameraZ">An out parameter that will be filled with the Z vector during the call.</param>
 /// <returns>true if current camera orientation is valid; otherwise false.</returns>
 public bool GetCameraFrame(out Rhino.Geometry.Point3d location,  out Rhino.Geometry.Vector3d cameraX, out Rhino.Geometry.Vector3d cameraY, out Rhino.Geometry.Vector3d cameraZ)
 {
   location = new Rhino.Geometry.Point3d(0, 0, 0);
   cameraX = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraY = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraZ = new Rhino.Geometry.Vector3d(0, 0, 0);
   IntPtr pConstThis = ConstPointer();
   return UnsafeNativeMethods.ON_Viewport_GetCameraFrame(pConstThis, ref location, ref cameraX, ref cameraY, ref cameraZ);
 }
 /// <summary>
 /// Gets a world coordinate dolly vector that can be passed to DollyCamera().
 /// </summary>
 /// <param name="screenX0">Screen coords of start point.</param>
 /// <param name="screenY0">Screen coords of start point.</param>
 /// <param name="screenX1">Screen coords of end point.</param>
 /// <param name="screenY1">Screen coords of end point.</param>
 /// <param name="projectionPlaneDistance">Distance of projection plane from camera. When in doubt, use 0.5*(frus_near+frus_far).</param>
 /// <returns>The world coordinate dolly vector.</returns>
 public Rhino.Geometry.Vector3d GetDollyCameraVector(int screenX0, int screenY0, int screenX1, int screenY1, double projectionPlaneDistance)
 {
   Rhino.Geometry.Vector3d v = new Rhino.Geometry.Vector3d();
   IntPtr pConstThis = ConstPointer();
   if (UnsafeNativeMethods.ON_Viewport_GetDollyCameraVector(pConstThis, screenX0, screenY0, screenX1, screenY1, projectionPlaneDistance, ref v))
     v = Rhino.Geometry.Vector3d.Unset;
   return v;
 }
        public void SetInputs(List <DataTree <ResthopperObject> > values)
        {
            foreach (var tree in values)
            {
                if (!_input.TryGetValue(tree.ParamName, out var inputGroup))
                {
                    continue;
                }

                if (inputGroup.AlreadySet(tree))
                {
                    Console.WriteLine("Skipping input tree... same input");
                    continue;
                }

                inputGroup.CacheTree(tree);
                inputGroup.Param.VolatileData.Clear();
                inputGroup.Param.ExpireSolution(true);

                if (inputGroup.Param is Param_Point)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj = entree.Value[i];
                            Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            GH_Point data = new GH_Point(rPt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Vector)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject        restobj  = entree.Value[i];
                            Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                            GH_Vector data = new GH_Vector(rhVector);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Integer)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                            GH_Integer data          = new GH_Integer(rhinoInt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Number)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_String)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = restobj.Data;
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Line)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            GH_Line             data    = new GH_Line(rhLine);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Curve)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            GH_Curve         ghCurve;
                            try
                            {
                                Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                ghCurve = new GH_Curve(c);
                            }
                            catch
                            {
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                var c    = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict);
                                ghCurve = new GH_Curve(c);
                            }
                            inputGroup.Param.AddVolatileData(path, i, ghCurve);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Circle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject      restobj  = entree.Value[i];
                            Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                            GH_Circle             data     = new GH_Circle(rhCircle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Plane)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject     restobj = entree.Value[i];
                            Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                            GH_Plane             data    = new GH_Plane(rhPlane);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Rectangle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject           restobj     = entree.Value[i];
                            Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                            GH_Rectangle data = new GH_Rectangle(rhRectangle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Box)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject   restobj = entree.Value[i];
                            Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                            GH_Box             data    = new GH_Box(rhBox);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Surface)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj   = entree.Value[i];
                            Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                            GH_Surface             data      = new GH_Surface(rhSurface);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Brep)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                            GH_Brep             data    = new GH_Brep(rhBrep);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Mesh)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                            GH_Mesh             data    = new GH_Mesh(rhMesh);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_NumberSlider)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                            GH_Boolean       data    = new GH_Boolean(boolean);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_Panel)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }
            }
        }
Example #29
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments, 
    /// Output parameters as ref arguments. You don't have to assign output parameters, 
    /// they will have a default value.
    /// </summary>
    private void RunScript(Mesh Profile, Mesh x, bool y, ref object A)
    {
        if(y){
          try{
        using (var game = new GameWindow(Width, Height, GraphicsMode.Default))
        {
          game.Load += (sender, e) =>
            {
            OpenTK.Graphics.OpenGL.GL.ClearColor(Color.Gray);// 背景
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);
            // OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.CullFace);//反面不可见
            OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
              OpenTK.Graphics.OpenGL.LightParameter.Ambient, LightAmbient);//设置系统灯光
            OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
              OpenTK.Graphics.OpenGL.LightParameter.Diffuse, LightDiffuse);		// 设置漫射光
            OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
              OpenTK.Graphics.OpenGL.LightParameter.Position, LightPosition);	// 设置光源位置
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Light0);//启用灯光

            // OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);							// 启用纹理映射
            // OpenTK.Graphics.OpenGL.GL.ShadeModel(OpenTK.Graphics.OpenGL.ShadingModel.Smooth);							// 启用阴影平滑

            // OpenTK.Graphics.OpenGL.GL.ClearDepth(1.0f);									// 设置深度缓存
            //OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);								// 启用深度测试
            // OpenTK.Graphics.OpenGL.GL.DepthFunc(OpenTK.Graphics.OpenGL.DepthFunction.Lequal);							// 所作深度测试的类型
            // OpenTK.Graphics.OpenGL.GL.Hint(OpenTK.Graphics.OpenGL.HintTarget.PerspectiveCorrectionHint,
            //   OpenTK.Graphics.OpenGL.HintMode.Nicest);// 告诉系统对透视进行修正
            //  OpenTK.Graphics.OpenGL.GL.Color4(1.0f, 1.0f, 1.0f, 0.5f);						// 全亮度, 50% Alpha 混合
            //  OpenTK.Graphics.OpenGL.GL.BlendFunc(OpenTK.Graphics.OpenGL.BlendingFactorSrc.SrcAlpha, OpenTK.Graphics.OpenGL.BlendingFactorDest.One);

            v1 = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.CameraLocation;
            v2 = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.CameraUp;
            v3 = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.CameraTarget;
            };

          game.Resize += (sender, e) =>
            {
            OpenTK.Graphics.OpenGL.GL.Viewport(0, 0, Width, Height);
            double aspect_ratio = Width / (double) Height;
            OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float) aspect_ratio, 1, 12000);//设置视野最大最小距离
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Projection);
            OpenTK.Graphics.OpenGL.GL.LoadMatrix(ref perspective);

            };

          game.UpdateFrame += (sender, e) =>
            {
            if (game.Keyboard[Key.Escape]){ game.Exit();}
            };

          game.RenderFrame += (sender, e) =>
            {
            OpenTK.Graphics.OpenGL.GL.Clear
              (OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit | OpenTK.Graphics.OpenGL.ClearBufferMask.DepthBufferBit);

            OpenTK.Matrix4 LookAt = OpenTK.Matrix4.LookAt(
              (float) v1.X, (float) v1.Z, -(float) v1.Y,
              (float) v3.X, (float) v3.Z, -(float) v3.Y,
              0, 1, 0
              );

            // Matrix4 modelview = Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview0Ext);
            OpenTK.Graphics.OpenGL.GL.LoadMatrix(ref LookAt);

            angle = (float) ( (Width / 2 - game.Mouse.X) / (float) Width * 360f);

            OpenTK.Graphics.OpenGL.GL.Rotate(angle, OpenTK.Vector3d.UnitY);
            DrawMatrix();

            //OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Lighting);
            Drawface(x);
            //OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.Lighting);
           // OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.LineSmooth);
            // Drawface(Profile);
            Drawline(x);
            game.SwapBuffers();
            };
          // Run the game at 60 updates per second
          game.Run(60);
        }

          }catch(Exception ex){Print(ex.ToString());}
        }
    }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Vector3d V)
 {
     this.Enabled = true;
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + V);
 }
Example #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);
            }
        }
Example #32
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // get input
            Brep surface = null;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }

            double thickness = 0;

            if (!DA.GetData(1, ref thickness))
            {
                return;
            }

            FemDesign.Materials.Material material = null;
            if (!DA.GetData(2, ref material))
            {
                return;
            }

            FemDesign.Shells.ShellEccentricity eccentricity = FemDesign.Shells.ShellEccentricity.GetDefault();
            if (!DA.GetData(3, ref eccentricity))
            {
                // pass
            }

            FemDesign.Shells.ShellOrthotropy orthotropy = FemDesign.Shells.ShellOrthotropy.GetDefault();
            if (!DA.GetData(4, ref orthotropy))
            {
                // pass
            }

            FemDesign.Shells.EdgeConnection edgeConnection = FemDesign.Shells.EdgeConnection.GetRigid();
            if (!DA.GetData(5, ref edgeConnection))
            {
                // pass
            }

            Rhino.Geometry.Vector3d x = Vector3d.Zero;
            if (!DA.GetData(6, ref x))
            {
                // pass
            }

            Rhino.Geometry.Vector3d z = Vector3d.Zero;
            if (!DA.GetData(7, ref z))
            {
                // pass
            }

            string identifier = "P";

            if (!DA.GetData(8, ref identifier))
            {
                // pass
            }

            if (surface == null || material == null || eccentricity == null || orthotropy == null || edgeConnection == null || identifier == null)
            {
                return;
            }

            //
            FemDesign.Geometry.Region region = surface.FromRhino();

            //
            List <FemDesign.Shells.Thickness> thicknessObj = new List <FemDesign.Shells.Thickness>();

            thicknessObj.Add(new FemDesign.Shells.Thickness(region.CoordinateSystem.Origin, thickness));

            //
            FemDesign.Shells.Slab obj = FemDesign.Shells.Slab.Plate(identifier, material, region, edgeConnection, eccentricity, orthotropy, thicknessObj);

            // set local x-axis
            if (!x.Equals(Vector3d.Zero))
            {
                obj.SlabPart.LocalX = x.FromRhino();
            }

            // set local z-axis
            if (!z.Equals(Vector3d.Zero))
            {
                obj.SlabPart.LocalZ = z.FromRhino();
            }

            // return
            DA.SetData(0, obj);
        }
Example #33
0
 public XYZ RhinoToRevitPoint(rg.Vector3d pt)
 {
     return(new XYZ(pt.X, pt.Y, pt.Z));
 }