mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-30 22:02:45 -08:00
Optimize offset calculation for bulk config set & finish AutoBone implementation
This commit is contained in:
2 files changed
+28
-9
No files matched your search
@@ -159,9 +159,9 @@ public class AutoBone {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO Temporarily disabled, will fix in a later commit @ButterscotchVanilla
|
||||
//configs.forEach(skeleton::setSkeletonConfig);
|
||||
|
||||
SkeletonConfig skeletonConfig = skeleton.getSkeletonConfig();
|
||||
skeletonConfig.setConfigs(configs, null);
|
||||
skeletonConfig.saveToConfig(server.config);
|
||||
server.saveConfig();
|
||||
|
||||
LogManager.log.info("[AutoBone] Configured skeleton bone lengths");
|
||||
@@ -211,6 +211,16 @@ public class AutoBone {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public float sumSelectConfigs(List<SkeletonConfigValue> selection, SkeletonConfig skeletonConfig) {
|
||||
float sum = 0f;
|
||||
|
||||
for (SkeletonConfigValue config : selection) {
|
||||
sum += skeletonConfig.getConfig(config);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public float getLengthSum(Map<SkeletonConfigValue, Float> configs) {
|
||||
return getLengthSum(configs, null);
|
||||
}
|
||||
@@ -278,7 +288,7 @@ public class AutoBone {
|
||||
if(targetHeight < 0f) {
|
||||
if(skeleton != null) {
|
||||
// TODO Fix height calculation @ButterscotchVanilla
|
||||
targetHeight = 1.75f; //sumSelectConfigs(heightConfigs, skeleton.getSkeletonConfig(), staticConfigs);
|
||||
targetHeight = sumSelectConfigs(heightConfigs, skeleton.getSkeletonConfig());
|
||||
LogManager.log.warning("[AutoBone] Target height loaded from skeleton (Make sure you reset before running!): " + targetHeight);
|
||||
} else {
|
||||
float hmdHeight = getMaxHmdHeight(frames);
|
||||
|
||||
@@ -91,11 +91,11 @@ public class SkeletonConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, Float newValue) {
|
||||
public Float setConfig(SkeletonConfigValue config, Float newValue, boolean computeOffsets) {
|
||||
Float origVal = newValue != null ? configs.put(config, newValue) : configs.remove(config);
|
||||
|
||||
// Re-compute the affected offsets
|
||||
if (autoUpdateOffsets && config.affectedOffsets != null) {
|
||||
if (computeOffsets && autoUpdateOffsets && config.affectedOffsets != null) {
|
||||
for (SkeletonNodeOffset offset : config.affectedOffsets) {
|
||||
computeNodeOffset(offset);
|
||||
}
|
||||
@@ -112,6 +112,10 @@ public class SkeletonConfig {
|
||||
return origVal;
|
||||
}
|
||||
|
||||
public Float setConfig(SkeletonConfigValue config, Float newValue) {
|
||||
return setConfig(config, newValue, true);
|
||||
}
|
||||
|
||||
public Float setConfig(String config, Float newValue) {
|
||||
return setConfig(SkeletonConfigValue.getByStringValue(config), newValue);
|
||||
}
|
||||
@@ -249,7 +253,10 @@ public class SkeletonConfig {
|
||||
|
||||
public void setConfigs(Map<SkeletonConfigValue, Float> configs, Map<SkeletonConfigToggle, Boolean> toggles) {
|
||||
if (configs != null) {
|
||||
configs.forEach(this::setConfig);
|
||||
configs.forEach((key, value) -> {
|
||||
// Do not recalculate the offsets, these are done in bulk at the end
|
||||
setConfig(key, value, false);
|
||||
});
|
||||
}
|
||||
|
||||
if (toggles != null) {
|
||||
@@ -264,7 +271,8 @@ public class SkeletonConfig {
|
||||
public void setStringConfigs(Map<String, Float> configs, Map<String, Boolean> toggles) {
|
||||
if (configs != null) {
|
||||
configs.forEach((key, value) -> {
|
||||
setConfig(SkeletonConfigValue.getByStringValue(key), value);
|
||||
// Do not recalculate the offsets, these are done in bulk at the end
|
||||
setConfig(SkeletonConfigValue.getByStringValue(key), value, false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -317,7 +325,8 @@ public class SkeletonConfig {
|
||||
for (SkeletonConfigValue configValue : SkeletonConfigValue.values) {
|
||||
Float val = castFloat(config.getProperty(configValue.configKey));
|
||||
if (val != null) {
|
||||
setConfig(configValue, val);
|
||||
// Do not recalculate the offsets, these are done in bulk at the end
|
||||
setConfig(configValue, val, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user