using System; using System.Collections.Generic; using System.Text; using UnityEngine; public class BoneMorph_ { public void Init() { if (this.bones != null) { for (int i = this.bones.Count - 1; i >= 0; i--) { BoneMorphLocal boneMorphLocal = this.bones[i]; if (boneMorphLocal.linkT != null) { boneMorphLocal.linkT.localPosition = boneMorphLocal.pos; } } } this.bones = new List(); } public void Uninit() { this.m_listBoneMorphPos.Clear(); this.m_listBoneMorphScl.Clear(); } public void InitBoneMorphEdit(Transform t, MPN f_mpn, TBody.SlotID f_slot) { if (f_mpn == MPN.head && f_slot == TBody.SlotID.head) { Transform transform = CMT.SearchObjName(t, "Mayupos", false); if (transform != null) { this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "MayuY"); this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("MayuY", transform)); } Transform transform2 = CMT.SearchObjName(t, "Eye_L", false); if (transform2 != null) { this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXL"); this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosXL", transform2)); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYL"); this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosYL", transform2, new Vector3(0.00325f, -0.005f, 0f), new Vector3(0f, 0.004f, 0f))); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXL"); this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclXL", transform2, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f))); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYL"); this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclYL", transform2, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f))); } Transform transform3 = CMT.SearchObjName(t, "Eye_R", false); if (transform3 != null) { this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXR"); this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosXR", transform3)); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYR"); this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosYR", transform3, new Vector3(0.00325f, 0.005f, 0f), new Vector3(0f, -0.004f, 0f))); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXR"); this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclXR", transform3, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f))); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYR"); this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclYR", transform3, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f))); } } } public void DelBoneMorphEdit(MPN f_mpn, TBody.SlotID f_slot) { if (f_mpn == MPN.head && f_slot == TBody.SlotID.head) { this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "MayuY"); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXL"); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYL"); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXL"); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXR"); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXR"); this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYR"); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYL"); this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYR"); } } private void AddRoot_lp(Transform t, int level = 0, float Kahanshin = 0f) { string name = t.name; if (name.Contains("Thigh")) { Kahanshin = 1f; } BoneMorphLocal boneMorphLocal = null; List list = null; if (BoneMorph.dic2.TryGetValue(name, out list)) { for (int i = 0; i < list.Count; i++) { BoneMorph.BoneProp boneProp = list[i]; if (boneMorphLocal == null) { boneMorphLocal = new BoneMorphLocal(); boneMorphLocal.atr = 0L; boneMorphLocal.linkT = t; boneMorphLocal.pos = t.localPosition; boneMorphLocal.Kahanshin = Kahanshin; } int nIndex = boneProp.nIndex; if (boneProp.bExistM) { boneMorphLocal.atr |= 1L << nIndex; boneMorphLocal.vecs_min[nIndex] = boneProp.vMinM; boneMorphLocal.vecs_max[nIndex] = boneProp.vMaxM; } if (boneProp.bExistP) { boneMorphLocal.atr |= 1L << nIndex + 32; boneMorphLocal.vecs_min[nIndex + 32] = boneProp.vMinP; boneMorphLocal.vecs_max[nIndex + 32] = boneProp.vMaxP; } boneMorphLocal.props.Add(boneProp.strProp); } } if (boneMorphLocal != null) { this.bones.Add(boneMorphLocal); } for (int j = 0; j < t.childCount; j++) { this.AddRoot_lp(t.GetChild(j), level + 1, Kahanshin); } } public void AddRoot(Transform root) { this.AddRoot_lp(root, 0, 0f); } public void ChangeMorphPosValue(string strPropName, string f_strBoneName, Vector3 f_fAddMin, Vector3 f_fAddMax) { BoneMorph_.BoneMorphPos boneMorphPos = this.m_listBoneMorphPos.Find((BoneMorph_.BoneMorphPos f) => f.strPropName == strPropName && f.trBone.name == f_strBoneName); if (boneMorphPos != null) { boneMorphPos.m_vAddMin = boneMorphPos.trBone.localPosition + f_fAddMin; boneMorphPos.m_vAddMax = boneMorphPos.trBone.localPosition + f_fAddMax; } } public void ChangeMorphSclValue(string strPropName, string f_strBoneName, Vector3 f_fAddMin, Vector3 f_fAddMax) { BoneMorph_.BoneMorphScl boneMorphScl = this.m_listBoneMorphScl.Find((BoneMorph_.BoneMorphScl f) => f.strPropName == strPropName && f.trBone.name == f_strBoneName); if (boneMorphScl != null) { boneMorphScl.m_vAddMin = boneMorphScl.trBone.localScale + f_fAddMin; boneMorphScl.m_vAddMax = boneMorphScl.trBone.localScale + f_fAddMax; } } public void Blend() { for (int i = this.bones.Count - 1; i >= 0; i--) { BoneMorphLocal boneMorphLocal = this.bones[i]; Vector3 vector = new Vector3(1f, 1f, 1f); Vector3 vector2 = boneMorphLocal.pos; for (int j = 0; j < BoneMorph.PropNames.Length; j++) { float num = 1f; if (j == 0) { num = this.SCALE_Kubi; } if (j == 1) { num = this.SCALE_Ude; } if (j == 2) { num = this.SCALE_EyeX; } if (j == 3) { num = this.SCALE_EyeY; } if (j == 4) { num = this.Postion_EyeX * (0.5f + this.Postion_EyeY * 0.5f); } if (j == 5) { num = this.Postion_EyeY; } if (j == 6) { num = this.SCALE_HeadX; } if (j == 7) { num = this.SCALE_HeadY; } if (j == 8) { num = this.SCALE_DouPer; if (boneMorphLocal.Kahanshin == 0f) { num = 1f - num; } } if (j == 9) { num = this.SCALE_Sintyou; } if (j == 10) { num = this.SCALE_Koshi; } if (j == 11) { num = this.SCALE_Kata; } if (j == 12) { num = this.SCALE_West; } if ((boneMorphLocal.atr & 1L << j) != 0L) { vector = Vector3.Scale(vector, Vector3.Lerp(boneMorphLocal.vecs_min[j], boneMorphLocal.vecs_max[j], num)); } if ((boneMorphLocal.atr & 1L << 32 + j) != 0L) { vector2 = Vector3.Scale(vector2, Vector3.Lerp(boneMorphLocal.vecs_min[j + 32], boneMorphLocal.vecs_max[j + 32], num)); } } if (boneMorphLocal.linkT.name.Contains("Thigh_SCL_")) { this.SnityouOutScale = Mathf.Pow(vector.x, 0.9f); } boneMorphLocal.linkT.localPosition = vector2; boneMorphLocal.linkT.localScale = vector; } for (int k = 0; k < this.m_listBoneMorphPos.Count; k++) { BoneMorph_.BoneMorphPos boneMorphPos = this.m_listBoneMorphPos[k]; if (boneMorphPos.strPropName == "MayuY") { boneMorphPos.trBone.localPosition = ((this.POS_MayuY > 0.5f) ? Vector3.Lerp(boneMorphPos.m_vDefPos, boneMorphPos.m_vAddMax, (this.POS_MayuY - 0.5f) / 0.5f) : Vector3.Lerp(boneMorphPos.m_vAddMin, boneMorphPos.m_vDefPos, this.POS_MayuY / 0.5f)); } else if (boneMorphPos.strPropName == "EyeBallPosYL" || boneMorphPos.strPropName == "EyeBallPosYR") { boneMorphPos.trBone.localPosition = ((this.EyeBallPosY > 0.5f) ? Vector3.Lerp(boneMorphPos.m_vDefPos, boneMorphPos.m_vAddMax, (this.EyeBallPosY - 0.5f) / 0.5f) : Vector3.Lerp(boneMorphPos.m_vAddMin, boneMorphPos.m_vDefPos, this.EyeBallPosY / 0.5f)); } } for (int l = 0; l < this.m_listBoneMorphScl.Count; l++) { BoneMorph_.BoneMorphScl boneMorphScl = this.m_listBoneMorphScl[l]; if (boneMorphScl.strPropName == "EyeBallSclXL" || boneMorphScl.strPropName == "EyeBallSclXR") { float z = (this.EyeBallSclX >= 0.5f) ? Mathf.Lerp(boneMorphScl.m_vDefScl.z, boneMorphScl.m_vAddMax.z, (this.EyeBallSclX - 0.5f) / 0.5f) : Mathf.Lerp(boneMorphScl.m_vAddMin.z, boneMorphScl.m_vDefScl.z, this.EyeBallSclX / 0.5f); Vector3 localScale = boneMorphScl.trBone.localScale; localScale.z = z; boneMorphScl.trBone.localScale = localScale; } else if (boneMorphScl.strPropName == "EyeBallSclYL" || boneMorphScl.strPropName == "EyeBallSclYR") { float y = (this.EyeBallSclY >= 0.5f) ? Mathf.Lerp(boneMorphScl.m_vDefScl.y, boneMorphScl.m_vAddMax.y, (this.EyeBallSclY - 0.5f) / 0.5f) : Mathf.Lerp(boneMorphScl.m_vAddMin.y, boneMorphScl.m_vDefScl.y, this.EyeBallSclY / 0.5f); Vector3 localScale2 = boneMorphScl.trBone.localScale; localScale2.y = y; boneMorphScl.trBone.localScale = localScale2; } } } private TextAsset textUserDef1; public float SCALE_Sintyou = 1f; public float SCALE_Koshi = 1f; public float SCALE_DouPer; public float SCALE_Kata = 1f; public float SCALE_West = 1f; public float SCALE_EyeX = 1f; public float SCALE_EyeY = 1f; public float Postion_EyeX = 1f; public float Postion_EyeY = 1f; public float EyeBallPosX = 0.5f; public float EyeBallPosY = 0.5f; public float EyeBallSclX = 0.5f; public float EyeBallSclY = 0.5f; public float SCALE_Kubi = 1f; public float SCALE_Ude = 1f; public float SCALE_HeadX = 1f; public float SCALE_HeadY = 1f; public float POS_MayuY = 0.5f; public List bones; public float SnityouOutScale = 1f; private bool m_bMayuOffs; private List m_listBoneMorphPos = new List(); private List m_listBoneMorphScl = new List(); private static StringBuilder sbMinM = new StringBuilder(32); private static StringBuilder sbMinP = new StringBuilder(32); private static StringBuilder sbMaxM = new StringBuilder(32); private static StringBuilder sbMaxP = new StringBuilder(32); private class BoneMorphPos { public BoneMorphPos(string f_strPropName, Transform f_trBone) { this.strPropName = f_strPropName; this.trBone = f_trBone; this.m_vAddMin = (this.m_vAddMax = (this.m_vDefPos = f_trBone.localPosition)); } public BoneMorphPos(string f_strPropName, Transform f_trBone, Vector3 f_vAddMin, Vector3 f_vAddMax) { this.strPropName = f_strPropName; this.trBone = f_trBone; this.m_vDefPos = f_trBone.localPosition; this.m_vAddMin = this.m_vDefPos + f_vAddMin; this.m_vAddMax = this.m_vDefPos + f_vAddMax; } public string strPropName; public Transform trBone; public Vector3 m_vDefPos; public Vector3 m_vAddMin; public Vector3 m_vAddMax; } private class BoneMorphScl { public BoneMorphScl(string f_strPropName, Transform f_trBone) { this.strPropName = f_strPropName; this.trBone = f_trBone; this.m_vAddMin = (this.m_vAddMax = (this.m_vDefScl = f_trBone.localScale)); } public BoneMorphScl(string f_strPropName, Transform f_trBone, Vector3 f_vAddMin, Vector3 f_vAddMax) { this.strPropName = f_strPropName; this.trBone = f_trBone; this.m_vDefScl = f_trBone.localScale; this.m_vAddMin = this.m_vDefScl + f_vAddMin; this.m_vAddMax = this.m_vDefScl + f_vAddMax; } public string strPropName; public Transform trBone; public Vector3 m_vDefScl; public Vector3 m_vAddMin; public Vector3 m_vAddMax; } }