public override void init() { resetVariables(); //support undo function if (mScene != null && (afterCurveCount - beforeCurveCount) > 0) { if (mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()) != "") { Guid curveOnObjId = new Guid(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString())); ObjRef curveOnObjRef = new ObjRef(curveOnObjId); if (curveOnObjRef.Object().Attributes.Name.Contains("MoveP")) { UtilOld.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId); } } mScene.iCurveList.RemoveAt(mScene.iCurveList.Count - 1); pointOnObjRef = null; } if (drawnType != DrawnType.In3D && drawnType != DrawnType.None) { UtilOld.showLaser(ref mScene, true); if (drawnType == DrawnType.Plane) { UtilOld.setPlaneAlpha(ref mScene, 0.4f); } //init rayCastingObjs Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep; foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings)) { bool b1 = (drawnType == DrawnType.Plane) && rhObj.Attributes.Name.Contains("plane"); bool b2 = (drawnType == DrawnType.Surface) && (rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("patchSurface")); bool b3 = (drawnType == DrawnType.Reference) && rhObj.Attributes.Name.Contains("railPlane"); if (b1 || b2 || b3) { rayCastingObjs.Add(new ObjRef(rhObj.Id)); } } Geometry.Geometry geo = new Geometry.DrawPointMarker(new OpenTK.Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(1, 1, 1, 0); drawPoint = new SceneNode("drawPoint", ref geo, ref m); UtilOld.addSceneNode(ref mScene, ref drawPoint); } else { UtilOld.showLaser(ref mScene, false); } }
public override void init() { resetVariables(); //support undo function if (mScene != null && (afterCurveCount - beforeCurveCount) > 0) { if (mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()) != "") { Guid curveOnObjId = new Guid(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString())); ObjRef curveOnObjRef = new ObjRef(curveOnObjId); if (curveOnObjRef.Object().Attributes.Name.Contains("railPlane") || curveOnObjRef.Object().Attributes.Name.Contains("MoveP")) { UtilOld.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId); } } mScene.iCurveList.RemoveAt(mScene.iCurveList.Count - 1); UtilOld.removeSceneNode(ref mScene, ref strokeSN); strokeSN = null; //need to clear stroke tprint SceneNode as well here if (renderObjSN != null) { UtilOld.removeSceneNode(ref mScene, ref renderObjSN); renderObjSN = null; } //Util.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId); curveOnObjRef = null; if (railPlaneSN != null) { UtilOld.removeRhinoObjectSceneNode(ref mScene, ref railPlaneSN); railPlaneSN = null; } } if (drawnType != DrawnType.In3D && drawnType != DrawnType.None) { UtilOld.showLaser(ref mScene, true); //create and add referece planes to scene if (drawnType == DrawnType.Reference) { Vector3 railPlaneNormal = UtilOld.RhinoToOpenTKVector(UtilOld.getVectorfromString(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()))); OpenTK.Vector3 worldUpAxis = new Vector3(0, 0, 1); //trick to avoid cross product of 2 parallel vetors if (railPlaneNormal.X == 0 && railPlaneNormal.Y == 0 && railPlaneNormal.Z == 1) { railPlaneNormal = new Vector3(0, 0.005f, 1); } Plane railPlane = new Plane(mScene.iCurveList[mScene.iCurveList.Count - 1].GetBoundingBox(true).Center, UtilOld.openTkToRhinoVector(Vector3.Cross(railPlaneNormal, worldUpAxis))); float planeSize = 240; PlaneSurface plane_surface2 = new PlaneSurface(railPlane, new Interval(-planeSize, planeSize), new Interval(-planeSize, planeSize)); Brep railPlane2 = Brep.CreateFromSurface(plane_surface2); Guid railPlaneGuid = UtilOld.addRhinoObjectSceneNode(ref mScene, ref railPlane2, ref railPlane_m, "railPlane", out railPlaneSN); } else if (drawnType == DrawnType.Plane) { UtilOld.setPlaneAlpha(ref mScene, 0.4f); } //init rayCastingObjs Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep; foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings)) { bool b1 = (drawnType == DrawnType.Plane) && rhObj.Attributes.Name.Contains("plane"); bool b2 = (drawnType == DrawnType.Surface) && (rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("patchSurface")); bool b3 = (drawnType == DrawnType.Reference) && rhObj.Attributes.Name.Contains("railPlane"); if (b1 || b2 || b3) { rayCastingObjs.Add(new ObjRef(rhObj.Id)); } } Geometry.Geometry geo = new Geometry.DrawPointMarker(new OpenTK.Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(1, 1, 1, 0);//TODO: teseting alpha working or not drawPoint = new SceneNode("drawPoint", ref geo, ref m); UtilOld.addSceneNode(ref mScene, ref drawPoint); } else { UtilOld.showLaser(ref mScene, false); } //generate snap points when we need to draw from the center of the shapes, drawnType could be DrawnType.Reference or DrawnType.In3D if (dynamicRender == "Extrude" || dynamicRender == "Sweep" || drawnType == DrawnType.Reference) { shouldSnap = true; ShapeType shapeType = (ShapeType)mScene.selectionDic[SelectionKey.Profile1Shape]; Circle circle; Rectangle3d rect; if (shapeType == ShapeType.Circle) { if (mScene.iCurveList[mScene.iCurveList.Count - 1].TryGetCircle(out circle)) { snapPointsList.Add(circle.Center); } } else if (shapeType == ShapeType.Rect) { Rhino.Geometry.Polyline polyline; if (mScene.iCurveList[mScene.iCurveList.Count - 1].TryGetPolyline(out polyline)) { rect = Rectangle3d.CreateFromPolyline(polyline); snapPointsList.Add(rect.Center); } } //visualize the snap points Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(0, 1, 0, 1); UtilOld.MarkPointVR(ref mScene, UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(snapPointsList[0])), ref geo, ref m, out snapPointSN); } d = new generateModel_Delegate(generateModel); }
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; } }