示例#1
0
        protected override void onClickOculusTrigger(ref VREvent_t vrEvent)
        {
            primaryDeviceIndex = vrEvent.trackedDeviceIndex;

            if ((dynamicRender == "Extrude" || dynamicRender == "Sweep") && !isSnap)
            {
                return;
            }

            if (currentState == State.READY)
            {
                if (drawnType == DrawnType.In3D)
                {
                    stroke_g     = new Geometry.GeometryStroke(ref mScene);
                    reducePoints = new List <Vector3>();
                    currentState = State.DRAW;
                }
                else
                {
                    if (targetPRhObjID == Guid.Empty)
                    {
                        return;
                    }

                    curveOnObjRef = new ObjRef(targetPRhObjID);

                    if (curveOnObjRef != null)
                    {
                        //chage to only raycasting to the obj where we draw
                        rayCastingObjs.Clear();
                        rayCastingObjs.Add(curveOnObjRef);
                        stroke_g     = new Geometry.GeometryStroke(ref mScene);
                        reducePoints = new List <Vector3>();
                        currentState = State.DRAW;

                        //TODO- figure out why we do this here
                        if (drawnType == DrawnType.Plane)
                        {
                            //TODO-generalize change SceneNode alpha
                            UtilOld.hideOtherPlanes(ref mScene, curveOnObjRef.Object().Attributes.Name);
                        }
                        else if (drawnType == DrawnType.Reference)
                        {
                            ((Material.SingleColorMaterial)railPlaneSN.material).setAlpha(0.0f);
                        }

                        //detecting projection plane in a Brep
                        Double tolerance = 0;
                        curvePlane = new Plane();
                        if (drawnType != DrawnType.In3D)
                        {
                            Brep targetBrep = (Brep)(curveOnObjRef.Object().Geometry);

                            float minD     = 1000000f;
                            int   minIndex = -1;
                            for (int i = 0; i < targetBrep.Faces.Count; i++)
                            {
                                //cast BrepFace to Brep for ClosestPoint(P) menthod
                                double dist = targetBrep.Faces[i].DuplicateFace(false).ClosestPoint(projectP).DistanceTo(projectP);
                                if (dist < minD)
                                {
                                    minD     = (float)dist;
                                    minIndex = i;
                                }
                            }
                            Surface s = targetBrep.Faces[minIndex];
                            //surface might not be a perfect planar surface
                            while (tolerance < toleranceMax)
                            {
                                if (s.TryGetPlane(out curvePlane, tolerance))
                                {
                                    break;
                                }
                                tolerance++;
                            }
                        }

                        //add plane to iPlaneList since Sweep fun need it's info
                        if (tolerance < toleranceMax)
                        {
                            //DrawnType.Reference already has a railPlane

                            /*
                             * if (drawnType != DrawnType.Reference)
                             *  mScene.iPlaneList.Add(curvePlane);
                             */
                        }
                        else
                        {
                            Rhino.RhinoApp.WriteLine("Can't find projectPlane");
                        }
                    }
                }
            }
        }
示例#2
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;
            }
        }