mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
SamplerParam.WrapModes を WrapModesU と WrapModesV に展開
This commit is contained in:
@@ -42,7 +42,7 @@ namespace UniGLTF
|
||||
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
|
||||
return (key, param);
|
||||
}
|
||||
|
||||
|
||||
public static (SubAssetKey, TextureImportParam Param) CreateLinear(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
var gltfTexture = parser.GLTF.textures[textureIndex];
|
||||
@@ -102,91 +102,36 @@ namespace UniGLTF
|
||||
if (gltfTexture.sampler < 0 || gltfTexture.sampler >= gltf.samplers.Count)
|
||||
{
|
||||
// default
|
||||
return new SamplerParam
|
||||
{
|
||||
FilterMode = FilterMode.Bilinear,
|
||||
WrapModes = new (SamplerWrapType, TextureWrapMode)[] { },
|
||||
};
|
||||
return SamplerParam.Default;
|
||||
}
|
||||
|
||||
var gltfSampler = gltf.samplers[gltfTexture.sampler];
|
||||
return new SamplerParam
|
||||
{
|
||||
WrapModes = GetUnityWrapMode(gltfSampler).ToArray(),
|
||||
WrapModesU = GetUnityWrapMode(gltfSampler.wrapS),
|
||||
WrapModesV = GetUnityWrapMode(gltfSampler.wrapT),
|
||||
FilterMode = ImportFilterMode(gltfSampler.minFilter),
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<(SamplerWrapType, TextureWrapMode)> GetUnityWrapMode(glTFTextureSampler sampler)
|
||||
public static TextureWrapMode GetUnityWrapMode(glWrap wrap)
|
||||
{
|
||||
if (sampler.wrapS == sampler.wrapT)
|
||||
switch (wrap)
|
||||
{
|
||||
switch (sampler.wrapS)
|
||||
{
|
||||
case glWrap.NONE: // default
|
||||
yield return (SamplerWrapType.All, TextureWrapMode.Repeat);
|
||||
break;
|
||||
case glWrap.NONE: // default
|
||||
return TextureWrapMode.Repeat;
|
||||
|
||||
case glWrap.CLAMP_TO_EDGE:
|
||||
yield return (SamplerWrapType.All, TextureWrapMode.Clamp);
|
||||
break;
|
||||
case glWrap.CLAMP_TO_EDGE:
|
||||
return TextureWrapMode.Clamp;
|
||||
|
||||
case glWrap.REPEAT:
|
||||
yield return (SamplerWrapType.All, TextureWrapMode.Repeat);
|
||||
break;
|
||||
case glWrap.REPEAT:
|
||||
return TextureWrapMode.Repeat;
|
||||
|
||||
case glWrap.MIRRORED_REPEAT:
|
||||
yield return (SamplerWrapType.All, TextureWrapMode.Mirror);
|
||||
break;
|
||||
case glWrap.MIRRORED_REPEAT:
|
||||
return TextureWrapMode.Mirror;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sampler.wrapS)
|
||||
{
|
||||
case glWrap.NONE: // default
|
||||
yield return (SamplerWrapType.U, TextureWrapMode.Repeat);
|
||||
break;
|
||||
|
||||
case glWrap.CLAMP_TO_EDGE:
|
||||
yield return (SamplerWrapType.U, TextureWrapMode.Clamp);
|
||||
break;
|
||||
|
||||
case glWrap.REPEAT:
|
||||
yield return (SamplerWrapType.U, TextureWrapMode.Repeat);
|
||||
break;
|
||||
|
||||
case glWrap.MIRRORED_REPEAT:
|
||||
yield return (SamplerWrapType.U, TextureWrapMode.Mirror);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
switch (sampler.wrapT)
|
||||
{
|
||||
case glWrap.NONE: // default
|
||||
yield return (SamplerWrapType.V, TextureWrapMode.Repeat);
|
||||
break;
|
||||
|
||||
case glWrap.CLAMP_TO_EDGE:
|
||||
yield return (SamplerWrapType.V, TextureWrapMode.Clamp);
|
||||
break;
|
||||
|
||||
case glWrap.REPEAT:
|
||||
yield return (SamplerWrapType.V, TextureWrapMode.Repeat);
|
||||
break;
|
||||
|
||||
case glWrap.MIRRORED_REPEAT:
|
||||
yield return (SamplerWrapType.V, TextureWrapMode.Mirror);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,31 @@ namespace VRMShaders
|
||||
{
|
||||
public struct SamplerParam
|
||||
{
|
||||
public (SamplerWrapType, TextureWrapMode)[] WrapModes;
|
||||
public FilterMode FilterMode;
|
||||
public TextureWrapMode WrapModesU;
|
||||
|
||||
public TextureWrapMode WrapModesV;
|
||||
|
||||
public FilterMode FilterMode;
|
||||
|
||||
public static SamplerParam Default => new SamplerParam
|
||||
{
|
||||
FilterMode = FilterMode.Bilinear,
|
||||
WrapModesU = TextureWrapMode.Repeat,
|
||||
WrapModesV = TextureWrapMode.Repeat,
|
||||
};
|
||||
}
|
||||
|
||||
public static class SamplerParamExtensions
|
||||
{
|
||||
public static void SetSampler(this Texture2D texture, in SamplerParam param)
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
texture.wrapModeU = param.WrapModesU;
|
||||
texture.wrapModeV = param.WrapModesV;
|
||||
texture.filterMode = param.FilterMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace VRMShaders
|
||||
{
|
||||
public enum SamplerWrapType
|
||||
{
|
||||
All,
|
||||
U,
|
||||
V,
|
||||
W,
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e15e75e4b0c0c24999dcdee7dc17002
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -138,51 +138,13 @@ namespace VRMShaders
|
||||
texture.LoadImage(imageBytes);
|
||||
}
|
||||
|
||||
SetSampler(texture, param);
|
||||
texture.SetSampler(param.Sampler);
|
||||
|
||||
cacheInfo = new TextureLoadInfo(texture, used, false);
|
||||
m_textureCache.Add(name, cacheInfo);
|
||||
return cacheInfo;
|
||||
}
|
||||
|
||||
public static void SetSampler(Texture2D texture, TextureImportParam param)
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (param.Sampler.WrapModes != null)
|
||||
{
|
||||
foreach (var (key, value) in param.Sampler.WrapModes)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case SamplerWrapType.All:
|
||||
texture.wrapMode = value;
|
||||
break;
|
||||
|
||||
case SamplerWrapType.U:
|
||||
texture.wrapModeU = value;
|
||||
break;
|
||||
|
||||
case SamplerWrapType.V:
|
||||
texture.wrapModeV = value;
|
||||
break;
|
||||
|
||||
case SamplerWrapType.W:
|
||||
texture.wrapModeW = value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
texture.filterMode = param.Sampler.FilterMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// テクスチャーをロード、必要であれば変換して返す。
|
||||
/// 同じものはキャッシュを返す
|
||||
|
||||
Reference in New Issue
Block a user