add MaterialDescriptor constructor. add comment

This commit is contained in:
ousttrue 2025-03-05 01:31:53 +09:00
parent 4f45d51e8f
commit 20f31faf12
3 changed files with 54 additions and 12 deletions

View File

@ -25,13 +25,47 @@ namespace UniGLTF
/// <summary>
/// <code>
/// material = new Material(matDesc.Shader);
/// </code>
/// </summary>
public readonly Shader Shader;
/// <summary>
/// <code>
/// material.renderQueue = matDesc.RenderQueue.Value;
/// </code>
/// </summary>
public readonly int? RenderQueue;
public readonly IReadOnlyDictionary<string, TextureDescriptor> TextureSlots;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.FloatValues)
/// {
/// material.SetFloat(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, float> FloatValues;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.Colors)
/// {
/// material.SetColor(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, Color> Colors;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.Vectors)
/// {
/// material.SetVector(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, Vector4> Vectors;
/// <summary>
@ -43,6 +77,10 @@ namespace UniGLTF
/// </summary>
public readonly IReadOnlyList<Action<Material>> Actions;
/// <summary>
/// New api. for new code, this is a convenience.
/// MaterialGenerateAsyncFunc has full access to material and can get all textures.
/// </summary>
public readonly IReadOnlyList<MaterialGenerateAsyncFunc> AsyncActions;
public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.MaterialType, Name);
@ -68,5 +106,21 @@ namespace UniGLTF
Actions = actions;
AsyncActions = asyncActions ?? new List<MaterialGenerateAsyncFunc>();
}
public MaterialDescriptor(
string name,
Shader shader,
IReadOnlyList<MaterialGenerateAsyncFunc> asyncActions)
{
Name = name;
Shader = shader;
RenderQueue = default;
TextureSlots = new Dictionary<string, TextureDescriptor>();
FloatValues = new Dictionary<string, float>();
Colors = new Dictionary<string, Color>();
Vectors = new Dictionary<string, Vector4>();
Actions = new List<Action<Material>>();
AsyncActions = asyncActions;
}
}
}

View File

@ -36,12 +36,6 @@ namespace UniVRM10.VRM10Viewer
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader,
null,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>(),
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;

View File

@ -32,12 +32,6 @@ namespace UniVRM10.VRM10Viewer
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader,
null,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>(),
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;