Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public override void draw(bool isTop)
        {
            //visualize the point on the plane
            if (onPlane && isTop)
            {
                //ray casting to the pre-defind planes
                OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
                OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == 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)));

                Rhino.Geometry.Vector3d direction = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_pRhino.X, controller_pZRhin.Y - controller_pRhino.Y, controller_pZRhin.Z - controller_pRhino.Z);
                Ray3d ray = new Ray3d(controller_pRhino, direction);

                Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep;
                //settings.NameFilter = "plane";
                float mimD = 1000000f;
                hitPlane = false;
                if (!lockPlane)
                {
                    foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings))
                    {
                        //only drawing on planes for now rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("plane")
                        if (rhObj.Attributes.Name.Contains("plane"))
                        {
                            List <GeometryBase> geometries = new List <GeometryBase>();
                            geometries.Add(rhObj.Geometry);
                            //must be a brep or surface, not mesh
                            Point3d[] rayIntersections = Rhino.Geometry.Intersect.Intersection.RayShoot(ray, geometries, 1);
                            if (rayIntersections != null)
                            {
                                //get the nearest one
                                OpenTK.Vector3 tmpP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                                float          distance = (float)Math.Sqrt(Math.Pow(tmpP.X - controller_p.X, 2) + Math.Pow(tmpP.Y - controller_p.Y, 2) + Math.Pow(tmpP.Z - controller_p.Z, 2));

                                if (distance < mimD)
                                {
                                    hitPlane     = true;
                                    targetPRhObj = rhObj;
                                    mimD         = distance;
                                    projectP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (targetPRhObj != null)
                    {
                        List <GeometryBase> geometries = new List <GeometryBase>();
                        geometries.Add(targetPRhObj.Geometry);
                        //must be a brep or surface, not mesh
                        Point3d[] rayIntersections = Rhino.Geometry.Intersect.Intersection.RayShoot(ray, geometries, 1);
                        if (rayIntersections != null)
                        {
                            //get the nearest one
                            OpenTK.Vector3 tmpP     = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                            float          distance = (float)Math.Sqrt(Math.Pow(tmpP.X - controller_p.X, 2) + Math.Pow(tmpP.Y - controller_p.Y, 2) + Math.Pow(tmpP.Z - controller_p.Z, 2));

                            if (distance < mimD)
                            {
                                hitPlane = true;
                                mimD     = distance;
                                projectP = UtilOld.platformToVRPoint(ref mScene, new OpenTK.Vector3((float)rayIntersections[0].X, (float)rayIntersections[0].Y, (float)rayIntersections[0].Z));
                            }
                        }
                    }
                }

                if (!hitPlane)
                {
                    targetPRhObj = null;
                    projectP     = new OpenTK.Vector3(100, 100, 100); //make it invisable
                }

                //visualize the projection points
                // inverted rotation first

                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(UtilOld.transformPoint(mScene.tableGeometry.transform.Inverted(), projectP));
                t.Transpose();
                drawPoint.transform = t;
            }


            if (currentState != State.PAINT || !isTop)
            {
                return;
            }

            // drawing curve
            Vector3 pos = new Vector3();

            if (onPlane)
            {
                pos = projectP;
                if (hitPlane)
                {
                    //GeometryStroke handle rotation
                    ((Geometry.GeometryStroke)stroke_g).addPoint(pos);
                    rhihoPointList.Add(UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, pos)));
                }
            }
            else
            {
                pos = Util.Math.GetTranslationVector3(UtilOld.getControllerTipPosition(ref mScene, primaryDeviceIndex == mScene.leftControllerIdx));
                //GeometryStroke handle rotation already
                ((Geometry.GeometryStroke)stroke_g).addPoint(pos);
                rhihoPointList.Add(UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, pos)));
            }

            if (((Geometry.GeometryStroke)stroke_g).mNumPrimitives == 1)
            {
                SceneNode stroke = new SceneNode("Stroke", ref stroke_g, ref stroke_m);
                mScene.tableGeometry.add(ref stroke);
                //mScene.staticGeometry.add(ref stroke);
                strokeId = stroke.guid;
            }

            //testing the performance of rhino curve
            if (rhihoPointList.Count == 2)
            {
                rcurve = Curve.CreateInterpolatedCurve(rhihoPointList.ToArray(), 3);
            }
            else if (rhihoPointList.Count > 2)
            {
                rcurve.Extend(Rhino.Geometry.CurveEnd.End, Rhino.Geometry.CurveExtensionStyle.Line, rhihoPointList[rhihoPointList.Count - 1]);
            }
        }
Esempio n. 3
0
        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);
        }