Skip to content

Commit

Permalink
refactor: add lib abstraction layer
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Aug 20, 2023
1 parent 2dd6be1 commit fdacde2
Show file tree
Hide file tree
Showing 123 changed files with 717 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

using System.Collections.Generic;
using Chocopoi.AvatarLib.Animations;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Lib.Proxy;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.Logging;
using Chocopoi.DressingTools.Proxy;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
using UnityEngine;

Expand Down Expand Up @@ -69,21 +70,21 @@ private bool TryGetBlendshapeValue(GameObject obj, string blendshapeName, out fl
SkinnedMeshRenderer smr;
if ((smr = obj.GetComponent<SkinnedMeshRenderer>()) == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredObjectHasNoSkinnedMeshRendererAttached, obj.name);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredObjectHasNoSkinnedMeshRendererAttached, obj.name);
return false;
}

Mesh mesh;
if ((mesh = smr.sharedMesh) == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredObjectHasNoMeshAttached, obj.name);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredObjectHasNoMeshAttached, obj.name);
return false;
}

int blendshapeIndex;
if ((blendshapeIndex = mesh.GetBlendShapeIndex(blendshapeName)) == -1)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredObjectHasNoSuchBlendshape, obj.name, blendshapeName);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredObjectHasNoSuchBlendshape, obj.name, blendshapeName);
return false;
}

Expand All @@ -98,7 +99,7 @@ private void GenerateAvatarToggleAnimations(AnimationClip enableClip, AnimationC
var obj = _avatarObject.transform.Find(toggle.path);
if (obj == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredAvatarToggleObjectNotFound, toggle.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredAvatarToggleObjectNotFound, toggle.path);
}
else
{
Expand All @@ -118,13 +119,13 @@ private void GenerateAvatarBlendshapeAnimations(AnimationClip enableClip, Animat
var obj = _avatarObject.transform.Find(blendshape.path);
if (obj == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredAvatarBlendshapeObjectNotFound, _avatarObject.name, blendshape.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredAvatarBlendshapeObjectNotFound, _avatarObject.name, blendshape.path);
continue;
}

if (!TryGetBlendshapeValue(obj.gameObject, blendshape.blendshapeName, out var originalValue))
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredCouldNotObtainAvatarBlendshapeOriginalValue, _avatarObject.name, blendshape.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredCouldNotObtainAvatarBlendshapeOriginalValue, _avatarObject.name, blendshape.path);
continue;
}

Expand All @@ -144,7 +145,7 @@ private void GenerateWearableToggleAnimations(AnimationClip enableClip, Animatio
var obj = _wearableObject.transform.Find(toggle.path);
if (obj == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredWearableToggleObjectNotFound, toggle.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredWearableToggleObjectNotFound, toggle.path);
}
else
{
Expand All @@ -164,12 +165,12 @@ private void GenerateWearableBlendshapeAnimations(AnimationClip enableClip, Anim
var obj = _wearableObject.transform.Find(blendshape.path);
if (obj == null)
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredAvatarBlendshapeObjectNotFound, _wearableObject.name, blendshape.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredAvatarBlendshapeObjectNotFound, _wearableObject.name, blendshape.path);
}

if (!TryGetBlendshapeValue(obj.gameObject, blendshape.blendshapeName, out var originalValue))
{
_report.LogWarnLocalized(LogLabel, MessageCode.IgnoredCouldNotObtainWearableBlendshapeOriginalValue, _wearableObject.name, blendshape.path);
DTReportUtils.LogWarnLocalized(_report, LogLabel, MessageCode.IgnoredCouldNotObtainWearableBlendshapeOriginalValue, _wearableObject.name, blendshape.path);
continue;
}

Expand Down
10 changes: 6 additions & 4 deletions Packages/com.chocopoi.vrc.dressingtools/Editor/DTEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Lib.Cabinet;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.Wearable;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -71,8 +73,8 @@ public static DTCabinet GetAvatarCabinet(GameObject avatar, bool createIfNotExis
comp = avatar.AddComponent<DTCabinet>();

// TODO: read default config, scan for armature names?
comp.avatarGameObject = avatar;
comp.avatarArmatureName = "Armature";
comp.AvatarGameObject = avatar;
comp.AvatarArmatureName = "Armature";
}

return comp;
Expand Down Expand Up @@ -101,7 +103,7 @@ public static void AddCabinetWearable(DTCabinet cabinet, WearableConfig config,

public static void RemoveCabinetWearable(DTCabinet cabinet, DTCabinetWearable wearable)
{
var cabinetWearables = cabinet.avatarGameObject.GetComponentsInChildren<DTCabinetWearable>();
var cabinetWearables = cabinet.AvatarGameObject.GetComponentsInChildren<DTCabinetWearable>();
foreach (var cabinetWearable in cabinetWearables)
{
if (cabinetWearable == wearable)
Expand Down Expand Up @@ -137,7 +139,7 @@ public static void AddWearableTargetAvatarConfig(WearableConfig config, GameObje
}
else
{
config.targetAvatarConfig.armatureName = cabinet.avatarArmatureName;
config.targetAvatarConfig.armatureName = cabinet.AvatarArmatureName;
}

// can't do anything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void OnInspectorGUI()
var cabinet = (DTCabinet)target;

EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Avatar", cabinet.avatarGameObject, typeof(GameObject), true);
EditorGUILayout.ObjectField("Avatar", cabinet.AvatarGameObject, typeof(GameObject), true);
EditorGUI.EndDisabledGroup();

EditorGUILayout.Separator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#if VRC_SDK_VRCSDK3
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Logging;
using UnityEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Logging;
using Chocopoi.DressingTools.UI;
using UnityEditor;
Expand Down Expand Up @@ -79,7 +80,7 @@ public bool OnPreprocessAvatar(GameObject avatarGameObject)
}
catch (System.Exception ex)
{
report.LogExceptionLocalized(LogLabel, ex, "integrations.vrc.msgCode.error.exceptionProcessAvatar");
DTReportUtils.LogExceptionLocalized(report, LogLabel, ex, "integrations.vrc.msgCode.error.exceptionProcessAvatar");
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
using Chocopoi.AvatarLib.Animations;
using Chocopoi.AvatarLib.Expressions;
using Chocopoi.DressingTools.Animations;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Logging;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
using UnityEditor;
using UnityEditor.Animations;
Expand Down Expand Up @@ -63,7 +64,7 @@ public bool OnPreprocessAvatar()
EditorUtility.DisplayProgressBar("DressingTools", "Generating animations...", 0);

// get the avatar descriptor
var avatarDescriptor = _cabinet.avatarGameObject.GetComponent<VRCAvatarDescriptor>();
var avatarDescriptor = _cabinet.AvatarGameObject.GetComponent<VRCAvatarDescriptor>();

// obtain FX layer
var fxController = CopyAndReplaceLayerAnimator(avatarDescriptor, VRCAvatarDescriptor.AnimLayerType.FX);
Expand Down Expand Up @@ -112,7 +113,7 @@ public bool OnPreprocessAvatar()
}
catch (ParameterOverflowException ex)
{
_report.LogExceptionLocalized(LogLabel, ex, "integrations.vrc.msgCode.error.parameterOverFlow");
DTReportUtils.LogExceptionLocalized(_report, LogLabel, ex, "integrations.vrc.msgCode.error.parameterOverFlow");
return false;
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public bool OnPreprocessAvatar()
continue;
}

var animationGenerator = new AnimationGenerator(_report, _cabinet.avatarGameObject, module, wearables[i].wearableGameObject, wearableDynamics);
var animationGenerator = new AnimationGenerator(_report, _cabinet.AvatarGameObject, module, wearables[i].wearableGameObject, wearableDynamics);

// TODO: write defaults settings
var wearAnimations = animationGenerator.GenerateWearAnimations(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Text.RegularExpressions;
using Chocopoi.DressingTools.Dresser;
using Chocopoi.DressingTools.Dresser.Default;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Localization;
using Chocopoi.DressingTools.Logging;
using UnityEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Dresser;
using Chocopoi.DressingTools.Dresser.Default;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UI.View;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
Expand Down Expand Up @@ -64,9 +66,9 @@ static void QuickAutoSetup(MenuCommand menuCommand)
}

var config = new WearableConfig();
DTEditorUtils.PrepareWearableConfig(config, cabinet.avatarGameObject, wearable);
DTEditorUtils.PrepareWearableConfig(config, cabinet.AvatarGameObject, wearable);

var armatureName = cabinet.avatarArmatureName;
var armatureName = cabinet.AvatarArmatureName;

// attempt to find wearable armature using avatar armature name
var armature = DTRuntimeUtils.GuessArmature(wearable, armatureName);
Expand All @@ -86,15 +88,15 @@ static void QuickAutoSetup(MenuCommand menuCommand)

var dresserSettings = new DefaultDresserSettings()
{
targetAvatar = cabinet.avatarGameObject,
targetAvatar = cabinet.AvatarGameObject,
targetWearable = wearable,
dynamicsOption = DefaultDresserDynamicsOption.RemoveDynamicsAndUseParentConstraint
};

var dresser = new DefaultDresser();
var report = dresser.Execute(dresserSettings, out _);

if (report.HasLogType(Logging.DTReportLogType.Error))
if (report.HasLogType(DTReportLogType.Error))
{
ReportWindow.ShowWindow(report);
EditorUtility.DisplayDialog("DressingTools", "Default dresser has errors processing this wearable automatically, please use the wizard instead.", "OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Generic;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UI.View;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
using Newtonsoft.Json;
Expand Down Expand Up @@ -75,8 +76,8 @@ private void OnCabinetSettingsChange()

var cabinet = cabinets[_view.SelectedCabinetIndex];

cabinet.avatarArmatureName = _view.CabinetAvatarArmatureName;
cabinet.avatarGameObject = _view.CabinetAvatarGameObject;
cabinet.AvatarArmatureName = _view.CabinetAvatarArmatureName;
cabinet.AvatarGameObject = _view.CabinetAvatarGameObject;
}

private void OnForceUpdateView()
Expand Down Expand Up @@ -118,7 +119,7 @@ private void UpdateCabinetSelectionDropdown(DTCabinet[] cabinets)
string[] cabinetOptions = new string[cabinets.Length];
for (var i = 0; i < cabinets.Length; i++)
{
cabinetOptions[i] = cabinets[i].avatarGameObject != null ? cabinets[i].avatarGameObject.name : string.Format("Cabinet {0} (No GameObject Attached)", i + 1);
cabinetOptions[i] = cabinets[i].AvatarGameObject != null ? cabinets[i].AvatarGameObject.name : string.Format("Cabinet {0} (No GameObject Attached)", i + 1);
}
_view.AvailableCabinetSelections = cabinetOptions;
}
Expand Down Expand Up @@ -148,8 +149,8 @@ private void UpdateView()
// update selected cabinet view
var cabinet = cabinets[_view.SelectedCabinetIndex];

_view.CabinetAvatarGameObject = cabinet.avatarGameObject;
_view.CabinetAvatarArmatureName = cabinet.avatarArmatureName;
_view.CabinetAvatarGameObject = cabinet.AvatarGameObject;
_view.CabinetAvatarArmatureName = cabinet.AvatarArmatureName;

var wearables = cabinet.GetWearables();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System.Collections.Generic;
using Chocopoi.AvatarLib.Animations;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

using System.Collections.Generic;
using Chocopoi.DressingTools.Lib.UI;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Dresser;
using Chocopoi.DressingTools.Dresser.Default;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Lib.UI;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.Logging;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
Expand Down Expand Up @@ -188,8 +191,8 @@ private void UpdateDresserSettings()
if (_cabinet != null)
{
_view.IsAvatarAssociatedWithCabinet = true;
_view.AvatarArmatureName = _cabinet.avatarArmatureName;
_view.DresserSettings.avatarArmatureName = _cabinet.avatarArmatureName;
_view.AvatarArmatureName = _cabinet.AvatarArmatureName;
_view.DresserSettings.avatarArmatureName = _cabinet.AvatarArmatureName;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License along with DressingTools. If not, see <https://www.gnu.org/licenses/>.
*/

using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
using Chocopoi.DressingTools.Wearable.Modules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License along with DressingTools. If not, see <https://www.gnu.org/licenses/>.
*/

using Chocopoi.DressingTools.Lib.UI;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable.Modules;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Chocopoi.DressingTools.Lib.UI;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.Lib.Wearable.Modules;
using Chocopoi.DressingTools.UI.Views.Modules;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
Expand Down Expand Up @@ -90,7 +93,7 @@ private void ApplyTargetAvatarConfigChanges()
}
else
{
_view.Config.targetAvatarConfig.armatureName = cabinet.avatarArmatureName;
_view.Config.targetAvatarConfig.armatureName = cabinet.AvatarArmatureName;
}

// can't do anything
Expand Down Expand Up @@ -177,7 +180,7 @@ private void OnAddModuleButtonClick()
UpdateModulesView();
}

private ModuleEditor CreateModuleEditor(IWearableModule module)
private ModuleEditor CreateModuleEditor(WearableModuleBase module)
{
// prepare cache if not yet
if (s_moduleEditorTypesCache == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

using System.Collections.Generic;
using Chocopoi.DressingTools.Cabinet;
using Chocopoi.DressingTools.Lib.Cabinet;
using Chocopoi.DressingTools.Lib.Wearable;
using Chocopoi.DressingTools.UIBase.Views;
using Chocopoi.DressingTools.Wearable;
using UnityEngine;
Expand Down Expand Up @@ -75,7 +77,7 @@ private void AutoSetupMapping()
var armatureName = "Armature";
if (cabinet != null)
{
armatureName = cabinet.avatarArmatureName;
armatureName = cabinet.AvatarArmatureName;
_view.ShowAvatarNoCabinetHelpBox = false;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Generic;
using Chocopoi.DressingTools.Lib.Logging;
using Chocopoi.DressingTools.Localization;
using Chocopoi.DressingTools.Logging;
using UnityEditor;
Expand Down
Loading

0 comments on commit fdacde2

Please sign in to comment.