Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
相机预设
UI布局变动
UI颜色
  • Loading branch information
xiaoye97 committed Jan 13, 2022
1 parent 00e1ee3 commit 100a409
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

- 基于[BeplnEx][1]
- 链接纹理功能,通过外部绘图工具(PS/SAI等)对纹理进行处理,并实时同步到VRoid Studio内
- 镜头位置预设,快速定位到全身和脸部的四方向视角,可选透视或正交模式
- 镜头位置预设,快速定位到全身和脸部的四方向视角,可选透视或正交模式,支持自定义位置
- 参考工具,可以添加标尺和参考图
- 抗锯齿,除了在摄影棚中可以抗锯齿之外,在编辑模式下也可以开启抗锯齿

Expand Down
5 changes: 4 additions & 1 deletion README_English.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ Extension Plugin for VRoid Studio

`Q:` I installed the plugin. How can I open it in the VRoid Studio?

`A:` F11 or edit hotkey in BepInEx/config/me.xiaoye97.plugin.VRoidStudio.VRoidXYTool.cfg
`A:` F11 or edit hotkey in BepInEx/config/me.xiaoye97.plugin.VRoidStudio.VRoidXYTool.cfg, `Hotkey = You want key`

`Q:` How can I contact you?

`A:` VRoid QQGroup(684544577), My private QQGroup (528385469), discord xiaoye#3171(Slow reply), Twitter @xiaoye1997 (Slow reply)

`Q:` The UI language is Chinese, how to switch to English?

`A:` Edit language in BepInEx/config/me.xiaoye97.plugin.VRoidStudio.VRoidXYTool.cfg, `Language = English`

[1]: https://github.com/BepInEx/BepInEx/releases
[2]: https://www.bilibili.com/video/BV1TP4y1V7Qn/
Expand Down
151 changes: 150 additions & 1 deletion VRoidXYTool/CameraTool.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using BepInEx;
using System.Linq;
using UnityEngine;
using VRoid.UI.Component;
using BepInEx.Configuration;
using System.Collections.Generic;

namespace VRoidXYTool
{
Expand Down Expand Up @@ -54,6 +56,16 @@ public Camera MainCamera
/// </summary>
public ConfigEntry<int> AntiAliasingLevel;

/// <summary>
/// 镜头预设数据
/// </summary>
public CameraPosPresetData CameraPosPresetData;

/// <summary>
/// 镜头预设数据的保存路径
/// </summary>
public string CameraPosPresetPath;

public CameraTool()
{
AntiAliasing = XYTool.Inst.Config.Bind<bool>("CameraTool", "AntiAliasing", true, "AntiAliasing".Translate());
Expand All @@ -62,6 +74,8 @@ public CameraTool()
{
AntiAliasingLevel.Value = 8;
}
CameraPosPresetPath = $"{Paths.ConfigPath}/VRoidXYToolCameraPosPreset.json";
LoadPreset();
}

public void Update()
Expand All @@ -82,19 +96,24 @@ public void Update()

public void OnGUI()
{
GUI.contentColor = XYTool.HeadColor;
GUILayout.BeginVertical("CameraTool".Translate(), GUI.skin.window);
GUI.contentColor = Color.white;
try
{
if (MRTcamera == null || MainCamera == null)
{
// 没找到相机
GUILayout.Label("CameraNotFound".Translate());
}
else
{
// 正交
if (MainCamera.orthographic)
{
OrthoGUI();
}
// 透视
else
{
NormalGUI();
Expand Down Expand Up @@ -124,6 +143,7 @@ public void NormalGUI()
MainCamera.orthographic = true;
}
GUILayout.BeginHorizontal();
// 身体位置预设
GUILayout.BeginHorizontal("CameraPosBody".Translate(), GUI.skin.window);
if (GUILayout.Button("DirFront".Translate()))
{
Expand All @@ -142,6 +162,7 @@ public void NormalGUI()
SetCameraPos(GetAroundPos(PosHelper.GetHipsPos(), 4)[3], GetAroundAngles()[3]);
}
GUILayout.EndHorizontal();
// 头部位置预设
GUILayout.BeginHorizontal("CameraPosHead".Translate(), GUI.skin.window);
if (GUILayout.Button("DirFront".Translate()))
{
Expand All @@ -161,14 +182,53 @@ public void NormalGUI()
}
GUILayout.EndHorizontal();
GUILayout.EndHorizontal();
// 自定义预设
GUILayout.BeginHorizontal("PerspectiveCameraPosPreset".Translate(), GUI.skin.window);
for (int i = 0; i < CameraPosPresetData.PresetCount; i++)
{
GUILayout.BeginVertical();
var posData = CameraPosPresetData.PerspectiveCameraPosPresets[i];
if (posData == null)
{
GUI.contentColor = Color.gray;
if (GUILayout.Button($"{i}"))
{
}
GUI.contentColor = Color.white;
if (GUILayout.Button($"Save".Translate()))
{
PerspectiveCameraPosPreset preset = new PerspectiveCameraPosPreset();
preset.Pos = V3.Parse(MRTcamera.transform.position);
preset.Rot = V3.Parse(MRTcamera.transform.localEulerAngles);
CameraPosPresetData.PerspectiveCameraPosPresets[i] = preset;
SavePreset();
}
}
else
{
GUI.contentColor = Color.green;
if (GUILayout.Button($"{i}"))
{
SetCameraPos(posData.Pos.ToVector3(), posData.Rot.ToVector3());
}
GUI.contentColor = Color.white;
if (GUILayout.Button($"Clear".Translate()))
{
CameraPosPresetData.PerspectiveCameraPosPresets[i] = null;
SavePreset();
}
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
}

/// <summary>
/// 正交模式下GUI
/// </summary>
public void OrthoGUI()
{
if (GUILayout.Button("SetCaneraPerspective".Translate()))
if (GUILayout.Button("SetCameraPerspective".Translate()))
{
MainCamera.orthographic = false;
}
Expand Down Expand Up @@ -229,6 +289,47 @@ public void OrthoGUI()
}
GUILayout.EndHorizontal();
GUILayout.EndHorizontal();
// 自定义预设
GUILayout.BeginHorizontal("OrthographicCameraPosPreset".Translate(), GUI.skin.window);
for (int i = 0; i < CameraPosPresetData.PresetCount; i++)
{
GUILayout.BeginVertical();
var posData = CameraPosPresetData.OrthographicCameraPosPresets[i];
if (posData == null)
{
GUI.contentColor = Color.gray;
if (GUILayout.Button($"{i}"))
{
}
GUI.contentColor = Color.white;
if (GUILayout.Button($"Save".Translate()))
{
OrthographicCameraPosPreset preset = new OrthographicCameraPosPreset();
preset.Pos = V3.Parse(MRTcamera.transform.position);
preset.Rot = V3.Parse(MRTcamera.transform.localEulerAngles);
preset.OrthographicSize = MainCamera.orthographicSize;
CameraPosPresetData.OrthographicCameraPosPresets[i] = preset;
SavePreset();
}
}
else
{
GUI.contentColor = Color.green;
if (GUILayout.Button($"{i}"))
{
SetCameraPos(posData.Pos.ToVector3(), posData.Rot.ToVector3());
MainCamera.orthographicSize = posData.OrthographicSize;
}
GUI.contentColor = Color.white;
if (GUILayout.Button($"Clear".Translate()))
{
CameraPosPresetData.OrthographicCameraPosPresets[i] = null;
SavePreset();
}
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
}

/// <summary>
Expand Down Expand Up @@ -262,5 +363,53 @@ public static Vector3[] GetAroundAngles()
result[3] = new Vector3(0, 270, 0);
return result;
}

/// <summary>
/// 加载镜头预设
/// </summary>
public void LoadPreset()
{
CameraPosPresetData = FileHelper.LoadJson<CameraPosPresetData>(CameraPosPresetPath);
if (CameraPosPresetData == null)
{
CameraPosPresetData = new CameraPosPresetData();
CameraPosPresetData.PerspectiveCameraPosPresets = new PerspectiveCameraPosPreset[CameraPosPresetData.PresetCount];
CameraPosPresetData.OrthographicCameraPosPresets = new OrthographicCameraPosPreset[CameraPosPresetData.PresetCount];
}
}

/// <summary>
/// 保存镜头预设
/// </summary>
public void SavePreset()
{
FileHelper.SaveJson(CameraPosPresetPath, CameraPosPresetData);
}
}

[Serializable]
/// <summary>
/// 相机位置预设数据
/// </summary>
public class CameraPosPresetData
{
public static int PresetCount = 10;
public PerspectiveCameraPosPreset[] PerspectiveCameraPosPresets;
public OrthographicCameraPosPreset[] OrthographicCameraPosPresets;
}

[Serializable]
public class PerspectiveCameraPosPreset
{
public V3 Pos;
public V3 Rot;
}

[Serializable]
public class OrthographicCameraPosPreset
{
public V3 Pos;
public V3 Rot;
public float OrthographicSize;
}
}
15 changes: 11 additions & 4 deletions VRoidXYTool/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ public static T LoadJson<T>(string path) where T : class
{
try
{
var jsonStr = File.ReadAllText(path);
T result = JsonConvert.DeserializeObject<T>(jsonStr);
return result;
if (File.Exists(path))
{
var jsonStr = File.ReadAllText(path);
T result = JsonConvert.DeserializeObject<T>(jsonStr);
return result;
}
else
{
return null;
}
}
catch (Exception e)
{
Expand All @@ -99,7 +106,7 @@ public static void SaveJson<T>(string path, T data)
}
catch (Exception e)
{
Debug.LogError($"读取Json时出现异常:\n{e.Message}\n{e.StackTrace}");
Debug.LogError($"保存Json时出现异常:\n{e.Message}\n{e.StackTrace}");
}
}

Expand Down
2 changes: 2 additions & 0 deletions VRoidXYTool/GuideTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public void OnGUI()
}
needRemoveObjects.Clear();
}
GUI.contentColor = XYTool.HeadColor;
GUILayout.BeginVertical("GuideTool".Translate(), GUI.skin.window);
GUI.contentColor = Color.white;
try
{
GridBoxGUI();
Expand Down
6 changes: 4 additions & 2 deletions VRoidXYTool/LinkTextureTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public LinkTextureTool()

public void OnGUI()
{
GUI.contentColor = XYTool.HeadColor;
GUILayout.BeginVertical("LinkTextureTool".Translate(), GUI.skin.window);
GUI.contentColor = UnityEngine.Color.white;
try
{
// 显示链接文件夹
Expand Down Expand Up @@ -137,7 +139,7 @@ public void OnGUI()
}
if (LinkTextures.Count > 0)
{
svPos = GUILayout.BeginScrollView(svPos, GUI.skin.box, GUILayout.MaxHeight(200));
//svPos = GUILayout.BeginScrollView(svPos, GUI.skin.box, GUILayout.MaxHeight(200));

for (int i = 0; i < LinkTextures.Count; i++)
{
Expand Down Expand Up @@ -178,7 +180,7 @@ public void OnGUI()
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView();
//GUILayout.EndScrollView();
}
else
{
Expand Down
8 changes: 6 additions & 2 deletions VRoidXYTool/PluginI18N/ChineseSimplified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ IsShow=显示
AntiAliasingLevelDesc=抗锯齿级别 值为 2,4,8
CameraNotFound=目标相机不存在
SetCameraOrthographic=设置相机为正交模式
SetCaneraPerspective=设置相机为透视模式
SetCameraPerspective=设置相机为透视模式
OrthographicSize=正交尺寸
CameraPosBody=相机位置(全身)
CameraPosHead=相机位置(头部)
DirFront=前
DirBack=后
DirLeft=左
DirRight=右
PerspectiveCameraPosPreset=透视相机位置预设
OrthographicCameraPosPreset=正交相机位置预设

// 其他
Image=图片
Image=图片
Save=保存
Clear=清除
Loading

0 comments on commit 100a409

Please sign in to comment.