mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-19 08:41:49 -05:00
out (SubAssetKey, TextureDescriptor) を 2つの out に展開
This commit is contained in:
parent
f2d587e09f
commit
d974ddfa57
|
|
@ -76,13 +76,13 @@ namespace UniGLTF
|
|||
{
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null || src.occlusionTexture != null)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
standardTexDesc = value.Item2;
|
||||
standardTexDesc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,13 +97,13 @@ namespace UniGLTF
|
|||
if (src.pbrMetallicRoughness.baseColorTexture != null &&
|
||||
src.pbrMetallicRoughness.baseColorTexture.index != -1)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_MainTex", value.Item2);
|
||||
textureSlots.Add("_MainTex", desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,13 +127,13 @@ namespace UniGLTF
|
|||
if (src.normalTexture != null && src.normalTexture.index != -1)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_NORMALMAP"));
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_BumpMap", value.Item2);
|
||||
textureSlots.Add("_BumpMap", desc);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
}
|
||||
}
|
||||
|
|
@ -172,13 +172,13 @@ namespace UniGLTF
|
|||
|
||||
if (src.emissiveTexture != null && src.emissiveTexture.index != -1)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_EmissionMap", value.Item2);
|
||||
textureSlots.Add("_EmissionMap", desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ namespace UniGLTF
|
|||
if (src.pbrMetallicRoughness.baseColorTexture != null)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
if (GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out var value))
|
||||
if (GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out var key, out var desc))
|
||||
{
|
||||
textureSlots.Add("_MainTex", value.Item2);
|
||||
textureSlots.Add("_MainTex", desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ namespace UniGLTF
|
|||
{
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null || src.occlusionTexture != null)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
standardTexDesc = value.Item2;
|
||||
standardTexDesc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,10 +67,10 @@ namespace UniGLTF
|
|||
|
||||
if (src.pbrMetallicRoughness.baseColorTexture != null && src.pbrMetallicRoughness.baseColorTexture.index != -1)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
// from _MainTex !
|
||||
textureSlots.Add("_BaseMap", value.Item2);
|
||||
textureSlots.Add("_BaseMap", desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,10 +95,9 @@ namespace UniGLTF
|
|||
if (src.normalTexture != null && src.normalTexture.index != -1)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_NORMALMAP"));
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
var (key, textureParam) = value;
|
||||
textureSlots.Add("_BumpMap", textureParam);
|
||||
textureSlots.Add("_BumpMap", desc);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
}
|
||||
}
|
||||
|
|
@ -136,9 +135,9 @@ namespace UniGLTF
|
|||
|
||||
if (src.emissiveTexture != null && src.emissiveTexture.index != -1)
|
||||
{
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var value))
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var key, out var desc))
|
||||
{
|
||||
textureSlots.Add("_EmissionMap", value.Item2);
|
||||
textureSlots.Add("_EmissionMap", desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ namespace UniGLTF
|
|||
// base color
|
||||
if (m.pbrMetallicRoughness?.baseColorTexture != null)
|
||||
{
|
||||
if (TryBaseColorTexture(data, m, out var value))
|
||||
if (TryBaseColorTexture(data, m, out var key, out var desc))
|
||||
{
|
||||
yield return value;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,18 +31,18 @@ namespace UniGLTF
|
|||
// emission
|
||||
if (m.emissiveTexture != null)
|
||||
{
|
||||
if (TryEmissiveTexture(data, m, out var value))
|
||||
if (TryEmissiveTexture(data, m, out var key, out var desc))
|
||||
{
|
||||
yield return value;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
// normal
|
||||
if (m.normalTexture != null)
|
||||
{
|
||||
if (TryNormalTexture(data, m, out var value))
|
||||
if (TryNormalTexture(data, m, out var key, out var desc))
|
||||
{
|
||||
yield return value;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,20 +56,20 @@ namespace UniGLTF
|
|||
// metallicSmooth and occlusion
|
||||
if (metallicRoughnessTexture.HasValue || occlusionTexture.HasValue)
|
||||
{
|
||||
if (TryStandardTexture(data, m, out var value))
|
||||
if (TryStandardTexture(data, m, out var key, out var desc))
|
||||
{
|
||||
yield return value;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryBaseColorTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryBaseColorTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out value);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out key, out desc);
|
||||
}
|
||||
|
||||
public static bool TryStandardTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryStandardTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var metallicFactor = 1.0f;
|
||||
var roughnessFactor = 1.0f;
|
||||
|
|
@ -84,19 +84,19 @@ namespace UniGLTF
|
|||
src.occlusionTexture?.index,
|
||||
offset, scale,
|
||||
metallicFactor,
|
||||
roughnessFactor, out value);
|
||||
roughnessFactor, out key, out desc);
|
||||
}
|
||||
|
||||
public static bool TryNormalTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryNormalTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.normalTexture);
|
||||
return GltfTextureImporter.TryCreateNormal(data, src.normalTexture.index, offset, scale, out value);
|
||||
return GltfTextureImporter.TryCreateNormal(data, src.normalTexture.index, offset, scale, out key, out desc);
|
||||
}
|
||||
|
||||
public static bool TryEmissiveTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryEmissiveTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.emissiveTexture);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.emissiveTexture.index, offset, scale, out value);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.emissiveTexture.index, offset, scale, out key, out desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,19 +35,20 @@ namespace UniGLTF
|
|||
return (texDesc.SubAssetKey, texDesc);
|
||||
}
|
||||
|
||||
public static bool TryCreateSrgb(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryCreateSrgb(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
desc = new TextureDescriptor(
|
||||
name,
|
||||
offset, scale,
|
||||
sampler,
|
||||
|
|
@ -56,23 +57,24 @@ namespace UniGLTF
|
|||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
value = (param.SubAssetKey, param);
|
||||
key = desc.SubAssetKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryCreateLinear(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryCreateLinear(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.Linear, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
desc = new TextureDescriptor(
|
||||
name,
|
||||
offset,
|
||||
scale,
|
||||
|
|
@ -82,23 +84,24 @@ namespace UniGLTF
|
|||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
value = (param.SubAssetKey, param);
|
||||
key = desc.SubAssetKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryCreateNormal(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryCreateNormal(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.NormalMap, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
desc = new TextureDescriptor(
|
||||
name,
|
||||
offset,
|
||||
scale,
|
||||
|
|
@ -108,11 +111,11 @@ namespace UniGLTF
|
|||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
value = (param.SubAssetKey, param);
|
||||
key = desc.SubAssetKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryCreateStandard(GltfData data, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor, out (SubAssetKey, TextureDescriptor) value)
|
||||
public static bool TryCreateStandard(GltfData data, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
string name = default;
|
||||
|
||||
|
|
@ -146,11 +149,12 @@ namespace UniGLTF
|
|||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
value = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var texDesc = new TextureDescriptor(
|
||||
desc = new TextureDescriptor(
|
||||
name,
|
||||
offset,
|
||||
scale,
|
||||
|
|
@ -161,8 +165,8 @@ namespace UniGLTF
|
|||
getMetallicRoughnessAsync,
|
||||
getOcclusionAsync,
|
||||
default, default, default, default);
|
||||
value = (texDesc.SubAssetKey, texDesc);
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
key = desc.SubAssetKey;
|
||||
if (string.IsNullOrEmpty(desc.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,10 +301,9 @@ namespace VRM
|
|||
meta.Title = gltfMeta.title;
|
||||
if (gltfMeta.texture >= 0)
|
||||
{
|
||||
if (GltfTextureImporter.TryCreateSrgb(Data, gltfMeta.texture, Vector2.zero, Vector2.one, out var value))
|
||||
if (GltfTextureImporter.TryCreateSrgb(Data, gltfMeta.texture, Vector2.zero, Vector2.one, out var key, out var desc))
|
||||
{
|
||||
var (key, param) = value;
|
||||
meta.Thumbnail = await TextureFactory.GetTextureAsync(param, awaitCaller) as Texture2D;
|
||||
meta.Thumbnail = await TextureFactory.GetTextureAsync(desc, awaitCaller) as Texture2D;
|
||||
}
|
||||
}
|
||||
meta.AllowedUser = gltfMeta.allowedUser;
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ namespace VRM
|
|||
foreach (var kv in vrmMaterial.textureProperties)
|
||||
{
|
||||
if (VRMMToonTextureImporter.TryGetTextureFromMaterialProperty(data, vrmMaterial, kv.Key,
|
||||
out var texture))
|
||||
out var key, out var desc))
|
||||
{
|
||||
textureSlots.Add(kv.Key, texture.Item2);
|
||||
textureSlots.Add(kv.Key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ namespace VRM
|
|||
var vrmMaterial = vrm.materialProperties[materialIdx];
|
||||
foreach (var kv in vrmMaterial.textureProperties)
|
||||
{
|
||||
if (TryGetTextureFromMaterialProperty(data, vrmMaterial, kv.Key, out var texture))
|
||||
if (TryGetTextureFromMaterialProperty(data, vrmMaterial, kv.Key, out var key, out var desc))
|
||||
{
|
||||
yield return texture;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool TryGetTextureFromMaterialProperty(GltfData data, glTF_VRM_Material vrmMaterial, string textureKey, out (SubAssetKey, TextureDescriptor) texture)
|
||||
public static bool TryGetTextureFromMaterialProperty(GltfData data, glTF_VRM_Material vrmMaterial, string textureKey, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
// 任意の shader の import を許容する
|
||||
if (/*vrmMaterial.shader == MToon.Utils.ShaderName &&*/ vrmMaterial.textureProperties.TryGetValue(textureKey, out var textureIdx))
|
||||
|
|
@ -33,13 +33,14 @@ namespace VRM
|
|||
switch (textureKey)
|
||||
{
|
||||
case MToon.Utils.PropBumpMap:
|
||||
return GltfTextureImporter.TryCreateNormal(data, textureIdx, offset, scale, out texture);
|
||||
return GltfTextureImporter.TryCreateNormal(data, textureIdx, offset, scale, out key, out desc);
|
||||
default:
|
||||
return GltfTextureImporter.TryCreateSrgb(data, textureIdx, offset, scale, out texture);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, textureIdx, offset, scale, out key, out desc);
|
||||
}
|
||||
}
|
||||
|
||||
texture = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ namespace VRM
|
|||
if (vrmMaterial.textureProperties.ContainsKey(UnlitTransparentZWriteMainTexturePropName))
|
||||
{
|
||||
if (VRMMToonTextureImporter.TryGetTextureFromMaterialProperty(data, vrmMaterial,
|
||||
UnlitTransparentZWriteMainTexturePropName, out var texture))
|
||||
UnlitTransparentZWriteMainTexturePropName, out var key, out var desc))
|
||||
{
|
||||
textureSlots.Add(MToon.Utils.PropMainTex, texture.Item2);
|
||||
textureSlots.Add(MToon.Utils.PropMainTex, desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,20 +59,21 @@ namespace VRM
|
|||
}
|
||||
|
||||
// Thumbnail
|
||||
if (TryGetThumbnailTexture(data, vrm, out var thumbnail))
|
||||
if (TryGetThumbnailTexture(data, vrm, out var key, out var desc))
|
||||
{
|
||||
yield return thumbnail;
|
||||
yield return (key, desc);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetThumbnailTexture(GltfData data, glTF_VRM_extensions vrm, out (SubAssetKey, TextureDescriptor) texture)
|
||||
private static bool TryGetThumbnailTexture(GltfData data, glTF_VRM_extensions vrm, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
if (vrm.meta.texture > -1)
|
||||
{
|
||||
return GltfTextureImporter.TryCreateSrgb(data, vrm.meta.texture, Vector2.zero, Vector2.one, out texture);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, vrm.meta.texture, Vector2.zero, Vector2.one, out key, out desc);
|
||||
}
|
||||
|
||||
texture = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,170 +12,180 @@ namespace UniVRM10
|
|||
{
|
||||
public static IEnumerable<(string key, (SubAssetKey, TextureDescriptor))> EnumerateAllTextures(GltfData data, glTFMaterial material, VRMC_materials_mtoon mToon)
|
||||
{
|
||||
if (TryGetBaseColorTexture(data, material, out var litTex))
|
||||
if (TryGetBaseColorTexture(data, material, out var key, out var desc))
|
||||
{
|
||||
yield return (MToon10Prop.BaseColorTexture.ToUnityShaderLabName(), litTex);
|
||||
yield return (MToon10Prop.BaseColorTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetEmissiveTexture(data, material, out var emissiveTex))
|
||||
if (TryGetEmissiveTexture(data, material, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.EmissiveTexture.ToUnityShaderLabName(), emissiveTex);
|
||||
yield return (MToon10Prop.EmissiveTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetNormalTexture(data, material, out var normalTex))
|
||||
if (TryGetNormalTexture(data, material, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.NormalTexture.ToUnityShaderLabName(), normalTex);
|
||||
yield return (MToon10Prop.NormalTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetShadeMultiplyTexture(data, mToon, out var shadeTex))
|
||||
if (TryGetShadeMultiplyTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.ShadeColorTexture.ToUnityShaderLabName(), shadeTex);
|
||||
yield return (MToon10Prop.ShadeColorTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetShadingShiftTexture(data, mToon, out var shadeShiftTex))
|
||||
if (TryGetShadingShiftTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.ShadingShiftTexture.ToUnityShaderLabName(), shadeShiftTex);
|
||||
yield return (MToon10Prop.ShadingShiftTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetMatcapTexture(data, mToon, out var matcapTex))
|
||||
if (TryGetMatcapTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.MatcapTexture.ToUnityShaderLabName(), matcapTex);
|
||||
yield return (MToon10Prop.MatcapTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetRimMultiplyTexture(data, mToon, out var rimTex))
|
||||
if (TryGetRimMultiplyTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.RimMultiplyTexture.ToUnityShaderLabName(), rimTex);
|
||||
yield return (MToon10Prop.RimMultiplyTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetOutlineWidthMultiplyTexture(data, mToon, out var outlineTex))
|
||||
if (TryGetOutlineWidthMultiplyTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.OutlineWidthMultiplyTexture.ToUnityShaderLabName(), outlineTex);
|
||||
yield return (MToon10Prop.OutlineWidthMultiplyTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
|
||||
if (TryGetUvAnimationMaskTexture(data, mToon, out var uvAnimMaskTex))
|
||||
if (TryGetUvAnimationMaskTexture(data, mToon, out key, out desc))
|
||||
{
|
||||
yield return (MToon10Prop.UvAnimationMaskTexture.ToUnityShaderLabName(), uvAnimMaskTex);
|
||||
yield return (MToon10Prop.UvAnimationMaskTexture.ToUnityShaderLabName(), (key, desc));
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetBaseColorTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetBaseColorTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GltfPbrTextureImporter.TryBaseColorTexture(data, src, out pair);
|
||||
return GltfPbrTextureImporter.TryBaseColorTexture(data, src, out key, out desc);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetEmissiveTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetEmissiveTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GltfPbrTextureImporter.TryEmissiveTexture(data, src, out pair);
|
||||
return GltfPbrTextureImporter.TryEmissiveTexture(data, src, out key, out desc);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static bool TryGetNormalTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetNormalTexture(GltfData data, glTFMaterial src, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GltfPbrTextureImporter.TryNormalTexture(data, src, out pair);
|
||||
return GltfPbrTextureImporter.TryNormalTexture(data, src, out key, out desc);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out pair);
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetShadingShiftTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetShadingShiftTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetMatcapTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetMatcapTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.MatcapTexture), out pair);
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.MatcapTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetRimMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetRimMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair);
|
||||
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetOutlineWidthMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetOutlineWidthMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair);
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetUvAnimationMaskTexture(GltfData data, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetUvAnimationMaskTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair);
|
||||
return TryGetLinearTexture(data, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out key, out desc);
|
||||
}
|
||||
|
||||
private static bool TryGetSRGBTexture(GltfData data, Vrm10TextureInfo info, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetSRGBTexture(GltfData data, Vrm10TextureInfo info, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (offset, scale) = GetTextureOffsetAndScale(info);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, info.index, offset, scale, out pair);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, info.index, offset, scale, out key, out desc);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static bool TryGetLinearTexture(GltfData data, Vrm10TextureInfo info, out (SubAssetKey, TextureDescriptor) pair)
|
||||
private static bool TryGetLinearTexture(GltfData data, Vrm10TextureInfo info, out SubAssetKey key, out TextureDescriptor desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (offset, scale) = GetTextureOffsetAndScale(info);
|
||||
return GltfTextureImporter.TryCreateLinear(data, info.index, offset, scale, out pair);
|
||||
return GltfTextureImporter.TryCreateLinear(data, info.index, offset, scale, out key, out desc);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
key = default;
|
||||
desc = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user