Example #1
0
        public virtual PivotSO Create(SOMaterial shapeMaterial, SOMaterial frameMaterial = null, int nShapeLayer = -1)
        {
            // [TODO] replace frame geometry with line renderer ?
            // [TODO] still cast shadows  (semitransparent objects don't cast shadows, apparently)
            // [TODO] maybe render solid when not obscured by objects? use raycast in PreRender?

            AssignSOMaterial(shapeMaterial);       // need to do this to setup BaseSO material stack

            pivotGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("Pivot"));

            shapeGO = create_pivot_shape();
            AppendNewGO(shapeGO, pivotGO, false);

            pivotGO.AddChild(shapeGO);

            if (frameMaterial != null)
            {
                this.frameMaterial = frameMaterial;

                frameGO = UnityUtil.CreateMeshGO("pivotFrame", "icon_meshes/axis_frame", 1.0f,
                                                 UnityUtil.MeshAlignOption.NoAlignment, MaterialUtil.ToUnityMaterial(frameMaterial), false);
                MaterialUtil.SetIgnoreMaterialChanges(frameGO);
                MaterialUtil.DisableShadows(frameGO);
                AppendNewGO(frameGO, pivotGO, false);
            }

            if (nShapeLayer >= 0)
            {
                shapeGO.SetLayer(nShapeLayer);
            }

            increment_timestamp();
            return(this);
        }
Example #2
0
        public PivotSO Create(SOMaterial sphereMaterial, Material frameMaterial, int nSphereLayer = -1)
        {
            // [TODO] replace frame geometry with line renderer ?
            // [TODO] still cast shadows  (semitransparent objects don't cast shadows, apparently)
            // [TODO] maybe render solid when not obscured by objects? use raycast in PreRender?

            AssignSOMaterial(sphereMaterial);       // need to do this to setup BaseSO material stack

            pivot  = new GameObject(UniqueNames.GetNext("Pivot"));
            meshGO = AppendUnityPrimitiveGO("pivotMesh", PrimitiveType.Sphere, CurrentMaterial, pivot);
            meshGO.transform.localScale = 0.9f * Vector3.one;

            if (frameMaterial != null)
            {
                frameMesh = UnityUtil.CreateMeshGO("pivotFrame", "icon_meshes/axis_frame", 1.0f,
                                                   UnityUtil.MeshAlignOption.NoAlignment, frameMaterial, false);
                frameMesh.AddComponent <IgnoreMaterialChanges>();
                MaterialUtil.DisableShadows(frameMesh);
                AppendNewGO(frameMesh, pivot, false);
            }

            if (nSphereLayer >= 0)
            {
                meshGO.SetLayer(nSphereLayer);
            }

            increment_timestamp();
            return(this);
        }
            virtual public List <fGameObject> Generate()
            {
                GameObject meshGO = UnityUtil.CreateMeshGO("primitive", MeshPath, 1.0f,
                                                           UnityUtil.MeshAlignOption.AllAxesCentered, UseMaterial, true);

                meshGO.transform.localScale *= UseSize;
                meshGO.transform.Translate(0.0f, 0.0f, -UseSize);
                meshGO.transform.Rotate(-15.0f, 45.0f, 0.0f, Space.Self);
                //return new List<fGameObject>() { meshGO };
                return(new List <fGameObject>()
                {
                });
            }
            virtual public List <fGameObject> Generate()
            {
                GameObject primGO = UnityUtil.CreatePrimitiveGO("primitive", PrimitiveType.Sphere, SphereMaterial, true);
                GameObject meshGO = UnityUtil.CreateMeshGO("primitive", "icon_meshes/axis_frame", 1.0f,
                                                           UnityUtil.MeshAlignOption.NoAlignment, FrameMaterial, false);

                meshGO.transform.SetParent(primGO.transform, true);
                primGO.transform.localScale = new Vector3(PrimSize, PrimSize, PrimSize);
                primGO.transform.Translate(0.0f, 0.0f, -PrimSize);
                primGO.transform.Rotate(15.0f, 135.0f, 0.0f, Space.Self);
                return(new List <fGameObject>()
                {
                    primGO
                });
            }
Example #5
0
        public void SetHandIcon(Mesh m, int iSide)
        {
            SpatialDevice h = (iSide == 0) ? Left : Right;

            if (h.HandIcon != null)
            {
                h.HandIcon.transform.parent = null;
                GameObject.Destroy(h.HandIcon);
            }

            h.HandIcon =
                UnityUtil.CreateMeshGO("hand_icon", m, MaterialUtil.CreateStandardVertexColorMaterial(Color.white), false);
            h.HandIcon.transform.localScale    = 0.3f * Vector3.one;
            h.HandIcon.transform.localPosition = new Vector3(0.0f, -0.3f, -0.3f);
            h.HandIcon.transform.SetParent(h.Hand.transform, false);
            h.HandIcon.SetLayer(FPlatform.CursorLayer);
        }
        public void SetHandIcon(Mesh m, int iSide)
        {
            SpatialDevice h = (iSide == 0) ? Left : Right;

            if (h.HandIcon != null)
            {
                h.HandIcon.transform.parent = null;
                h.HandIcon.Destroy();
            }

            h.HandIcon =
                UnityUtil.CreateMeshGO("hand_icon", m, MaterialUtil.CreateStandardVertexColorMaterial(Color.white), false);
            float s = SceneGraphConfig.VRHandArrowRadius;

            h.HandIcon.transform.localScale    = s * 0.3f * Vector3.one;
            h.HandIcon.transform.localPosition = new Vector3(0.0f, -0.3f * s, -0.3f * s);
            h.HandIcon.transform.SetParent(h.Hand.transform, false);
            h.HandIcon.SetLayer(FPlatform.CursorLayer);
        }
Example #7
0
        override protected void Create_internal(fMaterial useMaterial)
        {
            if (polygon == null)
            {
                polygon = Polygon2d.MakeCircle(0.3f, 8);
            }

            // generate mesh tube
            TubeGenerator meshGen = new TubeGenerator()
            {
                Vertices = new List <Vector3d>(curve.Vertices), Capped = true,
                Polygon  = polygon,
                Frame    = new Frame3f(Vector3f.Zero, Vector3f.AxisY)
            };

            meshGen.Generate();
            Mesh m = meshGen.MakeUnityMesh(false);

            meshGO = UnityUtil.CreateMeshGO("tube_mesh", m, useMaterial, true);
            AppendNewGO(meshGO, RootGameObject, false);
        }
        // Use this for initialization
        public void Start()
        {
            fCursorSpeedNormalization = 1.0f;
            fCurPlaneX      = 0;
            fCurPlaneY      = 0;
            vPlaneCursorPos = Vector3.zero;
            vSceneCursorPos = vPlaneCursorPos;

            CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(Color.grey, 0.6f);
            //CursorHitMaterial = MaterialUtil.CreateTransparentMaterial (Color.yellow, 0.8f);
            CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(Color.yellow);
            CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(Color.yellow, 0.75f);

            CursorVisualAngleInDegrees = 1.5f;

            standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);
            UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0);
            activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16);
            UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0);

            Cursor = UnityUtil.CreateMeshGO("cursor", standardCursorMesh, CursorDefaultMaterial);
            Cursor.SetSharedMesh(standardCursorMesh);
            Cursor.transform.localScale    = new Vector3(0.3f, 0.3f, 0.3f);
            Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Cursor);

            xformObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
            xformObject.SetName("cursor_plane");
            MaterialUtil.DisableShadows(xformObject);
            xformObject.GetComponent <MeshRenderer>().material
                = MaterialUtil.CreateTransparentMaterial(Color.cyan, 0.2f);
            xformObject.GetComponent <MeshRenderer>().enabled = false;

            lastMouseEventTime = FPlatform.RealTime();
            mouseInactiveState = false;
        }
Example #9
0
        void InitializeSpatialInput()
        {
            Left  = new SpatialDevice();
            Right = new SpatialDevice();

            Left.CursorDefaultMaterial   = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.6f);
            Left.CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold);
            Left.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.SelectionGold, 0.75f);
            Left.HandMaterial            = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.3f);

            Right.CursorDefaultMaterial   = MaterialUtil.CreateTransparentMaterial(Colorf.DarkRed, 0.6f);
            Right.CursorHitMaterial       = MaterialUtil.CreateStandardMaterial(ColorUtil.PivotYellow);
            Right.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.PivotYellow, 0.75f);
            Right.HandMaterial            = MaterialUtil.CreateTransparentMaterial(ColorUtil.CgRed, 0.3f);

            CursorVisualAngleInDegrees = 1.5f;

            standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);
            UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0);
            activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16);
            UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0);

            Left.Cursor = UnityUtil.CreateMeshGO("left_cursor", standardCursorMesh, Left.CursorDefaultMaterial);
            Left.Cursor.transform.localScale    = 0.3f * Vector3.one;
            Left.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Left.Cursor);
            Left.Cursor.SetLayer(FPlatform.CursorLayer);
            Left.SmoothedHandFrame = Frame3f.Identity;

            var leftHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);

            Left.Hand = UnityUtil.CreateMeshGO("left_hand", leftHandMesh, Left.HandMaterial);
            UnityUtil.TranslateMesh(leftHandMesh, 0, -1.0f, 0);
            Left.Hand.transform.localScale = 0.1f * Vector3.one;
            Left.Hand.transform.rotation   = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
            Left.Hand.SetLayer(FPlatform.HUDLayer);

            Left.Laser    = new GameObject("left_laser");
            Left.LaserRen = Left.Laser.AddComponent <LineRenderer>();
            Left.LaserRen.SetPositions(new Vector3[2] {
                Vector3.zero, 100 * Vector3.up
            });
            Left.LaserRen.startWidth = Left.LaserRen.endWidth = 0.01f;
            Left.LaserRen.material   = MaterialUtil.CreateFlatMaterial(ColorUtil.ForestGreen, 0.2f);
            Left.Laser.SetLayer(FPlatform.CursorLayer);
            Left.Laser.transform.parent = Left.Cursor.transform;

            Right.Cursor = UnityUtil.CreateMeshGO("right_cursor", standardCursorMesh, Right.CursorDefaultMaterial);
            Right.Cursor.transform.localScale    = 0.3f * Vector3.one;
            Right.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized);
            MaterialUtil.DisableShadows(Right.Cursor);
            Right.Cursor.SetLayer(FPlatform.CursorLayer);
            Right.SmoothedHandFrame = Frame3f.Identity;

            var rightHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16);

            Right.Hand = UnityUtil.CreateMeshGO("right_hand", rightHandMesh, Right.HandMaterial);
            UnityUtil.TranslateMesh(rightHandMesh, 0, -1.0f, 0);
            Right.Hand.transform.localScale = 0.1f * Vector3.one;
            Right.Hand.transform.rotation   = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
            Right.Hand.SetLayer(FPlatform.HUDLayer);

            Right.Laser    = new GameObject("right_laser");
            Right.LaserRen = Right.Laser.AddComponent <LineRenderer>();
            Right.LaserRen.SetPositions(new Vector3[2] {
                Vector3.zero, 100 * Vector3.up
            });
            Right.LaserRen.startWidth = Right.LaserRen.endWidth = 0.01f;
            Right.LaserRen.material   = MaterialUtil.CreateFlatMaterial(ColorUtil.CgRed, 0.2f);
            Right.Laser.SetLayer(FPlatform.CursorLayer);
            Right.Laser.transform.parent = Right.Cursor.transform;

            spatialInputInitialized = true;
        }
        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
            });
        }