public static void CreateANIM(string fname, Animation a, VBN vbn) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname)) { AnimHeader header = new AnimHeader(); file.WriteLine("animVersion " + header.animVersion + ";"); file.WriteLine("mayaVersion " + header.mayaVersion + ";"); file.WriteLine("timeUnit " + header.timeUnit + ";"); file.WriteLine("linearUnit " + header.linearUnit + ";"); file.WriteLine("angularUnit " + header.angularUnit + ";"); file.WriteLine("startTime " + 1 + ";"); file.WriteLine("endTime " + a.FrameCount + ";"); a.SetFrame(a.FrameCount - 1); //from last frame for (int li = 0; li < a.FrameCount; ++li) //go through each frame with nextFrame { a.NextFrame(vbn); } a.NextFrame(vbn); //go on first frame int i = 0; // writing node attributes foreach (Bone b in vbn.getBoneTreeOrder()) { i = vbn.boneIndex(b.Text); if (a.HasBone(b.Text)) { // write the bone attributes // count the attributes Animation.KeyNode n = a.GetBone(b.Text); int ac = 0; if (n.XPOS.HasAnimation()) { file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.XPOS, n, a.Size(), "translateX"); file.WriteLine("}"); } if (n.YPOS.HasAnimation()) { file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.YPOS, n, a.Size(), "translateY"); file.WriteLine("}"); } if (n.ZPOS.HasAnimation()) { file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.ZPOS, n, a.Size(), "translateZ"); file.WriteLine("}"); } if (n.XROT.HasAnimation()) { file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.XROT, n, a.Size(), "rotateX"); file.WriteLine("}"); } if (n.YROT.HasAnimation()) { file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.YROT, n, a.Size(), "rotateY"); file.WriteLine("}"); } if (n.ZROT.HasAnimation()) { file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.ZROT, n, a.Size(), "rotateZ"); file.WriteLine("}"); } if (n.XSCA.HasAnimation()) { file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.XSCA, n, a.Size(), "scaleX"); file.WriteLine("}"); } if (n.YSCA.HasAnimation()) { file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.YSCA, n, a.Size(), "scaleY"); file.WriteLine("}"); } if (n.ZSCA.HasAnimation()) { file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, n.ZSCA, n, a.Size(), "scaleZ"); file.WriteLine("}"); } } else { file.WriteLine("anim " + b.Text + " 0 0 0;"); } } } }
public Animation toAnimation(VBN vbn) { Animation animation = new Animation(anim.Name); animation.FrameCount = anim.frameCount; int i = 0; foreach (Bone b in vbn.getBoneTreeOrder()) { i = vbn.boneIndex(b.Text); if (i < anim.nodes.Count) { List <DAT_Animation.DATAnimTrack> tracks = anim.nodes[i]; Animation.KeyNode node = new Animation.KeyNode(b.Text); animation.Bones.Add(node); node.RotType = Animation.RotationType.EULER; foreach (DAT_Animation.DATAnimTrack track in tracks) { switch (track.type) { case DAT_Animation.AnimType.XPOS: node.XPOS = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.YPOS: node.YPOS = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.ZPOS: node.ZPOS = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.XROT: node.XROT = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.YROT: node.YROT = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.ZROT: node.ZROT = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.XSCA: node.XSCA = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.YSCA: node.YSCA = CreateKeyGroup(i, track, false); break; case DAT_Animation.AnimType.ZSCA: node.ZSCA = CreateKeyGroup(i, track, false); break; } } } } return(animation); }
public void createANIM(string fname, VBN vbn) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname)) { file.WriteLine("animVersion 1.1;"); file.WriteLine("mayaVersion 2014 x64;\ntimeUnit ntscf;\nlinearUnit cm;\nangularUnit deg;\nstartTime 1;\nendTime " + (anim.frameCount + 1) + ";"); int i = 0; // writing node attributes foreach (Bone b in vbn.getBoneTreeOrder()) { i = vbn.boneIndex(b.Text); if (i < anim.nodes.Count) { // write the bone attributes // count the attributes List <DAT_Animation.DATAnimTrack> tracks = anim.nodes[i]; int tracknum = 0; if (tracks.Count == 0) { file.WriteLine("anim " + b.Text + " 0 0 0;"); } foreach (DAT_Animation.DATAnimTrack track in tracks) { switch (track.type) { case DAT_Animation.AnimType.XPOS: file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; case DAT_Animation.AnimType.YPOS: file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; case DAT_Animation.AnimType.ZPOS: file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; case DAT_Animation.AnimType.XROT: file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, true); break; case DAT_Animation.AnimType.YROT: file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, true); break; case DAT_Animation.AnimType.ZROT: file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, true); break; case DAT_Animation.AnimType.XSCA: file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; case DAT_Animation.AnimType.YSCA: file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; case DAT_Animation.AnimType.ZSCA: file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (tracknum++) + ";"); WriteAnimKey(file, i, track, false); break; } } } else { file.WriteLine("anim " + b.Text + " 0 0 0;"); } } } }
public static void createANIM(string fname, SkelAnimation a, VBN vbn) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname)) { file.WriteLine("animVersion 1.1;"); file.WriteLine("mayaVersion 2014 x64;\ntimeUnit ntscf;\nlinearUnit cm;\nangularUnit deg;\nstartTime 1;\nendTime " + (a.size()) + ";"); a.setFrame(a.size() - 1); //from last frame for (int li = 0; li < a.size(); ++li) //go through each frame with nextFrame { a.nextFrame(vbn); } a.nextFrame(vbn); //go on first frame List <int> nodes = a.getNodes(true, vbn); //getting node indexes int i = 0; // writing node attributes foreach (Bone b in vbn.getBoneTreeOrder()) { i = vbn.boneIndex(b.Text); if (nodes.Contains(i)) { // write the bone attributes // count the attributes KeyNode n = a.getNode(0, i); int ac = 0; if (n.t_type != -1) { file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "translateX", n.t_type); file.WriteLine("}"); file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "translateY", n.t_type); file.WriteLine("}"); file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "translateZ", n.t_type); file.WriteLine("}"); } if (n.r_type != -1) { file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "rotateX", n.r_type); file.WriteLine("}"); file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "rotateY", n.r_type); file.WriteLine("}"); file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "rotateZ", n.r_type); file.WriteLine("}"); } if (n.s_type != -1) { file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "scaleX", n.s_type); file.WriteLine("}"); file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "scaleY", n.s_type); file.WriteLine("}"); file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (ac++) + ";"); writeKey(file, a, i, "scaleZ", n.s_type); file.WriteLine("}"); } } else { file.WriteLine("anim " + b.Text + " 0 0 0;"); } } } }