This commit is contained in:
左右看
2023-07-30 00:38:21 +08:00
11 changed files with 2054 additions and 146 deletions
@@ -19,6 +19,7 @@ public class UnityCameraVMDRecorder : MonoBehaviour
public int KeyReductionLevel = 2;
public List<Vector3> LocalPositions { get; private set; } = new List<Vector3>();
public List<Vector3> LocalRotations { get; private set; } = new List<Vector3>();
public bool IsRecording { get; private set; } = false;
public int FrameNumber { get; private set; } = 0;
@@ -136,12 +137,12 @@ public class UnityCameraVMDRecorder : MonoBehaviour
LastRotation = vmdRotation;
}
Vector3 DeltaVector(Vector3 val ,Vector3 lastVal)
public static Vector3 DeltaVector(Vector3 val ,Vector3 lastVal)
{
return new Vector3(DeltaDegree(val.x, lastVal.x), DeltaDegree(val.y, lastVal.y), DeltaDegree(val.z, lastVal.z));
}
float DeltaDegree(float val,float lastVal)
public static float DeltaDegree(float val,float lastVal)
{
var deltaVal = val - lastVal;
if (Mathf.Abs(deltaVal) < 180)
@@ -323,6 +324,206 @@ public class UnityCameraVMDRecorder : MonoBehaviour
Destroy(this);
}
public static void SaveLiveCameraVMD(List<LiveCameraFrame> frames)
{
string directory = $"{Application.dataPath}/../VMDRecords/";
Directory.CreateDirectory(directory);
var time = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
string fileName = $"{directory}LiveCamera_POS_{time}.vmd";
string fovFileName = $"{directory}LiveCamera_FOV_{time}.vmd";
const string modelName = "カメラ・照明";
Debug.Log("Live Camera VMDファイル作成開始");
//ファイルの書き込み
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
{
try
{
const string ShiftJIS = "shift_jis";
const int intByteLength = 4;
//ファイルタイプの書き込み
const int fileTypeLength = 30;
const string RightFileType = "Vocaloid Motion Data 0002";
byte[] fileTypeBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(RightFileType);
binaryWriter.Write(fileTypeBytes, 0, fileTypeBytes.Length);
binaryWriter.Write(new byte[fileTypeLength - fileTypeBytes.Length], 0, fileTypeLength - fileTypeBytes.Length);
//モーション名の書き込み、Shift_JISで保存
const int motionNameLength = 20;
byte[] motionNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("CameraAttach to 全ての親");
binaryWriter.Write(motionNameBytes, 0, Mathf.Min(motionNameBytes.Length, 20));
if (motionNameLength - motionNameBytes.Length > 0)
{
binaryWriter.Write(new byte[motionNameLength - motionNameBytes.Length], 0, motionNameLength - motionNameBytes.Length);
}
//全ボーンフレーム数の書き込み
byte[] allKeyFrameNumberByte = BitConverter.GetBytes((uint)frames.Count);
binaryWriter.Write(allKeyFrameNumberByte, 0, intByteLength);
foreach (var frame in frames)
{
const int boneNameLength = 15;
string boneNameString = "全ての親";
byte[] boneNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(boneNameString);
binaryWriter.Write(boneNameBytes, 0, boneNameBytes.Length);
binaryWriter.Write(new byte[boneNameLength - boneNameBytes.Length], 0, boneNameLength - boneNameBytes.Length);
byte[] frameNumberByte = BitConverter.GetBytes((ulong)(frame.frameIndex/2));
binaryWriter.Write(frameNumberByte, 0, intByteLength);
Vector3 position = frame.Position * WorldScaleFix;
byte[] positionX = BitConverter.GetBytes(position.x);
binaryWriter.Write(positionX, 0, intByteLength);
byte[] positionY = BitConverter.GetBytes(position.y);
binaryWriter.Write(positionY, 0, intByteLength);
byte[] positionZ = BitConverter.GetBytes(position.z);
binaryWriter.Write(positionZ, 0, intByteLength);
Quaternion rotation = frame.Rotation;
byte[] rotationX = BitConverter.GetBytes(rotation.x);
binaryWriter.Write(rotationX, 0, intByteLength);
byte[] rotationY = BitConverter.GetBytes(rotation.y);
binaryWriter.Write(rotationY, 0, intByteLength);
byte[] rotationZ = BitConverter.GetBytes(rotation.z);
binaryWriter.Write(rotationZ, 0, intByteLength);
byte[] rotationW = BitConverter.GetBytes(rotation.w);
binaryWriter.Write(rotationW, 0, intByteLength);
byte[] interpolateBytes = new byte[64];
binaryWriter.Write(interpolateBytes, 0, 64);
}
//全モーフフレーム数の書き込み
byte[] faceFrameCount = BitConverter.GetBytes(0);
binaryWriter.Write(faceFrameCount, 0, intByteLength);
//カメラの書き込み
byte[] cameraFrameCount = BitConverter.GetBytes(0);
binaryWriter.Write(cameraFrameCount, 0, intByteLength);
//照明の書き込み
byte[] lightFrameCount = BitConverter.GetBytes(0);
binaryWriter.Write(lightFrameCount, 0, intByteLength);
//セルフシャドウの書き込み
byte[] selfShadowCount = BitConverter.GetBytes(0);
binaryWriter.Write(selfShadowCount, 0, intByteLength);
//IKの書き込み
byte[] ikCount = BitConverter.GetBytes(0);
binaryWriter.Write(ikCount, 0, intByteLength);
}
catch (Exception ex)
{
Debug.Log("VMD書き込みエラー" + ex.Message);
}
finally
{
binaryWriter.Close();
}
}
using (FileStream fileStream = new FileStream(fovFileName, FileMode.Create))
using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
{
try
{
const string ShiftJIS = "shift_jis";
const int intByteLength = 4;
//ファイルタイプの書き込み
const int fileTypeLength = 30;
const string RightFileType = "Vocaloid Motion Data 0002";
byte[] fileTypeBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(RightFileType);
binaryWriter.Write(fileTypeBytes, 0, fileTypeBytes.Length);
binaryWriter.Write(new byte[fileTypeLength - fileTypeBytes.Length], 0, fileTypeLength - fileTypeBytes.Length);
//モーション名の書き込み、Shift_JISで保存
const int motionNameLength = 20;
byte[] motionNameBytes = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes(modelName);
binaryWriter.Write(motionNameBytes, 0, Mathf.Min(motionNameBytes.Length, 20));
if (motionNameLength - motionNameBytes.Length > 0)
{
binaryWriter.Write(new byte[motionNameLength - motionNameBytes.Length], 0, motionNameLength - motionNameBytes.Length);
}
//全ボーンフレーム数の書き込み
byte[] allKeyFrameNumberByte = BitConverter.GetBytes(0);
binaryWriter.Write(allKeyFrameNumberByte, 0, intByteLength);
//全モーフフレーム数の書き込み
byte[] faceFrameCount = BitConverter.GetBytes(0);
binaryWriter.Write(faceFrameCount, 0, intByteLength);
var fovkeys = frames.FindAll(k => k.FovVaild);
//カメラの書き込み
byte[] cameraFrameCount = BitConverter.GetBytes((uint)fovkeys.Count);
binaryWriter.Write(cameraFrameCount, 0, intByteLength);
foreach (var frame in fovkeys)
{
byte[] frameNumberByte = BitConverter.GetBytes((ulong)frame.frameIndex/2);
binaryWriter.Write(frameNumberByte, 0, intByteLength);
byte[] cameraDistanceByte = BitConverter.GetBytes(0);
binaryWriter.Write(cameraDistanceByte, 0, intByteLength);
Vector3 position = Vector3.zero;
byte[] positionX = BitConverter.GetBytes(position.x);
binaryWriter.Write(positionX, 0, intByteLength);
byte[] positionY = BitConverter.GetBytes(position.y);
binaryWriter.Write(positionY, 0, intByteLength);
byte[] positionZ = BitConverter.GetBytes(position.z);
binaryWriter.Write(positionZ, 0, intByteLength);
Vector3 rotation = new Vector3(0,180,0) * Mathf.Deg2Rad;
byte[] rotationX = BitConverter.GetBytes(rotation.x);
binaryWriter.Write(rotationX, 0, intByteLength);
byte[] rotationY = BitConverter.GetBytes(rotation.y);
binaryWriter.Write(rotationY, 0, intByteLength);
byte[] rotationZ = BitConverter.GetBytes(rotation.z);
binaryWriter.Write(rotationZ, 0, intByteLength);
byte[] interpolateBytes = new byte[24];
binaryWriter.Write(interpolateBytes, 0, 24);
byte[] viewAngleByte = BitConverter.GetBytes((ulong)frame.Fov);
binaryWriter.Write(viewAngleByte, 0, intByteLength);
byte perspectiveByte = Convert.ToByte(frame.isOrthographic);
byte[] perspectiveBytes = new byte[] { perspectiveByte };
binaryWriter.Write(new byte[] { perspectiveByte }, 0, perspectiveBytes.Length);
}
//照明の書き込み
byte[] lightFrameCount = BitConverter.GetBytes(0);
binaryWriter.Write(lightFrameCount, 0, intByteLength);
//セルフシャドウの書き込み
byte[] selfShadowCount = BitConverter.GetBytes(0);
binaryWriter.Write(selfShadowCount, 0, intByteLength);
//IKの書き込み
byte[] ikCount = BitConverter.GetBytes(0);
binaryWriter.Write(ikCount, 0, intByteLength);
}
catch (Exception ex)
{
Debug.Log("FOV VMD書き込みエラー" + ex.Message);
}
finally
{
binaryWriter.Close();
}
}
}
/// <summary>
/// VMDを作成する
/// 呼び出す際は先にStopRecordingを呼び出すこと
@@ -334,4 +535,45 @@ public class UnityCameraVMDRecorder : MonoBehaviour
KeyReductionLevel = keyReductionLevel;
SaveVMD();
}
}
public class LiveCameraFrame
{
public int frameIndex;
public Vector3 Position;
public Quaternion Rotation;
public Vector3 CameraRotation;
public float Fov;
public bool FovVaild;
public bool isOrthographic;
public LiveCameraFrame(int frameIndex, Transform transform, float fov, LiveCameraFrame lastframe = null, bool isOrthographic = false)
{
this.frameIndex = frameIndex;
var fixedPosition = transform.position;
var vmdPosition = new Vector3(-fixedPosition.x, fixedPosition.y, -fixedPosition.z);
Position = vmdPosition;
var fixedQuatenion = transform.rotation;
var vmdQuatenion = new Quaternion(-fixedQuatenion.x, fixedQuatenion.y, -fixedQuatenion.z, fixedQuatenion.w);
Rotation = vmdQuatenion;
Vector3 vmdRotation = new Vector3(fixedQuatenion.eulerAngles.x, 180 - fixedQuatenion.eulerAngles.y, fixedQuatenion.eulerAngles.z);
var finalRotation = vmdRotation;
if (lastframe == null)
{
finalRotation = vmdRotation;
}
else
{
finalRotation = lastframe.CameraRotation + UnityCameraVMDRecorder.DeltaVector(vmdRotation, lastframe.CameraRotation);
}
CameraRotation = finalRotation;
Fov = fov;
this.isOrthographic = isOrthographic;
}
}
@@ -54,6 +54,7 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
Dictionary<BoneNames, List<Vector3>> positionDictionarySaved = new Dictionary<BoneNames, List<Vector3>>();
Dictionary<BoneNames, List<Quaternion>> rotationDictionary = new Dictionary<BoneNames, List<Quaternion>>();
Dictionary<BoneNames, List<Quaternion>> rotationDictionarySaved = new Dictionary<BoneNames, List<Quaternion>>();
Dictionary<int, bool> visitableDictionary = new Dictionary<int, bool>();
//ボーン移動量の補正係数
//この値は大体の値、正確ではない
const float DefaultBoneAmplifier = 12.5f;
@@ -66,10 +67,12 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
public MorphRecorder morphRecorder;
public MorphRecorder morphRecorderSaved;
private UmaContainer container;
float aposeDegress = 38.5f;
public void Initialize()
{
Time.fixedDeltaTime = FPSs;
container = GetComponentInParent<UmaContainer>();
List<Transform> objs = GetComponentsInChildren<Transform>().ToList();
BoneDictionary = new Dictionary<BoneNames, Transform>()
{
@@ -167,8 +170,6 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
animator.Play(state.shortNameHash, 0, state.normalizedTime);
}
private void FixedUpdate()
{
if (IsRecording)
@@ -178,11 +179,24 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
}
}
bool lastvisable;
void SaveFrame()
{
if (boneGhost != null) { boneGhost.GhostAll(); }
if (morphRecorder != null) { morphRecorder.RecrodAllMorph(); }
bool visable = container.LiveVisible;
if (visitableDictionary.Count == 0)
{
lastvisable = visable;
visitableDictionary.Add(0, visable);
}
else if(visable != lastvisable)
{
lastvisable = visable;
visitableDictionary.Add(FrameNumber, visable);
}
foreach (BoneNames boneName in BoneDictionary.Keys)
{
if (BoneDictionary[boneName] == null)
@@ -521,34 +535,40 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
//IKの書き込み
//0フレームにキーフレーム一つだけ置く
byte[] ikCount = BitConverter.GetBytes(1);
byte[] ikFrameNumber = BitConverter.GetBytes(0);
byte modelDisplay = Convert.ToByte(1);
//右足IKと左足IKと右足つま先IKと左足つま先IKの4つ
byte[] ikNumber = BitConverter.GetBytes(4);
const int IKNameLength = 20;
byte[] leftIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左足IK");
byte[] rightIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右足IK");
byte[] leftToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左つま先IK");
byte[] rightToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右つま先IK");
byte ikOn = Convert.ToByte(1);
byte ikOff = Convert.ToByte(0);
byte[] ikCount = BitConverter.GetBytes(visitableDictionary.Count);
binaryWriter.Write(ikCount, 0, intByteLength);
binaryWriter.Write(ikFrameNumber, 0, intByteLength);
binaryWriter.Write(modelDisplay);
binaryWriter.Write(ikNumber, 0, intByteLength);
binaryWriter.Write(leftIKName, 0, leftIKName.Length);
binaryWriter.Write(new byte[IKNameLength - leftIKName.Length], 0, IKNameLength - leftIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(leftToeIKName, 0, leftToeIKName.Length);
binaryWriter.Write(new byte[IKNameLength - leftToeIKName.Length], 0, IKNameLength - leftToeIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(rightIKName, 0, rightIKName.Length);
binaryWriter.Write(new byte[IKNameLength - rightIKName.Length], 0, IKNameLength - rightIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(rightToeIKName, 0, rightToeIKName.Length);
binaryWriter.Write(new byte[IKNameLength - rightToeIKName.Length], 0, IKNameLength - rightToeIKName.Length);
binaryWriter.Write(ikOff);
foreach(var visable in visitableDictionary)
{
byte[] ikFrameNumber = BitConverter.GetBytes(visable.Key);
byte modelDisplay = Convert.ToByte(visable.Value ? 1 : 0);
binaryWriter.Write(ikFrameNumber, 0, intByteLength);
binaryWriter.Write(modelDisplay);
//右足IKと左足IKと右足つま先IKと左足つま先IKの4つ
byte[] ikNumber = BitConverter.GetBytes(4);
const int IKNameLength = 20;
byte[] leftIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左足IK");
byte[] rightIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右足IK");
byte[] leftToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("左つま先IK");
byte[] rightToeIKName = System.Text.Encoding.GetEncoding(ShiftJIS).GetBytes("右つま先IK");
byte ikOn = Convert.ToByte(1);
byte ikOff = Convert.ToByte(0);
binaryWriter.Write(ikNumber, 0, intByteLength);
binaryWriter.Write(leftIKName, 0, leftIKName.Length);
binaryWriter.Write(new byte[IKNameLength - leftIKName.Length], 0, IKNameLength - leftIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(leftToeIKName, 0, leftToeIKName.Length);
binaryWriter.Write(new byte[IKNameLength - leftToeIKName.Length], 0, IKNameLength - leftToeIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(rightIKName, 0, rightIKName.Length);
binaryWriter.Write(new byte[IKNameLength - rightIKName.Length], 0, IKNameLength - rightIKName.Length);
binaryWriter.Write(ikOff);
binaryWriter.Write(rightToeIKName, 0, rightToeIKName.Length);
binaryWriter.Write(new byte[IKNameLength - rightToeIKName.Length], 0, IKNameLength - rightToeIKName.Length);
binaryWriter.Write(ikOff);
}
}
catch (Exception ex)
{
@@ -577,6 +597,14 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
SaveVMD(modelName, fileName);
}
public void SaveLiveVMD(string modelName, int keyReductionLevel = 3)
{
string fileName = Application.dataPath + "/../VMDRecords/" + string.Format("{0}_{1}.vmd", modelName, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
Directory.CreateDirectory(Application.dataPath + "/../VMDRecords");
KeyReductionLevel = keyReductionLevel;
SaveVMD(modelName, fileName);
}
//裏で正規化されたモデル
//(初期ポーズで各ボーンのlocalRotationがQuaternion.identityのモデル)を疑似的にアニメーションさせる
class BoneGhost
@@ -12,6 +12,8 @@ public class LiveViewerUI : MonoBehaviour
public RectTransform BottonUITransform;
public Dropdown FrameRateDropDown;
float targetHeight = 0;
float height;
private void Awake()
@@ -45,4 +47,9 @@ public class LiveViewerUI : MonoBehaviour
{
targetHeight = -height;
}
public void SetFrameRate(int fps)
{
Application.targetFrameRate = int.Parse(FrameRateDropDown.options[fps].text);
}
}
+1
View File
@@ -82,6 +82,7 @@ public class UmaContainer : MonoBehaviour
[Header("Live")]
public bool IsLive = false;
public bool LiveVisible = true;
public LiveTimelineCharaLocator LiveLocator;
[Header("Other")]
+1 -1
View File
@@ -22,7 +22,7 @@ public class UmaViewerAudio
static public UmaSoundInfo getSoundPath(string name)
{
Debug.Log(name);
//Debug.Log(name);
UmaSoundInfo info;
info.awb = Main.AbSounds.FirstOrDefault(a => a.Name.Contains(name) && a.Name.EndsWith("awb"));
return info;
+12 -11
View File
@@ -662,25 +662,26 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadLive(LiveEntry live, List<LiveCharacterSelect> characters)
{
GameObject MainLive = Instantiate(LiveControllerPrefab);
Gallop.Live.Director mController = MainLive.GetComponentInChildren<Gallop.Live.Director>();
mController.live = live;
mController.Initialize();
UmaSceneController.LoadScene("LiveScene",
delegate ()
{
GameObject MainLive = Instantiate(LiveControllerPrefab);
Gallop.Live.Director mController = MainLive.GetComponentInChildren<Gallop.Live.Director>();
mController.live = live;
mController.IsRecordVMD = UI.isRecordVMD;
List<GameObject> transferObjs = new List<GameObject>() {
List<GameObject> transferObjs = new List<GameObject>() {
MainLive,
GameObject.Find("ViewerMain"),
GameObject.Find("Directional Light"),
GameObject.Find("GlobalShaderController"),
GameObject.Find("AudioManager")
};
};
UmaSceneController.LoadScene("LiveScene",
delegate ()
{
// Move the GameObject (you attach this in the Inspector) to the newly loaded Scene
transferObjs.ForEach(o => SceneManager.MoveGameObjectToScene(o, SceneManager.GetSceneByName("LiveScene")));
mController.Initialize();
characters.ForEach(a =>
{
@@ -847,7 +848,7 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false, Transform SetParent = null)
{
Debug.Log("Loading " + entry.Name);
//Debug.Log("Loading " + entry.Name);
var bundle = UmaAssetManager.LoadAssetBundle(entry, isRecursive: false);
LoadBundle(entry, bundle, IsSubAsset, SetParent);
}
+65 -62
View File
@@ -10,7 +10,6 @@ using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Debug = UnityEngine.Debug;
public class UmaViewerUI : MonoBehaviour
{
@@ -135,8 +134,9 @@ public class UmaViewerUI : MonoBehaviour
[Header("Live")]
public bool LiveTime = false;
public Dropdown LiveDropdown;
public int LiveMode = 0;
public bool isRecordVMD;
public Dropdown LiveRecoedToggle;
public int LiveMode = 1;
public FaceDrivenKeyTarget currentFaceDrivenKeyTarget;
@@ -168,65 +168,6 @@ public class UmaViewerUI : MonoBehaviour
private void Update()
{
if (LiveMode != LiveDropdown.value)
{
LiveMode = LiveDropdown.value;
if (LiveSelectPannel.activeSelf && currentLive != null)
{
foreach (var select in LiveSelectList.content.GetComponentsInChildren<Transform>())
{
if(select != LiveSelectList.content.transform)
{
Destroy(select.gameObject);
}
}
switch (LiveMode)
{
case 0:
LiveSelectImage.sprite = currentLive.Icon;
int mainCount = 0;
foreach (var motion in Main.AbMotions.Where(a => a.Name.StartsWith($"3d/motion/live/body/son{currentLive.MusicId}") && Path.GetFileName(a.Name).Split('_').Length == 4))
{
mainCount += 1;
}
LiveSelectInfoText.text = $"{currentLive.SongName}\nMain Members Count: {mainCount}";
for (int i = 0; i < mainCount; i++)
{
var chara = Instantiate(LiveSelectPrefab, LiveSelectList.content).GetComponent<LiveCharacterSelect>();
chara.IndexText.text = (i + 1).ToString();
chara.GetComponent<Button>().onClick.AddListener(() =>
{
chara.SelectChara(this);
foreach (var t in LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>())
{
t.GetComponentInChildren<Text>().color = (t == chara ? Color.white : Color.black);
}
});
}
break;
case 1:
LiveSelectImage.sprite = currentLive.Icon;
LiveSelectInfoText.text = $"{currentLive.SongName}\nMembers Count: {currentLive.MemberCount}";
for (int i = 0; i < currentLive.MemberCount; i++)
{
var chara = Instantiate(LiveSelectPrefab, LiveSelectList.content).GetComponent<LiveCharacterSelect>();
chara.IndexText.text = (i + 1).ToString();
chara.GetComponent<Button>().onClick.AddListener(() =>
{
chara.SelectChara(this);
foreach (var t in LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>())
{
t.GetComponentInChildren<Text>().color = (t == chara ? Color.white : Color.black);
}
});
}
break;
}
}
}
if (Builder.CurrentAudioSources.Count > 0)
{
@@ -1366,6 +1307,66 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void UpdateLiveMode(int val)
{
LiveMode = val;
if (LiveSelectPannel.activeSelf && currentLive != null)
{
foreach (var select in LiveSelectList.content.GetComponentsInChildren<Transform>())
{
if (select != LiveSelectList.content.transform)
{
Destroy(select.gameObject);
}
}
switch (LiveMode)
{
case 0:
LiveSelectImage.sprite = currentLive.Icon;
int mainCount = 0;
foreach (var motion in Main.AbMotions.Where(a => a.Name.StartsWith($"3d/motion/live/body/son{currentLive.MusicId}") && Path.GetFileName(a.Name).Split('_').Length == 4))
{
mainCount += 1;
}
LiveSelectInfoText.text = $"{currentLive.SongName}\nMain Members Count: {mainCount}";
for (int i = 0; i < mainCount; i++)
{
var chara = Instantiate(LiveSelectPrefab, LiveSelectList.content).GetComponent<LiveCharacterSelect>();
chara.IndexText.text = (i + 1).ToString();
chara.GetComponent<Button>().onClick.AddListener(() =>
{
chara.SelectChara(this);
foreach (var t in LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>())
{
t.GetComponentInChildren<Text>().color = (t == chara ? Color.white : Color.black);
}
});
}
break;
case 1:
LiveSelectImage.sprite = currentLive.Icon;
LiveSelectInfoText.text = $"{currentLive.SongName}\nMembers Count: {currentLive.MemberCount}";
for (int i = 0; i < currentLive.MemberCount; i++)
{
var chara = Instantiate(LiveSelectPrefab, LiveSelectList.content).GetComponent<LiveCharacterSelect>();
chara.IndexText.text = (i + 1).ToString();
chara.GetComponent<Button>().onClick.AddListener(() =>
{
chara.SelectChara(this);
foreach (var t in LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>())
{
t.GetComponentInChildren<Text>().color = (t == chara ? Color.white : Color.black);
}
});
}
break;
}
}
}
public void UpdateGameDB()
{
if (UpdateResVerCoroutine != null && Config.Instance.WorkMode != WorkMode.Standalone) return;
@@ -1411,6 +1412,8 @@ public class UmaViewerUI : MonoBehaviour
Shader.SetGlobalFloat("_GlobalOutlineWidth", val);
}
public void SetLiveRecordMode(bool val) { isRecordVMD = val; }
public void ShowMessage(string msg, UIMessageType type)
{
MessageText.text += type switch
@@ -97,6 +97,9 @@ namespace Gallop.Live.Cutt
private bool _isExtraCameraLayer;
public bool IsRecordVMD;
public List<LiveCameraFrame> RecordFrames = new List<LiveCameraFrame>();
public float currentLiveTime
{
get
@@ -216,6 +219,7 @@ namespace Gallop.Live.Cutt
if (Director.instance)
{
Director.instance._liveTimelineControl = this;
IsRecordVMD = Director.instance.IsRecordVMD;
}
}
@@ -323,6 +327,21 @@ namespace Gallop.Live.Cutt
AlterUpdate_CameraFov(workSheet, _currentFrame);
AlterUpdate_CameraRoll(workSheet, _currentFrame);
_isNowAlterUpdate = false;
if (IsRecordVMD)
{
var currentFrame = Mathf.RoundToInt(_currentFrame);
var oldFrame = Mathf.RoundToInt(_oldFrame);
CacheCamera cacheCamera = GetCamera(workSheet.targetCameraIndex);
if ((oldFrame == currentFrame && currentFrame > 0)|| cacheCamera == null) return;
LiveCameraFrame lastframe = RecordFrames.Count > 0 ? RecordFrames[RecordFrames.Count - 1] : null;
var transform = cacheCamera.cacheTransform;
var camera = cacheCamera.camera;
LiveCameraFrame frame = new LiveCameraFrame(currentFrame, transform, camera.fieldOfView, lastframe);
RecordFrames.Add(frame);
}
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
@@ -527,16 +546,21 @@ namespace Gallop.Live.Cutt
var chara = Director.instance.CharaContainerScript[targetIndex];
if (!chara) return;
chara.Materials.ForEach(m=>
{
foreach(var key in m.Renderers.Keys)
if(chara.LiveVisible != curKey.visible)
{
chara.Materials.ForEach(m =>
{
foreach (var key in m.Renderers.Keys)
{
key.gameObject.SetActive(curKey.visible);
if (key.gameObject.activeSelf != curKey.visible)
key.gameObject.SetActive(curKey.visible);
}
}
);
});
chara.LiveVisible = curKey.visible;
}
if (curKey.visible)
if (curKey.visible || IsRecordVMD)
{
if(nextKey != null && nextKey.interpolateType != LiveCameraInterpolateType.None)
{
@@ -259,7 +259,6 @@ namespace Gallop.Live
public static Director instance => _instance;
public static bool HasInstance { get; }
public LiveTimelineControl LiveTimelineControl { get; }
public Director.DisplayMode displayMode { get; set; }
public bool IsStarted { get; }
public bool IsFinished { get; set; }
@@ -347,6 +346,8 @@ namespace Gallop.Live
public SliderControl sliderControl;
public bool IsRecordVMD;
public bool isTimelineControlled
{
get
@@ -589,6 +590,22 @@ namespace Gallop.Live
_isLiveSetup = true;
_liveCurrentTime = 0;
if (IsRecordVMD)
{
foreach(var container in CharaContainerScript)
{
var rootbone = container.transform.Find("Position");
var newRecorder = rootbone.gameObject.AddComponent<UnityHumanoidVMDRecorder>();
newRecorder.UseParentOfAll = true;
newRecorder.UseAbsoluteCoordinateSystem = true;
newRecorder.Initialize();
if (!newRecorder.IsRecording)
{
newRecorder.StartRecording();
}
}
}
}
private void OnTimelineUpdate(float _liveCurrentTime)
@@ -604,18 +621,15 @@ namespace Gallop.Live
void Update()
{
if (isExit) return;
if (Input.GetKeyDown(KeyCode.Escape))
{
isExit = true;
UmaSceneController.LoadScene("Version2");
UmaAssetManager.UnloadAllBundle(true);
}
if (_isLiveSetup)
{
if(_syncTime == false)
if (Input.GetKeyDown(KeyCode.Escape) || _liveCurrentTime >= totalTime)
{
ExitLive();
}
if (_syncTime == false)
{
if (liveMusic.sourceList[0].time > 0.01)
{
@@ -672,9 +686,7 @@ namespace Gallop.Live
{
_liveCurrentTime += Time.deltaTime;
UI.ProgressBar.value = _liveCurrentTime / totalTime;
//Debug.Log((float)liveMusic.time / 1000);
Debug.Log(_liveCurrentTime * 60);
UI.ProgressBar.SetValueWithoutNotify(_liveCurrentTime / totalTime);
OnTimelineUpdate(_liveCurrentTime);
}
}
@@ -686,6 +698,43 @@ namespace Gallop.Live
{
_liveTimelineControl.AlterLateUpdate();
}
private void ExitLive()
{
isExit = true;
if (_liveTimelineControl.IsRecordVMD)
{
var frames = _liveTimelineControl.RecordFrames;
frames[0].FovVaild = true;
var fov = _liveTimelineControl.data.worksheetList[0].cameraFovKeys.thisList;
fov.ForEach(k => {
var index = k.frame;
if (index < frames.Count)
{
frames[index].FovVaild = true;
if(index - 1 > 0) frames[index - 1].FovVaild = true;
if(index - 2 > 0) frames[index - 2].FovVaild = true;
}
});
UnityCameraVMDRecorder.SaveLiveCameraVMD(frames);
foreach (var container in CharaContainerScript)
{
var rootbone = container.transform.Find("Position");
if (rootbone.gameObject.TryGetComponent(out UnityHumanoidVMDRecorder recorder))
{
if (recorder.IsRecording)
{
recorder.StopRecording();
recorder.SaveLiveVMD($"Live{live.MusicId}_Pos{CharaContainerScript.IndexOf(container)}", 1);
}
}
}
}
UmaSceneController.LoadScene("Version2");
UmaAssetManager.UnloadAllBundle(true);
}
}
}