mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 21:38:56 -05:00
VRMShaders.TextureImportTypes
This commit is contained in:
@@ -61,7 +61,7 @@ namespace UniGLTF
|
||||
{
|
||||
switch (x.TextureType)
|
||||
{
|
||||
case GetTextureParam.TextureTypes.NormalMap:
|
||||
case TextureImportTypes.NormalMap:
|
||||
return x.GltfName;
|
||||
|
||||
default:
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace UniGLTF
|
||||
{
|
||||
switch (texParam.TextureType)
|
||||
{
|
||||
case GetTextureParam.TextureTypes.StandardMap:
|
||||
case TextureImportTypes.StandardMap:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace UniGLTF
|
||||
|
||||
switch (param.TextureType)
|
||||
{
|
||||
case GetTextureParam.TextureTypes.StandardMap:
|
||||
case TextureImportTypes.StandardMap:
|
||||
{
|
||||
// write converted texture
|
||||
var subAsset = m_subAssets.FirstOrDefault(x => x.name == param.ConvertedName);
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace UniGLTF
|
||||
{
|
||||
switch (textureInfo.TextureType)
|
||||
{
|
||||
case GetTextureParam.TextureTypes.NormalMap:
|
||||
case TextureImportTypes.NormalMap:
|
||||
{
|
||||
if (ExternalMap.TryGetValue(textureInfo.GltfName, out Texture2D external))
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace UniGLTF
|
||||
}
|
||||
break;
|
||||
|
||||
case GetTextureParam.TextureTypes.StandardMap:
|
||||
case TextureImportTypes.StandardMap:
|
||||
{
|
||||
if (ExternalMap.TryGetValue(textureInfo.ConvertedName, out Texture2D external))
|
||||
{
|
||||
@@ -86,7 +86,7 @@ namespace UniGLTF
|
||||
}
|
||||
break;
|
||||
|
||||
case GetTextureParam.TextureTypes.sRGB:
|
||||
case TextureImportTypes.sRGB:
|
||||
{
|
||||
if (ExternalMap.TryGetValue(textureInfo.GltfName, out Texture2D external))
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace UniGLTF
|
||||
if (param.Index0!=null && ExternalMap != null)
|
||||
{
|
||||
var cacheName = param.ConvertedName;
|
||||
if (param.TextureType == GetTextureParam.TextureTypes.NormalMap)
|
||||
if (param.TextureType == TextureImportTypes.NormalMap)
|
||||
{
|
||||
cacheName = param.GltfName;
|
||||
if (m_textureCache.TryGetValue(cacheName, out TextureLoadInfo normalInfo))
|
||||
@@ -236,7 +236,7 @@ namespace UniGLTF
|
||||
|
||||
switch (param.TextureType)
|
||||
{
|
||||
case GetTextureParam.TextureTypes.NormalMap:
|
||||
case TextureImportTypes.NormalMap:
|
||||
{
|
||||
var baseTexture = await GetOrCreateBaseTexture(awaitCaller, param, param.Index0, RenderTextureReadWrite.Linear, false);
|
||||
var converted = NormalConverter.Import(baseTexture.Texture);
|
||||
@@ -246,7 +246,7 @@ namespace UniGLTF
|
||||
return info.Texture;
|
||||
}
|
||||
|
||||
case GetTextureParam.TextureTypes.StandardMap:
|
||||
case TextureImportTypes.StandardMap:
|
||||
{
|
||||
TextureLoadInfo baseTexture = default;
|
||||
if (param.Index0!=null)
|
||||
@@ -277,18 +277,18 @@ namespace UniGLTF
|
||||
|
||||
public static GetTextureParam CreateSRGB(GltfParser parser, int textureIndex)
|
||||
{
|
||||
var name = CreateNameExt(parser.GLTF, textureIndex, GetTextureParam.TextureTypes.sRGB);
|
||||
var name = CreateNameExt(parser.GLTF, textureIndex, TextureImportTypes.sRGB);
|
||||
var sampler = CreateSampler(parser.GLTF, textureIndex);
|
||||
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
|
||||
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return new GetTextureParam(name, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
}
|
||||
|
||||
public static GetTextureParam CreateNormal(GltfParser parser, int textureIndex)
|
||||
{
|
||||
var name = CreateNameExt(parser.GLTF, textureIndex, GetTextureParam.TextureTypes.NormalMap);
|
||||
var name = CreateNameExt(parser.GLTF, textureIndex, TextureImportTypes.NormalMap);
|
||||
var sampler = CreateSampler(parser.GLTF, textureIndex);
|
||||
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
|
||||
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return new GetTextureParam(name, sampler, TextureImportTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
}
|
||||
|
||||
public static GetTextureParam CreateStandard(GltfParser parser, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, float metallicFactor, float roughnessFactor)
|
||||
@@ -299,7 +299,7 @@ namespace UniGLTF
|
||||
GetTextureParam.TextureSamplerParam sampler = default;
|
||||
if (metallicRoughnessTextureIndex.HasValue)
|
||||
{
|
||||
name = CreateNameExt(parser.GLTF, metallicRoughnessTextureIndex.Value, GetTextureParam.TextureTypes.StandardMap);
|
||||
name = CreateNameExt(parser.GLTF, metallicRoughnessTextureIndex.Value, TextureImportTypes.StandardMap);
|
||||
sampler = CreateSampler(parser.GLTF, metallicRoughnessTextureIndex.Value);
|
||||
getMetallicRoughnessAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, metallicRoughnessTextureIndex.Value);
|
||||
}
|
||||
@@ -308,13 +308,13 @@ namespace UniGLTF
|
||||
if (occlusionTextureIndex.HasValue)
|
||||
{
|
||||
if(string.IsNullOrEmpty(name.GltfName)){
|
||||
name = CreateNameExt(parser.GLTF, occlusionTextureIndex.Value, GetTextureParam.TextureTypes.StandardMap);
|
||||
name = CreateNameExt(parser.GLTF, occlusionTextureIndex.Value, TextureImportTypes.StandardMap);
|
||||
}
|
||||
sampler = CreateSampler(parser.GLTF, occlusionTextureIndex.Value);
|
||||
getOcclusionAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, occlusionTextureIndex.Value);
|
||||
}
|
||||
|
||||
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
|
||||
return new GetTextureParam(name, sampler, TextureImportTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
|
||||
}
|
||||
|
||||
public static GetTextureParam Create(GltfParser parser, int index, string prop, float metallicFactor, float roughnessFactor)
|
||||
@@ -333,7 +333,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public static GetTextureParam.NameExt CreateNameExt(glTF gltf, int textureIndex, GetTextureParam.TextureTypes textureType)
|
||||
public static GetTextureParam.NameExt CreateNameExt(glTF gltf, int textureIndex, TextureImportTypes textureType)
|
||||
{
|
||||
if (textureIndex < 0 || textureIndex >= gltf.textures.Count)
|
||||
{
|
||||
|
||||
@@ -19,15 +19,6 @@ namespace VRMShaders
|
||||
public const string OCCLUSION_PROP = "_OcclusionMap";
|
||||
public const string STANDARD_SUFFIX = ".standard";
|
||||
|
||||
public enum TextureTypes
|
||||
{
|
||||
sRGB,
|
||||
NormalMap,
|
||||
// Occlusion + Metallic + Smoothness
|
||||
StandardMap,
|
||||
Linear,
|
||||
}
|
||||
|
||||
public static string RemoveSuffix(string src)
|
||||
{
|
||||
if (src.EndsWith(NORMAL_SUFFIX))
|
||||
@@ -64,12 +55,12 @@ namespace VRMShaders
|
||||
|
||||
public string ConvertedFileName => $"{ConvertedName}.png";
|
||||
|
||||
public static string Convert(string name, TextureTypes textureType)
|
||||
public static string Convert(string name, TextureImportTypes textureType)
|
||||
{
|
||||
switch (textureType)
|
||||
{
|
||||
case TextureTypes.StandardMap: return $"{name}{STANDARD_SUFFIX}";
|
||||
case TextureTypes.NormalMap: return $"{name}{NORMAL_SUFFIX}";
|
||||
case TextureImportTypes.StandardMap: return $"{name}{STANDARD_SUFFIX}";
|
||||
case TextureImportTypes.NormalMap: return $"{name}{NORMAL_SUFFIX}";
|
||||
default: return name;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +89,7 @@ namespace VRMShaders
|
||||
|
||||
public TextureSamplerParam Sampler;
|
||||
|
||||
public readonly TextureTypes TextureType;
|
||||
public readonly TextureImportTypes TextureType;
|
||||
public readonly float MetallicFactor;
|
||||
public readonly float RoughnessFactor;
|
||||
|
||||
@@ -112,9 +103,9 @@ namespace VRMShaders
|
||||
/// <summary>
|
||||
/// この種類は RGB チャンネルの組み換えが必用
|
||||
/// </summary>
|
||||
public bool ExtractConverted => TextureType == TextureTypes.StandardMap;
|
||||
public bool ExtractConverted => TextureType == TextureImportTypes.StandardMap;
|
||||
|
||||
public GetTextureParam(NameExt name, TextureSamplerParam sampler, TextureTypes textureType, float metallicFactor, float roughnessFactor,
|
||||
public GetTextureParam(NameExt name, TextureSamplerParam sampler, TextureImportTypes textureType, float metallicFactor, float roughnessFactor,
|
||||
GetTextureBytesAsync i0,
|
||||
GetTextureBytesAsync i1,
|
||||
GetTextureBytesAsync i2,
|
||||
|
||||
28
Assets/VRMShaders/Runtime/TextureImportTypes.cs
Normal file
28
Assets/VRMShaders/Runtime/TextureImportTypes.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace VRMShaders
|
||||
{
|
||||
public enum TextureImportTypes
|
||||
{
|
||||
// runtime:
|
||||
// new Texture2D(linear = false)
|
||||
// extract:
|
||||
sRGB,
|
||||
// runtime:
|
||||
// new Texture2D(linear = true)
|
||||
// encode to DXT5nm
|
||||
// extract:
|
||||
// TextureImporter.textureType = TextureImporterType.NormalMap;
|
||||
NormalMap,
|
||||
// runtime:
|
||||
// new Texture2D(linear = true)
|
||||
// converted(Occlusion + Metallic + Smoothness)
|
||||
// extract:
|
||||
// converted(Occlusion + Metallic + Smoothness)
|
||||
// TextureImporter.sRGBTexture = false;
|
||||
StandardMap,
|
||||
// runtime:
|
||||
// new Texture2D(linear = true)
|
||||
// extract:
|
||||
// TextureImporter.sRGBTexture = false;
|
||||
Linear,
|
||||
}
|
||||
}
|
||||
11
Assets/VRMShaders/Runtime/TextureImportTypes.cs.meta
Normal file
11
Assets/VRMShaders/Runtime/TextureImportTypes.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b30953f01d374784e8e4de02d649cb06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user