/// <summary>
        ///     Initializes the static fields and properites of the <see cref="UVMapping"/> class
        /// </summary>
        static UVMapping()
        {
            UVMapping.defaultMapping = new UVMapping();

            UVMapping.defaultMapping.gameObjectName = UVMapping.AnyGameObjectName;

            UVMapping.defaultMapping.uv = new Vector2[]
            {
                new Vector2(0.0f, 0.0f),
                new Vector2(1.0f, 0.0f),
                new Vector2(0.0f, 1.0f),
                new Vector2(1.0f, 1.0f)
            };
        }
        /// <summary>
        ///     Returns the UV mapping for the specified name or <seealso cref="UVMapping.DefaultMapping"/>
        ///     if none is found.
        /// </summary>
        /// <param name="mappings">An enumarable of mappings</param>
        /// <param name="name">The name of the GameObject</param>
        /// <returns>A fitting UVMapping or <seealso cref="UVMapping.DefaultMapping"/></returns>
        public static UVMapping GetMappingFor(this IEnumerable <UVMapping> mappings, string name)
        {
            UVMapping @default = null;

            foreach (UVMapping mapping in mappings)
            {
                if (mapping.gameObjectName == name)
                {
                    return(mapping);
                }
                else if (@default == null && mapping.gameObjectName == UVMapping.AnyGameObjectName)
                {
                    @default = mapping;
                }
            }

            return(@default != null ? @default : UVMapping.DefaultMapping);
        }
Beispiel #3
0
        /// <summary>
        ///     Adds the vertices from <paramref name="mesh"/>, in regards to <paramref name="transform"/>'s local transformation.
        ///     The mesh must have at least one vertex.
        /// </summary>
        /// <param name="mesh">The mesh of which to add the vertices</param>
        /// <param name="transform">The transform to consider</param>
        private void AddVertices(Mesh mesh, Transform transform)
        {
            // Get vertices
            int vertexIndexOffset = this.vertices.Count;

            foreach (Vector3 vertex in mesh.vertices)
            {
                Vector3 absoluteVertex;

                absoluteVertex = VariousCommon.LinearMultiply(vertex, transform.localScale);

                absoluteVertex += transform.localPosition;

                absoluteVertex = VariousCommon.RotateVectorAroundOrigin(absoluteVertex, transform.eulerAngles);

                this.vertices.Add(absoluteVertex);
            }

            // Get triangles
            int[] triangles = mesh.triangles;
            for (int i = 0; i < triangles.Length; i++)
            {
                this.triangles.Add(triangles[i] + vertexIndexOffset);
            }

            // Get UV
            Vector2[] uv        = mesh.uv;
            UVMapping uvMapping = this.uvMappings.GetMappingFor(transform.name);

            for (int i = 0; i < uv.Length; i++)
            {
                Vector2 normalizedUV = VariousCommon.LinearDivide(
                    uv[i] - RoomMesh.cubeUVMapTopLeft,
                    RoomMesh.cubeUVMapBottomRight - RoomMesh.cubeUVMapTopLeft);

                this.uv.Add(VariousCommon.LinearMultiply(normalizedUV, uvMapping.uv[i % uvMapping.uv.Length]));
            }
        }