mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-30 23:01:24 -05:00
mv TextureImportParam TextureDescriptor
This commit is contained in:
@@ -42,7 +42,7 @@ namespace UniGLTF
|
||||
return Path.GetExtension(uri).ToLower();
|
||||
}
|
||||
|
||||
public void Extract(SubAssetKey key, TextureImportParam param)
|
||||
public void Extract(SubAssetKey key, TextureDescriptor texDesc)
|
||||
{
|
||||
if (Textures.ContainsKey(key))
|
||||
{
|
||||
|
||||
@@ -58,13 +58,13 @@ namespace UniGLTF
|
||||
var src = parser.GLTF.materials[i];
|
||||
param = new MaterialImportParam(GltfMaterialImporter.GetMaterialName(i, src), ShaderName);
|
||||
|
||||
var standardParam = default(TextureImportParam);
|
||||
var standardTexDesc = default(TextureDescriptor);
|
||||
if (src.pbrMetallicRoughness != null || src.occlusionTexture != null)
|
||||
{
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null || src.occlusionTexture != null)
|
||||
{
|
||||
SubAssetKey key;
|
||||
(key, standardParam) = GltfPbrTextureImporter.StandardTexture(parser, src);
|
||||
(key, standardTexDesc) = GltfPbrTextureImporter.StandardTexture(parser, src);
|
||||
}
|
||||
|
||||
if (src.pbrMetallicRoughness.baseColorFactor != null && src.pbrMetallicRoughness.baseColorFactor.Length == 4)
|
||||
@@ -83,7 +83,7 @@ namespace UniGLTF
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null && src.pbrMetallicRoughness.metallicRoughnessTexture.index != -1)
|
||||
{
|
||||
param.Actions.Add(material => material.EnableKeyword("_METALLICGLOSSMAP"));
|
||||
param.TextureSlots.Add("_MetallicGlossMap", standardParam);
|
||||
param.TextureSlots.Add("_MetallicGlossMap", standardTexDesc);
|
||||
// Set 1.0f as hard-coded. See: https://github.com/dwango/UniVRM/issues/212.
|
||||
param.FloatValues.Add("_Metallic", 1.0f);
|
||||
param.FloatValues.Add("_GlossMapScale", 1.0f);
|
||||
@@ -105,7 +105,7 @@ namespace UniGLTF
|
||||
|
||||
if (src.occlusionTexture != null && src.occlusionTexture.index != -1)
|
||||
{
|
||||
param.TextureSlots.Add("_OcclusionMap", standardParam);
|
||||
param.TextureSlots.Add("_OcclusionMap", standardTexDesc);
|
||||
param.FloatValues.Add("_OcclusionStrength", src.occlusionTexture.strength);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace UniGLTF
|
||||
{
|
||||
public static class MaterialImporterParamExtensions
|
||||
{
|
||||
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateSubAssetKeyValue(this MaterialImportParam param)
|
||||
public static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateSubAssetKeyValue(this MaterialImportParam param)
|
||||
{
|
||||
foreach (var kv in param.TextureSlots)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace UniGLTF
|
||||
{
|
||||
public sealed class GltfPbrTextureImporter
|
||||
{
|
||||
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTextures(GltfParser parser, int i)
|
||||
public static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfParser parser, int i)
|
||||
{
|
||||
var m = parser.GLTF.materials[i];
|
||||
|
||||
@@ -51,13 +51,13 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) BaseColorTexture(GltfParser parser, glTFMaterial src)
|
||||
public static (SubAssetKey, TextureDescriptor) BaseColorTexture(GltfParser parser, glTFMaterial src)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
return GltfTextureImporter.CreateSRGB(parser, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam) StandardTexture(GltfParser parser, glTFMaterial src)
|
||||
public static (SubAssetKey, TextureDescriptor) StandardTexture(GltfParser parser, glTFMaterial src)
|
||||
{
|
||||
var metallicFactor = 1.0f;
|
||||
var roughnessFactor = 1.0f;
|
||||
@@ -75,13 +75,13 @@ namespace UniGLTF
|
||||
roughnessFactor);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) NormalTexture(GltfParser parser, glTFMaterial src)
|
||||
public static (SubAssetKey, TextureDescriptor) NormalTexture(GltfParser parser, glTFMaterial src)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.normalTexture);
|
||||
return GltfTextureImporter.CreateNormal(parser, src.normalTexture.index, offset, scale);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) EmissiveTexture(GltfParser parser, glTFMaterial src)
|
||||
public static (SubAssetKey, TextureDescriptor) EmissiveTexture(GltfParser parser, glTFMaterial src)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.emissiveTexture);
|
||||
return GltfTextureImporter.CreateSRGB(parser, src.emissiveTexture.index, offset, scale);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace UniGLTF
|
||||
/// <summary>
|
||||
/// glTF 全体で使うテクスチャーを列挙。
|
||||
/// </summary>
|
||||
private static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTextures(GltfParser parser)
|
||||
private static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfParser parser)
|
||||
{
|
||||
for (int i = 0; i < parser.GLTF.materials.Count; ++i)
|
||||
{
|
||||
|
||||
@@ -29,40 +29,40 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) CreateSRGB(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static (SubAssetKey, TextureDescriptor) CreateSRGB(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
var gltfTexture = parser.GLTF.textures[textureIndex];
|
||||
var gltfImage = parser.GLTF.images[gltfTexture.source];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(parser.GLTF, textureIndex);
|
||||
GetTextureBytesAsync getTextureBytesAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex)));
|
||||
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
var param = new TextureDescriptor(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) CreateLinear(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static (SubAssetKey, TextureDescriptor) CreateLinear(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
var gltfTexture = parser.GLTF.textures[textureIndex];
|
||||
var gltfImage = parser.GLTF.images[gltfTexture.source];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.Linear, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(parser.GLTF, textureIndex);
|
||||
GetTextureBytesAsync getTextureBytesAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex)));
|
||||
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.Linear, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
var param = new TextureDescriptor(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.Linear, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) CreateNormal(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static (SubAssetKey, TextureDescriptor) CreateNormal(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
var gltfTexture = parser.GLTF.textures[textureIndex];
|
||||
var gltfImage = parser.GLTF.images[gltfTexture.source];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.NormalMap, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(parser.GLTF, textureIndex);
|
||||
GetTextureBytesAsync getTextureBytesAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex)));
|
||||
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
var param = new TextureDescriptor(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) CreateStandard(GltfParser parser, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor)
|
||||
public static (SubAssetKey, TextureDescriptor) CreateStandard(GltfParser parser, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor)
|
||||
{
|
||||
string name = default;
|
||||
|
||||
@@ -88,8 +88,8 @@ namespace UniGLTF
|
||||
getOcclusionAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, occlusionTextureIndex.Value)));
|
||||
}
|
||||
|
||||
var param = new TextureImportParam(name, ".png", null, offset, scale, sampler, TextureImportTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
var texDesc = new TextureDescriptor(name, ".png", null, offset, scale, sampler, TextureImportTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
|
||||
return (texDesc.SubAssetKey, texDesc);
|
||||
}
|
||||
|
||||
public static (Vector2, Vector2) GetTextureOffsetAndScale(glTFTextureInfo textureInfo)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace VRM
|
||||
{
|
||||
public static class VRMMToonTextureImporter
|
||||
{
|
||||
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTextures(GltfParser parser, glTF_VRM_extensions vrm, int materialIdx)
|
||||
public static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfParser parser, glTF_VRM_extensions vrm, int materialIdx)
|
||||
{
|
||||
var vrmMaterial = vrm.materialProperties[materialIdx];
|
||||
foreach (var kv in vrmMaterial.textureProperties)
|
||||
@@ -19,7 +19,7 @@ namespace VRM
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetTextureFromMaterialProperty(GltfParser parser, glTF_VRM_extensions vrm, int materialIdx, string textureKey, out (SubAssetKey, TextureImportParam) texture)
|
||||
public static bool TryGetTextureFromMaterialProperty(GltfParser parser, glTF_VRM_extensions vrm, int materialIdx, string textureKey, out (SubAssetKey, TextureDescriptor) texture)
|
||||
{
|
||||
var vrmMaterial = vrm.materialProperties[materialIdx];
|
||||
if (vrmMaterial.shader == MToon.Utils.ShaderName && vrmMaterial.textureProperties.TryGetValue(textureKey, out var textureIdx))
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace VRM
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTextures(GltfParser parser, glTF_VRM_extensions vrm)
|
||||
private static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfParser parser, glTF_VRM_extensions vrm)
|
||||
{
|
||||
// Materials
|
||||
for (var materialIdx = 0; materialIdx < parser.GLTF.materials.Count; ++materialIdx)
|
||||
@@ -65,7 +65,7 @@ namespace VRM
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetThumbnailTexture(GltfParser parser, glTF_VRM_extensions vrm, out (SubAssetKey, TextureImportParam) texture)
|
||||
private static bool TryGetThumbnailTexture(GltfParser parser, glTF_VRM_extensions vrm, out (SubAssetKey, TextureDescriptor) texture)
|
||||
{
|
||||
if (vrm.meta.texture > -1)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace UniVRM10
|
||||
{
|
||||
public static class Vrm10MToonTextureImporter
|
||||
{
|
||||
public static IEnumerable<(string key, (SubAssetKey, TextureImportParam))> EnumerateAllTextures(GltfParser parser, glTFMaterial material, VRMC_materials_mtoon mToon)
|
||||
public static IEnumerable<(string key, (SubAssetKey, TextureDescriptor))> EnumerateAllTextures(GltfParser parser, glTFMaterial material, VRMC_materials_mtoon mToon)
|
||||
{
|
||||
if (TryGetBaseColorTexture(parser, material, out var litTex))
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetEmissiveTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetEmissiveTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace UniVRM10
|
||||
|
||||
}
|
||||
|
||||
private static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -116,37 +116,37 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetShadeMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetShadeMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetShadingShiftTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetShadingShiftTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetMatcapTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetMatcapTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetRimMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetRimMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetOutlineWidthMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetOutlineWidthMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetUvAnimationMaskTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetUvAnimationMaskTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair);
|
||||
}
|
||||
|
||||
private static bool TryGetSRGBTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetSRGBTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -165,7 +165,7 @@ namespace UniVRM10
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static bool TryGetLinearTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair)
|
||||
private static bool TryGetLinearTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureDescriptor) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace UniVRM10
|
||||
/// <summary>
|
||||
/// glTF 全体で使うテクスチャーを列挙する
|
||||
/// </summary>
|
||||
private static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTextures(GltfParser parser)
|
||||
private static IEnumerable<(SubAssetKey, TextureDescriptor)> EnumerateAllTextures(GltfParser parser)
|
||||
{
|
||||
if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
// Thumbnail Texture referenced by VRM Meta.
|
||||
if (TryGetMetaThumbnailTextureImportParam(parser, vrm, out (SubAssetKey key, TextureImportParam) thumbnail))
|
||||
if (TryGetMetaThumbnailTextureImportParam(parser, vrm, out (SubAssetKey key, TextureDescriptor) thumbnail))
|
||||
{
|
||||
yield return thumbnail;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace UniVRM10
|
||||
/// <summary>
|
||||
/// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い)
|
||||
/// </summary>
|
||||
public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out (SubAssetKey, TextureImportParam) value)
|
||||
public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
if (vrm?.Meta?.ThumbnailImage == null)
|
||||
{
|
||||
@@ -88,11 +88,11 @@ namespace UniVRM10
|
||||
var bytes = parser.GLTF.GetImageBytes(parser.Storage, imageIndex);
|
||||
return Task.FromResult(GltfTextureImporter.ToArray(bytes));
|
||||
};
|
||||
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
|
||||
var texDesc = new TextureDescriptor(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
|
||||
getThumbnailImageBytesAsync, default, default,
|
||||
default, default, default
|
||||
);
|
||||
value = (param.SubAssetKey, param);
|
||||
value = (texDesc.SubAssetKey, texDesc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace UniVRM10
|
||||
{
|
||||
m_meta.Authors.AddRange(src.Authors);
|
||||
}
|
||||
if (Vrm10TextureDescriptorGenerator.TryGetMetaThumbnailTextureImportParam(Parser, vrm, out (SubAssetKey, VRMShaders.TextureImportParam Param) kv))
|
||||
if (Vrm10TextureDescriptorGenerator.TryGetMetaThumbnailTextureImportParam(Parser, vrm, out (SubAssetKey, VRMShaders.TextureDescriptor Param) kv))
|
||||
{
|
||||
var texture = await TextureFactory.GetTextureAsync(kv.Param);
|
||||
if (texture is Texture2D tex2D)
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace VRMShaders
|
||||
textureImporter.SaveAndReimport();
|
||||
}
|
||||
|
||||
public static void ConfigureSampler(TextureImportParam param, TextureImporter textureImporter)
|
||||
public static void ConfigureSampler(TextureDescriptor texDesc, TextureImporter textureImporter)
|
||||
{
|
||||
textureImporter.mipmapEnabled = param.Sampler.EnableMipMap;
|
||||
textureImporter.filterMode = param.Sampler.FilterMode;
|
||||
textureImporter.wrapModeU = param.Sampler.WrapModesU;
|
||||
textureImporter.wrapModeV = param.Sampler.WrapModesV;
|
||||
textureImporter.mipmapEnabled = texDesc.Sampler.EnableMipMap;
|
||||
textureImporter.filterMode = texDesc.Sampler.FilterMode;
|
||||
textureImporter.wrapModeU = texDesc.Sampler.WrapModesU;
|
||||
textureImporter.wrapModeV = texDesc.Sampler.WrapModesV;
|
||||
}
|
||||
|
||||
class ImporterGetter : IDisposable
|
||||
@@ -84,9 +84,9 @@ namespace VRMShaders
|
||||
}
|
||||
}
|
||||
|
||||
static void Configure(TextureImportParam textureInfo, Texture external, TextureImporter importer)
|
||||
static void Configure(TextureDescriptor texDesc, Texture external, TextureImporter importer)
|
||||
{
|
||||
switch (textureInfo.TextureType)
|
||||
switch (texDesc.TextureType)
|
||||
{
|
||||
case TextureImportTypes.NormalMap:
|
||||
{
|
||||
@@ -119,18 +119,18 @@ namespace VRMShaders
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ConfigureSampler(textureInfo, importer);
|
||||
ConfigureSampler(texDesc, importer);
|
||||
}
|
||||
|
||||
public static void Configure(TextureImportParam textureInfo, IReadOnlyDictionary<SubAssetKey, Texture> ExternalMap)
|
||||
public static void Configure(TextureDescriptor texDesc, IReadOnlyDictionary<SubAssetKey, Texture> ExternalMap)
|
||||
{
|
||||
if (ExternalMap.TryGetValue(textureInfo.SubAssetKey, out Texture external))
|
||||
if (ExternalMap.TryGetValue(texDesc.SubAssetKey, out Texture external))
|
||||
{
|
||||
if (ImporterGetter.TryGetImporter(external, out ImporterGetter getter))
|
||||
{
|
||||
using (getter)
|
||||
{
|
||||
Configure(textureInfo, external, getter.Importer);
|
||||
Configure(texDesc, external, getter.Importer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace VRMShaders
|
||||
{
|
||||
public delegate Task<Texture> GetTextureAsyncFunc(TextureImportParam param);
|
||||
public delegate Task<Texture> GetTextureAsyncFunc(TextureDescriptor texDesc);
|
||||
|
||||
public class MaterialFactory : IDisposable
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace VRMShaders
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string ShaderName;
|
||||
public readonly Dictionary<string, TextureImportParam> TextureSlots = new Dictionary<string, TextureImportParam>();
|
||||
public readonly Dictionary<string, TextureDescriptor> TextureSlots = new Dictionary<string, TextureDescriptor>();
|
||||
public readonly Dictionary<string, float> FloatValues = new Dictionary<string, float>();
|
||||
public readonly Dictionary<string, Color> Colors = new Dictionary<string, Color>();
|
||||
public readonly Dictionary<string, Vector4> Vectors = new Dictionary<string, Vector4>();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace VRMShaders
|
||||
/// <summary>
|
||||
/// 入力 glTF ファイルを Import した結果生成される、UnityEngine.Texture のアセット 1 つを確定させる Import 情報。
|
||||
/// </summary>
|
||||
public readonly struct TextureImportParam
|
||||
public readonly struct TextureDescriptor
|
||||
{
|
||||
public readonly string UnityObjectName;
|
||||
public readonly string Ext;
|
||||
@@ -46,7 +46,7 @@ namespace VRMShaders
|
||||
/// </summary>
|
||||
public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.TextureType, UnityObjectName);
|
||||
|
||||
public TextureImportParam(string name, string ext, string uri, Vector2 offset, Vector2 scale, SamplerParam sampler, TextureImportTypes textureType, float metallicFactor, float roughnessFactor,
|
||||
public TextureDescriptor(string name, string ext, string uri, Vector2 offset, Vector2 scale, SamplerParam sampler, TextureImportTypes textureType, float metallicFactor, float roughnessFactor,
|
||||
GetTextureBytesAsync i0,
|
||||
GetTextureBytesAsync i1,
|
||||
GetTextureBytesAsync i2,
|
||||
@@ -7,18 +7,18 @@ namespace VRMShaders
|
||||
/// </summary>
|
||||
public sealed class TextureDescriptorSet
|
||||
{
|
||||
private readonly Dictionary<SubAssetKey, TextureImportParam> _params = new Dictionary<SubAssetKey, TextureImportParam>();
|
||||
private readonly Dictionary<SubAssetKey, TextureDescriptor> _texDescDict = new Dictionary<SubAssetKey, TextureDescriptor>();
|
||||
|
||||
public void Add(TextureImportParam param)
|
||||
public void Add(TextureDescriptor texDesc)
|
||||
{
|
||||
if (_params.ContainsKey(param.SubAssetKey)) return;
|
||||
if (_texDescDict.ContainsKey(texDesc.SubAssetKey)) return;
|
||||
|
||||
_params.Add(param.SubAssetKey, param);
|
||||
_texDescDict.Add(texDesc.SubAssetKey, texDesc);
|
||||
}
|
||||
|
||||
public IEnumerable<TextureImportParam> GetEnumerable()
|
||||
public IEnumerable<TextureDescriptor> GetEnumerable()
|
||||
{
|
||||
foreach (var kv in _params)
|
||||
foreach (var kv in _texDescDict)
|
||||
{
|
||||
yield return kv.Value;
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ namespace VRMShaders
|
||||
/// <param name="roughnessFactor">METALLIC_GLOSS_PROPの追加パラメーター</param>
|
||||
/// <param name="indices">gltf の texture index</param>
|
||||
/// <returns></returns>
|
||||
public async Task<Texture> GetTextureAsync(TextureImportParam param)
|
||||
public async Task<Texture> GetTextureAsync(TextureDescriptor texDesc)
|
||||
{
|
||||
var subAssetKey = param.SubAssetKey;
|
||||
var subAssetKey = texDesc.SubAssetKey;
|
||||
|
||||
if (m_externalMap != null && m_externalMap.TryGetValue(subAssetKey, out var externalTexture))
|
||||
{
|
||||
@@ -95,15 +95,15 @@ namespace VRMShaders
|
||||
return cachedTexture;
|
||||
}
|
||||
|
||||
switch (param.TextureType)
|
||||
switch (texDesc.TextureType)
|
||||
{
|
||||
case TextureImportTypes.NormalMap:
|
||||
{
|
||||
// Runtime/SubAsset 用に変換する
|
||||
var rawTexture = await LoadTextureAsync(param.Index0, param.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
var convertedTexture = NormalConverter.Import(rawTexture);
|
||||
convertedTexture.name = subAssetKey.Name;
|
||||
convertedTexture.SetSampler(param.Sampler);
|
||||
convertedTexture.SetSampler(texDesc.Sampler);
|
||||
m_textureCache.Add(subAssetKey, convertedTexture);
|
||||
DestroyResource(rawTexture);
|
||||
return convertedTexture;
|
||||
@@ -114,19 +114,19 @@ namespace VRMShaders
|
||||
Texture2D metallicRoughnessTexture = default;
|
||||
Texture2D occlusionTexture = default;
|
||||
|
||||
if (param.Index0 != null)
|
||||
if (texDesc.Index0 != null)
|
||||
{
|
||||
metallicRoughnessTexture = await LoadTextureAsync(param.Index0, param.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
metallicRoughnessTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
}
|
||||
if (param.Index1 != null)
|
||||
if (texDesc.Index1 != null)
|
||||
{
|
||||
occlusionTexture = await LoadTextureAsync(param.Index1, param.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
occlusionTexture = await LoadTextureAsync(texDesc.Index1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
}
|
||||
|
||||
var combinedTexture = OcclusionMetallicRoughnessConverter.Import(metallicRoughnessTexture,
|
||||
param.MetallicFactor, param.RoughnessFactor, occlusionTexture);
|
||||
texDesc.MetallicFactor, texDesc.RoughnessFactor, occlusionTexture);
|
||||
combinedTexture.name = subAssetKey.Name;
|
||||
combinedTexture.SetSampler(param.Sampler);
|
||||
combinedTexture.SetSampler(texDesc.Sampler);
|
||||
m_textureCache.Add(subAssetKey, combinedTexture);
|
||||
DestroyResource(metallicRoughnessTexture);
|
||||
DestroyResource(occlusionTexture);
|
||||
@@ -135,17 +135,17 @@ namespace VRMShaders
|
||||
|
||||
case TextureImportTypes.sRGB:
|
||||
{
|
||||
var rawTexture = await LoadTextureAsync(param.Index0, param.Sampler.EnableMipMap, ColorSpace.sRGB);
|
||||
var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB);
|
||||
rawTexture.name = subAssetKey.Name;
|
||||
rawTexture.SetSampler(param.Sampler);
|
||||
rawTexture.SetSampler(texDesc.Sampler);
|
||||
m_textureCache.Add(subAssetKey, rawTexture);
|
||||
return rawTexture;
|
||||
}
|
||||
case TextureImportTypes.Linear:
|
||||
{
|
||||
var rawTexture = await LoadTextureAsync(param.Index0, param.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear);
|
||||
rawTexture.name = subAssetKey.Name;
|
||||
rawTexture.SetSampler(param.Sampler);
|
||||
rawTexture.SetSampler(texDesc.Sampler);
|
||||
m_textureCache.Add(subAssetKey, rawTexture);
|
||||
return rawTexture;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user