GetUVs() private method

private GetUVs ( int channel ) : ReadOnlyCollection
channel int
return ReadOnlyCollection
        /// <summary>
        /// Compile a UnityEngine.Mesh from a ProBuilderMesh.
        /// </summary>
        /// <param name="probuilderMesh">The mesh source.</param>
        /// <param name="targetMesh">Destination UnityEngine.Mesh.</param>
        /// <param name="preferredTopology">If specified, the function will try to create topology matching the reqested format (and falling back on triangles where necessary).</param>
        /// <returns>The resulting material array from the compiled faces array. This is suitable to assign to the MeshRenderer.sharedMaterials property.</returns>
        public static void Compile(ProBuilderMesh probuilderMesh, Mesh targetMesh, MeshTopology preferredTopology = MeshTopology.Triangles)
        {
            if (probuilderMesh == null)
            {
                throw new ArgumentNullException("probuilderMesh");
            }

            if (targetMesh == null)
            {
                throw new ArgumentNullException("targetMesh");
            }

            targetMesh.Clear();

            targetMesh.vertices = probuilderMesh.positionsInternal;
            targetMesh.uv       = probuilderMesh.texturesInternal;

            if (probuilderMesh.HasArrays(MeshArrays.Texture2))
            {
                List <Vector4> uvChannel = new List <Vector4>();
                probuilderMesh.GetUVs(2, uvChannel);
                targetMesh.SetUVs(2, uvChannel);
            }

            if (probuilderMesh.HasArrays(MeshArrays.Texture3))
            {
                List <Vector4> uvChannel = new List <Vector4>();
                probuilderMesh.GetUVs(3, uvChannel);
                targetMesh.SetUVs(3, uvChannel);
            }

            targetMesh.normals  = probuilderMesh.GetNormals();
            targetMesh.tangents = probuilderMesh.GetTangents();

            if (probuilderMesh.HasArrays(MeshArrays.Color))
            {
                targetMesh.colors = probuilderMesh.colorsInternal;
            }

            var materialCount = probuilderMesh.GetComponent <Renderer>().sharedMaterials.Length;
            var submeshes     = Submesh.GetSubmeshes(probuilderMesh.facesInternal, materialCount, preferredTopology);

            targetMesh.subMeshCount = submeshes.Length;

            for (int i = 0; i < targetMesh.subMeshCount; i++)
            {
                targetMesh.SetIndices(submeshes[i].m_Indexes, submeshes[i].m_Topology, i, false);
            }

            targetMesh.name = string.Format("pb_Mesh{0}", probuilderMesh.id);
        }
Beispiel #2
0
        /// <summary>
        /// Copy mesh data from another mesh to self.
        /// </summary>
        /// <param name="other"></param>
        public void CopyFrom(ProBuilderMesh other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            Clear();
            positions      = other.positions;
            sharedVertices = other.sharedVerticesInternal;
            SetSharedTextures(other.sharedTextureLookup);
            facesInternal = other.faces.Select(x => new Face(x)).ToArray();

            List <Vector4> uvs = new List <Vector4>();

            for (var i = 0; i < k_UVChannelCount; i++)
            {
                other.GetUVs(i, uvs);
                SetUVs(i, uvs);
            }

            tangents         = other.tangents;
            colors           = other.colors;
            userCollisions   = other.userCollisions;
            selectable       = other.selectable;
            unwrapParameters = new UnwrapParameters(other.unwrapParameters);
        }