MToon URPの読み込み処理を追加

This commit is contained in:
notargs
2023-04-26 16:24:23 +09:00
parent 963775dfc1
commit d756e3487d
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1987bdfe8c2df174abb9cf04caaaba15
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System;
using System.Linq;
using UniGLTF;
using UnityEngine;
using VRMShaders;
using VRMShaders.VRM10.MToon10.Runtime;
namespace UniVRM10
{
/// <summary>
/// Convert MToon parameters from glTF specification to Unity implementation.
/// </summary>
public static class UrpVrm10MToonMaterialImporter
{
/// <summary>
/// VMRC_materials_mtoon の場合にマテリアル生成情報を作成する
/// </summary>
public static bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
var m = data.GLTF.materials[i];
if (!UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out var mtoon))
{
// Fallback to glTF, when MToon extension does not exist.
matDesc = default;
return false;
}
// use material.name, because material name may renamed in GltfParser.
matDesc = new MaterialDescriptor(
m.name,
Shader.Find(MToon10Meta.URPUnityShaderName),
null,
Vrm10MToonTextureImporter.EnumerateAllTextures(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.Item2.Item2),
BuiltInVrm10MToonMaterialImporter.TryGetAllFloats(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
BuiltInVrm10MToonMaterialImporter.TryGetAllColors(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
BuiltInVrm10MToonMaterialImporter.TryGetAllFloatArrays(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
new Action<Material>[]
{
material =>
{
// Set hidden properties, keywords from float properties.
new MToonValidator(material).Validate();
}
});
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57d820ccc1ff7e2469f7fb5cc435bd5b
timeCreated: 1620630516