public static ResNX.ResFile BFRESConvertWiiUToSwitch(ResU.ResFile resFileU) { ResNX.ResFile resFile = new ResNX.ResFile(); foreach (var model in resFileU.Models) { } return(resFile); }
public void Import(string[] FileNames, ResNX.ResFile resFileNX, ResU.ResFile resFileU) { if (Type == BRESGroupType.Textures) { ImportTexture(FileNames); return; } foreach (string FileName in FileNames) { string ResourceName = Path.GetFileNameWithoutExtension(FileName); string ResourceNameExt = Path.GetFileName(FileName); string extension = Path.GetExtension(FileName); switch (Type) { case BRESGroupType.Models: FMDL fmdl = NewModel(false); fmdl.Text = ResourceName; fmdl.Replace(FileName, resFileNX, resFileU); fmdl.UpdateVertexData(); AddNode(fmdl); break; case BRESGroupType.SkeletalAnim: FSKA fska = new FSKA(); fska.Text = ResourceName; if (IsWiiU) { fska.SkeletalAnimU = new ResU.SkeletalAnim(); } else { fska.SkeletalAnim = new ResNX.SkeletalAnim(); } fska.Replace(FileName, resFileNX, resFileU); Nodes.Add(fska); break; case BRESGroupType.ShaderParamAnim: if (IsWiiU) { FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.ShaderParam); fshu.Text = ResourceName; fshu.Replace(FileName, resFileU); Nodes.Add(fshu); } else { FMAA fmaaPrm = new FMAA(new ResNX.MaterialAnim()); fmaaPrm.Text = ResourceName; fmaaPrm.Replace(FileName); Nodes.Add(fmaaPrm); } break; case BRESGroupType.ColorAnim: if (IsWiiU) { FSHU fclh = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.Color); fclh.Text = ResourceName; fclh.Replace(FileName, resFileU); Nodes.Add(fclh); } else { FMAA fmaaClr = new FMAA(new ResNX.MaterialAnim()); fmaaClr.Text = ResourceName; fmaaClr.Replace(FileName); Nodes.Add(fmaaClr); } break; case BRESGroupType.TexSrtAnim: if (IsWiiU) { FSHU fsth = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.TextureSrt); fsth.Text = ResourceName; fsth.Replace(FileName, resFileU); Nodes.Add(fsth); } else { FMAA fmaaSrt = new FMAA(new ResNX.MaterialAnim()); fmaaSrt.Text = ResourceName; fmaaSrt.Replace(FileName); Nodes.Add(fmaaSrt); } break; case BRESGroupType.TexPatAnim: if (IsWiiU) { FTXP ftxp = new FTXP(new ResU.TexPatternAnim()); ftxp.Text = ResourceName; ftxp.Replace(FileName, resFileU); Nodes.Add(ftxp); } else { FMAA fmaaTxp = new FMAA(new ResNX.MaterialAnim()); fmaaTxp.Text = ResourceName; fmaaTxp.Replace(FileName); Nodes.Add(fmaaTxp); } break; case BRESGroupType.BoneVisAnim: FVIS fbnv = new FVIS(); fbnv.Text = ResourceName; if (IsWiiU) { fbnv.VisibilityAnimU = new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Bone } } ; else { fbnv.VisibilityAnim = new ResNX.VisibilityAnim(); } fbnv.Replace(FileName, resFileNX, resFileU); Nodes.Add(fbnv); break; case BRESGroupType.MatVisAnim: if (IsWiiU) { FVIS fmtv = new FVIS(new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Material }); fmtv.Text = ResourceName; fmtv.Replace(FileName, resFileNX, resFileU); Nodes.Add(fmtv); } else { FMAA fmaaVis = new FMAA(new ResNX.MaterialAnim()); fmaaVis.Text = ResourceName; fmaaVis.Replace(FileName); Nodes.Add(fmaaVis); } break; case BRESGroupType.ShapeAnim: FSHA fsha = new FSHA(); fsha.Text = ResourceName; if (IsWiiU) { fsha.ShapeAnimU = new ResU.ShapeAnim(); } else { fsha.ShapeAnim = new ResNX.ShapeAnim(); } fsha.Replace(FileName, resFileNX, resFileU); Nodes.Add(fsha); break; case BRESGroupType.SceneAnim: FSCN fscn = new FSCN(); fscn.Text = ResourceName; if (IsWiiU) { fscn.SceneAnimU = new ResU.SceneAnim(); } else { fscn.SceneAnim = new ResNX.SceneAnim(); } fscn.Replace(FileName, resFileNX, resFileU); Nodes.Add(fscn); break; case BRESGroupType.Embedded: ExternalFileData ext = new ExternalFileData(ResourceNameExt, File.ReadAllBytes(FileName)); ext.Replace(FileName); Nodes.Add(ext); break; case BRESGroupType.MaterialAnim: FMAA fmaa = new FMAA(new ResNX.MaterialAnim()); fmaa.Replace(FileName); Nodes.Add(fmaa); break; } } }
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 ResU.ResFile BFRESConvertSwitchToWiiU(ResNX.ResFile resFileNX) { ResU.ResFile resFile = new ResU.ResFile(); return(resFile); }
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(); } }
public void Import(string[] FileNames, ResNX.ResFile resFileNX, ResU.ResFile resFileU) { if (Type == BRESGroupType.Textures) { ImportTexture(FileNames); return; } foreach (string FileName in FileNames) { string ResourceName = Path.GetFileNameWithoutExtension(FileName); string extension = Path.GetExtension(FileName); switch (Type) { case BRESGroupType.Models: FMDL fmdl = new FMDL(); fmdl.Text = ResourceName; if (IsWiiU) { fmdl.ModelU = new ResU.Model(); fmdl.ModelU = new ResU.Model(); fmdl.ModelU.Name = ResourceName; var skeleton = new ResU.Skeleton(); //Create skeleton with empty bone skeleton.Bones.Add("Root", new ResU.Bone() { Name = "Root" }); fmdl.ModelU.Skeleton = skeleton; BfresWiiU.ReadModel(fmdl, fmdl.ModelU); ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton); } else { fmdl.Model = new ResNX.Model(); fmdl.Model.Name = ResourceName; //Create skeleton with empty bone var skeleton = new ResNX.Skeleton(); skeleton.Bones.Add(new ResNX.Bone() { Name = "Root" }); fmdl.Model.Skeleton = skeleton; BfresSwitch.ReadModel(fmdl, fmdl.Model); ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton); } fmdl.Replace(FileName, resFileNX, resFileU); Nodes.Add(fmdl); fmdl.UpdateVertexData(); break; case BRESGroupType.SkeletalAnim: FSKA fska = new FSKA(); fska.Text = ResourceName; if (IsWiiU) { fska.SkeletalAnimU = new ResU.SkeletalAnim(); } else { fska.SkeletalAnim = new ResNX.SkeletalAnim(); } fska.Replace(FileName, resFileNX, resFileU); Nodes.Add(fska); break; case BRESGroupType.ShaderParamAnim: FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.ShaderParam); fshu.Text = ResourceName; fshu.Replace(FileName, resFileU); Nodes.Add(fshu); break; case BRESGroupType.ColorAnim: FSHU fclh = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.Color); fclh.Text = ResourceName; fclh.Replace(FileName, resFileU); Nodes.Add(fclh); break; case BRESGroupType.TexSrtAnim: FSHU fsth = new FSHU(new ResU.ShaderParamAnim(), MaterialAnimation.AnimationType.TextureSrt); fsth.Text = ResourceName; fsth.Replace(FileName, resFileU); Nodes.Add(fsth); break; case BRESGroupType.TexPatAnim: FTXP ftxp = new FTXP(new ResU.TexPatternAnim()); ftxp.Text = ResourceName; ftxp.Replace(FileName, resFileU); Nodes.Add(ftxp); break; case BRESGroupType.BoneVisAnim: FVIS fbnv = new FVIS(); fbnv.Text = ResourceName; if (IsWiiU) { fbnv.VisibilityAnimU = new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Bone } } ; else { fbnv.VisibilityAnim = new ResNX.VisibilityAnim(); } fbnv.Replace(FileName, resFileNX, resFileU); Nodes.Add(fbnv); break; case BRESGroupType.MatVisAnim: FVIS fmtv = new FVIS(new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Material }); fmtv.Text = ResourceName; fmtv.Replace(FileName, resFileNX, resFileU); Nodes.Add(fmtv); break; case BRESGroupType.ShapeAnim: FSHA fsha = new FSHA(); fsha.Text = ResourceName; if (IsWiiU) { fsha.ShapeAnimU = new ResU.ShapeAnim(); } else { fsha.ShapeAnim = new ResNX.ShapeAnim(); } fsha.Replace(FileName, resFileNX, resFileU); Nodes.Add(fsha); break; case BRESGroupType.SceneAnim: FSCN fscn = new FSCN(); fscn.Text = ResourceName; if (IsWiiU) { fscn.SceneAnimU = new ResU.SceneAnim(); } else { fscn.SceneAnim = new ResNX.SceneAnim(); } fscn.Replace(FileName, resFileNX, resFileU); Nodes.Add(fscn); break; case BRESGroupType.Embedded: ExternalFileData ext = new ExternalFileData(ResourceName, File.ReadAllBytes(FileName)); ext.Replace(FileName); Nodes.Add(ext); break; case BRESGroupType.MaterialAnim: FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.ShaderParam); fmaa.Replace(FileName); Nodes.Add(fmaa); break; } } }
public void Read(ResFile targetWiiUbfres, AnimationGroupNode thisAnimation, ResNSW.ResFile b) { Console.WriteLine("Reading Skeleton Animations ..."); if (b != null) { TreeNode skeletonAnimationNode = new TreeNode { Text = "Skeleton Animations" }; thisAnimation.Nodes.Add(skeletonAnimationNode); // Split animation nodes into groups so they can all fit inside the view. // Make sure to add an additional set if the animations can't be divided evenly. int setCount = b.SkeletalAnims.Count / setSize; if (b.SkeletalAnims.Count % setSize != 0) { setCount += 1; } for (int i = 0; i < setCount; i++) { int start = i * setSize; int end = start + setSize - 1; skeletonAnimationNode.Nodes.Add(new TreeNode { Text = $"Animation Set {start} - {end}" }); } for (int i = 0; i < b.SkeletalAnims.Count; i++) { var ska = b.SkeletalAnims[i]; int setIndex = i / setSize; Animation a = new Animation(ska.Name); SkeletonAnimations.Add(a); a.frameCount = ska.FrameCount; skeletonAnimationNode.Nodes[setIndex].Nodes.Add(a); 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 keyFrame = new Animation.KeyFrame(); keyFrame.interType = Animation.InterpolationType.Hermite; keyFrame.Frame = frame; FSKAKey left = track.GetLeft(frame); FSKAKey right = track.GetRight(frame); // interpolate the value and apply float value = Animation.Hermite(frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); switch (track.flag) { case (int)TrackType.XPOS: keyFrame.Value = value; bone.xpos.keys.Add(keyFrame); break; case (int)TrackType.YPOS: keyFrame.Value = value; bone.ypos.keys.Add(keyFrame); break; case (int)TrackType.ZPOS: keyFrame.Value = value; bone.zpos.keys.Add(keyFrame); break; case (int)TrackType.XROT: keyFrame.Value = value; bone.xrot.keys.Add(keyFrame); break; case (int)TrackType.YROT: keyFrame.Value = value; bone.yrot.keys.Add(keyFrame); break; case (int)TrackType.ZROT: keyFrame.Value = value; bone.zrot.keys.Add(keyFrame); break; case (int)TrackType.XSCA: keyFrame.Value = value; bone.xsca.keys.Add(keyFrame); break; case (int)TrackType.YSCA: keyFrame.Value = value; bone.ysca.keys.Add(keyFrame); break; case (int)TrackType.ZSCA: keyFrame.Value = value; bone.zsca.keys.Add(keyFrame); 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); 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 { } } } }