internal static Animation Load(FileSystem fs, string path) { List <AnimationForBone> afb = new List <AnimationForBone>(); using (Stream s = fs.open(path)) { BinaryReader br = new BinaryReader(s); int version = br.ReadInt32(); int bonecount = br.ReadInt32(); for (int boneid = 0; boneid < bonecount; ++boneid) { AnimationForBone ab = new AnimationForBone(); afb.Add(ab); int poscount = br.ReadInt32(); for (int posid = 0; posid < poscount; ++posid) { float time = br.ReadSingle(); vec3 pos = vec3.Read(br); ab.addPositon(time, pos); } int rotcount = br.ReadInt32(); for (int rotid = 0; rotid < rotcount; ++rotid) { float time = br.ReadSingle(); quat rot = quat.Read(br); ab.addRotation(time, rot); } } } return(new Animation(afb)); }
internal AnimationForBone sub(int start, int end) { AnimationForBone ab = new AnimationForBone(); float length = end - start; bool first = true; float last = 0; foreach (FramePosition fp in this.fp) { if (math1.IsBetween(start, fp.time, end)) { float mark = fp.time - start; if (first && math1.IsZero(mark) == false) { ab.addPositon(0, Interpolate(start, this.fp)); } mark = math1.ZeroOrValue(mark); first = false; ab.addPositon(mark, fp.location); last = mark; } } if (math1.isSame(length, last) == false) { ab.addPositon(length, Interpolate(end, this.fp)); } first = true; last = 0; foreach (FrameRotation fr in this.fr) { if (math1.IsBetween(start, fr.time, end)) { float mark = fr.time - start; if (first && math1.IsZero(mark) == false) { ab.addRotation(0, Interpolate(start, this.fr)); } mark = math1.ZeroOrValue(mark); first = false; ab.addRotation(mark, fr.rotation); last = mark; } } if (math1.isSame(length, last) == false) { ab.addRotation(length, Interpolate(end, this.fr)); } /*if (ab.fp.Count == 1) * { * AnimationForBone afb = ab; * ab = new AnimationForBone(); * ab.addPositon(start, afb.fp[0].location); * ab.addPositon(end, afb.fp[0].location); * * ab.addRotation(start, afb.fr[0].rotation); * ab.addRotation(end, afb.fr[0].rotation); * }*/ if (ab.fp.Count < 2 || ab.fr.Count < 2) { throw new Exception("Data error, need atleast 2 keyframes per animation"); } return(ab); }