Beispiel #1
0
        public override void draw(bool isTop)
        {
            if (!isTop)
            {
                return;
            }

            // Clean this monstrosity
            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);

            if (drawnType != DrawnType.In3D)
            {
                UtilOld.rayCasting(controller_pRhino, direction, ref rayCastingObjs, ref projectP, out targetPRhObjID);
            }
            else
            {
                projectP = controller_pRhino;
            }

            //only snap for the first drawing point
            if (currentState != State.DRAW && snapPointsList.Count > 0)
            {
                if (UtilOld.snapToPoints(ref projectP, ref snapPointsList) != -1)
                {
                    isSnap = true;
                    snapPointSN.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    isSnap = false;
                    snapPointSN.material = new Material.SingleColorMaterial(0, 1, 0, 1);
                }
            }

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

            if (drawnType != DrawnType.In3D)
            {
                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(projectPVR);
                t.Transpose();
                drawPoint.transform = t;
                if (targetPRhObjID != Guid.Empty)
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 0);
                }
            }



            //moving XYZ planes
            if (currentState == State.MOVEPLANE)
            {
                OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)) - UtilOld.RhinoToOpenTKPoint(moveControlerOrigin);

                float translate    = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;
                float relTranslate = translate - lastTranslate;
                lastTranslate = translate;

                Matrix4 transM = Matrix4.CreateTranslation(new Vector3(relTranslate * (float)planeNormal.X, relTranslate * (float)planeNormal.Y, relTranslate * (float)planeNormal.Z));
                transM.Transpose();
                UtilOld.updateRhinoObjectSceneNode(ref mScene, ref movePlaneRef, UtilOld.OpenTKToRhinoTransform(transM));
            }



            if (currentState != State.DRAW)
            {
                return;
            }
            else
            {
                //checking the projectPoint is valid
                if (drawnType != DrawnType.In3D && targetPRhObjID == Guid.Empty)
                {
                    return;
                }
            }

            //drawing curve section belows
            if (shouldSnap && ((Geometry.GeometryStroke)stroke_g).mNumPoints == 0)
            {
                ((Geometry.GeometryStroke)stroke_g).addPoint(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(snapPointsList[0])));
            }

            ((Geometry.GeometryStroke)stroke_g).addPoint(projectPVR);
            rhinoCurvePoints.Add(projectP);

            if (((Geometry.GeometryStroke)stroke_g).mNumPrimitives == 1)
            {
                strokeSN = new SceneNode("Stroke", ref stroke_g, ref stroke_m);
                UtilOld.addSceneNode(ref mScene, ref strokeSN);
            }

            //create rhino curve for comoputing length of the curve
            if (rhinoCurvePoints.Count == 2)
            {
                if (shouldSnap)
                {
                    //make sure the first point is the snap point if necessary
                    if (UtilOld.computePointDistance(UtilOld.RhinoToOpenTKPoint(rhinoCurvePoints[0]), UtilOld.RhinoToOpenTKPoint(snapPointsList[0])) != 0)
                    {
                        rhinoCurvePoints.Insert(0, snapPointsList[0]);
                    }
                }
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
            }
            else if (rhinoCurvePoints.Count > 2)
            {
                double length1 = rhinoCurve.GetLength();
                rhinoCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(rhinoCurvePoints.ToArray(), 3);
                double length2 = rhinoCurve.GetLength();
                displacement = displacement + (float)Math.Abs(length2 - length1);

                //TODO-Debug why it failed
                //rhinoCurve = rhinoCurve.Extend(Rhino.Geometry.CurveEnd.End, Rhino.Geometry.CurveExtensionStyle.Line, rhinoCurvePoints[rhinoCurvePoints.Count - 1]);

                //dynamic render model
                //TODO: finding the right curve
                if (dynamicRender != "none" && backgroundStart == false && displacement > 10)
                {
                    backgroundStart = true;
                    R = d.BeginInvoke(new AsyncCallback(modelCompleted), null);
                }
            }
        }
Beispiel #2
0
        public override void draw(bool isTop)
        {
            if (!isTop)
            {
                return;
            }


            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);

            if (drawnType != DrawnType.In3D)
            {
                UtilOld.rayCasting(controller_pRhino, direction, ref rayCastingObjs, ref projectP, out targetPRhObjID);
            }
            else
            {
                projectP = controller_pRhino;
            }

            //TODO-only snap for the first drawing point
            if (pointMarkers.Count == 0 && targetPRhObjID != Guid.Empty)
            {
                computeContourCurve();
                UtilOld.snapToPoints(ref projectP, ref snapPointsList);
            }

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

            if (drawnType != DrawnType.In3D)
            {
                OpenTK.Matrix4 t = OpenTK.Matrix4.CreateTranslation(projectPVR);
                t.Transpose();
                drawPoint.transform = t;
                if (targetPRhObjID != Guid.Empty)
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 1);
                }
                else
                {
                    drawPoint.material = new Material.SingleColorMaterial(1, 1, 1, 0);
                }
            }



            //moving XYZ planes
            if (currentState == State.MOVEPLANE)
            {
                OpenTK.Vector3 controllerVector = UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)) - UtilOld.RhinoToOpenTKPoint(moveControlerOrigin);

                float translate    = OpenTK.Vector3.Dot(controllerVector, UtilOld.RhinoToOpenTKVector(planeNormal)) / (float)planeNormal.Length;
                float relTranslate = translate - lastTranslate;
                lastTranslate = translate;

                Matrix4 transM = Matrix4.CreateTranslation(new Vector3(relTranslate * (float)planeNormal.X, relTranslate * (float)planeNormal.Y, relTranslate * (float)planeNormal.Z));
                transM.Transpose();
                UtilOld.updateRhinoObjectSceneNode(ref mScene, ref movePlaneRef, UtilOld.OpenTKToRhinoTransform(transM));
            }
        }