Exemple #1
0
        private void Rotate(float angle, Vector3 axis)
        {
            var selectedParents = GameObjectExtensions.GetParents(_selectedObjects.HashSet);

            GameObjectExtensions.RecordObjectTransformsForUndo(selectedParents);
            if (Settings.RotateAroundSelectionCenter)
            {
                Vector3 selectionCenter = GetWorldCenter();
                foreach (var parent in selectedParents)
                {
                    parent.RotateHierarchyBoxAroundPoint(angle, axis, selectionCenter);
                }
            }
            else
            {
                foreach (var parent in selectedParents)
                {
                    Box worldAABB = parent.GetHierarchyWorldBox();
                    if (worldAABB.IsValid())
                    {
                        parent.RotateHierarchyBoxAroundPoint(angle, axis, worldAABB.Center);
                    }
                }
            }
        }
Exemple #2
0
        public static void AlignSelectionToAxis(Axis axis)
        {
            int axisIndex = (int)axis;

            List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
            List <GameObject> selectedParents    = GameObjectExtensions.GetParents(allSelectedObjects);

            if (selectedParents.Count == 0)
            {
                return;
            }

            float average = 0.0f;

            foreach (var parent in selectedParents)
            {
                average += parent.transform.position[axisIndex];
            }
            average /= selectedParents.Count;

            GameObjectExtensions.RecordObjectTransformsForUndo(selectedParents);
            foreach (var parent in selectedParents)
            {
                Transform parentTransform = parent.transform;
                Vector3   alignedPosition = parentTransform.position;
                alignedPosition[axisIndex] = average;

                parentTransform.position = alignedPosition;
            }
        }
        public void Begin()
        {
            if (_state != State.Inactive)
            {
                return;
            }

            _state           = State.SelectPivot;
            _selectedParents = GameObjectExtensions.GetParents(ObjectSelection.Get().GetAllSelectedGameObjects());
        }
Exemple #4
0
        private void SetWorldRotation(Quaternion rotation)
        {
            var selectedParents = GameObjectExtensions.GetParents(_selectedObjects.HashSet);

            GameObjectExtensions.RecordObjectTransformsForUndo(selectedParents);
            foreach (var parent in selectedParents)
            {
                parent.transform.rotation = rotation;
            }
        }
Exemple #5
0
        public void Begin()
        {
            if (_isActive)
            {
                return;
            }

            _allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
            _selectedParents    = GameObjectExtensions.GetParents(_allSelectedObjects);
            _rayCastObjectMask.ObjectCollectionMask.Mask(_allSelectedObjects);
            _isActive = true;
        }
Exemple #6
0
        public static void DuplicateSelection()
        {
            if (ObjectSelection.Get().NumberOfSelectedObjects == 0)
            {
                return;
            }

            ObjectSelection   objectSelection    = ObjectSelection.Get();
            List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects();
            List <GameObject> selectedParents    = GameObjectExtensions.GetParents(allSelectedObjects);

            var clonedObjects = new List <GameObject>();
            var clonedParents = new List <GameObject>();

            foreach (GameObject parent in selectedParents)
            {
                GameObject prefab          = parent.GetSourcePrefab();
                Transform  parentTransform = parent.transform;

                if (prefab == null)
                {
                    GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent);
                    //clonedParent.transform.parent = parent.transform.parent;
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                    Octave3DScene.Get().RegisterObjectHierarchy(clonedParent);
                    clonedParents.Add(clonedParent);
                }
                else
                {
                    GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale);
                    clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf());
                    Octave3DScene.Get().RegisterObjectHierarchy(clonedParent);
                    clonedParents.Add(clonedParent);
                }
            }

            if (clonedObjects.Count != 0)
            {
                objectSelection.Clear();
                objectSelection.AddGameObjectCollectionToSelection(clonedObjects);
                objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated();
            }

            if (clonedParents.Count != 0)
            {
                ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedParents, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection);
            }

            SceneViewCamera.Instance.SetObjectVisibilityDirty();
        }
Exemple #7
0
        public void CombineSelectedObjects(List <GameObject> selectedObjects, List <GameObject> ignoreObjects)
        {
            if (_combineSettings == null || selectedObjects == null)
            {
                return;
            }
            if (selectedObjects.Count == 0)
            {
                EditorUtility.DisplayDialog("No Selected Objects", "The mesh combine process can not start because there are no objects currently selected.", "Ok");
                return;
            }

            List <GameObject> allMeshObjects = new List <GameObject>(selectedObjects.Count);

            foreach (var selectedObject in selectedObjects)
            {
                if (selectedObject.HasMeshFilterWithValidMesh())
                {
                    allMeshObjects.Add(selectedObject);
                }
            }
            if (ignoreObjects != null && ignoreObjects.Count != 0)
            {
                allMeshObjects.RemoveAll(item => ignoreObjects.Contains(item));
            }

            List <MeshCombineMaterial> meshCombineMaterials = GetMeshCombineMaterials(allMeshObjects, null);

            if (meshCombineMaterials.Count == 0)
            {
                EditorUtility.DisplayDialog("No Combinable Objects", "The current selection does not contain any objects which can be combined. Please check the following: \n\r" +
                                            "-the selection must contain mesh objects; \n\r " +
                                            "-check the \'Combine static/dynamic meshes\' toggles to ensure that the objects can actually be combined; \n\r" +
                                            "-if the objects belong to a hierarchy, make sure to unhceck the \'Ignore objects in hierarchies\' toggle.", "Ok");
                return;
            }

            Combine(meshCombineMaterials, _combineSettings.SelectionCombineDestinationParent);

            if (_combineSettings.SelCombineMode == MeshCombineSettings.CombineMode.Replace)
            {
                List <GameObject> parents = GameObjectExtensions.GetParents(selectedObjects);
                foreach (var parent in parents)
                {
                    UndoEx.DestroyObjectImmediate(parent);
                }
            }

            EditorUtility.DisplayDialog("Done!", "Mesh objects combined successfully!", "Ok");
        }
        public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint)
        {
            if (CanTransformObjects())
            {
                Vector3 newScaleAccumulatedByGizmoInteraction = Handles.ScaleHandle(_scaleAccumulatedByGizmoInteraction, _worldPosition, _worldRotation, HandleUtility.GetHandleSize(_worldPosition));
                if (newScaleAccumulatedByGizmoInteraction != _scaleAccumulatedByGizmoInteraction)
                {
                    GameObjectExtensions.RecordObjectTransformsForUndo(_targetObjects);
                    List <GameObject> topParents = GameObjectExtensions.GetParents(_targetObjects);

                    Vector3 scaleFactor = CalculateScaleFactorUsedToScaleObjects(newScaleAccumulatedByGizmoInteraction);
                    ScaleObjectsBySpecifiedPivotPoint(transformPivotPoint, scaleFactor, topParents);

                    _scaleAccumulatedByGizmoInteraction = newScaleAccumulatedByGizmoInteraction;
                    GizmoTransformedObjectsMessage.SendToInterestedListeners(this);
                }
            }
        }
Exemple #9
0
        public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint)
        {
            if (CanTransformObjects())
            {
                Vector3 newGizmoWorldPosition = Handles.PositionHandle(_worldPosition, _worldRotation);
                if (newGizmoWorldPosition != _worldPosition)
                {
                    GameObjectExtensions.RecordObjectTransformsForUndo(_targetObjects);
                    List <GameObject> topParents = GameObjectExtensions.GetParents(_targetObjects);

                    MoveObjects(newGizmoWorldPosition, topParents);

                    UndoEx.RecordForToolAction(this);
                    _worldPosition = newGizmoWorldPosition;
                    GizmoTransformedObjectsMessage.SendToInterestedListeners(this);
                }
            }
        }
Exemple #10
0
        public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint)
        {
            if (CanTransformObjects())
            {
                Quaternion newWorldRotationAccumulatedByGizmoInteraction = Handles.RotationHandle(_worldRotation, _worldPosition);
                if (newWorldRotationAccumulatedByGizmoInteraction.eulerAngles != _worldRotation.eulerAngles)
                {
                    GameObjectExtensions.RecordObjectTransformsForUndo(_targetObjects);
                    List <GameObject> topParents = GameObjectExtensions.GetParents(_targetObjects);

                    Quaternion rotationAmount = CalculateRotationAmount(newWorldRotationAccumulatedByGizmoInteraction);
                    RotateObjectsAroundSpecifiedPivotPoint(transformPivotPoint, rotationAmount, topParents);

                    UndoEx.RecordForToolAction(this);
                    _worldRotation = newWorldRotationAccumulatedByGizmoInteraction;
                    GizmoTransformedObjectsMessage.SendToInterestedListeners(this);
                }
            }
        }
Exemple #11
0
        public void RenderGizmos()
        {
            if (_objectVertexSnapSession.IsActive)
            {
                _objectVertexSnapSessionRenderer.RenderGizmos(_objectVertexSnapSession, ObjectVertexSnapSessionRenderSettings);
            }

            SelectionShape.RenderGizmos();
            _selectionGridSnapSession.RenderGizmos();
            _selectionGrabSession.RenderGizmos();

            IObjectSelectionRenderer objectSelectionRenderer = ObjectSelectionRendererFactory.Create();

            objectSelectionRenderer.Render(GetAllSelectedGameObjects());

            if (Mirror.IsActive)
            {
                Mirror.RenderGizmos();

                List <GameObject> topLevelParentsInSelection = GameObjectExtensions.GetParents(_selectedObjects.HashSet);
                Mirror.RenderMirroredEntityOrientedBoxes(GameObjectExtensions.GetHierarchyWorldOrientedBoxes(topLevelParentsInSelection));
            }
        }
        public override void RenderHandles(TransformGizmoPivotPoint transformPivotPoint)
        {
            Box targetWorldAABB = Box.FromObjectWorldAABB(_targetObjects);

            //Color[] axesColors = new Color[] { Handles.xAxisColor, Handles.xAxisColor, Handles.yAxisColor, Handles.yAxisColor, Handles.zAxisColor, Handles.zAxisColor };
            //Vector3[] axesDirs = new Vector3[] { Vector3.right, -Vector3.right, Vector3.up, -Vector3.up, Vector3.forward, -Vector3.forward };
            //float[] snapValues = new float[] { targetWorldAABB.Size.x, targetWorldAABB.Size.x, targetWorldAABB.Size.y, targetWorldAABB.Size.y, targetWorldAABB.Size.z, targetWorldAABB.Size.z };

            Color[]   axesColors = new Color[] { Handles.xAxisColor, Handles.yAxisColor, Handles.zAxisColor };
            Vector3[] axesDirs   = new Vector3[] { Vector3.right, Vector3.up, Vector3.forward };
            float[]   snapValues = new float[] { targetWorldAABB.Size.x *_snapSteps[0], targetWorldAABB.Size.y *_snapSteps[1], targetWorldAABB.Size.z *_snapSteps[2] };

            Vector3 oldPosition = WorldPosition;

            for (int axisIndex = 0; axisIndex < 3; ++axisIndex)
            {
                Handles.color = axesColors[axisIndex];
                Vector3 newGizmoPosition = Handles.Slider(oldPosition, axesDirs[axisIndex], HandleUtility.GetHandleSize(oldPosition), Handles.ArrowHandleCap, snapValues[axisIndex]);
                if (newGizmoPosition != oldPosition)
                {
                    Vector3 moveOffset = (newGizmoPosition - oldPosition);
                    WorldPosition = newGizmoPosition;
                    oldPosition   = newGizmoPosition;

                    if (Event.current.control)
                    {
                        float absNumGroups   = Mathf.Abs(moveOffset[axisIndex] / snapValues[axisIndex]);
                        float absFractional  = absNumGroups - (int)absNumGroups;
                        int   numCloneGroups = Mathf.FloorToInt(absNumGroups);
                        if (Mathf.Abs(absFractional - 1.0f) < 1e-4f)
                        {
                            ++numCloneGroups;
                        }

                        for (int cloneGroupIndex = 0; cloneGroupIndex < numCloneGroups; ++cloneGroupIndex)
                        {
                            var clonedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(ObjectActions.Duplicate(_targetObjects));
                            ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedRoots, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection);
                            ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(ObjectSelection.Get().Mirror.MirrorGameObjectHierarchies(clonedRoots), ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection);

                            if (cloneGroupIndex != 0)
                            {
                                Vector3 offset = axesDirs[axisIndex] * snapValues[axisIndex] * cloneGroupIndex *Mathf.Sign(moveOffset[axisIndex]);

                                foreach (var root in clonedRoots)
                                {
                                    root.transform.position += offset;
                                }
                            }
                        }
                    }

                    GameObjectExtensions.RecordObjectTransformsForUndo(_targetObjects);
                    var targetParents = GameObjectExtensions.GetParents(_targetObjects);
                    foreach (var parent in targetParents)
                    {
                        parent.transform.position += moveOffset;
                    }
                }
            }

            Handles.BeginGUI();
            GUI.BeginGroup(new Rect(0.0f, -15.0f, 200.0f, 200.0f));

            var content = new GUIContent();

            string[] snapStepLabels = new string[] { "Snap step X", "Snap step Y", "Snap step Z" };

            for (int axisIndex = 0; axisIndex < 3; ++axisIndex)
            {
                EditorGUILayout.BeginHorizontal();
                content.text = snapStepLabels[axisIndex];
                EditorGUILayout.LabelField(content, GUILayout.Width(80.0f));
                int newInt = EditorGUILayout.IntField("", _snapSteps[axisIndex], GUILayout.Width(50.0f));
                if (newInt != _snapSteps[axisIndex])
                {
                    UndoEx.RecordForToolAction(this);
                    SetSnapStep(axisIndex, newInt);
                }
                EditorGUILayout.EndHorizontal();
            }

            GUI.EndGroup();
            Handles.EndGUI();
        }