Take off responsibility of determining shaders from ImporterContext.

This commit is contained in:
Masataka SUMI
2022-12-05 16:30:43 +09:00
parent aed1d170d4
commit 2f915b4777
13 changed files with 101 additions and 10 deletions

View File

@@ -289,8 +289,8 @@ namespace UniGLTF
{
// no material. work around.
// TODO: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#default-material
var param = MaterialDescriptor.Default;
var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller);
var param = MaterialDescriptorGenerator.GetGltfDefault();
await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller);
}
else
{
@@ -298,7 +298,7 @@ namespace UniGLTF
{
await awaitCaller.NextFrameIfTimedOut();
var param = MaterialDescriptorGenerator.Get(Data, i);
var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller);
await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller);
}
}
}

View File

@@ -31,5 +31,10 @@ namespace UniGLTF
new Dictionary<string, Vector4>(),
new Action<Material>[]{});
}
public MaterialDescriptor GetGltfDefault()
{
return BuiltInGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using VRMShaders;
namespace UniGLTF
{
/// <summary>
/// Generate the descriptor of the glTF default material.
/// </summary>
public static class BuiltInGltfDefaultMaterialImporter
{
public static MaterialDescriptor CreateParam()
{
// FIXME
return new MaterialDescriptor(
"__default__",
"Standard",
default,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>()
);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aa5431a3a9ee4f9caac398688c3a8973
timeCreated: 1670224943

View File

@@ -8,6 +8,14 @@ namespace UniGLTF
/// </summary>
public interface IMaterialDescriptorGenerator
{
/// <summary>
/// Generate the MaterialDescriptor generated from the index i.
/// </summary>
MaterialDescriptor Get(GltfData data, int i);
/// <summary>
/// Generate the MaterialDescriptor for the non-specified glTF material.
/// </summary>
MaterialDescriptor GetGltfDefault();
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using VRMShaders;
namespace UniGLTF
{
/// <summary>
/// Generate the descriptor of the glTF default material.
/// </summary>
public static class UrpGltfDefaultMaterialImporter
{
public static MaterialDescriptor CreateParam()
{
// FIXME
return new MaterialDescriptor(
"__default__",
UrpGltfPbrMaterialImporter.ShaderName,
default,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>()
);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 320b6d26ea014356b1c37e38425bf152
timeCreated: 1670225169

View File

@@ -32,5 +32,10 @@ namespace UniGLTF
new Dictionary<string, Vector4>(),
new Collection<Action<Material>>());
}
public MaterialDescriptor GetGltfDefault()
{
return UrpGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -53,5 +53,10 @@ namespace VRM
new Dictionary<string, Vector4>(),
new Action<Material>[]{});
}
public MaterialDescriptor GetGltfDefault()
{
return BuiltInGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -37,5 +37,10 @@ namespace VRM
new Dictionary<string, Vector4>(),
new Action<Material>[]{});
}
public MaterialDescriptor GetGltfDefault()
{
return UrpGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -31,5 +31,9 @@ namespace UniVRM10
new Action<Material>[]{});
}
public MaterialDescriptor GetGltfDefault()
{
return BuiltInGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -27,5 +27,9 @@ namespace UniVRM10
new Action<Material>[]{});
}
public MaterialDescriptor GetGltfDefault()
{
return UrpGltfDefaultMaterialImporter.CreateParam();
}
}
}

View File

@@ -17,13 +17,6 @@ namespace VRMShaders
public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.MaterialType, Name);
public static readonly MaterialDescriptor Default = new MaterialDescriptor("__default__", "Standard", default,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>());
public MaterialDescriptor(
string name,
string shaderName,