예제 #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 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);
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
    public static Rhino.Commands.Result ObjectColor(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef[] objRefs;
        Rhino.Commands.Result     cmdResult = Rhino.Input.RhinoGet.GetMultipleObjects("Select objects to change color", false, Rhino.DocObjects.ObjectType.AnyObject, out objRefs);
        if (cmdResult != Rhino.Commands.Result.Success)
        {
            return(cmdResult);
        }

        System.Drawing.Color color = System.Drawing.Color.Black;
        bool rc = Rhino.UI.Dialogs.ShowColorDialog(ref color);

        if (!rc)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        for (int i = 0; i < objRefs.Length; i++)
        {
            Rhino.DocObjects.RhinoObject obj = objRefs[i].Object();
            if (null == obj || obj.IsReference)
            {
                continue;
            }

            if (color != obj.Attributes.ObjectColor)
            {
                obj.Attributes.ObjectColor = color;
                obj.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                obj.CommitChanges();
            }
        }

        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
예제 #7
0
    public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc)
    {
        // Select object to add texture
        const ObjectType filter = Rhino.DocObjects.ObjectType.Surface |
                                  Rhino.DocObjects.ObjectType.PolysrfFilter |
                                  Rhino.DocObjects.ObjectType.Mesh;

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

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

        // Select texture
        Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
        fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
        if (!fd.ShowDialog())
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify texture
        string bitmap_filename = fd.FileName;

        if (string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename))
        {
            return(Rhino.Commands.Result.Nothing);
        }

        // Make sure the object has it's material source set to "material_from_object"
        rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;

        // Make sure the object has a material assigned
        int material_index = rhino_object.Attributes.MaterialIndex;

        if (material_index < 0)
        {
            // Create a new material based on Rhino's default material
            material_index = doc.Materials.Add();
            // Assign the new material (index) to the object.
            rhino_object.Attributes.MaterialIndex = material_index;
        }

        if (material_index >= 0)
        {
            Rhino.DocObjects.Material mat = doc.Materials[material_index];
            mat.SetBumpTexture(bitmap_filename);
            mat.CommitChanges();

            //Don't forget to update the object, if necessary
            rhino_object.CommitChanges();

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }

        return(Rhino.Commands.Result.Failure);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CurveToCircle");

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



            GetObject gc = new GetObject();

            gc.SetCommandPrompt("Select curves to make into circles");
            gc.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            gc.GroupSelect     = true;
            gc.SubObjectSelect = false;
            gc.EnableClearObjectsOnEntry(false);
            gc.EnableUnselectObjectsOnExit(false);
            gc.DeselectAllBeforePostSelect = false;
            gc.GetMultiple(1, 0);

            for (int i = 0; i < gc.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = gc.Object(i);
                var curve = objref.Curve();
                if (curve == null)
                {
                    return(Result.Nothing);
                }

                Circle circle;

                if (!curve.TryGetCircle(out circle))
                {
                    if (!curve.IsClosed)
                    {
                        if (curve.IsClosable(doc.ModelAbsoluteTolerance))
                        {
                            curve.MakeClosed(doc.ModelAbsoluteTolerance);
                        }
                        else
                        {
                            Curve blendCurve;
                            blendCurve = Curve.CreateBlendCurve(curve, curve, BlendContinuity.Curvature);
                            Curve[] curveSet    = { curve, blendCurve };
                            Curve[] joinedCurve = Curve.JoinCurves(curveSet);
                            curve = joinedCurve[0];
                        }
                    }

                    //curve.Rebuild(3,2,true);
                    double[]  curveDivide = curve.DivideByCount(8, true);
                    Point3d   curvePoint;
                    Point3d[] curvePoints = new Point3d[8];
                    for (int d = 0; d < 8; d++)
                    {
                        curvePoint     = curve.PointAt(curveDivide[d]);
                        curvePoints[d] = curvePoint;
                    }

                    if (!Circle.TryFitCircleToPoints(curvePoints, out circle))
                    {
                        circle = new Circle(5);
                    }
                }



                var circGuid = doc.Objects.AddCircle(circle);
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(circGuid);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }


            doc.Views.Redraw();

            return(Result.Success);
        }
예제 #9
0
        /// <summary>
        /// Called by Rhino to "run" your command.
        /// </summary>
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            doc.Objects.Clear();

            Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog {
                Filter = "XML File (*.xml)|*.xml"
            };

            if (!fd.ShowOpenDialog())
            {
                return(Result.Cancel);
            }


            //Read TopoCreator
            String xmlfile  = fd.FileName;
            IntPtr topoData = TopoCreator.readXML(xmlfile);
            int    n_part   = TopoCreator.partNumber(topoData);

            //Part Layer
            int partlayer_index = getLayerOrCreate(doc, "Part");

            //Boundary Layer
            int boundarylayer_index = getLayerOrCreate(doc, "Boundary");

            for (int partID = 0; partID < n_part; partID++)
            {
                Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
                TopoCreator.getPartMesh(partID, mesh, topoData);

                Guid mesh_guid = doc.Objects.AddMesh(mesh);

                //error: exit
                if (mesh_guid == Guid.Empty)
                {
                    TopoCreator.deleteStructure(topoData);
                    return(Result.Failure);
                }

                Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(mesh_guid);
                int mat_index;
                if (TopoCreator.isBoundary(partID, topoData) == 1)
                {
                    mat_index = doc.Materials.Find("PlasterBoundary", false);
                    obj.Attributes.LayerIndex = boundarylayer_index;
                }
                else
                {
                    mat_index = doc.Materials.Find("PlasterPart", false);
                    obj.Attributes.LayerIndex = partlayer_index;
                }

                if (mat_index != -1)
                {
                    obj.Attributes.MaterialIndex  = mat_index;
                    obj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
                }
                obj.CommitChanges();
            }

            //CrossMesh

            int crossMeshlayer_index = getLayerOrCreate(doc, "CrossMesh");

            List <Rhino.Geometry.Polyline> polylines = new List <Rhino.Geometry.Polyline>();
            IntPtr crossMesh = TopoCreator.initCrossMeshPtr(topoData);

            TopoCreator.getPolyLines(polylines, crossMesh);
            TopoCreator.deletePolyLineRhino(crossMesh);
            for (int id = 0; id < polylines.Count; id++)
            {
                Guid polyline_guid = doc.Objects.AddPolyline(polylines[id]);

                Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(polyline_guid);
                obj.Attributes.LayerIndex = crossMeshlayer_index;
                obj.CommitChanges();
            }


            //Rhino.RhinoApp.RunScript("_SelMesh", false);
            //Rhino.RhinoApp.RunScript("_MeshToNURB", false);
            //Rhino.RhinoApp.RunScript("_SelMesh", false);
            //Rhino.RhinoApp.RunScript("_Delete", false);
            //Rhino.RhinoApp.RunScript("_SelPolysrf", false);
            //Rhino.RhinoApp.RunScript("_MergeAllFaces", false);

            doc.Objects.UnselectAll();
            TopoCreator.deleteStructure(topoData);
            return(Result.Success);
        }