-
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
I guess it's because Stream on the Android platform doesn't support certain methods, and I've encountered similar issues using the SharpGLTF library before.
my code:
public static Texture ImportTextureHdrFromStream(StreamReader streamReader, TextureImportSetting setting)
{
if (setting.FlipVertically)
{
StbImage.stbi_set_flip_vertically_on_load(1);
}
var imageResult = ImageResultFloat.FromStream(streamReader.BaseStream);
if (setting.FlipVertically)
{
StbImage.stbi_set_flip_vertically_on_load(0);
}
if (imageResult != null)
{
var texture = new Texture
{
Width = (uint)imageResult.Width,
Height = (uint)imageResult.Height,
Channel = imageResult.Comp.ToTexChannel()
};
texture.IsGammaSpace = setting.IsGammaSpace;
texture.HDRPixels = new(imageResult.Data);
texture.IsHdrTexture = true;
return texture;
}
throw new Exception("Load Texture error");
}The stream is from
new StreamReader(Activity.Assets.Open($"Resource/{Path}"));When I make the following modifications, it can avoid this problem
public static Texture ImportTextureHdrFromStream(StreamReader streamReader, TextureImportSetting setting)
{
MemoryStream ms = new MemoryStream();
using (BinaryReader br = new BinaryReader(streamReader.BaseStream))
{
List<byte> buffer = new List<byte>();
do
{
var data = br.ReadBytes(1024);
if (data.Length <= 0)
break;
ms.Write(data);
} while (true);
}
if (setting.FlipVertically)
{
StbImage.stbi_set_flip_vertically_on_load(1);
}
var imageResult = ImageResultFloat.FromStream(ms);
if (setting.FlipVertically)
{
StbImage.stbi_set_flip_vertically_on_load(0);
}
if (imageResult != null)
{
var texture = new Texture
{
Width = (uint)imageResult.Width,
Height = (uint)imageResult.Height,
Channel = imageResult.Comp.ToTexChannel()
};
texture.IsGammaSpace = setting.IsGammaSpace;
texture.HDRPixels = new(imageResult.Data);
texture.IsHdrTexture = true;
return texture;
}
throw new Exception("Load Texture error");
}Metadata
Metadata
Assignees
Labels
No labels