public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton) { IO_MayaANIM anim = new IO_MayaANIM(); anim.Open(FileName); var animation = new SBAnimation(); animation.Name = Path.GetFileNameWithoutExtension(FileName); animation.FrameCount = anim.header.endTime - 1; foreach (var node in anim.Bones) { SBTransformAnimation a = new SBTransformAnimation(); a.Name = node.name; animation.TransformNodes.Add(a); foreach (var att in node.atts) { if (!trackTypeConversion.ContainsKey(att.type)) { continue; } SBTransformTrack track = new SBTransformTrack(trackTypeConversion[att.type]); a.Tracks.Add(track); foreach (var key in att.keys) { InterpolationType itype = InterpolationType.Linear; float intan = 0; float outtan = 0; if (key.intan == "fixed") { itype = InterpolationType.Hermite; intan = key.t1; } if (key.outtan == "fixed") { itype = InterpolationType.Hermite; outtan = key.t2; } track.AddKey(key.input - header.startTime, GetOutputValue(anim, att, key.output), itype, intan , outtan); } } } return(animation); }
private void ReadTransformAnimations(Anim animFile, AnimGroup animGroup, SBAnimation animation) { var decoder = new SsbhAnimTrackDecoder(animFile); foreach (AnimNode animNode in animGroup.Nodes) { SBTransformAnimation tfrmAnim = new SBTransformAnimation() { Name = animNode.Name }; SBTransformTrack X = new SBTransformTrack(SBTrackType.TranslateX); SBTransformTrack Y = new SBTransformTrack(SBTrackType.TranslateY); SBTransformTrack Z = new SBTransformTrack(SBTrackType.TranslateZ); SBTransformTrack RX = new SBTransformTrack(SBTrackType.RotateX); SBTransformTrack RY = new SBTransformTrack(SBTrackType.RotateY); SBTransformTrack RZ = new SBTransformTrack(SBTrackType.RotateZ); SBTransformTrack SX = new SBTransformTrack(SBTrackType.ScaleX); SBTransformTrack SY = new SBTransformTrack(SBTrackType.ScaleY); SBTransformTrack SZ = new SBTransformTrack(SBTrackType.ScaleZ); SBTransformTrack CompensateScale = new SBTransformTrack(SBTrackType.CompensateScale); tfrmAnim.Tracks.AddRange(new SBTransformTrack[] { X, Y, Z, RX, RY, RZ, SX, SY, SZ, CompensateScale }); foreach (AnimTrack track in animNode.Tracks) { object[] Transform = decoder.ReadTrack(track); if (track.Name.Equals("Transform")) { for (int i = 0; i < Transform.Length; i++) { AnimTrackTransform t = (AnimTrackTransform)Transform[i]; SBBone transform = new SBBone(); transform.Transform = GetMatrix((AnimTrackTransform)Transform[i]); X.AddKey(i, transform.X); Y.AddKey(i, transform.Y); Z.AddKey(i, transform.Z); RX.AddKey(i, transform.RX); RY.AddKey(i, transform.RY); RZ.AddKey(i, transform.RZ); SX.AddKey(i, transform.SX); SY.AddKey(i, transform.SY); SZ.AddKey(i, transform.SZ); CompensateScale.AddKey(i, t.CompensateScale); } } } animation.TransformNodes.Add(tfrmAnim); } }
/// <summary> /// /// </summary> /// <param name="fobj"></param> /// <returns></returns> private static SBTransformTrack DecodeFOBJ(HSD_FOBJ fobj) { SBTrackType trackType = SBTrackType.TranslateX; switch (fobj.JointTrackType) { case JointTrackType.HSD_A_J_ROTX: trackType = SBTrackType.RotateX; break; case JointTrackType.HSD_A_J_ROTY: trackType = SBTrackType.RotateY; break; case JointTrackType.HSD_A_J_ROTZ: trackType = SBTrackType.RotateZ; break; case JointTrackType.HSD_A_J_TRAX: trackType = SBTrackType.TranslateX; break; case JointTrackType.HSD_A_J_TRAY: trackType = SBTrackType.TranslateY; break; case JointTrackType.HSD_A_J_TRAZ: trackType = SBTrackType.TranslateZ; break; case JointTrackType.HSD_A_J_SCAX: trackType = SBTrackType.ScaleX; break; case JointTrackType.HSD_A_J_SCAY: trackType = SBTrackType.ScaleY; break; case JointTrackType.HSD_A_J_SCAZ: trackType = SBTrackType.ScaleZ; break; } SBTransformTrack track = new SBTransformTrack(trackType); var Keys = fobj.GetDecodedKeys(); // get current frame state AnimState prevState = null; for (int i = 0; i < Keys.Count; i++) { var state = GetState(Keys[i].Frame, Keys); bool nextSlope = i + 1 < Keys.Count && Keys[i + 1].InterpolationType == GXInterpolationType.HSD_A_OP_SLP; if (Keys[i].Frame == state.t1) { state.t0 = state.t1; state.p0 = state.p1; state.d0 = state.d1; } if (Keys[i].InterpolationType == GXInterpolationType.HSD_A_OP_SLP) { continue; } if (state.op_intrp == GXInterpolationType.HSD_A_OP_CON || state.op_intrp == GXInterpolationType.HSD_A_OP_KEY) { track.AddKey(state.t0, state.p0, InterpolationType.Step); } if (state.op_intrp == GXInterpolationType.HSD_A_OP_LIN) { track.AddKey(state.t0, state.p0, InterpolationType.Linear); } if (state.op_intrp == GXInterpolationType.HSD_A_OP_SPL || state.op_intrp == GXInterpolationType.HSD_A_OP_SPL0 || state.op_intrp == GXInterpolationType.HSD_A_OP_SLP) { track.AddKey(state.t0, state.p0, InterpolationType.Hermite, (nextSlope && prevState != null) ? prevState.d1 : state.d0, state.d0); } prevState = state; } return(track); }