Ejemplo n.º 1
0
        override protected void BuildGizmo()
        {
            gizmo.SetName("SnapDragGizmo");

            float fAlpha = 0.5f;

            srcMaterial      = MaterialUtil.CreateTransparentMaterial(ColorUtil.SelectionGold, fAlpha);
            srcHoverMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold);

            // generate snap target set
            Snaps = SnapSet.CreateStandard(Scene);
            Snaps.IgnoreSet.AddRange(this.targets);
            Snaps.PreRender(parentScene.ActiveCamera.GetPosition());

            // [TODO] this should iterate through targets...

            Debug.Assert(this.targets.Count == 1);
            // [TODO] should maybe be using GetBoundingBox now??
            Bounds b = this.targets[0].GetLocalBoundingBox();
            float  h = b.extents[1];

            // object origin
            add_snap_source(Vector3.zero, "obj_origin", Snaps);
            add_snap_source(Vector3.zero + h * Vector3.up, "obj_top", Snaps);
            add_snap_source(Vector3.zero - h * Vector3.up, "obj_base", Snaps);

            gizmo.Hide();
        }
Ejemplo n.º 2
0
        public SnapDrawPrimitivesTool(FScene scene)
        {
            this.scene = scene;

            behaviors = new InputBehaviorSet();

            // TODO is this where we should be doing this??
            behaviors.Add(
                new SnapDrawPrimitivesTool_MouseBehavior(scene.Context)
            {
                Priority = 5
            });
            behaviors.Add(
                new SnapDrawPrimitivesTool_SpatialDeviceBehavior(scene.Context)
            {
                Priority = 5
            });

            // generate snap target set
            Snaps = SnapSet.CreateStandard(scene);
            Snaps.EnableSnapSegments = true;

            // shut off transform gizmo
            scene.Context.TransformManager.PushOverrideGizmoType(TransformManager.NoGizmoType);

            scene.SelectionChangedEvent += Scene_SelectionChangedEvent;
            // initialize active set with input selection
            Scene_SelectionChangedEvent(null, null);
        }
Ejemplo n.º 3
0
        public RevolveTool(FScene scene, List <SceneObject> targets)
        {
            this.scene = scene;

            behaviors = new InputBehaviorSet();

            // TODO is this where we should be doing this??
            behaviors.Add(
                new RevolveTool_MouseBehavior(scene.Context)
            {
                Priority = 5
            });
            behaviors.Add(
                new RevolveTool_SpatialDeviceBehavior(scene.Context)
            {
                Priority = 5
            });

            // generate snap target set
            Snaps = SnapSet.CreateStandard(scene);
            Snaps.EnableSnapSegments = false;
            Snaps.EnableSnapPoints   = false;

            // shut off transform gizmo
            //scene.ActiveController.TransformManager.SetOverrideGizmoType(TransformManager.NoGizmoType);

            scene.SelectionChangedEvent += Scene_SelectionChangedEvent;
            // initialize active set with input selection
            Scene_SelectionChangedEvent(null, null);


            if (targets != null)
            {
                if (targets.Count == 2 && targets[0] is PolyCurveSO && targets[1] is PolyCurveSO)
                {
                    PolyCurveSO curveSO = targets[0] as PolyCurveSO;
                    PolyCurveSO axisSO  = targets[1] as PolyCurveSO;
                    set_curve(curveSO, true);
                    set_axis(axisSO, true);
                }
                else
                {
                    SceneObject foundCurveSO = targets.Find((so) => { return(so is PolyCurveSO); });
                    if (foundCurveSO != null)
                    {
                        set_curve(foundCurveSO as PolyCurveSO, false);
                    }
                    SceneObject otherSO = targets.Find((so) => { return(!(so is PolyCurveSO)); });
                    if (otherSO != null)
                    {
                        set_axis(otherSO, false);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // initializes snap set with default materials and known generators
        static public SnapSet CreateStandard(FScene scene)
        {
            SnapSet s = new SnapSet(scene);
            var     genVisibleMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.5f);
            var     genHiddenMaterial  = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.2f);

            s.Generators.Add(
                new PrimitiveSnapGenerator(genVisibleMaterial, genHiddenMaterial));
            s.Generators.Add(
                new CurveSnapGenerator(genVisibleMaterial, genHiddenMaterial));
            return(s);
        }
Ejemplo n.º 5
0
        void add_snap_source(Vector3 vPosition, string name, SnapSet targets)
        {
            fMeshGameObject go = AppendMeshGO(name,
                                              UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere), srcMaterial, gizmo);

            go.SetLocalScale(0.5f * Vector3f.One);
            Frame3f sourceFrame = new Frame3f(vPosition);

            UnityUtil.SetGameObjectFrame(go, sourceFrame, CoordSpace.ObjectCoords);
            Widgets[go] = new SnapDragSourceWidget(this, this.parentScene, targets)
            {
                RootGameObject = go, StandardMaterial = srcMaterial, HoverMaterial = srcHoverMaterial,
                SourceFrameL   = sourceFrame
            };
        }
Ejemplo n.º 6
0
        public RemoteGrabBehavior(Cockpit cockpit)
        {
            this.cockpit = cockpit;

            EnableSnapping = true;

            // build snap target set
            Snaps      = SnapSet.CreateStandard(cockpit.Scene);
            SnapHelper = new PreRenderHelper("remote_grab_snap_helper")
            {
                PreRenderF = () => { Snaps.PreRender(cockpit.ActiveCamera.GetPosition()); }
            };

            cockpit.Scene.SelectionChangedEvent += ActiveScene_SelectionChangedEvent;
            cockpit.Scene.ChangedEvent          += ActiveScene_ChangedEvent;
        }
Ejemplo n.º 7
0
        // returns snapped world-frame, or input frame if no snap
        public Frame3f UpdateSnapW(Frame3f fSourceFrameW, SnapSet Snaps)
        {
            FScene scene        = targetSO.GetScene();
            float  fSnapRadiusW = VRUtil.GetVRRadiusForVisualAngle(fSourceFrameW.Origin,
                                                                   scene.ActiveCamera.GetPosition(), SnapThreshVisualAngleDeg);
            float fSnapRadiusS = fSnapRadiusW / scene.GetSceneScale();

            // fSourceFrameW in Scene coordinates
            Frame3f fSourceS = scene.ToSceneFrame(fSourceFrameW);

            SnapResult best_snap    = null;
            float      fNearest     = float.MaxValue;
            Frame3f    fBestSourceL = Frame3f.Identity;

            // snapframes are stored in local coords relative to object
            foreach (Frame3f fPointFrameL in snapFramesL)
            {
                // convert local-coord snap frame into scene coords
                Frame3f fPointFrameS = fSourceS.FromFrame(fPointFrameL);

                SnapResult snap = Snaps.FindNearestSnapPointS(fPointFrameS, fSnapRadiusS);
                if (snap != null)
                {
                    float d = ((Vector3f)snap.FrameS.Origin - fPointFrameS.Origin).Length;
                    if (d < fNearest)
                    {
                        fNearest     = d;
                        fBestSourceL = fPointFrameL;
                        best_snap    = snap;
                    }
                }
            }

            snapState.UpdateState(best_snap, fBestSourceL);
            if (snapState.IsSnapped)
            {
                SnapResult useSnap    = snapState.ActiveSnapTarget;
                Frame3f    useSourceL = (Frame3f)snapState.ActiveSnapData;

                if (SnapOrientation)
                {
                    // compute min-rotation frame, then align origins
                    Frame3f fAlignedSourceS =
                        Frame3f.SolveMinRotation(fSourceS, useSnap.FrameS);
                    Frame3f  fPointFrameS = fAlignedSourceS.FromFrame(useSourceL);
                    Vector3f deltaS       = (Vector3f)useSnap.FrameS.Origin - fPointFrameS.Origin;
                    snapFrameS = fAlignedSourceS.Translated(deltaS);


                    //// this is tricky...we have an object-space frame useSourceL, which
                    ////  we want to snap to a scene-space frame usePoint.FrameS. So we need
                    ////  to shift origin of that frame by -useSourceL_in_FrameS!
                    //snapFrameS = usePoint.FrameS.Translated(
                    //    -usePoint.FrameS.FromFrameV(useSourceL.Origin));
                }
                else
                {
                    // translation-only snap - find shift in scene space, apply to input source frame
                    Frame3f  fPointFrameS = fSourceS.FromFrame(useSourceL);
                    Vector3f deltaS       = (Vector3f)useSnap.FrameS.Origin - fPointFrameS.Origin;
                    snapFrameS = fSourceS.Translated(deltaS);
                }

                // now convert to world frame for return
                return(scene.ToWorldFrame(snapFrameS));
            }

            return(fSourceFrameW);
        }
Ejemplo n.º 8
0
            public void update(Frame3f handF, SnapSet snap)
            {
                curHandF = handF;

                // [RMS] this function updates the position of object based on hand frame
                //  Not clear how this should work, there are lots of options...

                // [1] scaled relative motion of hand inherited by object  (lags ray though)
                //Vector3 dt = startHandF.ToFrameP(handF.Origin);
                //dt *= 10.0f;
                //Frame3 fNew = new Frame3(startObjFW);
                //fNew.Origin += dt;

                // [2] object stays on ray, inherits a bit of xform
                //   - resulting orientation is weird. works well for rotate in-place around ray,
                //     but up/down/left/right tilts are impossible w/o moving object
                Frame3f fNew = handF.FromFrame(this.startObjRelF);

                if (RotationSpeed != 1.0f)
                {
                    fNew.Rotation = Quaternionf.Slerp(startObjFW.Rotation, fNew.Rotation, RotationSpeed);
                }
                if (TranslationSpeed != 1.0f)
                {
                    fNew.Origin = Vector3f.Lerp(startObjFW.Origin, fNew.Origin, TranslationSpeed);
                }

                // [3] object stays on ray but no rotation
                //   - weird if you rotate left/right, because distance stays same but it
                //     keeps pointing in same direction
                //   - we have gizmo for this kind of translation.
                //Frame3 fNew = handF.FromFrame(this.startObjRelF);
                //fNew.Rotation = startObjFW.Rotation;

                // [4] object stays in place, rotate by hand rotation
                //   - pretty hard to control, but would be good for approx orienting...
                //   - definitely needs damping!!
                //Frame3 fNew = startObjFW;
                //Quaternion relative = handF.Rotation * Quaternion.Inverse(startHandF.Rotation);
                //fNew.Rotation = relative * fNew.Rotation;

                // apply stick rotation  DOESN"T WORK
                //Quaternion stickY = Quaternion.AngleAxis(stickDelta[1], startHandF.X);
                //fNew.Rotation = fNew.Rotation * stickY;

                // shift in/out along hand-ray by Z
                fNew.Origin += 0.1f * stickDelta[1] * handF.Z * cockpit.Scene.GetSceneScale();

                curHandTargetF = fNew;
                curUseTargetF  = new Frame3f(curHandTargetF);

                if (snap != null)
                {
                    if (snapSolver == null)
                    {
                        snapSolver = new DynamicSnapSolver(grabbedSO);
                    }
                    snapSolver.SnapOrientation =
                        (cockpit.Context.TransformManager.ActiveFrameType == FrameType.LocalFrame);
                    curUseTargetF = snapSolver.UpdateSnapW(curUseTargetF, snap);
                }

                // update so
                grabbedSO.SetLocalFrame(curUseTargetF, CoordSpace.WorldCoords);
            }
Ejemplo n.º 9
0
 public SnapDragSourceWidget(ITransformGizmo parent, FScene scene, SnapSet targets)
 {
     this.parent  = parent;
     this.scene   = scene;
     this.Targets = targets;
 }