private void ParseSamplerTrack(FMAT material, SamplerTrack track) { if (TextureList.Count == 0) { return; } if (material.AnimatedSamplers.ContainsKey(track.Sampler)) { material.AnimatedSamplers.Remove(track.Sampler); } var value = (int)track.GetFrameValue(this.Frame); var texture = TextureList[value]; material.AnimatedSamplers.Add(track.Sampler, texture); }
public void Reload(MaterialAnim anim) { Name = anim.Name; FrameCount = anim.FrameCount; FrameRate = 60.0f; Loop = anim.Loop; if (anim.TextureNames != null) { TextureList = anim.TextureNames.Keys.ToList(); } if (anim.MaterialAnimDataList == null) { return; } AnimGroups.Clear(); foreach (var matAnim in anim.MaterialAnimDataList) { var group = new MaterialAnimGroup(); AnimGroups.Add(group); group.Name = matAnim.Name; //Get the material animation's texture pattern animation lists //Each sampler has their own info for (int i = 0; i < matAnim.PatternAnimInfos.Count; i++) { var patternInfo = matAnim.PatternAnimInfos[i]; //Get the curve index for animated indices int curveIndex = patternInfo.CurveIndex; //Get the base index for starting values int textureBaseIndex = matAnim.BaseDataList.Length > i ? matAnim.BaseDataList[i] : 0; //Make a new sampler track using step interpolation var samplerTrack = new SamplerTrack(); samplerTrack.InterpolationType = STInterpoaltionType.Step; samplerTrack.Sampler = patternInfo.Name; group.Tracks.Add(samplerTrack); if (curveIndex != -1) { BfresAnimations.GenerateKeys(samplerTrack, matAnim.Curves[curveIndex], true); } else //Use the base data and make a constant key { samplerTrack.KeyFrames.Add(new STKeyFrame(0, textureBaseIndex)); } } //Get the list of animated parameters for (int i = 0; i < matAnim.ParamAnimInfos.Count; i++) { ParamAnimGroup paramGroup = new ParamAnimGroup(); paramGroup.Name = matAnim.ParamAnimInfos[i].Name; group.SubAnimGroups.Add(paramGroup); var paramInfo = matAnim.ParamAnimInfos[i]; //Params have int and float curves int curveIndex = paramInfo.BeginCurve; int constantIndex = paramInfo.BeginConstant; int numFloats = paramInfo.FloatCurveCount; int numInts = paramInfo.IntCurveCount; int numConstants = paramInfo.ConstantCount; //Each constant and curve get's their own value using a value offset for (int j = 0; j < numConstants; j++) { var constant = matAnim.Constants[constantIndex + j]; float value = constant.Value; //A bit hacky, convert int32 types by value range SRT modes use if (constant.Value.Int32 > 0 && constant.Value.Int32 < 6) { value = constant.Value.Int32; } paramGroup.Tracks.Add(new ParamTrack() { Name = constant.AnimDataOffset.ToString("X"), ValueOffset = constant.AnimDataOffset, //Not the best way, but 4 is typically the stride size for each value ChannelIndex = (int)(constant.AnimDataOffset / 4), KeyFrames = new List <STKeyFrame>() { new STKeyFrame(0, value) }, InterpolationType = STInterpoaltionType.Constant, }); } //Loop through all int and float curve values for (int j = 0; j < numInts + numFloats; j++) { var curve = matAnim.Curves[curveIndex + j]; var paramTrack = new ParamTrack() { Name = curve.AnimDataOffset.ToString("X") }; paramTrack.ValueOffset = curve.AnimDataOffset; //Not the best way, but 4 is typically the stride size for each value paramTrack.ChannelIndex = (int)(curve.AnimDataOffset / 4); paramGroup.Tracks.Add(paramTrack); BfresAnimations.GenerateKeys(paramTrack, curve); } } } }