コード例 #1
0
        public void AddInstance(Rhino.Geometry.Transform transform)
        {
            foreach (GltfMeshMaterialPair pair in  meshMaterialPairs)
            {
                Rhino.Geometry.Mesh rhinoMesh = pair.RhinoMesh.DuplicateMesh();

                rhinoMesh.Transform(GltfUtils.YupToZup * transform);

                rhinoMesh.TextureCoordinates.ReverseTextureCoordinates(1);

                Guid objectId = doc.Objects.AddMesh(rhinoMesh);

                Rhino.DocObjects.RhinoObject rhinoObject = doc.Objects.Find(objectId);

                Rhino.Render.RenderMaterial material = converter.GetMaterial(pair.MaterialIndex);

                if (rhinoObject != null && material != null)
                {
                    rhinoObject.RenderMaterial            = material;
                    rhinoObject.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                    rhinoObject.Attributes.Name           = pair.Name;

                    rhinoObject.CommitChanges();
                }
            }
        }
コード例 #2
0
            protected override void DrawForeground(DrawEventArgs e)
            {
                int index = 0;

                if (Dir != null)
                {
                    e.Display.DrawLineArrow(Dir, System.Drawing.Color.Red, 3, .1);
                }

                foreach (Guid G in m_id_list)
                {
                    //Rhino.DocObjects.RhinoObject rhobj = m_pChannelAttrs.m_pObject;
                    Rhino.DocObjects.RhinoObject rhobj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(G);
                    if (rhobj == null)
                    {
                        m_id_list.Remove(G);
                        continue;
                    }
                    // Draw our own representation of the object
                    Rhino.Geometry.Point2d screen_pt = e.Display.Viewport.WorldToClient(rhobj.Geometry.GetBoundingBox(true).Min);
                    if ((rhobj.IsSelected(false) != 0))
                    {
                        e.Display.DrawSprite(RS, rhobj.Geometry.GetBoundingBox(true).Min, 0.5f, true);// screen_pt, 32.0f);
                        e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                    }
                    else
                    {
                        e.Display.DrawSprite(RU, rhobj.Geometry.GetBoundingBox(true).Min, 0.5f, true);// screen_pt, 32.0f);
                        e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                    }
                    index++;
                }
            }
コード例 #3
0
    protected override void UpdateVertexColors(Rhino.DocObjects.RhinoObject obj, Mesh[] meshes)
    {
        // A "mapping tag" is used to determine if the colors need to be set
        Rhino.Render.MappingTag mt = GetMappingTag(obj.RuntimeSerialNumber);

        for (int mi = 0; mi < meshes.Length; mi++)
        {
            var mesh = meshes[mi];
            if (mesh.VertexColors.Tag.Id != this.Id)
            {
                // The mesh's mapping tag is different from ours. Either the mesh has
                // no false colors, has false colors set by another analysis mode, has
                // false colors set using different m_z_range[]/m_hue_range[] values, or
                // the mesh has been moved.  In any case, we need to set the false
                // colors to the ones we want.
                System.Drawing.Color[] colors = new System.Drawing.Color[mesh.Vertices.Count];
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    double z = mesh.Vertices[i].Z;
                    colors[i] = FalseColor(z);
                }
                mesh.VertexColors.SetColors(colors);
                // set the mesh's color tag
                mesh.VertexColors.Tag = mt;
            }
        }
    }
コード例 #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.

            GetObject gpath = new GetObject();

            gpath.SetCommandPrompt("get the pathp");
            gpath.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            gpath.SubObjectSelect = false;
            gpath.Get();
            if (gpath.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gpath.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gpath.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            int path_number = my_obj.Geometry.UserDictionary.Getint("path_number", -1);

            RhinoApp.WriteLine("the number of the object is {0}", path_number);
            return(Result.Success);
        }
コード例 #5
0
        /// <summary>
        /// Gets a value indicating if this visual analysis mode can be used on a given Rhino object.
        /// </summary>
        /// <param name="obj">The object to be tested.</param>
        /// <returns>true if this mode can indeed be used on the object; otherwise false.</returns>
        public virtual bool ObjectSupportsAnalysisMode(Rhino.DocObjects.RhinoObject obj)
        {
            IntPtr pConstPointer     = ConstPointer();
            IntPtr pConstRhinoObject = obj.ConstPointer();

            return(UnsafeNativeMethods.CRhinoVisualAnalysisMode_ObjectSupportsAnalysisMode(pConstPointer, pConstRhinoObject));
        }
コード例 #6
0
        /// <summary>
        /// For derived classes implementers.
        /// <para>Defines the necessary implementation to free the instance from being const.</para>
        /// </summary>
        protected virtual void NonConstOperation()
        {
            if (IntPtr.Zero == m_ptr)
            {
                bool   applymempressure;
                IntPtr pNewPointer = _InternalDuplicate(out applymempressure);
                m_ptr = pNewPointer;
                if (applymempressure)
                {
                    ApplyMemoryPressure();
                }

#if RHINO_SDK
                Rhino.DocObjects.RhinoObject parent_object = m__parent as Rhino.DocObjects.RhinoObject;
                if (null != parent_object)
                {
                    if (parent_object.m_original_geometry == this)
                    {
                        parent_object.m_original_geometry = null;
                        parent_object.m_edited_geometry   = this as Geometry.GeometryBase;
                    }
                    if (parent_object.m_original_attributes == this)
                    {
                        parent_object.m_original_attributes = null;
                        parent_object.m_edited_attributes   = this as DocObjects.ObjectAttributes;
                    }
                }
#endif
                OnSwitchToNonConst();
            }
        }
コード例 #7
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);
                }
            }
        }
コード例 #8
0
    public static Rhino.Commands.Result DupBorder(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
        Rhino.Geometry.Brep          brep  = objref.Brep();
        if (rhobj == null || brep == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        rhobj.Select(false);
        Rhino.Geometry.Curve[] curves = brep.DuplicateEdgeCurves(true);
        double tol = doc.ModelAbsoluteTolerance * 2.1;

        curves = Rhino.Geometry.Curve.JoinCurves(curves, tol);
        for (int i = 0; i < curves.Length; i++)
        {
            Guid id = doc.Objects.AddCurve(curves[i]);
            doc.Objects.Select(id);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
コード例 #9
0
        internal override IntPtr _InternalGetConstPointer()
        {
#if RHINO_SDK
            Rhino.DocObjects.RhinoObject parent_object = m__parent as Rhino.DocObjects.RhinoObject;
            if (null == parent_object)
            {
                Rhino.FileIO.File3dmObject parent_model_object = m__parent as Rhino.FileIO.File3dmObject;
                if (parent_model_object != null)
                {
                    return(parent_model_object.GetAttributesConstPointer());
                }
            }
            IntPtr pConstParent = IntPtr.Zero;
            if (null != parent_object)
            {
                pConstParent = parent_object.ConstPointer();
            }
            return(UnsafeNativeMethods.CRhinoObject_Attributes(pConstParent));
#else
            Rhino.FileIO.File3dmObject parent_model_object = m__parent as Rhino.FileIO.File3dmObject;
            if (parent_model_object != null)
            {
                return(parent_model_object.GetAttributesConstPointer());
            }
            return(IntPtr.Zero);
#endif
        }
コード例 #10
0
        // Dynamic Draw
        void RefObjDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
        {
            Rhino.DocObjects.RhinoObject rhobj = e.Source.Tag as Rhino.DocObjects.RhinoObject;
            if (rhobj == null)
            {
                return;
            }

            double   u, v;
            var      currentPoint = e.CurrentPoint;
            Vector3d direction    = new Vector3d();
            Plane    currentPlane = new Plane();

            if (surface != null)
            {
                surface.ClosestPoint(currentPoint, out u, out v);
                direction    = surface.NormalAt(u, v);
                currentPlane = new Plane(currentPoint, direction);
                Transform xform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, currentPlane);
                e.Display.DrawObject(rhobj, xform);
            }
            else if (surface == null)
            {
                surface2.ClosestPoint(currentPoint, out u, out v);
                direction    = surface2.NormalAt(u, v);
                currentPlane = new Plane(currentPoint, direction);
                Transform xform = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, currentPlane);
                e.Display.DrawObject(rhobj, xform);
            }
        }
コード例 #11
0
ファイル: VrGame.cs プロジェクト: lanicon/SparrowHawk
        protected void notifyRobotIfSafe()
        {
            //Vector3 tableOrigin = Util.transformPoint(mScene.vrToRobot.Inverted(), new Vector3(0, 0, 0));

            Vector3 tableOrigin = UtilOld.platformToVRPoint(ref mScene, new Vector3(0, 0, 0));

            Vector3 headOrigin = UtilOld.transformPoint(mScene.mHMDPose.Inverted(), new Vector3(0, 0, 0));

            Vector3 displacement = tableOrigin - headOrigin;

            displacement.Y = 0;

            if (displacement.Length > 1.0f && isUserIn == true)
            {
                Rhino.DocObjects.RhinoObject rhobj = mScene.rhinoDoc.Objects.Find(uGuid);
                rhobj.Attributes.Name = "user:out";
                rhobj.CommitChanges();

                isUserIn = false;
                Rhino.RhinoApp.WriteLine("User out. " + displacement.Length);
            }
            else if (displacement.Length < 1.0f && isUserIn == false)
            {
                Rhino.DocObjects.RhinoObject rhobj = mScene.rhinoDoc.Objects.Find(uGuid);
                rhobj.Attributes.Name = "user:in";
                rhobj.CommitChanges();

                isUserIn = true;
                Rhino.RhinoApp.WriteLine("User in. " + displacement.Length);
            }
        }
コード例 #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);
            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);
            RhinoApp.WriteLine("the name of the object is {0}", brep.UserDictionary.GetString("name"));
            return(Result.Success);
        }
コード例 #13
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)
        {
            bool b = false;

            Rhino.DocObjects.RhinoObject myGeo = null;

            ///Rhino.DocObjects.RhinoObject obj = x as Rhino.DocObjects.RhinoObject;
            ///A = x;


            if (!DA.GetData(0, ref b))
            {
                return;
            }
            if (!DA.GetData(1, ref myGeo))
            {
                return;
            }


            string   texName = TextureName(b, myGeo);
            Vector3d OffU    = CreateUOffset(b, myGeo);

            DA.SetData(0, texName);
            DA.SetData(1, OffU);
        }
コード例 #14
0
            /// <summary>
            /// Sets materials for an object by layer.
            /// </summary>
            /// <param name="ID">object GUID (UUID)</param>
            /// <returns></returns>
            public static bool Material_SetObjectToLayer(Guid ID)
            {
                Rhino.DocObjects.RhinoObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(ID);
                bool result = obj.Geometry.SetUserString("Acoustics_User", "no");

                Rhino.RhinoDoc.ActiveDoc.Objects.ModifyAttributes(obj, obj.Attributes, true);
                return(result);
            }
コード例 #15
0
 public override bool ObjectSupportsAnalysisMode(Rhino.DocObjects.RhinoObject obj)
 {
     if (obj is Rhino.DocObjects.MeshObject || obj is Rhino.DocObjects.BrepObject)
     {
         return(true);
     }
     return(false);
 }
コード例 #16
0
    public static Rhino.Commands.Result MoveGripObjects(Rhino.RhinoDoc doc)
    {
        // The following example demonstrates how to move a surface's grip objects.
        // In this sample, all grips will be moved a fixed distance of 0.5 units
        // in the normal direction of the surface at that grip location.

        Rhino.DocObjects.ObjRef objRef;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select surface for control point editing", false, Rhino.DocObjects.ObjectType.Surface, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

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

        Rhino.Geometry.Surface srf = objRef.Surface();
        if (null == srf)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Make sure the object's grips are enabled
        obj.GripsOn = true;
        doc.Views.Redraw();

        Rhino.DocObjects.GripObject[] grips = obj.GetGrips();
        for (int i = 0; i < grips.Length; i++)
        {
            Rhino.DocObjects.GripObject grip = grips[i];

            // Calculate the point on the surface closest to our test point,
            // which is the grip's 3-D location (for this example).
            double u, v;
            if (srf.ClosestPoint(grip.CurrentLocation, out u, out v))
            {
                // Compute the surface normal at a point
                Rhino.Geometry.Vector3d dir = srf.NormalAt(u, v);
                dir.Unitize();

                // Scale by our fixed distance
                dir *= 0.5;

                // Move the grip to a new location
                grip.Move(dir);
            }
        }

        // Altered grip positions on a RhinoObject are used to calculate an updated
        // object that is added to the document.
        doc.Objects.GripUpdate(obj, false);
        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
コード例 #17
0
            //Called whenever a Rhino document is being loaded and plug-in user data was
            //encountered written by a plug-in with this plug-in's GUID.
            //
            //If any ON_BinaryArchive::Read*() functions return false than you should
            //immediately return false otherwise return true when all data was read.
            protected override void ReadDocument(Rhino.RhinoDoc doc, Rhino.FileIO.BinaryArchiveReader archive, Rhino.FileIO.FileReadOptions options)
            {
                //Always read data in the EXACT same order you wrote it
                int major, minor;

                archive.Read3dmChunkVersion(out major, out minor);

                //If you've changed your reading/writing code over time,
                //you can use the version number of what you read
                //to figure out what can be read from the archive
                if ((major > 1 | minor > 0))
                {
                    return;
                }

                //the data you read/write will probably be member variables of your plug-in class,
                //but for simplicity this sample is just using locally defined strings
                string date_string = archive.ReadString();
                string time_string = archive.ReadString();

                //Get the commands for "Insert_Source" and "Insert_Receiver". This is where the Source and Receiver conduits are stored.
                UI.Pach_Source_Object   S_command = Pach_Source_Object.Instance;
                UI.Pach_Receiver_Object R_command = Pach_Receiver_Object.Instance;

                System.Guid objectId = default(System.Guid);
                string      Type     = null;

                do
                {
                    try
                    {
                        objectId = archive.ReadGuid();
                        Type     = archive.ReadString();
                        if (Type == "Source")
                        {
                            Rhino.DocObjects.RhinoObject Source = doc.Objects.Find(objectId);
                            if (Source != null)
                            {
                                SourceConduit.Instance.SetSource(Source);
                                doc.Views.Redraw();
                            }
                        }
                        else if (Type == "Receiver")
                        {
                            Rhino.DocObjects.RhinoObject Receiver = doc.Objects.Find(objectId);
                            if (Receiver != null)
                            {
                                ReceiverConduit.Instance.SetReceiver(Receiver);
                                doc.Views.Redraw();
                            }
                        }
                        Type = null;
                    }catch (Exception)
                    {
                        break;
                    }
                }while (objectId != null);
            }
コード例 #18
0
 internal void OnAttachedToRhinoObject(Rhino.DocObjects.RhinoObject rhObj)
 {
     m_bDeleteOnDispose = false;
     // make sure all of the callback functions are hooked up
     UnsafeNativeMethods.CRhinoObjectGrips_SetCallbacks(m_OnResetCallback,
                                                        m_OnResetMeshesCallback, m_OnUpdateMeshCallback, m_OnNewGeometryCallback,
                                                        m_OnDrawCallback, m_OnNeighborGripCallback, m_OnNurbsSurfaceGripCallback,
                                                        m_NurbsSurfaceCallback);
 }
コード例 #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CenterPoints");

            if (layerCheck == null)
            {
                doc.Layers.Add("CenterPoints", System.Drawing.Color.Blue);
                layerCheck = doc.Layers.FindName("CenterPoints");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to add center point");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid pointG;
                Rhino.DocObjects.ObjRef      objref = go.Object(i);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                var objType = obj.ObjectType;
                if (objType == Rhino.DocObjects.ObjectType.Curve)
                {
                    Curve  curve  = objref.Curve();
                    Circle circle = new Circle();
                    if (!curve.TryGetCircle(out circle, doc.ModelAbsoluteTolerance))
                    {
                        BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                        Point3d     bbObjCenter = bbObj.Center;
                        pointG = doc.Objects.AddPoint(bbObjCenter);
                    }
                    else
                    {
                        Point3d circleCenter = circle.Center;
                        pointG = doc.Objects.AddPoint(circleCenter);
                    }
                }
                else
                {
                    BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                    Point3d     bbObjCenter = bbObj.Center;
                    pointG = doc.Objects.AddPoint(bbObjCenter);
                }
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(pointG);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #20
0
            /// <summary>
            /// Sets materials for an object by object.
            /// </summary>
            /// <param name="ID">object GUID (UUID)</param>
            /// <param name="Abs">0 to 100</param>
            /// <param name="Scat">0 to 100</param>
            /// <param name="Trans">0 to 100</param>
            /// <returns></returns>
            public static bool Material_SetByObject(Guid ID, int[] Abs, int[] Scat, int[] Trans)
            {
                Rhino.DocObjects.RhinoObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(ID);
                obj.Geometry.SetUserString("Acoustics_User", "yes");
                string MaterialCode = RC_PachTools.EncodeAcoustics(Abs, Scat, Trans);
                bool   result       = obj.Geometry.SetUserString("Acoustics", MaterialCode);

                return(result);
            }
コード例 #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("Numbers");

            if (layerCheck == null)
            {
                doc.Layers.Add("Numbers", System.Drawing.Color.DarkRed);
                layerCheck = doc.Layers.FindName("Numbers");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to number");
            var heightref = new Rhino.Input.Custom.OptionDouble(height);

            go.AddOptionDouble("Text_height_mm", ref heightref);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                height = heightref.CurrentValue;
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                Guid        objGuid            = objref.ObjectId;
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;

                int a = i + 1;

                Plane plane = Plane.WorldXY;
                plane.Origin = bbObjCenter;
                var    Justification = TextJustification.MiddleCenter;
                string text          = a.ToString();
                var    Font          = "Arial";

                Guid num = doc.Objects.AddText(text, plane, height, Font, false, false, Justification);

                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(num);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();

                int groupIndex = doc.Groups.Count;
                groupIndex++;
                string group = groupIndex.ToString();
                var    gI    = doc.Groups.Add(group);
                doc.Groups.AddToGroup(gI, num);
                doc.Groups.AddToGroup(gI, objGuid);
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #22
0
ファイル: interop.cs プロジェクト: lleibman/rhinocommon
        /// <summary>
        /// Returns the underlying const CRhinoObject* for a RhinoCommon class. You should only
        /// be interested in using this function if you are writing C++ code.
        /// </summary>
        /// <param name="rhinoObject">A Rhino object.</param>
        /// <returns>A pointer to the Rhino const object.</returns>
        public static IntPtr RhinoObjectConstPointer(Rhino.DocObjects.RhinoObject rhinoObject)
        {
            IntPtr rc = IntPtr.Zero;

            if (rhinoObject != null)
            {
                rc = rhinoObject.ConstPointer();
            }
            return(rc);
        }
コード例 #23
0
        protected override void onClickOculusTrigger(ref VREvent_t vrEvent)
        {
            OpenTK.Vector4 controller_p      = UtilOld.getLeftControllerTipPosition(ref mScene, true) * new OpenTK.Vector4(0, 0, 0, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));

            Rhino.DocObjects.RhinoObject rhobj = mScene.rhinoDoc.Objects.Find(cutPGuid);
            rhobj.Attributes.Name = "cut:" + controller_pRhino.X + ":" + controller_pRhino.Y + ":" + controller_pRhino.Z;
            rhobj.CommitChanges();
            Rhino.RhinoApp.WriteLine(rhobj.Attributes.Name);
        }
コード例 #24
0
        //Update illustrator doc bound if docbox changes in rhino.
        public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox)
        {
            //Parse rectangle from incoming RhinoObject.
            Guid incomingGuid = docBox.Id;

            Rhino.Geometry.Curve newCurve = null;

            Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid);

            newCurve = oRef.Curve();

            Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false);

            Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min;
            Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max;

            double newWidth  = newMaxPoint.X - newMinPoint.X;
            double newHeight = newMaxPoint.Y - newMinPoint.Y;

            int conversion = utils.units.conversion();

            //Compare previous size, or record if first run.
            string D01_Path = utils.file_structure.getPathFor("D01");
            string jsxPath  = utils.file_structure.getJavascriptPath();

            if (System.IO.File.Exists(D01_Path) == false)
            {
                string newData = newWidth.ToString() + "|" + newHeight.ToString();
                System.IO.File.WriteAllText(D01_Path, newData);
            }
            else if (System.IO.File.Exists(D01_Path) == true)
            {
                //If file exists, verify bounds changed. (Otherwise, box moved.)
                string[] oldData   = System.IO.File.ReadAllText(D01_Path).Split('|');
                double   oldWidth  = Convert.ToDouble(oldData[0]);
                double   oldHeight = Convert.ToDouble(oldData[1]);

                //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString());

                if (oldWidth == newWidth && oldHeight == newHeight)
                {
                    //outbound.push.fullReset();
                }
                else
                {
                    string newData = newWidth.ToString() + "|" + newHeight.ToString();
                    System.IO.File.WriteAllText(D01_Path, newData);

                    echo.interop echo = new echo.interop();
                    echo.docBounds(newWidth, newHeight, conversion, jsxPath);

                    //outbound.push.fullReset();
                }
            }
        }
コード例 #25
0
ファイル: PFoam_Pick.cs プロジェクト: worbit/PolyFrame
        public void SetVertexConstraints(IList <PFVertex> constr, Rhino.DocObjects.RhinoObject cBase, double coef = 1.0, bool on = true)
        {
            foreach (var vrt in constr)
            {
                vrt.RestrictSupport = cBase.Geometry;
                vrt.InfluenceCoef   = coef;

                vrt.SupportGuid = cBase.Id;
            }

            var type = cBase.Geometry.GetType();

            if (cBase.Geometry is Rhino.Geometry.Point) //(cBase.Geometry.GetType() == typeof(Rhino.Geometry.Point))
            {
                foreach (var vert in constr)
                {
                    vert.RestrictPosition = vert.ConstrainPoint;
                }
            }
            else if (cBase.Geometry is Curve) //(cBase.Geometry.GetType() == typeof(Curve) || cBase.Geometry.GetType() == typeof(NurbsCurve) || cBase.Geometry.GetType() == typeof(LineCurve))
            {
                foreach (var vert in constr)
                {
                    vert.RestrictPosition = vert.ConstrainCurve;
                }
            }
            else if (cBase.Geometry is Brep) //(cBase.Geometry.GetType() == typeof(Brep))
            {
                foreach (var vert in constr)
                {
                    if (on)
                    {
                        vert.RestrictPosition = vert.ConstrainOnBrep;
                    }
                    else
                    {
                        vert.RestrictPosition = vert.ConstrainInBrep;
                    }
                }
            }
            else if (cBase.Geometry is Mesh)// (cBase.Geometry.GetType() == typeof(Mesh))
            {
                foreach (var vert in constr)
                {
                    if (on)
                    {
                        vert.RestrictPosition = vert.ConstrainOnMesh;
                    }
                    else
                    {
                        vert.RestrictPosition = vert.ConstrainInMesh;
                    }
                }
            }
        }
コード例 #26
0
    private static bool CircleWithRadiusOf10GeometryFilter(Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry,
                                                           ComponentIndex componentIndex)
    {
        bool   is_circle_with_radius_of10 = false;
        Circle circle;

        if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle))
        {
            is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance;
        }
        return(is_circle_with_radius_of10);
    }
コード例 #27
0
            public override bool CustomGeometryFilter(
                Rhino.DocObjects.RhinoObject rhObject,
                Rhino.Geometry.GeometryBase geometry,
                Rhino.Geometry.ComponentIndex componentIndex)
            {
                var m = geometry as Mesh;

                if (m == null)
                {
                    return(false);
                }

                return(m.IsValid);
            }
コード例 #28
0
ファイル: Get_mesh.cs プロジェクト: TianyiWang3259/Overpaint
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

            Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject();
            gmesh.SetCommandPrompt("Get the Mesh");
            gmesh.GeometryFilter  = Rhino.DocObjects.ObjectType.Mesh;
            gmesh.SubObjectSelect = true;
            gmesh.Get();
            if (gmesh.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gmesh.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref = gmesh.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Rhino.Geometry.Mesh mesh = objref.Mesh();
            if (mesh == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            obj.Select(false);

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

            for (int i = 0; i < texture_list.Count - 1; i++)
            {
                Point2f f1 = texture_list[i];
                Point2f f2 = texture_list[i + 1];
                Point3d t1 = new Point3d(f1.X, f1.Y, 0);
                Point3d t2 = new Point3d(f2.X, f2.Y, 0);
                Line    l  = new Line(t1, t2);
                doc.Objects.AddLine(l);
                RhinoApp.WriteLine("Line added");
            }
            doc.Views.Redraw();
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
コード例 #29
0
ファイル: GisUtil.cs プロジェクト: nicoazel/ArcRhino
        /// <summary>
        /// Apply feature attributes (key-value pairs) as Rhino user text
        /// </summary>
        /// <param name="obj">RhinoObject</param>
        /// <param name="feature">Feature</param>
        private static void bindAttrs(Rhino.DocObjects.RhinoObject obj, Feature feature)
        {
            var fields = feature.GetFields();

            for (int i = 0; i < fields.Count; i++)
            {
                try
                {
                    var name = fields[i].Name;
                    var val  = feature.GetOriginalValue(i);
                    obj.Attributes.SetUserString(name, val.ToString());
                }
                catch { }
            }
        }
コード例 #30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Brep brep = new GH_Brep();

            DA.GetData <GH_Brep>("Element", ref brep);
            string layername = "";

            Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
            if (brep.ReferenceID != null && brep.ReferenceID != Guid.Empty)
            {
                Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(brep.ReferenceID);
                layername = doc.Layers[obj.Attributes.LayerIndex].Name;
            }

            DA.SetData("Layer", layername);
        }
コード例 #31
0
    public Rhino.DocObjects.RhinoObject[] ToArray()
    {
      if (null != m_rhino_objects)
        return m_rhino_objects.ToArray();

      int count = UnsafeNativeMethods.RhinoObjectArray_Count(m_ptr);
      Rhino.DocObjects.RhinoObject[] rc = new Rhino.DocObjects.RhinoObject[count];
      for (int i = 0; i < count; i++)
      {
        IntPtr pRhinoObject = UnsafeNativeMethods.RhinoObjectArray_Get(m_ptr, i);
        rc[i] = DocObjects.RhinoObject.CreateRhinoObjectHelper(pRhinoObject);
      }
      return rc;
    }
コード例 #32
0
    public static Rhino.DocObjects.RhinoObject[] ToArrayFromPointer(IntPtr pRhinoObjectArray)
    {
      if (IntPtr.Zero == pRhinoObjectArray)
        return new Rhino.DocObjects.RhinoObject[0];

      int count = UnsafeNativeMethods.RhinoObjectArray_Count(pRhinoObjectArray);
      Rhino.DocObjects.RhinoObject[] rc = new Rhino.DocObjects.RhinoObject[count];
      for (int i = 0; i < count; i++)
      {
        IntPtr pRhinoObject = UnsafeNativeMethods.RhinoObjectArray_Get(pRhinoObjectArray, i);
        rc[i] = DocObjects.RhinoObject.CreateRhinoObjectHelper(pRhinoObject);
      }
      return rc;
    }