mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 19:38:13 -05:00
Merge pull request #2280 from Santarh/basisuApi
Define ExtensionSupportFlags for limited supporting KHR_texture_basisu
This commit is contained in:
19
Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs
Normal file
19
Assets/UniGLTF/Runtime/UniGLTF/IO/ExtensionSupportFlags.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace UniGLTF
|
||||
{
|
||||
public sealed class ExtensionSupportFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// KHR_texture_basisu 拡張を考慮するかどうか。
|
||||
/// </summary>
|
||||
public bool ConsiderKhrTextureBasisu { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ファイルに含まれる "全ての" テクスチャの画像が Y 軸反転しているかどうか。
|
||||
/// 標準的なファイルは false。
|
||||
///
|
||||
/// Unity は内部で画像を Y 軸反転させているため、あらかじめ Y 軸反転させておくほうが効率的であり、その場合に対応。
|
||||
/// https://docs.unity3d.com/Packages/com.unity.cloud.ktx@3.2/manual/creating-textures.html
|
||||
/// </summary>
|
||||
public bool IsAllTexturesYFlipped { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b1a24ae974547b4bfec426c33c5d612
|
||||
timeCreated: 1714458314
|
||||
@@ -53,6 +53,13 @@ namespace UniGLTF
|
||||
/// </summary>
|
||||
public MigrationFlags MigrationFlags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Extension Supporting flags.
|
||||
///
|
||||
/// User can set flags to enable or disable some extensions.
|
||||
/// </summary>
|
||||
public ExtensionSupportFlags ExtensionSupportFlags { get; } = new ExtensionSupportFlags();
|
||||
|
||||
/// <summary>
|
||||
/// URI access
|
||||
/// </summary>
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace UniGLTF
|
||||
ITextureDeserializer textureDeserializer = null,
|
||||
IMaterialDescriptorGenerator materialGenerator = null)
|
||||
{
|
||||
TryValidateGltfData(data);
|
||||
Data = data;
|
||||
TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data);
|
||||
MaterialDescriptorGenerator = materialGenerator ?? new BuiltInGltfMaterialDescriptorGenerator();
|
||||
@@ -74,6 +75,21 @@ namespace UniGLTF
|
||||
"KHR_draco_mesh_compression",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// GltfData をバリデートし、読み込み不可能な問題があれば例外を投げる
|
||||
/// </summary>
|
||||
private static void TryValidateGltfData(GltfData data)
|
||||
{
|
||||
if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !Application.isPlaying)
|
||||
{
|
||||
throw new UniGLTFNotSupportedException("KHR_texture_basisu is only available in play mode.");
|
||||
}
|
||||
if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu && !data.ExtensionSupportFlags.IsAllTexturesYFlipped)
|
||||
{
|
||||
throw new UniGLTFNotSupportedException("KHR_texture_basisu is only supported with all textures Y-flipped.");
|
||||
}
|
||||
}
|
||||
|
||||
#region Load. Build unity objects
|
||||
public virtual async Task<RuntimeGltfInstance> LoadAsync(IAwaitCaller awaitCaller, Func<string, IDisposable> MeasureTime = null)
|
||||
{
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace UniGLTF
|
||||
/// </summary>
|
||||
public static class GltfTextureImporter
|
||||
{
|
||||
public static bool ImportKhrTextureBasisuExtension { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// glTF の Texture が存在せず Image のみのものを、Texture として扱いたい場合の関数.
|
||||
/// </summary>
|
||||
@@ -240,9 +238,7 @@ namespace UniGLTF
|
||||
{
|
||||
var texture = data.GLTF.textures[textureIndex];
|
||||
|
||||
// NOTE: Runtime の場合は KHR_texture_basisu 拡張を考える.
|
||||
if (ImportKhrTextureBasisuExtension &&
|
||||
Application.isPlaying &&
|
||||
if (data.ExtensionSupportFlags.ConsiderKhrTextureBasisu &&
|
||||
glTF_KHR_texture_basisu.TryGet(texture, out var basisuExtension))
|
||||
{
|
||||
var basisuImageIndex = basisuExtension.source;
|
||||
|
||||
Reference in New Issue
Block a user