Exemple #1
0
        /// <summary>
        /// Show the Toast widget with an animated fade in. The widget will fade out
        /// after Duration seconds, unless the user hovers over it, in which case it
        /// will stay until they end the hover.
        /// </summary>
        public void Show(Cockpit cockpit, float fDuration, float fFadeInOut = 0.25f)
        {
            AlphaFade = 0.0f;

            hovering  = false;
            disappear = false;

            // if this goes true, toast will begin animated-fade on next frame
            dismiss = false;

            // we register a basic animator that just watches for dismiss=true and
            // when that happens we fade out and remove the toast
            cockpit.HUDAnimator.Register(
                new GenericAnimatable(() => {
                if (dismiss)
                {
                    FUtil.SafeSendEvent(this.OnDismissed, this, EventArgs.Empty);
                    HUDUtil.AnimatedDimiss_Cockpit(this, cockpit, true, (disappear) ? 0.001f : fFadeInOut);
                    if (dismiss_timer != null)
                    {
                        dismiss_timer.Dispose();
                        dismiss_timer = null;
                    }
                    return(true);
                }
                return(false);
            })
                );


            // timer event that is called after the initial duration, and then ever
            // couple hundred MS to check that hover ended.
            // This is called from a Timer, which runs in a separate thread, and hence
            // we cannot manipulate the scene in this function
            // TODO: couldn't we just do this in animator above??
            Action timer_elapsed = () => {
                if (hovering)
                {
                    dismiss_timer.Interval = 300;
                    dismiss_timer.Start();
                }
                else
                {
                    dismiss = true;
                }
            };


            // ok, this kicks everything off - we do animated transition to show ourself,
            // and then start a timer that waits the initial duration
            HUDUtil.AnimatedShow(this, fFadeInOut, () => {
                dismiss_timer          = new Timer(fDuration * 1000);
                dismiss_timer.Elapsed += (o, e) => {
                    timer_elapsed();
                };
                dismiss_timer.Enabled = true;
            });


            if (ClickToDismiss)
            {
                this.OnClicked += (s, e) => {
                    dismiss = true;
                };
            }
        }
        void AddMenuButtonsGroup(Cockpit cockpit)
        {
            HUDButton importButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                //0.1f, 0.05f, 0.7f, 5.0f, -5.0f,       // for debugging
                "icons/import_v1");

            importButton.Name = "import";
            cockpit.AddUIElement(importButton, true);
            importButton.OnClicked += (s, e) => {
                var cp = new FileImportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                cockpit.Context.PushCockpit(cp);
            };

            HUDButton exportButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                //0.1f, 0.05f, 0.7f, 5.0f, -5.0f,       // for debugging convenience
                "icons/export_v1");

            UnityUtil.TranslateInFrame(exportButton.RootGameObject, 0, -0.055f, 0, CoordSpace.WorldCoords);
            exportButton.Name = "export";
            cockpit.AddUIElement(exportButton, true);
            exportButton.OnClicked += (s, e) => {
                var cp = new FileExportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                cockpit.Context.PushCockpit(cp);
            };


            HUDButton janusButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                //0.1f, 0.05f, 0.7f, 5.0f, -5.0f,       // for debugging convenience
                "cockpit_icons/menu_buttons/janus_v1");

            UnityUtil.TranslateInFrame(janusButton.RootGameObject, 0, 2.0f * -0.055f, 0, CoordSpace.WorldCoords);
            janusButton.Name = "export";
            cockpit.AddUIElement(janusButton, true);
            janusButton.OnClicked += (s, e) => {
                var cp = new JanusVRExportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                cockpit.Context.PushCockpit(cp);
            };


            HUDButton loadButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                // 0.1f, 0.05f, 0.7f, 5.0f, -5.0f,       // for debugging convenience
                "icons/load_v1");

            UnityUtil.TranslateInFrame(loadButton.RootGameObject, 0.12f, 0, 0, CoordSpace.WorldCoords);
            loadButton.Name = "load";
            cockpit.AddUIElement(loadButton, true);
            loadButton.OnClicked += (s, e) => {
                var cp = new FileLoadSceneCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                cockpit.Context.PushCockpit(cp);
            };

            HUDButton saveButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                // 0.1f, 0.05f, 0.7f, 5.0f, -5.0f,       // for debugging
                "icons/save_v1");

            UnityUtil.TranslateInFrame(saveButton.RootGameObject, 0.12f, -0.055f, 0, CoordSpace.WorldCoords);
            saveButton.Name = "save";
            cockpit.AddUIElement(saveButton, true);
            saveButton.OnClicked += (s, e) => {
                var cp = new FileSaveSceneCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                cockpit.Context.PushCockpit(cp);
            };



            HUDButton newButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                "icons/new_v1");

            UnityUtil.TranslateInFrame(newButton.RootGameObject, 0.24f, 0, 0, CoordSpace.WorldCoords);
            newButton.Name = "new";
            cockpit.AddUIElement(newButton, true);
            newButton.OnClicked += (s, e) => {
                cockpit.Context.NewScene(true);
            };


            HUDButton quitButton = HUDBuilder.CreateRectIconClickButton(
                0.1f, 0.05f, 0.7f, 55.0f, -50.0f,
                "icons/quit_v1");

            UnityUtil.TranslateInFrame(quitButton.RootGameObject, 0.24f, -0.055f, 0, CoordSpace.WorldCoords);
            quitButton.Name = "quit";
            cockpit.AddUIElement(quitButton, true);
            quitButton.OnClicked += (s, e) => { FPlatform.QuitApplication(); };
        }
 public BoxRegionContainerProvider(Cockpit c, ISurfaceBoxRegion region)
 {
     Cockpit = c;
     Region  = region;
 }
 public Cockpit2DContainerProvider(Cockpit c)
 {
     cockpit = c;
     cockpit.Context.OnWindowResized += Context_OnWindowResized;
 }
        public void Create(Cockpit cockpit)
        {
            base.Create();
            this.cockpit = cockpit;

            float fHUDRadius    = 0.7f;
            float fButtonRadius = 0.06f;

            Colorf bgColor     = new Color(0.7f, 0.7f, 1.0f, 0.7f);
            Colorf activeColor = new Colorf(ColorUtil.SelectionGold, 0.7f);

            defaultMaterial = (bgColor.a == 1.0f) ?
                              MaterialUtil.CreateStandardMaterialF(bgColor) : MaterialUtil.CreateTransparentMaterialF(bgColor);
            activeMaterial = (activeColor.a == 1.0f) ?
                             MaterialUtil.CreateStandardMaterialF(activeColor) : MaterialUtil.CreateTransparentMaterialF(activeColor);

            List <toolInfo> toolNames = new List <toolInfo>()
            {
                new toolInfo()
                {
                    identifier = "cancel", sMeshPath = "tool_icons/cancel", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = SnapDrawPrimitivesTool.Identifier, sMeshPath = "tool_icons/draw_primitive", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawTubeTool.Identifier, sMeshPath = "tool_icons/draw_tube", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawCurveTool.Identifier, sMeshPath = "tool_icons/draw_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawSurfaceCurveTool.Identifier, sMeshPath = "tool_icons/draw_surface_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = RevolveTool.Identifier, sMeshPath = "tool_icons/revolve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = TwoPointMeasureTool.Identifier, sMeshPath = "tool_icons/measure", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = SculptCurveTool.Identifier, sMeshPath = "tool_icons/sculpt_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = PlaneCutTool.Identifier, sMeshPath = "tool_icons/plane_cut", fMeshScaleFudge = 1.2f
                }
            };


            float        fRight     = -43.0f;
            float        df         = -11.0f;
            List <float> AngleSteps = new List <float>()
            {
                fRight, fRight + df, fRight + 2 * df
            };
            float fVertStep = 11.0f;
            float fTop      = 0.0f;

            int ri = 0, ci = 0;

            toolButtons    = new List <ActivateToolButton>();
            toolButtonInfo = new List <toolInfo>();
            foreach (toolInfo t in toolNames)
            {
                float fX = AngleSteps[ci++];
                float fY = fTop - (float)ri * fVertStep;
                if (ci == AngleSteps.Count)
                {
                    ci = 0; ri++;
                }

                var button = add_tool_button(cockpit, t.identifier, fHUDRadius,
                                             fX, fY, fButtonRadius, t);
                AddChild(button);
                toolButtons.Add(button);

                toolInfo ti = new toolInfo();
                ti        = t;
                ti.button = button;
                toolButtonInfo.Add(ti);
            }


            // build indicators
            string[] paths = { "tool_icons/star_green", "tool_icons/star_red" };
            for (int k = 0; k < 2; ++k)
            {
                Mesh     iconMesh     = null;
                Material iconMaterial = null;
                try {
                    iconMesh     = Resources.Load <Mesh>(paths[k]);
                    iconMaterial = MaterialUtil.CreateStandardVertexColorMaterial(Color.white);
                } catch { }
                if (iconMesh == null)
                {
                    iconMesh     = UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere);
                    iconMaterial = MaterialUtil.CreateStandardMaterial((k == 0) ? Color.green : Color.red);
                }
                indicator[k]      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                indicator[k].name = (k == 0) ? "left_tool_star" : "right_tool_star";
                Component.Destroy(indicator[k].GetComponent <Collider>());
                indicator[k].SetMesh(iconMesh);
                indicator[k].GetComponent <Renderer>().material = iconMaterial;


                // have to add to some button because we need them to be in GO tree
                //  when we do AddChild() on cockpit...that sets up layer, size, etc
                indicatorButton[k] = toolButtons[0];
                indicator[k].transform.localScale     = fIndicatorSize * Vector3.one;
                indicator[k].transform.localPosition +=
                    fIndicatorShiftXY * (Vector3.up + Vector3.right * ((k == 0) ? -1 : 1)) - fIndicatorShiftZ * Vector3.forward;
                indicatorButton[k].AppendNewGO(indicator[k], indicatorButton[k].RootGameObject, false);
                indicator[k].Hide();
            }


            // listen for changes
            cockpit.Context.ToolManager.OnToolActivationChanged += on_tool_changed;
        }
        public void Initialize(Cockpit cockpit, float fCockpitRadius)
        {
            activeCockpit = cockpit;
            activeCockpit.PositionMode = Cockpit.MovementMode.Static;
            activeCockpit.GrabFocus    = true;
            activeHUDRadius            = fCockpitRadius;

            string[] files, folders;
            try {
                files   = Source.GetFiles(FolderPath);
                folders = Source.GetFolders(FolderPath);
            } catch (Exception e) {
                Debug.Log("[CurrentFolderList.Initialize] exception! " + e.Message);
                return;
            }

            float fMinHorz = -45.0f, fMaxHorz = 45.0f;
            float fStartVert = 15.0f;
            float fTop       = HUDUtil.GetSphereFrame(fCockpitRadius, 0.0f, fStartVert).Origin.y;

            int folderi = 0, filei = 0;

            Mesh  folderMesh              = Resources.Load <Mesh>("icon_meshes/folder_v1");
            Color folderColor             = ColorUtil.make(241, 213, 146);
            Color inaccessibleFolderColor = ColorUtil.make(100, 100, 100);
            Mesh  fileMesh                = Resources.Load <Mesh>("icon_meshes/file_v1");
            Color fileColor               = ColorUtil.make(250, 250, 250);

            // [TODO] something wrong here, icons are loading backwards...??
            Quaternion meshRotation =
                Quaternion.AngleAxis(270.0f, Vector3.right) *
                Quaternion.AngleAxis(180.0f + 25.0f, Vector3.forward);
            float meshScale = IconSize * 0.9f;

            HUDCylinder hudSurf = new HUDCylinder()
            {
                Radius = fCockpitRadius, VerticalCoordIsAngle = false
            };
            float fStepH     = VRUtil.HorizontalStepAngle(fCockpitRadius, 0, IconSize + IconPadding);
            int   nStepsHorz = (int)((fMaxHorz - fMinHorz) / fStepH);

            fMinHorz = -(nStepsHorz * fStepH * 0.5f);
            fMaxHorz = (nStepsHorz * fStepH * 0.5f);
            float fStepV = IconSize + IconPadding;


            IconCollection = new HUDCollection();
            IconCollection.Create();

            bool bDone = false;
            int  yi    = 0;

            while (!bDone)
            {
                float fCurV = fTop - yi * fStepV;
                yi++;

                for (int xi = 0; xi < nStepsHorz && bDone == false; ++xi)
                {
                    float fCurH = fMinHorz + ((float)xi + 0.5f) * fStepH;

                    string name        = "x";
                    fMesh  useMesh     = null;
                    Color  useColor    = Color.white;
                    bool   bAccessible = true;
                    bool   bIsFile     = false;
                    if (folderi < folders.Length)
                    {
                        name     = folders[folderi++];
                        useMesh  = new fMesh(UnityEngine.Object.Instantiate <Mesh>(folderMesh));
                        useColor = folderColor;
                        if (Source.FilterInaccessibleFolders == false &&
                            FileSystemUtils.CanAccessFolder(Path.Combine(FolderPath, name)) == false)
                        {
                            bAccessible = false;
                            useColor    = inaccessibleFolderColor;
                        }
                    }
                    else if (filei < files.Length)
                    {
                        name     = files[filei++];
                        useMesh  = new fMesh(UnityEngine.Object.Instantiate <Mesh>(fileMesh));
                        useColor = fileColor;
                        bIsFile  = true;
                    }
                    else
                    {
                        bDone = true;
                        break;
                    }
                    //useColor.a = 0.999f;        // [RMS] can use this to force into alpha pass

                    string displayName = name;
                    if (displayName.Length > 12)
                    {
                        displayName = name.Substring(0, 12) + "...";
                    }

                    //float TextScale = 0.01f, ShiftX = -IconSize * 0.5f;
                    float TextScale = 0.005f, ShiftX = -IconSize * 0.5f;

                    HUDButton iconButton = HUDBuilder.CreateMeshClickButton(
                        useMesh, useColor, meshScale, meshRotation,
                        hudSurf, fCurH, fCurV,
                        new TextLabelGenerator()
                    {
                        Text = displayName, Scale = TextScale, Translate = new Vector3(ShiftX, 0.0f, 0.0f)
                    });
                    iconButton.Name = name;
                    //cockpit.AddUIElement(iconButton, true);
                    IconCollection.AddChild(iconButton);

                    if (bIsFile)
                    {
                        iconButton.OnClicked += (o, e) => {
                            if (this.OnFileClicked != null)
                            {
                                this.OnFileClicked(name);
                            }
                        };
                    }

                    if (bAccessible)
                    {
                        iconButton.OnDoubleClicked += IconButton_DoubleClick;
                    }
                }
            }

            cockpit.AddUIElement(IconCollection, true);
            fCurMaxScroll = Mathf.Max(0, (yi - 4) * fStepV);
        }
 public SpatialDeviceViewManipBehavior(Cockpit cockpit)
 {
     this.cockpit = cockpit;
 }
Exemple #8
0
 public SpatialDeviceGrabBehavior(Cockpit cockpit)
 {
     this.cockpit = cockpit;
 }
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "splashCockpit";
            cockpit.DefaultCursorDepth = 3.0f;
            cockpit.PositionMode       = Cockpit.MovementMode.Static;

            // create black sphere around camera to hide existing scene
            fGameObject blackBackground = new fGameObject(
                UnityUtil.CreateMeshGO("background_delete", "icon_meshes/inverted_sphere_tiny", 1.0f,
                                       UnityUtil.MeshAlignOption.AllAxesCentered, MaterialUtil.CreateFlatMaterial(Color.black), false));

            // add as bounds object to do mouse hit-test
            cockpit.Context.Scene.AddWorldBoundsObject(blackBackground);

            // re-parent from Scene so the sphere tracks the camera
            cockpit.FixedCameraTrackingGO.AddChild(blackBackground, false);

            HUDButton title = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 2.0f, 0.8f),
                3.0f, 0.0f, 2.5f, "simplex_startup/simplex_v2");

            title.Name    = "title";
            title.Enabled = false;
            cockpit.AddUIElement(title, true);

            HUDButton start = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.5f, 0.25f),
                3.0f, 8.0f, -10, "simplex_startup/start_v1");

            start.Name       = "start";
            start.OnClicked += (s, e) => {
                cockpit.ActiveCamera.Animator().DoActionDuringDipToBlack(() => {
                    cockpit.Context.Scene.RemoveWorldBoundsObject(blackBackground);
                    UnityEngine.GameObject.Destroy(blackBackground);
                    cockpit.Context.PushCockpit(
                        new SetupCADCockpit_V1());
                }, 1.0f);
            };
            cockpit.AddUIElement(start, true);

            HUDButton quit = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.5f, 0.25f),
                3.0f, -8.0f, -10, "simplex_startup/quit_v1");

            quit.Name       = "quit";
            quit.OnClicked += (s, e) => {
                FPlatform.QuitApplication();
            };
            cockpit.AddUIElement(quit, true);

            HUDButton logo = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.8f, 0.2f),
                3.0f, 0.0f, -25.0f, "simplex_startup/gradientspace_splash");

            logo.Name    = "logo";
            logo.Enabled = false;
            cockpit.AddUIElement(logo, true);



            HUDButton about_arrow = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.75f, 0.75f),
                3.0f, -30.0f, -10.0f, "simplex_startup/about_arrow");

            about_arrow.Name    = "about_arrow";
            about_arrow.Enabled = false;
            cockpit.AddUIElement(about_arrow, true);


            float     about_text_scale = 3.0f;
            float     angle_left       = -65.0f;
            HUDButton about_text       = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle,
                             0.8f * about_text_scale, 1.0f * about_text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_left, 0.0f, "simplex_startup/about_text");

            UnityUtil.TranslateInFrame(about_text.RootGameObject, 0.0f, -0.5f, 0, CoordSpace.WorldCoords);
            about_text.Name    = "about_text";
            about_text.Enabled = false;
            cockpit.AddUIElement(about_text, true);



            HUDButton controls_arrow = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.75f, 0.75f),
                3.0f, 30.0f, -10.0f, "simplex_startup/controls_arrow");

            controls_arrow.Name    = "controls_arrow";
            controls_arrow.Enabled = false;
            cockpit.AddUIElement(controls_arrow, true);



            float     text_scale     = 3.0f;
            float     angle_right    = 65.0f;
            HUDButton controls_mouse = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.7f * text_scale, 0.7f * text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_right, 0.0f, "simplex_startup/controls_mouse");

            UnityUtil.TranslateInFrame(controls_mouse.RootGameObject, 0.25f, 0.1f, 0, CoordSpace.WorldCoords);
            controls_mouse.Name    = "controls_mouse";
            controls_mouse.Enabled = false;
            cockpit.AddUIElement(controls_mouse, true);

            HUDButton controls_gamepad = HUDBuilder.CreateIconClickButton(
                new HUDShape(HUDShapeType.Rectangle, 0.7f * text_scale, 0.7f * text_scale)
            {
                UseUVSubRegion = false
            },
                3.0f, angle_right, 0.0f, "simplex_startup/controls_gamepad");

            UnityUtil.TranslateInFrame(controls_gamepad.RootGameObject, 0.25f, 0.1f, 0, CoordSpace.WorldCoords);
            controls_gamepad.Name    = "controls_gamepad";
            controls_gamepad.Enabled = false;
            cockpit.AddUIElement(controls_gamepad, true);
            controls_gamepad.RootGameObject.Hide();



            HUDToggleButton mouse_button = HUDBuilder.CreateToggleButton(
                new HUDShape(HUDShapeType.Rectangle, 1.0f, 1.0f),
                2.9f, angle_right, 0.0f, "simplex_startup/mouse", "simplex_startup/mouse_disabled");

            UnityUtil.TranslateInFrame(mouse_button.RootGameObject, -0.5f, -1.0f, 0, CoordSpace.WorldCoords);
            mouse_button.Name = "mouse_button";
            cockpit.AddUIElement(mouse_button, true);

            HUDToggleButton gamepad_button = HUDBuilder.CreateToggleButton(
                new HUDShape(HUDShapeType.Rectangle, 1.0f, 1.0f),
                2.9f, angle_right, 0.0f, "simplex_startup/gamepad_with_labels", "simplex_startup/gamepad_disabled");

            UnityUtil.TranslateInFrame(gamepad_button.RootGameObject, 0.5f, -1.0f, 0, CoordSpace.WorldCoords);
            gamepad_button.Name = "gamepad_button";
            cockpit.AddUIElement(gamepad_button, true);


            HUDToggleGroup group = new HUDToggleGroup();

            group.AddButton(mouse_button);
            group.AddButton(gamepad_button);
            group.Selected   = 0;
            group.OnToggled += (sender, nSelected) => {
                if (nSelected == 0)
                {
                    controls_gamepad.RootGameObject.Hide();
                    controls_mouse.RootGameObject.Show();
                }
                else
                {
                    controls_gamepad.RootGameObject.Show();
                    controls_mouse.RootGameObject.Hide();
                }
            };



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

            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
            });
        }
 public HUDParametersPanel(Cockpit cockpit)
 {
     this.cockpit = cockpit;
     cockpit.Scene.SelectionChangedEvent += Scene_SelectionChangedEvent;
 }
 public MouseWheelZoomBehavior(Cockpit cockpit)
 {
     this.cockpit = cockpit;
 }