chore: update for NDMF API changes (#883)

This commit is contained in:
bd_ 2024-06-17 11:47:54 +09:00 committed by GitHub
parent 628c07a505
commit 4c20d1e052
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 60 deletions

View File

@ -19,7 +19,7 @@
"dependencies": {}
},
"nadena.dev.ndmf": {
"version": "1.5.0-alpha.1"
"version": "1.5.0-alpha.2"
}
}
}

View File

@ -37,14 +37,14 @@ namespace nadena.dev.modular_avatar.core.editor
return null;
}
public ReactiveValue<IImmutableList<IImmutableList<Renderer>>> TargetGroups { get; } =
ReactiveValue<IImmutableList<IImmutableList<Renderer>>>.Create(
public ReactiveValue<ImmutableList<RenderGroup>> TargetGroups { get; } =
ReactiveValue<ImmutableList<RenderGroup>>.Create(
"Scale Adjuster: Find targets",
async ctx =>
{
var scaleAdjusters = await ctx.Observe(CommonQueries.GetComponentsByType<ModularAvatarScaleAdjuster>());
HashSet<Renderer> targets = new HashSet<Renderer>();
ImmutableList<RenderGroup>.Builder result = ImmutableList.CreateBuilder<RenderGroup>();
foreach (var adjuster in scaleAdjusters)
{
@ -57,14 +57,18 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (var renderer in renderers)
{
targets.Add(renderer);
if (renderer is SkinnedMeshRenderer smr)
{
result.Add(RenderGroup.For(renderer));
}
}
}
return targets.Select(r => (IImmutableList<Renderer>)ImmutableList.Create(r)).ToImmutableList();
return result.ToImmutable();
});
public Task<IRenderFilterNode> Instantiate(IEnumerable<(Renderer, Renderer)> proxyPairs, ComputeContext context)
public Task<IRenderFilterNode> Instantiate(RenderGroup group, IEnumerable<(Renderer, Renderer)> proxyPairs,
ComputeContext context)
{
return Task.FromResult((IRenderFilterNode)new ScaleAdjusterPreviewNode());
}
@ -78,8 +82,8 @@ namespace nadena.dev.modular_avatar.core.editor
{
}
public ulong Reads => IRenderFilterNode.Shapes;
public ulong WhatChanged => IRenderFilterNode.Shapes;
public RenderAspects Reads => RenderAspects.Shapes;
public RenderAspects WhatChanged => RenderAspects.Shapes;
public void OnFrame(Renderer original, Renderer proxy)
{

View File

@ -17,61 +17,51 @@ namespace nadena.dev.modular_avatar.core.editor
{
public class ShapeChangerPreview : IRenderFilter
{
private static ReactiveValue<ImmutableDictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>>>
InternalTargetGroups
= ReactiveValue<ImmutableDictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>>>.Create(
"ShapeChangerPreview.TargetGroups", async ctx =>
{
var allChangers =
await ctx.Observe(CommonQueries.GetComponentsByType<ModularAvatarShapeChanger>());
Dictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>.Builder> groups =
new Dictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>.Builder>(
new ObjectIdentityComparer<Renderer>());
foreach (var changer in allChangers)
{
// TODO: observe avatar root
ctx.Observe(changer);
if (!ctx.ActiveAndEnabled(changer)) continue;
var target = ctx.Observe(changer.targetRenderer.Get(changer));
var renderer = ctx.GetComponent<SkinnedMeshRenderer>(target);
if (renderer == null) continue;
if (!groups.TryGetValue(renderer, out var group))
{
group = ImmutableList.CreateBuilder<ModularAvatarShapeChanger>();
groups[renderer] = group;
}
group.Add(changer);
}
return groups.ToImmutableDictionary(p => p.Key, p => p.Value.ToImmutable());
});
public ReactiveValue<IImmutableList<IImmutableList<Renderer>>> TargetGroups { get; } =
ReactiveValue<IImmutableList<IImmutableList<Renderer>>>.Create(
public ReactiveValue<ImmutableList<RenderGroup>> TargetGroups { get; }
= ReactiveValue<ImmutableList<RenderGroup>>.Create(
"ShapeChangerPreview.TargetGroups", async ctx =>
{
var targetGroups = await ctx.Observe(InternalTargetGroups);
var allChangers =
await ctx.Observe(CommonQueries.GetComponentsByType<ModularAvatarShapeChanger>());
return targetGroups.Keys
.Select(v => (IImmutableList<Renderer>)ImmutableList.Create(v))
Dictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>.Builder> groups =
new Dictionary<Renderer, ImmutableList<ModularAvatarShapeChanger>.Builder>(
new ObjectIdentityComparer<Renderer>());
foreach (var changer in allChangers)
{
// TODO: observe avatar root
ctx.Observe(changer);
if (!ctx.ActiveAndEnabled(changer)) continue;
var target = ctx.Observe(changer.targetRenderer.Get(changer));
var renderer = ctx.GetComponent<SkinnedMeshRenderer>(target);
if (renderer == null) continue;
if (!groups.TryGetValue(renderer, out var group))
{
group = ImmutableList.CreateBuilder<ModularAvatarShapeChanger>();
groups[renderer] = group;
}
group.Add(changer);
}
return groups.Select(g => RenderGroup.For(g.Key).WithData(g.Value.ToImmutable()))
.ToImmutableList();
});
public async Task<IRenderFilterNode> Instantiate(IEnumerable<(Renderer, Renderer)> proxyPairs,
public async Task<IRenderFilterNode> Instantiate(
RenderGroup group,
IEnumerable<(Renderer, Renderer)> proxyPairs,
ComputeContext context)
{
var node = new Node();
try
{
await node.Init(proxyPairs, context);
await node.Init(group, proxyPairs, context);
}
catch (Exception e)
{
@ -101,16 +91,16 @@ namespace nadena.dev.modular_avatar.core.editor
}
}
public async Task Init(IEnumerable<(Renderer, Renderer)> renderers, ComputeContext context)
public async Task Init(RenderGroup group, IEnumerable<(Renderer, Renderer)> renderers,
ComputeContext context)
{
var targetGroups = await context.Observe(InternalTargetGroups);
var (original, proxy) = renderers.First();
if (original == null || proxy == null) return;
if (!targetGroups.TryGetValue(original, out _changers)) return;
if (!(proxy is SkinnedMeshRenderer smr)) return;
_changers = group.GetData<ImmutableList<ModularAvatarShapeChanger>>();
HashSet<int> toDelete = new HashSet<int>();
var mesh = smr.sharedMesh;
@ -179,8 +169,8 @@ namespace nadena.dev.modular_avatar.core.editor
}
public ulong Reads => IRenderFilterNode.Shapes | IRenderFilterNode.Mesh;
public ulong WhatChanged => IRenderFilterNode.Shapes | IRenderFilterNode.Mesh;
public RenderAspects Reads => RenderAspects.Shapes | RenderAspects.Mesh;
public RenderAspects WhatChanged => RenderAspects.Shapes | RenderAspects.Mesh;
public void Dispose()
{

View File

@ -16,6 +16,6 @@
},
"vpmDependencies": {
"com.vrchat.avatars": ">=3.4.0",
"nadena.dev.ndmf": ">=1.5.0-alpha.1 <2.0.0-a"
"nadena.dev.ndmf": ">=1.5.0-alpha.2 <2.0.0-a"
}
}