mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
add Vrm10UrpMaterialDescriptorGenerator and VRMURPMaterialDescriptorGenerator
This commit is contained in:
@@ -23,7 +23,8 @@ namespace VRM
|
||||
public VRMImporterContext(
|
||||
GltfData data,
|
||||
IReadOnlyDictionary<SubAssetKey, Object> externalObjectMap = null,
|
||||
ITextureDeserializer textureDeserializer = null)
|
||||
ITextureDeserializer textureDeserializer = null,
|
||||
IMaterialDescriptorGenerator materialGenerator = null)
|
||||
: base(data, externalObjectMap, textureDeserializer)
|
||||
{
|
||||
// parse VRM part
|
||||
@@ -31,7 +32,7 @@ namespace VRM
|
||||
{
|
||||
VRM = vrm;
|
||||
TextureDescriptorGenerator = new VrmTextureDescriptorGenerator(Data, VRM);
|
||||
MaterialDescriptorGenerator = new VRMMaterialDescriptorGenerator(VRM);
|
||||
MaterialDescriptorGenerator = materialGenerator ?? new VRMMaterialDescriptorGenerator(VRM);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
34
Assets/VRM/Runtime/IO/VRMURPMaterialDescriptorGenerator.cs
Normal file
34
Assets/VRM/Runtime/IO/VRMURPMaterialDescriptorGenerator.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public sealed class VRMURPMaterialDescriptorGenerator : IMaterialDescriptorGenerator
|
||||
{
|
||||
readonly glTF_VRM_extensions m_vrm;
|
||||
public VRMURPMaterialDescriptorGenerator(glTF_VRM_extensions vrm)
|
||||
{
|
||||
m_vrm = vrm;
|
||||
}
|
||||
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
// mtoon URP "MToon" shader is not ready. import fallback to unlit
|
||||
// unlit "UniUnlit" work in URP
|
||||
if (!GltfUnlitMaterialImporter.TryCreateParam(data, i, out MaterialDescriptor matDesc))
|
||||
{
|
||||
// pbr "Standard" to "Universal Render Pipeline/Lit"
|
||||
if (!GltfPbrURPMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
{
|
||||
// fallback
|
||||
#if VRM_DEVELOP
|
||||
Debug.LogWarning($"material: {i} out of range. fallback");
|
||||
#endif
|
||||
return new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
|
||||
}
|
||||
}
|
||||
return matDesc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5aeab73a304ef644b0d20fac93bcfb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,9 +14,12 @@ namespace UniVRM10
|
||||
[SerializeField]
|
||||
public bool MigrateToVrm1 = default;
|
||||
|
||||
[SerializeField]
|
||||
public bool UseUrp = default;
|
||||
|
||||
public override void OnImportAsset(AssetImportContext ctx)
|
||||
{
|
||||
VrmScriptedImporterImpl.Import(this, ctx, MigrateToVrm1);
|
||||
VrmScriptedImporterImpl.Import(this, ctx, MigrateToVrm1, UseUrp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,11 @@ namespace UniVRM10
|
||||
{
|
||||
case Vrm10FileType.Vrm1:
|
||||
EditorGUILayout.HelpBox(m_result.Message, MessageType.Info);
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("UseUrp"));
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
ApplyRevertGUI();
|
||||
break;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace UniVRM10
|
||||
{
|
||||
public static class VrmScriptedImporterImpl
|
||||
{
|
||||
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1)
|
||||
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, bool useUrp)
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
|
||||
@@ -35,7 +35,17 @@ namespace UniVRM10
|
||||
.Where(kv => kv.Value != null)
|
||||
.ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);
|
||||
|
||||
using (var loader = new Vrm10Importer(result.Data, result.Vrm, extractedObjects))
|
||||
IMaterialDescriptorGenerator materialGenerator;
|
||||
if (useUrp)
|
||||
{
|
||||
materialGenerator = new Vrm10UrpMaterialDescriptorGenerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
materialGenerator = new Vrm10MaterialDescriptorGenerator();
|
||||
}
|
||||
|
||||
using (var loader = new Vrm10Importer(result.Data, result.Vrm, extractedObjects, materialGenerator: materialGenerator))
|
||||
{
|
||||
// settings TextureImporters
|
||||
foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public sealed class Vrm10UrpMaterialDescriptorGenerator : IMaterialDescriptorGenerator
|
||||
{
|
||||
public MaterialDescriptor Get(GltfData data, int i)
|
||||
{
|
||||
// unlit
|
||||
if (!GltfUnlitMaterialImporter.TryCreateParam(data, i, out MaterialDescriptor matDesc))
|
||||
{
|
||||
// pbr
|
||||
if (!GltfPbrURPMaterialImporter.TryCreateParam(data, i, out matDesc))
|
||||
{
|
||||
// fallback
|
||||
#if VRM_DEVELOP
|
||||
Debug.LogWarning($"material: {i} out of range. fallback");
|
||||
#endif
|
||||
return new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName);
|
||||
}
|
||||
}
|
||||
return matDesc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 377d1bd166d5452408fc7772554715ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,7 +23,8 @@ namespace UniVRM10
|
||||
public Vrm10Importer(
|
||||
UniGLTF.GltfData data, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm,
|
||||
IReadOnlyDictionary<SubAssetKey, UnityEngine.Object> externalObjectMap = null,
|
||||
ITextureDeserializer textureDeserializer = null)
|
||||
ITextureDeserializer textureDeserializer = null,
|
||||
IMaterialDescriptorGenerator materialGenerator = null)
|
||||
: base(data, externalObjectMap, textureDeserializer)
|
||||
{
|
||||
if (data == null)
|
||||
@@ -38,7 +39,7 @@ namespace UniVRM10
|
||||
m_vrm = vrm;
|
||||
|
||||
TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(data);
|
||||
MaterialDescriptorGenerator = new Vrm10MaterialDescriptorGenerator();
|
||||
MaterialDescriptorGenerator = materialGenerator ?? new Vrm10MaterialDescriptorGenerator();
|
||||
|
||||
m_externalMap = externalObjectMap;
|
||||
if (m_externalMap == null)
|
||||
|
||||
Reference in New Issue
Block a user