bug fix, add Animation continuous play

This commit is contained in:
CroakFang
2022-11-14 14:09:24 +08:00
parent 7e201baa89
commit e103b53480
7 changed files with 107 additions and 46 deletions
+1 -1
View File
@@ -443,7 +443,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: motion_1 m_Name: motion_t
m_Speed: 1 m_Speed: 1
m_CycleOffset: 0 m_CycleOffset: 0
m_Transitions: [] m_Transitions: []
+1 -1
View File
@@ -7,7 +7,7 @@ AnimationClip:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: clip_1 m_Name: clip_1
serializedVersion: 7 serializedVersion: 6
m_Legacy: 0 m_Legacy: 0
m_Compressed: 0 m_Compressed: 0
m_UseHighQualityCurve: 1 m_UseHighQualityCurve: 1
+7 -6
View File
@@ -22268,12 +22268,12 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1174230681} m_GameObject: {fileID: 1174230681}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: -1, z: -2.4000015}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} m_LocalScale: {x: 0.3, y: 0.3, z: 0.3}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 8918259399633999301}
m_RootOrder: 11 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1177175081 --- !u!1 &1177175081
GameObject: GameObject:
@@ -46226,7 +46226,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: 2.4000015} m_LocalPosition: {x: 0, y: 1, z: 2.4000015}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
- {fileID: 1174230685}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+35 -2
View File
@@ -1,6 +1,7 @@
using Gallop; using Gallop;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq;
using UnityEngine; using UnityEngine;
public class UmaContainer : MonoBehaviour public class UmaContainer : MonoBehaviour
@@ -18,6 +19,7 @@ public class UmaContainer : MonoBehaviour
public AnimatorOverrideController OverrideController; public AnimatorOverrideController OverrideController;
public Animator UmaFaceAnimator; public Animator UmaFaceAnimator;
public AnimatorOverrideController FaceOverrideController; public AnimatorOverrideController FaceOverrideController;
public bool isAnimatorControl; public bool isAnimatorControl;
[Header("Face")] [Header("Face")]
@@ -28,6 +30,11 @@ public class UmaContainer : MonoBehaviour
public float EyeHeight; public float EyeHeight;
public bool EnableEyeTracking = true; public bool EnableEyeTracking = true;
[Header("Body")]
public GameObject UpBodyBone;
public Vector3 UpBodyPosition;
public Quaternion UpBodyRotation;
[Header("Cheek")] [Header("Cheek")]
public Texture CheekTex; public Texture CheekTex;
public Material CheekMaterial; public Material CheekMaterial;
@@ -48,11 +55,17 @@ public class UmaContainer : MonoBehaviour
[Header("Shader")] [Header("Shader")]
public Material FaceMaterial; public Material FaceMaterial;
public void Initialize()
{
EyeHeight = 0.1f;
TrackTarget = Camera.main.gameObject;
UpBodyPosition = UpBodyBone.transform.localPosition;
UpBodyRotation = UpBodyBone.transform.localRotation;
}
public void MergeModel() public void MergeModel()
{ {
if (!Body) return; if (!Body) return;
EyeHeight = 0.1f;
TrackTarget = Camera.main.gameObject;
List<Transform> bodybones = new List<Transform>(Body.GetComponentInChildren<SkinnedMeshRenderer>().bones); List<Transform> bodybones = new List<Transform>(Body.GetComponentInChildren<SkinnedMeshRenderer>().bones);
List<Transform> emptyBones = new List<Transform>(); List<Transform> emptyBones = new List<Transform>();
@@ -199,4 +212,24 @@ public class UmaContainer : MonoBehaviour
} }
} }
} }
public void SetNextAnimationCut(string cutName)
{
var asset = UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.Equals(cutName));
UmaViewerBuilder.Instance.RecursiveLoadAsset(asset);
}
public void SetEndAnimationCut()
{
UmaViewerUI.Instance.AnimationPause();
}
public void UpBodyReset()
{
if (UpBodyBone)
{
UpBodyBone.transform.localPosition = UpBodyPosition;
UpBodyBone.transform.localRotation = UpBodyRotation;
}
}
} }
+52 -29
View File
@@ -176,7 +176,7 @@ public class UmaViewerBuilder : MonoBehaviour
// Record Head Data // Record Head Data
int head_id; int head_id;
string head_costumeId; string head_costumeId;
int tailId = Convert.ToInt32(charaData["tail_model_id"]); int tailId = Convert.ToInt32(charaData["tail_model_id"]);
//The tailId of 9006 is 1, but the character has no tail //The tailId of 9006 is 1, but the character has no tail
if (id == 9006) tailId = -1; if (id == 9006) tailId = -1;
@@ -275,8 +275,8 @@ public class UmaViewerBuilder : MonoBehaviour
if (CurrentUMAContainer.Head) if (CurrentUMAContainer.Head)
{ {
var firsehead = CurrentUMAContainer.Head; var firsehead = CurrentUMAContainer.Head;
var FaceDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "facial_target"; }).Value as FaceDrivenKeyTarget; var FaceDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => a.Key.Equals("facial_target")).Value as FaceDrivenKeyTarget;
var EarDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "ear_target"; }).Value as DrivenKeyTarget; var EarDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => a.Key.Equals("ear_target")).Value as DrivenKeyTarget;
FaceDriven._earTarget = EarDriven._targetFaces; FaceDriven._earTarget = EarDriven._targetFaces;
CurrentUMAContainer.FaceDrivenKeyTarget = FaceDriven; CurrentUMAContainer.FaceDrivenKeyTarget = FaceDriven;
CurrentUMAContainer.FaceDrivenKeyTarget.Container = CurrentUMAContainer; CurrentUMAContainer.FaceDrivenKeyTarget.Container = CurrentUMAContainer;
@@ -288,12 +288,13 @@ public class UmaViewerBuilder : MonoBehaviour
emotionDriven.FaceDrivenKeyTarget = FaceDriven; emotionDriven.FaceDrivenKeyTarget = FaceDriven;
emotionDriven.FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList(); emotionDriven.FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList();
emotionDriven.Initialize(); emotionDriven.Initialize();
CurrentUMAContainer.HeadBone = (GameObject)CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable.list.FindLast(a => a.Key.Equals("head")).Value;
CurrentUMAContainer.HeadBone = (GameObject)CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable.list.FindLast(a => a.Key == "head").Value;
} }
CurrentUMAContainer.MergeModel(); CurrentUMAContainer.MergeModel();
CurrentUMAContainer.Initialize();
CurrentUMAContainer.SetHeight(Convert.ToInt32(CurrentUMAContainer.CharaData["scale"])); CurrentUMAContainer.SetHeight(Convert.ToInt32(CurrentUMAContainer.CharaData["scale"]));
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop"))); LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop")));
} }
@@ -586,7 +587,7 @@ public class UmaViewerBuilder : MonoBehaviour
} }
} }
private void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false) public void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false)
{ {
if (!string.IsNullOrEmpty(entry.Prerequisites)) if (!string.IsNullOrEmpty(entry.Prerequisites))
{ {
@@ -729,6 +730,15 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.Body = Instantiate(go, CurrentUMAContainer.transform); CurrentUMAContainer.Body = Instantiate(go, CurrentUMAContainer.transform);
CurrentUMAContainer.UmaAnimator = CurrentUMAContainer.Body.GetComponent<Animator>(); CurrentUMAContainer.UmaAnimator = CurrentUMAContainer.Body.GetComponent<Animator>();
if (CurrentUMAContainer.IsMini)
{
CurrentUMAContainer.UpBodyBone = CurrentUMAContainer.Body.transform.Find("Position/Hip").gameObject;
}
else
{
CurrentUMAContainer.UpBodyBone = CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable.list.Find(a => a.Key.Equals("upbody_ctrl")).Value as GameObject;
}
if (CurrentUMAContainer.IsGeneric) if (CurrentUMAContainer.IsGeneric)
{ {
List<Texture2D> textures = CurrentUMAContainer.GenericBodyTextures; List<Texture2D> textures = CurrentUMAContainer.GenericBodyTextures;
@@ -867,9 +877,10 @@ public class UmaViewerBuilder : MonoBehaviour
m.shader = alphaShader; m.shader = alphaShader;
} }
//Blush Setting //Blush Setting
if (r.name.Contains("Cheek")){ if (r.name.Contains("Cheek"))
{
CurrentUMAContainer.CheekMaterial = m; CurrentUMAContainer.CheekMaterial = m;
CurrentUMAContainer.CheekTex = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "cheek1"; }).Value as Texture; CurrentUMAContainer.CheekTex = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable.list.Find(a => a.Key.Equals("cheek1")).Value as Texture;
if (UI.IsCheekBlushing) if (UI.IsCheekBlushing)
{ {
m.SetTexture("_MainTex", CurrentUMAContainer.CheekTex); m.SetTexture("_MainTex", CurrentUMAContainer.CheekTex);
@@ -882,7 +893,7 @@ public class UmaViewerBuilder : MonoBehaviour
switch (m.shader.name) switch (m.shader.name)
{ {
case "Gallop/3D/Chara/MultiplyCheek": case "Gallop/3D/Chara/MultiplyCheek":
m.shader = cheekShader;; m.shader = cheekShader; ;
break; break;
case "Gallop/3D/Chara/ToonFace/TSER": case "Gallop/3D/Chara/ToonFace/TSER":
m.shader = faceShader; m.shader = faceShader;
@@ -954,7 +965,6 @@ public class UmaViewerBuilder : MonoBehaviour
} }
else if (clip.name.EndsWith("_E")) else if (clip.name.EndsWith("_E"))
{ {
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.OverrideController["clip_e"] = clip; CurrentUMAContainer.OverrideController["clip_e"] = clip;
} }
else if (clip.name.EndsWith("_loop")) else if (clip.name.EndsWith("_loop"))
@@ -975,18 +985,13 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.UmaAnimator.Play("motion_1", -1); CurrentUMAContainer.UmaAnimator.Play("motion_1", -1);
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next"); CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
CurrentUMAContainer.isAnimatorControl = false; CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
} }
else if (clip.name.Contains("tail")) else if (clip.name.Contains("tail"))
{ {
if (CurrentUMAContainer.IsMini) return; if (CurrentUMAContainer.IsMini) return;
var currentStateInfo = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0);
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.OverrideController["clip_t"] = clip; CurrentUMAContainer.OverrideController["clip_t"] = clip;
CurrentUMAContainer.UmaAnimator.Play("motion_t", 1, 0); CurrentUMAContainer.UmaAnimator.Play("motion_t", 1, 0);
CurrentUMAContainer.UmaAnimator.Play(currentStateInfo.shortNameHash, 0, currentStateInfo.normalizedTime);
} }
else if (clip.name.Contains("face")) else if (clip.name.Contains("face"))
{ {
@@ -1006,17 +1011,15 @@ public class UmaViewerBuilder : MonoBehaviour
{ {
if (CurrentUMAContainer.IsMini) return; if (CurrentUMAContainer.IsMini) return;
CurrentUMAContainer.OverrideController["clip_p"] = clip; CurrentUMAContainer.OverrideController["clip_p"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 2, 0); CurrentUMAContainer.UmaAnimator.Play("motion_1", 2, 0);
} }
else if (clip.name.Contains("cam")) else if (clip.name.Contains("cam"))
{ {
var overrideController = Instantiate(CameraOverrideController); SetPreviewCamera(clip);
overrideController["clip_1"] = clip;
SetPreviewCamera(overrideController);
} }
else else
{ {
CurrentUMAContainer.UmaAnimator.Rebind(); CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_1"] = CurrentUMAContainer.OverrideController["clip_2"]; CurrentUMAContainer.OverrideController["clip_1"] = CurrentUMAContainer.OverrideController["clip_2"];
var lastTime = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime; var lastTime = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
CurrentUMAContainer.OverrideController["clip_2"] = clip; CurrentUMAContainer.OverrideController["clip_2"] = clip;
@@ -1052,8 +1055,25 @@ public class UmaViewerBuilder : MonoBehaviour
{ {
SetPreviewCamera(null); SetPreviewCamera(null);
} }
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0); CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
CurrentUMAContainer.TrackTarget = AnimationCamera.gameObject;
if (clip.name.Contains("cti_crd"))
{
string[] param = clip.name.Split('_');
if (param.Length > 4)
{
int index = int.Parse(param[4]) + 1;
var nextMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"{param[0]}_{param[1]}_{param[2]}_{param[3]}_0{index}"));
var aevent = new AnimationEvent
{
time = clip.length*0.99f,
stringParameter = (nextMotion != null ? nextMotion.Name : null),
functionName = (nextMotion != null ? "SetNextAnimationCut" : "SetEndAnimationCut")
};
clip.AddEvent(aevent);
}
}
} }
else else
{ {
@@ -1062,27 +1082,28 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator(); CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
} }
CurrentUMAContainer.isAnimatorControl = false; CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
SetPreviewCamera(null); SetPreviewCamera(null);
CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime); CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime);
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next"); CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
} }
} }
} }
public void SetPreviewCamera(RuntimeAnimatorController controller)
public void SetPreviewCamera(AnimationClip clip)
{ {
if (controller) if (clip)
{ {
AnimationCameraAnimator.runtimeAnimatorController = controller; if (!AnimationCameraAnimator.runtimeAnimatorController)
{
AnimationCameraAnimator.runtimeAnimatorController = Instantiate(CameraOverrideController);
}
(AnimationCameraAnimator.runtimeAnimatorController as AnimatorOverrideController)["clip_1"] = clip;
AnimationCamera.enabled = true; AnimationCamera.enabled = true;
AnimationCameraAnimator.Play("motion_1", 0, 0); AnimationCameraAnimator.Play("motion_1", 0, 0);
} }
else else
{ {
AnimationCameraAnimator.runtimeAnimatorController = null;
AnimationCamera.enabled = false; AnimationCamera.enabled = false;
} }
} }
@@ -1158,6 +1179,7 @@ public class UmaViewerBuilder : MonoBehaviour
Destroy(CurrentUMAContainer.gameObject); Destroy(CurrentUMAContainer.gameObject);
} }
} }
public void ClearMorphs() public void ClearMorphs()
{ {
if (CurrentUMAContainer != null && CurrentUMAContainer.FaceDrivenKeyTarget != null) if (CurrentUMAContainer != null && CurrentUMAContainer.FaceDrivenKeyTarget != null)
@@ -1184,7 +1206,8 @@ public class UmaViewerBuilder : MonoBehaviour
{ {
if (AnimationCamera && AnimationCamera.enabled == true) if (AnimationCamera && AnimationCamera.enabled == true)
{ {
AnimationCamera.fieldOfView = AnimationCamera.gameObject.transform.parent.transform.localScale.x; var fov = AnimationCamera.gameObject.transform.parent.transform.localScale.x;
AnimationCamera.fieldOfView = fov;
} }
} }
} }
+10 -6
View File
@@ -128,12 +128,16 @@ public class UmaViewerGlobalShader : MonoBehaviour
//Used to calculate the correct outline //Used to calculate the correct outline
if (UmaViewerBuilder.Instance.CurrentUMAContainer) if (UmaViewerBuilder.Instance.CurrentUMAContainer)
{ {
var container = UmaViewerBuilder.Instance.CurrentUMAContainer; if (UmaViewerBuilder.Instance.CurrentUMAContainer.UpBodyBone)
var aniCamera = UmaViewerBuilder.Instance.AnimationCamera; {
var camera = aniCamera.enabled ? aniCamera: Camera.main; var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
var distance = Vector3.Distance(camera.transform.position, container.transform.position); var upBone = container.UpBodyBone;
var outlineWidth = (container.IsMini ? 20f : 40.0f) * (distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad)); var aniCamera = UmaViewerBuilder.Instance.AnimationCamera;
Shader.SetGlobalFloat("_GlobalCameraFov", outlineWidth); var camera = aniCamera.enabled ? aniCamera : Camera.main;
var distance = Vector3.Distance(camera.transform.position, upBone.transform.position);
var outlineWidth = (container.IsMini ? 20f : 40.0f) * (distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad));
Shader.SetGlobalFloat("_GlobalCameraFov", outlineWidth);
}
} }
} }
@@ -128,7 +128,6 @@ public class UnityCameraVMDRecorder : MonoBehaviour
else else
{ {
finalRotation += DeltaVector(vmdRotation, LastRotation); finalRotation += DeltaVector(vmdRotation, LastRotation);
Debug.Log(DeltaVector(vmdRotation, LastRotation)+" "+ vmdRotation + " "+ LastRotation);
} }
LocalPositions.Add(vmdPosition); LocalPositions.Add(vmdPosition);
@@ -210,6 +209,7 @@ public class UnityCameraVMDRecorder : MonoBehaviour
public void SaveVMD() public void SaveVMD()
{ {
string fileName = Application.dataPath + "/../VMDRecords/" + string.Format("Camera_{0}.vmd", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); string fileName = Application.dataPath + "/../VMDRecords/" + string.Format("Camera_{0}.vmd", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
Directory.CreateDirectory(Application.dataPath + "/../VMDRecords");
if (IsRecording) if (IsRecording)
{ {
Debug.Log(targetCameraTransform.name + "VMD保存前にレコーディングをストップしてください。"); Debug.Log(targetCameraTransform.name + "VMD保存前にレコーディングをストップしてください。");