コード例 #1
0
        private void OnBeginMove(BaseHandle positionHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                positionHandle.EnableUndo = false;

                m_rte.Undo.BeginRecord();
                if (UVEditingMode)
                {
                    m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.offset));
                }
                else
                {
                    m_rte.Undo.BeginRecordTransform(m_pivot);
                    m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position));
                    m_shift = m_rte.Input.GetKey(KeyCode.LeftShift);
                    if (m_shift)
                    {
                        MeshEditorState oldState = meshEditor.GetState();
                        meshEditor.Extrude();
                        this.RecordState(meshEditor, oldState, null, false);
                    }
                }

                m_rte.Undo.EndRecord();
                m_initialUVOffset = UV.offset;
            }
        }
コード例 #2
0
        private void RunStateChangeAction(Action <IMeshEditor> action, bool clearSelection)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                m_rte.Undo.BeginRecord();
                m_rte.Undo.BeginRecordTransform(m_pivot);
                m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position));

                MeshEditorState oldState = meshEditor.GetState();
                action(meshEditor);
                MeshEditorState newState  = meshEditor.GetState();
                MeshSelection   selection = null;
                if (clearSelection)
                {
                    selection = meshEditor.ClearSelection();
                }
                this.RecordState(meshEditor, oldState, newState);
                if (selection != null)
                {
                    RecordSelection(meshEditor, selection);
                }
                TrySelectPivot(meshEditor);
                m_rte.Undo.EndRecord();
            }
        }
コード例 #3
0
        private void RefreshSelectionAndPivotPoint()
        {
            m_selection.Clear();

            IMeshEditor editor = m_tool.GetEditor();

            if (editor == null)
            {
                return;
            }

            MeshSelection meshSelection = editor.GetSelection();

            if (meshSelection != null)
            {
                foreach (PBMesh mesh in meshSelection.GetSelectedMeshes())
                {
                    ManualUVSelection uvSelection = new ManualUVSelection(mesh.gameObject);
                    m_selection.Add(uvSelection);

                    if (MeshSelected != null)
                    {
                        MeshSelected(uvSelection);
                    }
                }

                Select(meshSelection);
            }

            RefreshPivotPoint();
        }
コード例 #4
0
        private void RecordStateAndSelection(IMeshEditor meshEditor, MeshSelection selection, MeshEditorState oldState, MeshEditorState newState)
        {
            UndoRedoCallback redo = record =>
            {
                if (newState != null)
                {
                    meshEditor.ClearSelection();
                    meshEditor.SetState(newState);
                    meshEditor.ApplySelection(selection);
                    m_pivot.position = meshEditor.Position;
                    m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal);
                    OnSelectionChanged();
                    return(true);
                }
                return(false);
            };

            UndoRedoCallback undo = record =>
            {
                if (oldState != null)
                {
                    meshEditor.ClearSelection();
                    meshEditor.SetState(oldState);
                    meshEditor.RollbackSelection(selection);
                    m_pivot.position = meshEditor.Position;
                    m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal);
                    OnSelectionChanged();
                    return(true);
                }
                return(false);
            };

            m_rte.Undo.CreateRecord(redo, undo);
            OnSelectionChanged();
        }
コード例 #5
0
        private void OnBoxSelection(object sender, BoxSelectionArgs e)
        {
            IMeshEditor meshEditor = m_meshEditors[(int)m_mode];

            if (meshEditor == null)
            {
                return;
            }

            RuntimeWindow window = m_rte.ActiveWindow;

            Vector2       min  = m_boxSelection.SelectionBounds.min;
            Vector2       max  = m_boxSelection.SelectionBounds.max;
            RectTransform rt   = window.GetComponent <RectTransform>();
            Rect          rect = new Rect(new Vector2(min.x, rt.rect.height - max.y), m_boxSelection.SelectionBounds.size);

            MeshSelection selection = meshEditor.Select(window.Camera, rect, e.GameObjects.Where(g => g.GetComponent <ExposeToEditor>() != null).ToArray(), MeshEditorSelectionMode.Add);

            m_rte.Undo.BeginRecord();

            if (selection != null)
            {
                RecordSelection(meshEditor, selection);
            }

            m_pivot.position = meshEditor.Position;
            m_pivot.rotation = GetPivotRotation(meshEditor);

            TrySelectPivot(meshEditor);

            m_rte.Undo.EndRecord();
        }
コード例 #6
0
        private void OnEndMove(BaseHandle positionHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                positionHandle.EnableUndo = true;

                m_rte.Undo.BeginRecord();

                if (UVEditingMode)
                {
                    m_pivot.position = meshEditor.Position;
                    m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.offset));
                }
                else
                {
                    MeshEditorState newState = meshEditor.GetState();
                    this.RecordState(meshEditor, null, newState, false, false);

                    m_rte.Undo.EndRecordTransform(m_pivot);
                    m_rte.Undo.RecordValue(meshEditor, Strong.PropertyInfo((IMeshEditor x) => x.Position));
                }
                m_rte.Undo.EndRecord();
            }
        }
コード例 #7
0
        public static void RecordState(this IProBuilderTool tool, IMeshEditor meshEditor, MeshEditorState oldState, MeshEditorState newState,
                                       bool oldStateChanged = true, bool newStateChanged = true)
        {
            UndoRedoCallback redo = record =>
            {
                if (newState != null)
                {
                    meshEditor.SetState(newState);
                    return(newStateChanged);
                }
                return(false);
            };

            UndoRedoCallback undo = record =>
            {
                if (oldState != null)
                {
                    meshEditor.SetState(oldState);
                    return(oldStateChanged);
                }
                return(false);
            };

            IOC.Resolve <IRTE>().Undo.CreateRecord(redo, undo);
        }
コード例 #8
0
        public void ApplyMaterial(Material material, Camera camera, Vector3 mousePosition)
        {
            IMeshEditor editor = GetEditor();

            if (editor != null)
            {
                MeshSelection       selection = editor.GetSelection();
                ApplyMaterialResult result    = m_materialEditor.ApplyMaterial(material, selection, camera, mousePosition);
                RecordApplyMaterialResult(result);
            }
            else
            {
                GameObject gameObject = PBUtility.PickObject(camera, mousePosition);
                if (gameObject != null)
                {
                    if (m_rte.Selection.IsSelected(gameObject))
                    {
                        ApplyMaterialToSelectedGameObjects(material);
                    }
                    else
                    {
                        ApplyMaterialResult result = m_materialEditor.ApplyMaterial(material, gameObject);
                        RecordApplyMaterialResult(result);
                    }
                }
            }
        }
コード例 #9
0
        private void OnSceneLoading()
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                meshEditor.ClearSelection();
            }
        }
コード例 #10
0
        private void OnUVChanged()
        {
            IMeshEditor editor = GetEditor();

            if (editor != null)
            {
                MeshSelection selection = editor.GetSelection();
                m_autoUVEditor.ApplySettings(m_uv, selection);
            }
        }
コード例 #11
0
        private void OnSceneLoading()
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                meshEditor.ClearSelection();
            }

            Mode = ProBuilderToolMode.Object;
        }
コード例 #12
0
        public static void Extrude(this IProBuilderTool tool, float distance)
        {
            IMeshEditor     meshEditor = tool.GetEditor();
            MeshEditorState oldState   = meshEditor.GetState();

            meshEditor.Extrude(distance);
            MeshEditorState newState = meshEditor.GetState();

            tool.UpdatePivot();
            tool.RecordState(meshEditor, oldState, newState);
        }
コード例 #13
0
 private void TrySelectPivot(IMeshEditor meshEditor)
 {
     if (meshEditor.HasSelection)
     {
         m_rte.Selection.activeObject = m_pivot.gameObject;
     }
     else
     {
         m_rte.Selection.activeObject = null;
     }
 }
コード例 #14
0
        public void SelectHoles()
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                MeshSelection selection = meshEditor.SelectHoles();
                if (selection != null)
                {
                    RecordSelection(meshEditor, selection);
                }
            }
        }
コード例 #15
0
        private void OnSelectionChanged()
        {
            IMeshEditor editor = GetEditor();

            if (editor != null)
            {
                MeshSelection        selection = editor.GetSelection();
                PBAutoUnwrapSettings settings  = m_autoUVEditor.GetSettings(selection);
                m_uv.CopyFrom(settings);
            }

            if (SelectionChanged != null)
            {
                SelectionChanged();
            }
        }
コード例 #16
0
        public static void RecordStateWithAction(this IProBuilderTool tool, IMeshEditor meshEditor, MeshEditorState oldState, Action <Record> newState, bool changed = true)
        {
            UndoRedoCallback redo = record =>
            {
                newState(record);
                return(changed);
            };

            UndoRedoCallback undo = record =>
            {
                meshEditor.SetState(oldState);
                return(true);
            };

            IOC.Resolve <IRTE>().Undo.CreateRecord(redo, undo);
        }
コード例 #17
0
        private void OnSelectionChanged()
        {
            m_selection = null;
            IMeshEditor meshEditor = m_proBuilderTool.GetEditor();

            if (meshEditor == null)
            {
                return;
            }

            m_selection = meshEditor.GetSelection();

            ClearSmoothGroups();
            CreateSmoothGroups();
            UpdateEditorsPanel();
        }
コード例 #18
0
        private void OnBeginScale(BaseHandle scaleHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                scaleHandle.EnableUndo = false;
                m_pivot.localScale     = Vector3.one;
                m_initialUVScale       = UV.scale;
                if (UVEditingMode)
                {
                    m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.scale));
                }
                meshEditor.BeginScale();
            }
        }
コード例 #19
0
        private void OnClear(object sender, EventArgs e)
        {
            SmoothGroupEditor editor = (SmoothGroupEditor)sender;
            PBMesh            pbMesh = editor.Data.PBMesh;

            IMeshEditor     meshEditor = m_proBuilderTool.GetEditor();
            MeshEditorState oldState   = meshEditor.GetState(false);

            PBSmoothing.ClearGroup(pbMesh, meshEditor.GetSelection());

            m_smoothGroups[pbMesh].Rebuild(pbMesh);
            m_proBuilderTool.TryUpdatePivotTransform();

            MeshEditorState newState = meshEditor.GetState(false);

            m_proBuilderTool.RecordState(oldState, newState, true);
        }
コード例 #20
0
        public void ApplyMaterial(Material material)
        {
            IMeshEditor editor = GetEditor();

            if (editor != null)
            {
                MeshSelection selection = editor.GetSelection();
                //  m_rte.Undo.BeginRecord();

                ApplyMaterialResult result = m_materialEditor.ApplyMaterial(material, selection);
                RecordApplyMaterialResult(result);
            }
            else
            {
                ApplyMaterialToSelectedGameObjects(material);
            }
        }
コード例 #21
0
        private void UpdateEditorsPanel()
        {
            foreach (Transform child in m_contentPanel)
            {
                SmoothGroupEditor editor = child.GetComponent <SmoothGroupEditor>();
                Unsubscribe(editor);

                Destroy(child.gameObject);
            }

            IMeshEditor meshEditor = m_proBuilderTool.GetEditor();

            if (meshEditor == null)
            {
                return;
            }

            MeshSelection selection = meshEditor.GetSelection();

            if (selection == null)
            {
                return;
            }

            selection = selection.ToFaces(false);
            if (!selection.HasFaces)
            {
                return;
            }

            const int maxVisibleGroups = 8;
            int       index            = 0;

            foreach (PBMesh pbMesh in selection.GetSelectedMeshes())
            {
                index++;
                if (index == maxVisibleGroups)
                {
                    return;
                }

                SmoothGroupEditor editor = Instantiate(m_groupPrefab, m_contentPanel);
                editor.Data = m_smoothGroups[pbMesh];
                Subscribe(editor);
            }
        }
コード例 #22
0
        private void UpdateGlobalMode()
        {
            foreach (IMeshEditor editor in m_meshEditors)
            {
                if (editor == null)
                {
                    continue;
                }
                editor.GlobalMode = m_rte.Tools.PivotRotation == RuntimePivotRotation.Global;
            }

            IMeshEditor currentEditor = GetEditor();

            if (currentEditor != null)
            {
                m_pivot.rotation = GetPivotRotation(currentEditor);
            }
        }
コード例 #23
0
        private void OnBeginRotate(BaseHandle rotationHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                rotationHandle.EnableUndo = false;
                m_initialRotation         = GetPivotRotation(meshEditor);
                m_pivot.rotation          = m_initialRotation;
                m_initialRight            = m_pivot.TransformDirection(Vector3.right);
                m_initialUVRotation       = UV.rotation;
                if (UVEditingMode)
                {
                    m_rte.Undo.BeginRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.rotation));
                }
                meshEditor.BeginRotate(m_initialRotation);
            }
        }
コード例 #24
0
        private void UpdateCenterMode()
        {
            foreach (IMeshEditor editor in m_meshEditors)
            {
                if (editor == null)
                {
                    continue;
                }
                editor.CenterMode = m_rte.Tools.PivotMode == RuntimePivotMode.Center;
            }

            IMeshEditor meshEditor = m_meshEditors[(int)m_mode];

            if (meshEditor != null)
            {
                m_pivot.position = meshEditor.Position;
                m_pivot.rotation = GetPivotRotation(meshEditor);
            }
        }
コード例 #25
0
        private void OnEndRotate(BaseHandle rotationHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                rotationHandle.EnableUndo = true;

                Quaternion initialRotation = m_initialRotation;
                Quaternion endRotation     = m_pivot.rotation;
                meshEditor.EndRotate();

                Quaternion newStartRotation = GetPivotRotation(meshEditor);
                m_pivot.rotation = newStartRotation;

                if (UVEditingMode)
                {
                    m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.rotation));
                }
                else
                {
                    m_rte.Undo.CreateRecord(record =>
                    {
                        meshEditor.BeginRotate(initialRotation);
                        meshEditor.Rotate(endRotation);
                        meshEditor.EndRotate();

                        m_pivot.transform.rotation = newStartRotation;
                        return(true);
                    },
                                            record =>
                    {
                        meshEditor.BeginRotate(endRotation);
                        meshEditor.Rotate(initialRotation);
                        meshEditor.EndRotate();

                        m_pivot.transform.rotation = initialRotation;
                        return(true);
                    });
                }
            }
        }
コード例 #26
0
        public void UnselectFaces(Material material)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                MeshSelection selection = meshEditor.Unselect(material);
                m_rte.Undo.BeginRecord();

                if (selection != null)
                {
                    RecordSelection(meshEditor, selection);
                }

                m_pivot.position = meshEditor.Position;
                m_pivot.rotation = GetPivotRotation(meshEditor);

                TrySelectPivot(meshEditor);

                m_rte.Undo.EndRecord();
            }
        }
コード例 #27
0
        private void UpdateGlobalMode()
        {
            if (m_mode == ProBuilderToolMode.PolyShape)
            {
                return;
            }

            foreach (IMeshEditor editor in m_meshEditors)
            {
                if (editor == null)
                {
                    continue;
                }
                editor.GlobalMode = m_rte.Tools.PivotRotation == RuntimePivotRotation.Global;
            }

            IMeshEditor currentEditor = GetEditor();

            if (currentEditor != null)
            {
                m_pivot.rotation = GetPivotRotation(currentEditor);
            }
        }
コード例 #28
0
        private void RecordSelection(IMeshEditor meshEditor, MeshSelection selection)
        {
            UndoRedoCallback redo = record =>
            {
                meshEditor.ApplySelection(selection);
                m_pivot.position = meshEditor.Position;
                m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal);
                OnSelectionChanged();
                return(true);
            };

            UndoRedoCallback undo = record =>
            {
                meshEditor.RollbackSelection(selection);
                m_pivot.position = meshEditor.Position;
                m_pivot.rotation = GetPivotRotation(meshEditor);// Quaternion.LookRotation(meshEditor.Normal);
                OnSelectionChanged();
                return(true);
            };

            m_rte.Undo.CreateRecord(redo, undo);
            OnSelectionChanged();
        }
コード例 #29
0
        private void OnExpandSelection(object sender, EventArgs e)
        {
            IMeshEditor     meshEditor = m_proBuilderTool.GetEditor();
            MeshSelection   selection  = meshEditor.GetSelection();
            MeshEditorState oldState   = meshEditor.GetState(false);

            selection = PBSmoothing.ExpandSelection(selection);
            if (m_proBuilderTool.Mode == ProBuilderToolMode.Vertex)
            {
                selection = selection.ToVertices(false);
            }
            else if (m_proBuilderTool.Mode == ProBuilderToolMode.Edge)
            {
                selection = selection.ToEdges(false);
            }

            meshEditor.SetSelection(selection);
            m_proBuilderTool.TryUpdatePivotTransform();

            MeshEditorState newState = meshEditor.GetState(false);

            m_proBuilderTool.RecordState(oldState, newState, true);
        }
コード例 #30
0
        private void OnEndScale(BaseHandle scaleHandle)
        {
            IMeshEditor meshEditor = GetEditor();

            if (meshEditor != null)
            {
                scaleHandle.EnableUndo = true;
                meshEditor.EndScale();

                Vector3    newScale = m_pivot.localScale;
                Quaternion rotation = m_pivot.rotation;
                m_pivot.localScale = Vector3.one;

                if (UVEditingMode)
                {
                    m_rte.Undo.EndRecordValue(UV, Strong.PropertyInfo((PBAutoUnwrapSettings x) => x.scale));
                }
                else
                {
                    m_rte.Undo.CreateRecord(record =>
                    {
                        meshEditor.BeginScale();
                        meshEditor.Scale(newScale, rotation);
                        meshEditor.EndScale();
                        return(true);
                    },
                                            record =>
                    {
                        meshEditor.BeginScale();
                        meshEditor.Scale(new Vector3(1.0f / newScale.x, 1.0f / newScale.y, 1.0f / newScale.z), rotation);
                        meshEditor.EndRotate();
                        return(true);
                    });
                }
            }
        }