mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-25 07:28:51 -05:00
新しく FixNameUnique で名前を作る
This commit is contained in:
parent
4aca030dd5
commit
aad1b1252e
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
|
@ -68,6 +69,8 @@ namespace UniVRM10
|
|||
}
|
||||
}
|
||||
|
||||
public const string THUMBNAIL_NAME = "__VRM10_thumbnail__";
|
||||
|
||||
/// <summary>
|
||||
/// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い)
|
||||
/// </summary>
|
||||
|
|
@ -81,18 +84,25 @@ namespace UniVRM10
|
|||
|
||||
var imageIndex = vrm.Meta.ThumbnailImage.Value;
|
||||
var gltfImage = data.GLTF.images[imageIndex];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfImage.name, gltfImage.uri);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
|
||||
// data.GLTF.textures は前処理によりユニーク性がある
|
||||
// unique な名前を振り出す
|
||||
var used = new HashSet<string>(data.GLTF.textures.Select(x => x.name));
|
||||
var imageName = gltfImage.name;
|
||||
if (string.IsNullOrEmpty(imageName))
|
||||
{
|
||||
name = MigrationVrmMeta.THUMBNAIL_NAME;
|
||||
imageName = THUMBNAIL_NAME;
|
||||
}
|
||||
var uniqueName = GlbLowLevelParser.FixNameUnique(used, imageName);
|
||||
|
||||
var objectName = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, uniqueName, gltfImage.uri);
|
||||
|
||||
GetTextureBytesAsync getThumbnailImageBytesAsync = () =>
|
||||
{
|
||||
var bytes = data.GLTF.GetImageBytes(data.Storage, imageIndex);
|
||||
return Task.FromResult(GltfTextureImporter.ToArray(bytes));
|
||||
};
|
||||
var texDesc = new TextureDescriptor(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
|
||||
var texDesc = new TextureDescriptor(objectName, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
|
||||
getThumbnailImageBytesAsync, default, default,
|
||||
default, default, default
|
||||
);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ namespace UniVRM10
|
|||
// },
|
||||
public static class MigrationVrmMeta
|
||||
{
|
||||
public const string THUMBNAIL_NAME = "__VRM10_thumbnail__";
|
||||
|
||||
public static UniGLTF.Extensions.VRMC_vrm.Meta Migrate(UniGLTF.glTF gltf, JsonNode vrm0)
|
||||
{
|
||||
var meta = new UniGLTF.Extensions.VRMC_vrm.Meta
|
||||
|
|
@ -60,19 +58,14 @@ namespace UniVRM10
|
|||
{
|
||||
// vrm0x use texture. vrm10 use image
|
||||
var textureIndex = kv.Value.GetInt32();
|
||||
var gltfTexture = gltf.textures[textureIndex];
|
||||
meta.ThumbnailImage = gltfTexture.source;
|
||||
|
||||
var gltfImage = gltf.images[gltfTexture.source];
|
||||
if (string.IsNullOrEmpty(gltfImage.name))
|
||||
if (textureIndex == -1)
|
||||
{
|
||||
// use texture name
|
||||
gltfImage.name = gltfTexture.name;
|
||||
if (string.IsNullOrEmpty(gltfImage.name))
|
||||
{
|
||||
// fall back default name
|
||||
gltfImage.name = THUMBNAIL_NAME;
|
||||
}
|
||||
meta.ThumbnailImage = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var gltfTexture = gltf.textures[textureIndex];
|
||||
meta.ThumbnailImage = gltfTexture.source;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user