void update_capture(InputState input, InputState lastInput, CaptureSide eSide)
        {
            Frame3f handFrameW = (eSide == CaptureSide.Left) ? input.LeftHandFrame : input.RightHandFrame;
            Frame3f newPosS    = SceneTransforms.WorldToScene(context.Scene, handFrameW);

            Vector3f start = startSocketFrameS.ToFrameP(startPosS.Origin);
            Vector3f cur   = startSocketFrameS.ToFrameP(newPosS.Origin);

            float dy = cur.y - start.y;

            start.y = cur.y = 0;
            float dx = cur.Length - start.Length;

            if (op is EnclosedRegionOffsetOp)
            {
                EnclosedRegionOffsetOp deformOp = op as EnclosedRegionOffsetOp;
                deformOp.PushPullDistance = startParam0 + 0.1 * dx;
            }
            else if (op is EnclosedRegionSmoothOp)
            {
                EnclosedRegionSmoothOp deformOp = op as EnclosedRegionSmoothOp;
                deformOp.OffsetDistance = startParam0 + 0.1 * dx;
                deformOp.SmoothAlpha    = startParam1 + 0.1 * dy;
            }
            else if (op is PlaneBandExpansionOp)
            {
                PlaneBandExpansionOp deformOp = op as PlaneBandExpansionOp;
                deformOp.PushPullDistance = startParam0 + 0.1 * dx;
                deformOp.BandDistance     = startParam1 + 0.25 * dy;
            }



            lastPosS = newPosS;
        }
        void begin_capture(InputState input, CaptureSide eSide)
        {
            Frame3f handFrameW = (eSide == CaptureSide.Left) ? input.LeftHandFrame : input.RightHandFrame;

            lastPosS          = SceneTransforms.WorldToScene(context.Scene, handFrameW);
            startPosS         = lastPosS;
            startSocketFrameS = legSO.GetLocalFrame(CoordSpace.SceneCoords);
            startAxisS        = new Line3f(startSocketFrameS.Origin, startSocketFrameS.Y);


            if (op is EnclosedRegionOffsetOp)
            {
                EnclosedRegionOffsetOp deformOp = op as EnclosedRegionOffsetOp;
                startParam0 = deformOp.PushPullDistance;
            }
            else if (op is EnclosedRegionSmoothOp)
            {
                EnclosedRegionSmoothOp deformOp = op as EnclosedRegionSmoothOp;
                startParam0 = deformOp.OffsetDistance;
                startParam1 = deformOp.SmoothAlpha;
            }
            else if (op is PlaneBandExpansionOp)
            {
                PlaneBandExpansionOp deformOp = op as PlaneBandExpansionOp;
                startParam0 = deformOp.PushPullDistance;
                startParam1 = deformOp.BandDistance;
            }
        }
示例#3
0
        /// <summary>
        /// Serialize data model. THIS IS A DEMO!!
        /// </summary>
        protected virtual void StoreDataModel(XmlWriter writer)
        {
            writer.WriteStartElement("DataModel");

            if (OG.Leg != null)
            {
                // iterate over deformation operators and store them
                // elements are [so,op]
                foreach (var pair in OG.Leg.OperatorObjectPairs())
                {
                    if (pair.Item2 is EnclosedRegionOffsetOp)
                    {
                        EnclosedRegionOffsetOp op = pair.Item2 as EnclosedRegionOffsetOp;
                        writer.WriteStartElement("LegDeformOp");
                        writer.WriteAttributeString("OpType", op.GetType().ToString());
                        writer.WriteAttributeString("SceneObjectUUID", pair.Item1.UUID);
                        writer.WriteAttributeString("Offset", op.PushPullDistance.ToString());
                        writer.WriteEndElement();
                    }
                    else if (pair.Item2 is EnclosedRegionSmoothOp)
                    {
                        EnclosedRegionSmoothOp op = pair.Item2 as EnclosedRegionSmoothOp;
                        writer.WriteStartElement("LegDeformOp");
                        writer.WriteAttributeString("OpType", op.GetType().ToString());
                        writer.WriteAttributeString("SceneObjectUUID", pair.Item1.UUID);
                        writer.WriteAttributeString("Offset", op.OffsetDistance.ToString());
                        writer.WriteAttributeString("Smooth", op.SmoothAlpha.ToString());
                        writer.WriteEndElement();
                    }
                    else if (pair.Item2 is PlaneBandExpansionOp)
                    {
                        PlaneBandExpansionOp op = pair.Item2 as PlaneBandExpansionOp;
                        writer.WriteStartElement("LegDeformOp");
                        writer.WriteAttributeString("OpType", op.GetType().ToString());
                        writer.WriteAttributeString("SceneObjectUUID", pair.Item1.UUID);
                        writer.WriteAttributeString("Extent", op.BandDistance.ToString());
                        writer.WriteAttributeString("Offset", op.PushPullDistance.ToString());
                        writer.WriteAttributeString("Origin", op.Origin.ToString());
                        writer.WriteAttributeString("Normal", op.Normal.ToString());
                        writer.WriteEndElement();
                    }
                    else if (pair.Item2 is LengthenOp)
                    {
                        LengthenOp op = pair.Item2 as LengthenOp;
                        writer.WriteStartElement("LegDeformOp");
                        writer.WriteAttributeString("OpType", op.GetType().ToString());
                        writer.WriteAttributeString("SceneObjectUUID", pair.Item1.UUID);
                        writer.WriteAttributeString("Distance", op.LengthenDistance.ToString());
                        writer.WriteEndElement();
                    }
                }


                // what else?!?
            }

            writer.WriteEndElement();
        }
示例#4
0
 static void add_input_behaviors_for_mouse(BaseSO so, IVectorDisplacementSourceOp op)
 {
     if (op is EnclosedRegionOffsetOp)
     {
         EnclosedRegionOffsetOp deformOp = op as EnclosedRegionOffsetOp;
         so.InputBehaviors.Add(
             new RightMouseClickDragBehavior()
         {
             WantsCaptureF  = (input) => { return(input.bCtrlKeyDown); },
             UpdateCaptureF = (input, lastInput) => {
                 deformOp.PushPullDistance += input.vMouseDelta2D.x * 0.1;
             }
         });
     }
     else if (op is EnclosedRegionSmoothOp)
     {
         EnclosedRegionSmoothOp deformOp = op as EnclosedRegionSmoothOp;
         so.InputBehaviors.Add(
             new RightMouseClickDragBehavior()
         {
             WantsCaptureF  = (input) => { return(input.bCtrlKeyDown); },
             UpdateCaptureF = (input, lastInput) => {
                 deformOp.OffsetDistance += input.vMouseDelta2D.x * 0.1;
                 deformOp.SmoothAlpha    += input.vMouseDelta2D.y * 0.1;
             }
         });
     }
     else if (op is PlaneBandExpansionOp)
     {
         PlaneBandExpansionOp deformOp = op as PlaneBandExpansionOp;
         so.InputBehaviors.Add(
             new RightMouseClickDragBehavior()
         {
             WantsCaptureF  = (input) => { return(input.bCtrlKeyDown); },
             UpdateCaptureF = (input, lastInput) => {
                 deformOp.PushPullDistance += input.vMouseDelta2D.x * 0.1;
                 deformOp.BandDistance     += input.vMouseDelta2D.y * 0.1;
             }
         });
     }
 }
示例#5
0
        public IVectorDisplacementSourceOp AppendPlaneBandExpansion(PlaneIntersectionCurveSO Source)
        {
            Frame3f deformF = Frame3f.Identity;

            deformF = SceneTransforms.TransformTo(deformF, Source, leg);

            PlaneBandExpansionOp deformOp = new PlaneBandExpansionOp()
            {
                Origin           = deformF.Origin,
                Normal           = deformF.Y,
                BandDistance     = 15.0f,
                PushPullDistance = -1.0f,
                MeshSource       = SOMeshSource
            };

            Combiner.Append(deformOp);
            SO_Op.Add(Source, deformOp);

            OnDeformationAdded?.Invoke(Source, deformOp);

            return(deformOp);
        }
示例#6
0
        /// <summary>
        /// adds an expand/contract-type plane/leg intersection thing at the given frame
        /// </summary>
        public static void EmitOffsetBandFromTool(SceneObject targetLegSO, Frame3f startFrameS, Frame3f endFrameS)
        {
            Frame3f midFrame = new Frame3f((startFrameS.Origin + endFrameS.Origin) * 0.5f);
            PlaneIntersectionCurveSO curveSO = PlaneIntersectionCurveSO.CreateFromPlane(
                targetLegSO as DMeshSO, midFrame, OrthogenMaterials.PlaneCurveMaterial,
                targetLegSO.GetScene(), OrthogenUI.CurveOnSurfaceOffsetTol);

            curveSO.Name = "PlaneBandExpansion";
            curveSO.RootGameObject.SetLayer(OrthogenMaterials.CurvesLayer);

            // create and associate deformation op
            PlaneBandExpansionOp deformOp = OG.Leg.AppendPlaneBandExpansion(curveSO) as PlaneBandExpansionOp;

            deformOp.BandDistance = startFrameS.Origin.Distance(endFrameS.Origin) * 0.5;


            OG.Model.RegisterDeleteSOAction(curveSO, MakeDeleteLegDeformationAction(deformOp));
            OG.Model.RegisterSelectSOAction(curveSO, MakeSelectLegDeformationAction(deformOp));

            // [RMS] this is called at end
            OG.Context.RegisterNextFrameAction(() => {
                OG.Scene.Select(curveSO, true);
            });
        }
示例#7
0
        public bool HandleShortcuts()
        {
            bool bShiftDown = Input.GetKey(KeyCode.LeftShift);
            bool bCtrlDown  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

            // ESCAPE CLEARS ACTIVE TOOL OR SELECTION
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (context.ToolManager.HasActiveTool(0) || context.ToolManager.HasActiveTool(1))
                {
                    OGActions.CancelCurrentTool();
                }
                else if (context.Scene.Selected.Count > 0)
                {
                    context.Scene.ClearSelection();
                }
                return(true);


                // ENTER AND LETTER A APPLY CURRENT TOOL IF POSSIBLE
            }
            else if (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.A))
            {
                if (OGActions.CanAcceptCurrentTool())
                {
                    OGActions.AcceptCurrentTool();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Delete))
            {
                if (context.Scene.Selected.Count == 1)
                {
                    DeleteSOChange change = new DeleteSOChange()
                    {
                        scene = context.Scene, so = context.Scene.Selected[0]
                    };
                    context.Scene.History.PushChange(change, false);
                }
                return(true);


                // CENTER TARGET (??)
            }
            else if (Input.GetKeyUp(KeyCode.C))
            {
                Ray3f     cursorRay = context.MouseController.CurrentCursorWorldRay();
                AnyRayHit hit       = null;
                if (context.Scene.FindSceneRayIntersection(cursorRay, out hit))
                {
                    context.ActiveCamera.Manipulator().ScenePanFocus(context.Scene, context.ActiveCamera, hit.hitPos, true);
                }
                return(true);

                // TOGGLE FRAME TYPE
            }
            else if (Input.GetKeyUp(KeyCode.F))
            {
                FrameType eCur = context.TransformManager.ActiveFrameType;
                context.TransformManager.ActiveFrameType = (eCur == FrameType.WorldFrame)
                    ? FrameType.LocalFrame : FrameType.WorldFrame;
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                return(true);

                // VISIBILITY  (V HIDES, SHIFT+V SHOWS)
            }
            else if (Input.GetKeyUp(KeyCode.V))
            {
                // show/hide (should be abstracted somehow?? instead of directly accessing GOs?)
                if (bShiftDown)
                {
                    foreach (SceneObject so in context.Scene.SceneObjects)
                    {
                        so.RootGameObject.Show();
                    }
                }
                else
                {
                    foreach (SceneObject so in context.Scene.Selected)
                    {
                        so.RootGameObject.Hide();
                    }
                    context.Scene.ClearSelection();
                }
                return(true);

                // UNDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Z))
            {
                context.Scene.History.InteractiveStepBack();
                return(true);

                // REDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Y))
            {
                context.Scene.History.InteractiveStepForward();
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Backspace))
            {
                if (OG.IsInState(OGWorkflow.SocketState) && OG.CanTransitionToState(OGWorkflow.RectifyState))
                {
                    OG.TransitionToState(OGWorkflow.RectifyState);
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow))
            {
                float sign = Input.GetKeyUp(KeyCode.UpArrow) ? 1 : -1;
                if (OG.LastActiveModelingOp != null)
                {
                    if (OG.LastActiveModelingOp is PlaneBandExpansionOp)
                    {
                        PlaneBandExpansionOp deform = OG.LastActiveModelingOp as PlaneBandExpansionOp;
                        deform.BandDistance = MathUtil.Clamp(deform.BandDistance + sign * 2.0f, 10.0f, 1000.0f);
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionSmoothOp)
                    {
                        EnclosedRegionSmoothOp deform = OG.LastActiveModelingOp as EnclosedRegionSmoothOp;
                        deform.OffsetDistance += sign * 0.1f;
                    }
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
            {
                float sign = Input.GetKeyUp(KeyCode.RightArrow) ? 1 : -1;
                if (OG.LastActiveModelingOp != null)
                {
                    if (OG.LastActiveModelingOp is PlaneBandExpansionOp)
                    {
                        PlaneBandExpansionOp deform = OG.LastActiveModelingOp as PlaneBandExpansionOp;
                        deform.PushPullDistance += sign * 0.25f;
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionOffsetOp)
                    {
                        EnclosedRegionOffsetOp deform = OG.LastActiveModelingOp as EnclosedRegionOffsetOp;
                        deform.PushPullDistance += sign * 0.25f;
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionSmoothOp)
                    {
                        EnclosedRegionSmoothOp deform = OG.LastActiveModelingOp as EnclosedRegionSmoothOp;
                        deform.SmoothAlpha += sign * 0.1f;
                    }
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.LeftBracket) || Input.GetKeyUp(KeyCode.RightBracket))
            {
                SculptCurveTool tool = OG.ActiveToolAs <SculptCurveTool>();
                if (tool != null)
                {
                    float  fSign    = Input.GetKeyUp(KeyCode.LeftBracket) ? -1 : 1;
                    double fRadiusS = tool.Radius.SceneValue;
                    fRadiusS    = MathUtil.Clamp(fRadiusS + 2.5 * fSign, 5.0, 100.0);
                    tool.Radius = fDimension.Scene(fRadiusS);
                }
                return(true);
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Q))
            {
                FPlatform.QuitApplication();
                return(true);
            }
            else
            {
                return(false);
            }
        }