Add Extrar Morph Support(WIP)

This commit is contained in:
CroakFang
2022-11-18 20:44:46 +08:00
parent 379de0c072
commit fece4442a9
11 changed files with 540 additions and 641 deletions
+34 -19
View File
@@ -19,9 +19,13 @@ public class UmaContainer : MonoBehaviour
public AnimatorOverrideController OverrideController;
public Animator UmaFaceAnimator;
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;
@@ -29,15 +33,20 @@ public class UmaContainer : MonoBehaviour
public GameObject TrackTarget;
public float EyeHeight;
public bool EnableEyeTracking = true;
[Header("Body")]
public GameObject UpBodyBone;
public Vector3 UpBodyPosition;
public Quaternion UpBodyRotation;
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 List<GameObject> TearObjects_0 = new List<GameObject>();
public List<GameObject> TearObjects_1 = new List<GameObject>();
[Header("Generic")]
public bool IsGeneric = false;
@@ -52,15 +61,16 @@ public class UmaContainer : MonoBehaviour
public bool EnablePhysics = true;
public List<CySpringDataContainer> cySpringDataContainers;
[Header("Shader")]
public Material FaceMaterial;
public void Initialize()
{
EyeHeight = 0.1f;
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()
@@ -108,16 +118,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)
@@ -156,12 +166,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);
}
}
@@ -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;
+135 -26
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>();
@@ -239,7 +241,6 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
if (tailId != 0)
{
string tailName = $"tail{tailId.ToString().PadLeft(4, '0')}_00";
@@ -268,33 +269,76 @@ 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);
bool invert = false;
if (RightObj.TryGetComponent<AssetHolder>(out var holder))
{
if (holder._assetTableValue["invert"] > 0)
invert = true;
}
new List<Renderer>(RightObj.GetComponentsInChildren<Renderer>()).ForEach(a => {
a.material.renderQueue = -1;
if (invert) a.material.mainTextureScale = new Vector2(-1, 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));
}
var firsehead = CurrentUMAContainer.Head;
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 => a.Key.Equals("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.Equals("head")).Value;
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")));
}
@@ -648,6 +692,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;
}
}
@@ -667,8 +713,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:
@@ -694,6 +743,10 @@ public class UmaViewerBuilder : MonoBehaviour
{
LoadTail(go);
}
else if (bundle.name.Contains("pfb_chr_tear"))
{
LoadTear(go);
}
else
{
if (!IsSubAsset)
@@ -736,7 +789,7 @@ public class UmaViewerBuilder : MonoBehaviour
}
else
{
CurrentUMAContainer.UpBodyBone = CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable.list.Find(a => a.Key.Equals("upbody_ctrl")).Value as GameObject;
CurrentUMAContainer.UpBodyBone = CurrentUMAContainer.Body.GetComponent<AssetHolder>()._assetTable["upbody_ctrl"] as GameObject;
}
if (CurrentUMAContainer.IsGeneric)
@@ -754,6 +807,7 @@ public class UmaViewerBuilder : MonoBehaviour
foreach (Material m in r.sharedMaterials)
{
string mainTex = "", toonMap = "", tripleMap = "", optionMap = "", zekkenNumberTex = "";
if (CurrentUMAContainer.IsMini)
{
@@ -761,6 +815,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":
@@ -827,6 +887,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)
@@ -876,19 +950,14 @@ 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 => a.Key.Equals("cheek1")).Value as Texture;
if (UI.IsCheekBlushing)
{
m.SetTexture("_MainTex", CurrentUMAContainer.CheekTex);
}
else
{
m.SetTexture("_MainTex", null);
}
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)
{
@@ -926,9 +995,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>())
{
@@ -956,6 +1025,45 @@ public class UmaViewerBuilder : MonoBehaviour
}
}
private void LoadTear(GameObject go)
{
if (CurrentUMAContainer)
{
var headBone = (GameObject)CurrentUMAContainer.Head.GetComponent<AssetHolder>()._assetTable["head"];
var attachBone_2_L = headBone.transform.Find("Eye_tear_attach_02_L");
var attachBone_2_R = headBone.transform.Find("Eye_tear_attach_02_R");
var attachBone_3_L = headBone.transform.Find("Eye_tear_attach_03_L");
var attachBone_3_R = headBone.transform.Find("Eye_tear_attach_03_R");
var ani = go.GetComponent<Animator>();
var controller = new AnimatorOverrideController(ani.runtimeAnimatorController);
controller["anm_tear000_00"] = go.GetComponent<AssetHolder>()._assetTable["default_animation"] as AnimationClip;
ani.runtimeAnimatorController = controller;
if (go.name.EndsWith("000"))
{
for(int i = 0; i < 4; i++)
{
var obj = Instantiate(go, headBone.transform);
var attachBone = (i % 2 == 0 ? attachBone_3_L : attachBone_3_R);
obj.transform.SetPositionAndRotation(attachBone.TransformPoint(Vector3.zero), attachBone.transform.rotation);
CurrentUMAContainer.TearObjects_0.Add(obj);
}
}
else if(go.name.EndsWith("001"))
{
for (int i = 0; i < 4; i++)
{
var obj = Instantiate(go, headBone.transform);
var animator = obj.GetComponent<Animator>();
Debug.LogError(animator.GetCurrentAnimatorClipInfo(0)[0].clip.name);
var attachBone = (i % 2 == 0 ? attachBone_2_L : attachBone_2_R);
obj.transform.SetPositionAndRotation(attachBone.TransformPoint(Vector3.zero), attachBone.transform.rotation);
CurrentUMAContainer.TearObjects_1.Add(obj);
}
}
}
}
private void LoadAnimation(AnimationClip clip)
{
bool needTransit = false;
@@ -1169,6 +1277,7 @@ public class UmaViewerBuilder : MonoBehaviour
Destroy(CurrentLiveContainer.gameObject);
}
}
public void UnloadUma()
{
if (CurrentUMAContainer != null)
+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();
}
+53 -25
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,55 @@ 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 FacialExtraMorph extraMorph)
{
foreach(var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
container.Name = $"{morph.name}_{extraMorph.BindProperties.IndexOf(prop)}_{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.Bool:
container.Slider.wholeNumbers = true;
container.Slider.maxValue = 1;
container.Slider.minValue = 0;
break;
}
container.Slider.onValueChanged.AddListener((a) => {
target.ChangeMorphWeight(prop, a);
if(prop.Type == BindProperty.BindType.Bool&& 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 +287,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()
@@ -658,24 +703,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()
{
@@ -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<FacialExtraMorph> OtherMorphs = new List<FacialExtraMorph>();
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,168 @@ 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 FacialExtraMorph
{
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)
{
FacialExtraMorph FaceShadowMorph = new FacialExtraMorph()
{
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);
}
FacialExtraMorph FaceMangaMorph = new FacialExtraMorph()
{
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.Bool,
BindPrefab = mangaObjects
});
OtherMorphs.Add(FaceMangaMorph);
}
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 +337,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 +346,50 @@ namespace Gallop
}
}
private void ProcessExtraMorph(FacialExtraMorph 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.Bool:
if (property.Value <= 0)
{
property.BindPrefab.ForEach(a =>a.SetActive(false));
}
break;
}
}
}
public void FacialResetAll()
{
FacialReset(BaseLEarMorph.trsArray);
@@ -336,6 +442,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,26 +462,32 @@ 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.weight < 0)
morph.weight = -morph.weight;
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;
}
});
@@ -378,39 +497,20 @@ namespace Gallop
LeftEyeYrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
RightEyeYrange.weight = (EyeballCtrl_R_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
OtherMorphs.ForEach(morph =>
{
morph.BindProperties.ForEach(property =>
{
property.Value = morph.GetLocatorValue(property.Part);
});
});
ChangeMorph();
}
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();
ChangeMorph();
}
}
+50 -1
View File
@@ -13,9 +13,58 @@ 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 FacialExtraMorph : 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,
Bool
}
public Material BindMaterial;
public Texture BindTexture;
public List<GameObject> BindPrefab = new List<GameObject>();
public string PropertyName;
public LocatorPart Part;
public BindType Type;
public float Value;
}
}
+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;
}