Merge pull request #8 from croakfang/AssetLoadingRework
This commit is contained in:
@@ -17,7 +17,7 @@ public class ModelExporter
|
||||
{
|
||||
static string modelInfo = $"Generated by UmaViewer {Application.version}, Copyright Cygames \nLink : https://github.com/katboi01/UmaViewer";
|
||||
|
||||
public static void ExportModel(UmaContainer container, string path)
|
||||
public static void ExportModel(UmaContainerCharacter container, string path)
|
||||
{
|
||||
container.SetDynamicBoneEnable(false);
|
||||
container.UmaFaceAnimator?.Rebind();
|
||||
@@ -93,7 +93,7 @@ public class ModelExporter
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private static void AddBlendShape(UmaContainer container)
|
||||
private static void AddBlendShape(UmaContainerCharacter container)
|
||||
{
|
||||
if (!container.FaceDrivenKeyTarget) return;
|
||||
SkinnedMeshRenderer faceMesh = null;
|
||||
|
||||
@@ -139,7 +139,7 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
|
||||
transformDictionary.Add(pair.Key.ToString(), pair.Value);
|
||||
}
|
||||
|
||||
var animator = GetComponentInParent<UmaContainer>().UmaAnimator;
|
||||
var animator = GetComponentInParent<UmaContainerCharacter>().UmaAnimator;
|
||||
var state = animator.GetCurrentAnimatorStateInfo(0);
|
||||
animator.Rebind();
|
||||
|
||||
@@ -814,7 +814,7 @@ public class UnityHumanoidVMDRecorder : MonoBehaviour
|
||||
|
||||
public MorphRecorder(Transform model)
|
||||
{
|
||||
var facialTarget = model.GetComponentInParent<UmaContainer>().FaceDrivenKeyTarget;
|
||||
var facialTarget = model.GetComponentInParent<UmaContainerCharacter>().FaceDrivenKeyTarget;
|
||||
FacialMorphList = new List<FacialMorph>();
|
||||
FacialMorphList.AddRange(facialTarget.EyeBrowMorphs);
|
||||
FacialMorphList.AddRange(facialTarget.EyeMorphs);
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
|
||||
|
||||
|
||||
public class UmaAssetManager : MonoBehaviour
|
||||
@@ -11,9 +12,18 @@ public class UmaAssetManager : MonoBehaviour
|
||||
public static UmaAssetManager instance;
|
||||
|
||||
private Dictionary<string, AssetBundle> LoadedBundles = new Dictionary<string, AssetBundle>();
|
||||
private Dictionary<string, AssetBundle> NeverUnload = new Dictionary<string, AssetBundle>();
|
||||
private Dictionary<string, AssetBundle> NeverUnload = new Dictionary<string, AssetBundle>();
|
||||
|
||||
public static event Action <UmaDatabaseEntry> OnLoadedBundleUpdate;
|
||||
public static Shader HairShader,
|
||||
FaceShader,
|
||||
EyeShader,
|
||||
CheekShader,
|
||||
EyebrowShader,
|
||||
AlphaShader,
|
||||
BodyAlphaShader,
|
||||
BodyBehindAlphaShader;
|
||||
|
||||
public static event Action<UmaDatabaseEntry> OnLoadedBundleUpdate;
|
||||
public static event Action OnLoadedBundleClear;
|
||||
public static event Action<int, int, string> OnLoadProgressChange;
|
||||
|
||||
@@ -44,8 +54,8 @@ public class UmaAssetManager : MonoBehaviour
|
||||
{
|
||||
SearchAB(Main, entry, ref result);
|
||||
}
|
||||
|
||||
for(int i = 0; i < result.Count; i++)
|
||||
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
var exist = LoadAB(result[i]);
|
||||
if (!exist)
|
||||
@@ -62,7 +72,7 @@ public class UmaAssetManager : MonoBehaviour
|
||||
|
||||
public static AssetBundle LoadAssetBundle(UmaDatabaseEntry entry, bool neverUnload = false, bool isRecursive = true)
|
||||
{
|
||||
if (Exist(entry)) return Get(entry);
|
||||
if (Exist(entry)) return Get(entry);
|
||||
if (isRecursive)
|
||||
{
|
||||
var Main = UmaViewerMain.Instance;
|
||||
@@ -94,6 +104,18 @@ public class UmaAssetManager : MonoBehaviour
|
||||
Debug.Log(filePath + " exists and doesn't work");
|
||||
UmaViewerUI.Instance?.ShowMessage(filePath + " exists and doesn't work", UIMessageType.Error);
|
||||
}
|
||||
if (bundle.name == "shader.a")
|
||||
{
|
||||
neverUnload = true;
|
||||
EyeShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactertooneyet.shader");
|
||||
FaceShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactertoonfacetser.shader");
|
||||
HairShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactertoonhairtser.shader");
|
||||
AlphaShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/characteralphanolinetoonhairtser.shader");
|
||||
CheekShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactermultiplycheek.shader");
|
||||
EyebrowShader = (Shader)bundle.LoadAsset("assets/_gallop/resources/shader/3d/character/charactertoonmayu.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");
|
||||
}
|
||||
AddOrUpdate(entry.Name, bundle, neverUnload);
|
||||
if (!neverUnload)
|
||||
{
|
||||
@@ -108,7 +130,7 @@ public class UmaAssetManager : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void SearchAB(UmaViewerMain Main, UmaDatabaseEntry entry,ref List<UmaDatabaseEntry> result)
|
||||
private static void SearchAB(UmaViewerMain Main, UmaDatabaseEntry entry, ref List<UmaDatabaseEntry> result)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(entry.Prerequisites))
|
||||
{
|
||||
@@ -124,7 +146,7 @@ public class UmaAssetManager : MonoBehaviour
|
||||
|
||||
public static AssetBundle Get(UmaDatabaseEntry entry) => Get(entry.Name);
|
||||
|
||||
public static void AddOrUpdate(string name, AssetBundle bundle, bool neverUnload = false)
|
||||
public static void AddOrUpdate(string name, AssetBundle bundle, bool neverUnload = false)
|
||||
{
|
||||
if (instance.LoadedBundles.ContainsKey(name))
|
||||
{
|
||||
@@ -156,7 +178,7 @@ public class UmaAssetManager : MonoBehaviour
|
||||
|
||||
private static void UnloadBundle(AssetBundle bundle, bool unloadAllObjects)
|
||||
{
|
||||
if(instance.NeverUnload.ContainsValue(bundle)) return;
|
||||
if (instance.NeverUnload.ContainsValue(bundle)) return;
|
||||
var entry = instance.LoadedBundles.FirstOrDefault(b => b.Value == bundle);
|
||||
if (entry.Key != null)
|
||||
{
|
||||
@@ -182,13 +204,13 @@ public class UmaAssetManager : MonoBehaviour
|
||||
{
|
||||
if (builder.CurrentUMAContainer)
|
||||
builder.UnloadUma();
|
||||
if (builder.CurrentOtherContainer)
|
||||
if (builder.CurrentOtherContainer)
|
||||
Destroy(builder.CurrentOtherContainer.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
instance.LoadedBundles.Clear();
|
||||
foreach(var bundle in instance.NeverUnload)
|
||||
foreach (var bundle in instance.NeverUnload)
|
||||
{
|
||||
instance.LoadedBundles.Add(bundle.Key, bundle.Value);
|
||||
}
|
||||
|
||||
@@ -12,74 +12,8 @@ using Random = UnityEngine.Random;
|
||||
|
||||
public class UmaContainer : MonoBehaviour
|
||||
{
|
||||
public CharaEntry CharaEntry;
|
||||
public DataRow CharaData;
|
||||
public GameObject Body;
|
||||
public GameObject Tail;
|
||||
public GameObject Head;
|
||||
public GameObject Hair;
|
||||
|
||||
public Transform Position;
|
||||
|
||||
public List<Texture2D> TailTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Animator")]
|
||||
public Animator UmaAnimator;
|
||||
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;
|
||||
public FaceOverrideData FaceOverrideData;
|
||||
public GameObject HeadBone;
|
||||
public Transform TrackTarget;
|
||||
public float EyeHeight;
|
||||
public bool EnableEyeTracking = true;
|
||||
public Material FaceMaterial;
|
||||
|
||||
[Header("Cheek")]
|
||||
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;
|
||||
public string VarCostumeIdShort, VarCostumeIdLong, VarSkin, VarHeight, VarSocks, VarBust;
|
||||
public List<Texture2D> GenericBodyTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Mini")]
|
||||
public bool IsMini = false;
|
||||
public List<Texture2D> MiniHeadTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Mob")]
|
||||
public bool IsMob = false;
|
||||
public DataRow MobDressColor;
|
||||
public DataRow MobHeadColor;
|
||||
public List<Texture2D> MobHeadTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Physics")]
|
||||
public bool EnablePhysics = true;
|
||||
public List<CySpringDataContainer> cySpringDataContainers;
|
||||
public GameObject PhysicsContainer;
|
||||
public float BodyScale = 1;
|
||||
|
||||
[Header("Live")]
|
||||
public bool IsLive = false;
|
||||
public bool LiveVisible = true;
|
||||
@@ -89,380 +23,9 @@ public class UmaContainer : MonoBehaviour
|
||||
public CharaShaderEffectData ShaderEffectData;
|
||||
public List<MaterialHelper> Materials = new List<MaterialHelper>();
|
||||
|
||||
|
||||
public void Initialize(bool smile)
|
||||
{
|
||||
TrackTarget = new GameObject("TrackTarget").transform;
|
||||
TrackTarget.SetParent(transform);
|
||||
TrackTarget.position = HeadBone.transform.TransformPoint(0, 0, 10);
|
||||
|
||||
UpBodyPosition = UpBodyBone.transform.localPosition;
|
||||
UpBodyRotation = UpBodyBone.transform.localRotation;
|
||||
|
||||
//Models must be merged before handling extra morphs
|
||||
if (FaceDrivenKeyTarget && smile)
|
||||
FaceDrivenKeyTarget.ChangeMorphWeight(FaceDrivenKeyTarget.MouthMorphs[3], 1);
|
||||
|
||||
CreateIK();
|
||||
}
|
||||
|
||||
public void MergeModel()
|
||||
{
|
||||
if (!Body) return;
|
||||
var bodyBones = Body.GetComponentInChildren<SkinnedMeshRenderer>().bones.ToDictionary(bone => bone.name, bone => bone.transform);
|
||||
List<Transform> emptyBones = new List<Transform>();
|
||||
emptyBones.Add(Body.transform.Find("Position/Hip/Tail_Ctrl"));
|
||||
while (Body.transform.childCount > 0)
|
||||
{
|
||||
Body.transform.GetChild(0).SetParent(transform);
|
||||
}
|
||||
Body.SetActive(false); //for debugging
|
||||
|
||||
//MergeHead
|
||||
if (Head)
|
||||
{
|
||||
var headskins = Head.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
foreach (SkinnedMeshRenderer headskin in headskins)
|
||||
{
|
||||
MergeBone(headskin, bodyBones,ref emptyBones);
|
||||
}
|
||||
var eyes = new GameObject("Eyes");
|
||||
eyes.transform.SetParent(transform);
|
||||
while (Head.transform.childCount > 0)
|
||||
{
|
||||
var child = Head.transform.GetChild(0);
|
||||
child.SetParent(child.name.Contains("info") ? eyes.transform : transform);
|
||||
}
|
||||
Head.SetActive(false); //for debugging
|
||||
}
|
||||
|
||||
|
||||
//MergeTail
|
||||
if (Tail)
|
||||
{
|
||||
var tailskin = Tail.GetComponentInChildren<SkinnedMeshRenderer>();
|
||||
MergeBone(tailskin, bodyBones, ref emptyBones);
|
||||
while (Tail.transform.childCount > 0)
|
||||
{
|
||||
var child = Tail.transform.GetChild(0);
|
||||
child.SetParent(transform);
|
||||
}
|
||||
Tail.SetActive(false); //for debugging
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
//Materials
|
||||
foreach (var rend in gameObject.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
for(int i = 0; i < rend.materials.Length; i++)
|
||||
{
|
||||
Material mat = rend.materials[i];
|
||||
|
||||
var matHlp = Materials.FirstOrDefault(m => m.Mat == mat);
|
||||
if (matHlp == null)
|
||||
{
|
||||
matHlp = new MaterialHelper()
|
||||
{
|
||||
Mat = mat,
|
||||
Renderers = new Dictionary<Renderer, List<int>>(),
|
||||
Toggle = Instantiate(UmaViewerUI.Instance.UmaContainerTogglePrefab, UmaViewerUI.Instance.MaterialsList.content)
|
||||
};
|
||||
matHlp.Toggle.Name = mat.name;
|
||||
matHlp.Toggle.Toggle.onValueChanged.AddListener((value) => { Debug.Log("e"); matHlp.ToggleMaterials(value); });
|
||||
Materials.Add(matHlp);
|
||||
}
|
||||
|
||||
if (!matHlp.Renderers.ContainsKey(rend))
|
||||
{
|
||||
matHlp.Renderers.Add(rend, new List<int> { i });
|
||||
}
|
||||
else
|
||||
{
|
||||
matHlp.Renderers[rend].Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MergeHairModel()
|
||||
{
|
||||
if (!Head || !Hair) return;
|
||||
|
||||
var bodyBones = Head.GetComponentInChildren<SkinnedMeshRenderer>().bones.ToDictionary(bone => bone.name, bone => bone.transform);
|
||||
List<Transform> emptyBones = new List<Transform>();
|
||||
|
||||
var headHolder = Head.GetComponent<AssetHolder>();
|
||||
var hairHolder = Hair.GetComponent<AssetHolder>();
|
||||
|
||||
headHolder._assetTable.list.AddRange(hairHolder._assetTable.list);
|
||||
headHolder._assetTableValue.list.AddRange(hairHolder._assetTableValue.list);
|
||||
|
||||
//MergeHair
|
||||
var hairskins = Hair.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
foreach (SkinnedMeshRenderer hairskin in hairskins)
|
||||
{
|
||||
hairskin.gameObject.transform.SetParent(Head.transform);
|
||||
MergeBone(hairskin, bodyBones ,ref emptyBones);
|
||||
}
|
||||
Hair.gameObject.SetActive(false);
|
||||
|
||||
emptyBones.ForEach(a => { if (a) Destroy(a.gameObject); });
|
||||
}
|
||||
|
||||
public void SetHeight(int scale = 0)
|
||||
{
|
||||
if (scale == 0)
|
||||
{
|
||||
BodyScale = 1;
|
||||
}
|
||||
else if (scale == -1)
|
||||
{
|
||||
BodyScale = (Convert.ToInt32(CharaData[IsMob ? "chara_height" : "scale"]) / 160.7529f);
|
||||
}
|
||||
else
|
||||
{
|
||||
BodyScale = (scale / 160.7529f);
|
||||
}
|
||||
transform.Find("Position").localScale = new Vector3(BodyScale, BodyScale, BodyScale);
|
||||
}
|
||||
|
||||
public void MergeBone(SkinnedMeshRenderer from, Dictionary<string, Transform> targetBones,ref List<Transform> emptyBones)
|
||||
{
|
||||
var rootbone = targetBones[from.rootBone.name];
|
||||
if (rootbone) from.rootBone = rootbone;
|
||||
|
||||
Transform[] tmpBone = new Transform[from.bones.Length];
|
||||
for (int i = 0; i < tmpBone.Length; i++)
|
||||
{
|
||||
if (targetBones.TryGetValue(from.bones[i].name, out Transform targetbone))
|
||||
{
|
||||
tmpBone[i] = targetbone;
|
||||
from.bones[i].position = targetbone.position;
|
||||
while (from.bones[i].transform.childCount > 0)
|
||||
{
|
||||
from.bones[i].transform.GetChild(0).SetParent(targetbone);
|
||||
}
|
||||
emptyBones.Add(from.bones[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpBone[i] = from.bones[i];
|
||||
}
|
||||
}
|
||||
from.bones = tmpBone;
|
||||
}
|
||||
|
||||
public void LoadPhysics()
|
||||
{
|
||||
cySpringDataContainers = new List<CySpringDataContainer>(PhysicsContainer.GetComponentsInChildren<CySpringDataContainer>());
|
||||
var bones = new Dictionary<string,Transform>();
|
||||
foreach (var bone in GetComponentsInChildren<Transform>())
|
||||
{
|
||||
if (!bones.ContainsKey(bone.name))
|
||||
bones.Add(bone.name, bone);
|
||||
}
|
||||
|
||||
var colliders = new Dictionary<string, Transform>();
|
||||
|
||||
for (int i = 0; i < cySpringDataContainers.Count; i++)
|
||||
{
|
||||
colliders = UmaUtility.MergeDictionaries(colliders,cySpringDataContainers[i].InitiallizeCollider(bones));
|
||||
}
|
||||
|
||||
for (int i = 0; i < cySpringDataContainers.Count; i++)
|
||||
{
|
||||
cySpringDataContainers[i].InitializePhysics(bones, colliders);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDynamicBoneEnable(bool isOn)
|
||||
{
|
||||
if (IsMini) return;
|
||||
EnablePhysics = isOn;
|
||||
foreach (CySpringDataContainer cySpring in cySpringDataContainers)
|
||||
{
|
||||
cySpring.EnablePhysics(isOn);
|
||||
}
|
||||
}
|
||||
|
||||
Collider dragCollider;
|
||||
float dragdistance;
|
||||
Vector3 dragStartPos;
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsMini)
|
||||
{
|
||||
if (TrackTarget && EnableEyeTracking && !isAnimatorControl)
|
||||
{
|
||||
if (IK && !IK.enabled)
|
||||
{
|
||||
IK.enabled = true;
|
||||
if(PuppetMaster.mode != PuppetMaster.Mode.Active)
|
||||
{
|
||||
PuppetMaster.mode = PuppetMaster.Mode.Active;
|
||||
}
|
||||
}
|
||||
|
||||
var finalRotation = FaceDrivenKeyTarget.GetEyeTrackRotation(TrackTarget.transform.position);
|
||||
FaceDrivenKeyTarget.SetEyeTrack(finalRotation);
|
||||
|
||||
var cam = Camera.main;
|
||||
var distance = Mathf.Clamp(cam.transform.InverseTransformPoint(HeadBone.transform.position).magnitude - 0.1f, 0, 2);
|
||||
var mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
|
||||
var worldPos = cam.ScreenToWorldPoint(mousePos);
|
||||
|
||||
//Hold D key to Drag Body
|
||||
if (Input.GetKey(KeyCode.D))
|
||||
{
|
||||
if (dragCollider && dragCollider.attachedRigidbody)
|
||||
{
|
||||
if (PuppetMaster)
|
||||
{
|
||||
PuppetMaster.pinWeight = 0.75f;
|
||||
PuppetMaster.muscleWeight = 0.25f;
|
||||
}
|
||||
dragCollider.attachedRigidbody.isKinematic = true;
|
||||
dragCollider.transform.position = Vector3.Lerp(dragCollider.transform.position, cam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, dragdistance)) - dragStartPos, Time.fixedDeltaTime * 4);
|
||||
//LookAt Mouse when Dragging
|
||||
TrackTarget.position = Vector3.Lerp(TrackTarget.position, dragCollider.transform.position, Time.fixedDeltaTime * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Physics.Raycast(cam.ScreenPointToRay(mousePos), out RaycastHit hit))
|
||||
{
|
||||
dragCollider = hit.collider;
|
||||
dragStartPos = (hit.point - hit.collider.transform.position);
|
||||
dragdistance = cam.transform.InverseTransformPoint(hit.point).magnitude;
|
||||
}
|
||||
//LookAt Camera
|
||||
TrackTarget.position = Vector3.Lerp(TrackTarget.position, cam.transform.position, Time.fixedDeltaTime * 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PuppetMaster)
|
||||
{
|
||||
PuppetMaster.pinWeight = 1;
|
||||
PuppetMaster.muscleWeight = 1;
|
||||
}
|
||||
//LookAt Camera
|
||||
TrackTarget.position = Vector3.Lerp(TrackTarget.position, cam.transform.position, Time.fixedDeltaTime * 3);
|
||||
if (dragCollider && dragCollider.attachedRigidbody) dragCollider.attachedRigidbody.isKinematic = false;
|
||||
dragCollider = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IK && IK.enabled)
|
||||
{
|
||||
IK.enabled = false;
|
||||
if (PuppetMaster.mode != PuppetMaster.Mode.Kinematic)
|
||||
{
|
||||
PuppetMaster.mode = PuppetMaster.Mode.Kinematic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isAnimatorControl)
|
||||
{
|
||||
FaceDrivenKeyTarget.ProcessLocator();
|
||||
}
|
||||
|
||||
if (FaceMaterial)
|
||||
{
|
||||
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)
|
||||
{
|
||||
UmaViewerMain.Instance.AbList.TryGetValue(cutName, out UmaDatabaseEntry asset);
|
||||
UmaViewerBuilder.Instance.RecursiveLoadAsset(asset);
|
||||
}
|
||||
|
||||
public void SetEndAnimationCut()
|
||||
{
|
||||
UmaViewerUI.Instance.AnimationPause();
|
||||
}
|
||||
|
||||
public void UpBodyReset()
|
||||
{
|
||||
if (UpBodyBone)
|
||||
{
|
||||
UpBodyBone.transform.localPosition = UpBodyPosition;
|
||||
UpBodyBone.transform.localRotation = UpBodyRotation;
|
||||
}
|
||||
}
|
||||
|
||||
BipedIK IK;
|
||||
PuppetMaster PuppetMaster;
|
||||
public void CreateIK()
|
||||
{
|
||||
if (IsMini) return;
|
||||
var container = this;
|
||||
var animator = UmaAnimator;
|
||||
BipedRagdollReferences r = BipedRagdollReferences.FromAvatar(animator);
|
||||
BipedRagdollCreator.Options options = BipedRagdollCreator.AutodetectOptions(r);
|
||||
|
||||
var ik = container.gameObject.AddComponent<BipedIK>();
|
||||
ik.references.root = container.transform;
|
||||
ik.references.pelvis = r.hips;
|
||||
ik.references.spine = new Transform[] { r.spine, r.chest };
|
||||
ik.references.leftThigh = r.leftUpperLeg;
|
||||
ik.references.leftCalf = r.leftLowerLeg;
|
||||
ik.references.leftFoot = r.leftFoot;
|
||||
ik.references.rightThigh = r.rightUpperLeg;
|
||||
ik.references.rightCalf = r.rightLowerLeg;
|
||||
ik.references.rightFoot = r.rightFoot;
|
||||
ik.references.leftUpperArm = r.leftUpperArm;
|
||||
ik.references.leftForearm = r.leftLowerArm;
|
||||
ik.references.leftHand = r.leftHand;
|
||||
ik.references.rightUpperArm = r.rightUpperArm;
|
||||
ik.references.rightForearm = r.rightLowerArm;
|
||||
ik.references.rightHand = r.rightHand;
|
||||
ik.references.head = r.head;
|
||||
|
||||
new List<IKSolver>(ik.solvers.ikSolvers).ForEach(i => i.IKPositionWeight = 0);
|
||||
new List<IKSolverLimb>(ik.solvers.limbs).ForEach(i => i.IKRotationWeight = 0);
|
||||
ik.solvers.lookAt.IKPositionWeight = 1;
|
||||
ik.solvers.lookAt.headWeight = 0.8f;
|
||||
ik.solvers.lookAt.bodyWeight = 0.25f;
|
||||
ik.solvers.lookAt.clampWeightHead = 0.62f;
|
||||
ik.solvers.lookAt.target = TrackTarget.transform;
|
||||
ik.solvers.lookAt.spineWeightCurve = new AnimationCurve(new Keyframe[2] { new Keyframe(0f, 1f), new Keyframe(1f, 0.3f) });
|
||||
IK = ik;
|
||||
|
||||
BipedRagdollCreator.Create(r, options);
|
||||
PuppetMaster = PuppetMaster.SetUp(container.transform, 8, 9);
|
||||
PuppetMaster.solverIterationCount = 3;
|
||||
PuppetMaster.FlattenHierarchy();
|
||||
}
|
||||
protected UmaViewerBuilder Builder => UmaViewerBuilder.Instance;
|
||||
protected UmaViewerMain Main => UmaViewerMain.Instance;
|
||||
protected UmaViewerUI UI => UmaViewerUI.Instance;
|
||||
|
||||
public class MaterialHelper
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7c6a9fc3cd459843a63b765a5223b38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
public class UmaContainerProp : UmaContainer
|
||||
{
|
||||
public void LoadProp(UmaDatabaseEntry entry, Transform SetParent = null)
|
||||
{
|
||||
var go = entry.Get<GameObject>();
|
||||
var prop = Instantiate(go, SetParent ? SetParent : this.transform);
|
||||
|
||||
/*
|
||||
foreach (Renderer r in prop.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
foreach (Material m in r.sharedMaterials)
|
||||
{
|
||||
//Shaders can be differentiated by checking m.shader.name
|
||||
m.shader = Shader.Find("Unlit/Transparent Cutout");
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05abd4720709e3647ba1a239f87def58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,42 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Gallop;
|
||||
using System.IO;
|
||||
using static UmaViewerUI;
|
||||
using System;
|
||||
|
||||
public class UmaDatabaseEntry
|
||||
{
|
||||
public UmaFileType Type;
|
||||
public string Name;
|
||||
public string Url;
|
||||
public string Prerequisites;
|
||||
public string FilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}";
|
||||
if (!File.Exists(path) && Config.Instance.WorkMode == WorkMode.Standalone)
|
||||
{
|
||||
DownloadAsset(this);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Make it async
|
||||
public static void DownloadAsset(UmaDatabaseEntry entry)
|
||||
{
|
||||
var path = $"{Config.Instance.MainPath}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}";
|
||||
Debug.Log("Downloading:" + entry.Name);
|
||||
UmaViewerDownload.DownloadAssetSync(entry, path , delegate(string msg, UIMessageType type)
|
||||
{
|
||||
Instance.ShowMessage(msg, type);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class UmaCharaData
|
||||
{
|
||||
public int id;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
|
||||
|
||||
public class UmaDatabaseEntry
|
||||
{
|
||||
public UmaFileType Type;
|
||||
public string Name;
|
||||
public string Url;
|
||||
public string Checksum;
|
||||
public string Prerequisites;
|
||||
|
||||
public string FilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}";
|
||||
if (!File.Exists(path) && Config.Instance.WorkMode == WorkMode.Standalone)
|
||||
{
|
||||
DownloadAsset(this);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public T Get<T>(bool withDependencies = true)
|
||||
{
|
||||
UmaAssetManager.LoadAssetBundle(this, isRecursive: withDependencies);
|
||||
Object asset = UmaAssetManager.Get(this).LoadAllAssets().FirstOrDefault(a=>a.GetType() == typeof(T));
|
||||
return (T)System.Convert.ChangeType(asset, typeof(T));
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll<T>(bool withDependencies = true)
|
||||
{
|
||||
UmaAssetManager.LoadAssetBundle(this, isRecursive: withDependencies);
|
||||
IEnumerable<Object> assets = UmaAssetManager.Get(this).LoadAllAssets().Where(a => a.GetType() == typeof(T));
|
||||
return assets.Select(asset => (T)System.Convert.ChangeType(asset, typeof(T)));
|
||||
}
|
||||
|
||||
//TODO Make it async
|
||||
public static void DownloadAsset(UmaDatabaseEntry entry)
|
||||
{
|
||||
var path = $"{Config.Instance.MainPath}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}";
|
||||
UmaViewerDownload.DownloadAssetSync(entry, path, delegate (string msg, UIMessageType type)
|
||||
{
|
||||
UmaViewerUI.Instance.ShowMessage(msg, type);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2738c1f730a360045b019ee4912535bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+125
-723
File diff suppressed because it is too large
Load Diff
@@ -128,21 +128,15 @@ public class UmaViewerGlobalShader : MonoBehaviour
|
||||
{
|
||||
//Used to calculate the correct outline
|
||||
//Outline need more adjust in live
|
||||
if (UmaViewerBuilder.Instance.AnimationCamera != null)
|
||||
var umaContainer = UmaViewerBuilder.Instance.CurrentUMAContainer;
|
||||
if (umaContainer != null && umaContainer.UpBodyBone)
|
||||
{
|
||||
if (UmaViewerBuilder.Instance.CurrentUMAContainer)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
var upBone = umaContainer.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 = (umaContainer.IsMini ? 20f : 40.0f) * (distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad));
|
||||
Shader.SetGlobalFloat("_GlobalCameraFov", outlineWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -181,14 +181,15 @@ public class UmaViewerUI : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
if (Builder.CurrentUMAContainer != null && Builder.CurrentUMAContainer.OverrideController != null)
|
||||
var umaContainer = Builder.CurrentUMAContainer;
|
||||
if (umaContainer != null && umaContainer.OverrideController != null)
|
||||
{
|
||||
if (Builder.CurrentUMAContainer.OverrideController["clip_2"].name != "clip_2")
|
||||
if (umaContainer.OverrideController["clip_2"].name != "clip_2")
|
||||
{
|
||||
bool isLoop = Builder.CurrentUMAContainer.OverrideController["clip_2"].name.Contains("_loop");
|
||||
var AnimeState = Builder.CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0);
|
||||
var AnimeClip = Builder.CurrentUMAContainer.OverrideController["clip_2"];
|
||||
if (AnimeClip && Builder.CurrentUMAContainer.UmaAnimator.speed != 0)
|
||||
bool isLoop = umaContainer.OverrideController["clip_2"].name.Contains("_loop");
|
||||
var AnimeState = umaContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0);
|
||||
var AnimeClip = umaContainer.OverrideController["clip_2"];
|
||||
if (AnimeClip && umaContainer.UmaAnimator.speed != 0)
|
||||
{
|
||||
var normalizedTime = (isLoop) ? Mathf.Repeat(AnimeState.normalizedTime, 1) : Mathf.Min(AnimeState.normalizedTime, 1);
|
||||
AnimationTitleText.text = AnimeClip.name;
|
||||
@@ -837,7 +838,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
pageentry.OnClick = (container) =>
|
||||
{
|
||||
HighlightChildImage(animationList.content, container);
|
||||
Builder.LoadAsset(entry);
|
||||
(Builder.CurrentUMAContainer)?.LoadAnimation(entry);
|
||||
LoadedAnimation();
|
||||
};
|
||||
pageentrys.Add(pageentry);
|
||||
@@ -848,16 +849,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
foreach (var entry in filteredList.Where(a => a.Name.Contains($"/tail")))
|
||||
{
|
||||
var entryInstance = entry;
|
||||
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = Path.GetFileName(entry.Name);
|
||||
container.FontSize = 20;
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(animationList.content, container);
|
||||
Builder.LoadAsset(entryInstance);
|
||||
LoadedAnimation();
|
||||
});
|
||||
CreateAnimationSelectionPanel(entry, animationList.content);
|
||||
}
|
||||
pageManager.ResetCtrl();
|
||||
}
|
||||
@@ -865,16 +857,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
foreach (var entry in Main.AbMotions.Where(a => a.Name.Contains($"type00_ear") && !a.Name.EndsWith("driven") && !a.Name.Contains("touch")))
|
||||
{
|
||||
var entryInstance = entry;
|
||||
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = Path.GetFileName(entry.Name);
|
||||
container.FontSize = 20;
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(animationList.content, container);
|
||||
Builder.LoadAsset(entryInstance);
|
||||
LoadedAnimation();
|
||||
});
|
||||
CreateAnimationSelectionPanel(entry, animationList.content);
|
||||
}
|
||||
pageManager.ResetCtrl();
|
||||
}
|
||||
@@ -883,36 +866,31 @@ public class UmaViewerUI : MonoBehaviour
|
||||
//Common animations
|
||||
foreach (var entry in filteredList.Where(a => a.Name.Contains($"chara/chr{umaId}") && !a.Name.Contains("pose")))
|
||||
{
|
||||
var entryInstance = entry;
|
||||
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = Path.GetFileName(entry.Name);
|
||||
container.FontSize = 20;
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(animationList.content, container);
|
||||
Builder.LoadAsset(entryInstance);
|
||||
LoadedAnimation();
|
||||
});
|
||||
CreateAnimationSelectionPanel(entry, animationList.content);
|
||||
}
|
||||
|
||||
//Skill animations
|
||||
foreach (var entry in filteredList.Where(a => a.Name.Contains($"card/body/crd{umaId}")))
|
||||
{
|
||||
var entryInstance = entry;
|
||||
var container = Instantiate(UmaContainerPrefab, animationList.content).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = Path.GetFileName(entry.Name);
|
||||
container.FontSize = 20;
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(animationList.content, container);
|
||||
Builder.LoadAsset(entryInstance);
|
||||
LoadedAnimation();
|
||||
});
|
||||
CreateAnimationSelectionPanel(entry, animationList.content);
|
||||
}
|
||||
pageManager.ResetCtrl();
|
||||
}
|
||||
}
|
||||
|
||||
void CreateAnimationSelectionPanel(UmaDatabaseEntry entry, Transform parent)
|
||||
{
|
||||
var container = Instantiate(UmaContainerPrefab, parent).GetComponent<UmaUIContainer>();
|
||||
container.Name = container.name = Path.GetFileName(entry.Name);
|
||||
container.FontSize = 20;
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(parent, container);
|
||||
(Builder.CurrentUMAContainer)?.LoadAnimation(entry);
|
||||
LoadedAnimation();
|
||||
});
|
||||
}
|
||||
|
||||
void ListBackgrounds()
|
||||
{
|
||||
var pageentrys = new List<PageManager.Entry>();
|
||||
@@ -1071,29 +1049,19 @@ public class UmaViewerUI : MonoBehaviour
|
||||
public void SetDynamicBoneEnable(bool isOn)
|
||||
{
|
||||
DynamicBoneEnable = isOn;
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
Builder.CurrentUMAContainer.SetDynamicBoneEnable(isOn);
|
||||
}
|
||||
(Builder.CurrentUMAContainer)?.SetDynamicBoneEnable(isOn);
|
||||
}
|
||||
|
||||
public void SetEyeTrackingEnable(bool isOn)
|
||||
{
|
||||
EnableEyeTracking = isOn;
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
Builder.CurrentUMAContainer.EnableEyeTracking = isOn;
|
||||
}
|
||||
(Builder.CurrentUMAContainer)?.SetEyeTracking(isOn);
|
||||
}
|
||||
|
||||
public void SetFaceOverrideEnable(bool isOn)
|
||||
{
|
||||
EnableFaceOverride = isOn;
|
||||
var container = Builder.CurrentUMAContainer;
|
||||
if (container && container.FaceOverrideData)
|
||||
{
|
||||
container.FaceOverrideData.Enable = isOn;
|
||||
}
|
||||
(Builder.CurrentUMAContainer)?.SetFaceOverrideData(isOn);
|
||||
}
|
||||
|
||||
public void AudioPause()
|
||||
@@ -1185,7 +1153,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
var animator_cam = Builder.AnimationCameraAnimator;
|
||||
if (animator != null)
|
||||
{
|
||||
var AnimeClip = Builder.CurrentUMAContainer.OverrideController["clip_2"];
|
||||
var AnimeClip = container.OverrideController["clip_2"];
|
||||
|
||||
// Pause and Seek;
|
||||
animator.speed = 0;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Gallop
|
||||
{
|
||||
public class FaceDrivenKeyTarget : ScriptableObject
|
||||
{
|
||||
public UmaContainer Container;
|
||||
public UmaContainerCharacter Container;
|
||||
|
||||
public List<EyeTarget> _eyeTarget;
|
||||
public List<EyebrowTarget> _eyebrowTarget;
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace Gallop.Live.Cutt
|
||||
{
|
||||
public class LiveTimelineCharaLocator : ILiveTimelineCharactorLocator
|
||||
{
|
||||
public UmaContainer UmaContainer;
|
||||
public UmaContainerCharacter UmaContainer;
|
||||
|
||||
public Dictionary<string, Transform> Bones;
|
||||
|
||||
public LiveTimelineCharaLocator(UmaContainer umaContainer)
|
||||
public LiveTimelineCharaLocator(UmaContainerCharacter umaContainer)
|
||||
{
|
||||
UmaContainer = umaContainer;
|
||||
Bones = new Dictionary<string, Transform>();
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace Gallop.Live
|
||||
|
||||
public List<Transform> charaObjs;
|
||||
|
||||
public List<UmaContainer> CharaContainerScript = new List<UmaContainer>();
|
||||
public List<UmaContainerCharacter> CharaContainerScript = new List<UmaContainerCharacter>();
|
||||
|
||||
public List<Animation> charaAnims;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user