コード例 #1
0
 /// <summary>
 /// Find if a vertex attribute has been set.
 /// </summary>
 /// <param name="attribute">The attribute or attributes to test for.</param>
 /// <returns>True if this vertex has the specified attributes set, false if they are default values.</returns>
 public bool HasArrays(CSG_VertexAttributes attribute)
 {
     return((m_Attributes & attribute) == attribute);
 }
コード例 #2
0
        /// <summary>
        /// Allocate and fill the requested attribute arrays.
        /// </summary>
        /// <remarks>
        /// If you are using this function to rebuild a mesh, use SetMesh instead. SetMesh handles setting null arrays where appropriate for you.
        /// </remarks>
        /// <seealso cref="SetMesh"/>
        /// <param name="vertices">The source vertices.</param>
        /// <param name="position">A new array of the vertex position values if requested by the attributes parameter, or null.</param>
        /// <param name="color">A new array of the vertex color values if requested by the attributes parameter, or null.</param>
        /// <param name="uv0">A new array of the vertex uv0 values if requested by the attributes parameter, or null.</param>
        /// <param name="normal">A new array of the vertex normal values if requested by the attributes parameter, or null.</param>
        /// <param name="tangent">A new array of the vertex tangent values if requested by the attributes parameter, or null.</param>
        /// <param name="uv2">A new array of the vertex uv2 values if requested by the attributes parameter, or null.</param>
        /// <param name="uv3">A new array of the vertex uv3 values if requested by the attributes parameter, or null.</param>
        /// <param name="uv4">A new array of the vertex uv4 values if requested by the attributes parameter, or null.</param>
        /// <param name="attributes">A flag with the MeshAttributes requested.</param>
        /// <seealso cref="HasArrays"/>
        public static void GetArrays(
            IList <CSG_Vertex> vertices,
            out Vector3[] position,
            out Color[] color,
            out Vector2[] uv0,
            out Vector3[] normal,
            out Vector4[] tangent,
            out Vector2[] uv2,
            out List <Vector4> uv3,
            out List <Vector4> uv4,
            CSG_VertexAttributes attributes)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("vertices");
            }

            int vc    = vertices.Count;
            var first = vc < 1 ? new CSG_Vertex() : vertices[0];

            bool hasPosition = ((attributes & CSG_VertexAttributes.Position) == CSG_VertexAttributes.Position) && first.hasPosition;
            bool hasColor    = ((attributes & CSG_VertexAttributes.Color) == CSG_VertexAttributes.Color) && first.hasColor;
            bool hasUv0      = ((attributes & CSG_VertexAttributes.Texture0) == CSG_VertexAttributes.Texture0) && first.hasUV0;
            bool hasNormal   = ((attributes & CSG_VertexAttributes.Normal) == CSG_VertexAttributes.Normal) && first.hasNormal;
            bool hasTangent  = ((attributes & CSG_VertexAttributes.Tangent) == CSG_VertexAttributes.Tangent) && first.hasTangent;
            bool hasUv2      = ((attributes & CSG_VertexAttributes.Texture1) == CSG_VertexAttributes.Texture1) && first.hasUV2;
            bool hasUv3      = ((attributes & CSG_VertexAttributes.Texture2) == CSG_VertexAttributes.Texture2) && first.hasUV3;
            bool hasUv4      = ((attributes & CSG_VertexAttributes.Texture3) == CSG_VertexAttributes.Texture3) && first.hasUV4;

            position = hasPosition ? new Vector3[vc] : null;
            color    = hasColor ? new Color[vc] : null;
            uv0      = hasUv0 ? new Vector2[vc] : null;
            normal   = hasNormal ? new Vector3[vc] : null;
            tangent  = hasTangent ? new Vector4[vc] : null;
            uv2      = hasUv2 ? new Vector2[vc] : null;
            uv3      = hasUv3 ? new List <Vector4>(vc) : null;
            uv4      = hasUv4 ? new List <Vector4>(vc) : null;

            for (int i = 0; i < vc; i++)
            {
                if (hasPosition)
                {
                    position[i] = vertices[i].position;
                }
                if (hasColor)
                {
                    color[i] = vertices[i].color;
                }
                if (hasUv0)
                {
                    uv0[i] = vertices[i].uv0;
                }
                if (hasNormal)
                {
                    normal[i] = vertices[i].normal;
                }
                if (hasTangent)
                {
                    tangent[i] = vertices[i].tangent;
                }
                if (hasUv2)
                {
                    uv2[i] = vertices[i].uv2;
                }
                if (hasUv3)
                {
                    uv3.Add(vertices[i].uv3);
                }
                if (hasUv4)
                {
                    uv4.Add(vertices[i].uv4);
                }
            }
        }