From 3f304f72759e7a702fab81b20588f7eafc74f674 Mon Sep 17 00:00:00 2001 From: ButterscotchVanilla Date: Thu, 16 Dec 2021 02:06:55 -0500 Subject: [PATCH] Optimize offset calculation for bulk config set & finish AutoBone implementation --- .../java/dev/slimevr/autobone/AutoBone.java | 18 ++++++++++++++---- .../vr/processor/skeleton/SkeletonConfig.java | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/slimevr/autobone/AutoBone.java b/src/main/java/dev/slimevr/autobone/AutoBone.java index a2ec344da..f38b5c424 100644 --- a/src/main/java/dev/slimevr/autobone/AutoBone.java +++ b/src/main/java/dev/slimevr/autobone/AutoBone.java @@ -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 selection, SkeletonConfig skeletonConfig) { + float sum = 0f; + + for (SkeletonConfigValue config : selection) { + sum += skeletonConfig.getConfig(config); + } + + return sum; + } + public float getLengthSum(Map 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); diff --git a/src/main/java/dev/slimevr/vr/processor/skeleton/SkeletonConfig.java b/src/main/java/dev/slimevr/vr/processor/skeleton/SkeletonConfig.java index 5f41f9e1a..97742afc1 100644 --- a/src/main/java/dev/slimevr/vr/processor/skeleton/SkeletonConfig.java +++ b/src/main/java/dev/slimevr/vr/processor/skeleton/SkeletonConfig.java @@ -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 configs, Map 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 configs, Map 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); } }