ActivateToolButton add_tool_button(Cockpit cockpit, string sName,
                                       float fHUDRadius, float dx, float dy,
                                       float fButtonRadius,
                                       Material bgMaterial, Material activeMaterial, toolInfo info)
    {
        ActivateToolButton button = new ActivateToolButton()
        {
            TargetScene = cockpit.Scene,
            ToolType    = info.identifier
        };

        button.CreateMeshIconButton(fButtonRadius, info.sMeshPath, bgMaterial, info.fMeshScaleFudge);
        HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
        button.Name = sName;

        if (info.identifier == "cancel")
        {
            button.OnClicked += (s, e) => {
                int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1;
                cockpit.Context.ToolManager.DeactivateTool((ToolSide)nSide);
                if (activeButtons[nSide] != null)
                {
                    activeButtons[nSide].SetBackgroundMaterial(bgMaterial);
                    activeButtons[nSide] = null;
                }
            };
        }
        else
        {
            button.OnClicked += (s, e) => {
                int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1;
                cockpit.Context.ToolManager.SetActiveToolType(info.identifier, (ToolSide)nSide);
                cockpit.Context.ToolManager.ActivateTool((ToolSide)nSide);
                if (activeButtons[nSide] != null)
                {
                    activeButtons[nSide].SetBackgroundMaterial(bgMaterial);
                }
                activeButtons[nSide] = button;
                button.SetBackgroundMaterial(activeMaterial);
            };
        }
        return(button);
    }
    public void Initialize(Cockpit cockpit)
    {
        cockpit.Name = "photoCockpit";


        // Configure how the cockpit moves

        cockpit.PositionMode = Cockpit.MovementMode.TrackPosition;
        // [RMS] use orientation mode to make cockpit follow view orientation.
        //  (however default widgets below are off-screen!)
        //cockpit.PositionMode = Cockpit.MovementMode.TrackOrientation;


        // Add some UI elements to the cockpit
        //   - cylinder & box buttons - double-click or drag/drop into scene
        //   - button to start and cancel draw-primitives tool


        float    fHUDRadius = 1.0f;
        Color    bgColor    = new Color(0.7f, 0.7f, 1.0f, 0.7f);
        Material bgMaterial = (bgColor.a == 1.0f) ?
                              MaterialUtil.CreateStandardMaterial(bgColor) : MaterialUtil.CreateTransparentMaterial(bgColor);
        Material primMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow);

        float fButtonsY       = -50.0f; // degrees
        float fButtonsSpacing = 15.0f;
        float fPrimitivesX    = -35.0f;

        DropPrimitiveButton cylinderButton =
            add_primitive_button(cockpit, "create_cylinder", fHUDRadius, fPrimitivesX, fButtonsY,
                                 PrimitiveType.Cylinder, SOTypes.Cylinder, 0.7f, bgMaterial, primMaterial,
                                 () => { return(new CylinderSO().Create(cockpit.Scene.DefaultSOMaterial)); });

        cockpit.AddUIElement(cylinderButton);

        DropPrimitiveButton boxButton =
            add_primitive_button(cockpit, "create_box", fHUDRadius, fPrimitivesX + fButtonsSpacing, fButtonsY,
                                 PrimitiveType.Cube, SOTypes.Box, 0.8f, bgMaterial, primMaterial,
                                 () => { return(new BoxSO().Create(cockpit.Scene.DefaultSOMaterial)); });

        cockpit.AddUIElement(boxButton);



        float fToolsX           = 35.0f;
        float fToolButtonRadius = 0.08f;

        // buttons for draw-primitive tool and cancel-tool button

        ActivateToolButton drawPrimButton = add_tool_button(cockpit, DrawSurfaceCurveTool.Identifier, fHUDRadius,
                                                            fToolsX - fButtonsSpacing, fButtonsY, fToolButtonRadius, bgMaterial, primMaterial,
                                                            new toolInfo()
        {
            identifier = DrawSurfaceCurveTool.Identifier, sMeshPath = "draw_primitive", fMeshScaleFudge = 1.2f
        });

        cockpit.AddUIElement(drawPrimButton);

        ActivateToolButton cancelButton = add_tool_button(cockpit, "cancel", fHUDRadius,
                                                          fToolsX, fButtonsY, fToolButtonRadius, bgMaterial, primMaterial,
                                                          new toolInfo()
        {
            identifier = "cancel", sMeshPath = "cancel", fMeshScaleFudge = 1.2f
        });

        cockpit.AddUIElement(cancelButton);



        // Configure interaction behaviors
        //   - below we add behaviors for mouse, gamepad, and spatial devices (oculus touch, etc)
        //   - keep in mind that Tool objects will register their own behaviors when active

        // setup key handlers (need to move to behavior...)
        cockpit.AddKeyHandler(new SampleKeyHandler(cockpit.Context));

        // these behaviors let us interact with UIElements (ie left-click/trigger, or either triggers for Touch)
        cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
        {
            Priority = 0
        });
        cockpit.InputBehaviors.Add(new VRGamepadUIBehavior(cockpit.Context)
        {
            Priority = 0
        });
        cockpit.InputBehaviors.Add(new VRSpatialDeviceUIBehavior(cockpit.Context)
        {
            Priority = 0
        });

        // spatial device does camera manipulation via Behavior
        //   (mouse/gamepad currently do not, but will in future!)
        cockpit.InputBehaviors.Add(new SpatialDeviceViewManipBehavior(cockpit)
        {
            Priority = 2
        });

        SpatialDeviceGrabBehavior grab = new SpatialDeviceGrabBehavior(cockpit)
        {
            StickMoveSpeed = 0.03f, Priority = 3
        };

        grab.OnBeginGrab += (sender, target) => {
            cockpit.Scene.Select(target, true);
        };
        grab.OnEndGrab += (sender, target) => {
            cockpit.Scene.ClearSelection();
        };
        cockpit.InputBehaviors.Add(grab);

        // selection / multi-selection behaviors
        cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context)
        {
            Priority = 10
        });
        cockpit.InputBehaviors.Add(new GamepadMultiSelectBehavior(cockpit.Context)
        {
            Priority = 10
        });
        cockpit.InputBehaviors.Add(new SpatialDeviceMultiSelectBehavior(cockpit.Context)
        {
            Priority = 10
        });

        // de-selection behaviors
        cockpit.InputBehaviors.Add(new MouseDeselectBehavior(cockpit.Context)
        {
            Priority = 999
        });
        cockpit.InputBehaviors.Add(new GamepadDeselectBehavior(cockpit.Context)
        {
            Priority = 999
        });
        cockpit.InputBehaviors.Add(new SpatialDeviceDeselectBehavior(cockpit.Context)
        {
            Priority = 999
        });


        cockpit.InputBehaviors.Add(new UndoShortcutBehavior(cockpit.Context)
        {
            Priority = 999
        });

        // screencap to your dropbox
        cockpit.OverrideBehaviors.Add(new ScreenCaptureBehavior()
        {
            Priority       = 0,
            ScreenshotPath = Environment.GetEnvironmentVariable("homepath") + "\\DropBox\\ScreenShots\\"
        });
    }
Exemplo n.º 3
0
    public void Initialize(Cockpit cockpit)
    {
        cockpit.Name = "sampleCockpit";

        // Configure how the cockpit moves
        cockpit.PositionMode = Cockpit.MovementMode.TrackPosition;


        // initialize layout
        BoxContainer screenContainer           = new BoxContainer(new Cockpit2DContainerProvider(cockpit));
        PinnedBoxes2DLayoutSolver screenLayout = new PinnedBoxes2DLayoutSolver(screenContainer);
        PinnedBoxesLayout         layout       = new PinnedBoxesLayout(cockpit, screenLayout)
        {
            StandardDepth = 1.0f
        };

        cockpit.AddLayout(layout, "2D", true);



        float pixelScale = cockpit.GetPixelScale();
        float buttonDiam = 150 * pixelScale;

        HUDElementList primitives_list = new HUDElementList()
        {
            Width     = 5 * buttonDiam,
            Height    = buttonDiam,
            Spacing   = 25 * pixelScale,
            Direction = HUDElementList.ListDirection.Horizontal
        };


        // Add some UI elements to the cockpit
        //   - cylinder & box buttons - double-click or drag/drop into scene
        //   - button to start and cancel draw-primitives tool

        Color    bgColor    = new Color(0.7f, 0.7f, 1.0f, 0.7f);
        Material bgMaterial = (bgColor.a == 1.0f) ?
                              MaterialUtil.CreateStandardMaterial(bgColor) : MaterialUtil.CreateTransparentMaterial(bgColor);
        Material primMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow);

        DropPrimitiveButton cylinderButton =
            create_primitive_button(cockpit, "create_cylinder", buttonDiam / 2,
                                    PrimitiveType.Cylinder, SOTypes.Cylinder, 0.7f, bgMaterial, primMaterial,
                                    () => { return(new CylinderSO().Create(cockpit.Scene.DefaultSOMaterial)); });

        primitives_list.AddListItem(cylinderButton);

        DropPrimitiveButton boxButton =
            create_primitive_button(cockpit, "create_box", buttonDiam / 2,
                                    PrimitiveType.Cube, SOTypes.Box, 0.8f, bgMaterial, primMaterial,
                                    () => { return(new BoxSO().Create(cockpit.Scene.DefaultSOMaterial)); });

        primitives_list.AddListItem(boxButton);


        primitives_list.Create();
        primitives_list.Name = "prims_button_bar";

        // align primitives_list to bottom-left
        layout.Add(primitives_list, new LayoutOptions()
        {
            Flags            = LayoutFlags.None,
            PinSourcePoint2D = LayoutUtil.BoxPointF(primitives_list, BoxPosition.BottomLeft),
            PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.BottomLeft, 25 * pixelScale * Vector2f.One)
        });



        HUDElementList tool_buttons_list = new HUDElementList()
        {
            Width     = 5 * buttonDiam,
            Height    = buttonDiam,
            Spacing   = 25 * pixelScale,
            HorzAlign = HorizontalAlignment.Right,
            Direction = HUDElementList.ListDirection.Horizontal
        };

        // buttons for draw-primitive tool and cancel-tool button

        ActivateToolButton drawPrimButton = create_tool_button(cockpit, DrawPrimitivesTool.Identifier,
                                                               buttonDiam / 2, bgMaterial, primMaterial,
                                                               new toolInfo()
        {
            identifier = DrawPrimitivesTool.Identifier, sMeshPath = "draw_primitive", fMeshScaleFudge = 1.2f
        });

        tool_buttons_list.AddListItem(drawPrimButton);

        ActivateToolButton cancelButton = create_tool_button(cockpit, "cancel",
                                                             buttonDiam / 2, bgMaterial, primMaterial,
                                                             new toolInfo()
        {
            identifier = "cancel", sMeshPath = "cancel", fMeshScaleFudge = 1.2f
        });

        tool_buttons_list.AddListItem(cancelButton);

        tool_buttons_list.Create();
        tool_buttons_list.Name = "tool_button_bar";

        // align tool_buttons_list to bottom-right
        layout.Add(tool_buttons_list, new LayoutOptions()
        {
            Flags            = LayoutFlags.None,
            PinSourcePoint2D = LayoutUtil.BoxPointF(tool_buttons_list, BoxPosition.BottomRight),
            PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.BottomRight, 25 * pixelScale * new Vector2f(-1, 1))
        });


        // Configure interaction behaviors
        //   - below we add behaviors for mouse, gamepad, and spatial devices (oculus touch, etc)
        //   - keep in mind that Tool objects will register their own behaviors when active

        // setup key handlers (need to move to behavior...)
        cockpit.AddKeyHandler(new BasicShapesDemo_KeyHandler(cockpit.Context));

        // these behaviors let us interact with UIElements (ie left-click/trigger, or either triggers for Touch)
        cockpit.InputBehaviors.Add(new Mouse2DCockpitUIBehavior(cockpit.Context)
        {
            Priority = 0
        });
        cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
        {
            Priority = 1
        });

        // selection / multi-selection behaviors
        cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context)
        {
            Priority = 10
        });
        cockpit.InputBehaviors.Add(new GamepadMultiSelectBehavior(cockpit.Context)
        {
            Priority = 10
        });

        // left click-drag to tumble, and left click-release to de-select
        cockpit.InputBehaviors.Add(new MouseClickDragSuperBehavior()
        {
            Priority     = 100,
            DragBehavior = new MouseViewRotateBehavior(cockpit.Context)
            {
                Priority = 100, RotateSpeed = 3.0f
            },
            ClickBehavior = new MouseDeselectBehavior(cockpit.Context)
            {
                Priority = 999
            }
        });

        // also right-click-drag to tumble
        cockpit.InputBehaviors.Add(new MouseViewRotateBehavior(cockpit.Context)
        {
            Priority  = 100, RotateSpeed = 3.0f,
            ActivateF = MouseBehaviors.RightButtonPressedF, ContinueF = MouseBehaviors.RightButtonDownF
        });

        // middle-click-drag to pan
        cockpit.InputBehaviors.Add(new MouseViewPanBehavior(cockpit.Context)
        {
            Priority  = 100, PanSpeed = 1.0f,
            ActivateF = MouseBehaviors.MiddleButtonPressedF, ContinueF = MouseBehaviors.MiddleButtonDownF
        });

        cockpit.OverrideBehaviors.Add(new MouseWheelZoomBehavior(cockpit)
        {
            Priority = 100, ZoomScale = 10.0f
        });

        // touch input
        cockpit.InputBehaviors.Add(new TouchUIBehavior(cockpit.Context)
        {
            Priority = 1
        });
        cockpit.InputBehaviors.Add(new Touch2DCockpitUIBehavior(cockpit.Context)
        {
            Priority = 0
        });
        cockpit.InputBehaviors.Add(new TouchViewManipBehavior(cockpit.Context)
        {
            Priority = 999, TouchZoomSpeed = 0.1f, TouchPanSpeed = 0.03f
        });
    }