Merge pull request #1903 from Santarh/thumbFIx

Consider thumbnail image's mimeType when loading the VRM 1.0 model.
This commit is contained in:
ousttrue 2022-11-04 14:00:47 +09:00 committed by GitHub
commit bc2131a3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -31,7 +31,7 @@ namespace UniGLTF
() => () =>
{ {
var imageBytes = data.GetBytesFromImage(imageIndex); var imageBytes = data.GetBytesFromImage(imageIndex);
return Task.FromResult<(byte[], string)?>((ToArray(imageBytes?.binary ?? default), null)); return Task.FromResult<(byte[], string)?>((ToArray(imageBytes?.binary ?? default), imageBytes?.mimeType));
}, },
default, default, default, default, default); default, default, default, default, default);
return (texDesc.SubAssetKey, texDesc); return (texDesc.SubAssetKey, texDesc);

View File

@ -10,6 +10,8 @@ namespace UniVRM10
{ {
public sealed class Vrm10TextureDescriptorGenerator : ITextureDescriptorGenerator public sealed class Vrm10TextureDescriptorGenerator : ITextureDescriptorGenerator
{ {
public const string UniqueThumbnailName = "thumbnail__VRM10";
private readonly GltfData m_data; private readonly GltfData m_data;
private TextureDescriptorSet _textureDescriptorSet; private TextureDescriptorSet _textureDescriptorSet;
@ -69,8 +71,6 @@ namespace UniVRM10
} }
} }
public const string THUMBNAIL_NAME = "__VRM10_thumbnail__";
/// <summary> /// <summary>
/// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い) /// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い)
/// </summary> /// </summary>
@ -99,12 +99,7 @@ namespace UniVRM10
// data.GLTF.textures は前処理によりユニーク性がある // data.GLTF.textures は前処理によりユニーク性がある
// unique な名前を振り出す // unique な名前を振り出す
var used = new HashSet<string>(data.GLTF.textures.Select(x => x.name)); var used = new HashSet<string>(data.GLTF.textures.Select(x => x.name));
var imageName = gltfImage.name; var uniqueName = GlbLowLevelParser.FixNameUnique(used, UniqueThumbnailName);
if (string.IsNullOrEmpty(imageName))
{
imageName = THUMBNAIL_NAME;
}
var uniqueName = GlbLowLevelParser.FixNameUnique(used, imageName);
value = GltfTextureImporter.CreateSrgbFromOnlyImage(data, imageIndex, uniqueName, gltfImage.uri); value = GltfTextureImporter.CreateSrgbFromOnlyImage(data, imageIndex, uniqueName, gltfImage.uri);
return true; return true;

View File

@ -18,7 +18,14 @@ namespace VRMShaders
case "image/jpeg": case "image/jpeg":
break; break;
default: default:
Debug.LogWarning($"Texture image MIME type `{textureInfo.DataMimeType}` is not supported."); if (string.IsNullOrEmpty(textureInfo.DataMimeType))
{
Debug.Log($"Texture image MIME type is empty.");
}
else
{
Debug.Log($"Texture image MIME type `{textureInfo.DataMimeType}` is not supported.");
}
break; break;
} }