Merge pull request #13 from croakfang/master

Add Other FacialMorph
This commit is contained in:
katboi01
2022-11-23 14:06:30 +01:00
committed by GitHub
18 changed files with 4204 additions and 746 deletions
+1 -1
View File
@@ -443,7 +443,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: motion_1
m_Name: motion_t
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
+1 -1
View File
@@ -7,7 +7,7 @@ AnimationClip:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: clip_1
serializedVersion: 7
serializedVersion: 6
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
+3304 -482
View File
File diff suppressed because it is too large Load Diff
+94 -39
View File
@@ -1,6 +1,7 @@
using Gallop;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using UnityEngine;
public class UmaContainer : MonoBehaviour
@@ -20,6 +21,11 @@ public class UmaContainer : MonoBehaviour
public AnimatorOverrideController FaceOverrideController;
public bool isAnimatorControl;
[Header("Body")]
public GameObject UpBodyBone;
public Vector3 UpBodyPosition;
public Quaternion UpBodyRotation;
[Header("Face")]
public FaceDrivenKeyTarget FaceDrivenKeyTarget;
public FaceEmotionKeyTarget FaceEmotionKeyTarget;
@@ -27,10 +33,21 @@ public class UmaContainer : MonoBehaviour
public GameObject TrackTarget;
public float EyeHeight;
public bool EnableEyeTracking = true;
public Material FaceMaterial;
[Header("Cheek")]
public Texture CheekTex;
public Material CheekMaterial;
public Texture CheekTex_0;
public Texture CheekTex_1;
public Texture CheekTex_2;
[Header("Manga")]
public List<GameObject> LeftMangaObject = new List<GameObject>();
public List<GameObject> RightMangaObject = new List<GameObject>();
[Header("Tear")]
public GameObject TearPrefab_0;
public GameObject TearPrefab_1;
public List<TearController> TearControllers = new List<TearController>();
[Header("Generic")]
public bool IsGeneric = false;
@@ -45,14 +62,21 @@ public class UmaContainer : MonoBehaviour
public bool EnablePhysics = true;
public List<CySpringDataContainer> cySpringDataContainers;
[Header("Shader")]
public Material FaceMaterial;
public void Initialize()
{
TrackTarget = Camera.main.gameObject;
UpBodyPosition = UpBodyBone.transform.localPosition;
UpBodyRotation = UpBodyBone.transform.localRotation;
//Models must be merged before handling extra morphs
if (FaceDrivenKeyTarget)
FaceDrivenKeyTarget.ChangeMorphWeight(FaceDrivenKeyTarget.MouthMorphs[3], 1);
}
public void MergeModel()
{
if (!Body) return;
EyeHeight = 0.1f;
TrackTarget = Camera.main.gameObject;
List<Transform> bodybones = new List<Transform>(Body.GetComponentInChildren<SkinnedMeshRenderer>().bones);
List<Transform> emptyBones = new List<Transform>();
@@ -95,16 +119,16 @@ public class UmaContainer : MonoBehaviour
child.SetParent(transform);
}
Tail.SetActive(false); //for debugging
emptyBones.ForEach(a => { if (a) Destroy(a.gameObject); });
}
emptyBones.ForEach(a => { if (a) Destroy(a.gameObject); });
//MergeAvatar
UmaAnimator = gameObject.AddComponent<Animator>();
UmaAnimator.avatar = AvatarBuilder.BuildGenericAvatar(gameObject, gameObject.name);
OverrideController = Instantiate(UmaViewerBuilder.Instance.OverrideController);
UmaAnimator.runtimeAnimatorController = OverrideController;
FaceMaterial = transform.Find("M_Face").GetComponent<SkinnedMeshRenderer>().material;
}
public void SetHeight(int scale)
@@ -143,12 +167,17 @@ public class UmaContainer : MonoBehaviour
public void LoadPhysics()
{
cySpringDataContainers = new List<CySpringDataContainer>();
var springs = PhysicsController.GetComponentsInChildren<CySpringDataContainer>();
foreach (CySpringDataContainer spring in springs)
cySpringDataContainers = new List<CySpringDataContainer>(PhysicsController.GetComponentsInChildren<CySpringDataContainer>());
var bones = new List<Transform>(GetComponentsInChildren<Transform>());
var colliders = new List<GameObject>();
foreach (CySpringDataContainer spring in cySpringDataContainers)
{
cySpringDataContainers.Add(spring);
spring.InitializePhysics();
colliders.AddRange(spring.InitiallizeCollider(bones));
}
foreach (CySpringDataContainer spring in cySpringDataContainers)
{
spring.InitializePhysics(bones, colliders);
}
}
@@ -164,39 +193,65 @@ public class UmaContainer : MonoBehaviour
private void FixedUpdate()
{
if (TrackTarget && EnableEyeTracking && !isAnimatorControl && !IsMini)
if (!IsMini)
{
var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up*EyeHeight;
var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion);
var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles;
if (deltaRotation.x > 180) deltaRotation.x -= 360;
if (deltaRotation.y > 180) deltaRotation.y -= 360;
if (TrackTarget && EnableEyeTracking && !isAnimatorControl)
{
var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up * EyeHeight;
var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion);
var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles;
if (deltaRotation.x > 180) deltaRotation.x -= 360;
if (deltaRotation.y > 180) deltaRotation.y -= 360;
var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35,-1,1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view
FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y);
}
var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35, -1, 1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view
FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y);
}
if (isAnimatorControl && !IsMini)
{
FaceDrivenKeyTarget.ProcessLocator();
}
if (!IsMini && FaceMaterial)
{
if (isAnimatorControl)
{
FaceMaterial.SetVector("_FaceForward", Vector3.zero);
FaceMaterial.SetVector("_FaceUp", Vector3.zero);
FaceMaterial.SetVector("_FaceCenterPos", Vector3.zero);
FaceDrivenKeyTarget.ProcessLocator();
}
else
if (FaceMaterial)
{
//Used to calculate facial shadows
FaceMaterial.SetVector("_FaceForward", HeadBone.transform.forward);
FaceMaterial.SetVector("_FaceUp", HeadBone.transform.up);
FaceMaterial.SetVector("_FaceCenterPos", HeadBone.transform.position);
if (isAnimatorControl)
{
FaceMaterial.SetVector("_FaceForward", Vector3.zero);
FaceMaterial.SetVector("_FaceUp", Vector3.zero);
FaceMaterial.SetVector("_FaceCenterPos", Vector3.zero);
}
else
{
//Used to calculate facial shadows
FaceMaterial.SetVector("_FaceForward", HeadBone.transform.forward);
FaceMaterial.SetVector("_FaceUp", HeadBone.transform.up);
FaceMaterial.SetVector("_FaceCenterPos", HeadBone.transform.position);
}
FaceMaterial.SetFloat("_faceShadowEndY", HeadBone.transform.position.y);
}
TearControllers.ForEach(a => a.UpdateOffset());
}
}
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;
}
}
}
@@ -70,6 +70,7 @@ public class CharaEntry
public string Name;
public Sprite Icon;
public int Id;
public string ThemeColor;
}
[System.Serializable]
@@ -36,6 +36,8 @@ public class UmaDatabaseController
public static string MotionPath = "3d/motion/";
/// <summary> 3d/chara/ </summary>
public static string CharaPath = "3d/chara/";
/// <summary> 3d/effect/ </summary>
public static string EffectPath = "3d/effect/";
public IEnumerable<UmaDatabaseEntry> MetaEntries;
public IEnumerable<DataRow> CharaData;
+187 -52
View File
@@ -33,6 +33,8 @@ public class UmaViewerBuilder : MonoBehaviour
public Shader cheekShader;
public Shader eyebrowShader;
public Shader alphaShader;
public Shader bodyAlphaShader;
public Shader bodyBehindAlphaShader;
public List<AudioSource> CurrentAudioSources = new List<AudioSource>();
public List<UmaLyricsData> CurrentLyrics = new List<UmaLyricsData>();
@@ -176,7 +178,7 @@ public class UmaViewerBuilder : MonoBehaviour
// Record Head Data
int head_id;
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
if (id == 9006) tailId = -1;
@@ -239,7 +241,6 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
if (tailId != 0)
{
string tailName = $"tail{tailId.ToString().PadLeft(4, '0')}_00";
@@ -268,32 +269,83 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
CurrentUMAContainer.LoadPhysics(); //Need to load physics before loading FacialMorph
//Load FacialMorph
if (CurrentUMAContainer.Head)
{
var locatorEntry = Main.AbList.FirstOrDefault(a => a.Name.EndsWith("3d/animator/drivenkeylocator"));
var bundle = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(locatorEntry));
Main.LoadedBundles.Add(locatorEntry.Name, bundle);
var locator = Instantiate(bundle.LoadAsset("DrivenKeyLocator"), CurrentUMAContainer.transform) as GameObject;
locator.name = "DrivenKeyLocator";
var headBone = (GameObject)CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable["head"];
var eyeLocator_L = headBone.transform.Find("Eye_target_locator_L");
var eyeLocator_R = headBone.transform.Find("Eye_target_locator_R");
var mangaEntry = Main.AbEffect.FindAll(a => a.Name.StartsWith("3d/effect/charaemotion/pfb_eff_chr_emo_eye"));
var mangaObjects = new List<GameObject>();
mangaEntry.ForEach(entry =>
{
AssetBundle ab = AssetBundle.LoadFromFile(UmaDatabaseController.GetABPath(entry));
Main.LoadedBundles.Add(entry.Name, ab);
var obj = ab.LoadAsset(Path.GetFileNameWithoutExtension(entry.Name)) as GameObject;
obj.SetActive(false);
var leftObj = Instantiate(obj, eyeLocator_L.transform);
new List<Renderer>(leftObj.GetComponentsInChildren<Renderer>()).ForEach(a => a.material.renderQueue = -1);
CurrentUMAContainer.LeftMangaObject.Add(leftObj);
var RightObj = Instantiate(obj, eyeLocator_R.transform);
if (RightObj.TryGetComponent<AssetHolder>(out var holder))
{
if (holder._assetTableValue["invert"] > 0)
RightObj.transform.localScale = new Vector3(-1, 1, 1);
}
new List<Renderer>(RightObj.GetComponentsInChildren<Renderer>()).ForEach(a => { a.material.renderQueue = -1; });
CurrentUMAContainer.RightMangaObject.Add(RightObj);
});
var tearEntry = Main.AbChara.FindAll(a => a.Name.StartsWith("3d/chara/common/tear/") && a.Name.Contains("pfb_chr_tear"));
if (tearEntry.Count > 0)
{
tearEntry.ForEach(a => RecursiveLoadAsset(a));
}
if (CurrentUMAContainer.TearPrefab_0 && CurrentUMAContainer.TearPrefab_1)
{
var p0 = CurrentUMAContainer.TearPrefab_0;
var p1 = CurrentUMAContainer.TearPrefab_1;
var t = headBone.transform;
CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 1));
CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 1));
CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 0));
CurrentUMAContainer.TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 0));
}
var firsehead = CurrentUMAContainer.Head;
var FaceDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "facial_target"; }).Value as FaceDrivenKeyTarget;
var EarDriven = firsehead.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "ear_target"; }).Value as DrivenKeyTarget;
FaceDriven._earTarget = EarDriven._targetFaces;
CurrentUMAContainer.FaceDrivenKeyTarget = FaceDriven;
var faceDriven = firsehead.GetComponent<AssetHolder>()._assetTable["facial_target"] as FaceDrivenKeyTarget;
var earDriven = firsehead.GetComponent<AssetHolder>()._assetTable["ear_target"] as DrivenKeyTarget;
faceDriven._earTarget = earDriven._targetFaces;
CurrentUMAContainer.FaceDrivenKeyTarget = faceDriven;
CurrentUMAContainer.FaceDrivenKeyTarget.Container = CurrentUMAContainer;
FaceDriven.Initialize(firsehead.GetComponentsInChildren<Transform>().ToList());
faceDriven.DrivenKeyLocator = locator.transform;
faceDriven.Initialize(firsehead.GetComponentsInChildren<Transform>().ToList());
var emotionDriven = ScriptableObject.CreateInstance<FaceEmotionKeyTarget>();
emotionDriven.name = $"char{id}_{costumeId}_emotion_target";
CurrentUMAContainer.FaceEmotionKeyTarget = emotionDriven;
emotionDriven.FaceDrivenKeyTarget = FaceDriven;
emotionDriven.FaceDrivenKeyTarget = faceDriven;
emotionDriven.FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList();
emotionDriven.Initialize();
CurrentUMAContainer.HeadBone = (GameObject)CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable.list.FindLast(a => a.Key == "head").Value;
}
CurrentUMAContainer.TearControllers.ForEach(a => a.SetDir(a.CurrentDir));
CurrentUMAContainer.HeadBone = (GameObject)CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable["head"];
CurrentUMAContainer.EyeHeight = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTableValue["head_center_offset_y"];
CurrentUMAContainer.MergeModel();
CurrentUMAContainer.Initialize();
CurrentUMAContainer.SetHeight(Convert.ToInt32(CurrentUMAContainer.CharaData["scale"]));
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop")));
}
@@ -586,7 +638,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))
{
@@ -647,6 +699,8 @@ public class UmaViewerBuilder : MonoBehaviour
cheekShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactermultiplycheek.shader");
eyebrowShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactertoonmayu.shader");
alphaShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/characteralphanolinetoonhairtser.shader");
bodyAlphaShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/characteralphanolinetoontser.shader");
bodyBehindAlphaShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/characteralphanolinetoonbehindtser.shader");
Main.ShadersLoaded = true;
}
}
@@ -666,8 +720,11 @@ public class UmaViewerBuilder : MonoBehaviour
LoadAnimation(aClip);
}
if (!CurrentLiveContainer)
UnloadBundle(bundle, false);
if (CurrentLiveContainer || aClip.name.Contains("tear"))
{
break;
}
UnloadBundle(bundle, false);
break;
}
case GameObject go:
@@ -693,6 +750,10 @@ public class UmaViewerBuilder : MonoBehaviour
{
LoadTail(go);
}
else if (bundle.name.Contains("pfb_chr_tear"))
{
LoadTear(go);
}
else
{
if (!IsSubAsset)
@@ -729,6 +790,15 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.Body = Instantiate(go, CurrentUMAContainer.transform);
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["upbody_ctrl"] as GameObject;
}
if (CurrentUMAContainer.IsGeneric)
{
List<Texture2D> textures = CurrentUMAContainer.GenericBodyTextures;
@@ -744,6 +814,7 @@ public class UmaViewerBuilder : MonoBehaviour
foreach (Material m in r.sharedMaterials)
{
string mainTex = "", toonMap = "", tripleMap = "", optionMap = "", zekkenNumberTex = "";
if (CurrentUMAContainer.IsMini)
{
@@ -751,6 +822,12 @@ public class UmaViewerBuilder : MonoBehaviour
}
else
{
//BodyAlapha's shader need to change manually.
if (m.name.Contains("bdy") && m.name.Contains("Alpha"))
{
m.shader = bodyAlphaShader;
}
switch (costumeIdShort.Split('_')[0]) //costume ID
{
case "0001":
@@ -817,6 +894,20 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
}
else
{
foreach (Renderer r in CurrentUMAContainer.Body.GetComponentsInChildren<Renderer>())
{
foreach (Material m in r.sharedMaterials)
{
//BodyAlapha's shader need to change manually.
if (m.name.Contains("bdy") && m.name.Contains("Alpha"))
{
m.shader = bodyAlphaShader;
}
}
}
}
}
private void LoadHead(GameObject go)
@@ -866,23 +957,19 @@ public class UmaViewerBuilder : MonoBehaviour
{
m.shader = alphaShader;
}
//Blush Setting
if (r.name.Contains("Cheek")){
CurrentUMAContainer.CheekMaterial = m;
CurrentUMAContainer.CheekTex = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable.list.Find(a => { return a.Key == "cheek1"; }).Value as Texture;
if (UI.IsCheekBlushing)
{
m.SetTexture("_MainTex", CurrentUMAContainer.CheekTex);
}
else
{
m.SetTexture("_MainTex", null);
}
if (r.name.Contains("Cheek"))
{
var table = CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable.list;
CurrentUMAContainer.CheekTex_0 = table.FindLast(a => a.Key.Equals("cheek0")).Value as Texture;
CurrentUMAContainer.CheekTex_1 = table.FindLast(a => a.Key.Equals("cheek1")).Value as Texture;
CurrentUMAContainer.CheekTex_2 = table.FindLast(a => a.Key.Equals("cheek2")).Value as Texture;
}
switch (m.shader.name)
{
case "Gallop/3D/Chara/MultiplyCheek":
m.shader = cheekShader;;
m.shader = cheekShader; ;
break;
case "Gallop/3D/Chara/ToonFace/TSER":
m.shader = faceShader;
@@ -915,9 +1002,9 @@ public class UmaViewerBuilder : MonoBehaviour
//}
}
private void LoadTail(GameObject gameObject)
private void LoadTail(GameObject go)
{
CurrentUMAContainer.Tail = Instantiate(gameObject, CurrentUMAContainer.transform);
CurrentUMAContainer.Tail = Instantiate(go, CurrentUMAContainer.transform);
var textures = CurrentUMAContainer.TailTextures;
foreach (Renderer r in CurrentUMAContainer.Tail.GetComponentsInChildren<Renderer>())
{
@@ -945,22 +1032,54 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
private void LoadTear(GameObject go)
{
if (CurrentUMAContainer)
{
if (go.name.EndsWith("000"))
{
CurrentUMAContainer.TearPrefab_0 = go;
}
else if (go.name.EndsWith("001"))
{
CurrentUMAContainer.TearPrefab_1 = go;
}
}
}
private void LoadAnimation(AnimationClip clip)
{
bool needTransit = false;
if (clip.name.EndsWith("_S"))
{
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_s"] = clip;
}
else if (clip.name.EndsWith("_E"))
{
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_e"] = clip;
}
else if (clip.name.EndsWith("_loop"))
{
var motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
var motion_e = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e")));
CurrentUMAContainer.UpBodyReset();
UmaDatabaseEntry motion_e = null, motion_s = null;
if (clip.name.EndsWith("_loop"))
{
motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
}
if (CurrentUMAContainer.OverrideController["clip_2"].name.EndsWith("_loop"))
{
motion_e = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e")));
}
if (CurrentUMAContainer.isAnimatorControl && CurrentUMAContainer.FaceDrivenKeyTarget)
{
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
bool needTransit = false;
needTransit = (motion_s != null && motion_e != null);
if (needTransit)
{
@@ -975,18 +1094,14 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.UmaAnimator.Play("motion_1", -1);
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
}
else if (clip.name.Contains("tail"))
{
if (CurrentUMAContainer.IsMini) return;
var currentStateInfo = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0);
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_t"] = clip;
CurrentUMAContainer.UmaAnimator.Play("motion_t", 1, 0);
CurrentUMAContainer.UmaAnimator.Play(currentStateInfo.shortNameHash, 0, currentStateInfo.normalizedTime);
}
else if (clip.name.Contains("face"))
{
@@ -1006,16 +1121,15 @@ public class UmaViewerBuilder : MonoBehaviour
{
if (CurrentUMAContainer.IsMini) return;
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"))
{
var overrideController = Instantiate(CameraOverrideController);
overrideController["clip_1"] = clip;
SetPreviewCamera(overrideController);
SetPreviewCamera(clip);
}
else
{
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.OverrideController["clip_1"] = CurrentUMAContainer.OverrideController["clip_2"];
var lastTime = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
@@ -1052,8 +1166,25 @@ public class UmaViewerBuilder : MonoBehaviour
{
SetPreviewCamera(null);
}
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
{
@@ -1062,27 +1193,28 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
SetPreviewCamera(null);
CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime);
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
CurrentUMAContainer.UmaAnimator.SetTrigger("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;
AnimationCameraAnimator.Play("motion_1", 0, 0);
}
else
{
AnimationCameraAnimator.runtimeAnimatorController = null;
AnimationCamera.enabled = false;
}
}
@@ -1147,6 +1279,7 @@ public class UmaViewerBuilder : MonoBehaviour
Destroy(CurrentLiveContainer.gameObject);
}
}
public void UnloadUma()
{
if (CurrentUMAContainer != null)
@@ -1158,6 +1291,7 @@ public class UmaViewerBuilder : MonoBehaviour
Destroy(CurrentUMAContainer.gameObject);
}
}
public void ClearMorphs()
{
if (CurrentUMAContainer != null && CurrentUMAContainer.FaceDrivenKeyTarget != null)
@@ -1184,7 +1318,8 @@ public class UmaViewerBuilder : MonoBehaviour
{
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
if (UmaViewerBuilder.Instance.CurrentUMAContainer)
{
var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
var aniCamera = UmaViewerBuilder.Instance.AnimationCamera;
var camera = aniCamera.enabled ? aniCamera: Camera.main;
var distance = Vector3.Distance(camera.transform.position, container.transform.position);
var outlineWidth = (container.IsMini ? 20f : 40.0f) * (distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad));
Shader.SetGlobalFloat("_GlobalCameraFov", outlineWidth);
if (UmaViewerBuilder.Instance.CurrentUMAContainer.UpBodyBone)
{
var container = UmaViewerBuilder.Instance.CurrentUMAContainer;
var upBone = container.UpBodyBone;
var aniCamera = UmaViewerBuilder.Instance.AnimationCamera;
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);
}
}
}
+5 -2
View File
@@ -18,6 +18,7 @@ public class UmaViewerMain : MonoBehaviour
public List<UmaDatabaseEntry> AbMotions = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbSounds = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbChara = new List<UmaDatabaseEntry>();
public List<UmaDatabaseEntry> AbEffect = new List<UmaDatabaseEntry>();
[Header("Asset Memory")]
public bool ShadersLoaded = false;
@@ -30,6 +31,7 @@ public class UmaViewerMain : MonoBehaviour
AbList = UmaDatabaseController.Instance.MetaEntries.ToList();
AbChara = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.CharaPath)).ToList();
AbMotions = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.MotionPath)).ToList();
AbEffect = AbList.Where(ab => ab.Name.StartsWith(UmaDatabaseController.EffectPath)).ToList();
AbSounds = AbList.Where(ab => ab.Name.EndsWith(".awb") || ab.Name.EndsWith(".acb")).ToList();
}
@@ -57,9 +59,10 @@ public class UmaViewerMain : MonoBehaviour
{
Characters.Add(new CharaEntry()
{
Name = enNames.ContainsKey(id)? enNames[id] : item["charaname"].ToString(),
Name = enNames.ContainsKey(id) ? enNames[id] : item["charaname"].ToString(),
Icon = UmaViewerBuilder.Instance.LoadCharaIcon(id.ToString()),
Id = id
Id = id,
ThemeColor = "#"+item["ui_nameplate_color_1"].ToString()
});
}
}
+72 -26
View File
@@ -38,6 +38,7 @@ public class UmaViewerUI : MonoBehaviour
public ScrollRect EyeBrowList;
public ScrollRect EyeList;
public ScrollRect MouthList;
public ScrollRect OtherList;
public ScrollRect LiveList;
public ScrollRect LiveSoundList;
public ScrollRect LiveCharaSoundList;
@@ -84,7 +85,6 @@ public class UmaViewerUI : MonoBehaviour
public bool isCriware = false;
public bool isHeadFix = false;
public bool EnableEyeTracking = true;
public bool IsCheekBlushing = false;
public FaceDrivenKeyTarget currentFaceDrivenKeyTarget;
@@ -219,12 +219,65 @@ public class UmaViewerUI : MonoBehaviour
{
foreach (FacialMorph morph in targetMorph)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = morph.name + " (" + morph.tag + ")";
container.Slider.value = morph.weight;
container.Slider.maxValue = 1;
container.Slider.minValue = morph.tag.Contains("Range") ? -1 : 0;
container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
if(morph is FacialOtherMorph extraMorph)
{
foreach(var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = $"{morph.locator.name}({prop.Type})";
container.Slider.value = prop.Value;
switch (prop.Type)
{
case BindProperty.BindType.Shader:
case BindProperty.BindType.Texture:
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.Select:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count - 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.EyeSelect:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = prop.BindPrefab.Count/2 - 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.Enable:
case BindProperty.BindType.TearSelect:
case BindProperty.BindType.TearSide:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.TearWeight:
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
case BindProperty.BindType.TearSpeed:
container.Slider.maxValue = 2;
container.Slider.minValue = 0;
break;
}
container.Slider.onValueChanged.AddListener((a) => {
target.ChangeMorphWeight(prop, a);
if(prop.Type == BindProperty.BindType.Enable&& morph.name.Contains("Manga"))
{
target.ChangeMorphWeight(target.EyeMorphs[42], container.Slider.value > 0 ? 1 : 0);
target.ChangeMorphWeight(target.EyeMorphs[43], container.Slider.value > 0 ? 1 : 0);
}
});
}
}
else
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = $"{morph.name}({morph.tag})";
container.Slider.value = morph.weight;
container.Slider.maxValue = 1;
container.Slider.minValue = morph.tag.Contains("Range") ? -1 : 0;
container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
}
}
}
@@ -244,6 +297,8 @@ public class UmaViewerUI : MonoBehaviour
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.EyeMorphs, EyeList);
InstantiateFacialPart(UmaContainerSliderPrefab, target, target.MouthMorphs, MouthList);
List<FacialMorph> targetMorph = new List<FacialMorph>(target.OtherMorphs);
InstantiateFacialPart(UmaContainerSliderPrefab, target, targetMorph, OtherList);
}
public void UpdateFacialPanels()
@@ -438,8 +493,16 @@ public class UmaViewerUI : MonoBehaviour
{
var container = Instantiate(UmaContainerPrefab, LiveCharaSoundList.content).GetComponent<UmaUIContainer>();
string[] split = Path.GetFileNameWithoutExtension(entry.Name).Split('_');
string name = split[split.Length - 2] + getCharaName(split[split.Length - 2]) + " " + split[split.Length - 1];
string name = $"{ split[split.Length - 2]} {getCharaName(split[split.Length - 2])}";
container.Name = name;
var icon = Main.Characters.Find(a => a.Id.ToString().Equals(split[split.Length - 2]));
if (icon != null)
{
container.Image.sprite = icon.Icon;
container.Image.enabled = true;
}
container.Button.onClick.AddListener(() => {
HighlightChildImage(LiveCharaSoundList.content, container.GetComponent<Image>());
if (isCriware)
@@ -650,24 +713,7 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void SetBlushing(bool isOn)
{
IsCheekBlushing = isOn;
if (Builder.CurrentUMAContainer)
{
if (Builder.CurrentUMAContainer.CheekMaterial)
{
if (isOn)
{
Builder.CurrentUMAContainer.CheekMaterial.SetTexture("_MainTex", Builder.CurrentUMAContainer.CheekTex);
}
else
{
Builder.CurrentUMAContainer.CheekMaterial.SetTexture("_MainTex", null);
}
}
}
}
public void AudioPause()
{
@@ -128,7 +128,6 @@ public class UnityCameraVMDRecorder : MonoBehaviour
else
{
finalRotation += DeltaVector(vmdRotation, LastRotation);
Debug.Log(DeltaVector(vmdRotation, LastRotation)+" "+ vmdRotation + " "+ LastRotation);
}
LocalPositions.Add(vmdPosition);
@@ -210,6 +209,7 @@ public class UnityCameraVMDRecorder : MonoBehaviour
public void SaveVMD()
{
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)
{
Debug.Log(targetCameraTransform.name + "VMD保存前にレコーディングをストップしてください。");
@@ -7,6 +7,6 @@ namespace Gallop
public class AssetHolder : MonoBehaviour
{
[SerializeField] public AssetTable _assetTable;
[SerializeField] private AssetTableValue _assetTableValue;
[SerializeField] public AssetTableValue _assetTableValue;
}
}
@@ -26,24 +26,14 @@ namespace Gallop
public float HipMoveInfluenceMaxDistance;
public List<DynamicBone> DynamicBones = new List<DynamicBone>();
private void Awake()
{
//InitializePhysics();
}
public void InitializePhysics()
{
DynamicBones.Clear();
List<Transform> gameObjects = new List<Transform>();
gameObjects.AddRange(transform.parent.transform.parent.GetComponentsInChildren<Transform>());
List<DynamicBoneColliderBase> colliders = new List<DynamicBoneColliderBase>();
public List<GameObject> InitiallizeCollider(List<Transform> bones)
{
var colliders = new List<GameObject>();
foreach (CySpringCollisionData collider in collisionParam)
{
if (collider._isInner) continue;
var bone = gameObjects.Find(a => { return a.name == collider._targetObjectName; });
var bone = bones.Find(a => { return a.name == collider._targetObjectName; });
if (bone)
{
@@ -52,6 +42,7 @@ namespace Gallop
child.transform.localPosition = Vector3.zero;
child.transform.localRotation = Quaternion.identity;
child.transform.localScale = Vector3.one;
colliders.Add(child);
switch (collider._type)
{
@@ -64,7 +55,6 @@ namespace Gallop
dynamic.m_Height = (collider._offset - collider._offset2).magnitude + collider._radius;
dynamic.m_Radius = collider._radius;
dynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(dynamic);
break;
case CySpringCollisionData.CollisionType.Sphere:
var Spheredynamic = child.AddComponent<DynamicBoneCollider>();
@@ -73,25 +63,27 @@ namespace Gallop
Spheredynamic.m_Radius = collider._radius;
Spheredynamic.m_Height = collider._distance;
Spheredynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(Spheredynamic);
break;
case CySpringCollisionData.CollisionType.Plane:
var planedynamic = child.AddComponent<DynamicBonePlaneCollider>();
planedynamic.ColliderName = collider._collisionName;
child.transform.localPosition = collider._offset;
planedynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
colliders.Add(planedynamic);
break;
case CySpringCollisionData.CollisionType.None:
break;
}
}
}
return colliders;
}
foreach(CySpringParamDataElement spring in springParam)
public void InitializePhysics(List<Transform> bones, List<GameObject> colliders)
{
DynamicBones.Clear();
foreach (CySpringParamDataElement spring in springParam)
{
var bone = gameObjects.Find(a => { return a.name == spring._boneName; });
var bone = bones.Find(a => { return a.name == spring._boneName; });
if (bone)
{
bool isTail = gameObject.name.Contains("tail");//The tail needs less traction
@@ -112,14 +104,13 @@ namespace Gallop
dynamic.m_Damping = 0.2f;
dynamic.m_Stiffness = Mathf.Clamp01(45 / spring._stiffnessForce);
dynamic.m_Elasticity = Mathf.Clamp01(45 / spring._dragForce);
}
dynamic.m_Radius = spring._collisionRadius;
dynamic.m_Friction = 0.5f;
dynamic.m_Inert = spring.MoveSpringApplyRate / 3;
dynamic.SetupParticles();
DynamicBones.Add(dynamic);
foreach (string collisionName in spring._collisionNameList)
{
var tmp = colliders.Find(a => { return a.gameObject.name == collisionName; });
@@ -130,7 +121,7 @@ namespace Gallop
}
foreach (CySpringParamDataChildElement Childcollision in spring._childElements)
{
var tempParticle = dynamic.Particles.Find(a => { return a.m_Transform.gameObject.name == Childcollision._boneName; });
if (tempParticle != null)
{
@@ -146,7 +137,6 @@ namespace Gallop
tempParticle.m_Stiffness = Mathf.Clamp01(45 / Childcollision._stiffnessForce);
tempParticle.m_Elasticity = Mathf.Clamp01(45 / Childcollision._dragForce);
}
tempParticle.m_Friction = 0.5f;
tempParticle.m_Inert = Childcollision.MoveSpringApplyRate / 3;
tempParticle.m_Radius = Childcollision._collisionRadius;
tempParticle.m_LimitAngel_Min = Childcollision._limitAngleMin;
@@ -8,6 +8,8 @@ namespace Gallop
{
public class FaceDrivenKeyTarget : ScriptableObject
{
public UmaContainer Container;
public List<EyeTarget> _eyeTarget;
public List<EyebrowTarget> _eyebrowTarget;
public List<MouthTarget> _mouthTarget;
@@ -20,18 +22,19 @@ namespace Gallop
private FacialMorph BaseMouthMorph;
public FacialMorph LeftEyeXrange, LeftEyeYrange, RightEyeXrange, RightEyeYrange;
public List<FacialMorph> EarMorphs = new List<FacialMorph>();
public List<FacialMorph> EyeBrowMorphs = new List<FacialMorph>();
public List<FacialMorph> EyeMorphs = new List<FacialMorph>();
public List<FacialMorph> MouthMorphs = new List<FacialMorph>();
public List<FacialOtherMorph> OtherMorphs = new List<FacialOtherMorph>();
public GameObject DrivenKeyLocator;
public GameObject EyeballCtrl_L_Locator, EyeballCtrl_R_Locator, EyeballCtrl_All_Locator;
public UmaContainer Container;
public Transform DrivenKeyLocator;
public Transform EyeballCtrl_L_Locator, EyeballCtrl_R_Locator, EyeballCtrl_All_Locator;
Dictionary<Transform, Vector3> RotationRecorder = new Dictionary<Transform, Vector3>();
Dictionary<Particle, Vector3> ParticleRecorder = new Dictionary<Particle, Vector3>();
public void Initialize(List<Transform> objs)
{
Objs = objs;
@@ -50,7 +53,6 @@ namespace Gallop
for (int j = 0; j < _earTarget[i]._faceGroupInfo.Count; j++)
{
FacialMorph morph = new FacialMorph();
morph.target = this;
morph.direction = j > 0;
morph.name = "Ear_" + i + "_" + (morph.direction ? "L" : "R");
morph.tag = Enum.GetName(typeof(EarType), i);
@@ -82,7 +84,6 @@ namespace Gallop
for (int j = 0; j < _eyebrowTarget[i]._faceGroupInfo.Count; j++)
{
FacialMorph morph = new FacialMorph();
morph.target = this;
morph.direction = j > 0;
morph.name = "EyeBrow_" + i + "_" + (morph.direction ? "L" : "R");
morph.tag = Enum.GetName(typeof(LiveTimelineDefine.FacialEyebrowId), i);
@@ -108,7 +109,6 @@ namespace Gallop
for (int j = 0; j < _eyeTarget[i]._faceGroupInfo.Count; j++)
{
FacialMorph morph = new FacialMorph();
morph.target = this;
morph.direction = j > 0;
morph.name = "Eye_" + i + "_" + (morph.direction ? "L" : "R");
morph.tag = Enum.GetName(typeof(LiveTimelineDefine.FacialEyeId), i);
@@ -145,7 +145,6 @@ namespace Gallop
for (int j = 0; j < _mouthTarget[i]._faceGroupInfo.Count; j++)
{
FacialMorph morph = new FacialMorph();
morph.target = this;
morph.direction = j > 0;
morph.name = "Mouth_" + i + "_" + j;
morph.tag = Enum.GetName(typeof(LiveTimelineDefine.FacialMouthId), i);
@@ -165,105 +164,207 @@ namespace Gallop
}
}
ChangeMorphWeight(MouthMorphs[3], 1);
InitializeExtra();
SetupAnimator();
if (UmaViewerUI.Instance)
{
UmaViewerUI.Instance.LoadFacialPanels(this);
}
public void InitializeExtra()
{
if (Container.CheekTex_0)
{
var CheekMorph = new FacialOtherMorph
{
name = "Cheek_Ctrl",
locator = DrivenKeyLocator.Find("Cheek_Ctrl"),
BindGameObject = Container.Head.transform.Find("M_Cheek").gameObject
};
var bindMaterial = CheekMorph.BindGameObject.GetComponent<SkinnedMeshRenderer>().material;
BindProperty cheekProperty = new BindProperty()
{
BindMaterial = bindMaterial,
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.Texture,
BindTexture = Container.CheekTex_0,
PropertyName = "_CheekRate"
};
CheekMorph.BindProperties.Add(cheekProperty);
if (Container.CheekTex_1)
{
BindProperty cheekProperty1 = new BindProperty()
{
BindMaterial = bindMaterial,
Part = BindProperty.LocatorPart.ScaY,
Type = BindProperty.BindType.Texture,
BindTexture = Container.CheekTex_1,
PropertyName = "_CheekRate"
};
CheekMorph.BindProperties.Add(cheekProperty1);
}
if (Container.CheekTex_2)
{
BindProperty cheekProperty2 = new BindProperty()
{
BindMaterial = bindMaterial,
Part = BindProperty.LocatorPart.ScaZ,
Type = BindProperty.BindType.Texture,
BindTexture = Container.CheekTex_2,
PropertyName = "_CheekRate"
};
CheekMorph.BindProperties.Add(cheekProperty2);
}
OtherMorphs.Add(CheekMorph);
}
Container.FaceMaterial = Container.Head.transform.Find("M_Face").GetComponent<SkinnedMeshRenderer>().material;
if (Container.FaceMaterial)
{
FacialOtherMorph FaceShadowMorph = new FacialOtherMorph()
{
name = "Shade_Ctrl",
locator = DrivenKeyLocator.Find("Shade_Ctrl")
};
FaceShadowMorph.BindProperties.Add(
new BindProperty()
{
BindMaterial = Container.FaceMaterial,
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.Shader,
PropertyName = "_faceShadowAlpha"
});
OtherMorphs.Add(FaceShadowMorph);
}
FacialOtherMorph FaceMangaMorph = new FacialOtherMorph()
{
name = "Manga_Ctrl",
locator = DrivenKeyLocator.Find("Manga_Ctrl")
};
var mangaObjects = new List<GameObject>();
mangaObjects.AddRange(Container.LeftMangaObject);
mangaObjects.AddRange(Container.RightMangaObject);
FaceMangaMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaY,
Type = BindProperty.BindType.EyeSelect,
BindPrefab = mangaObjects
});
FaceMangaMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.Enable,
BindPrefab = mangaObjects
});
OtherMorphs.Add(FaceMangaMorph);
foreach(var tear in Container.TearControllers)
{
var index = Container.TearControllers.IndexOf(tear);
FacialOtherMorph FaceTearMorph = new FacialOtherMorph()
{
name = $"Tear{index}_Ctrl",
locator = DrivenKeyLocator.Find($"Tear{index}_Ctrl")
};
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.TearWeight,
BindTearController = tear,
Value = tear.Weight
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.PosY,
Type = BindProperty.BindType.TearSide,
BindTearController = tear,
Value = tear.CurrentDir
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaY,
Type = BindProperty.BindType.TearSelect,
BindTearController = tear,
Value = tear.CurrenObject
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaZ,
Type = BindProperty.BindType.TearSpeed,
BindTearController = tear,
Value = tear.Speed
});
OtherMorphs.Add(FaceTearMorph);
}
}
public void SetupAnimator()
{
DrivenKeyLocator = new GameObject("DrivenKeyLocator");
DrivenKeyLocator.transform.SetParent(Container.transform);
SetupLocator("Ear_L_Ctrl", "Ear_L__", EarMorphs.FindAll(a => a.direction == true));
SetupLocator("Ear_R_Ctrl", "Ear_R__", EarMorphs.FindAll(a => a.direction == false));
SetupLocator("Eye_L_Base_Ctrl", "Eye_L__", EyeMorphs.FindAll(a => a.direction == true));
SetupLocator("Eye_R_Base_Ctrl", "Eye_R__", EyeMorphs.FindAll(a => a.direction == false));
SetupLocator("Eyebrow_L_Base_Ctrl", "Eyebrow_L__", EyeBrowMorphs.FindAll(a => a.direction == true));
SetupLocator("Eyebrow_R_Base_Ctrl", "Eyebrow_R__", EyeBrowMorphs.FindAll(a => a.direction == false));
SetupLocator("Mouth_Base_Ctrl", "Mouth__", MouthMorphs.FindAll(a => a.direction == false));
if (!DrivenKeyLocator) return;
var root = new GameObject("Eyeball_L_Ctrl");
root.transform.SetParent(DrivenKeyLocator.transform);
EyeballCtrl_L_Locator = root;
root = new GameObject("Eyeball_R_Ctrl");
root.transform.SetParent(DrivenKeyLocator.transform);
EyeballCtrl_R_Locator = root;
root = new GameObject("Eyeball_all_Ctrl");
root.transform.SetParent(DrivenKeyLocator.transform);
EyeballCtrl_All_Locator = root;
SetupLocator("Ear_L_Ctrl", EarMorphs.FindAll(a => a.direction == true));
SetupLocator("Ear_R_Ctrl", EarMorphs.FindAll(a => a.direction == false));
SetupLocator("Eye_L_Base_Ctrl", EyeMorphs.FindAll(a => a.direction == true));
SetupLocator("Eye_R_Base_Ctrl", EyeMorphs.FindAll(a => a.direction == false));
SetupLocator("Eyebrow_L_Base_Ctrl", EyeBrowMorphs.FindAll(a => a.direction == true));
SetupLocator("Eyebrow_R_Base_Ctrl", EyeBrowMorphs.FindAll(a => a.direction == false));
SetupLocator("Mouth_Base_Ctrl", MouthMorphs.FindAll(a => a.direction == false));
Container.UmaFaceAnimator = DrivenKeyLocator.AddComponent<Animator>();
Container.UmaFaceAnimator.avatar = AvatarBuilder.BuildGenericAvatar(DrivenKeyLocator, "DrivenKeyLocator");
EyeballCtrl_L_Locator = DrivenKeyLocator.transform.Find("Eyeball_L_Ctrl");
EyeballCtrl_R_Locator = DrivenKeyLocator.transform.Find("Eyeball_R_Ctrl");
EyeballCtrl_All_Locator = DrivenKeyLocator.transform.Find("Eyeball_all_Ctrl");
Container.UmaFaceAnimator = DrivenKeyLocator.GetComponent<Animator>();
Container.UmaFaceAnimator.avatar = AvatarBuilder.BuildGenericAvatar(DrivenKeyLocator.gameObject, "DrivenKeyLocator");
Container.FaceOverrideController = Instantiate(UmaViewerBuilder.Instance.FaceOverrideController);
Container.UmaFaceAnimator.runtimeAnimatorController = Container.FaceOverrideController;
}
public void SetupLocator(string rootName, string prefix, List<FacialMorph> morphs)
public void SetupLocator(string rootName, List<FacialMorph> morphs)
{
var root = new GameObject(rootName);
root.transform.SetParent(DrivenKeyLocator.transform);
var root = DrivenKeyLocator.transform.Find(rootName);
var locators = new List<Transform>(root.GetComponentsInChildren<Transform>());
morphs.ForEach(morph =>
{
var locator = new GameObject(prefix + morph.tag);
locator.transform.SetParent(root.transform);
morph.locator = locator.transform;
var locator = locators.Find(a => a.name.EndsWith(morph.tag));
if (locator)
{
morph.locator = locator;
}
});
}
public void ChangeMorph()
{
FacialResetAll();
foreach (FacialMorph morph in EarMorphs)
{
ProcessMorph(morph);
}
foreach (FacialMorph morph in EyeBrowMorphs)
{
ProcessMorph(morph);
}
foreach (FacialMorph morph in EyeMorphs)
{
ProcessMorph(morph);
}
foreach (FacialMorph morph in MouthMorphs)
{
ProcessMorph(morph);
}
EarMorphs.ForEach(morph => ProcessMorph(morph));
EyeBrowMorphs.ForEach(morph => ProcessMorph(morph));
EyeMorphs.ForEach(morph => ProcessMorph(morph));
MouthMorphs.ForEach(morph => ProcessMorph(morph));
OtherMorphs.ForEach(morph => ProcessExtraMorph(morph));
ApplyRotation();
}
public void ClearMorph()
{
foreach (FacialMorph morph in EarMorphs)
{
morph.weight = 0;
}
EarMorphs.ForEach(morph => morph.weight = 0);
EyeBrowMorphs.ForEach(morph => morph.weight = 0);
EyeMorphs.ForEach(morph => morph.weight = 0);
MouthMorphs.ForEach(morph => morph.weight = 0);
foreach (FacialMorph morph in EyeBrowMorphs)
OtherMorphs.ForEach(morph =>
{
morph.weight = 0;
}
foreach (FacialMorph morph in EyeMorphs)
{
morph.weight = 0;
}
foreach (FacialMorph morph in MouthMorphs)
{
morph.weight = 0;
}
morph.BindProperties.ForEach(property =>
{
property.Value = morph.GetLocatorValue(property.Part);
});
});
}
private void ProcessMorph(FacialMorph morph)
@@ -275,7 +376,7 @@ namespace Gallop
trs.physicsParticle.m_InitLocalPosition += trs._position * morph.weight;
ParticleRecorder[trs.physicsParticle] += trs._rotation * morph.weight;
}
else if(trs.transform)
else if (trs.transform)
{
trs.transform.localScale += trs._scale * morph.weight;
trs.transform.localPosition += trs._position * morph.weight;
@@ -284,6 +385,62 @@ namespace Gallop
}
}
private void ProcessExtraMorph(FacialOtherMorph morph)
{
foreach (var property in morph.BindProperties)
{
switch (property.Type)
{
case BindProperty.BindType.Texture:
if (property.Value > 0.01f)
{
morph.BindGameObject.SetActive(true);
property.BindMaterial.mainTexture = property.BindTexture;
property.BindMaterial.SetFloat(property.PropertyName, property.Value);
return;
}
else
{
if (morph.BindProperties.IndexOf(property) == morph.BindProperties.Count - 1)
{
morph.BindGameObject.SetActive(false);
}
}
break;
case BindProperty.BindType.Shader:
property.BindMaterial.SetFloat(property.PropertyName, property.Value);
break;
case BindProperty.BindType.Select:
property.BindPrefab.ForEach(a=>a.SetActive((int)property.Value == property.BindPrefab.IndexOf(a)));
break;
case BindProperty.BindType.EyeSelect:
var count = property.BindPrefab.Count / 2;
var val = (int)property.Value;
property.BindPrefab.ForEach(a =>
a.SetActive(val + count < property.BindPrefab.Count && (val == property.BindPrefab.IndexOf(a) || val + count == property.BindPrefab.IndexOf(a))));
break;
case BindProperty.BindType.Enable:
if (property.Value <= 0)
{
property.BindPrefab.ForEach(a =>a.SetActive(false));
}
break;
case BindProperty.BindType.TearSide:
property.BindTearController.SetDir((int)property.Value);
break;
case BindProperty.BindType.TearWeight:
property.BindTearController.SetWegiht(property.Value);
break;
case BindProperty.BindType.TearSelect:
property.BindTearController.SetObject((int)property.Value);
break;
case BindProperty.BindType.TearSpeed:
property.BindTearController.SetSpeed(property.Value);
break;
}
}
}
public void FacialResetAll()
{
FacialReset(BaseLEarMorph.trsArray);
@@ -336,6 +493,13 @@ namespace Gallop
ChangeMorph();
}
public void ChangeMorphWeight(BindProperty property, float val)
{
Container.isAnimatorControl = false;
property.Value = val < 0 ? 0 : val;
ChangeMorph();
}
public void SetEyeRange(float lx, float ly, float rx, float ry)
{
LeftEyeXrange.weight = lx;
@@ -349,27 +513,43 @@ namespace Gallop
{
EyeBrowMorphs.ForEach(morph =>
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph.locator)
morph.weight = morph.locator.transform.localPosition.x * -100;
});
EarMorphs.ForEach(morph =>
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph.locator)
morph.weight = morph.locator.transform.localPosition.x * -100;
});
MouthMorphs.ForEach(morph =>
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph.locator)
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph.weight < 0)
morph.weight = -morph.weight;
}
});
EyeMorphs.ForEach(morph =>
{
if (!(morph == LeftEyeXrange || morph == LeftEyeYrange || morph == RightEyeXrange || morph == RightEyeYrange))
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph.locator)
morph.weight = morph.locator.transform.localPosition.x * -100;
}
});
OtherMorphs.ForEach(morph =>
{
morph.BindProperties.ForEach(property =>
{
property.Value = morph.GetLocatorValue(property.Part);
});
});
LeftEyeXrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
RightEyeXrange.weight = -(EyeballCtrl_R_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
@@ -381,34 +561,8 @@ namespace Gallop
public void ResetLocator()
{
EarMorphs.ForEach(morph =>
{
morph.weight = 0;
morph.locator.transform.localPosition = Vector3.zero;
});
EyeBrowMorphs.ForEach(morph =>
{
morph.weight = 0;
morph.locator.transform.localPosition = Vector3.zero;
});
EyeMorphs.ForEach(morph =>
{
morph.weight = 0;
morph.locator.transform.localPosition = Vector3.zero;
});
MouthMorphs.ForEach(morph =>
{
morph.weight = 0;
morph.locator.transform.localPosition = Vector3.zero;
});
EyeballCtrl_L_Locator.transform.localPosition = Vector3.zero;
EyeballCtrl_R_Locator.transform.localPosition = Vector3.zero;
EyeballCtrl_All_Locator.transform.localPosition = Vector3.zero;
Container.UmaFaceAnimator.Rebind();
ProcessLocator();
ChangeMorph();
}
}
+55 -1
View File
@@ -13,9 +13,63 @@ namespace Gallop
public string name;
public string tag = "";
public bool direction;
public FaceDrivenKeyTarget target;
public float weight;
public List<TrsArray> trsArray;
public Transform locator;
}
[System.Serializable]
public class FacialOtherMorph : FacialMorph
{
public GameObject BindGameObject;
public List<BindProperty> BindProperties = new List<BindProperty>();
public float GetLocatorValue(BindProperty.LocatorPart part)
{
switch (part)
{
case BindProperty.LocatorPart.PosX: return locator.localPosition.x;
case BindProperty.LocatorPart.PosY: return locator.localPosition.y;
case BindProperty.LocatorPart.PosZ: return locator.localPosition.z;
case BindProperty.LocatorPart.ScaX: return locator.localScale.x;
case BindProperty.LocatorPart.ScaY: return locator.localScale.y;
case BindProperty.LocatorPart.ScaZ: return locator.localScale.z;
default: return locator.position.x;
}
}
}
[System.Serializable]
public class BindProperty
{
public enum LocatorPart
{
PosX,
PosY,
PosZ,
ScaX,
ScaY,
ScaZ,
}
public enum BindType
{
Shader,
Select,
EyeSelect,
Texture,
Enable,
TearSide,
TearWeight,
TearSelect,
TearSpeed
}
public Material BindMaterial;
public Texture BindTexture;
public TearController BindTearController;
public List<GameObject> BindPrefab = new List<GameObject>();
public string PropertyName;
public LocatorPart Part;
public BindType Type;
public float Value;
}
}
@@ -0,0 +1,150 @@
using Gallop;
using UnityEngine;
public class TearController
{
public GameObject TearObject_0;
public GameObject TearObject_1;
public Material CurrentMaterial;
public Material TearMaterial_0;
public Material TearMaterial_1;
public int CurrenObject;
public int CurrentDir;
public float Weight;
public float Speed = 1;
private Animator CurrentAnimator;
private Animator Animator_0;
private Animator Animator_1;
private Transform AttachBone_2_L;
private Transform AttachBone_2_R;
private Transform AttachBone_3_L;
private Transform AttachBone_3_R;
private AssetHolder CurrentAssetHolder;
private AssetHolder AssetHolder0;
private AssetHolder AssetHolder1;
bool intialized;
public TearController(Transform headBone, GameObject tearPrefab_0, GameObject tearPrefab_1, int dir, int currentObject)
{
AttachBone_2_L = headBone.transform.Find("Eye_tear_attach_02_L");
AttachBone_2_R = headBone.transform.Find("Eye_tear_attach_02_R");
AttachBone_3_L = headBone.transform.Find("Eye_tear_attach_03_L");
AttachBone_3_R = headBone.transform.Find("Eye_tear_attach_03_R");
TearObject_0 = tearPrefab_0;
AssetHolder0 = TearObject_0.GetComponent<AssetHolder>();
TearMaterial_0 = TearObject_0.GetComponentInChildren<SkinnedMeshRenderer>().material;
TearMaterial_0.SetFloat("_OffsetFactor", -1000);
Animator_0 = TearObject_0.GetComponent<Animator>();
var clip = AssetHolder0._assetTable["default_animation"] as AnimationClip;
var controller = new AnimatorOverrideController(Animator_0.runtimeAnimatorController);
controller["anm_tear000_00"] = clip;
Animator_0.runtimeAnimatorController = controller;
TearObject_1 = tearPrefab_1;
AssetHolder1 = TearObject_1.GetComponent<AssetHolder>();
TearMaterial_1 = TearObject_1.GetComponentInChildren<SkinnedMeshRenderer>().material;
TearMaterial_1.SetFloat("_OffsetFactor", -1000);
Animator_1 = TearObject_1.GetComponent<Animator>();
clip = AssetHolder1._assetTable["default_animation"] as AnimationClip;
controller = new AnimatorOverrideController(Animator_1.runtimeAnimatorController);
controller["anm_tear000_00"] = clip;
Animator_1.runtimeAnimatorController = controller;
SetWegiht(0);
SetDir(dir);
SetObject(currentObject);
intialized = true;
}
public void SetDir(int dir)
{
if (intialized && ((dir > 0 && CurrentDir > 0) || (dir <= 0 && CurrentDir <= 0))) return;
CurrentDir = dir;
if (dir > 0)//RightEye
{
TearObject_0.transform.position = AttachBone_3_R.position;
TearObject_1.transform.position = AttachBone_2_R.position;
TearObject_0.transform.localScale = new Vector3(-1, 1, 1);
TearObject_1.transform.localScale = new Vector3(-1, 1, 1);
}
else//LeftEye
{
TearObject_0.transform.position = AttachBone_3_L.position;
TearObject_1.transform.position = AttachBone_2_L.position;
TearObject_0.transform.localScale = new Vector3(1, 1, 1);
TearObject_1.transform.localScale = new Vector3(1, 1, 1);
}
}
public void SetObject(int curObject)
{
if (intialized && ((curObject < 1 && CurrenObject < 1) || (curObject >= 1 && CurrenObject >= 1))) return;
CurrenObject = curObject;
CurrentAnimator = (curObject < 1) ? Animator_0 : Animator_1;
CurrentMaterial = (curObject < 1) ? TearMaterial_0 : TearMaterial_1;
CurrentAssetHolder = (curObject < 1) ? AssetHolder0 : AssetHolder1;
if (Weight > 0)
{
TearObject_0.SetActive(curObject < 1);
TearObject_1.SetActive(curObject >= 1);
}
}
public void SetWegiht(float weight)
{
if (intialized && (weight <= 0 && Weight <= 0)) return;
Weight = weight;
if (weight <= 0)
{
TearObject_0.SetActive(false);
TearObject_1.SetActive(false);
}
else
{
TearObject_0.SetActive(CurrenObject < 1);
TearObject_1.SetActive(CurrenObject >= 1);
}
}
public void SetSpeed(float speed)
{
if (speed == Speed) return;
Speed = speed;
Animator_0.speed = speed;
Animator_1.speed = speed;
}
public void UpdateOffset()
{
if (Weight <= 0) return;
var time = Mathf.Repeat(CurrentAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime,1);
var width = (int)CurrentAssetHolder._assetTableValue["texture_width"];
var height = (int)CurrentAssetHolder._assetTableValue["texture_height"];
var partWidth = (int)CurrentAssetHolder._assetTableValue["texture_part_width"];
var partHeight = (int)CurrentAssetHolder._assetTableValue["texture_part_height"];
var offset = GetTextureOffset(time, width, height, partWidth, partHeight);
CurrentMaterial.SetColor("_TexScrollParam", new Color(offset.x, -offset.y, 0, Weight));
}
private Vector2 GetTextureOffset(float time,int w,int h,int pw ,int ph)
{
int wCount = w / pw;
int hCount = h / ph;
int index = (int)(time * (wCount * hCount));
return new Vector2((index % wCount) / (float)wCount,(index/wCount)/(float)hCount);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 52416b72680489b4a9a3b590b739e09a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+31
View File
@@ -6,6 +6,22 @@ using static DynamicBone;
[System.Serializable]
public class AssetTable
{
public Object this[string key]
{
get
{
var item = list.Find(a => a.Key.Equals(key));
if(item != null)
{
return item.Value;
}
else
{
return null;
}
}
}
public List<StringObjectPair> list;
}
@@ -13,6 +29,21 @@ public class AssetTable
[System.Serializable]
public class AssetTableValue
{
public float this[string key]
{
get
{
var item = list.Find(a => a.Key.Equals(key));
if (item != null)
{
return item.Value;
}
else
{
return -1;
}
}
}
public List<StringValuePair> list;
}