From 4c20d1e052c62fdaae930f950f4d80331a2c116a Mon Sep 17 00:00:00 2001 From: bd_ Date: Mon, 17 Jun 2024 11:47:54 +0900 Subject: [PATCH] chore: update for NDMF API changes (#883) --- .github/ProjectRoot/vpm-manifest-2022.json | 2 +- Editor/ScaleAdjuster/ScaleAdjusterPreview.cs | 22 +++-- Editor/ShapeChanger/ShapeChangerPreview.cs | 88 +++++++++----------- package.json | 2 +- 4 files changed, 54 insertions(+), 60 deletions(-) diff --git a/.github/ProjectRoot/vpm-manifest-2022.json b/.github/ProjectRoot/vpm-manifest-2022.json index dba599c3..9e7156ec 100644 --- a/.github/ProjectRoot/vpm-manifest-2022.json +++ b/.github/ProjectRoot/vpm-manifest-2022.json @@ -19,7 +19,7 @@ "dependencies": {} }, "nadena.dev.ndmf": { - "version": "1.5.0-alpha.1" + "version": "1.5.0-alpha.2" } } } \ No newline at end of file diff --git a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs index 5346ed34..d2625888 100644 --- a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs +++ b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs @@ -37,15 +37,15 @@ namespace nadena.dev.modular_avatar.core.editor return null; } - public ReactiveValue>> TargetGroups { get; } = - ReactiveValue>>.Create( + public ReactiveValue> TargetGroups { get; } = + ReactiveValue>.Create( "Scale Adjuster: Find targets", async ctx => { var scaleAdjusters = await ctx.Observe(CommonQueries.GetComponentsByType()); - HashSet targets = new HashSet(); - + ImmutableList.Builder result = ImmutableList.CreateBuilder(); + foreach (var adjuster in scaleAdjusters) { // Find parent object @@ -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)ImmutableList.Create(r)).ToImmutableList(); + return result.ToImmutable(); }); - public Task Instantiate(IEnumerable<(Renderer, Renderer)> proxyPairs, ComputeContext context) + public Task 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) { diff --git a/Editor/ShapeChanger/ShapeChangerPreview.cs b/Editor/ShapeChanger/ShapeChangerPreview.cs index ea600c4f..96940d65 100644 --- a/Editor/ShapeChanger/ShapeChangerPreview.cs +++ b/Editor/ShapeChanger/ShapeChangerPreview.cs @@ -17,61 +17,51 @@ namespace nadena.dev.modular_avatar.core.editor { public class ShapeChangerPreview : IRenderFilter { - private static ReactiveValue>> - InternalTargetGroups - = ReactiveValue>>.Create( - "ShapeChangerPreview.TargetGroups", async ctx => - { - var allChangers = - await ctx.Observe(CommonQueries.GetComponentsByType()); - - Dictionary.Builder> groups = - new Dictionary.Builder>( - new ObjectIdentityComparer()); - - 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(target); - - if (renderer == null) continue; - - if (!groups.TryGetValue(renderer, out var group)) - { - group = ImmutableList.CreateBuilder(); - groups[renderer] = group; - } - - group.Add(changer); - } - - return groups.ToImmutableDictionary(p => p.Key, p => p.Value.ToImmutable()); - }); - - public ReactiveValue>> TargetGroups { get; } = - ReactiveValue>>.Create( + public ReactiveValue> TargetGroups { get; } + = ReactiveValue>.Create( "ShapeChangerPreview.TargetGroups", async ctx => { - var targetGroups = await ctx.Observe(InternalTargetGroups); + var allChangers = + await ctx.Observe(CommonQueries.GetComponentsByType()); - return targetGroups.Keys - .Select(v => (IImmutableList)ImmutableList.Create(v)) + Dictionary.Builder> groups = + new Dictionary.Builder>( + new ObjectIdentityComparer()); + + 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(target); + + if (renderer == null) continue; + + if (!groups.TryGetValue(renderer, out var group)) + { + group = ImmutableList.CreateBuilder(); + groups[renderer] = group; + } + + group.Add(changer); + } + + return groups.Select(g => RenderGroup.For(g.Key).WithData(g.Value.ToImmutable())) .ToImmutableList(); }); - - public async Task Instantiate(IEnumerable<(Renderer, Renderer)> proxyPairs, + public async Task 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>(); + HashSet toDelete = new HashSet(); 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() { diff --git a/package.json b/package.json index 60f5b6f0..63778ac8 100644 --- a/package.json +++ b/package.json @@ -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" } }