public Vector3 GetWorldCenter()
        {
            if (NumberOfSelectedObjects == 0)
            {
                return(Vector3.zero);
            }
            else
            {
                Vector3 objectCenterSum = Vector3.zero;
                foreach (GameObject selectedObject in _selectedObjects.HashSet)
                {
                    OrientedBox worldOrientedBox = selectedObject.GetWorldOrientedBox();
                    if (worldOrientedBox.IsValid())
                    {
                        objectCenterSum += worldOrientedBox.Center;
                    }
                    else
                    {
                        objectCenterSum += selectedObject.transform.position;
                    }
                }

                return(objectCenterSum / NumberOfSelectedObjects);
            }
        }
        public void RenderMirroredEntityOrientedBox(Plane mirrorPlane, OrientedBox entityBox, bool mirrorRotation, Color boxColor, Color boxBorderLineColor)
        {
            if (!entityBox.IsValid())
            {
                return;
            }

            OrientedBox mirroredEntityBox = Mirroring.MirrorOrientedBox(mirrorPlane, entityBox, mirrorRotation);

            GizmosEx.RenderOrientedBox(mirroredEntityBox, boxColor);
            GizmosEx.RenderOrientedBoxEdges(mirroredEntityBox, boxBorderLineColor);
        }
        private bool IsWorldOrientedBoxFullyOverlappedByCircle(OrientedBox worldOrientedBox)
        {
            if (worldOrientedBox.IsValid())
            {
                if (ContainsAllPoints(worldOrientedBox.GetCornerPointsProjectedOnPlane(Plane)) &&
                    DoesWorldOrientedBoxIntersectOrResideOnShapeSurface(worldOrientedBox))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        public void SnapObjectHierarchyToCenterOfSnapSurface(GameObject hierarchyRoot, Vector3 snapPivotPoint, ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, float offsetFromSnapSurface)
        {
            _objectSnapSurface.FromMouseCursorRayHit(GetCursorRayHit());
            if (_objectSnapSurface.IsValid)
            {
                OrientedBox hierarchyWorldOrientedBox = hierarchyRoot.GetHierarchyWorldOrientedBox();
                if (!hierarchyWorldOrientedBox.IsValid())
                {
                    return;
                }

                SnapObjectHierarchyPosition(hierarchyRoot, snapPivotPoint, _objectSnapSurface.Center, projectedBoxFacePivotPoints, offsetFromSnapSurface);
            }
        }
Exemple #5
0
        private List <GameObject> GetGameObjectsOverlappedByEnclosingRectForFullOverlap(List <GameObject> visibleGameObjects, Camera camera)
        {
            var overlappedGameObjects = new List <GameObject>(visibleGameObjects.Count);

            foreach (GameObject visibleGameObject in visibleGameObjects)
            {
                OrientedBox worldOrientedBox = visibleGameObject.GetWorldOrientedBox();
                if (worldOrientedBox.IsValid() && _enclosingRect.FullyContainsOrientedBoxCenterAndCornerPointsInScreenSpace(worldOrientedBox, camera))
                {
                    overlappedGameObjects.Add(visibleGameObject);
                }
            }

            return(overlappedGameObjects);
        }
Exemple #6
0
        public void SnapObjectHierarchy(GameObject hierarchyRoot, ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, float offsetFromSnapSurface)
        {
            _objectSnapSurface.FromMouseCursorRayHit(GetCursorRayHit());
            if (_objectSnapSurface.IsValid)
            {
                OrientedBox hierarchyWorldOrientedBox = hierarchyRoot.GetHierarchyWorldOrientedBox();
                if (!hierarchyWorldOrientedBox.IsValid())
                {
                    return;
                }

                Vector3 pivotPoint = projectedBoxFacePivotPoints.ActivePoint;
                if (Settings.UseOriginalPivot)
                {
                    pivotPoint = hierarchyRoot.transform.position;
                }

                if (Settings.SnapToCursorHitPoint || Settings.EnableObjectToObjectSnap)
                {
                    SnapObjectHierarchyPosition(hierarchyRoot, pivotPoint, _objectSnapSurface.CursorPickPoint, projectedBoxFacePivotPoints, offsetFromSnapSurface);
                }
                else
                {
                    if (_objectSnapSurface.SurfaceType == SnapSurfaceType.GridCell && Settings.SnapCenterToCenterForXZGrid && !Settings.UseOriginalPivot)
                    {
                        SnapObjectHierarchyToCenterOfSnapSurface(hierarchyRoot, projectedBoxFacePivotPoints.CenterPoint, projectedBoxFacePivotPoints, offsetFromSnapSurface);
                    }
                    else
                    if (_objectSnapSurface.SurfaceType == SnapSurfaceType.ObjectCollider && Settings.SnapCenterToCenterForObjectSurface && !Settings.UseOriginalPivot)
                    {
                        SnapObjectHierarchyToCenterOfSnapSurface(hierarchyRoot, projectedBoxFacePivotPoints.CenterPoint, projectedBoxFacePivotPoints, offsetFromSnapSurface);
                    }
                    else
                    {
                        SnapObjectHierarchyPosition(hierarchyRoot, pivotPoint, _objectSnapSurface.GetSnapDestinationPointClosestToCursorPickPoint(), projectedBoxFacePivotPoints, offsetFromSnapSurface);
                    }
                    if (AllShortcutCombos.Instance.KeepSnappedHierarchyInSnapSurfaceArea.IsActive())
                    {
                        KeepSnappedHierarchyInSnapSurfaceArea(hierarchyRoot, projectedBoxFacePivotPoints);
                    }
                }

                if (Settings.EnableObjectToObjectSnap)
                {
                    SnapHierarchyToNearbyObjects(hierarchyRoot, projectedBoxFacePivotPoints);
                }
            }
        }
        private bool IsGameObjectPartiallyOverlapped(GameObject gameObject)
        {
            OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();

            if (worldOrientedBox.IsValid())
            {
                Polygon3D projectedBoxCornerPointsPoly = worldOrientedBox.Get3DPolygonFromCornerPointsProjectedOnPlane(Plane);
                if (OverlapsPolygon(projectedBoxCornerPointsPoly) &&
                    DoesWorldOrientedBoxIntersectOrResideOnShapeSurface(worldOrientedBox))
                {
                    return(true);
                }
            }

            return(false);
        }
        private List <GameObject> GetOverlappedGameObjectsForFullOverlap(List <GameObject> objectsOveralppedByEnclosingRect, Camera camera)
        {
            Ellipse2D ellipse = Ellipse;

            List <GameObject> overlappedGameObjects = new List <GameObject>(objectsOveralppedByEnclosingRect.Count);

            foreach (GameObject gameObject in objectsOveralppedByEnclosingRect)
            {
                OrientedBox worldOrientedBox = gameObject.gameObject.GetWorldOrientedBox();
                if (worldOrientedBox.IsValid() && ellipse.FullyContainsOrientedBoxCenterAndCornerPointsInScreenSpace(worldOrientedBox, camera))
                {
                    overlappedGameObjects.Add(gameObject);
                }
            }

            return(overlappedGameObjects);
        }
Exemple #9
0
        public GameObject MirrorGameObjectHierarchy(GameObject hierarchyRoot, Prefab sourcePrefab)
        {
            if (!IsActive)
            {
                return(null);
            }

            GameObject  mirroredHierarchyRoot     = null;
            OrientedBox hierarchyWorldOrientedBox = hierarchyRoot.GetHierarchyWorldOrientedBox();

            if (!hierarchyWorldOrientedBox.IsValid())
            {
                return(null);
            }

            OrientedBox mirroredBox = Mirroring.MirrorOrientedBox(_mirror.WorldPlane, hierarchyWorldOrientedBox, _mirrorRotation);

            if (!_allowIntersectionForMirroredObjects && ObjectQueries.IntersectsAnyObjectsInScene(mirroredBox, true))
            {
                return(null);
            }
            if (!_mirrorSpanningObjects && _mirror.WorldPlane.ClassifyOrientedBox(hierarchyWorldOrientedBox) == BoxPlaneClassificationResult.Spanning)
            {
                return(null);
            }

            Transform hierarchyRootTransform = hierarchyRoot.transform;

            if (sourcePrefab != null)
            {
                mirroredHierarchyRoot = Octave3DScene.Get().InstantiateObjectHierarchyFromPrefab(sourcePrefab, hierarchyRootTransform.position, hierarchyRootTransform.rotation, hierarchyRootTransform.lossyScale);
            }
            else
            {
                mirroredHierarchyRoot = hierarchyRoot.CloneAsWorkingObject(hierarchyRoot.transform.parent);
            }

            mirroredHierarchyRoot.ApplyTransformDataToRootChildren(hierarchyRoot);

            Mirroring.MirrorObjectHierarchyTransform(_mirror.WorldPlane, mirroredHierarchyRoot, _mirrorRotation);

            return(mirroredHierarchyRoot);
        }
Exemple #10
0
        public static void MirrorObjectHierarchyTransform(Plane mirrorPlane, GameObject root, bool mirrorRotation)
        {
            Transform rootTransform = root.transform;

            OrientedBox hierarchyWorldOrientedBox = root.GetHierarchyWorldOrientedBox();

            if (!hierarchyWorldOrientedBox.IsValid())
            {
                return;
            }

            if (mirrorRotation)
            {
                MirrorTransformRotation(mirrorPlane, rootTransform);
            }

            Vector3 mirroredCenter = MirrorPosition(mirrorPlane, hierarchyWorldOrientedBox.Center);

            rootTransform.position = ObjectPositionCalculator.CalculateObjectHierarchyPosition(root, mirroredCenter, rootTransform.lossyScale, rootTransform.rotation);
        }
Exemple #11
0
        public void UpdateProjectedBoxFacePivotPoints(GameObject hierarchyRoot, ProjectedBoxFacePivotPoints projectedBoxFacePivotPoints, bool keepCurrentSnapSurface)
        {
            OrientedBox hierarchyWorldOrientedBox = hierarchyRoot.GetHierarchyWorldOrientedBox();

            if (!hierarchyWorldOrientedBox.IsValid())
            {
                return;
            }

            if (keepCurrentSnapSurface)
            {
                if (!_objectSnapSurface.IsValid)
                {
                    return;
                }
                projectedBoxFacePivotPoints.FromOrientedBoxAndSnapSurface(hierarchyWorldOrientedBox, _objectSnapSurface);
            }
            else
            {
                _objectSnapSurface.FromMouseCursorRayHit(GetCursorRayHit());
                projectedBoxFacePivotPoints.FromOrientedBoxAndSnapSurface(hierarchyWorldOrientedBox, _objectSnapSurface);
            }
        }
Exemple #12
0
        public void UpdateForMouseMovement()
        {
            if (_state == State.Inactive)
            {
                return;
            }

            if (MouseButtonStates.Instance.IsMouseButtonDown(MouseButton.Left))
            {
                _state = State.Snap;
            }
            else
            {
                _state = State.SelectPivot;
            }

            if (_state == State.SelectPivot && _selectedParents.Count != 0)
            {
                Camera  camera   = SceneViewCamera.Camera;
                Vector2 mousePos = Event.current.InvMousePos(camera);

                _isPivotAvailable = false;
                float minDistanceSq = float.MaxValue;
                foreach (var parent in _selectedParents)
                {
                    if (parent == null)
                    {
                        continue;
                    }

                    OrientedBox worldOOBB = parent.GetHierarchyWorldOrientedBox();
                    if (worldOOBB.IsValid())
                    {
                        List <Vector3> centerAndCorners = worldOOBB.GetCenterAndCornerPoints();
                        List <Vector2> oobbScreenPts    = Vector2Extensions.GetScreenPoints(centerAndCorners, camera);

                        for (int ptIndex = 0; ptIndex < centerAndCorners.Count; ++ptIndex)
                        {
                            Vector3 worldPt  = centerAndCorners[ptIndex];
                            Vector2 screenPt = oobbScreenPts[ptIndex];
                            float   distSq   = (mousePos - screenPt).sqrMagnitude;
                            if (distSq < minDistanceSq)
                            {
                                minDistanceSq     = distSq;
                                _pivot            = worldPt;
                                _isPivotAvailable = true;
                            }
                        }
                    }
                }
            }
            else
            if (_state == State.Snap && _isPivotAvailable)
            {
                GameObjectExtensions.RecordObjectTransformsForUndo(_selectedParents);
                MouseCursorRayHit cursorHit = MouseCursor.Instance.GetCursorRayHitForGridCell();
                if (cursorHit.WasACellHit)
                {
                    Camera         camera          = SceneViewCamera.Camera;
                    Vector2        mousePos        = Event.current.InvMousePos(camera);
                    GridCellRayHit cellRayHit      = cursorHit.GridCellRayHit;
                    Vector3        snapDestination = Vector3Extensions.GetClosestPointToPoint(cellRayHit.HitCell.Quad.GetCenterAndCornerPoints(), cellRayHit.HitPoint);

                    Vector3 moveVector = snapDestination - _pivot;
                    foreach (var parent in _selectedParents)
                    {
                        if (parent != null)
                        {
                            parent.transform.position += moveVector;
                        }
                    }

                    _pivot = snapDestination;

                    ObjectSelection.Get().ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated();
                }
            }
        }
Exemple #13
0
        public override void Render(List <GameObject> selectedObjects)
        {
            ObjectSelectionRenderSettings                   selectionRenderSettings                   = ObjectSelectionRenderSettings.Get();
            ObjectSelectionBoxRenderModeSettings            selectionBoxRenderModeSettings            = selectionRenderSettings.BoxRenderModeSettings;
            ObjectSelectionBoxCornerEdgesRenderModeSettings selectionBoxCornerEdgesRenderModeSettings = selectionBoxRenderModeSettings.CornerEdgesRenderModeSettings;

            Color boxColor  = selectionBoxRenderModeSettings.BoxColor;
            Color edgeColor = selectionBoxRenderModeSettings.EdgeColor;
            float boxScale  = selectionBoxRenderModeSettings.BoxScale;

            bool renderBoxes = boxColor.a != 0.0f;
            bool renderEdges = edgeColor.a != 0.0f;

            if (!renderBoxes && !renderEdges)
            {
                return;
            }

            // Note: Code duplication is intentional here in order to avoid further abstractions which may hinder performance.
            if (selectionBoxRenderModeSettings.EdgeRenderMode == ObjectSelectionBoxEdgeRenderMode.Wire)
            {
                if (renderBoxes && renderEdges)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBox(worldOrientedBox, boxColor);
                            GizmosEx.RenderOrientedBoxEdges(worldOrientedBox, edgeColor);
                        }
                    }
                }
                else
                if (renderEdges && !renderBoxes)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBoxEdges(worldOrientedBox, edgeColor);
                        }
                    }
                }
                else
                if (renderBoxes && !renderEdges)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBox(worldOrientedBox, boxColor);
                        }
                    }
                }
            }
            else
            if (selectionBoxRenderModeSettings.EdgeRenderMode == ObjectSelectionBoxEdgeRenderMode.CornerEdges)
            {
                float cornerEdgeLengthPercentage = selectionBoxCornerEdgesRenderModeSettings.CornerEdgeLengthPercentage;
                if (renderBoxes && renderEdges)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBox(worldOrientedBox, boxColor);
                            GizmosEx.RenderOrientedBoxCornerEdges(worldOrientedBox, cornerEdgeLengthPercentage, edgeColor);
                        }
                    }
                }
                else
                if (renderEdges && !renderBoxes)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBoxCornerEdges(worldOrientedBox, cornerEdgeLengthPercentage, edgeColor);
                        }
                    }
                }
                else
                if (renderBoxes && !renderEdges)
                {
                    foreach (GameObject gameObject in selectedObjects)
                    {
                        if (!gameObject.activeInHierarchy)
                        {
                            continue;
                        }

                        OrientedBox worldOrientedBox = gameObject.GetWorldOrientedBox();
                        if (worldOrientedBox.IsValid())
                        {
                            worldOrientedBox.Scale *= boxScale;
                            GizmosEx.RenderOrientedBox(worldOrientedBox, boxColor);
                        }
                    }
                }
            }
        }