mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-02-02 03:32:56 +08:00
Support path remappings in the FPVProcessor
As part of this, PathMappings was refactored to support processing original paths through multiple phases of remapping. Closes #73
This commit is contained in:
parent
c2f390071a
commit
8bb1969ecf
@ -112,9 +112,9 @@ namespace net.fushizen.modular_avatar.core.editor
|
||||
new MergeArmatureHook().OnPreprocessAvatar(avatarGameObject);
|
||||
new RetargetMeshes().OnPreprocessAvatar(avatarGameObject);
|
||||
new BoneProxyProcessor().OnPreprocessAvatar(avatarGameObject);
|
||||
new FirstPersonVisibleProcessor(avatarGameObject.GetComponent<VRCAvatarDescriptor>()).Process();
|
||||
new MergeAnimatorProcessor().OnPreprocessAvatar(avatarGameObject);
|
||||
new BlendshapeSyncAnimationProcessor().OnPreprocessAvatar(avatarGameObject);
|
||||
new FirstPersonVisibleProcessor(avatarGameObject.GetComponent<VRCAvatarDescriptor>()).Process();
|
||||
|
||||
AfterProcessing?.Invoke(avatarGameObject);
|
||||
|
||||
|
@ -89,7 +89,14 @@ namespace net.fushizen.modular_avatar.core.editor
|
||||
var oscale = xform.lossyScale;
|
||||
xform.localScale = new Vector3(oscale.x / pscale.x, oscale.y / pscale.y, oscale.z / pscale.z);
|
||||
|
||||
var oldPath = RuntimeUtil.AvatarRootPath(target.gameObject);
|
||||
target.transform.SetParent(proxy, true);
|
||||
var newPath = RuntimeUtil.AvatarRootPath(target.gameObject);
|
||||
PathMappings.Remap(oldPath, new PathMappings.MappingEntry()
|
||||
{
|
||||
path = newPath,
|
||||
transformPath = newPath
|
||||
});
|
||||
|
||||
didWork = true;
|
||||
}
|
||||
|
@ -30,8 +30,7 @@ namespace net.fushizen.modular_avatar.core.editor
|
||||
{
|
||||
public static class PathMappings
|
||||
{
|
||||
private static SortedDictionary<string, MappingEntry> Mappings = new SortedDictionary<string, MappingEntry>();
|
||||
private static List<string> CachedMappingKeys = null;
|
||||
private static List<(string, MappingEntry)> Mappings = new List<(string, MappingEntry)>();
|
||||
|
||||
public struct MappingEntry
|
||||
{
|
||||
@ -43,33 +42,30 @@ namespace net.fushizen.modular_avatar.core.editor
|
||||
return isTransformMapping ? transformPath : path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static void Clear()
|
||||
{
|
||||
Mappings.Clear();
|
||||
CachedMappingKeys = null;
|
||||
}
|
||||
|
||||
internal static void Remap(string from, MappingEntry to)
|
||||
{
|
||||
Mappings[from] = to;
|
||||
CachedMappingKeys = null;
|
||||
Mappings.Add((from, to));
|
||||
}
|
||||
|
||||
internal static string MapPath(string path, bool isTransformMapping = false)
|
||||
{
|
||||
if (CachedMappingKeys == null) CachedMappingKeys = new List<string>(Mappings.Keys);
|
||||
var bsResult = CachedMappingKeys.BinarySearch(path);
|
||||
if (bsResult >= 0) return Mappings[path].Get(isTransformMapping);
|
||||
|
||||
int index = ~bsResult;
|
||||
if (index == 0) return path;
|
||||
|
||||
var priorKey = CachedMappingKeys[index - 1];
|
||||
if (path.StartsWith(priorKey + "/"))
|
||||
foreach (var (src, mapping) in Mappings)
|
||||
{
|
||||
return Mappings[priorKey].Get(isTransformMapping) + path.Substring(priorKey.Length);
|
||||
if (path == src || path.StartsWith(src + "/"))
|
||||
{
|
||||
var suffix = path.Substring(src.Length);
|
||||
path = mapping.Get(isTransformMapping) + suffix;
|
||||
|
||||
// Continue processing subsequent remappings
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user