Esempio n. 1
0
        public static void PlaceTextureOnFaces(this Mesh mesh, IEnumerable <int> faces, ImageBuffer textureToUse, Matrix4X4 textureCoordinateMapping)
        {
            var faceTextures = new Dictionary <int, FaceTextureData>();

            var uvs = new Vector2Float[3];

            foreach (var face in faces)
            {
                int uvIndex = 0;
                foreach (int vertexIndex in new int[] { mesh.Faces[face].v0, mesh.Faces[face].v1, mesh.Faces[face].v2 })
                {
                    var edgeStartPosition = mesh.Vertices[vertexIndex];
                    var textureUv         = edgeStartPosition.Transform(textureCoordinateMapping);
                    uvs[uvIndex++] = new Vector2Float(textureUv);
                }

                faceTextures.Add(face, new FaceTextureData(textureToUse, uvs[0], uvs[1], uvs[2]));
            }

            // add in any existing face textures
            if (mesh.FaceTextures != null)
            {
                foreach (var kvp in mesh.FaceTextures)
                {
                    faceTextures[kvp.Key] = kvp.Value;
                }
            }

            mesh.FaceTextures = faceTextures;

            mesh.MarkAsChanged();
        }
Esempio n. 2
0
        public static void PlaceTexture(this Mesh mesh, ImageBuffer textureToUse, Matrix4X4 textureCoordinateMapping)
        {
            foreach (var face in mesh.Faces)
            {
                face.PlaceTextureOnFace(textureToUse, textureCoordinateMapping);
            }

            mesh.MarkAsChanged();
        }
Esempio n. 3
0
        public static void RemoveTexture(this Mesh mesh, ImageBuffer texture, int index)
        {
            foreach (var face in mesh.Faces)
            {
                face.RemoveTexture(texture, index);
            }

            mesh.MarkAsChanged();
        }
Esempio n. 4
0
        public static void PlaceTexture(this Mesh mesh, ImageBuffer textureToUse, Matrix4X4 textureCoordinateMapping)
        {
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                mesh.PlaceTextureOnFace(i, textureToUse, textureCoordinateMapping, false);
            }

            mesh.MarkAsChanged();
        }
Esempio n. 5
0
        public static void RemoveTexture(this Mesh mesh, ImageBuffer texture, int index)
        {
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                mesh.RemoveTexture(i, texture, index);
            }

            mesh.MarkAsChanged();
        }
Esempio n. 6
0
        public static void RemoveTexture(this Mesh mesh, int faceIndex, ImageBuffer texture, int index)
        {
            var faceTextures = mesh.FaceTextures;

            if (faceTextures.ContainsKey(faceIndex) &&
                faceTextures[faceIndex].image == texture)
            {
                faceTextures.Remove(faceIndex);
                mesh.MarkAsChanged();
            }
        }
Esempio n. 7
0
        public static void PlaceTextureOnFace(this Mesh mesh, int face, ImageBuffer textureToUse, Matrix4X4 textureCoordinateMapping)
        {
            var uvs     = new Vector2Float[3];
            int uvIndex = 0;

            foreach (int vertexIndex in new int[] { mesh.Faces[face].v0, mesh.Faces[face].v1, mesh.Faces[face].v2 })
            {
                var edgeStartPosition = mesh.Vertices[vertexIndex];
                var textureUv         = edgeStartPosition.Transform(textureCoordinateMapping);
                uvs[uvIndex++] = new Vector2Float(textureUv);
            }

            mesh.FaceTextures.Add(face, new FaceTextureData(textureToUse, uvs[0], uvs[1], uvs[2]));

            mesh.MarkAsChanged();
        }