Add Urp/UrpPipelineTypes.cs

This commit is contained in:
ousttrue
2021-08-31 21:12:10 +09:00
parent dc58edafdd
commit 32b728bd05
8 changed files with 58 additions and 29 deletions

View File

@@ -12,7 +12,7 @@ namespace UniGLTF
{
public override void OnImportAsset(AssetImportContext ctx)
{
Import(this, ctx, m_reverseAxis.ToAxes(), m_useUrpMaterial);
Import(this, ctx, m_reverseAxis.ToAxes(), m_renderPipeline);
}
}
}

View File

@@ -12,7 +12,7 @@ namespace UniGLTF
{
public override void OnImportAsset(AssetImportContext ctx)
{
Import(this, ctx, m_reverseAxis.ToAxes(), m_useUrpMaterial);
Import(this, ctx, m_reverseAxis.ToAxes(), m_renderPipeline);
}
}
}

View File

@@ -1,8 +1,6 @@
using UnityEngine;
using UnityEditor;
using System.Linq;
using VRMShaders;
using UnityEngine.Rendering;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
#else
@@ -21,17 +19,20 @@ namespace UniGLTF
public ScriptedImporterAxes m_reverseAxis = default;
[SerializeField]
public bool m_useUrpMaterial;
public RenderPipelineTypes m_renderPipeline;
static IMaterialDescriptorGenerator GetMaterialGenerator(bool useUrpMaterial)
static IMaterialDescriptorGenerator GetMaterialGenerator(RenderPipelineTypes renderPipeline)
{
if (useUrpMaterial)
switch (renderPipeline)
{
return new GltfUrpMaterialDescriptorGenerator();
}
else
{
return new GltfMaterialDescriptorGenerator();
case RenderPipelineTypes.Builtin:
return new GltfUrpMaterialDescriptorGenerator();
case RenderPipelineTypes.UniversalRenderPipeline:
return new GltfMaterialDescriptorGenerator();
default:
throw new System.NotImplementedException();
}
}
@@ -41,7 +42,7 @@ namespace UniGLTF
/// <param name="scriptedImporter"></param>
/// <param name="context"></param>
/// <param name="reverseAxis"></param>
protected static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis, bool useUrpMaterial)
protected static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axes reverseAxis, RenderPipelineTypes renderPipeline)
{
#if VRM_DEVELOP
Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
@@ -62,7 +63,7 @@ namespace UniGLTF
.Where(x => x.Value != null)
.ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);
IMaterialDescriptorGenerator materialGenerator = GetMaterialGenerator(useUrpMaterial);
IMaterialDescriptorGenerator materialGenerator = GetMaterialGenerator(renderPipeline);
using (var loader = new ImporterContext(data, extractedObjects, materialGenerator: materialGenerator))
{

View File

@@ -14,7 +14,7 @@ namespace UniGLTF
{
public override void OnImportAsset(AssetImportContext ctx)
{
Import(this, ctx, m_reverseAxis.ToAxes(), m_useUrpMaterial);
Import(this, ctx, m_reverseAxis.ToAxes(), m_renderPipeline);
}
}
}

View File

@@ -0,0 +1,12 @@
namespace UniGLTF
{
/// <summary>
/// TODO: HDRP ?
/// TODO: UserCustom ?
/// </summary>
public enum RenderPipelineTypes
{
Builtin,
UniversalRenderPipeline,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2ddf76db17176b4bb4480924f97c9d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -15,11 +15,11 @@ namespace UniVRM10
public bool MigrateToVrm1 = default;
[SerializeField]
public bool UseUrp = default;
public UniGLTF.RenderPipelineTypes RenderPipeline = default;
public override void OnImportAsset(AssetImportContext ctx)
{
VrmScriptedImporterImpl.Import(this, ctx, MigrateToVrm1, UseUrp);
VrmScriptedImporterImpl.Import(this, ctx, MigrateToVrm1, RenderPipeline);
}
}
}

View File

@@ -1,9 +1,7 @@
using System.Linq;
using UnityEngine;
using UniGLTF;
using System.IO;
using System;
using UniJSON;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
@@ -16,7 +14,22 @@ namespace UniVRM10
{
public static class VrmScriptedImporterImpl
{
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, bool useUrp)
static IMaterialDescriptorGenerator GetMaterialDescriptorGenerator(RenderPipelineTypes renderPipeline)
{
switch (renderPipeline)
{
case RenderPipelineTypes.Builtin:
return new Vrm10MaterialDescriptorGenerator();
case RenderPipelineTypes.UniversalRenderPipeline:
return new Vrm10UrpMaterialDescriptorGenerator();
default:
throw new NotImplementedException();
}
}
public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, RenderPipelineTypes renderPipeline)
{
#if VRM_DEVELOP
Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
@@ -35,15 +48,7 @@ namespace UniVRM10
.Where(kv => kv.Value != null)
.ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);
IMaterialDescriptorGenerator materialGenerator;
if (useUrp)
{
materialGenerator = new Vrm10UrpMaterialDescriptorGenerator();
}
else
{
materialGenerator = new Vrm10MaterialDescriptorGenerator();
}
var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);
using (var loader = new Vrm10Importer(result.Data, result.Vrm, extractedObjects, materialGenerator: materialGenerator))
{