private void SetBonePoperty(Bone bone, BoneGroup group, ActionFrame property) { bone.Group = group; bone.Property = property; foreach (var child in bone.Children) { SetBonePoperty(child, group, property); } }
private List <BoneSwitch> GetModelVisibilitySectionBoneSwitches(int boneSwitchStartLocation, int numberOfBoneSwitches) { List <BoneSwitch> boneSwitches = new List <BoneSwitch>(); for (int boneSwitchIndex = 0; boneSwitchIndex < numberOfBoneSwitches; boneSwitchIndex++) { BoneSwitch boneSwitch = new BoneSwitch(); boneSwitches.Add(boneSwitch); boneSwitch.Offset = PsaFile.DataSection[boneSwitchStartLocation] + boneSwitchIndex * 8; int boneGroupStartLocation = PsaFile.DataSection[boneSwitchStartLocation] / 4 + boneSwitchIndex * 2; boneSwitch.DataOffset = PsaFile.DataSection[boneGroupStartLocation]; boneSwitch.Count = PsaFile.DataSection[boneGroupStartLocation + 1]; if (PsaFile.DataSection[boneSwitchStartLocation + boneSwitchIndex * 2] >= 8096 && PsaFile.DataSection[boneSwitchStartLocation + boneSwitchIndex * 2] < PsaFile.DataSectionSize) { int numberOfBoneGroups = PsaFile.DataSection[boneGroupStartLocation + boneSwitchIndex * 2 + 1]; if (numberOfBoneGroups > 0 && numberOfBoneGroups < 256) { for (int boneGroupIndex = 0; boneGroupIndex < numberOfBoneGroups; boneGroupIndex++) { BoneGroup boneGroup = new BoneGroup(); boneSwitch.BoneGroups.Add(boneGroup); boneGroup.Offset = PsaFile.DataSection[boneGroupStartLocation] + boneGroupIndex * 8; int bonesStartLocation = PsaFile.DataSection[boneGroupStartLocation] / 4 + boneGroupIndex * 2; boneGroup.DataOffset = PsaFile.DataSection[bonesStartLocation]; boneGroup.Count = PsaFile.DataSection[bonesStartLocation + 1]; if (PsaFile.DataSection[bonesStartLocation] >= 8096 && PsaFile.DataSection[bonesStartLocation] < PsaFile.DataSectionSize) { int numberOfBones = PsaFile.DataSection[bonesStartLocation + 1]; boneGroup.BoneList.Offset = PsaFile.DataSection[bonesStartLocation]; int boneValuesLocation = PsaFile.DataSection[bonesStartLocation] / 4; if (numberOfBones > 0 && numberOfBones < 256) { for (int boneIndex = 0; boneIndex < numberOfBones; boneIndex++) { int bone = PsaFile.DataSection[boneValuesLocation + boneIndex]; boneGroup.BoneList.Bones.Add(bone); } } } } } } } return(boneSwitches); }
public void LoadBoneGroup(Gfbanim.Bone boneAnim) { BoneGroup groupAnim = new BoneGroup(); groupAnim.Name = boneAnim.Name; AnimGroups.Add(groupAnim); //Tracks use 3 types // Fixed/constant // Dynamic (baked and multiple keys, no frames) // Framed (multiple keys and frames) List <float> Frames = new List <float>(); switch (boneAnim.RotateType) { case Gfbanim.QuatTrack.DynamicQuatTrack: { var rotate = boneAnim.Rotate <Gfbanim.DynamicQuatTrack>(); if (rotate.HasValue) { var values = GfbanimKeyFrameLoader.LoadRotationTrack(rotate.Value); groupAnim.RotationX = values[0]; groupAnim.RotationY = values[1]; groupAnim.RotationZ = values[2]; } } break; case Gfbanim.QuatTrack.FixedQuatTrack: { var rotate = boneAnim.Rotate <Gfbanim.FixedQuatTrack>(); if (rotate.HasValue) { var vec = rotate.Value.Value.Value; groupAnim.RotationX.KeyFrames.Add(new STKeyFrame(0, GfbanimKeyFrameLoader.ConvertRotation(vec.X))); groupAnim.RotationY.KeyFrames.Add(new STKeyFrame(0, GfbanimKeyFrameLoader.ConvertRotation(vec.Y))); groupAnim.RotationZ.KeyFrames.Add(new STKeyFrame(0, GfbanimKeyFrameLoader.ConvertRotation(vec.Z))); } } break; case Gfbanim.QuatTrack.FramedQuatTrack: { var rotate = boneAnim.Rotate <Gfbanim.FramedQuatTrack>(); if (rotate.HasValue) { var values = GfbanimKeyFrameLoader.LoadRotationTrack(rotate.Value); groupAnim.RotationX = values[0]; groupAnim.RotationY = values[1]; groupAnim.RotationZ = values[2]; } } break; } switch (boneAnim.ScaleType) { case Gfbanim.VectorTrack.FixedVectorTrack: { var scale = boneAnim.Scale <Gfbanim.FixedVectorTrack>(); if (scale.HasValue) { var vec = scale.Value.Value.Value; groupAnim.ScaleX.KeyFrames.Add(new STKeyFrame(0, vec.X)); groupAnim.ScaleY.KeyFrames.Add(new STKeyFrame(0, vec.Y)); groupAnim.ScaleZ.KeyFrames.Add(new STKeyFrame(0, vec.Z)); } } break; } switch (boneAnim.ScaleType) { case Gfbanim.VectorTrack.DynamicVectorTrack: { var scale = boneAnim.Scale <Gfbanim.DynamicVectorTrack>(); if (scale.HasValue) { var values = GfbanimKeyFrameLoader.LoadVectorTrack(scale.Value); groupAnim.ScaleX = values[0]; groupAnim.ScaleY = values[1]; groupAnim.ScaleZ = values[2]; } } break; case Gfbanim.VectorTrack.FramedVectorTrack: { var scale = boneAnim.Scale <Gfbanim.FramedVectorTrack>(); if (scale.HasValue) { var values = GfbanimKeyFrameLoader.LoadVectorTrack(scale.Value); groupAnim.ScaleX = values[0]; groupAnim.ScaleY = values[1]; groupAnim.ScaleZ = values[2]; } } break; case Gfbanim.VectorTrack.FixedVectorTrack: { var scale = boneAnim.Scale <Gfbanim.FixedVectorTrack>(); if (scale.HasValue) { var vec = scale.Value.Value.Value; groupAnim.ScaleX.KeyFrames.Add(new STKeyFrame(0, vec.X)); groupAnim.ScaleY.KeyFrames.Add(new STKeyFrame(0, vec.Y)); groupAnim.ScaleZ.KeyFrames.Add(new STKeyFrame(0, vec.Z)); } } break; } switch (boneAnim.TranslateType) { case Gfbanim.VectorTrack.DynamicVectorTrack: { var trans = boneAnim.Translate <Gfbanim.DynamicVectorTrack>(); if (trans.HasValue) { var values = GfbanimKeyFrameLoader.LoadVectorTrack(trans.Value); groupAnim.TranslateX = values[0]; groupAnim.TranslateY = values[1]; groupAnim.TranslateZ = values[2]; } } break; case Gfbanim.VectorTrack.FramedVectorTrack: { var trans = boneAnim.Translate <Gfbanim.FramedVectorTrack>(); if (trans.HasValue) { var values = GfbanimKeyFrameLoader.LoadVectorTrack(trans.Value); groupAnim.TranslateX = values[0]; groupAnim.TranslateY = values[1]; groupAnim.TranslateZ = values[2]; } } break; case Gfbanim.VectorTrack.FixedVectorTrack: { var trans = boneAnim.Translate <Gfbanim.FixedVectorTrack>(); if (trans.HasValue) { var vec = trans.Value.Value.Value; groupAnim.TranslateX.KeyFrames.Add(new STKeyFrame(0, vec.X)); groupAnim.TranslateY.KeyFrames.Add(new STKeyFrame(0, vec.Y)); groupAnim.TranslateZ.KeyFrames.Add(new STKeyFrame(0, vec.Z)); } } break; } }