示例#1
0
 public SceneNode(string _name)
 {
     name        = _name;
     geometry    = null;
     material    = null;
     guid        = Guid.NewGuid();
     mRenderLate = false;
 }
示例#2
0
 public SceneNode(string _name, ref Geometry.Geometry g, ref Material.Material m, bool renderLate = false)
 {
     name        = _name;
     geometry    = g;
     material    = m;
     guid        = Guid.NewGuid();
     mRenderLate = renderLate;
 }
示例#3
0
        public bool init()
        {
            // Set up HMD
            EVRInitError eError = EVRInitError.None;

            mHMD = OpenVR.Init(ref eError, EVRApplicationType.VRApplication_Scene);

            if (eError == EVRInitError.None)
            {
                Rhino.RhinoApp.WriteLine("Booted VR System");
                renderPoseArray = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount];
                gamePoseArray   = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount];
            }
            else
            {
                Rhino.RhinoApp.WriteLine("Failed to boot");
                mTitleBase = "SparrowHawk (No VR Detected)";
            }

            // // THIS IS FOR UNCLIPPED
            // Width = 864;
            // Height = 820;

            // THIS IS FOR CLIPPED RECTANGLE
            Width  = 691;
            Height = 692;

            // Window Setup Info
            mStrDriver  = UtilOld.GetTrackedDeviceString(ref mHMD, OpenVR.k_unTrackedDeviceIndex_Hmd, ETrackedDeviceProperty.Prop_TrackingSystemName_String);
            mStrDisplay = UtilOld.GetTrackedDeviceString(ref mHMD, OpenVR.k_unTrackedDeviceIndex_Hmd, ETrackedDeviceProperty.Prop_SerialNumber_String);
            mTitleBase  = "SparrowHawk - " + mStrDriver + " " + mStrDisplay;
            Title       = mTitleBase;
            MakeCurrent();
            setupScene();


            if (eError == EVRInitError.None)
            {
                mRenderer = new VrRenderer(ref mHMD, ref mScene, mRenderWidth, mRenderHeight);
            }
            else
            {
                mRenderer = new VrRenderer(ref mHMD, ref mScene, mRenderWidth, mRenderHeight);
            }

            //use other 8 points for calibrartion
            robotCallibrationPointsTest.Add(new Vector3(22, 15, -100) / 1000);
            robotCallibrationPointsTest.Add(new Vector3(-10, 40, -153) / 1000);
            robotCallibrationPointsTest.Add(new Vector3(25, -25, -181) / 1000);

            foreach (Vector3 v in robotCallibrationPointsTest)
            {
                Vector4 v4 = new Vector4(v.X, v.Y, v.Z, 1);
                v4 = mScene.vrToRobot.Inverted() * v4;
                UtilOld.MarkPoint(ref mScene.staticGeometry, new Vector3(v4.X, v4.Y, v4.Z), 1, 1, 1);
            }
            robotCallibrationPointsTest.Clear();

            //set default matrix
            if (mRenderer.ovrvision_controller != null)
            {
                mRenderer.ovrvision_controller.setDefaultMatrixHC();
            }

            //detecting whether users in control or left
            Rhino.DocObjects.ObjectAttributes attr = new Rhino.DocObjects.ObjectAttributes();
            attr.Name = "user:out";
            Point3d userP = new Point3d(0, 0, 0);

            uGuid = mScene.rhinoDoc.Objects.AddPoint(userP, attr);

            //testing - rotate rhino object as well

            /*
             * Transform transM = new Transform();
             * for (int row = 0; row < 4; row++)
             * {
             *  for (int col = 0; col < 4; col++)
             *  {
             *      transM[row, col] = mScene.platformRotation[row, col];
             *  }
             * }
             * 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))
             * {
             *  mDoc.Objects.Transform(rhObj.Id, transM, true);
             * }
             * mScene.rhinoDoc.Views.Redraw();
             */

            //testing visualize printStroke
            printStroke   = new Geometry.RobotPrintStroke(ref mScene);
            printStroke_m = new Material.SingleColorMaterial(1, 1, 0, 1.0f);

            return(eError == EVRInitError.None);
        }
示例#4
0
        protected void handleSignals()
        {
            SparrowHawkSignal s = SparrowHawkEventListeners.Instance.getOneSignal();

            if (s == null)
            {
                return;
            }
            switch (s.type)
            {
            case SparrowHawkSignal.ESparrowHawkSigalType.InitType:
                if (s.data.Length >= 3)
                {
                    //To compute VRtoRobot matrix, press V key 8 times.
                    //robotPoint is in mm unit so the calibration result already deal with scale issue
                    Vector3 robotPoint = new Vector3(s.data[0], s.data[1], s.data[2]);
                    robotCallibrationPoints.Add(robotPoint);
                    Rhino.RhinoApp.WriteLine("add robotPoint: " + robotPoint.ToString());
                    if (mIsLefty && mScene.leftControllerIdx < 0 || !mIsLefty && mScene.leftControllerIdx < 0)
                    {
                        break;
                    }
                }
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.LineType:
                if (s.data.Length >= 4)
                {
                    if (s.data[0] == 0)
                    {
                        OpenTK.Vector3 p1 = new Vector3(s.data[1], s.data[2], s.data[3]);
                        p1 = UtilOld.platformToVRPoint(ref mScene, p1);
                        OpenTK.Vector3 p2 = new Vector3(s.data[4], s.data[5], s.data[6]);
                        p2 = UtilOld.platformToVRPoint(ref mScene, p2);

                        if (((Geometry.RobotPrintStroke)printStroke).mPoints.Count == 0)
                        {
                            printStroke = new Geometry.RobotPrintStroke(ref mScene);
                            ((Geometry.RobotPrintStroke)printStroke).addEdge(p1, p2);
                            printStrokeSN = new SceneNode("PrintStroke", ref printStroke, ref printStroke_m);
                            mScene.tableGeometry.add(ref printStrokeSN);
                        }
                        else
                        {
                            ((Geometry.RobotPrintStroke)printStroke).addEdge(p1, p2);
                            printStrokeSN.geometry = printStroke;
                        }
                    }
                    else
                    {
                        OpenTK.Vector3 p1 = new Vector3(s.data[1], s.data[2], s.data[3]);
                        p1 = UtilOld.platformToVRPoint(ref mScene, p1);
                        //((Geometry.GeometryStroke2)printStroke).addPoint(p1);
                        ((Geometry.RobotPrintStroke)printStroke).addEdge(((Geometry.RobotPrintStroke)printStroke).mPoints[((Geometry.RobotPrintStroke)printStroke).mPoints.Count - 1], p1);
                        printStrokeSN.geometry = printStroke;
                    }
                }
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.CutType:
                string guidStr = s.strData;
                Guid   delId   = new Guid(guidStr);
                UtilOld.removeRhinoObjectSceneNode(ref mScene, delId);
                //removePrintStroke and show the model again
                ((Geometry.RobotPrintStroke)printStroke).removePoint();
                //mScene.tableGeometry.remove(ref printStrokeSN); //already remove
                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))
                {
                    if (rhObj.Attributes.Name.Contains("aprint"))
                    {
                        SceneNode sn = mScene.BiDictionaryRhinoVR.GetByFirst(rhObj.Id);
                        Material.LambertianMaterial show_m = new Material.LambertianMaterial(((Material.LambertianMaterial)sn.material).mColor.R, ((Material.LambertianMaterial)sn.material).mColor.G, ((Material.LambertianMaterial)sn.material).mColor.B, .3f);
                        sn.material = show_m;
                    }
                }

                mScene.rhinoDoc.Views.Redraw();
                break;

            case SparrowHawkSignal.ESparrowHawkSigalType.EncoderType:

                //for rhino object
                OpenTK.Matrix4 currentRotation = mScene.platformRotation;
                float          theta           = (float)(s.data[0] / 360f * 2 * Math.PI);
                mScene.rhinoTheta = theta;
                Rhino.RhinoApp.WriteLine("Theta = " + theta);
                Matrix4.CreateRotationZ(-theta, out mScene.platformRotation);
                mScene.platformRotation.Transpose();

                //rotate Rhino objects
                OpenTK.Matrix4 rotMRhino = mScene.platformRotation * currentRotation.Inverted();
                mScene.transM = new Transform();
                for (int row = 0; row < 4; row++)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        mScene.transM[row, col] = rotMRhino[row, col];
                    }
                }

                /*
                 * 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))
                 * {
                 *  if (mScene.brepToSceneNodeDic.ContainsKey(rhObj.Id) && !rhObj.Attributes.Name.Contains("planeXY") && !rhObj.Attributes.Name.Contains("planeXZ")
                 *                                                          && !rhObj.Attributes.Name.Contains("planeYZ"))
                 *  {
                 *      //SceneNode sn = mScene.brepToSceneNodeDic[rhObj.Id];
                 *      //mScene.brepToSceneNodeDic.Remove(rhObj.Id);
                 *
                 *      Guid newGuid = mScene.rhinoDoc.Objects.Transform(rhObj.Id, mScene.transM, true);
                 *      Rhino.RhinoApp.WriteLine("transM " + mScene.transM.ToString());
                 *      mScene.rhinoDoc.Views.Redraw();
                 *
                 *      //mScene.brepToSceneNodeDic.Add(newGuid, sn);
                 *      //mScene.SceneNodeToBrepDic[sn.guid] = mScene.rhinoDoc.Objects.Find(newGuid);
                 *  }
                 *
                 * }*/

                //rotate the current interaction curve as well

                /*
                 * foreach(Curve iCurve in mScene.iCurveList)
                 * {
                 *  iCurve.Transform(transM);
                 *
                 * }
                 * if (mScene.peekInteraction().GetType() == typeof(Interaction.EditPoint2))
                 * {
                 *  mScene.peekInteraction().init();
                 * }*/

                break;
            }
        }