public static void ApplyBindposes(Mesh aMesh, Cal3DSkeleton aSkel) { Matrix4x4[] bindposes = new Matrix4x4[aSkel.bones.Count]; for (int i = 0; i < bindposes.Length; i++) { bindposes[i] = aSkel.bones[i].localToBone; } aMesh.bindposes = bindposes; }
public static AnimationClip CreateAnimation(Cal3DAnimation aAnim, Cal3DSkeleton aSkel, Transform[] aBones, Transform aRoot) { var clip = new AnimationClip(); clip.name = aAnim.name; foreach (var track in aAnim.tracks) { var xPosCurve = new AnimationCurve(); var yPosCurve = new AnimationCurve(); var zPosCurve = new AnimationCurve(); var xRotCurve = new AnimationCurve(); var yRotCurve = new AnimationCurve(); var zRotCurve = new AnimationCurve(); var wRotCurve = new AnimationCurve(); for (int i = 0; i < track.keyframes.Count; i++) { var kf = track.keyframes[i]; xPosCurve.AddKey(kf.time, kf.localPos.x); yPosCurve.AddKey(kf.time, kf.localPos.y); zPosCurve.AddKey(kf.time, kf.localPos.z); xRotCurve.AddKey(kf.time, kf.localRot.x); yRotCurve.AddKey(kf.time, kf.localRot.y); zRotCurve.AddKey(kf.time, kf.localRot.z); wRotCurve.AddKey(kf.time, kf.localRot.w); } var bone = aBones[track.boneID]; var pathname = AnimationUtility.CalculateTransformPath(bone, aRoot); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localPosition.x"), xPosCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localPosition.y"), yPosCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localPosition.z"), zPosCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localRotation.x"), xRotCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localRotation.y"), yRotCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localRotation.z"), zRotCurve); AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(pathname, typeof(Transform), "localRotation.w"), wRotCurve); } return(clip); }
public static Transform[] CreateSkeleton(Cal3DSkeleton aSkel, out Transform aRoot) { var bones = new Transform[aSkel.bones.Count]; for (int i = 0; i < bones.Length; i++) { bones[i] = new GameObject(aSkel.bones[i].name).transform; } for (int i = 0; i < bones.Length; i++) { var b = aSkel.bones[i]; var p = bones[i]; foreach (int child in b.children) { var c = bones[child]; c.SetParent(p, false); } p.localPosition = b.localPos; p.localRotation = b.localRot; } aRoot = (bones.Length > 0)?bones[0].root:null; return(bones); }