private void openFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Nif Files (*.nif)|*.nif|" + "EGM Files (*.egm)|*.egm|" + "TRI Files (*.tri)|*.tri|" + "All files (*.*)|*.*"; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { HeadFile nifFile = new HeadFile(open.FileName); this.modifiersStages.Clear(); this.modifiers.Clear(); this.modifiersStages.Add(nifFile); this.modifierPropertiesPanel.Controls.Clear(); this.modifiersListView.Items.Clear(); this.addButton.Enabled = true; this.deletebutton.Enabled = true; this.moveUpButton.Enabled = true; this.moveDownbutton.Enabled = true; this.clearButton.Enabled = true; this.resetButton.Enabled = true; this.targetFileTextBox.Text = open.FileName; } catch (FileNotFoundException) { MessageBox.Show("Could not load tri file"); } } }
void openReferenceFileButton_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Nif Files (*.nif)|*.nif|" + "EGM Files (*.egm)|*.egm|" + "TRI Files (*.tri)|*.tri|" + "All files (*.*)|*.*"; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { HeadFile nifFile = new HeadFile(open.FileName); if (nifFile.TRI.Header.VertexCount == this.targetFile.TRI.Header.VertexCount) { this.referenceFile = nifFile; if (this.autodetect == true) { this.AutoDetectVertices(); } } } catch (Exception) { return; } } }
public override HeadFile Apply() { if (this.targetFile == null) { //MessageBox.Show("No target file"); return(this.targetFile); } if (this.referenceFile == null) { //MessageBox.Show("No reference file"); return(this.targetFile); } if (this.vertexIndexes == null || this.vertexIndexes.Count == 0) { //MessageBox.Show("No vertex indexes"); return(this.targetFile); } HeadFile ret = new HeadFile(this.targetFile); ret.EGM.Append(this.vertexIndexes, this.referenceFile.EGM); StringBuilder bld = new StringBuilder(this.menu.nameTextBox.Text); bld.Append("\0"); this.modifierName = bld.ToString(); ret.TRI.AppendModifier(this.vertexIndexes, this.referenceFile.TRI, bld.ToString()); this.applied = true; return(ret); }
public override HeadFile Apply() { if (this.target == null) { return(null); } HeadFile ret = new HeadFile(this.target); TRIMorphData targetMorph = null; foreach (TRIMorphData morph in ret.TRI.Morphs) { if (morph.Name.ToLower().StartsWith("vampiremorph")) { targetMorph = morph; break; } } if (targetMorph != null) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { targetMorph[i] = new VertexDisplacement(0, 0, 0); } this.applied = true; this.menu.appliedLabel.Text = "Applied: True"; } return(ret); }
public void Reset() { FaceFile?.Reset(); HairFile?.Reset(); BodyFile?.Reset(); HeadFile?.Reset(); Manipulations.Clear(); }
public OBJFile(FileStream stream) { this.vertices = new List <VertexPosition>(); this.triangleFaces = new List <TriangleFace>(); this.quadFaces = new List <QuadFace>(); StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); text = text.Replace("\r", ""); text = text.Replace('.', ','); string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string[] words = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); //if (words[0] == "v") //{ // float x = float.Parse(words[1]); // float y = float.Parse(words[2]); // float z = float.Parse(words[3]); // VertexPosition coord = new VertexPosition(x, y, z); // this.vertices.Add(coord); //} switch (words[0]) { case "v": float x = float.Parse(words[1]); float y = float.Parse(words[2]); float z = float.Parse(words[3]); VertexPosition coord = new VertexPosition(x, y, z); this.vertices.Add(coord); break; case "f": if (words.Length == 5) { int a4 = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); int b4 = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); int c4 = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); int d4 = int.Parse(words[4].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); QuadFace face4 = new QuadFace(a4, b4, c4, d4); this.quadFaces.Add(face4); break; } int a = int.Parse(words[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); int b = int.Parse(words[2].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); int c = int.Parse(words[3].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]); TriangleFace face = new TriangleFace(a, b, c); this.triangleFaces.Add(face); break; } } this.mesh = new MeshBase(); this.mesh.QuadFaces = this.quadFaces; this.mesh.TriangleFaces = this.triangleFaces; this.mesh.Vertices = this.vertices; string[] path = stream.Name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); this.mesh.Name = HeadFile.ReplaceExtention(path[path.Length - 1], ""); }
public void Dispose() { FaceFile?.Dispose(); HairFile?.Dispose(); BodyFile?.Dispose(); HeadFile?.Dispose(); FaceFile = null; HairFile = null; BodyFile = null; HeadFile = null; Manipulations.Clear(); }
private void clearButton_Click(object sender, EventArgs e) { this.modifierPropertiesPanel.Controls.Clear(); HeadFile start = this.modifiersStages[0]; this.modifiersStages.Clear(); this.modifiersStages.Add(start); this.modifiers.Clear(); this.modifiersListView.BeginUpdate(); this.modifiersListView.Items.Clear(); this.modifiersListView.EndUpdate(); }
public AddEyeMorph() { this.menu = new AddEyeMorphControl(); this.menu.openVertexIndexesButton.Click += new EventHandler(openVertexIndexesButton_Click); this.menu.openReferenceFileButton.Click += new EventHandler(openReferenceFileButton_Click); this.menu.applyButton.Click += new EventHandler(applyButton_Click); this.menu.radioButton1.CheckedChanged += new EventHandler(radioButton1_CheckedChanged); this.menu.radioButton2.CheckedChanged += new EventHandler(radioButton2_CheckedChanged); this.autodetect = false; this.applied = false; this.targetFile = null; this.referenceFile = null; }
public override HeadFile Apply() { if (this.target == null || this.reference == null) { return(this.target); } HeadFile ret = new HeadFile(this.target); for (int i = 0; i < this.target.TRI.Header.VertexCount; i++) { ret.TRI.Vertices[i] = this.reference.Vertices[i]; } this.applied = true; return(ret); }
public override HeadFile Apply() { if (this.reference == null || this.targetMorph == null) { return(this.target); } if (this.reference.Vertices.Count != this.target.TRI.Header.VertexCount) { return(this.target); } if (!(this.targetMorph.StartsWith("SYM") || this.targetMorph.StartsWith("ASYM"))) { return(this.target); } List <VertexDisplacement> morphList = this.CalculateDisplacements(this.target.TRI.Vertices, this.reference.Vertices, this.ignoreList, this.accuracy); HeadFile ret = new HeadFile(this.target); try { int number = int.Parse(this.targetMorph.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)[1]); if (this.targetMorph.StartsWith("SYM")) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { ret.EGM.SymMorps[number][i] = morphList[i]; } //ret.EGM.SymMorps[number].Unknown = BitConverter.GetBytes(((float)(scale))).Reverse<byte>().ToArray<byte>(); } if (this.targetMorph.StartsWith("ASYM")) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { ret.EGM.AsymMorps[number][i] = morphList[i]; } //ret.EGM.AsymMorps[number].Unknown = BitConverter.GetBytes(((float)(scale))).Reverse<byte>().ToArray<byte>(); } this.applied = true; } catch (Exception) { } return(ret); }
private void addButton_Click(object sender, EventArgs e) { AbstractModifier mod = AbstractModifier.MakeModifier(this.modifiersComboBox.Text); if (mod != null) { this.modifierPropertiesPanel.Controls.Clear(); this.modifiersListView.SelectedItems.Clear(); mod.Target = this.modifiersStages[this.modifiersStages.Count - 1]; this.modifiersListView.BeginUpdate(); this.modifiersListView.SelectedItems.Clear(); this.modifiersListView.Items.Add(mod.ToListViewItem(this.modifiers.Count)); this.modifiersListView.EndUpdate(); this.modifierPropertiesPanel.Controls.Clear(); this.modifierPropertiesPanel.Controls.Add(mod.Menu); this.modifiers.Add(mod); mod.WhenReady += new AbstractModifier.Ready(mod_WhenReady); HeadFile tmp = this.modifiersStages[this.modifiersStages.Count - 1]; this.modifiersStages.Add(tmp); } }
public override HeadFile Apply() { if (this.reference == null || this.targetExpression == null) { return(this.target); } if (this.reference.Vertices.Count != this.target.TRI.Header.VertexCount) { return(this.target); } if (this.targetExpression.Length < 1) { return(this.target); } List <VertexDisplacement> morphList = this.CalculateDisplacements(this.target.TRI.Vertices, this.reference.Vertices, this.ignoreList, this.accuracy); HeadFile ret = new HeadFile(this.target); try { foreach (TRIMorphData morph in ret.TRI.Morphs) { if (morph.Name.StartsWith(this.targetExpression)) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { morph[i] = morphList[i]; } break; } } } catch (Exception) { return(this.target); } this.applied = true; return(ret); }
public override HeadFile Apply(HeadFile target) { throw new NotImplementedException(); }
private HeadFile ApplyAbsolute() { Dictionary <Expression, List <Triple <double, double, double> > > offsets = new Dictionary <Expression, List <Triple <double, double, double> > >(); foreach (KeyValuePair <Expression, MeshBase> expression in this.expressions) { offsets.Add(expression.Key, this.CalculateOffsets(this.target.TRI.Vertices, expression.Value.Vertices)); } Dictionary <Morph, List <VertexPosition> > unmorphs = new Dictionary <Morph, List <VertexPosition> >(); for (int i = 0; i < 4; i++) { Morph morph = (Morph)i; List <Triple <double, double, double> > unmorph = new List <Triple <double, double, double> >(); for (int j = 0; j < this.target.TRI.Header.VertexCount; j++) { unmorph.Add(new Triple <double, double, double>()); } foreach (KeyValuePair <Expression, Dictionary <Morph, double> > weight in this.weights) { if (weight.Value.ContainsKey(morph)) { List <Triple <double, double, double> > mlist = offsets[weight.Key]; double w = weight.Value[morph]; for (int k = 0; k < mlist.Count; k++) { Triple <double, double, double> aux = unmorph[k]; aux.X = aux.X + w * (double)(mlist[k].X); aux.Y = aux.Y + w * (double)(mlist[k].Y); aux.Z = aux.Z + w * (double)(mlist[k].Z); unmorph[k] = aux; } } } List <VertexPosition> unmorph2 = new List <VertexPosition>(); for (int j = 0; j < unmorph.Count; j++) { Triple <double, double, double> aux = unmorph[j]; VertexPosition pos = new VertexPosition(); pos.X = this.target.TRI.Vertices[j].X - (float)(aux.X / 100d); pos.Y = this.target.TRI.Vertices[j].Y - (float)(aux.Y / 100d); pos.Z = this.target.TRI.Vertices[j].Z - (float)(aux.Z / 100d); unmorph2.Add(pos); } unmorphs.Add(morph, unmorph2); } Dictionary <Morph, List <VertexDisplacement> > displacements = new Dictionary <Morph, List <VertexDisplacement> >(); for (int i = 0; i < 4; i++) { Morph morph = (Morph)i; displacements.Add(morph, this.CalculateDisplacements(this.target.TRI.Vertices, unmorphs[morph], this.ignoreList, this.accuracy)); } HeadFile ret = new HeadFile(this.target); try { foreach (KeyValuePair <Morph, List <VertexDisplacement> > keypair in displacements) { foreach (TRIMorphData morph in ret.TRI.Morphs) { if (morph.Name.ToLower().StartsWith(keypair.Key.ToString().ToLower())) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { morph[i] = keypair.Value[i]; } } } } } catch (Exception) { return(this.target); } this.applied = true; return(ret); }
private HeadFile ApplyRelative() { Dictionary <Expression, List <VertexDisplacement> > displacements = new Dictionary <Expression, List <VertexDisplacement> >(); for (int j = 0; j < 5; j++) { Expression exp = (Expression)j; displacements.Add(exp, this.CalculateDisplacements(this.target.TRI.Vertices, this.expressions[exp].Vertices, this.ignoreList, this.accuracy)); } Dictionary <Morph, List <Triple <double, double, double> > > unmorphs = new Dictionary <Morph, List <Triple <double, double, double> > >(); for (int i = 0; i < 4; i++) { Morph morph = (Morph)i; List <Triple <double, double, double> > unmorph = new List <Triple <double, double, double> >(); for (int j = 0; j < this.target.TRI.Header.VertexCount; j++) { unmorph.Add(new Triple <double, double, double>()); } foreach (KeyValuePair <Expression, Dictionary <Morph, double> > weight in this.weights) { if (weight.Value.ContainsKey(morph)) { List <VertexDisplacement> mlist = displacements[weight.Key]; double w = weight.Value[morph]; for (int k = 0; k < mlist.Count; k++) { Triple <double, double, double> aux = unmorph[k]; aux.X = aux.X + w * (double)(mlist[k].X); aux.Y = aux.Y + w * (double)(mlist[k].Y); aux.Z = aux.Z + w * (double)(mlist[k].Z); unmorph[k] = aux; } } } for (int j = 0; j < unmorph.Count; j++) { Triple <double, double, double> aux = unmorph[j]; aux.X = aux.X / 100d; aux.Y = aux.Y / 100d; aux.Z = aux.Z / 100d; unmorph[j] = aux; } unmorphs.Add(morph, unmorph); } Dictionary <Morph, List <VertexDisplacement> > morphs = new Dictionary <Morph, List <VertexDisplacement> >(); foreach (KeyValuePair <Morph, List <Triple <double, double, double> > > keypair in unmorphs) { double totalscale = 0; foreach (KeyValuePair <Expression, Dictionary <Morph, double> > weight in this.weights) { if (weight.Value.ContainsKey(keypair.Key)) { totalscale += weight.Value[keypair.Key]; } } if (totalscale > 100) { List <VertexDisplacement> morph = new List <VertexDisplacement>(); double max = 100 / totalscale; for (int i = 0; i < keypair.Value.Count; i++) { Triple <double, double, double> triple = keypair.Value[i]; morph.Add(new VertexDisplacement((short)(Math.Min(triple.X * max, short.MaxValue)), (short)(Math.Min(triple.Y * max, short.MaxValue)), (short)(Math.Min(triple.Z * max, short.MaxValue)))); } morphs.Add(keypair.Key, morph); } else { List <VertexDisplacement> morph = new List <VertexDisplacement>(); for (int i = 0; i < keypair.Value.Count; i++) { Triple <double, double, double> triple = keypair.Value[i]; morph.Add(new VertexDisplacement((short)(triple.X), (short)(triple.Y), (short)(triple.Z))); } morphs.Add(keypair.Key, morph); } } HeadFile ret = new HeadFile(this.target); try { foreach (KeyValuePair <Morph, List <VertexDisplacement> > keypair in morphs) { List <VertexDisplacement> morph2 = keypair.Value; foreach (TRIMorphData morph in ret.TRI.Morphs) { if (morph.Name.ToLower().StartsWith(keypair.Key.ToString().ToLower())) { for (int i = 0; i < ret.TRI.Header.VertexCount; i++) { morph[i] = morph2[i]; } } } } } catch (Exception) { return(this.target); } this.applied = true; return(ret); }