private void NewCLR() { CLR0MaterialEntryNode n = ((CLR0Node)_resource).CreateEntry(); if (n != null) { BaseWrapper b = FindResource(n, true); b?.EnsureVisible(); } }
public CLR0MaterialEntryNode CreateEntry() { CLR0MaterialNode node = new CLR0MaterialNode(); CLR0MaterialEntryNode entry = new CLR0MaterialEntryNode(); entry._target = EntryTarget.Color0; entry._name = entry._target.ToString(); entry._numEntries = -1; entry.NumEntries = _numFrames; entry.Constant = true; entry.SolidColor = new ARGBPixel(); node.Name = this.FindName("MaterialName"); this.AddChild(node); node.AddChild(entry); return(entry); }
private void lstTarget_SelectedIndexChanged(object sender, EventArgs e) { if (_mat == null) { if (_mainWindow.KeyframePanel != null) { _mainWindow.KeyframePanel.chkEnabled.Checked = false; _mainWindow.KeyframePanel.chkConstant.Checked = false; } return; } _entry = _mat.FindChild(lstTarget.SelectedItem as string, false) as CLR0MaterialEntryNode; _mainWindow.KeyframePanel.chkEnabled.Checked = _entry != null; _mainWindow.KeyframePanel.chkConstant.Checked = _entry != null ? _entry.Constant : false; _mainWindow.KeyframePanel.TargetSequence = _entry; }
public static ResU.ShaderParamMatAnim Clr0Entry2ShaderMatAnim(CLR0Node clr0, CLR0MaterialNode clrMaterial) { ResU.ShaderParamMatAnim matAnim = new ResU.ShaderParamMatAnim(); matAnim.Name = clrMaterial.Name; foreach (var entry in clrMaterial.Children) { ushort curveIndex = 0; ushort constantIndex = 0; CLR0MaterialEntryNode ParamEntry = (CLR0MaterialEntryNode)entry; //Add constants for RGBA if constant if (ParamEntry.Constant) { //Red matAnim.Constants.Add(new ResU.AnimConstant() { AnimDataOffset = 0, Value = (float)ParamEntry.Colors[0].R / 255f, }); //Green matAnim.Constants.Add(new ResU.AnimConstant() { AnimDataOffset = 4, Value = (float)ParamEntry.Colors[0].G / 255f, }); //Blue matAnim.Constants.Add(new ResU.AnimConstant() { AnimDataOffset = 8, Value = (float)ParamEntry.Colors[0].B / 255f, }); //Alpha matAnim.Constants.Add(new ResU.AnimConstant() { AnimDataOffset = 12, Value = (float)ParamEntry.Colors[0].A / 255f, }); } var RedCurve = GenerateCurve(0, clr0, ParamEntry); var GreenCurve = GenerateCurve(4, clr0, ParamEntry); var BlueCurve = GenerateCurve(8, clr0, ParamEntry); var AlphaCurve = GenerateCurve(12, clr0, ParamEntry); if (RedCurve != null) { matAnim.Curves.Add(RedCurve); } if (GreenCurve != null) { matAnim.Curves.Add(GreenCurve); } if (BlueCurve != null) { matAnim.Curves.Add(BlueCurve); } if (AlphaCurve != null) { matAnim.Curves.Add(AlphaCurve); } matAnim.ParamAnimInfos.Add(new ResU.ParamAnimInfo() { Name = entry.Name, BeginCurve = matAnim.Curves.Count > 0 ? curveIndex : ushort.MaxValue, FloatCurveCount = (ushort)matAnim.Curves.Count, SubBindIndex = ushort.MaxValue, ConstantCount = (ushort)matAnim.Constants.Count, BeginConstant = matAnim.Constants.Count > 0 ? constantIndex : ushort.MaxValue, }); constantIndex += (ushort)matAnim.Constants.Count; curveIndex += (ushort)matAnim.Curves.Count; } return(matAnim); }
private static ResU.AnimCurve GenerateCurve(uint AnimOffset, CLR0Node anim, CLR0MaterialEntryNode entry) { ResU.AnimCurve curve = new ResU.AnimCurve(); curve.AnimDataOffset = AnimOffset; curve.StartFrame = 0; curve.Offset = 0; curve.Scale = 1; curve.FrameType = ResU.AnimCurveFrameType.Single; curve.KeyType = ResU.AnimCurveKeyType.Single; curve.CurveType = ResU.AnimCurveType.Linear; List <float> Frames = new List <float>(); List <float> Keys = new List <float>(); for (int c = 0; c < entry.Colors.Count; c++) { Frames.Add(c); //Max of 4 values. Cubic using 4, linear using 2, and step using 1 float[] KeyValues = new float[4]; switch (AnimOffset) { case 0: //Red Keys.Add((float)entry.Colors[c].R / 255f); break; case 4: //Green Keys.Add((float)entry.Colors[c].G / 255f); break; case 8: //Blue Keys.Add((float)entry.Colors[c].B / 255f); break; case 12: //Alpha Keys.Add((float)entry.Colors[c].A / 255f); break; default: throw new Exception("Invalid animation offset set!"); } } //Max value in frames is our end frame curve.EndFrame = Frames.Max(); curve.Frames = Frames.ToArray(); //If a curve only has one frame we don't need to interpolate or add keys to a curve as it's constant if (curve.Frames.Length <= 1) { return(null); } switch (curve.CurveType) { case ResU.AnimCurveType.Cubic: curve.Keys = new float[Keys.Count, 4]; for (int frame = 0; frame < Keys.Count; frame++) { float Delta = 0; if (frame < Keys.Count - 1) { Delta = Keys[frame + 1] - Keys[frame]; } float value = Keys[frame]; float Slope = 0; float Slope2 = 0; curve.Keys[frame, 0] = value; curve.Keys[frame, 1] = Slope; curve.Keys[frame, 2] = Slope2; curve.Keys[frame, 3] = Delta; } break; case ResU.AnimCurveType.StepInt: //Step requires no interpolation curve.Keys = new float[Keys.Count, 1]; for (int frame = 0; frame < Keys.Count; frame++) { curve.Keys[frame, 0] = 0; } break; case ResU.AnimCurveType.Linear: curve.Keys = new float[Keys.Count, 2]; for (int frame = 0; frame < Keys.Count; frame++) { //Delta for second value used in linear curves float time = curve.Frames[frame]; float Delta = 0; if (frame < Keys.Count - 1) { Delta = Keys[frame + 1] - Keys[frame]; } curve.Keys[frame, 0] = Keys[frame]; curve.Keys[frame, 1] = Delta; } break; } return(curve); }