VFX Category Label Generation
This commit is contained in:
+196
-18
@@ -29,6 +29,7 @@ type autogenManifestEntry struct {
|
||||
Source string `json:"source"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Subgroup string `json:"subgroup,omitempty"`
|
||||
Category string `json:"category,omitempty"`
|
||||
ModelStem string `json:"model_stem,omitempty"`
|
||||
RowID int `json:"row_id,omitempty"`
|
||||
}
|
||||
@@ -319,6 +320,7 @@ func deriveAutogenManifestEntry(rel string, derive project.AutogenDeriveConfig)
|
||||
entry.Group = parts[0]
|
||||
if len(parts) > 2 {
|
||||
entry.Subgroup = strings.Join(parts[1:len(parts)-1], "/")
|
||||
entry.Category = parts[len(parts)-2]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,10 +742,25 @@ func augmentWithAutogeneratedHeadVisualeffects(collected []nativeCollectedDatase
|
||||
|
||||
rowID, ok := lockData[key]
|
||||
if !ok {
|
||||
var migratedLegacyKey string
|
||||
if preservedRowID, preserved := historicalLockData[key]; preserved {
|
||||
rowID = preservedRowID
|
||||
} else {
|
||||
rowID = allocateNextID()
|
||||
preservedLegacyID := false
|
||||
for _, legacyKey := range headVisualeffectLegacyKeys(dataset.Dataset.Name, entry, policy) {
|
||||
if preservedRowID, preserved := historicalLockData[legacyKey]; preserved {
|
||||
rowID = preservedRowID
|
||||
preservedLegacyID = true
|
||||
migratedLegacyKey = legacyKey
|
||||
break
|
||||
}
|
||||
}
|
||||
if !preservedLegacyID {
|
||||
rowID = allocateNextID()
|
||||
}
|
||||
}
|
||||
if migratedLegacyKey != "" && migratedLegacyKey != key {
|
||||
delete(lockData, migratedLegacyKey)
|
||||
}
|
||||
lockData[key] = rowID
|
||||
}
|
||||
@@ -772,9 +789,15 @@ func nextAvailableAutogenID(used map[int]struct{}) int {
|
||||
|
||||
type headVisualeffectsPolicy struct {
|
||||
Groups map[string]headVisualeffectsGroupPolicy
|
||||
GroupTokenSource string
|
||||
CategoryFrom string
|
||||
Delimiter string
|
||||
Case string
|
||||
StripModelPrefixes []string
|
||||
KeyFormat string
|
||||
LabelFormat string
|
||||
LegacyGroups map[string]string
|
||||
LegacyKeyFormat string
|
||||
ModelColumn string
|
||||
RowDefaults map[string]string
|
||||
}
|
||||
@@ -798,11 +821,13 @@ func applyHeadVisualeffectsConfig(policy *headVisualeffectsPolicy, cfg project.H
|
||||
for group, groupCfg := range cfg.Groups {
|
||||
group = strings.TrimSpace(group)
|
||||
prefix := strings.TrimSpace(groupCfg.Prefix)
|
||||
if group == "" || prefix == "" {
|
||||
if group == "" {
|
||||
continue
|
||||
}
|
||||
groupPolicy := policy.Groups[group]
|
||||
groupPolicy.Prefix = prefix
|
||||
if prefix != "" {
|
||||
groupPolicy.Prefix = prefix
|
||||
}
|
||||
if columns := normalizeHeadVisualeffectsModelColumns(groupCfg.ModelColumn, groupCfg.ModelColumns); len(columns) > 0 {
|
||||
groupPolicy.ModelColumns = columns
|
||||
}
|
||||
@@ -812,6 +837,18 @@ func applyHeadVisualeffectsConfig(policy *headVisualeffectsPolicy, cfg project.H
|
||||
mergeStringMap(groupPolicy.RowDefaults, normalizeHeadVisualeffectsRowDefaults(groupCfg.RowDefaults))
|
||||
policy.Groups[group] = groupPolicy
|
||||
}
|
||||
if strings.TrimSpace(cfg.GroupTokenSource) != "" {
|
||||
policy.GroupTokenSource = strings.TrimSpace(cfg.GroupTokenSource)
|
||||
}
|
||||
if strings.TrimSpace(cfg.CategoryFrom) != "" {
|
||||
policy.CategoryFrom = strings.TrimSpace(cfg.CategoryFrom)
|
||||
}
|
||||
if cfg.Delimiter != "" {
|
||||
policy.Delimiter = cfg.Delimiter
|
||||
}
|
||||
if strings.TrimSpace(cfg.Case) != "" {
|
||||
policy.Case = strings.TrimSpace(cfg.Case)
|
||||
}
|
||||
if len(cfg.StripModelPrefixes) > 0 {
|
||||
policy.StripModelPrefixes = append([]string(nil), cfg.StripModelPrefixes...)
|
||||
}
|
||||
@@ -821,6 +858,22 @@ func applyHeadVisualeffectsConfig(policy *headVisualeffectsPolicy, cfg project.H
|
||||
if strings.TrimSpace(cfg.LabelFormat) != "" {
|
||||
policy.LabelFormat = strings.TrimSpace(cfg.LabelFormat)
|
||||
}
|
||||
if len(cfg.LegacyGroups) > 0 {
|
||||
if policy.LegacyGroups == nil {
|
||||
policy.LegacyGroups = map[string]string{}
|
||||
}
|
||||
for legacyGroup, group := range cfg.LegacyGroups {
|
||||
legacyGroup = strings.TrimSpace(legacyGroup)
|
||||
group = strings.TrimSpace(group)
|
||||
if legacyGroup == "" || group == "" {
|
||||
continue
|
||||
}
|
||||
policy.LegacyGroups[legacyGroup] = group
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(cfg.LegacyKeyFormat) != "" {
|
||||
policy.LegacyKeyFormat = strings.TrimSpace(cfg.LegacyKeyFormat)
|
||||
}
|
||||
if strings.TrimSpace(cfg.ModelColumn) != "" {
|
||||
policy.ModelColumn = strings.TrimSpace(cfg.ModelColumn)
|
||||
}
|
||||
@@ -834,6 +887,10 @@ func defaultHeadVisualeffectsPolicy() headVisualeffectsPolicy {
|
||||
"head_decorations": {Prefix: "headdecoration"},
|
||||
"head_features": {Prefix: "headfeature"},
|
||||
},
|
||||
GroupTokenSource: "prefix",
|
||||
CategoryFrom: "none",
|
||||
Delimiter: "_",
|
||||
Case: "preserve",
|
||||
StripModelPrefixes: []string{"hfx_", "vfx_"},
|
||||
KeyFormat: "{dataset}:{prefix}_{stem}",
|
||||
LabelFormat: "{prefix}_{stem_upper}",
|
||||
@@ -882,11 +939,104 @@ func mergeStringMap(target map[string]string, source map[string]string) {
|
||||
}
|
||||
|
||||
func headVisualeffectIdentity(dataset string, entry autogenManifestEntry, policy headVisualeffectsPolicy) (string, string, string, headVisualeffectsGroupPolicy, bool) {
|
||||
entry = normalizeHeadVisualeffectEntry(entry, policy)
|
||||
group, ok := policy.Groups[entry.Group]
|
||||
if !ok || strings.TrimSpace(entry.ModelStem) == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
modelStem := strings.TrimSpace(entry.ModelStem)
|
||||
stem := stripHeadVisualeffectModelPrefix(modelStem, policy)
|
||||
stem = strings.TrimSpace(stem)
|
||||
if stem == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
category := headVisualeffectCategory(entry, policy)
|
||||
groupToken := headVisualeffectGroupToken(entry.Group, group, policy)
|
||||
values := map[string]string{
|
||||
"dataset": dataset,
|
||||
"group": applyHeadVisualeffectCase(groupToken, policy),
|
||||
"group_raw": entry.Group,
|
||||
"prefix": applyHeadVisualeffectCase(group.Prefix, policy),
|
||||
"category": applyHeadVisualeffectCase(category, policy),
|
||||
"category_upper": strings.ToUpper(category),
|
||||
"category_segment": headVisualeffectDelimitedSegment(applyHeadVisualeffectCase(category, policy), policy.Delimiter),
|
||||
"category_segment_upper": headVisualeffectDelimitedSegment(strings.ToUpper(category), policy.Delimiter),
|
||||
"subgroup": applyHeadVisualeffectCase(entry.Subgroup, policy),
|
||||
"stem": applyHeadVisualeffectCase(stem, policy),
|
||||
"stem_upper": strings.ToUpper(stem),
|
||||
"model_stem": modelStem,
|
||||
"delimiter": policy.Delimiter,
|
||||
}
|
||||
key := expandHeadVisualeffectsFormat(policy.KeyFormat, values)
|
||||
label := expandHeadVisualeffectsFormat(policy.LabelFormat, values)
|
||||
if strings.TrimSpace(key) == "" || strings.TrimSpace(label) == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
}
|
||||
return key, label, modelStem, group, true
|
||||
}
|
||||
|
||||
func headVisualeffectLegacyKeys(dataset string, entry autogenManifestEntry, policy headVisualeffectsPolicy) []string {
|
||||
if strings.TrimSpace(policy.LegacyKeyFormat) == "" {
|
||||
return nil
|
||||
}
|
||||
entry = normalizeHeadVisualeffectEntry(entry, policy)
|
||||
group, ok := policy.Groups[entry.Group]
|
||||
if !ok || strings.TrimSpace(entry.ModelStem) == "" {
|
||||
return nil
|
||||
}
|
||||
modelStem := strings.TrimSpace(entry.ModelStem)
|
||||
stem := strings.TrimSpace(stripHeadVisualeffectModelPrefix(modelStem, policy))
|
||||
if stem == "" {
|
||||
return nil
|
||||
}
|
||||
groupToken := headVisualeffectGroupToken(entry.Group, group, policy)
|
||||
values := map[string]string{
|
||||
"dataset": dataset,
|
||||
"group": applyHeadVisualeffectCase(groupToken, policy),
|
||||
"group_raw": entry.Group,
|
||||
"prefix": applyHeadVisualeffectCase(group.Prefix, policy),
|
||||
"stem": applyHeadVisualeffectCase(stem, policy),
|
||||
"stem_upper": strings.ToUpper(stem),
|
||||
"model_stem": modelStem,
|
||||
"delimiter": policy.Delimiter,
|
||||
}
|
||||
legacyKey := strings.TrimSpace(expandHeadVisualeffectsFormat(policy.LegacyKeyFormat, values))
|
||||
if legacyKey == "" {
|
||||
return nil
|
||||
}
|
||||
return []string{legacyKey}
|
||||
}
|
||||
|
||||
func normalizeHeadVisualeffectEntry(entry autogenManifestEntry, policy headVisualeffectsPolicy) autogenManifestEntry {
|
||||
entry.Group = strings.TrimSpace(entry.Group)
|
||||
if mapped, ok := policy.LegacyGroups[entry.Group]; ok && strings.TrimSpace(mapped) != "" {
|
||||
entry.Group = strings.TrimSpace(mapped)
|
||||
}
|
||||
if strings.TrimSpace(entry.Group) == "" && strings.TrimSpace(entry.Source) != "" {
|
||||
parts := strings.Split(filepath.ToSlash(entry.Source), "/")
|
||||
if len(parts) > 1 {
|
||||
entry.Group = parts[0]
|
||||
if mapped, ok := policy.LegacyGroups[entry.Group]; ok && strings.TrimSpace(mapped) != "" {
|
||||
entry.Group = strings.TrimSpace(mapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(entry.Subgroup) == "" && strings.TrimSpace(entry.Source) != "" {
|
||||
parts := strings.Split(filepath.ToSlash(entry.Source), "/")
|
||||
if len(parts) > 2 {
|
||||
entry.Subgroup = strings.Join(parts[1:len(parts)-1], "/")
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(entry.Category) == "" && strings.TrimSpace(entry.Source) != "" {
|
||||
parts := strings.Split(filepath.ToSlash(entry.Source), "/")
|
||||
if len(parts) > 2 {
|
||||
entry.Category = parts[len(parts)-2]
|
||||
}
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
func stripHeadVisualeffectModelPrefix(modelStem string, policy headVisualeffectsPolicy) string {
|
||||
stem := modelStem
|
||||
for _, prefix := range policy.StripModelPrefixes {
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
@@ -895,24 +1045,46 @@ func headVisualeffectIdentity(dataset string, entry autogenManifestEntry, policy
|
||||
}
|
||||
stem = strings.TrimPrefix(stem, prefix)
|
||||
}
|
||||
stem = strings.TrimSpace(stem)
|
||||
if stem == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
return stem
|
||||
}
|
||||
|
||||
func headVisualeffectGroupToken(groupName string, group headVisualeffectsGroupPolicy, policy headVisualeffectsPolicy) string {
|
||||
if policy.GroupTokenSource == "folder_name" {
|
||||
return groupName
|
||||
}
|
||||
values := map[string]string{
|
||||
"dataset": dataset,
|
||||
"group": entry.Group,
|
||||
"prefix": group.Prefix,
|
||||
"stem": stem,
|
||||
"stem_upper": strings.ToUpper(stem),
|
||||
"model_stem": modelStem,
|
||||
if strings.TrimSpace(group.Prefix) != "" {
|
||||
return group.Prefix
|
||||
}
|
||||
key := expandHeadVisualeffectsFormat(policy.KeyFormat, values)
|
||||
label := expandHeadVisualeffectsFormat(policy.LabelFormat, values)
|
||||
if strings.TrimSpace(key) == "" || strings.TrimSpace(label) == "" {
|
||||
return "", "", "", headVisualeffectsGroupPolicy{}, false
|
||||
return groupName
|
||||
}
|
||||
|
||||
func headVisualeffectCategory(entry autogenManifestEntry, policy headVisualeffectsPolicy) string {
|
||||
switch policy.CategoryFrom {
|
||||
case "immediate_parent":
|
||||
return strings.TrimSpace(entry.Category)
|
||||
case "full_subgroup":
|
||||
return strings.TrimSpace(entry.Subgroup)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func headVisualeffectDelimitedSegment(value, delimiter string) string {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return ""
|
||||
}
|
||||
return value + delimiter
|
||||
}
|
||||
|
||||
func applyHeadVisualeffectCase(value string, policy headVisualeffectsPolicy) string {
|
||||
switch policy.Case {
|
||||
case "lower":
|
||||
return strings.ToLower(value)
|
||||
case "upper":
|
||||
return strings.ToUpper(value)
|
||||
default:
|
||||
return value
|
||||
}
|
||||
return key, label, modelStem, group, true
|
||||
}
|
||||
|
||||
func expandHeadVisualeffectsFormat(format string, values map[string]string) string {
|
||||
@@ -997,9 +1169,15 @@ func formatAutogenManifest(root string, producer project.AutogenProducerConfig,
|
||||
|
||||
func autogenHeadVisualeffectsConfigConfigured(cfg project.HeadVisualeffectsConfig) bool {
|
||||
return len(cfg.Groups) > 0 ||
|
||||
strings.TrimSpace(cfg.GroupTokenSource) != "" ||
|
||||
strings.TrimSpace(cfg.CategoryFrom) != "" ||
|
||||
cfg.Delimiter != "" ||
|
||||
strings.TrimSpace(cfg.Case) != "" ||
|
||||
len(cfg.StripModelPrefixes) > 0 ||
|
||||
strings.TrimSpace(cfg.KeyFormat) != "" ||
|
||||
strings.TrimSpace(cfg.LabelFormat) != "" ||
|
||||
len(cfg.LegacyGroups) > 0 ||
|
||||
strings.TrimSpace(cfg.LegacyKeyFormat) != "" ||
|
||||
strings.TrimSpace(cfg.ModelColumn) != "" ||
|
||||
len(cfg.RowDefaults) > 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user