public static Quaternion getQuaternionFromBoneData( ref SkeletonBone bone, bool flip ) { Vector3 vZ; Vector3 vY; vZ.x = bone.m13; vZ.y = bone.m23; vZ.z = bone.m33; vY.x = bone.m12; vY.y = bone.m22; vY.z = bone.m32; if (!flip) { vZ.y = -vZ.y; vY.x = -vY.x; vY.z = -vY.z; } else { vZ.x = -vZ.x; vZ.y = -vZ.y; vY.z = -vY.z; } if (vZ.x != 0.0f || vZ.y != 0.0f || vZ.z != 0.0f) return Quaternion.LookRotation(vZ, vY); else return Quaternion.identity; }
static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.SkeletonBone o; o = new UnityEngine.SkeletonBone(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static void HumanDescription_skeleton(JSVCall vc) { if (vc.bGet) { UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj; var result = _this.skeleton; var arrRet = result; for (int i = 0; arrRet != null && i < arrRet.Length; i++) { JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]); JSApi.moveSaveID2Arr(i); } JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true); } else { UnityEngine.SkeletonBone[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.SkeletonBone[]>(() => { int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg); int length = JSApi.getArrayLength(jsObjID); var ret = new UnityEngine.SkeletonBone[length]; for (var i = 0; i < length; i++) { JSApi.getElement(jsObjID, i); ret[i] = (UnityEngine.SkeletonBone)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove); } return(ret); }); UnityEngine.HumanDescription _this = (UnityEngine.HumanDescription)vc.csObj; _this.skeleton = arg0; JSMgr.changeJSObj(vc.jsObjID, _this); } }
static public int set_rotation(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); UnityEngine.Quaternion v; checkType(l, 2, out v); o.rotation = v; setBack(l, o); return(0); }
static public int set_name(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); System.String v; checkType(l, 2, out v); o.name = v; setBack(l, o); return(0); }
static public int set_scale(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); UnityEngine.Vector3 v; checkType(l, 2, out v); o.scale = v; setBack(l, o); return(0); }
static public int set_transformModified(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); System.Int32 v; checkType(l, 2, out v); o.transformModified = v; setBack(l, o); return(0); }
private SkeletonBone DeSerializeSkeletonBone(BinaryReader br) { var res = new SkeletonBone(); res.name = br.ReadString(); res.position = DeserializeVector3(br); res.rotation = DeSerializeQuaternion(br); res.scale = DeserializeVector3(br); res.transformModified = br.ReadInt32(); return res; }
public static int constructor(IntPtr l) { try { UnityEngine.SkeletonBone o; o=new UnityEngine.SkeletonBone(); pushValue(l,o); return 1; } catch(Exception e) { LuaDLL.luaL_error(l, e.ToString()); return 0; } }
static public int ctor_s(IntPtr l) { try { UnityEngine.SkeletonBone o; o = new UnityEngine.SkeletonBone(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { UnityEngine.SkeletonBone o; o = new UnityEngine.SkeletonBone(); pushValue(l, o); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
public static int constructor(IntPtr l) { try { UnityEngine.SkeletonBone o; o=new UnityEngine.SkeletonBone(); pushValue(l,true); pushValue(l,o); return 2; } catch(Exception e) { return error(l,e); } }
static void SkeletonBone_scale(JSVCall vc) { if (vc.bGet) { UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; var result = _this.scale; JSApi.setVector3S((int)JSApi.SetType.Rval, result); } else { UnityEngine.Vector3 arg0 = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg); UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; _this.scale = arg0; JSMgr.changeJSObj(vc.jsObjID, _this); } }
static void SkeletonBone_rotation(JSVCall vc) { if (vc.bGet) { UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; var result = _this.rotation; JSMgr.datax.setObject((int)JSApi.SetType.Rval, result); } else { UnityEngine.Quaternion arg0 = (UnityEngine.Quaternion)JSMgr.datax.getObject((int)JSApi.GetType.Arg); UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; _this.rotation = arg0; JSMgr.changeJSObj(vc.jsObjID, _this); } }
static void SkeletonBone_transformModified(JSVCall vc) { if (vc.bGet) { UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; var result = _this.transformModified; JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result)); } else { System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg); UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; _this.transformModified = arg0; JSMgr.changeJSObj(vc.jsObjID, _this); } }
// fields static void SkeletonBone_name(JSVCall vc) { if (vc.bGet) { UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; var result = _this.name; JSApi.setStringS((int)JSApi.SetType.Rval, result); } else { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); UnityEngine.SkeletonBone _this = (UnityEngine.SkeletonBone)vc.csObj; _this.name = arg0; JSMgr.changeJSObj(vc.jsObjID, _this); } }
public static SkeletonBone[] cloneSkeleton( ref SkeletonBone[] bone ) { int size = bone.Length; SkeletonBone[] b = new HBP.SkeletonBone[size]; for(int i=0 ; i<size ; ++i) { b[i].posx = bone[i].posx; b[i].posy = bone[i].posy; b[i].posz = bone[i].posz; b[i].m11 = bone[i].m11; b[i].m12 = bone[i].m12; b[i].m13 = bone[i].m13; b[i].m21 = bone[i].m21; b[i].m22 = bone[i].m22; b[i].m23 = bone[i].m23; b[i].m31 = bone[i].m31; b[i].m32 = bone[i].m32; b[i].m33 = bone[i].m33; b[i].id = bone[i].id; } return b; }
/// <summary> /// Creates a Mecanim human description for a UMA character. /// </summary> /// <returns>The human description.</returns> /// <param name="umaData">UMA data.</param> /// <param name="umaTPose">UMA TPose.</param> public static HumanDescription CreateHumanDescription(UMAData umaData, UmaTPose umaTPose) { var res = new HumanDescription(); res.armStretch = 0; res.feetSpacing = 0; res.legStretch = 0; res.lowerArmTwist = 0.2f; res.lowerLegTwist = 1f; res.upperArmTwist = 0.5f; res.upperLegTwist = 0.1f; var animatedBones = umaData.GetAnimatedBones(); if (animatedBones.Length > 0) { List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>(umaTPose.boneInfo); foreach (var animatedBoneHash in animatedBones) { var animatedBone = umaData.GetBoneGameObject(animatedBoneHash).transform; var sb = new SkeletonBone(); sb.name = animatedBone.name; sb.position = animatedBone.localPosition; sb.rotation = animatedBone.localRotation; sb.scale = animatedBone.localScale; animatedSkeleton.Add(sb); } res.skeleton = animatedSkeleton.ToArray(); } else { res.skeleton = umaTPose.boneInfo; } res.human = umaTPose.humanInfo; SkeletonModifier(umaData, ref res.skeleton, res.human); return res; }
public static HumanDescription CreateHumanDescription(UMAData umaData, UmaTPose umaTPose) { var res = new HumanDescription(); res.armStretch = 0; res.feetSpacing = 0; res.legStretch = 0; res.lowerArmTwist = 0.2f; res.lowerLegTwist = 1f; res.upperArmTwist = 0.5f; res.upperLegTwist = 0.1f; var animatedBones = umaData.GetAnimatedBones(); if (animatedBones.Length > 0) { List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>(umaTPose.boneInfo); foreach (var animatedBoneHash in animatedBones) { var animatedBone = umaData.GetBoneGameObject(animatedBoneHash).transform; var sb = new SkeletonBone(); sb.name = animatedBone.name; sb.position = animatedBone.localPosition; sb.rotation = animatedBone.localRotation; sb.scale = animatedBone.localScale; animatedSkeleton.Add(sb); } res.skeleton = animatedSkeleton.ToArray(); } else { res.skeleton = umaTPose.boneInfo; } // List<HumanBone> animatedHuman = new List<HumanBone>(); // foreach (HumanBone bone in umaTPose.humanInfo) { // int animIndex = System.Array.IndexOf(umaData.animatedBones, bone.boneName); // if (animIndex > -1) { // animatedHuman.Add(bone); // } // else { // int traitIndex = System.Array.IndexOf(HumanTrait.BoneName, bone.humanName); // if (HumanTrait.RequiredBone(traitIndex)) { // animatedHuman.Add(bone); // } // } // } // List<SkeletonBone> animatedSkeleton = new List<SkeletonBone>(); // foreach (SkeletonBone bone in umaTPose.boneInfo) { // int animIndex = System.Array.IndexOf(umaData.animatedBones, bone.name); // if (animIndex > -1) { // animatedSkeleton.Add(bone); // } // } // res.human = animatedHuman.ToArray(); // res.skeleton = animatedSkeleton.ToArray(); res.human = umaTPose.humanInfo; res.skeleton[0].name = umaData.umaRoot.name; SkeletonModifier(umaData, ref res.skeleton); return res; }
private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones) { Dictionary<Transform, Transform> animatedBones = new Dictionary<Transform,Transform>(); for (var i = 0; i < umaData.animatedBones.Length; i++) { animatedBones.Add(umaData.animatedBones[i], umaData.animatedBones[i]); } for (var i = 0; i < bones.Length; i++) { var skeletonbone = bones[i]; UMAData.BoneData entry; if (umaData.boneHashList.TryGetValue(UMASkeleton.StringToHash(skeletonbone.name), out entry)) { //var entry = umaData.boneList[skeletonbone.name]; skeletonbone.position = entry.boneTransform.localPosition; //skeletonbone.rotation = entry.boneTransform.localRotation; skeletonbone.scale = entry.boneTransform.localScale; bones[i] = skeletonbone; animatedBones.Remove(entry.boneTransform); } } if (animatedBones.Count > 0) { var newBones = new List<SkeletonBone>(bones); // iterate original list rather than dictionary to ensure that relative order is preserved for (var i = 0; i < umaData.animatedBones.Length; i++) { var animatedBone = umaData.animatedBones[i]; if (animatedBones.ContainsKey(animatedBone)) { var newBone = new SkeletonBone(); newBone.name = animatedBone.name; newBone.position = animatedBone.localPosition; newBone.rotation = animatedBone.localRotation; newBone.scale = animatedBone.localScale; newBones.Add(newBone); } } bones = newBones.ToArray(); } }
private void Serialize(BinaryWriter bn, SkeletonBone bone) { bn.Write(bone.name); Serialize(bn, bone.position); Serialize(bn, bone.rotation); Serialize(bn, bone.scale); bn.Write(bone.transformModified); }
private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones) { for (var i = 0; i < bones.Length; i++) { var skeletonbone = bones[i]; UMAData.BoneData entry; if (umaData.boneHashList.TryGetValue(UMASkeleton.StringToHash(skeletonbone.name), out entry)) { //var entry = umaData.boneList[skeletonbone.name]; skeletonbone.position = entry.boneTransform.localPosition; //skeletonbone.rotation = entry.boneTransform.localRotation; skeletonbone.scale = entry.boneTransform.localScale; bones[i] = skeletonbone; } } }
private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones, HumanBone[] human) { // Dictionary<Transform, Transform> animatedBones = new Dictionary<Transform,Transform>(); Dictionary<int, Transform> animatedBones = new Dictionary<int, Transform>(); for (var i = 0; i < umaData.animatedBones.Length; i++) { // animatedBones.Add(umaData.animatedBones[i], umaData.animatedBones[i]); animatedBones.Add(UMAUtils.StringToHash(umaData.animatedBones[i].name), umaData.animatedBones[i]); } for (int i = 0; i < human.Length; i++) { int boneHash = UMAUtils.StringToHash(human[i].boneName); animatedBones[boneHash] = null; } for (var i = 0; i < bones.Length; i++) { var skeletonbone = bones[i]; UMAData.BoneData entry; int boneHash = UMAUtils.StringToHash(skeletonbone.name); GameObject boneGO = umaData.skeleton.GetBoneGameObject(boneHash); if (boneGO != null) { skeletonbone.position = boneGO.transform.localPosition; //skeletonbone.rotation = boneGO.transform.localRotation; skeletonbone.scale = boneGO.transform.localScale; bones[i] = skeletonbone; animatedBones.Remove(boneHash); } } bool foundSkelRoot = umaData.skeleton.HasBone(UMAUtils.StringToHash(bones[0].name)); if ((animatedBones.Count > 0) || !foundSkelRoot) { var newBones = new List<SkeletonBone>(bones); if (!foundSkelRoot) { int missingBoneCount = 0; int rootBoneHash = 0; while (!foundSkelRoot) { missingBoneCount++; rootBoneHash = UMAUtils.StringToHash(bones[missingBoneCount].name); foundSkelRoot = umaData.skeleton.HasBone(rootBoneHash); } if (missingBoneCount > 0) { missingBoneCount -= 2; newBones.RemoveRange(0, missingBoneCount); var realRootBone = umaData.transform; var newBone = newBones[0]; newBone.position = realRootBone.localPosition; newBone.rotation = realRootBone.localRotation; newBone.scale = realRootBone.localScale; newBone.name = realRootBone.name; newBones[0] = newBone; var rootBoneTransform = umaData.umaRoot.transform; newBone = newBones[1]; newBone.position = rootBoneTransform.localPosition; newBone.rotation = rootBoneTransform.localRotation; newBone.scale = rootBoneTransform.localScale; newBone.name = rootBoneTransform.name; newBones[1] = newBone; } } // iterate original list rather than dictionary to ensure that relative order is preserved for (var i = 0; i < umaData.animatedBones.Length; i++) { var animatedBone = umaData.animatedBones[i]; var animatedBoneHash = UMAUtils.StringToHash(animatedBone.name); if (animatedBones.ContainsKey(animatedBoneHash)) { var newBone = new SkeletonBone(); newBone.name = animatedBone.name; newBone.position = animatedBone.localPosition; newBone.rotation = animatedBone.localRotation; newBone.scale = animatedBone.localScale; newBones.Add(newBone); } } bones = newBones.ToArray(); } }
private static void SkeletonModifier(UMAData umaData, ref SkeletonBone[] bones, HumanBone[] human) { int missingBoneCount = 0; var newBones = new List<SkeletonBone>(bones.Length); while (!umaData.skeleton.HasBone(UMAUtils.StringToHash(bones[missingBoneCount].name))) { missingBoneCount++; } if (missingBoneCount > 0) { // force the two root transforms, reuse old bones entries to ensure any humanoid identifiers stay intact var realRootBone = umaData.transform; var newBone = bones[missingBoneCount - 2]; newBone.position = realRootBone.localPosition; newBone.rotation = realRootBone.localRotation; newBone.scale = realRootBone.localScale; // Debug.Log(newBone.name + "<-"+realRootBone.name); newBone.name = realRootBone.name; newBones.Add(newBone); var rootBoneTransform = umaData.umaRoot.transform; newBone = bones[missingBoneCount - 1]; newBone.position = rootBoneTransform.localPosition; newBone.rotation = rootBoneTransform.localRotation; newBone.scale = rootBoneTransform.localScale; // Debug.Log(newBone.name + "<-" + rootBoneTransform.name); newBone.name = rootBoneTransform.name; newBones.Add(newBone); } for (var i = missingBoneCount; i < bones.Length; i++) { var skeletonbone = bones[i]; int boneHash = UMAUtils.StringToHash(skeletonbone.name); GameObject boneGO = umaData.skeleton.GetBoneGameObject(boneHash); if (boneGO != null) { skeletonbone.position = boneGO.transform.localPosition; skeletonbone.scale = boneGO.transform.localScale; skeletonbone.rotation = umaData.skeleton.GetTPoseCorrectedRotation(boneHash, skeletonbone.rotation); newBones.Add(skeletonbone); } } bones = newBones.ToArray(); }
#pragma warning disable 618 private void ModifySkeletonBone(ref SkeletonBone bone, Transform trans) { bone.position = trans.localPosition; bone.rotation = trans.localRotation; bone.scale = trans.localScale; }
/// <summary> /// MMD用スケルトンボーン作成 /// </summary> /// <returns>スケルトンボーン</returns> SkeletonBone[] CreateSkeletonBone() { return bones_.Select(x=>{ SkeletonBone skeleton_bone = new SkeletonBone(); skeleton_bone.name = x.name; Transform transform = x.transform; skeleton_bone.position = transform.localPosition; skeleton_bone.rotation = transform.localRotation; skeleton_bone.scale = transform.localScale; return skeleton_bone; }).ToArray(); }
static public int get_position(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); pushValue(l, o.position); return(1); }
static public int get_scale(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); pushValue(l, o.scale); return(1); }
static int _CreateSkeletonBone(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 0); SkeletonBone obj = new SkeletonBone(); LuaScriptMgr.PushValue(L, obj); return 1; }
/// <summary> /// MMD用スケルトンボーン作成 /// </summary> /// <returns>スケルトンボーン</returns> SkeletonBone[] CreateSkeletonBone() { IEnumerable<GameObject> bones_enumerator = bones_; //Hipsボーンの親ボーン迄SkeletonBoneに入れる必要が有るので、確認と追加 string hips_bone_name = ((HasBone("腰"))? "腰": "センター"); Transform hips_parent_bone = bones_.Where(x=>x.name == hips_bone_name).Select(x=>x.transform.parent).FirstOrDefault(); if (null != hips_parent_bone) { //Hipsボーンの親ボーンが有るなら //Hipsボーンの親ボーンがbones_に含まれているか確認する if (!HasBone(hips_parent_bone.name)) { //Hipsボーンの親ボーンがbones_に無いなら //追加(Hipsボーン依りも前に追加しないといけないので注意) bones_enumerator = Enumerable.Repeat(hips_parent_bone.gameObject, 1) .Concat(bones_enumerator); } } var result = bones_enumerator.Select(x=>{ SkeletonBone skeleton_bone = new SkeletonBone(); skeleton_bone.name = x.name; Transform transform = x.transform; skeleton_bone.position = transform.localPosition; skeleton_bone.rotation = transform.localRotation; skeleton_bone.scale = transform.localScale; return skeleton_bone; }); return result.ToArray(); }
private static void SkeletonModifier(GameObject root, ref SkeletonBone[] bones) { var umaData = root.GetComponent<UMAData>(); for(var i = 0; i < bones.Length; i++) { var skeletonbone = bones[i]; UMAData.BoneData entry; if (umaData.boneList.TryGetValue(skeletonbone.name, out entry)) { //var entry = umaData.boneList[skeletonbone.name]; skeletonbone.position = entry.boneTransform.localPosition; //skeletonbone.rotation = entry.boneTransform.localRotation; skeletonbone.scale = entry.boneTransform.localScale; bones[i] = skeletonbone; } } }
internal static extern void UpdateSkeletonPose(SkeletonBone[] skeletonBones, SerializedProperty serializedProperty);
static public int get_transformModified(IntPtr l) { UnityEngine.SkeletonBone o = (UnityEngine.SkeletonBone)checkSelf(l); pushValue(l, o.transformModified); return(1); }