Example #1
0
        void Update()
        {
            if (VRInput.TryGetDevices())
            {
                // Toggle selection
                if (enableToggleTool)
                {
                    VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.secondaryButton, () =>
                    {
                        ToolsManager.ToggleTool();
                    });
                }

                // if tool has switch, THIS is now disabled, we dont want updates.
                if (!gameObject.activeSelf)
                {
                    return;
                }

                // Custom tool update
                if (IsInGui)
                {
                    DoUpdateGui();
                }
                else // TODO: voir si il faut pas quand meme faire DoUpdate dans tous les cas.
                // le probleme de faire les deux vient quand ils reagissent au meme input (ex: Grip dans UI)
                {
                    DoUpdate(); // call children DoUpdate
                }
            }
        }
Example #2
0
        void OnCurveChanged(GameObject gObject, AnimatableProperty property)
        {
            RigGoalController[] controllers = gObject.GetComponentsInChildren <RigGoalController>();
            if (controllers.Length > 0)
            {
                if ((ToolsManager.CurrentToolName() == "Animation"))
                {
                    //update all goals' curves
                    UpdateGoalCurve(controllers);
                }
                else
                {
                    //only update rig's root curve
                    UpdateGoalCurve(new RigGoalController[] { controllers[0] });
                }
            }
            if (property != AnimatableProperty.PositionX && property != AnimatableProperty.PositionY && property != AnimatableProperty.PositionZ)
            {
                return;
            }

            if (!Selection.IsSelected(gObject))
            {
                return;
            }

            UpdateCurve(gObject);
        }
Example #3
0
        public void OnBackToScene()
        {
            RestoreViewParameters();

            GlobalState.Instance.playerController.IsInLobby = false;
            world.SetActive(true);
            gameObject.SetActive(false);

            // Change volume
            sceneVolume.SetActive(true);
            lobbyVolume.SetActive(false);

            // Activate palette
            palette.SetActive(true);

            // Show windows (vehicle_hud)
            vehicleHUD.SetActive(true);

            // Active tool
            ToolsManager.ActivateCurrentTool(true);

            // Activate selection helper
            GlobalState.Instance.toolsController.Find("SelectionHelper").gameObject.SetActive(true);

            // Set selector tool active
            ToolsUIManager.Instance.ChangeTab("Selector");
            ToolsManager.ChangeTool("Selector");
        }
Example #4
0
        public void OnUI3DObjectExit(int gohash)
        {
            ToolBase tool = ToolsManager.CurrentTool();

            if (tool != null)
            {
                tool.OnUIObjectExit(gohash);
            }
        }
Example #5
0
        public void ShowCurrentTool(bool doShowTool)
        {
            ToolBase tool = ToolsManager.CurrentTool();

            if (tool != null)
            {
                tool.IsInGui = !doShowTool;
            }
        }
Example #6
0
        public CommandAddKeyframes(GameObject obj, bool updateCurve = true) : base("Add Keyframes")
        {
            gObject = obj;
            Interpolation interpolation = GlobalState.Settings.interpolation;
            int           frame         = GlobalState.Animation.CurrentFrame;

            bool isHuman = obj.TryGetComponent <RigController>(out RigController skinController);

            if (ToolsManager.CurrentToolName() != "Animation" || !isHuman)
            {
                new CommandAddKeyframe(gObject, AnimatableProperty.PositionX, frame, gObject.transform.localPosition.x, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.PositionY, frame, gObject.transform.localPosition.y, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.PositionZ, frame, gObject.transform.localPosition.z, interpolation, updateCurve).Submit();

                // convert to ZYX euler
                Vector3 angles = ReduceAngles(gObject.transform.localRotation);
                new CommandAddKeyframe(gObject, AnimatableProperty.RotationX, frame, angles.x, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.RotationY, frame, angles.y, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.RotationZ, frame, angles.z, interpolation, updateCurve).Submit();
            }

            CameraController controller  = gObject.GetComponent <CameraController>();
            LightController  lcontroller = gObject.GetComponent <LightController>();

            if (null != controller)
            {
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraFocal, frame, controller.focal, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraFocus, frame, controller.Focus, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraAperture, frame, controller.aperture, interpolation, updateCurve).Submit();
            }
            else if (null != lcontroller)
            {
                new CommandAddKeyframe(gObject, AnimatableProperty.Power, frame, lcontroller.Power, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorR, frame, lcontroller.Color.r, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorG, frame, lcontroller.Color.g, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorB, frame, lcontroller.Color.b, interpolation, updateCurve).Submit();
            }
            else
            {
                // Scale
                Vector3 scale = gObject.transform.localScale;
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleX, frame, scale.x, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleY, frame, scale.y, interpolation, updateCurve).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleZ, frame, scale.z, interpolation, updateCurve).Submit();
            }

            if (isHuman && ToolsManager.CurrentToolName() == "Animation")
            {
                foreach (Transform child in gObject.transform)
                {
                    RecursiveAddKeyFrame(child, frame, interpolation);
                }
            }
        }
Example #7
0
        public void OnSetVisible(bool start = false)
        {
            // Stop play if playing
            AnimationEngine.Instance.Pause();

            ResetVRCamera();

            GlobalState.Instance.playerController.IsInLobby = true;
            world.SetActive(false);
            gameObject.SetActive(true);

            // Change volume
            sceneVolume.SetActive(false);
            lobbyVolume.SetActive(true);



            // Hide all windows (vehicle_hud)
            vehicleHUD.SetActive(false);

            // Deactive current tool
            ToolsManager.ActivateCurrentTool(false);

            // Deactivate selection helper
            GlobalState.Instance.toolsController.Find("SelectionHelper").gameObject.SetActive(false);

            // Orient lobby
            float camY = Camera.main.transform.localEulerAngles.y;

            transform.localEulerAngles = new Vector3(0f, camY, 0f);

            LoadProjectItems();
            if (!start)
            {
                HighlightSelectedProject();
                launchProjectButton.Disabled = true;

                // Hide & disable palette
                palette.SetActive(false);
            }
            else
            {
                currentProject = null;
            }

            backToSceneButton.Disabled = start;

            // Set lobby tool active
            ToolsManager.ChangeTool("Lobby");

            needToSetCameraRef = true;
        }
Example #8
0
        public static void SetRightHanded(bool value)
        {
            if (null != Instance.secondaryControllerDisplay && Settings.rightHanded == value)
            {
                return;
            }

            Settings.rightHanded = value;

            GameObject leftHandleRightController = Instance.paletteController.Find("right_controller").gameObject;
            GameObject leftHandleLeftController  = Instance.paletteController.Find("left_controller").gameObject;

            GameObject rightHandleRightController = Instance.toolsController.Find("right_controller").gameObject;
            GameObject rightHandleLeftController  = Instance.toolsController.Find("left_controller").gameObject;

            leftHandleLeftController.SetActive(value);
            leftHandleRightController.SetActive(!value);
            rightHandleRightController.SetActive(value);
            rightHandleLeftController.SetActive(!value);

            // Update controller's displays
            Instance.primaryControllerDisplay        = GetPrimaryControllerTransform().Find("Canvas/Text").GetComponent <TextMeshProUGUI>();
            Instance.secondaryControllerDisplay      = GetSecondaryControllerTransform().Find("Canvas/Text").GetComponent <TextMeshProUGUI>();
            Instance.secondaryControllerDisplay.text = "";
            Instance.primaryControllerDisplay.text   = "";

            // Update tooltips
            Tooltips.HideAll(VRDevice.PrimaryController);
            Tooltips.HideAll(VRDevice.SecondaryController);
            ToolBase tool = ToolsManager.CurrentTool();

            if (null != tool)
            {
                tool.SetTooltips();
            }
            Instance.playerController.HandleCommonTooltipsVisibility();

            // Move Palette
            Transform palette = Instance.paletteController.Find("PaletteHandle");
            Vector3   currentPalettePosition = palette.localPosition;

            if (Settings.rightHanded)
            {
                palette.localPosition = new Vector3(-0.02f, currentPalettePosition.y, currentPalettePosition.z);
            }
            else
            {
                palette.localPosition = new Vector3(-0.2f, currentPalettePosition.y, currentPalettePosition.z);
            }
        }
Example #9
0
        void Start()
        {
            OnToolChangedEvent += ToolsManager.OnChangeTool;

            string firstToolName = ToolsManager.CurrentToolName();

            ChangeTab(firstToolName);
            currentToolName = firstToolName;
            //ChangeTool(firstToolName);

            colorPanel = tabButtonsContainer.Find("ColorPanel").gameObject;

            keyboardWindow.localScale        = Vector3.zero;
            numericKeyboardWindow.localScale = Vector3.zero;

            createInstanceVFXPrefab = Resources.Load <GameObject>("VFX/ParticleSpawn");
            deleteInstanceVFXPrefab = Resources.Load <GameObject>("VFX/ParticleDespawn");
        }
Example #10
0
 void UpdateFromSelection()
 {
     ClearCurves();
     foreach (GameObject gObject in Selection.SelectedObjects)
     {
         AddCurve(gObject);
         if (gObject.TryGetComponent(out RigController skinController))
         {
             if ((ToolsManager.CurrentToolName() == "Animation"))
             {
                 AddHumanCurve(gObject, skinController);
             }
             else
             {
                 //Only display curve for Rig's root
                 RigGoalController goalController = skinController.RootObject.GetComponent <RigGoalController>();
                 AddGoalCurve(goalController, skinController);
             }
         }
     }
 }
Example #11
0
        public void SetRightHanded(bool value)
        {
            inverseRightController.controllerTransform.gameObject.SetActive(!value);
            inverseLeftController.controllerTransform.gameObject.SetActive(!value);
            rightController.controllerTransform.gameObject.SetActive(value);
            leftController.controllerTransform.gameObject.SetActive(value);

            Transform toolsController   = GlobalState.Instance.toolsController;
            Transform paletteController = GlobalState.Instance.paletteController;


            // Update controller's displays
            rightController.controllerDisplay.text        = "";
            inverseRightController.controllerDisplay.text = "";
            leftController.controllerDisplay.text         = "";
            inverseLeftController.controllerDisplay.text  = "";

            // Update tooltips
            Tooltips.HideAll(VRDevice.PrimaryController);
            Tooltips.HideAll(VRDevice.SecondaryController);
            ToolBase tool = ToolsManager.CurrentTool();

            if (null != tool)
            {
                tool.SetTooltips();
            }
            GlobalState.Instance.playerController.HandleCommonTooltipsVisibility();

            Transform palette = GlobalState.Instance.paletteController.Find("PaletteHandle");

            if (value)
            {
                SetHolders(leftController, rightController, toolsController, paletteController, palette);
            }
            else
            {
                SetHolders(inverseRightController, inverseLeftController, toolsController, paletteController, palette);
            }
        }
Example #12
0
        private void HandleHoverPhysicObject(GameObject gObj)
        {
            //Selection.SetHoveredObject(gObj);

            //TitleBarIsGripped

            if (gObj == null)              // REMOVE
            {
                if (hoveredObject != null) // Only if we had hovered an object with the cursor => Dont un-hover general objects.
                {
                    if (TitleBarIsGripped)
                    {
                    }
                    else
                    {
                        Selection.HoveredObject = null;
                        hoveredObject           = null;
                        ToolsManager.PopWindowTool();
                    }

                    // NOTE: problem here if the ray goes out of the titlebar, and we are GRIPPED on it. It will disable the tool and drop the window.
                    // TOOD: find a way here to know that we are gripped with the WindowTool.
                }
            }
            else // ADD
            {
                if (hoveredObject != gObj) // Only once for gObj
                {
                    Selection.HoveredObject = gObj; // will automatically switch with previously hovered object (UI or other).
                    hoveredObject           = gObj;

                    if (null != gObj.GetComponent <UIHandle>())
                    {
                        ToolsManager.PushWindowTool();
                    }
                }
            }
        }
Example #13
0
 protected virtual void Awake()
 {
     ToolsManager.RegisterTool(gameObject);
     mouthpieces = GlobalState.Instance.toolsController.Find("mouthpieces");
 }
Example #14
0
        public override void Update()
        {
            //
            // LEFT GRIP WORLD
            //

            VRInput.ButtonEvent(VRInput.secondaryController, CommonUsages.gripButton,
                                () =>
            {
                // left AFTER right => reset all
                // NOTE: isRightGripped && Selection.selection.Count > 0 means that the selectionTool will/has gripped objects,
                //       and is no longer able to be used for two-hands interaction.
                if (isRightGripped) // && Selection.selection.Count == 0)
                {
                    ResetInitControllerMatrices(ResetType.LEFT_AND_RIGHT);
                    ResetInitWorldMatrix();
                    ResetDistance(); // after reset world, use scale

                    SetLeftControllerVisibility(ControllerVisibility.SHOW_NORMAL);

                    lineUI.Show(true, StretchUI.LineMode.DOUBLE);
                    GlobalState.IsGrippingWorld = true;
                    ToolsManager.ActivateCurrentTool(false);
                }

                isLeftGripped = true;
            },
                                () =>
            {
                SetLeftControllerVisibility(ControllerVisibility.SHOW_NORMAL);

                lineUI.Show(false);
                ToolsManager.ActivateCurrentTool(true);
                GlobalState.IsGrippingWorld = false;

                isLeftGripped = false;
            });

            //
            // RIGHT GRIP WORLD
            //

            // NOTE: On ne peut predire dans quel ordre les Update vont s'executer. Le Selector/SelectorTrigger peuvent
            //       recuperer le LeftGrip avant nous, et commencer a grip un objet avant qu'on ait pu set la property
            //       GlobalState.IsGrippingWorld. Cela pose-t-il encore un probleme?
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.gripButton,
                                () =>
            {
                //if (Selection.selection.Count == 0)
                {
                    // right AFTER left and no selection, reset all
                    if (isLeftGripped)
                    {
                        ResetInitControllerMatrices(ResetType.LEFT_AND_RIGHT);
                        ResetInitWorldMatrix();
                        ResetDistance(); // NOTE: called after "reset world", because it uses the scale.

                        SetLeftControllerVisibility(ControllerVisibility.SHOW_NORMAL);
                        lineUI.Show(true, StretchUI.LineMode.DOUBLE);
                        GlobalState.IsGrippingWorld = true;
                        ToolsManager.ActivateCurrentTool(false);
                    }

                    // even if no left gripped, just flag the right as gripped for the next update
                    isRightGripped = true;
                }
            },
                                () =>
            {
                // si on relache le right et que le left est tjs grip, reset left
                if (isLeftGripped)
                {
                    ResetInitControllerMatrices(ResetType.LEFT_ONLY);
                    ResetInitWorldMatrix();

                    SetLeftControllerVisibility(ControllerVisibility.SHOW_NORMAL);
                }
                //lineUI.Show(true, StretchUI.LineMode.SINGLE);
                ToolsManager.ActivateCurrentTool(true);
                GlobalState.IsGrippingWorld = false;

                isRightGripped = false;
            });

            // NOTE: we test isLeftGrip because we can be ungripped but still over the deadzone, strangely.
            if (isLeftGripped && VRInput.GetValue(VRInput.secondaryController, CommonUsages.grip) > deadZone)
            {
                if (isRightGripped)
                {
                    float prevScale = scale;

                    VRInput.GetControllerTransform(VRInput.secondaryController, out Vector3 currentLeftControllerPosition_L, out Quaternion currentLeftControllerRotation_L);
                    VRInput.GetControllerTransform(VRInput.primaryController, out Vector3 currentRightControllerPosition_L, out Quaternion currentRightControllerRotation_L);

                    Matrix4x4 currentLeftControllerMatrix_L_Scaled = Matrix4x4.TRS(currentLeftControllerPosition_L, currentLeftControllerRotation_L, new Vector3(scale, scale, scale));
                    Matrix4x4 currentLeftControllerMatrix_W        = initPivotMatrix * currentLeftControllerMatrix_L_Scaled;
                    Vector3   currentLeftControllerPosition_W      = currentLeftControllerMatrix_W.MultiplyPoint(Vector3.zero);

                    // update right joystick
                    Matrix4x4 currentRightControllerMatrix_L_Scaled = Matrix4x4.TRS(currentRightControllerPosition_L, currentRightControllerRotation_L, new Vector3(scale, scale, scale));
                    Vector3   currentRightControllerPosition_W      = (initPivotMatrix * currentRightControllerMatrix_L_Scaled).MultiplyPoint(Vector3.zero);

                    // scale handling (before computing the "transformed" matrix with the new scale)
                    float newDistance = Vector3.Distance(currentLeftControllerPosition_W, currentRightControllerPosition_W);
                    float factor      = newDistance / prevDistance;

                    float oldScale = scale;
                    scale       *= factor;
                    prevDistance = newDistance;

                    Vector3    middlePosition_L    = (currentLeftControllerPosition_L + currentRightControllerPosition_L) * 0.5f;
                    Vector3    middleXVector       = (currentRightControllerPosition_L - currentLeftControllerPosition_L).normalized;
                    Vector3    middleForwardVector = -Vector3.Cross(middleXVector, pivot.up).normalized;
                    Quaternion middleRotation_L    = Quaternion.LookRotation(middleForwardVector, pivot.up);

                    Matrix4x4 middleMatrix_L_Scaled = Matrix4x4.TRS(middlePosition_L, middleRotation_L, Vector3.one) * Matrix4x4.Scale(Vector3.one * scale);
                    Matrix4x4 middleMatrix_W_Delta  = initPivotMatrix * middleMatrix_L_Scaled * initMiddleMatrix_WtoL;
                    Matrix4x4 transformed           = middleMatrix_W_Delta * initWorldMatrix_W;
                    transformed = transformed.inverse;

                    float s            = 1.0f;
                    float clampedScale = Mathf.Clamp(transformed.lossyScale.x, 1.0f / maxPlayerScale, minPlayerScale);
                    if (transformed.lossyScale.x == clampedScale)
                    {
                        // translate/rotate/scale using the new scale
                        rig.localPosition = new Vector3(transformed.GetColumn(3).x, transformed.GetColumn(3).y, transformed.GetColumn(3).z);
                        rig.localRotation = transformed.rotation;
                        rig.localScale    = new Vector3(clampedScale, clampedScale, clampedScale);

                        s = oldScale;
                    }

                    // Get head position
                    VRInput.GetControllerTransform(VRInput.head, out Vector3 HeadPosition, out Quaternion headRotation);
                    Matrix4x4 invHeadMatrix = Matrix4x4.TRS(HeadPosition, headRotation, Vector3.one).inverse;
                    // Project left & right controller into head matrix to determine which one is on the left
                    Vector3 leftControllerInHeadMatrix  = invHeadMatrix.MultiplyPoint(currentLeftControllerPosition_L);
                    Vector3 rightControllerInHeadMatrix = invHeadMatrix.MultiplyPoint(currentRightControllerPosition_L);
                    // reverse text if right and left hands are crossed
                    if (leftControllerInHeadMatrix.x > rightControllerInHeadMatrix.x)
                    {
                        middleXVector = -middleXVector;
                    }

                    // Rotation for the line text
                    Vector3    middleForward180              = Vector3.Cross(middleXVector, pivot.up).normalized;
                    Vector3    rolledUp                      = Vector3.Cross(-middleXVector, middleForward180).normalized;
                    Quaternion middleRotationWithRoll_L      = Quaternion.LookRotation(middleForward180, rolledUp);
                    Matrix4x4  middleMatrixWithRoll_L_Scaled = Matrix4x4.TRS(middlePosition_L, middleRotationWithRoll_L, new Vector3(s, s, s));
                    Quaternion middleRotationWithRoll_W      = (pivot.localToWorldMatrix * middleMatrixWithRoll_L_Scaled).rotation;

                    lineUI.UpdateLineUI(pivot.TransformPoint(currentLeftControllerPosition_L), pivot.TransformPoint(currentRightControllerPosition_L), middleRotationWithRoll_W, 1f / GlobalState.WorldScale);
                }
                GlobalState.WorldScale = 1f / rig.localScale.x;

                UpdateCameraClipPlanes();
            }
        }
Example #15
0
        public void OnRemoveKeyFrame()
        {
            CommandGroup group = new CommandGroup("Remove Keyframe");

            try
            {
                foreach (GameObject gObject in Selection.SelectedObjects)
                {
                    if (gObject.TryGetComponent <RigController>(out RigController controller) && ToolsManager.CurrentToolName() != "Animation")
                    {
                        new CommandRemoveRecursiveKeyframes(gObject).Submit();
                    }
                    else
                    {
                        if (GlobalState.Animation.ObjectHasKeyframeAt(gObject, GlobalState.Animation.CurrentFrame))
                        {
                            new CommandRemoveKeyframes(gObject).Submit();
                        }
                    }
                }