private void createAnimationGroupToolStripMenuItem_Click(object sender, EventArgs e) { AnimationGroupNode ag = new AnimationGroupNode(); treeView1.Nodes.Add(ag); //ag.BeginEdit(); }
public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { Console.WriteLine("Reading Textue Pattern Animations ..."); TreeNode TexAnimation = new TreeNode() { Text = "Textue Pattern Animations" }; ThisAnimation.Nodes.Add(TexAnimation); TreeNode dummy = new TreeNode() { Text = "Animation Set" }; foreach (TexPatternAnim tex in b.TexPatternAnims.Values) { modelContainer.BFRES_MTA = new MTA(); BFRES_FVTX FVTX = new BFRES_FVTX(modelContainer.BFRES_MTA, tex, b); TexAnimation.Nodes.Add(modelContainer.BFRES_MTA); } }
public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { Console.WriteLine("Reading Shader Animations ..."); TreeNode TexAnimation = new TreeNode() { Text = "Shader Animations" }; ThisAnimation.Nodes.Add(TexAnimation); TreeNode dummy = new TreeNode() { Text = "Animation Set" }; foreach (ShaderParamAnim shd in b.ColorAnims.Values) { modelContainer.BFRES_MTA = new MTA(); BFRES_FSHU FSHU = new BFRES_FSHU(modelContainer.BFRES_MTA, shd, b); TexAnimation.Nodes.Add(modelContainer.BFRES_MTA); } foreach (ShaderParamAnim shd in b.ShaderParamAnims.Values) { modelContainer.BFRES_MTA = new MTA(); BFRES_FSHU FSHU = new BFRES_FSHU(modelContainer.BFRES_MTA, shd, b); TexAnimation.Nodes.Add(modelContainer.BFRES_MTA); } foreach (ShaderParamAnim shd in b.TexSrtAnims.Values) { modelContainer.BFRES_MTA = new MTA(); BFRES_FSHU FSHU = new BFRES_FSHU(modelContainer.BFRES_MTA, shd, b); TexAnimation.Nodes.Add(modelContainer.BFRES_MTA); } }
public void Read(string filename, BFRES bfres, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { Console.WriteLine("Reading Material Animations ..."); ResFile b = new ResFile(filename); ThisAnimation.Text = "Material Animations"; TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (MaterialAnim vis in b.MaterialAnims) { modelContainer.BFRES_MTA = new BFRES_MTA(vis); ThisAnimation.Nodes.Add(modelContainer.BFRES_MTA); } }
// temp stuff public static Dictionary <string, SkelAnimation> LoadAJ(string fname, VBN vbn) { // a note, I know that the main player file has the offsets for // animations, this is just for viewing FileData f = new FileData(fname); f.Endian = System.IO.Endianness.Big; int pos = 0; Dictionary <string, SkelAnimation> animations = new Dictionary <string, SkelAnimation>(); AnimationGroupNode group = new AnimationGroupNode() { Text = fname }; MainForm.Instance.animList.treeView1.Nodes.Add(group); while (pos < f.size()) { Console.WriteLine(pos.ToString("x")); int len = f.readInt(); DAT_Animation anim = new DAT_Animation(); anim.Read(new FileData(f.getSection(pos, len))); AnimTrack track = new AnimTrack(anim); if (pos == 0) { //track.Show(); } group.Nodes.Add(track.toAnimation(vbn)); SkelAnimation sa = track.BakeToSkel(vbn); //sa.Tag = track; //Runtime.Animations.Add(anim.Name, sa); // MainForm.Instance.animList.treeView1.Nodes.Add(anim.Name); animations.Add(anim.Name, sa); if (pos != 0) { track.Dispose(); track.Close(); } f.skip(len - 4); f.align(32); pos = f.pos(); } return(animations); }
public void ImportAnimation(string filename) { if (filename.ToLower().EndsWith(".pac")) { PAC p = new PAC(); p.Read(filename); AnimationGroupNode animGroup = new AnimationGroupNode() { Text = filename }; string groupname = null; foreach (var pair in p.Files) { if (pair.Key.EndsWith(".omo")) { var anim = OMOOld.read(new FileData(pair.Value)); animGroup.Nodes.Add(anim); string AnimName = Regex.Match(pair.Key, @"([A-Z][0-9][0-9])(.*)").Groups[0].ToString(); if (!string.IsNullOrEmpty(AnimName)) { if (groupname == null) { groupname = pair.Key.Replace(AnimName, ""); } anim.Text = AnimName; } //Runtime.acmdEditor.updateCrcList(); } else if (pair.Key.EndsWith(".mta")) { MTA mta = new MTA(); mta.read(new FileData(pair.Value)); mta.Text = pair.Key; animGroup.Nodes.Add(mta); } } if (groupname != null && !groupname.Equals("")) { animGroup.UseGroupName = true; animGroup.Text = groupname; } treeView1.Nodes.Add(animGroup); } }
public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { Console.WriteLine("Reading Material Animations ..."); TreeNode MaterialAnimation = new TreeNode() { Text = "Material Animations" }; ThisAnimation.Nodes.Add(MaterialAnimation); foreach (MaterialAnim vis in b.MaterialAnims) { modelContainer.BFRES_MTA = new BFRES.MTA(); PerMatAnim perAnim = new PerMatAnim(modelContainer.BFRES_MTA, vis); MaterialAnimation.Nodes.Add(modelContainer.BFRES_MTA); } }
public void Read(Syroot.NintenTools.NSW.Bfres.ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { TreeNode BoneVISAnimation = new TreeNode() { Text = "Bone Visual Animations" }; ThisAnimation.Nodes.Add(BoneVISAnimation); int i = 0; foreach (Syroot.NintenTools.NSW.Bfres.VisibilityAnim vis in b.BoneVisibilityAnims) { modelContainer.BFRES_MTA = new BFRES.MTA(); ReadVIS(modelContainer.BFRES_MTA, vis); BoneVISAnimation.Nodes.Add(modelContainer.BFRES_MTA); i++; } }
public void Read(ResFile b, AnimationGroupNode ThisAnimation, ModelContainer modelContainer) { Console.WriteLine("Reading Shape Animations ..."); TreeNode ShapeAnimation = new TreeNode() { Text = "Shape Animations" }; ThisAnimation.Nodes.Add(ShapeAnimation); int i = 0; foreach (ShapeAnim fsha in b.ShapeAnims) { modelContainer.BFRES_MTA = new BFRES.MTA(); PerShapeAnim perAnim = new PerShapeAnim(modelContainer.BFRES_MTA, fsha); ShapeAnimation.Nodes.Add(modelContainer.BFRES_MTA); } }
public static AnimationGroupNode Read(string filename) { bchHeader header = new bchHeader(); FileData f = new FileData(filename); f.Endian = System.IO.Endianness.Little; f.skip(4); header.backwardCompatibility = f.readByte(); header.forwardCompatibility = f.readByte(); header.version = f.readUShort(); header.mainHeaderOffset = f.readInt(); header.stringTableOffset = f.readInt(); header.gpuCommandsOffset = f.readInt(); header.dataOffset = f.readInt(); if (header.backwardCompatibility > 0x20) { header.dataExtendedOffset = f.readInt(); } header.relocationTableOffset = f.readInt(); header.mainHeaderLength = f.readInt(); header.stringTableLength = f.readInt(); header.gpuCommandsLength = f.readInt(); header.dataLength = f.readInt(); if (header.backwardCompatibility > 0x20) { header.dataExtendedLength = f.readInt(); } header.relocationTableLength = f.readInt(); header.uninitializedDataSectionLength = f.readInt(); header.uninitializedDescriptionSectionLength = f.readInt(); if (header.backwardCompatibility > 7) { header.flags = f.readUShort(); header.addressCount = f.readUShort(); } // Relocation table for (int i = 0; i < header.relocationTableLength; i += 4) { f.seek(header.relocationTableOffset + i); int val = f.readInt(); int off = val & 0x1FFFFFF; byte flag = (byte)(val >> 25); switch (flag) { case 0: f.seek((off * 4) + header.mainHeaderOffset); f.writeInt((off * 4) + header.mainHeaderOffset, f.readInt() + header.mainHeaderOffset); break; case 1: f.seek(off + header.mainHeaderOffset); f.writeInt((off) + header.mainHeaderOffset, f.readInt() + header.stringTableOffset); break; case 2: f.seek((off * 4) + header.mainHeaderOffset); f.writeInt((off * 4) + header.mainHeaderOffset, f.readInt() + header.gpuCommandsOffset); break; case 0xc: f.seek((off * 4) + header.mainHeaderOffset); f.writeInt((off * 4) + header.mainHeaderOffset, f.readInt() + header.dataOffset); break; } } // Content Header f.seek(header.mainHeaderOffset); bchContentHeader content = new bchContentHeader(); { content.modelsPointerTableOffset = f.readInt(); content.modelsPointerTableEntries = f.readInt(); content.modelsNameOffset = f.readInt(); content.materialsPointerTableOffset = f.readInt(); content.materialsPointerTableEntries = f.readInt(); content.materialsNameOffset = f.readInt(); content.shadersPointerTableOffset = f.readInt(); content.shadersPointerTableEntries = f.readInt(); content.shadersNameOffset = f.readInt(); content.texturesPointerTableOffset = f.readInt(); content.texturesPointerTableEntries = f.readInt(); content.texturesNameOffset = f.readInt(); content.materialsLUTPointerTableOffset = f.readInt(); content.materialsLUTPointerTableEntries = f.readInt(); content.materialsLUTNameOffset = f.readInt(); content.lightsPointerTableOffset = f.readInt(); content.lightsPointerTableEntries = f.readInt(); content.lightsNameOffset = f.readInt(); content.camerasPointerTableOffset = f.readInt(); content.camerasPointerTableEntries = f.readInt(); content.camerasNameOffset = f.readInt(); content.fogsPointerTableOffset = f.readInt(); content.fogsPointerTableEntries = f.readInt(); content.fogsNameOffset = f.readInt(); content.skeletalAnimationsPointerTableOffset = f.readInt(); content.skeletalAnimationsPointerTableEntries = f.readInt(); content.skeletalAnimationsNameOffset = f.readInt(); content.materialAnimationsPointerTableOffset = f.readInt(); content.materialAnimationsPointerTableEntries = f.readInt(); content.materialAnimationsNameOffset = f.readInt(); content.visibilityAnimationsPointerTableOffset = f.readInt(); content.visibilityAnimationsPointerTableEntries = f.readInt(); content.visibilityAnimationsNameOffset = f.readInt(); content.lightAnimationsPointerTableOffset = f.readInt(); content.lightAnimationsPointerTableEntries = f.readInt(); content.lightAnimationsNameOffset = f.readInt(); content.cameraAnimationsPointerTableOffset = f.readInt(); content.cameraAnimationsPointerTableEntries = f.readInt(); content.cameraAnimationsNameOffset = f.readInt(); content.fogAnimationsPointerTableOffset = f.readInt(); content.fogAnimationsPointerTableEntries = f.readInt(); content.fogAnimationsNameOffset = f.readInt(); content.scenePointerTableOffset = f.readInt(); content.scenePointerTableEntries = f.readInt(); content.sceneNameOffset = f.readInt(); } //Skeletal animation AnimationGroupNode ThisAnimation = new AnimationGroupNode() { Text = filename }; for (int index1 = 0; index1 < content.skeletalAnimationsPointerTableEntries; index1++)// { f.seek(content.skeletalAnimationsPointerTableOffset + (index1 * 4)); int dataOffset = f.readInt(); f.seek(dataOffset); string skeletalAnimationName = f.readString(f.readInt(), -1); int animationFlags = f.readInt(); //int skeletalAnimationloopMode = f.readByte(); //pas ça du tout float skeletalAnimationframeSize = f.readFloat(); int boneTableOffset = f.readInt(); int boneTableEntries = f.readInt(); int metaDataPointerOffset = f.readInt(); //Runtime.Animations.Add(skeletalAnimationName, a); //MainForm.animNode.Nodes.Add(skeletalAnimationName); //Debug.WriteLine("Animation Name: " + skeletalAnimationName); Animation a = new Animation(skeletalAnimationName); ThisAnimation.Nodes.Add(a); for (int i = 0; i < boneTableEntries; i++) { f.seek(boneTableOffset + (i * 4)); int offset = f.readInt(); Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); f.seek(offset); bone.Text = f.readString(f.readInt(), -1); //Console.WriteLine("Bone Name: " + bone.name); int animationTypeFlags = f.readInt(); uint flags = (uint)f.readInt(); OSegmentType segmentType = (OSegmentType)((animationTypeFlags >> 16) & 0xf); //Debug.WriteLine(bone.Text + " " + flags.ToString("x")); switch (segmentType) { case OSegmentType.transform: f.seek(offset + 0xC); //Console.WriteLine(f.pos().ToString("x") + " " + flags.ToString("x")); uint notExistMask = 0x10000; uint constantMask = 0x40; for (int j = 0; j < 3; j++) { for (int axis = 0; axis < 3; axis++) { bool notExist = (flags & notExistMask) > 0; bool constant = (flags & constantMask) > 0; //Console.WriteLine(notExist + " " + constant); Animation.KeyGroup group = new Animation.KeyGroup(); //frame.exists = !notExist; if (!notExist) { if (constant) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.LINEAR; frame.Value = f.readFloat(); frame.Frame = 0; group.Keys.Add(frame); } else { int frameOffset = f.readInt(); int position = f.pos(); f.seek(frameOffset); float c = 0; //Debug.WriteLine(j + " " + axis + " " + bone.Text); getAnimationKeyFrame(f, group, out c); if (c > a.FrameCount) { a.FrameCount = (int)c; } f.seek(position); } } else { f.seek(f.pos() + 0x04); } bone.RotType = Animation.RotationType.EULER; if (j == 0) { switch (axis) { case 0: bone.XSCA = group; break; case 1: bone.YSCA = group; break; case 2: bone.ZSCA = group; break; } } else if (j == 1) { switch (axis) { case 0: bone.XROT = group; break; case 1: bone.YROT = group; break; case 2: bone.ZROT = group; break; } } else if (j == 2) { switch (axis) { case 0: bone.XPOS = group; break; case 1: bone.YPOS = group; break; case 2: bone.ZPOS = group; break; } } notExistMask <<= 1; constantMask <<= 1; } if (j == 1) { constantMask <<= 1; } } break; /*case OSegmentType.transformQuaternion: * bone.isFrameFormat = true; * * int scaleOffset = f.readInt(); * int rotationOffset = f.readInt(); * int translationOffset = f.readInt(); * * if ((flags & 0x20) == 0) * { * bone.scale.exists = true; * f.seek(scaleOffset); * * if ((flags & 4) > 0) * { * bone.scale.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * 0)); * } * else * { * bone.scale.startFrame = f.readFloat(); * bone.scale.endFrame = f.readFloat(); * * int scaleFlags = f.readInt(); * int scaleDataOffset = f.readInt(); * int scaleEntries = f.readInt(); * * f.seek(scaleDataOffset); * for (int j = 0; j < scaleEntries; j++) * { * bone.scale.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * 0)); * } * } * } * * if ((flags & 0x10) == 0) * { * bone.rotationQuaternion.exists = true; * f.seek(rotationOffset); * * if ((flags & 2) > 0) * { * bone.rotationQuaternion.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * f.readFloat())); * } * else * { * bone.rotationQuaternion.startFrame = f.readFloat(); * bone.rotationQuaternion.endFrame = f.readFloat(); * * int rotationFlags = f.readInt(); * int rotationDataOffset = f.readInt(); * int rotationEntries = f.readInt(); * * f.seek(rotationDataOffset); * for (int j = 0; j < rotationEntries; j++) * { * bone.rotationQuaternion.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * f.readFloat())); * } * } * } * * if ((flags & 8) == 0) * { * bone.translation.exists = true; * f.seek(translationOffset); * * if ((flags & 1) > 0) * { * bone.translation.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * 0)); * } * else * { * bone.translation.startFrame = f.readFloat(); * bone.translation.endFrame = f.readFloat(); * * int translationFlags = f.readInt(); * int translationDataOffset = f.readInt(); * int translationEntries = f.readInt(); * * f.seek(translationDataOffset); * for (int j = 0; j < translationEntries; j++) * { * bone.translation.vector.Add(new Vector4( * f.readFloat(), * f.readFloat(), * f.readFloat(), * 0)); * } * } * } * * break; * case OSegmentType.transformMatrix: * bone.isFullBakedFormat = true; * * f.readInt(); * f.readInt(); * int matrixOffset = f.readInt(); * int entries = f.readInt(); * * f.seek(matrixOffset); * for (int j = 0; j < entries; j++) * { * OMatrix transform = new OMatrix(); * transform.M11 = f.readFloat(); * transform.M21 = f.readFloat(); * transform.M31 = f.readFloat(); * transform.M41 = f.readFloat(); * * transform.M12 = f.readFloat(); * transform.M22 = f.readFloat(); * transform.M32 = f.readFloat(); * transform.M42 = f.readFloat(); * * transform.M13 = f.readFloat(); * transform.M23 = f.readFloat(); * transform.M33 = f.readFloat(); * transform.M43 = f.readFloat(); * * bone.transform.Add(transform); * } * * break;*/ default: throw new Exception(string.Format("BCH: Unknow Segment Type {0} on Skeletal Animation bone {1}! STOP!", segmentType, bone.Text)); } //skeletalAnimation.bone.Add(bone); } } //return a; return(ThisAnimation); }
public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES) { FileData f = new FileData(filename); f.seek(0); f.Endian = Endianness.Little; Console.WriteLine("Reading Animations ..."); f.seek(4); // magic check int SwitchCheck = f.readInt(); //Switch version only has padded magic f.skip(4); if (SwitchCheck == 0x20202020) { // SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u ResNSW.ResFile b = new ResNSW.ResFile(filename); AnimationGroupNode ThisAnimation = new AnimationGroupNode() { Text = "Skeleton Animations" }; TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims) { Animation a = new Animation(ska.Name); ThisAnimation.Nodes.Add(a); a.FrameCount = ska.FrameCount; i++; try { foreach (Syroot.NintenTools.NSW.Bfres.BoneAnim bn in ska.BoneAnims) { FSKANode bonean = new FSKANode(bn); Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); if (ska.FlagsRotate == ResNSW.SkeletalAnimFlagsRotate.EulerXYZ) { bone.RotType = Animation.RotationType.EULER; } else { bone.RotType = Animation.RotationType.QUATERNION; } bone.Text = bonean.Text; for (int Frame = 0; Frame < ska.FrameCount; Frame++) { //Set base/start values for bones. //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false) { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); bone.XROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.X }); bone.YROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Y }); bone.ZROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Z }); bone.XPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.X }); bone.YPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Y }); bone.ZPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Z }); } foreach (FSKATrack track in bonean.tracks) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.HERMITE; frame.Frame = Frame; FSKAKey left = track.GetLeft(Frame); FSKAKey right = track.GetRight(Frame); float value; value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); // interpolate the value and apply switch (track.flag) { case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break; case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break; case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break; case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break; case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break; case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break; case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break; case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break; case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break; } } } } } catch { } } return(ThisAnimation); } else { f.eof(); TargetWiiUBFRES = new ResFile(filename); ThisAnimation = new AnimationGroupNode() { Text = "Skeleton Animations" }; TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values) { Animation a = new Animation(ska.Name); ThisAnimation.Nodes.Add(a); a.FrameCount = ska.FrameCount; i++; try { foreach (BoneAnim bn in ska.BoneAnims) { FSKANodeWiiU bonean = new FSKANodeWiiU(bn); Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ) { bone.RotType = Animation.RotationType.EULER; } else { bone.RotType = Animation.RotationType.QUATERNION; } bone.Text = bonean.Text; for (int Frame = 0; Frame < ska.FrameCount; Frame++) { //Set base/start values for bones. //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false) { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.X }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Y }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Z }); bone.XROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.X }); bone.YROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Y }); bone.ZROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Z }); bone.XPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.X }); bone.YPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Y }); bone.ZPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Z }); } foreach (FSKATrack track in bonean.tracks) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.HERMITE; frame.Frame = Frame; FSKAKey left = track.GetLeft(Frame); FSKAKey right = track.GetRight(Frame); float value; value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); // interpolate the value and apply switch (track.flag) { case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break; case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break; case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break; case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break; case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break; case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break; case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break; case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break; case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break; } } } } } catch { } } return(ThisAnimation); } }
public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES, BFRES bfres) { string path = filename; FileData f = new FileData(filename); int Magic = f.readInt(); if (Magic == 0x59617A30) //YAZO compressed { using (FileStream input = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read)) { Yaz0Compression.Decompress(path, TEMP_FILE); path = TEMP_FILE; } } f = new FileData(path); f.seek(0); f.Endian = Endianness.Little; Console.WriteLine("Reading Animations ..."); f.seek(4); // magic check int SwitchCheck = f.readInt(); //Switch version only has padded magic f.skip(4); // SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u Syroot.NintenTools.NSW.Bfres.ResFile b = new Syroot.NintenTools.NSW.Bfres.ResFile(path); AnimationGroupNode ThisAnimation = new AnimationGroupNode() { Text = "Bone Visual Animations" }; TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (Syroot.NintenTools.NSW.Bfres.VisibilityAnim vis in b.BoneVisibilityAnims) { Animation a = new Animation(vis.Name); ThisAnimation.Nodes.Add(a); a.FrameCount = vis.FrameCount; i++; int boneindx = 0; if (vis.Names != null) { foreach (string nm in vis.Names) //Loop through every bone. Not all have base and curve data { Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); bone.Text = vis.Names[boneindx]; if (boneindx < vis.BaseDataList.Length) { bool bas = vis.BaseDataList[boneindx]; if (bas == true) { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 1 }); } else { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 0 }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 0 }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = 0 }); } } if (vis.Curves.Count != 0) { if (boneindx < vis.Curves.Count) { Syroot.NintenTools.NSW.Bfres.AnimCurve cr = vis.Curves[boneindx]; Console.WriteLine($"{vis.Name} {vis.Names[boneindx]}"); int frm = 0; foreach (bool bn in cr.KeyStepBoolData) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.STEP; frame.Frame = cr.Frames[frm]; Console.WriteLine(vis.Name + " " + vis.Names[boneindx] + " " + bn); switch (bn) { case true: frame.Value = 1; bone.XSCA.Keys.Add(frame); frame.Value = 1; bone.YSCA.Keys.Add(frame); frame.Value = 1; bone.ZSCA.Keys.Add(frame); break; case false: frame.Value = 0; bone.XSCA.Keys.Add(frame); frame.Value = 0; bone.YSCA.Keys.Add(frame); frame.Value = 0; bone.ZSCA.Keys.Add(frame); break; } frm++; } } } boneindx++; } } } return(ThisAnimation); }
public void Read(ResFile TargetWiiUBFRES, AnimationGroupNode ThisAnimation, ResNSW.ResFile b) { Console.WriteLine("Reading Skeleton Animations ..."); if (b != null) { TreeNode SkeletonAnimation = new TreeNode() { Text = "Skeleton Animations" }; ThisAnimation.Nodes.Add(SkeletonAnimation); TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims) { if (i == 0) { dummy = new TreeNode() { Text = "Animation Set " + "0 - 100" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 100) { dummy = new TreeNode() { Text = "Animation Set " + "100 - 200" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 200) { dummy = new TreeNode() { Text = "Animation Set " + "200 - 300" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 300) { dummy = new TreeNode() { Text = "Animation Set " + "300 - 400" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 400) { dummy = new TreeNode() { Text = "Animation Set " + "400 - 500" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 500) { dummy = new TreeNode() { Text = "Animation Set " + "500 - 600" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 600) { dummy = new TreeNode() { Text = "Animation Set " + "600 - 700" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 700) { dummy = new TreeNode() { Text = "Animation Set " + "700 - 800" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 800) { dummy = new TreeNode() { Text = "Animation Set " + "800 - 900" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 900) { dummy = new TreeNode() { Text = "Animation Set " + "900 - 1000" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 1000) { dummy = new TreeNode() { Text = "Animation Set " + "1000+" }; SkeletonAnimation.Nodes.Add(dummy); } Animation a = new Animation(ska.Name); SkeletonAnimations.Add(a); a.FrameCount = ska.FrameCount; if (i >= 0 && i < 100) { SkeletonAnimation.Nodes[0].Nodes.Add(a); } if (i >= 100 && i < 200) { SkeletonAnimation.Nodes[1].Nodes.Add(a); } if (i >= 200 && i < 300) { SkeletonAnimation.Nodes[2].Nodes.Add(a); } if (i >= 300 && i < 400) { SkeletonAnimation.Nodes[3].Nodes.Add(a); } if (i >= 400 && i < 500) { SkeletonAnimation.Nodes[4].Nodes.Add(a); } if (i >= 500 && i < 600) { SkeletonAnimation.Nodes[5].Nodes.Add(a); } if (i >= 600 && i < 700) { SkeletonAnimation.Nodes[6].Nodes.Add(a); } if (i >= 700 && i < 800) { SkeletonAnimation.Nodes[7].Nodes.Add(a); } if (i >= 800 && i < 900) { SkeletonAnimation.Nodes[8].Nodes.Add(a); } if (i >= 900 && i < 1000) { SkeletonAnimation.Nodes[9].Nodes.Add(a); } i++; try { foreach (ResNSW.BoneAnim bn in ska.BoneAnims) { FSKANode bonean = new FSKANode(bn); Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); if (ska.FlagsRotate == ResNSW.SkeletalAnimFlagsRotate.EulerXYZ) { bone.RotType = Animation.RotationType.EULER; } else { bone.RotType = Animation.RotationType.QUATERNION; } bone.Text = bonean.Text; for (int Frame = 0; Frame < ska.FrameCount; Frame++) { //Set base/start values for bones. //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these if (Frame == 0) { if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Scale)) { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.X }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Y }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Z }); } if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Rotate)) { bone.XROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.X }); bone.YROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Y }); bone.ZROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Z }); bone.WROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.W }); } if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Translate)) { bone.XPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.X }); bone.YPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Y }); bone.ZPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Z }); } } foreach (FSKATrack track in bonean.tracks) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.HERMITE; frame.Frame = Frame; FSKAKey left = track.GetLeft(Frame); FSKAKey right = track.GetRight(Frame); float value; value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); // interpolate the value and apply switch (track.flag) { case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break; case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break; case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break; case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break; case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break; case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break; case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break; case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break; case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break; } } } } } catch { } } } else { TreeNode SkeletonAnimation = new TreeNode() { Text = "Skeleton Animations" }; ThisAnimation.Nodes.Add(SkeletonAnimation); TreeNode dummy = new TreeNode() { Text = "Animation Set" }; int i = 0; foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values) { if (i == 0) { dummy = new TreeNode() { Text = "Animation Set " + "0 - 100" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 100) { dummy = new TreeNode() { Text = "Animation Set " + "100 - 200" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 200) { dummy = new TreeNode() { Text = "Animation Set " + "200 - 300" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 300) { dummy = new TreeNode() { Text = "Animation Set " + "300 - 400" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 400) { dummy = new TreeNode() { Text = "Animation Set " + "400 - 500" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 500) { dummy = new TreeNode() { Text = "Animation Set " + "500 - 600" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 600) { dummy = new TreeNode() { Text = "Animation Set " + "600 - 700" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 700) { dummy = new TreeNode() { Text = "Animation Set " + "700 - 800" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 800) { dummy = new TreeNode() { Text = "Animation Set " + "800 - 900" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 900) { dummy = new TreeNode() { Text = "Animation Set " + "900 - 1000" }; SkeletonAnimation.Nodes.Add(dummy); } if (i == 1000) { dummy = new TreeNode() { Text = "Animation Set " + "1000+" }; SkeletonAnimation.Nodes.Add(dummy); } Animation a = new Animation(ska.Name); SkeletonAnimations.Add(a); if (i >= 0 && i < 100) { SkeletonAnimation.Nodes[0].Nodes.Add(a); } if (i >= 100 && i < 200) { SkeletonAnimation.Nodes[1].Nodes.Add(a); } if (i >= 200 && i < 300) { SkeletonAnimation.Nodes[2].Nodes.Add(a); } if (i >= 300 && i < 400) { SkeletonAnimation.Nodes[3].Nodes.Add(a); } if (i >= 400 && i < 500) { SkeletonAnimation.Nodes[4].Nodes.Add(a); } if (i >= 500 && i < 600) { SkeletonAnimation.Nodes[5].Nodes.Add(a); } if (i >= 600 && i < 700) { SkeletonAnimation.Nodes[6].Nodes.Add(a); } if (i >= 700 && i < 800) { SkeletonAnimation.Nodes[7].Nodes.Add(a); } if (i >= 800 && i < 900) { SkeletonAnimation.Nodes[8].Nodes.Add(a); } if (i >= 900 && i < 1000) { SkeletonAnimation.Nodes[9].Nodes.Add(a); } a.FrameCount = ska.FrameCount; i++; try { foreach (BoneAnim bn in ska.BoneAnims) { FSKANodeWiiU bonean = new FSKANodeWiiU(bn); Animation.KeyNode bone = new Animation.KeyNode(""); a.Bones.Add(bone); if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ) { bone.RotType = Animation.RotationType.EULER; } else { bone.RotType = Animation.RotationType.QUATERNION; } bone.Text = bonean.Text; for (int Frame = 0; Frame < ska.FrameCount; Frame++) { //Set base/start values for bones. //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these if (Frame == 0) { if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale)) { bone.XSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.X }); bone.YSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Y }); bone.ZSCA.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.sca.Z }); } if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate)) { bone.XROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.X }); bone.YROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Y }); bone.ZROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.Z }); bone.WROT.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.rot.W }); } if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate)) { bone.XPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.X }); bone.YPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Y }); bone.ZPOS.Keys.Add(new Animation.KeyFrame() { Frame = 0, Value = bonean.pos.Z }); } } foreach (FSKATrack track in bonean.tracks) { Animation.KeyFrame frame = new Animation.KeyFrame(); frame.InterType = Animation.InterpolationType.HERMITE; frame.Frame = Frame; FSKAKey left = track.GetLeft(Frame); FSKAKey right = track.GetRight(Frame); float value; value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); // interpolate the value and apply switch (track.flag) { case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break; case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break; case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break; case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break; case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break; case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break; case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break; case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break; case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break; } } } } } catch { } } } Console.WriteLine("Saving " + SkeletonAnimations.Count + " anims"); foreach (var anim in SkeletonAnimations) { anim.SaveAsExpeditedAnim(); } }