Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
BytesWithPath to BytesWithMime
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Sep 21, 2018
1 parent 4005bde commit 2d70847
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions Core/Scripts/IO/TextureIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,43 @@ public static IEnumerable<TextureExportItem> GetTextures(Material m)
}
}

struct BytesWithPath

struct BytesWithMime
{
public Byte[] Bytes;
//public string Path;
public string Mime;
}

public BytesWithPath(Texture texture, glTFTextureTypes textureType)
{
static BytesWithMime GetBytesWithMime(Texture texture, glTFTextureTypes textureType)
{
#if UNITY_EDITOR
var path = UnityPath.FromAsset(texture);
if (path.IsUnderAssetsFolder)
var path = UnityPath.FromAsset(texture);
if (path.IsUnderAssetsFolder)
{
if (path.Extension == ".png")
{
if (path.Extension == ".png")
return new BytesWithMime
{
Bytes = System.IO.File.ReadAllBytes(path.FullPath);
Mime = "image/png";
return;
}
}
#endif
//Path = "";
Bytes = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG();
Mime = "image/png";
Bytes = System.IO.File.ReadAllBytes(path.FullPath),
Mime = "image/png",
};
}
}
#endif

return new BytesWithMime
{
Bytes = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG(),
Mime = "image/png",
};
}

public static int ExportTexture(glTF gltf, int bufferIndex, Texture texture, glTFTextureTypes textureType)
{
var bytesWithPath = new BytesWithPath(texture, textureType); ;
var bytesWithMime = GetBytesWithMime(texture, textureType); ;

// add view
var view = gltf.buffers[bufferIndex].Append(bytesWithPath.Bytes, glBufferTarget.NONE);
var view = gltf.buffers[bufferIndex].Append(bytesWithMime.Bytes, glBufferTarget.NONE);
var viewIndex = gltf.AddBufferView(view);

// add image
Expand All @@ -149,7 +154,7 @@ public static int ExportTexture(glTF gltf, int bufferIndex, Texture texture, glT
{
name = texture.name,
bufferView = viewIndex,
mimeType = bytesWithPath.Mime,
mimeType = bytesWithMime.Mime,
});

// add sampler
Expand Down

0 comments on commit 2d70847

Please sign in to comment.