public override void Extrude(float distance)
        {
            m_faceSelection.BeginChange();

            ProBuilderMesh[] meshes = m_faceSelection.Meshes.OrderBy(m => m == m_faceSelection.LastMesh).ToArray();
            foreach (ProBuilderMesh mesh in meshes)
            {
                IList <Face> faces = m_faceSelection.GetFaces(mesh).ToArray();
                for (int i = 0; i < faces.Count; ++i)
                {
                    m_faceSelection.Remove(faces[i]);
                }

                mesh.Extrude(faces, ExtrudeMethod.FaceNormal, distance);

                for (int i = 0; i < faces.Count; ++i)
                {
                    m_faceSelection.Add(mesh, faces[i]);
                }

                mesh.ToMesh();
                mesh.Refresh();
            }

            m_faceSelection.EndChange();

            if (distance != 0.0f)
            {
                m_faceSelection.Synchronize(
                    m_faceSelection.GetCenterOfMass(),
                    m_faceSelection.LastPosition + m_faceSelection.LastNormal * distance);
            }
        }
Ejemplo n.º 2
0
        public override MeshSelection Select(Camera camera, Vector3 pointer, bool shift)
        {
            MeshSelection selection = null;
            MeshAndFace   result    = PBUtility.PickFace(camera, pointer);

            if (result.face != null)
            {
                int faceIndex = result.mesh.faces.IndexOf(result.face);
                if (m_faceSelection.IsSelected(faceIndex))
                {
                    if (shift)
                    {
                        m_faceSelection.Remove(faceIndex);
                        selection = new MeshSelection();
                        selection.UnselectedFaces.Add(result.mesh, new[] { faceIndex });
                    }
                    else
                    {
                        selection = ReadSelection();
                        selection = null;
                    }
                }
                else
                {
                    if (shift)
                    {
                        selection = new MeshSelection();
                    }
                    else
                    {
                        selection = ReadSelection();
                        m_faceSelection.Clear();
                    }

                    m_faceSelection.Add(result.mesh, faceIndex);
                    selection.SelectedFaces.Add(result.mesh, new[] { faceIndex });
                }
            }
            else
            {
                if (!shift)
                {
                    selection = ReadSelection();
                    if (selection.UnselectedFaces.Count == 0)
                    {
                        selection = null;
                    }
                    m_faceSelection.Clear();
                }
            }
            return(selection);
        }
Ejemplo n.º 3
0
        public override MeshSelection Select(Camera camera, Vector3 pointer, bool shift, bool ctrl)
        {
            MeshSelection selection = null;
            MeshAndFace   result    = PBUtility.PickFace(camera, pointer);

            if (result.face != null)
            {
                if (ctrl)
                {
                    int          submeshIndex      = result.face.submeshIndex;
                    IList <Face> faces             = result.mesh.faces;
                    List <int>   sameMaterialFaces = new List <int>();

                    bool wasSelected   = false;
                    bool wasUnselected = false;

                    m_faceSelection.BeginChange();
                    for (int i = 0; i < faces.Count; ++i)
                    {
                        Face face = faces[i];
                        if (face.submeshIndex == submeshIndex)
                        {
                            sameMaterialFaces.Add(i);

                            if (!m_faceSelection.IsSelected(result.mesh, i))
                            {
                                m_faceSelection.Add(result.mesh, i);
                                wasUnselected = true;
                            }
                            else
                            {
                                wasSelected = true;
                            }
                        }
                    }

                    if (wasSelected && !wasUnselected)
                    {
                        for (int i = 0; i < sameMaterialFaces.Count; ++i)
                        {
                            m_faceSelection.Remove(result.mesh, sameMaterialFaces[i]);
                        }

                        selection = new MeshSelection();
                        selection.UnselectedFaces.Add(result.mesh, sameMaterialFaces.ToArray());
                    }
                    else
                    {
                        selection = new MeshSelection();
                        selection.SelectedFaces.Add(result.mesh, sameMaterialFaces.ToArray());
                    }

                    m_faceSelection.EndChange();
                }
                else
                {
                    int faceIndex = result.mesh.faces.IndexOf(result.face);
                    if (m_faceSelection.IsSelected(result.mesh, faceIndex))
                    {
                        if (shift)
                        {
                            m_faceSelection.Remove(result.mesh, faceIndex);
                            selection = new MeshSelection();
                            selection.UnselectedFaces.Add(result.mesh, new[] { faceIndex });
                        }
                        else
                        {
                            //selection = ReadSelection();
                            selection = null;
                        }
                    }
                    else
                    {
                        if (shift)
                        {
                            selection = new MeshSelection();
                        }
                        else
                        {
                            selection = ReadSelection();
                            m_faceSelection.Clear();
                        }

                        m_faceSelection.Add(result.mesh, faceIndex);
                        selection.SelectedFaces.Add(result.mesh, new[] { faceIndex });
                    }
                }
            }
            else
            {
                if (!shift)
                {
                    selection = ReadSelection();
                    if (selection.UnselectedFaces.Count == 0)
                    {
                        selection = null;
                    }
                    m_faceSelection.Clear();
                }
            }
            return(selection);
        }