コード例 #1
0
ファイル: PBAutoUVEditor.cs プロジェクト: lbm7926/Imp
        public void SetAutoUV(MeshSelection selection, bool auto)
        {
            if (selection == null)
            {
                return;
            }

            if (selection.HasVertices)
            {
                selection.VerticesToFaces(false);
            }
            else if (selection.HasEdges)
            {
                selection.EdgesToFaces(false);
            }

            List<Face> faces = new List<Face>();
            foreach(KeyValuePair<ProBuilderMesh, IList<int>> kvp in selection.SelectedFaces)
            {
                ProBuilderMesh mesh = kvp.Key;

                faces.Clear();
                mesh.GetFaces(kvp.Value, faces);

                PBAutoUVConversion.SetAutoUV(mesh, faces.ToArray(), auto);

                mesh.ToMesh();
                mesh.Refresh();
            }
        }
コード例 #2
0
        public virtual void EndDrag(bool refreshMeshes = false)
        {
            List <Face> faces = new List <Face>();

            for (int m = 0; m < Meshes.Length; ++m)
            {
                ProBuilderMesh mesh       = Meshes[m];
                bool[]         isManualUv = IsManualUv[m];
                int[]          indexes    = Indexes[m];

                mesh.GetFaces(Selection.SelectedFaces[mesh], faces);

                for (int i = 0; i < isManualUv.Length; ++i)
                {
                    faces[i].manualUV = isManualUv[i];
                }

                PBAutoUVConversion.SetAutoAndAlignUnwrapParamsToUVs(mesh, faces.Where(x => !x.manualUV));
                faces.Clear();
            }

            if (refreshMeshes)
            {
                for (int m = 0; m < Meshes.Length; ++m)
                {
                    ProBuilderMesh mesh = Meshes[m];
                    mesh.ToMesh();
                    mesh.Refresh();
                }
            }

            Indexes      = null;
            Origins      = null;
            FaceCenters  = null;
            UVTransforms = null;
            IsManualUv   = null;
            Meshes       = null;
        }
コード例 #3
0
        public void SetAutoUV(MeshSelection selection, bool auto)
        {
            if (selection == null)
            {
                return;
            }

            selection = selection.ToFaces(false, false);

            List <Face> faces = new List <Face>();

            foreach (KeyValuePair <GameObject, IList <int> > kvp in selection.SelectedFaces)
            {
                ProBuilderMesh mesh = kvp.Key.GetComponent <ProBuilderMesh>();

                faces.Clear();
                mesh.GetFaces(kvp.Value, faces);

                PBAutoUVConversion.SetAutoUV(mesh, faces.ToArray(), auto);
                mesh.ToMesh();
                mesh.Refresh();
            }
        }
コード例 #4
0
        public virtual void BeginDrag(MeshSelection selection, Vector3 initialPosition, Quaternion initialRotation)
        {
            Selection = selection;
            if (Selection.HasEdges)
            {
                Selection.EdgesToFaces(false, false);
            }
            if (Selection.HasVertices)
            {
                Selection.VerticesToFaces(false, false);
            }

            InitialPosition = initialPosition;
            InitialRotation = initialRotation;
            Matrix          = Matrix4x4.TRS(InitialPosition, InitialRotation, Vector3.one);
            MatrixInv       = Matrix.inverse;

            List <ProBuilderMesh> allMeshes      = new List <ProBuilderMesh>();
            List <Vector2[]>      allOrigins     = new List <Vector2[]>();
            List <Vector2[]>      allFaceCenters = new List <Vector2[]>();
            List <PBAutoUVConversion.UVTransform[]> allUVTransforms = new List <PBAutoUVConversion.UVTransform[]>();
            List <bool[]> allIsManualUv = new List <bool[]>();
            List <int[]>  allIndexes    = new List <int[]>();

            HashSet <int>  indexes     = new HashSet <int>();
            List <Vector2> origins     = new List <Vector2>();
            List <Vector2> faceCenters = new List <Vector2>();
            List <PBAutoUVConversion.UVTransform> uvTransforms = new List <PBAutoUVConversion.UVTransform>();
            List <bool> isManualUv = new List <bool>();
            List <Face> faces      = new List <Face>();

            foreach (KeyValuePair <ProBuilderMesh, IList <int> > kvp in Selection.SelectedFaces)
            {
                ProBuilderMesh mesh = kvp.Key;
                mesh.GetFaces(kvp.Value, faces);

                IList <Vector2> textures = mesh.textures;

                for (int f = 0; f < faces.Count; ++f)
                {
                    Face        face        = faces[f];
                    IList <int> faceIndexes = face.indexes;
                    for (int i = 0; i < faceIndexes.Count; ++i)
                    {
                        int faceIndex = faceIndexes[i];
                        if (!indexes.Contains(faceIndex))
                        {
                            indexes.Add(faceIndex);
                            origins.Add(textures[faceIndex]);
                            faceCenters.Add(GetCenterOfMass(textures, face));

                            PBAutoUVConversion.UVTransform transform = PBAutoUVConversion.GetUVTransform(mesh, face);
                            if (!face.manualUV)
                            {
                                Vector2 scale = transform.scale;
                                scale.x         = -scale.x;
                                transform.scale = scale;
                            }
                            uvTransforms.Add(transform);
                        }
                    }

                    isManualUv.Add(face.manualUV);
                    face.manualUV = true;
                }

                allIndexes.Add(indexes.ToArray());
                allOrigins.Add(origins.ToArray());
                allFaceCenters.Add(faceCenters.ToArray());
                allUVTransforms.Add(uvTransforms.ToArray());
                allIsManualUv.Add(isManualUv.ToArray());
                allMeshes.Add(mesh);

                indexes.Clear();
                origins.Clear();
                faceCenters.Clear();
                uvTransforms.Clear();
                isManualUv.Clear();
                faces.Clear();
            }

            Indexes      = allIndexes.ToArray();
            Origins      = allOrigins.ToArray();
            FaceCenters  = allFaceCenters.ToArray();
            UVTransforms = allUVTransforms.ToArray();
            IsManualUv   = allIsManualUv.ToArray();
            Meshes       = allMeshes.ToArray();
        }