コード例 #1
0
        private void OnMeshSelected(ManualUVSelection uvSelection)
        {
            PBMesh mesh = uvSelection.Mesh;

            PBEdge[] meshEdges = mesh.Edges;
            Dictionary <int, List <int> > faceToEdge = new Dictionary <int, List <int> >();

            Tuple <int, int>[] edges = new Tuple <int, int> [meshEdges.Length];
            for (int i = 0; i < meshEdges.Length; ++i)
            {
                PBEdge edge = meshEdges[i];
                edges[i] = new Tuple <int, int>(edge.A, edge.B);

                List <int> edgeIndices;
                if (!faceToEdge.TryGetValue(edge.FaceIndex, out edgeIndices))
                {
                    edgeIndices = new List <int>();
                    faceToEdge.Add(edge.FaceIndex, edgeIndices);
                }

                edgeIndices.Add(i);
            }

            ManualUVRenderer uvRenderer = m_meshToRenderer[mesh];

            uvRenderer.UV          = mesh.Textures;
            uvRenderer.IsSelected  = new bool[uvRenderer.UV.Length];
            uvRenderer.Edges       = edges;
            uvRenderer.FaceToEdges = faceToEdge;
            uvRenderer.Faces       = mesh.Faces.Select(f => f.Indexes).ToArray();
            uvRenderer.Refresh(false, false);
        }
コード例 #2
0
        public void Move()
        {
            Vector2 uv    = ManualUVRenderer.WorldToUV(m_pivotPoint.transform.position);
            Vector2 delta = uv - m_initialUV;

            Move(delta);
            m_prevPivotPoint = m_pivotPoint.transform.position;
        }
コード例 #3
0
 private void RefreshUVRenderers()
 {
     foreach (KeyValuePair <PBMesh, ManualUVRenderer> kvp in m_meshToRenderer)
     {
         PBMesh           mesh     = kvp.Key;
         ManualUVRenderer renderer = kvp.Value;
         renderer.UV = mesh.Textures;
         renderer.Refresh(true, false);
     }
 }
コード例 #4
0
 private void Update()
 {
     if (m_prevPivotPoint != m_pivotPoint.position)
     {
         BeginMove();
         Vector2 uv    = ManualUVRenderer.WorldToUV(m_pivotPoint.transform.position);
         Vector2 delta = uv - ManualUVRenderer.WorldToUV(m_prevPivotPoint);
         Move(delta);
         m_prevPivotPoint = m_pivotPoint.transform.position;
     }
 }
コード例 #5
0
        private bool Raycast(out Vector2 uv)
        {
            float dinstance;
            Ray   ray = Window.Pointer;

            if (!m_plane.Raycast(ray, out dinstance))
            {
                uv = Vector2.zero;
                return(false);
            }

            uv = ManualUVRenderer.WorldToUV(ray.GetPoint(dinstance));
            return(true);
        }
コード例 #6
0
        private void OnModeChanged(ProBuilderToolMode oldMode)
        {
            switch (m_tool.Mode)
            {
            case ProBuilderToolMode.Vertex:
                foreach (ManualUVSelection selection in m_uvEditor.Selection)
                {
                    ManualUVRenderer uvRenderer = m_meshToRenderer[selection.Mesh];

                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Vertex;
                    uvRenderer.Refresh(false, false);

                    OnUVSelectionChanged(selection);
                }
                break;

            case ProBuilderToolMode.Face:
                foreach (ManualUVSelection selection in m_uvEditor.Selection)
                {
                    ManualUVRenderer uvRenderer = m_meshToRenderer[selection.Mesh];

                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Face;
                    uvRenderer.Refresh(false, false);

                    OnUVSelectionChanged(selection);
                }
                break;

            default:
                foreach (ManualUVSelection selection in m_uvEditor.Selection)
                {
                    ManualUVRenderer uvRenderer = m_meshToRenderer[selection.Mesh];

                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Edge;
                    uvRenderer.Refresh(false, false);

                    OnUVSelectionChanged(selection);
                }
                break;
            }

            m_uvEditor.RefreshPivotPoint();
        }
コード例 #7
0
        private void OnBoxSelection(object sender, BoxSelectionArgs e)
        {
            Bounds  selectionBounds = m_selectionComponent.BoxSelection.SelectionBounds;
            Vector2 min             = ManualUVRenderer.WorldToUV(Window.Camera.ScreenToWorldPoint(selectionBounds.min));
            Vector2 max             = ManualUVRenderer.WorldToUV(Window.Camera.ScreenToWorldPoint(selectionBounds.max));

            switch (m_tool.Mode)
            {
            case ProBuilderToolMode.Vertex:
                m_uvEditor.SelectVertices(uv => (min.x <= uv.x && min.y <= uv.y && uv.x <= max.x && uv.y <= max.y) ? 0 : 1, false, !SelectMultipleAction());
                break;

            case ProBuilderToolMode.Face:
                m_uvEditor.SelectFaces(uv => (min.x <= uv.x && min.y <= uv.y && uv.x <= max.x && uv.y <= max.y) ? 0 : 1, false, !SelectMultipleAction());
                break;

            default:
                m_uvEditor.SelectEdges((uv0, uv1) => PBMath.Intersects(min, max, uv0, uv1) ? 0 : 1, false, !SelectMultipleAction());
                break;
            }

            m_uvEditor.RefreshPivotPoint();
        }
コード例 #8
0
        public void Rotate()
        {
            Vector2 uv    = ManualUVRenderer.WorldToUV(m_pivotPoint.transform.position);
            float   angle = -m_pivotPoint.transform.eulerAngles.z;

            for (int i = 0; i < m_selection.Count; ++i)
            {
                ManualUVSelection selection = m_selection[i];
                PBMesh            mesh      = selection.Mesh;
                Vector2[]         textures  = mesh.Textures;
                foreach (int index in m_indexes[i])
                {
                    textures[index] = (m_initialUVs[i][index]).RotateAroundPoint(uv, angle);
                }
                mesh.Textures = textures;
                mesh.RefreshUV();
            }

            if (UVChanged != null)
            {
                UVChanged();
            }
        }
コード例 #9
0
        private void OnUVSelectionChanged(ManualUVSelection selection)
        {
            ManualUVRenderer renderer = m_meshToRenderer[selection.Mesh];

            if (m_tool.Mode == ProBuilderToolMode.Vertex)
            {
                Color[] vertexColors = renderer.VertexColors;
                bool[]  isSelected   = renderer.IsSelected;
                for (int i = 0; i < vertexColors.Length; ++i)
                {
                    bool selected = selection.Vertices.Contains(i);
                    vertexColors[i] = selected ? m_selectionColor : Color.white;
                    isSelected[i]   = selected;
                }
            }
            else if (m_tool.Mode == ProBuilderToolMode.Edge)
            {
                PBEdge[] edges      = selection.Mesh.Edges;
                Color[]  edgeColors = renderer.EdgeColors;
                bool[]   isSelected = renderer.IsSelected;
                for (int i = 0; i < isSelected.Length; ++i)
                {
                    isSelected[i] = false;
                }

                for (int i = 0; i < edgeColors.Length; ++i)
                {
                    int  edgeIndex = i / 2;
                    bool selected  = selection.Edges.Contains(edgeIndex);
                    edgeColors[i] = selected ? m_selectionColor : Color.white;

                    PBEdge edge = edges[edgeIndex];
                    isSelected[edge.A] = selected;
                    isSelected[edge.B] = selected;
                }
            }
            else
            {
                Color[] vertexColors = renderer.VertexColors;
                int[][] faces        = renderer.Faces;
                bool[]  isSelected   = renderer.IsSelected;
                for (int i = 0; i < isSelected.Length; ++i)
                {
                    isSelected[i] = false;
                }
                for (int i = 0; i < vertexColors.Length; ++i)
                {
                    bool selected = selection.Faces.Contains(i);
                    vertexColors[i] = selected ? m_selectionColor : Color.white;

                    if (selected)
                    {
                        int[] faceIdexes = faces[i];
                        for (int j = 0; j < faceIdexes.Length; ++j)
                        {
                            int faceIndex = faceIdexes[j];
                            isSelected[faceIndex] = true;
                        }
                    }
                }

                Color[] edgeColors = renderer.EdgeColors;
                for (int i = 0; i < edgeColors.Length; ++i)
                {
                    edgeColors[i] = Color.white;
                }

                Dictionary <int, List <int> > faceToEdges = renderer.FaceToEdges;
                foreach (int faceIndex in selection.Faces)
                {
                    List <int> edgeIndices = faceToEdges[faceIndex];
                    for (int i = 0; i < edgeIndices.Count; ++i)
                    {
                        int edgeIndex = edgeIndices[i];
                        edgeColors[edgeIndex * 2 + 0] = m_selectionColor;
                        edgeColors[edgeIndex * 2 + 1] = m_selectionColor;
                    }
                }
            }

            renderer.Refresh(true, true);
        }
コード例 #10
0
        private void CreateUVRenderers()
        {
            HashSet <PBMesh> selectedMeshes = new HashSet <PBMesh>();
            IMeshEditor      meshEditor     = m_tool.GetEditor();

            if (meshEditor != null)
            {
                MeshSelection selection = meshEditor.GetSelection();
                if (selection != null)
                {
                    selectedMeshes = new HashSet <PBMesh>(selection.GetSelectedMeshes());
                }
            }

            int delta = selectedMeshes.Count() - m_uvRenderers.Count;

            if (delta > 0)
            {
                m_uvRenderersRoot.SetActive(false);
                for (int i = 0; i < delta; ++i)
                {
                    ManualUVRenderer renderer = m_uvRenderersRoot.AddComponent <ManualUVRenderer>();
                    renderer.Window = Window;
                    m_uvRenderers.Add(renderer);
                }
                m_uvRenderersRoot.SetActive(true);
            }
            else
            {
                delta = -delta;
                for (int i = 0; i < delta; ++i)
                {
                    Destroy(m_uvRenderers[m_uvRenderers.Count - 1]);
                    m_uvRenderers.RemoveAt(m_uvRenderers.Count - 1);
                }
            }

            foreach (PBMesh mesh in m_meshToRenderer.Keys.ToArray())
            {
                if (!selectedMeshes.Contains(mesh))
                {
                    m_meshToRenderer.Remove(mesh);
                }
            }

            int index = 0;

            foreach (PBMesh mesh in selectedMeshes)
            {
                ManualUVRenderer uvRenderer = m_uvRenderers[index];
                switch (m_tool.Mode)
                {
                case ProBuilderToolMode.Vertex:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Vertex;
                    break;

                case ProBuilderToolMode.Edge:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Edge;
                    break;

                case ProBuilderToolMode.Face:
                    uvRenderer.Mode = ManualUVRenderer.RenderMode.Face;
                    break;
                }

                index++;

                m_meshToRenderer[mesh] = uvRenderer;
            }
        }
コード例 #11
0
 public void BeginScale()
 {
     m_initialUV  = ManualUVRenderer.WorldToUV(m_pivotPoint.transform.position);
     m_initialUVs = m_selection.Select(s => s.Mesh.Textures.ToArray()).ToArray();
     GetIndexes();
 }