예제 #1
0
        private string ShootScene(Point3d loc, int res, double lens)
        {
            // Generate list of point targets in circle around basepoint
            var circ     = new Rhino.Geometry.Circle(loc, 1);
            var circCast = circ.ToNurbsCurve();
            var ptParams = circCast.DivideByCount(res, false);

            // Get the active vpt
            var av = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

            // Set viewport props
            av.ActiveViewport.Camera35mmLensLength = lens;

            // Create temp directory
            var appdpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var myPath   = appdpath + @"\aviary\";

            System.IO.Directory.CreateDirectory(myPath);

            // Clear existing in temp directory
            System.IO.DirectoryInfo di = new DirectoryInfo(myPath);
            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }


            int nameIterator = 0;

            foreach (var par in ptParams)
            {
                // Convert par to target point
                var tar = circCast.PointAt(par);

                // Set the camera
                av.ActiveViewport.SetCameraLocations(tar, loc);

                // Capture the active viewport
                using (Bitmap map = av.CaptureToBitmap(new Size(800, 600)))
                {
                    string outputFileName = myPath + "_" + nameIterator.ToString() + ".jpg";
                    using (MemoryStream memory = new MemoryStream())
                    {
                        using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
                        {
                            map.Save(memory, System.Drawing.Imaging.ImageFormat.Jpeg);
                            byte[] bytes = memory.ToArray();
                            fs.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
                nameIterator++;
            }
            return(myPath);
        }
예제 #2
0
        private void createModel()
        {
            /*
             * Rhino.Geometry.Point3d origin = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, 0)));
             * Rhino.Geometry.Point3d normalP1 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -0.05f)));
             * Rhino.Geometry.Point3d normalP2 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -1)));
             * Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(normalP2.X - normalP1.X, normalP2.Y - normalP1.Y, normalP2.Z - normalP1.Z);
             * Plane plane = new Plane(origin, normal);
             * float radius = 20;
             * Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, origin, radius);
             * NurbsCurve circleCurve = circle.ToNurbsCurve();
             *
             * //compute transform to follow controllers
             * OpenTK.Matrix4 tansform = mScene.robotToPlatform * mScene.vrToRobot * Util.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx);
             * Transform t = Util.OpenTKToRhinoTransform(tansform);
             * circleCurve.Transform(t);
             * Brep[] shapes = Brep.CreatePlanarBreps(circleCurve);
             * Brep circle_s = shapes[0];
             * Brep circleBrep = circle_s;
             *
             * Guid renderObjId = Util.addSceneNode(ref mScene, circleBrep, ref mesh_m, "circle");
             */


            //offset the point a little bit to make the plane better
            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -0.05f, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));


            //fix the x and y axis of the model Plane
            OpenTK.Vector4 controller_x1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(1, 0, 0, 1);
            OpenTK.Vector4 controller_y1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 1, 0, 1);
            Point3d        controller_x1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_x1.X, controller_x1.Y, controller_x1.Z)));
            Point3d        controller_y1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_y1.X, controller_y1.Y, controller_y1.Z)));

            OpenTK.Vector4 controller_o      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            Point3d        controller_oRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_o.X, controller_o.Y, controller_o.Z)));

            Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_oRhino.X, controller_pZRhin.Y - controller_oRhino.Y, controller_pZRhin.Z - controller_oRhino.Z);
            normal.Unitize();
            modelPlane = new Plane(controller_oRhino, normal);

            if (shapeType == ShapeType.Circle)
            {
                Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(modelPlane, controller_oRhino, radius);
                modelcurve = circle.ToNurbsCurve();
            }
            else if (shapeType == ShapeType.Rect)
            {
                Rhino.Geometry.Vector3d xAxis = new Rhino.Geometry.Vector3d(controller_x1Rhino.X - controller_oRhino.X, controller_x1Rhino.Y - controller_oRhino.Y, controller_x1Rhino.Z - controller_oRhino.Z);
                xAxis.Unitize();
                Rhino.Geometry.Vector3d yAxis = new Rhino.Geometry.Vector3d(controller_y1Rhino.X - controller_oRhino.X, controller_y1Rhino.Y - controller_oRhino.Y, controller_y1Rhino.Z - controller_oRhino.Z);
                yAxis.Unitize();

                modelPlane.XAxis = xAxis;
                modelPlane.YAxis = yAxis;

                //Rectangle3d rect = new Rectangle3d(modelPlane, width, height);
                Rectangle3d rect = new Rectangle3d(modelPlane, new Interval(-width / 2, width / 2), new Interval(-height / 2, height / 2));
                modelcurve = rect.ToNurbsCurve();
            }

            if (modelcurve != null)
            {
                Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                modelBrep = shapes[0];
                UtilOld.updateSceneNode(ref mScene, modelBrep, ref mesh_m, "3D-" + shapeType.ToString(), ref previewObjSN);
            }
        }
예제 #3
0
        protected override void onClickOculusTrigger(ref VREvent_t vrEvent)
        {
            primaryDeviceIndex = vrEvent.trackedDeviceIndex;
            if (currentState != State.READY || targetPRhObjID == Guid.Empty)
            {
                return;
            }

            pointOnObjRef = new ObjRef(targetPRhObjID);
            //chage to only raycasting to the obj where we draw, if not snap to the origin
            if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
            {
                rayCastingObjs.Clear();
                rayCastingObjs.Add(pointOnObjRef);
            }

            //testing
            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, projectPVR)); //not use at the current version, point is VR coordinate
            pointsList.Add(projectP);

            //render edit points in VR
            Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0));
            Material.Material m   = new Material.SingleColorMaterial(0, 1, 0, 1);
            SceneNode         editPointSN;

            UtilOld.MarkPointVR(ref mScene, projectPVR, ref geo, ref m, out editPointSN);
            pointMarkers.Add(editPointSN);

            //TODO-hide two other design plane
            if (pointMarkers.Count == 1)
            {
                if (pointOnObjRef != null && drawnType == DrawnType.Plane)
                {
                    if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
                    {
                        UtilOld.hideOtherPlanes(ref mScene, pointOnObjRef.Object().Attributes.Name);
                    }
                    computeContourCurve();
                }
                //TODO- how to find the curvePlane on the surface like teapot body, using the normal of first point?
                //do we need to use different ways for patch surface and other generated surface
                else if (pointOnObjRef != null && drawnType == DrawnType.Surface)
                {
                    computeContourCurve();
                }
            }

            if (maxNumPoint == pointMarkers.Count)
            {
                //Assume we always can find a curvePlane sicnce we use a huge tolerance
                NurbsCurve modelcurve = null;
                Brep       modelBrep;
                string     modelName = "";
                if (shapeType == ShapeType.Circle)
                {
                    float  radius = (float)Math.Sqrt(Math.Pow(pointsList[1].X - pointsList[0].X, 2) + Math.Pow(pointsList[1].Y - pointsList[0].Y, 2) + Math.Pow(pointsList[1].Z - pointsList[0].Z, 2));
                    Circle circle = new Rhino.Geometry.Circle(curvePlane, pointsList[0], radius);
                    modelcurve = circle.ToNurbsCurve();
                    modelName  = "Circle";
                }
                else if (shapeType == ShapeType.Rect)
                {
                    Vector3 rectDiagonalV = new Vector3((float)(pointsList[0].X - pointsList[1].X), (float)(pointsList[0].Y - pointsList[1].Y), (float)(pointsList[0].Z - pointsList[1].Z));
                    float   lenDiagonal   = rectDiagonalV.Length;
                    Vector3 rectLeftTop   = new Vector3((float)pointsList[0].X, (float)pointsList[0].Y, (float)pointsList[0].Z) + lenDiagonal * rectDiagonalV.Normalized();
                    Point3d topLeftP      = new Point3d(rectLeftTop.X, rectLeftTop.Y, rectLeftTop.Z);

                    Rectangle3d rect = new Rectangle3d(curvePlane, topLeftP, pointsList[1]);

                    //using top-left cornel and bottom right

                    //Rectangle3d rect = new Rectangle3d(curvePlane, pointsList[0], pointsList[1]);

                    modelcurve = rect.ToNurbsCurve();
                    modelName  = "Rect";
                }

                /*
                 * Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                 * modelBrep = shapes[0];
                 * Guid guid = Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref profile_m, modelName, out renderObjSN);
                 */

                //generate new curveOnObj for mvoingPlane cases sicne and move the XYZPlanes to origial positons
                if (drawnType == DrawnType.Plane)
                {
                    Rhino.Geometry.Vector3d newNormal = new Rhino.Geometry.Vector3d();;
                    Point3d newOrigin   = new Point3d();
                    String  planeName   = pointOnObjRef.Object().Attributes.Name;
                    Point3d planeOrigin = pointOnObjRef.Object().Geometry.GetBoundingBox(true).Center;
                    if (planeName.Contains("planeXY"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 0, 1);
                        newOrigin = new Point3d(0, 0, planeOrigin.Z);
                    }
                    else if (planeName.Contains("planeYZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(1, 0, 0);
                        newOrigin = new Point3d(planeOrigin.X, 0, 0);
                    }
                    else if (planeName.Contains("planeXZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 1, 0);
                        newOrigin = new Point3d(0, planeOrigin.Y, 0);
                    }

                    Plane        newPlane      = new Plane(newOrigin, newNormal);
                    int          size          = 240;
                    PlaneSurface plane_surface = new PlaneSurface(newPlane, new Interval(-size, size), new Interval(-size, size));
                    Brep         newPlaneBrep  = Brep.CreateFromSurface(plane_surface);

                    Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "MoveP");
                    //might be better to use Replace(), just need to be careful about the referece count
                    pointOnObjRef = null;
                    pointOnObjRef = new ObjRef(newPlaneID);

                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), newPlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), newPlane.Normal.ToString());
                }
                else if (drawnType == DrawnType.Surface)
                {
                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), pointOnObjRef.ObjectId.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString());
                }

                mScene.iCurveList.Add(modelcurve);

                //call next interaction in the chain
                afterCurveCount = mScene.iCurveList.Count;
                mScene.pushInteractionFromChain();
                currentState = State.READY;
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        ComputeServer.AuthToken = authToken;

        var model  = new Rhino.FileIO.File3dm();
        var curves = new List <Rhino.Geometry.NurbsCurve>();

        for (int i = 0; i < 20; i++)
        {
            var s  = 10f;
            var pt = new Rhino.Geometry.Point3d(Random.Range(-s, s), Random.Range(-s, s), 0);
            // model.Objects.AddPoint(pt);
            var r      = Random.Range(1f, 3f);
            var circle = new Rhino.Geometry.Circle(pt, r);
            var curve  = circle.ToNurbsCurve();
            curves.Add(curve);
        }

        var unionCrvsC = CurveCompute.CreateBooleanUnion(curves);

        var height     = Random.Range(1f, 5f);
        var extrusions = new List <Rhino.Geometry.Extrusion>();

        foreach (var unionCrvC in unionCrvsC)
        {
            var extrusion = Rhino.Geometry.Extrusion.Create(unionCrvC, height, true);
            model.Objects.AddExtrusion(extrusion);
            extrusions.Add(extrusion);
        }

        var meshList = new List <Rhino.Geometry.Mesh>();

        foreach (var extrusion in extrusions)
        {
            var brep   = extrusion.ToBrep();
            var meshes = MeshCompute.CreateFromBrep(brep);
            meshList.AddRange(meshes.ToList());
        }

        foreach (var mesh in meshList)
        {
            Mesh meshObj = new Mesh();

            var vertices = new List <Vector3>();
            // mesh.RebuildNormals();
            foreach (var meshVertex in mesh.Vertices)
            {
                var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y);
                vertices.Add(vertex);
            }

            var triangles = new List <int>();
            foreach (var meshFace in mesh.Faces)
            {
                if (meshFace.IsTriangle)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                }
                else if (meshFace.IsQuad)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                    triangles.Add(meshFace.D);
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.A);
                }
            }


            meshObj.vertices  = vertices.ToArray();
            meshObj.triangles = triangles.ToArray();


            meshObj.RecalculateNormals();

            GameObject gb = new GameObject();
            gb.AddComponent <MeshFilter>().mesh       = meshObj;
            gb.AddComponent <MeshRenderer>().material = mat;
        }


        var path = Application.dataPath + "/../Outputs/model.3dm";

        model.Write(path, 5);
    }
예제 #5
0
 public Geometry(Rg.Circle circle)
 {
     curveType = CurveTypes.Circle;
     curve     = circle.ToNurbsCurve();
 }