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/YOTSCore.cs | 20 ++++++++++++++++++++ Scripts/YOTSNDMFGenerator.cs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'Scripts') diff --git a/Scripts/YOTSCore.cs b/Scripts/YOTSCore.cs index f32bdfa..c5cd5dc 100644 --- a/Scripts/YOTSCore.cs +++ b/Scripts/YOTSCore.cs @@ -143,6 +143,10 @@ namespace YOTS [SerializeField] public List paths = new List(); + // Names of object sets to use as paths. + [SerializeField] + public List sets = new List(); + // The value of the blendshape when the toggle is off. Range from 0-100. [SerializeField] public float offValue = 0.0f; @@ -163,6 +167,10 @@ namespace YOTS [SerializeField] public List paths = new List(); + // Names of object sets to use as paths. + [SerializeField] + public List sets = new List(); + [SerializeField] public float offValue = 0.0f; @@ -185,8 +193,20 @@ namespace YOTS public float onValue = 1.0f; } + [System.Serializable] + public class ObjectSet { + [SerializeField] + public string name; + + [SerializeField] + public List objects = new List(); + } + [System.Serializable] public class AnimatorConfigFile { + [SerializeField] + public List objectSets = new List(); + [SerializeField] public List toggles = new List(); 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