mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-30 14:53:09 -05:00
Import MToon textures.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Extensions.VRMC_materials_mtoon;
|
||||
using UnityEngine;
|
||||
@@ -8,7 +9,56 @@ namespace UniVRM10
|
||||
{
|
||||
public static class Vrm10MToonMaterialTextureImporter
|
||||
{
|
||||
public static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
public static IEnumerable<(string key, (SubAssetKey, TextureImportParam))> TryGetAllTextures(GltfParser parser, glTFMaterial material, VRMC_materials_mtoon mToon)
|
||||
{
|
||||
if (TryGetBaseColorTexture(parser, material, out var litTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropMainTex, litTex);
|
||||
}
|
||||
|
||||
if (TryGetEmissiveTexture(parser, material, out var emissiveTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropEmissionMap, emissiveTex);
|
||||
}
|
||||
|
||||
if (TryGetNormalTexture(parser, material, out var normalTex))
|
||||
{
|
||||
yield return ("_BumpMap", normalTex);
|
||||
}
|
||||
|
||||
if (TryGetShadeMultiplyTexture(parser, mToon, out var shadeTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropShadeTexture, shadeTex);
|
||||
}
|
||||
|
||||
if (TryGetShadingShiftTexture(parser, mToon, out var shadeShiftTex))
|
||||
{
|
||||
Debug.LogWarning("Need VRM 1.0 MToon implementation.");
|
||||
yield return ("_NEED_IMPLEMENTATION_MTOON_1_0", shadeShiftTex);
|
||||
}
|
||||
|
||||
if (TryGetMatcapTexture(parser, mToon, out var matcapTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropSphereAdd, matcapTex);
|
||||
}
|
||||
|
||||
if (TryGetRimMultiplyTexture(parser, mToon, out var rimTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropRimTexture, rimTex);
|
||||
}
|
||||
|
||||
if (TryGetOutlineWidthMultiplyTexture(parser, mToon, out var outlineTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropOutlineWidthTexture, outlineTex);
|
||||
}
|
||||
|
||||
if (TryGetUvAnimationMaskTexture(parser, mToon, out var uvAnimMaskTex))
|
||||
{
|
||||
yield return (MToon.Utils.PropUvAnimMaskTexture, uvAnimMaskTex);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -26,8 +76,28 @@ namespace UniVRM10
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
|
||||
private static bool TryGetEmissiveTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
pair = GltfPBRMaterial.EmissiveTexture(parser, src);
|
||||
return true;
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
pair = default;
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
pair = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -46,32 +116,32 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair);
|
||||
}
|
||||
|
||||
public 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, TextureImportParam) pair)
|
||||
{
|
||||
return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair);
|
||||
}
|
||||
|
||||
@@ -80,23 +80,10 @@ namespace UniVRM10
|
||||
var m = parser.GLTF.materials[i];
|
||||
if (UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out var mToon))
|
||||
{
|
||||
// Enumerate VRM MToon Textures
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetBaseColorTexture(parser, m, out var litTex))
|
||||
yield return litTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetNormalTexture(parser, m, out var normalTex))
|
||||
yield return normalTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetShadeMultiplyTexture(parser, mToon, out var shadeTex))
|
||||
yield return shadeTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetShadingShiftTexture(parser, mToon, out var shadeShiftTex))
|
||||
yield return shadeShiftTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetMatcapTexture(parser, mToon, out var matcapTex))
|
||||
yield return matcapTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetRimMultiplyTexture(parser, mToon, out var rimTex))
|
||||
yield return rimTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetOutlineWidthMultiplyTexture(parser, mToon, out var outlineTex))
|
||||
yield return outlineTex;
|
||||
if (Vrm10MToonMaterialTextureImporter.TryGetUvAnimationMaskTexture(parser, mToon, out var uvAnimMaskTex))
|
||||
yield return uvAnimMaskTex;
|
||||
foreach (var (key, tex) in Vrm10MToonMaterialTextureImporter.TryGetAllTextures(parser, m, mToon))
|
||||
{
|
||||
yield return tex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace UniVRM10
|
||||
// use material.name, because material name may renamed in GltfParser.
|
||||
param = new MaterialImportParam(m.name, MToon.Utils.ShaderName);
|
||||
|
||||
foreach (var (key, (subAssetKey, value)) in Vrm10MToonMaterialTextureImporter.TryGetAllTextures(parser, m, mtoon))
|
||||
{
|
||||
param.TextureSlots.Add(key, value);
|
||||
}
|
||||
|
||||
foreach (var (key, value) in Vrm10MToonMaterialParameterImporter.TryGetAllColors(m, mtoon))
|
||||
{
|
||||
param.Colors.Add(key, value);
|
||||
|
||||
@@ -240,11 +240,18 @@ namespace VRMShaders
|
||||
return info.Texture;
|
||||
}
|
||||
|
||||
default:
|
||||
case TextureImportTypes.sRGB:
|
||||
{
|
||||
var baseTexture = await GetOrCreateBaseTexture(param.UnityObjectName, param, param.Index0, RenderTextureReadWrite.sRGB, true);
|
||||
return baseTexture.Texture;
|
||||
}
|
||||
case TextureImportTypes.Linear:
|
||||
{
|
||||
var baseTexture = await GetOrCreateBaseTexture(param.UnityObjectName, param, param.Index0, RenderTextureReadWrite.Linear, true);
|
||||
return baseTexture.Texture;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
Reference in New Issue
Block a user