UnityGLTF插件扩展,支持加载bmp贴图

插件原方法:

public Stream LoadStream(string relativeFilePath)
{
    if (relativeFilePath == null)
    {
        throw new ArgumentNullException("relativeFilePath");
    }

    string pathToLoad = Path.Combine(_rootDirectoryPath, relativeFilePath);
    pathToLoad = pathToLoad.Replace("file:///", "");
    if (!File.Exists(pathToLoad))
    {
        Debug.LogError("Buffer file not found" + pathToLoad);
        throw new FileNotFoundException("Buffer file not found", relativeFilePath);
    }
    return File.OpenRead(pathToLoad);
}

修改后:

public Stream LoadStream(string relativeFilePath)
{
    if (relativeFilePath == null)
    {
        throw new ArgumentNullException("relativeFilePath");
    }

    string pathToLoad = Path.Combine(_rootDirectoryPath, relativeFilePath);
    pathToLoad = pathToLoad.Replace("file:///", "");
    if (!File.Exists(pathToLoad))
    {
        Debug.LogError("Buffer file not found" + pathToLoad);
        throw new FileNotFoundException("Buffer file not found", relativeFilePath);
    }
    var fileStream = File.OpenRead(pathToLoad);
    if (!string.IsNullOrEmpty(relativeFilePath) && relativeFilePath.ToLower().EndsWith(".bmp"))
    {
        var bitmap = new System.Drawing.Bitmap(fileStream);
        var memoryStream = new MemoryStream();
        bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
        bitmap.Dispose();
        fileStream.Dispose();
        return memoryStream;
    }
    else
    {
        return fileStream;
    }
}

 

posted @ 2023-10-08 15:30  zerozabuu  阅读(36)  评论(0编辑  收藏  举报