GetTextureFromRawFolder() 공개 메소드

public GetTextureFromRawFolder ( string filePath ) : Microsoft.Xna.Framework.Graphics.Texture2D
filePath string
리턴 Microsoft.Xna.Framework.Graphics.Texture2D
예제 #1
0
        private static ModelMesh LoadPMesh(GameMode gameMode, string filePath)
        {
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    var vertexCount  = binaryReader.ReadInt32();
                    var indicesCount = binaryReader.ReadInt32();
                    var textureName  = binaryReader.ReadString();

                    var       textureFilePath = Path.Combine(Path.GetDirectoryName(filePath) ?? "", Path.GetFileName(textureName) ?? "");
                    Texture2D texture         = null;
                    if (File.Exists(textureFilePath))
                    {
                        texture = gameMode.GetTextureFromRawFolder(textureFilePath);
                    }

                    var geometryData = new GeometryData
                    {
                        Vertices = new VertexPositionNormalTexture[vertexCount],
                        Indices  = new ushort[indicesCount]
                    };

                    for (var i = 0; i < vertexCount; i++)
                    {
                        var position = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var normal   = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var uv       = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        geometryData.Vertices[i] = new VertexPositionNormalTexture(position, normal, uv);
                    }

                    for (var i = 0; i < indicesCount; i++)
                    {
                        geometryData.Indices[i] = (ushort)binaryReader.ReadInt32();
                    }

                    return(new ModelMesh
                    {
                        Mesh = new Mesh(gameMode.GraphicsDevice, geometryData, PrimitiveType.TriangleList, false),
                        Material = new Material
                        {
                            DiffuseTexture = texture
                        }
                    });
                }
            }
        }
예제 #2
0
        private static ModelMesh LoadPMesh(GameMode gameMode, string filePath)
        {
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    var vertexCount = binaryReader.ReadInt32();
                    var indicesCount = binaryReader.ReadInt32();
                    var textureName = binaryReader.ReadString();

                    var textureFilePath = Path.Combine(Path.GetDirectoryName(filePath) ?? "", Path.GetFileName(textureName) ?? "");
                    Texture2D texture = null;
                    if (File.Exists(textureFilePath))
                    {
                        texture = gameMode.GetTextureFromRawFolder(textureFilePath);
                    }

                    var geometryData = new GeometryData
                    {
                        Vertices = new VertexPositionNormalTexture[vertexCount],
                        Indices = new ushort[indicesCount]
                    };

                    for (var i = 0; i < vertexCount; i++)
                    {
                        var position = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var normal = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var uv = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        geometryData.Vertices[i] = new VertexPositionNormalTexture(position, normal, uv);
                    }

                    for(var i = 0; i < indicesCount; i++)
                    {
                        geometryData.Indices[i] = (ushort) binaryReader.ReadInt32();
                    }

                    return new ModelMesh
                    {
                        Mesh = new Mesh(gameMode.GraphicsDevice, geometryData, PrimitiveType.TriangleList, false),
                        Material = new Material
                        {
                            DiffuseTexture = texture
                        }
                    };
                }
            }
        }
예제 #3
0
        private Texture2D GetTextureFromSlot(GameMode gameMode, string modelDirectory, TextureSlot textureSlot)
        {
            if (string.IsNullOrEmpty(textureSlot.FilePath))
            {
                return(null);
            }

            var fileName        = Path.GetFileName(textureSlot.FilePath) ?? "";
            var textureFilePath = Path.Combine(modelDirectory, fileName);

            if (!File.Exists(fileName))
            {
                return(null);
            }

            return(gameMode.GetTextureFromRawFolder(textureFilePath));
        }
예제 #4
0
        private Texture2D GetTextureFromSlot(GameMode gameMode, string modelDirectory, TextureSlot textureSlot)
        {
            if (string.IsNullOrEmpty(textureSlot.FilePath)) return null;

            var fileName = Path.GetFileName(textureSlot.FilePath) ?? "";
            var textureFilePath = Path.Combine(modelDirectory, fileName);

            if (!File.Exists(fileName)) return null;

            return gameMode.GetTextureFromRawFolder(textureFilePath);
        }