From 161ccbaa357cacbaaf5d2ab715250bd69f3fc202 Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 8 Mar 2026 17:39:19 -0700 Subject: Implement object sets feature --- Scripts/YOTSNDMFGenerator.cs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'Scripts/YOTSNDMFGenerator.cs') diff --git a/Scripts/YOTSNDMFGenerator.cs b/Scripts/YOTSNDMFGenerator.cs index 338aebc..9af0772 100644 --- a/Scripts/YOTSNDMFGenerator.cs +++ b/Scripts/YOTSNDMFGenerator.cs @@ -55,6 +55,7 @@ namespace YOTS return; } var parsed = JsonUtility.FromJson(config.jsonConfig.text); + mergedConfig.objectSets.AddRange(parsed.objectSets); mergedConfig.toggles.AddRange(parsed.toggles); if (parsed.api_version != null) { mergedConfig.api_version = parsed.api_version; @@ -176,18 +177,30 @@ namespace YOTS } // Resolve bare names (no '/') to full hierarchy paths. Names containing - // '/' are kept as explicit paths. + // '/' are kept as explicit paths. Also expands object set references into paths. private static string ResolveNames(string jsonConfig, Transform avatarRoot) { var config = JsonUtility.FromJson(jsonConfig); + + // Build set lookup. + var setMap = new Dictionary>(); + if (config.objectSets != null) { + foreach (var set in config.objectSets) { + setMap[set.name] = set.objects; + } + } + + // Expand set references into paths, then resolve bare names. var nameToPathsMap = BuildNameToPathsMap(avatarRoot); foreach (var toggle in config.toggles) { toggle.meshToggles = ExpandNames(toggle.meshToggles, nameToPathsMap); toggle.inverseMeshToggles = ExpandNames(toggle.inverseMeshToggles, nameToPathsMap); foreach (var bs in toggle.blendShapes) { + bs.paths = ExpandSets(bs.paths, bs.sets, setMap, toggle.name, "blendShape"); bs.path = ExpandName(bs.path, nameToPathsMap); bs.paths = ExpandNames(bs.paths, nameToPathsMap); } foreach (var st in toggle.shaderToggles) { + st.paths = ExpandSets(st.paths, st.sets, setMap, toggle.name, "shaderToggle"); st.path = ExpandName(st.path, nameToPathsMap); st.paths = ExpandNames(st.paths, nameToPathsMap); } @@ -195,6 +208,22 @@ namespace YOTS return JsonUtility.ToJson(config); } + // Expand object set references into the paths list. + private static List ExpandSets(List paths, List sets, + Dictionary> setMap, string toggleName, string specType) { + if (sets == null || sets.Count == 0) return paths; + var result = paths != null ? new List(paths) : new List(); + foreach (var setName in sets) { + if (setMap.TryGetValue(setName, out var objects)) { + result.AddRange(objects); + } else { + throw new ArgumentException( + $"{specType} in '{toggleName}' references unknown object set '{setName}'"); + } + } + return result; + } + private static string ExpandName(string name, Dictionary> nameToPathsMap) { if (string.IsNullOrEmpty(name) || name.Contains('/')) return name; if (nameToPathsMap.TryGetValue(name, out var paths) && paths.Count == 1) return paths[0]; -- cgit v1.2.3